1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*
* 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
#include "../constants/EntityIdentifiers.h"
#include "../constants/Enumerations.h"
#include "../constants/VariantIdentifier.h"
#include "../modding/ModVerificationInfo.h"
#include "../serializer/Serializeable.h"
#include "../LogicalExpression.h"
#include "../int3.h"
#include "../texts/MetaString.h"
#include "../texts/TextLocalizationContainer.h"
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();
HeroTypeID heroId;
std::string heroName;
template <typename Handler>
void serialize(Handler & h)
{
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.
FactionID defaultCastle() const;
/// Gets the default hero id or -1 for a random hero.
HeroTypeID defaultHero() const;
bool canAnyonePlay() const;
bool hasCustomMainHero() const;
bool canHumanPlay;
bool canComputerPlay;
EAiTactic aiTactic; /// The default value is EAiTactic::RANDOM.
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.
HeroTypeID mainCustomHeroPortrait;
std::string mainCustomHeroNameTextId;
/// ID of custom hero (only if portrait and hero name are set, otherwise unpredicted value), -1 if none (not always -1)
HeroTypeID mainCustomHeroId;
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>
void serialize(Handler & h)
{
h & hasRandomHero;
h & mainCustomHeroId;
h & canHumanPlay;
h & canComputerPlay;
h & aiTactic;
h & allowedFactions;
h & isFactionRandom;
h & mainCustomHeroPortrait;
h & mainCustomHeroNameTextId;
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)
};
using TargetTypeID = VariantIdentifier<ArtifactID, CreatureID, GameResID, BuildingID, MapObjectID>;
EventCondition(EWinLoseType condition = STANDARD_WIN);
EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position = int3(-1, -1, -1));
ObjectInstanceID objectID; // object that was at specified position or with instance name on start
si32 value;
TargetTypeID objectType;
std::string objectInstanceName;
int3 position;
EWinLoseType condition;
template <typename Handler>
void serialize(Handler & h)
{
h & objectID;
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
MetaString toOtherMessage;
template <typename Handler>
void serialize(Handler & h)
{
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)
MetaString description;
/// Message that will be displayed when this event is triggered (You captured town. You won!)
MetaString onFulfill;
/// Effect of this event. TODO: refactor into something more flexible
EventEffect effect;
template <typename Handler>
void serialize(Handler & h)
{
h & identifier;
h & trigger;
h & description;
h & onFulfill;
h & effect;
}
};
enum class EMapDifficulty : uint8_t
{
EASY = 0,
NORMAL = 1,
HARD = 2,
EXPERT = 3,
IMPOSSIBLE = 4
};
/// The map header holds information about loss/victory condition,map format, version, players, height, width,...
class DLL_LINKAGE CMapHeader: public Serializeable
{
void setupEvents();
public:
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;
CMapHeader();
virtual ~CMapHeader();
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.
MetaString name;
MetaString description;
EMapDifficulty difficulty;
MetaString author;
MetaString authorContact;
MetaString mapVersion;
std::time_t creationDateTime;
/// 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;
MetaString victoryMessage;
MetaString defeatMessage;
ui16 victoryIconIndex;
ui16 defeatIconIndex;
std::vector<PlayerInfo> players; /// The default size of the vector is PlayerColor::PLAYER_LIMIT.
ui8 howManyTeams;
std::set<HeroTypeID> allowedHeroes;
std::set<HeroTypeID> reservedCampaignHeroes; /// Heroes that have placeholders in this map and are reserved for campaign
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;
/// translations for map to be transferred over network
JsonNode translations;
TextContainerRegistrable texts;
void registerMapStrings();
template <typename Handler>
void serialize(Handler & h)
{
h & texts;
h & version;
h & mods;
h & name;
h & description;
if (h.version >= Handler::Version::MAP_FORMAT_ADDITIONAL_INFOS)
{
h & author;
h & authorContact;
h & mapVersion;
h & creationDateTime;
}
h & width;
h & height;
h & twoLevel;
if (h.version >= Handler::Version::SAVE_COMPATIBILITY_FIXES)
h & difficulty;
else
{
uint8_t difficultyInteger = static_cast<uint8_t>(difficulty);
h & difficultyInteger;
difficulty = static_cast<EMapDifficulty>(difficultyInteger);
}
h & levelLimit;
h & areAnyPlayers;
h & players;
h & howManyTeams;
h & allowedHeroes;
h & reservedCampaignHeroes;
//Do not serialize triggeredEvents in header as they can contain information about heroes and armies
h & victoryMessage;
h & victoryIconIndex;
h & defeatMessage;
h & defeatIconIndex;
h & translations;
if(!h.saving)
registerMapStrings();
}
};
/// wrapper functions to register string into the map and stores its translation
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);
VCMI_LIB_NAMESPACE_END
|