2023-05-24 00:14:06 +02:00
|
|
|
/*
|
|
|
|
* CMapHeader.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
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../constants/EntityIdentifiers.h"
|
|
|
|
#include "../constants/Enumerations.h"
|
2023-11-08 17:35:17 +02:00
|
|
|
#include "../constants/VariantIdentifier.h"
|
2024-05-07 21:17:05 +02:00
|
|
|
#include "../modding/ModVerificationInfo.h"
|
|
|
|
#include "../serializer/Serializeable.h"
|
2023-05-24 00:14:06 +02:00
|
|
|
#include "../LogicalExpression.h"
|
|
|
|
#include "../int3.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../texts/MetaString.h"
|
|
|
|
#include "../texts/TextLocalizationContainer.h"
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CGObjectInstance;
|
|
|
|
enum class EMapFormat : uint8_t;
|
|
|
|
|
|
|
|
/// The hero name struct consists of the hero id and the hero name.
|
|
|
|
struct DLL_LINKAGE SHeroName
|
|
|
|
{
|
|
|
|
SHeroName();
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID heroId;
|
2023-05-24 00:14:06 +02:00
|
|
|
std::string heroName;
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
|
|
|
h & heroId;
|
|
|
|
h & heroName;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The player info constains data about which factions are allowed, AI tactical settings,
|
|
|
|
/// the main hero name, where to generate the hero, whether the faction should be selected randomly,...
|
|
|
|
struct DLL_LINKAGE PlayerInfo
|
|
|
|
{
|
|
|
|
PlayerInfo();
|
|
|
|
|
|
|
|
/// Gets the default faction id or -1 for a random faction.
|
2023-09-28 18:43:04 +02:00
|
|
|
FactionID defaultCastle() const;
|
2023-05-24 00:14:06 +02:00
|
|
|
/// Gets the default hero id or -1 for a random hero.
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID defaultHero() const;
|
2023-05-24 00:14:06 +02:00
|
|
|
bool canAnyonePlay() const;
|
|
|
|
bool hasCustomMainHero() const;
|
|
|
|
|
|
|
|
bool canHumanPlay;
|
|
|
|
bool canComputerPlay;
|
2023-08-19 21:35:44 +02:00
|
|
|
EAiTactic aiTactic; /// The default value is EAiTactic::RANDOM.
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
std::set<FactionID> allowedFactions;
|
|
|
|
bool isFactionRandom;
|
|
|
|
|
|
|
|
///main hero instance (VCMI maps only)
|
|
|
|
std::string mainHeroInstance;
|
|
|
|
/// Player has a random main hero
|
|
|
|
bool hasRandomHero;
|
|
|
|
/// The default value is -1.
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID mainCustomHeroPortrait;
|
2023-09-28 00:04:05 +02:00
|
|
|
std::string mainCustomHeroNameTextId;
|
2023-05-24 00:14:06 +02:00
|
|
|
/// ID of custom hero (only if portrait and hero name are set, otherwise unpredicted value), -1 if none (not always -1)
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID mainCustomHeroId;
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
std::vector<SHeroName> heroesNames; /// list of placed heroes on the map
|
|
|
|
bool hasMainTown; /// The default value is false.
|
|
|
|
bool generateHeroAtMainTown; /// The default value is false.
|
|
|
|
int3 posOfMainTown;
|
|
|
|
TeamID team; /// The default value NO_TEAM
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
|
|
|
h & hasRandomHero;
|
|
|
|
h & mainCustomHeroId;
|
|
|
|
h & canHumanPlay;
|
|
|
|
h & canComputerPlay;
|
|
|
|
h & aiTactic;
|
|
|
|
h & allowedFactions;
|
|
|
|
h & isFactionRandom;
|
|
|
|
h & mainCustomHeroPortrait;
|
2023-09-28 00:04:05 +02:00
|
|
|
h & mainCustomHeroNameTextId;
|
2023-05-24 00:14:06 +02:00
|
|
|
h & heroesNames;
|
|
|
|
h & hasMainTown;
|
|
|
|
h & generateHeroAtMainTown;
|
|
|
|
h & posOfMainTown;
|
|
|
|
h & team;
|
|
|
|
h & mainHeroInstance;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The loss condition describes the condition to lose the game. (e.g. lose all own heroes/castles)
|
|
|
|
struct DLL_LINKAGE EventCondition
|
|
|
|
{
|
|
|
|
enum EWinLoseType {
|
|
|
|
HAVE_ARTIFACT, // type - required artifact
|
|
|
|
HAVE_CREATURES, // type - creatures to collect, value - amount to collect
|
|
|
|
HAVE_RESOURCES, // type - resource ID, value - amount to collect
|
|
|
|
HAVE_BUILDING, // position - town, optional, type - building to build
|
|
|
|
CONTROL, // position - position of object, optional, type - type of object
|
|
|
|
DESTROY, // position - position of object, optional, type - type of object
|
|
|
|
TRANSPORT, // position - where artifact should be transported, type - type of artifact
|
|
|
|
|
|
|
|
DAYS_PASSED, // value - number of days from start of the game
|
|
|
|
IS_HUMAN, // value - 0 = player is AI, 1 = player is human
|
|
|
|
DAYS_WITHOUT_TOWN, // value - how long player can live without town, 0=instakill
|
|
|
|
STANDARD_WIN, // normal defeat all enemies condition
|
|
|
|
CONST_VALUE, // condition that always evaluates to "value" (0 = false, 1 = true)
|
|
|
|
};
|
|
|
|
|
2023-11-08 17:35:17 +02:00
|
|
|
using TargetTypeID = VariantIdentifier<ArtifactID, CreatureID, GameResID, BuildingID, MapObjectID>;
|
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
EventCondition(EWinLoseType condition = STANDARD_WIN);
|
2023-11-08 17:35:17 +02:00
|
|
|
EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position = int3(-1, -1, -1));
|
2023-05-24 00:14:06 +02:00
|
|
|
|
2023-11-17 16:39:15 +02:00
|
|
|
ObjectInstanceID objectID; // object that was at specified position or with instance name on start
|
2023-05-24 00:14:06 +02:00
|
|
|
si32 value;
|
2023-11-08 17:35:17 +02:00
|
|
|
TargetTypeID objectType;
|
2023-05-24 00:14:06 +02:00
|
|
|
std::string objectInstanceName;
|
|
|
|
int3 position;
|
|
|
|
EWinLoseType condition;
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
2023-11-17 16:39:15 +02:00
|
|
|
h & objectID;
|
2023-05-24 00:14:06 +02:00
|
|
|
h & value;
|
|
|
|
h & objectType;
|
|
|
|
h & position;
|
|
|
|
h & condition;
|
|
|
|
h & objectInstanceName;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using EventExpression = LogicalExpression<EventCondition>;
|
|
|
|
|
|
|
|
struct DLL_LINKAGE EventEffect
|
|
|
|
{
|
|
|
|
enum EType
|
|
|
|
{
|
|
|
|
VICTORY,
|
|
|
|
DEFEAT
|
|
|
|
};
|
|
|
|
|
|
|
|
/// effect type, using EType enum
|
|
|
|
si8 type;
|
|
|
|
|
|
|
|
/// message that will be sent to other players
|
2023-06-18 12:51:11 +02:00
|
|
|
MetaString toOtherMessage;
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
|
|
|
h & type;
|
|
|
|
h & toOtherMessage;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE TriggeredEvent
|
|
|
|
{
|
|
|
|
/// base condition that must be evaluated
|
|
|
|
EventExpression trigger;
|
|
|
|
|
|
|
|
/// string identifier read from config file (e.g. captureKreelah)
|
|
|
|
std::string identifier;
|
|
|
|
|
|
|
|
/// string-description, for use in UI (capture town to win)
|
2023-06-18 12:51:11 +02:00
|
|
|
MetaString description;
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
/// Message that will be displayed when this event is triggered (You captured town. You won!)
|
2023-06-18 12:51:11 +02:00
|
|
|
MetaString onFulfill;
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
/// Effect of this event. TODO: refactor into something more flexible
|
|
|
|
EventEffect effect;
|
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
|
|
|
h & identifier;
|
|
|
|
h & trigger;
|
|
|
|
h & description;
|
|
|
|
h & onFulfill;
|
|
|
|
h & effect;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-05 21:27:55 +02:00
|
|
|
enum class EMapDifficulty : uint8_t
|
|
|
|
{
|
|
|
|
EASY = 0,
|
|
|
|
NORMAL = 1,
|
|
|
|
HARD = 2,
|
|
|
|
EXPERT = 3,
|
|
|
|
IMPOSSIBLE = 4
|
|
|
|
};
|
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
/// The map header holds information about loss/victory condition,map format, version, players, height, width,...
|
2024-05-07 21:17:05 +02:00
|
|
|
class DLL_LINKAGE CMapHeader: public Serializeable
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
|
|
|
void setupEvents();
|
|
|
|
public:
|
|
|
|
|
2024-06-13 05:38:15 +02:00
|
|
|
static constexpr int MAP_SIZE_SMALL = 36;
|
|
|
|
static constexpr int MAP_SIZE_MIDDLE = 72;
|
|
|
|
static constexpr int MAP_SIZE_LARGE = 108;
|
|
|
|
static constexpr int MAP_SIZE_XLARGE = 144;
|
|
|
|
static constexpr int MAP_SIZE_HUGE = 180;
|
|
|
|
static constexpr int MAP_SIZE_XHUGE = 216;
|
|
|
|
static constexpr int MAP_SIZE_GIANT = 252;
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
CMapHeader();
|
2023-09-28 02:52:49 +02:00
|
|
|
virtual ~CMapHeader();
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
ui8 levels() const;
|
|
|
|
|
|
|
|
EMapFormat version; /// The default value is EMapFormat::SOD.
|
|
|
|
ModCompatibilityInfo mods; /// set of mods required to play a map
|
|
|
|
|
|
|
|
si32 height; /// The default value is 72.
|
|
|
|
si32 width; /// The default value is 72.
|
|
|
|
bool twoLevel; /// The default value is true.
|
2023-09-27 22:53:13 +02:00
|
|
|
MetaString name;
|
|
|
|
MetaString description;
|
2024-02-05 21:27:55 +02:00
|
|
|
EMapDifficulty difficulty;
|
2024-06-29 13:13:59 +02:00
|
|
|
MetaString author;
|
|
|
|
MetaString authorContact;
|
|
|
|
MetaString mapVersion;
|
|
|
|
std::time_t creationDateTime;
|
2023-05-24 00:14:06 +02:00
|
|
|
/// Specifies the maximum level to reach for a hero. A value of 0 states that there is no
|
|
|
|
/// maximum level for heroes. This is the default value.
|
|
|
|
ui8 levelLimit;
|
|
|
|
|
2023-06-18 12:51:11 +02:00
|
|
|
MetaString victoryMessage;
|
|
|
|
MetaString defeatMessage;
|
2023-05-24 00:14:06 +02:00
|
|
|
ui16 victoryIconIndex;
|
|
|
|
ui16 defeatIconIndex;
|
|
|
|
|
|
|
|
std::vector<PlayerInfo> players; /// The default size of the vector is PlayerColor::PLAYER_LIMIT.
|
|
|
|
ui8 howManyTeams;
|
2023-11-05 15:24:26 +02:00
|
|
|
std::set<HeroTypeID> allowedHeroes;
|
2024-06-24 03:23:26 +02:00
|
|
|
std::set<HeroTypeID> reservedCampaignHeroes; /// Heroes that have placeholders in this map and are reserved for campaign
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
bool areAnyPlayers; /// Unused. True if there are any playable players on the map.
|
|
|
|
|
|
|
|
/// "main quests" of the map that describe victory and loss conditions
|
|
|
|
std::vector<TriggeredEvent> triggeredEvents;
|
2023-09-28 13:09:01 +02:00
|
|
|
|
|
|
|
/// translations for map to be transferred over network
|
|
|
|
JsonNode translations;
|
2024-01-15 13:10:25 +02:00
|
|
|
TextContainerRegistrable texts;
|
2023-09-28 13:09:01 +02:00
|
|
|
|
|
|
|
void registerMapStrings();
|
2023-05-24 00:14:06 +02:00
|
|
|
|
|
|
|
template <typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-05-24 00:14:06 +02:00
|
|
|
{
|
2024-01-15 13:10:25 +02:00
|
|
|
h & texts;
|
2023-05-24 00:14:06 +02:00
|
|
|
h & version;
|
2023-09-21 04:31:08 +02:00
|
|
|
h & mods;
|
2023-05-24 00:14:06 +02:00
|
|
|
h & name;
|
|
|
|
h & description;
|
2024-06-29 13:13:59 +02:00
|
|
|
if (h.version >= Handler::Version::MAP_FORMAT_ADDITIONAL_INFOS)
|
|
|
|
{
|
|
|
|
h & author;
|
|
|
|
h & authorContact;
|
|
|
|
h & mapVersion;
|
|
|
|
h & creationDateTime;
|
|
|
|
}
|
2023-05-24 00:14:06 +02:00
|
|
|
h & width;
|
|
|
|
h & height;
|
|
|
|
h & twoLevel;
|
2024-02-11 17:31:30 +02:00
|
|
|
// FIXME: we should serialize enum's according to their underlying type
|
2024-06-24 03:23:26 +02:00
|
|
|
// should be fixed when we are making breaking change to save compatibility
|
2024-02-11 17:31:30 +02:00
|
|
|
static_assert(Handler::Version::MINIMAL < Handler::Version::RELEASE_143);
|
|
|
|
uint8_t difficultyInteger = static_cast<uint8_t>(difficulty);
|
|
|
|
h & difficultyInteger;
|
|
|
|
difficulty = static_cast<EMapDifficulty>(difficultyInteger);
|
2023-05-24 00:14:06 +02:00
|
|
|
h & levelLimit;
|
|
|
|
h & areAnyPlayers;
|
|
|
|
h & players;
|
|
|
|
h & howManyTeams;
|
|
|
|
h & allowedHeroes;
|
2023-06-25 16:47:45 +02:00
|
|
|
h & reservedCampaignHeroes;
|
2023-05-24 00:14:06 +02:00
|
|
|
//Do not serialize triggeredEvents in header as they can contain information about heroes and armies
|
|
|
|
h & victoryMessage;
|
|
|
|
h & victoryIconIndex;
|
|
|
|
h & defeatMessage;
|
|
|
|
h & defeatIconIndex;
|
2023-09-28 13:09:01 +02:00
|
|
|
h & translations;
|
|
|
|
if(!h.saving)
|
|
|
|
registerMapStrings();
|
2023-05-24 00:14:06 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-28 14:38:31 +02:00
|
|
|
/// wrapper functions to register string into the map and stores its translation
|
2023-09-29 00:24:45 +02:00
|
|
|
std::string DLL_LINKAGE mapRegisterLocalizedString(const std::string & modContext, CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized);
|
|
|
|
std::string DLL_LINKAGE mapRegisterLocalizedString(const std::string & modContext, CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized, const std::string & language);
|
2023-09-28 14:38:31 +02:00
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|