2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* CMapDefines.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../ResourceSet.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../texts/MetaString.h"
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class TerrainType;
|
|
|
|
class RiverType;
|
|
|
|
class RoadType;
|
|
|
|
class CGObjectInstance;
|
|
|
|
class CGTownInstance;
|
|
|
|
class JsonSerializeFormat;
|
|
|
|
|
|
|
|
/// The map event is an event which e.g. gives or takes resources of a specific
|
|
|
|
/// amount to/from players and can appear regularly or once a time.
|
|
|
|
class DLL_LINKAGE CMapEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMapEvent();
|
|
|
|
virtual ~CMapEvent() = default;
|
|
|
|
|
2024-08-12 12:38:31 +02:00
|
|
|
bool occursToday(int currentDay) const;
|
|
|
|
bool affectsPlayer(PlayerColor player, bool isHuman) const;
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
std::string name;
|
|
|
|
MetaString message;
|
|
|
|
TResources resources;
|
2024-08-12 12:36:49 +02:00
|
|
|
std::set<PlayerColor> players;
|
2024-02-05 21:27:55 +02:00
|
|
|
bool humanAffected;
|
|
|
|
bool computerAffected;
|
2024-06-24 03:23:26 +02:00
|
|
|
ui32 firstOccurrence;
|
|
|
|
ui32 nextOccurrence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
|
2023-10-19 16:19:09 +02:00
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
h & name;
|
|
|
|
h & message;
|
|
|
|
h & resources;
|
2024-08-12 12:36:49 +02:00
|
|
|
if (h.version >= Handler::Version::EVENTS_PLAYER_SET)
|
|
|
|
{
|
|
|
|
h & players;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui8 playersMask = 0;
|
|
|
|
h & playersMask;
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
if ((playersMask & (1 << i)) != 0)
|
|
|
|
players.insert(PlayerColor(i));
|
|
|
|
}
|
2023-10-19 16:19:09 +02:00
|
|
|
h & humanAffected;
|
|
|
|
h & computerAffected;
|
2024-06-24 03:23:26 +02:00
|
|
|
h & firstOccurrence;
|
|
|
|
h & nextOccurrence;
|
2023-10-19 16:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void serializeJson(JsonSerializeFormat & handler);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The castle event builds/adds buildings/creatures for a specific town.
|
|
|
|
class DLL_LINKAGE CCastleEvent: public CMapEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCastleEvent() = default;
|
|
|
|
|
|
|
|
std::set<BuildingID> buildings;
|
|
|
|
std::vector<si32> creatures;
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
h & static_cast<CMapEvent &>(*this);
|
|
|
|
h & buildings;
|
|
|
|
h & creatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The terrain tile describes the terrain type and the visual representation of the terrain.
|
|
|
|
/// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
|
|
|
|
struct DLL_LINKAGE TerrainTile
|
|
|
|
{
|
|
|
|
TerrainTile();
|
|
|
|
|
|
|
|
/// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
|
|
|
|
bool entrableTerrain(const TerrainTile * from = nullptr) const;
|
|
|
|
bool entrableTerrain(bool allowLand, bool allowSea) const;
|
|
|
|
/// Checks for blocking objects and terraint type (water / land).
|
|
|
|
bool isClear(const TerrainTile * from = nullptr) const;
|
|
|
|
/// Gets the ID of the top visitable object or -1 if there is none.
|
|
|
|
Obj topVisitableId(bool excludeTop = false) const;
|
|
|
|
CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
|
|
|
|
bool isWater() const;
|
2024-07-13 20:37:13 +02:00
|
|
|
bool isLand() const;
|
|
|
|
EDiggingStatus getDiggingStatus(bool excludeTop = true) const;
|
2023-10-19 16:19:09 +02:00
|
|
|
bool hasFavorableWinds() const;
|
|
|
|
|
2024-07-13 20:37:13 +02:00
|
|
|
bool visitable() const;
|
|
|
|
bool blocked() const;
|
|
|
|
|
|
|
|
const TerrainType * getTerrain() const;
|
|
|
|
const RiverType * getRiver() const;
|
|
|
|
const RoadType * getRoad() const;
|
|
|
|
|
|
|
|
TerrainId getTerrainID() const;
|
|
|
|
RiverId getRiverID() const;
|
|
|
|
RoadId getRoadID() const;
|
|
|
|
|
|
|
|
bool hasRiver() const;
|
|
|
|
bool hasRoad() const;
|
|
|
|
|
|
|
|
TerrainId terrainType;
|
|
|
|
RiverId riverType;
|
|
|
|
RoadId roadType;
|
2024-07-07 14:53:29 +02:00
|
|
|
ui8 terView;
|
|
|
|
ui8 riverDir;
|
2023-10-19 16:19:09 +02:00
|
|
|
ui8 roadDir;
|
|
|
|
/// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
|
|
|
|
/// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
|
|
|
|
ui8 extTileFlags;
|
|
|
|
|
|
|
|
std::vector<CGObjectInstance *> visitableObjects;
|
|
|
|
std::vector<CGObjectInstance *> blockingObjects;
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
2024-10-14 14:54:17 +02:00
|
|
|
if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
|
|
|
|
{
|
|
|
|
h & terrainType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool isNull = false;
|
|
|
|
h & isNull;
|
|
|
|
if (isNull)
|
|
|
|
h & terrainType;
|
|
|
|
}
|
2024-07-13 20:37:13 +02:00
|
|
|
h & terrainType;
|
2023-10-19 16:19:09 +02:00
|
|
|
h & terView;
|
2024-10-14 14:54:17 +02:00
|
|
|
if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
|
|
|
|
{
|
|
|
|
h & riverType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool isNull = false;
|
|
|
|
h & isNull;
|
|
|
|
if (isNull)
|
|
|
|
h & riverType;
|
|
|
|
}
|
2023-10-19 16:19:09 +02:00
|
|
|
h & riverDir;
|
2024-10-14 14:54:17 +02:00
|
|
|
if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
|
|
|
|
{
|
|
|
|
h & roadType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool isNull = false;
|
|
|
|
h & isNull;
|
|
|
|
if (isNull)
|
|
|
|
h & roadType;
|
|
|
|
}
|
2023-10-19 16:19:09 +02:00
|
|
|
h & roadDir;
|
|
|
|
h & extTileFlags;
|
2024-10-14 14:54:17 +02:00
|
|
|
if (h.version < Handler::Version::REMOVE_VLC_POINTERS)
|
|
|
|
{
|
2024-10-30 19:03:48 +02:00
|
|
|
bool unused = false;
|
2024-10-14 14:54:17 +02:00
|
|
|
h & unused;
|
|
|
|
h & unused;
|
|
|
|
}
|
2023-10-19 16:19:09 +02:00
|
|
|
h & visitableObjects;
|
|
|
|
h & blockingObjects;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|