EntityIdentifiers.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /*
  2. * EntityIdentifiers.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "Global.h"
  12. #include "NumericConstants.h"
  13. #include "IdentifierBase.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class Services;
  16. class Artifact;
  17. class ArtifactService;
  18. class Creature;
  19. class CreatureService;
  20. class HeroType;
  21. class CHero;
  22. class CHeroClass;
  23. class HeroClass;
  24. class HeroTypeService;
  25. class Resource;
  26. class ResourceType;
  27. class ResourceTypeService;
  28. class CFaction;
  29. class Faction;
  30. class Skill;
  31. class RoadType;
  32. class RiverType;
  33. class TerrainType;
  34. class MapLayerType;
  35. namespace spells
  36. {
  37. class Spell;
  38. class Service;
  39. }
  40. class CArtifact;
  41. class CArtifactInstance;
  42. class CCreature;
  43. class CHero;
  44. class CSpell;
  45. class CSkill;
  46. class IGameInfoCallback;
  47. class CNonConstInfoCallback;
  48. class ArtifactInstanceID : public StaticIdentifier<ArtifactInstanceID>
  49. {
  50. public:
  51. using StaticIdentifier<ArtifactInstanceID>::StaticIdentifier;
  52. DLL_LINKAGE static std::string encode(const si32 index);
  53. };
  54. class QueryID : public StaticIdentifier<QueryID>
  55. {
  56. public:
  57. using StaticIdentifier<QueryID>::StaticIdentifier;
  58. DLL_LINKAGE static const QueryID NONE;
  59. DLL_LINKAGE static const QueryID CLIENT;
  60. };
  61. class BattleID : public StaticIdentifier<BattleID>
  62. {
  63. public:
  64. using StaticIdentifier<BattleID>::StaticIdentifier;
  65. DLL_LINKAGE static const BattleID NONE;
  66. };
  67. class DLL_LINKAGE ObjectInstanceID : public StaticIdentifier<ObjectInstanceID>
  68. {
  69. public:
  70. using StaticIdentifier<ObjectInstanceID>::StaticIdentifier;
  71. static const ObjectInstanceID NONE;
  72. static si32 decode(const std::string & identifier);
  73. static std::string encode(const si32 index);
  74. };
  75. class DLL_LINKAGE QuestInstanceID : public StaticIdentifier<QuestInstanceID>
  76. {
  77. public:
  78. using StaticIdentifier<QuestInstanceID>::StaticIdentifier;
  79. static const QuestInstanceID NONE;
  80. static si32 decode(const std::string & identifier);
  81. static std::string encode(const si32 index);
  82. };
  83. class HeroClassID : public EntityIdentifier<HeroClassID>
  84. {
  85. public:
  86. using EntityIdentifier<HeroClassID>::EntityIdentifier;
  87. ///json serialization helpers
  88. DLL_LINKAGE static si32 decode(const std::string & identifier);
  89. DLL_LINKAGE static std::string encode(const si32 index);
  90. static std::string entityType();
  91. const CHeroClass * toHeroClass() const;
  92. const HeroClass * toEntity(const Services * services) const;
  93. };
  94. class DLL_LINKAGE HeroTypeID : public EntityIdentifier<HeroTypeID>
  95. {
  96. public:
  97. using EntityIdentifier<HeroTypeID>::EntityIdentifier;
  98. ///json serialization helpers
  99. static si32 decode(const std::string & identifier);
  100. static std::string encode(const si32 index);
  101. static std::string entityType();
  102. const CHero * toHeroType() const;
  103. const HeroType * toEntity(const Services * services) const;
  104. static const HeroTypeID NONE;
  105. static const HeroTypeID RANDOM;
  106. static const HeroTypeID CAMP_STRONGEST;
  107. static const HeroTypeID CAMP_GENERATED;
  108. static const HeroTypeID CAMP_RANDOM;
  109. bool isValid() const
  110. {
  111. return getNum() >= 0;
  112. }
  113. };
  114. class SlotID : public StaticIdentifier<SlotID>
  115. {
  116. public:
  117. using StaticIdentifier<SlotID>::StaticIdentifier;
  118. DLL_LINKAGE static const SlotID COMMANDER_SLOT_PLACEHOLDER;
  119. DLL_LINKAGE static const SlotID SUMMONED_SLOT_PLACEHOLDER; ///<for all summoned creatures, only during battle
  120. DLL_LINKAGE static const SlotID WAR_MACHINES_SLOT; ///<for all war machines during battle
  121. DLL_LINKAGE static const SlotID ARROW_TOWERS_SLOT; ///<for all arrow towers during battle
  122. bool validSlot() const
  123. {
  124. return getNum() >= 0 && getNum() < GameConstants::ARMY_SIZE;
  125. }
  126. };
  127. class DLL_LINKAGE PlayerColor : public StaticIdentifier<PlayerColor>
  128. {
  129. public:
  130. using StaticIdentifier<PlayerColor>::StaticIdentifier;
  131. enum EPlayerColor
  132. {
  133. PLAYER_LIMIT_I = 8,
  134. };
  135. static const PlayerColor SPECTATOR; //252
  136. static const PlayerColor CANNOT_DETERMINE; //253
  137. static const PlayerColor UNFLAGGABLE; //254 - neutral objects (pandora, banks)
  138. static const PlayerColor NEUTRAL; //255
  139. static const PlayerColor PLAYER_LIMIT; //player limit per map
  140. static const std::array<PlayerColor, PLAYER_LIMIT_I> & ALL_PLAYERS();
  141. bool isValidPlayer() const; //valid means < PLAYER_LIMIT (especially non-neutral)
  142. bool isSpectator() const;
  143. std::string toString() const;
  144. static si32 decode(const std::string& identifier);
  145. static std::string encode(const si32 index);
  146. static std::string entityType();
  147. };
  148. class TeamID : public StaticIdentifier<TeamID>
  149. {
  150. public:
  151. using StaticIdentifier<TeamID>::StaticIdentifier;
  152. DLL_LINKAGE static const TeamID NO_TEAM;
  153. };
  154. class TeleportChannelID : public StaticIdentifier<TeleportChannelID>
  155. {
  156. public:
  157. using StaticIdentifier<TeleportChannelID>::StaticIdentifier;
  158. };
  159. class SecondarySkillBase : public IdentifierBase
  160. {
  161. public:
  162. enum Type : int32_t
  163. {
  164. NONE = -1,
  165. PATHFINDING = 0,
  166. ARCHERY,
  167. LOGISTICS,
  168. SCOUTING,
  169. DIPLOMACY,
  170. NAVIGATION,
  171. LEADERSHIP,
  172. WISDOM,
  173. MYSTICISM,
  174. LUCK,
  175. BALLISTICS,
  176. EAGLE_EYE,
  177. NECROMANCY,
  178. ESTATES,
  179. FIRE_MAGIC,
  180. AIR_MAGIC,
  181. WATER_MAGIC,
  182. EARTH_MAGIC,
  183. SCHOLAR,
  184. TACTICS,
  185. ARTILLERY,
  186. LEARNING,
  187. OFFENCE,
  188. ARMORER,
  189. INTELLIGENCE,
  190. SORCERY,
  191. RESISTANCE,
  192. FIRST_AID,
  193. SKILL_SIZE
  194. };
  195. static_assert(GameConstants::SKILL_QUANTITY == SKILL_SIZE, "Incorrect number of skills");
  196. };
  197. class DLL_LINKAGE SecondarySkill : public EntityIdentifierWithEnum<SecondarySkill, SecondarySkillBase>
  198. {
  199. public:
  200. using EntityIdentifierWithEnum<SecondarySkill, SecondarySkillBase>::EntityIdentifierWithEnum;
  201. static std::string entityType();
  202. static si32 decode(const std::string& identifier);
  203. static std::string encode(const si32 index);
  204. const CSkill * toSkill() const;
  205. const Skill * toEntity(const Services * services) const;
  206. };
  207. class DLL_LINKAGE PrimarySkill : public StaticIdentifier<PrimarySkill>
  208. {
  209. public:
  210. using StaticIdentifier<PrimarySkill>::StaticIdentifier;
  211. static const PrimarySkill NONE;
  212. static const PrimarySkill ATTACK;
  213. static const PrimarySkill DEFENSE;
  214. static const PrimarySkill SPELL_POWER;
  215. static const PrimarySkill KNOWLEDGE;
  216. static const std::array<PrimarySkill, 4> & ALL_SKILLS();
  217. static si32 decode(const std::string& identifier);
  218. static std::string encode(const si32 index);
  219. static std::string entityType();
  220. };
  221. class DLL_LINKAGE FactionID : public EntityIdentifier<FactionID>
  222. {
  223. public:
  224. using EntityIdentifier<FactionID>::EntityIdentifier;
  225. static const FactionID NONE;
  226. static const FactionID DEFAULT;
  227. static const FactionID RANDOM;
  228. static const FactionID ANY;
  229. static const FactionID CASTLE;
  230. static const FactionID RAMPART;
  231. static const FactionID TOWER;
  232. static const FactionID INFERNO;
  233. static const FactionID NECROPOLIS;
  234. static const FactionID DUNGEON;
  235. static const FactionID STRONGHOLD;
  236. static const FactionID FORTRESS;
  237. static const FactionID CONFLUX;
  238. static const FactionID NEUTRAL;
  239. static si32 decode(const std::string& identifier);
  240. static std::string encode(const si32 index);
  241. const CFaction * toFaction() const;
  242. const Faction * toEntity(const Services * service) const;
  243. static std::string entityType();
  244. bool isValid() const
  245. {
  246. return getNum() >= 0;
  247. }
  248. };
  249. class BuildingIDBase : public IdentifierBase
  250. {
  251. public:
  252. // Quite useful as long as most of building mechanics hardcoded
  253. // NOTE: all building with completely configurable mechanics will be removed from list
  254. enum Type
  255. {
  256. DEFAULT = -50,
  257. HORDE_PLACEHOLDER8 = -37,
  258. HORDE_PLACEHOLDER7 = -36,
  259. HORDE_PLACEHOLDER6 = -35,
  260. HORDE_PLACEHOLDER5 = -34,
  261. HORDE_PLACEHOLDER4 = -33,
  262. HORDE_PLACEHOLDER3 = -32,
  263. HORDE_PLACEHOLDER2 = -31,
  264. HORDE_PLACEHOLDER1 = -30,
  265. NONE = -1,
  266. FIRST_REGULAR_ID = 0,
  267. MAGES_GUILD_1 = 0, MAGES_GUILD_2, MAGES_GUILD_3, MAGES_GUILD_4, MAGES_GUILD_5,
  268. TAVERN, SHIPYARD, FORT, CITADEL, CASTLE,
  269. VILLAGE_HALL, TOWN_HALL, CITY_HALL, CAPITOL, MARKETPLACE,
  270. RESOURCE_SILO, BLACKSMITH, SPECIAL_1, HORDE_1, HORDE_1_UPGR,
  271. SHIP, SPECIAL_2, SPECIAL_3, SPECIAL_4, HORDE_2,
  272. HORDE_2_UPGR, GRAIL, EXTRA_TOWN_HALL, EXTRA_CITY_HALL, EXTRA_CAPITOL,
  273. DWELL_LVL_1=30, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LVL_7=36,
  274. DWELL_LVL_1_UP=37, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, DWELL_LVL_6_UP, DWELL_LVL_7_UP=43,
  275. DWELL_LVL_1_UP2, DWELL_LVL_2_UP2, DWELL_LVL_3_UP2, DWELL_LVL_4_UP2, DWELL_LVL_5_UP2, DWELL_LVL_6_UP2, DWELL_LVL_7_UP2,
  276. DWELL_LVL_1_UP3, DWELL_LVL_2_UP3, DWELL_LVL_3_UP3, DWELL_LVL_4_UP3, DWELL_LVL_5_UP3, DWELL_LVL_6_UP3, DWELL_LVL_7_UP3,
  277. DWELL_LVL_1_UP4, DWELL_LVL_2_UP4, DWELL_LVL_3_UP4, DWELL_LVL_4_UP4, DWELL_LVL_5_UP4, DWELL_LVL_6_UP4, DWELL_LVL_7_UP4,
  278. DWELL_LVL_1_UP5, DWELL_LVL_2_UP5, DWELL_LVL_3_UP5, DWELL_LVL_4_UP5, DWELL_LVL_5_UP5, DWELL_LVL_6_UP5, DWELL_LVL_7_UP5,
  279. //150-155 reserved for 8. creature with potential upgrades
  280. DWELL_LVL_8=150, DWELL_LVL_8_UP=151, DWELL_LVL_8_UP2 = 152, DWELL_LVL_8_UP3 = 153, DWELL_LVL_8_UP4 = 154, DWELL_LVL_8_UP5 = 155,
  281. };
  282. };
  283. class DLL_LINKAGE BuildingID : public StaticIdentifierWithEnum<BuildingID, BuildingIDBase>
  284. {
  285. static std::array<std::array<BuildingID, 8>, 6> getDwellings()
  286. {
  287. static const std::array<std::array<BuildingID, 8>, 6> allDwellings = {{
  288. { DWELL_LVL_1, DWELL_LVL_2, DWELL_LVL_3, DWELL_LVL_4, DWELL_LVL_5, DWELL_LVL_6, DWELL_LVL_7, DWELL_LVL_8 },
  289. { DWELL_LVL_1_UP, DWELL_LVL_2_UP, DWELL_LVL_3_UP, DWELL_LVL_4_UP, DWELL_LVL_5_UP, DWELL_LVL_6_UP, DWELL_LVL_7_UP, DWELL_LVL_8_UP },
  290. { DWELL_LVL_1_UP2, DWELL_LVL_2_UP2, DWELL_LVL_3_UP2, DWELL_LVL_4_UP2, DWELL_LVL_5_UP2, DWELL_LVL_6_UP2, DWELL_LVL_7_UP2, DWELL_LVL_8_UP2 },
  291. { DWELL_LVL_1_UP3, DWELL_LVL_2_UP3, DWELL_LVL_3_UP3, DWELL_LVL_4_UP3, DWELL_LVL_5_UP3, DWELL_LVL_6_UP3, DWELL_LVL_7_UP3, DWELL_LVL_8_UP3 },
  292. { DWELL_LVL_1_UP4, DWELL_LVL_2_UP4, DWELL_LVL_3_UP4, DWELL_LVL_4_UP4, DWELL_LVL_5_UP4, DWELL_LVL_6_UP4, DWELL_LVL_7_UP4, DWELL_LVL_8_UP4 },
  293. { DWELL_LVL_1_UP5, DWELL_LVL_2_UP5, DWELL_LVL_3_UP5, DWELL_LVL_4_UP5, DWELL_LVL_5_UP5, DWELL_LVL_6_UP5, DWELL_LVL_7_UP5, DWELL_LVL_8_UP5 }
  294. }};
  295. return allDwellings;
  296. }
  297. public:
  298. using StaticIdentifierWithEnum<BuildingID, BuildingIDBase>::StaticIdentifierWithEnum;
  299. static BuildingID HALL_LEVEL(unsigned int level)
  300. {
  301. assert(level < 4);
  302. return BuildingID(Type::VILLAGE_HALL + level);
  303. }
  304. static BuildingID FORT_LEVEL(unsigned int level)
  305. {
  306. assert(level < 3);
  307. return BuildingID(Type::FORT + level);
  308. }
  309. static std::string encode(int32_t index);
  310. static si32 decode(const std::string & identifier);
  311. int getMagesGuildLevel() const
  312. {
  313. switch (toEnum())
  314. {
  315. case Type::MAGES_GUILD_1: return 1;
  316. case Type::MAGES_GUILD_2: return 2;
  317. case Type::MAGES_GUILD_3: return 3;
  318. case Type::MAGES_GUILD_4: return 4;
  319. case Type::MAGES_GUILD_5: return 5;
  320. }
  321. throw std::runtime_error("Call to getMageGuildLevel with building '" + std::to_string(getNum()) +"' that is not mages guild!");
  322. }
  323. static BuildingID getDwellingFromLevel(const int levelIndex, const int upgradeIndex)
  324. {
  325. if (upgradeIndex >= getDwellings().size() || levelIndex >= getDwellings()[upgradeIndex].size())
  326. return Type::NONE;
  327. return getDwellings().at(upgradeIndex).at(levelIndex);
  328. }
  329. /// @return 0 for the first one, going up to the supported no. of dwellings - 1
  330. static int getLevelIndexFromDwelling(BuildingID dwelling)
  331. {
  332. for (const auto & level : getDwellings())
  333. {
  334. auto it = std::find(level.begin(), level.end(), dwelling);
  335. if (it != level.end())
  336. return std::distance(level.begin(), it);
  337. }
  338. throw std::runtime_error("Call to getLevelFromDwelling with building '" + std::to_string(dwelling.num) +"' that is not dwelling!");
  339. }
  340. /// @return 0 for no upgrade, 1 for the first one, going up to the supported no. of upgrades
  341. static int getUpgradeNoFromDwelling(BuildingID dwelling)
  342. {
  343. const auto & dwellings = getDwellings();
  344. for(int i = 0; i < dwellings.size(); i++)
  345. {
  346. if (vstd::contains(dwellings[i], dwelling))
  347. return i;
  348. }
  349. throw std::runtime_error("Call to getUpgradedFromDwelling with building '" + std::to_string(dwelling.num) +"' that is not dwelling!");
  350. }
  351. static void advanceDwelling(BuildingID & dwelling)
  352. {
  353. int levelIndex = getLevelIndexFromDwelling(dwelling);
  354. int upgradeNo = getUpgradeNoFromDwelling(dwelling);
  355. dwelling = getDwellingFromLevel(levelIndex, upgradeNo + 1);
  356. }
  357. bool isDwelling() const
  358. {
  359. for (const auto & level : getDwellings())
  360. {
  361. if (vstd::contains(level, BuildingID(num)))
  362. return true;
  363. }
  364. return false;
  365. }
  366. };
  367. class MapObjectBaseID : public IdentifierBase
  368. {
  369. public:
  370. enum Type
  371. {
  372. NO_OBJ = -1,
  373. NOTHING = 0,
  374. ALTAR_OF_SACRIFICE = 2,
  375. ANCHOR_POINT = 3,
  376. ARENA = 4,
  377. ARTIFACT = 5,
  378. PANDORAS_BOX = 6,
  379. BLACK_MARKET = 7,
  380. BOAT = 8,
  381. BORDERGUARD = 9,
  382. KEYMASTER = 10,
  383. BUOY = 11,
  384. CAMPFIRE = 12,
  385. CARTOGRAPHER = 13,
  386. SWAN_POND = 14,
  387. COVER_OF_DARKNESS = 15,
  388. CREATURE_BANK = 16,
  389. CREATURE_GENERATOR1 = 17,
  390. CREATURE_GENERATOR2 = 18,
  391. CREATURE_GENERATOR3 = 19,
  392. CREATURE_GENERATOR4 = 20,
  393. CURSED_GROUND1 = 21,
  394. CORPSE = 22,
  395. MARLETTO_TOWER = 23,
  396. DERELICT_SHIP = 24,
  397. DRAGON_UTOPIA = 25,
  398. EVENT = 26,
  399. EYE_OF_MAGI = 27,
  400. FAERIE_RING = 28,
  401. FLOTSAM = 29,
  402. FOUNTAIN_OF_FORTUNE = 30,
  403. FOUNTAIN_OF_YOUTH = 31,
  404. GARDEN_OF_REVELATION = 32,
  405. GARRISON = 33,
  406. HERO = 34,
  407. HILL_FORT = 35,
  408. GRAIL = 36,
  409. HUT_OF_MAGI = 37,
  410. IDOL_OF_FORTUNE = 38,
  411. LEAN_TO = 39,
  412. LIBRARY_OF_ENLIGHTENMENT = 41,
  413. LIGHTHOUSE = 42,
  414. MONOLITH_ONE_WAY_ENTRANCE = 43,
  415. MONOLITH_ONE_WAY_EXIT = 44,
  416. MONOLITH_TWO_WAY = 45,
  417. MAGIC_PLAINS1 = 46,
  418. SCHOOL_OF_MAGIC = 47,
  419. MAGIC_SPRING = 48,
  420. MAGIC_WELL = 49,
  421. MARKET_OF_TIME = 50,
  422. MERCENARY_CAMP = 51,
  423. MERMAID = 52,
  424. MINE = 53,
  425. MONSTER = 54,
  426. MYSTICAL_GARDEN = 55,
  427. OASIS = 56,
  428. OBELISK = 57,
  429. REDWOOD_OBSERVATORY = 58,
  430. OCEAN_BOTTLE = 59,
  431. PILLAR_OF_FIRE = 60,
  432. STAR_AXIS = 61,
  433. PRISON = 62,
  434. PYRAMID = 63,//subtype 0
  435. WOG_OBJECT = 63,//subtype > 0
  436. RALLY_FLAG = 64,
  437. RANDOM_ART = 65,
  438. RANDOM_TREASURE_ART = 66,
  439. RANDOM_MINOR_ART = 67,
  440. RANDOM_MAJOR_ART = 68,
  441. RANDOM_RELIC_ART = 69,
  442. RANDOM_HERO = 70,
  443. RANDOM_MONSTER = 71,
  444. RANDOM_MONSTER_L1 = 72,
  445. RANDOM_MONSTER_L2 = 73,
  446. RANDOM_MONSTER_L3 = 74,
  447. RANDOM_MONSTER_L4 = 75,
  448. RANDOM_RESOURCE = 76,
  449. RANDOM_TOWN = 77,
  450. REFUGEE_CAMP = 78,
  451. RESOURCE = 79,
  452. SANCTUARY = 80,
  453. SCHOLAR = 81,
  454. SEA_CHEST = 82,
  455. SEER_HUT = 83,
  456. CRYPT = 84,
  457. SHIPWRECK = 85,
  458. SHIPWRECK_SURVIVOR = 86,
  459. SHIPYARD = 87,
  460. SHRINE_OF_MAGIC_INCANTATION = 88,
  461. SHRINE_OF_MAGIC_GESTURE = 89,
  462. SHRINE_OF_MAGIC_THOUGHT = 90,
  463. SIGN = 91,
  464. SIRENS = 92,
  465. SPELL_SCROLL = 93,
  466. STABLES = 94,
  467. TAVERN = 95,
  468. TEMPLE = 96,
  469. DEN_OF_THIEVES = 97,
  470. TOWN = 98,
  471. TRADING_POST = 99,
  472. LEARNING_STONE = 100,
  473. TREASURE_CHEST = 101,
  474. TREE_OF_KNOWLEDGE = 102,
  475. SUBTERRANEAN_GATE = 103,
  476. UNIVERSITY = 104,
  477. WAGON = 105,
  478. WAR_MACHINE_FACTORY = 106,
  479. SCHOOL_OF_WAR = 107,
  480. WARRIORS_TOMB = 108,
  481. WATER_WHEEL = 109,
  482. WATERING_HOLE = 110,
  483. WHIRLPOOL = 111,
  484. WINDMILL = 112,
  485. WITCH_HUT = 113,
  486. BRUSH = 114, // TODO: How does it look like?
  487. BUSH = 115,
  488. CACTUS = 116,
  489. CANYON = 117,
  490. CRATER = 118,
  491. DEAD_VEGETATION = 119,
  492. FLOWERS = 120,
  493. FROZEN_LAKE = 121,
  494. HEDGE = 122,
  495. HILL = 123,
  496. HOLE = 124,
  497. KELP = 125,
  498. LAKE = 126,
  499. LAVA_FLOW = 127,
  500. LAVA_LAKE = 128,
  501. MUSHROOMS = 129,
  502. LOG = 130,
  503. MANDRAKE = 131,
  504. MOSS = 132,
  505. MOUND = 133,
  506. MOUNTAIN = 134,
  507. OAK_TREES = 135,
  508. OUTCROPPING = 136,
  509. PINE_TREES = 137,
  510. PLANT = 138,
  511. RIVER_DELTA = 143,
  512. HOTA_CUSTOM_OBJECT_3 = 144,
  513. HOTA_CUSTOM_OBJECT_1 = 145,
  514. HOTA_CUSTOM_OBJECT_2 = 146,
  515. ROCK = 147,
  516. SAND_DUNE = 148,
  517. SAND_PIT = 149,
  518. SHRUB = 150,
  519. SKULL = 151,
  520. STALAGMITE = 152,
  521. STUMP = 153,
  522. TAR_PIT = 154,
  523. TREES = 155,
  524. VINE = 156,
  525. VOLCANIC_VENT = 157,
  526. VOLCANO = 158,
  527. WILLOW_TREES = 159,
  528. YUCCA_TREES = 160,
  529. REEF = 161,
  530. RANDOM_MONSTER_L5 = 162,
  531. RANDOM_MONSTER_L6 = 163,
  532. RANDOM_MONSTER_L7 = 164,
  533. BORDER_GATE = 212,
  534. FREELANCERS_GUILD = 213,
  535. HERO_PLACEHOLDER = 214,
  536. QUEST_GUARD = 215,
  537. RANDOM_DWELLING = 216,
  538. RANDOM_DWELLING_LVL = 217, //subtype = creature level
  539. RANDOM_DWELLING_FACTION = 218, //subtype = faction
  540. GARRISON2 = 219,
  541. ABANDONED_MINE = 220,
  542. TRADING_POST_SNOW = 221,
  543. CLOVER_FIELD = 222,
  544. CURSED_GROUND2 = 223,
  545. EVIL_FOG = 224,
  546. FAVORABLE_WINDS = 225,
  547. FIERY_FIELDS = 226,
  548. HOLY_GROUNDS = 227,
  549. LUCID_POOLS = 228,
  550. MAGIC_CLOUDS = 229,
  551. MAGIC_PLAINS2 = 230,
  552. ROCKLANDS = 231,
  553. };
  554. };
  555. class DLL_LINKAGE MapObjectID : public EntityIdentifierWithEnum<MapObjectID, MapObjectBaseID>
  556. {
  557. public:
  558. using EntityIdentifierWithEnum<MapObjectID, MapObjectBaseID>::EntityIdentifierWithEnum;
  559. static std::string encode(int32_t index);
  560. static si32 decode(const std::string & identifier);
  561. // TODO: Remove
  562. constexpr operator int32_t () const
  563. {
  564. return num;
  565. }
  566. };
  567. class DLL_LINKAGE MapObjectSubID : public Identifier<MapObjectSubID>
  568. {
  569. public:
  570. constexpr MapObjectSubID(const IdentifierBase & value):
  571. Identifier<MapObjectSubID>(value.getNum())
  572. {}
  573. constexpr MapObjectSubID(int32_t value = -1):
  574. Identifier<MapObjectSubID>(value)
  575. {}
  576. MapObjectSubID & operator =(int32_t value)
  577. {
  578. this->num = value;
  579. return *this;
  580. }
  581. MapObjectSubID & operator =(const IdentifierBase & value)
  582. {
  583. this->num = value.getNum();
  584. return *this;
  585. }
  586. static si32 decode(MapObjectID primaryID, const std::string & identifier);
  587. static std::string encode(MapObjectID primaryID, si32 index);
  588. // TODO: Remove
  589. constexpr operator int32_t () const
  590. {
  591. return num;
  592. }
  593. template <typename Handler>
  594. void serializeIdentifier(Handler &h, const MapObjectID & primaryID)
  595. {
  596. std::string secondaryStringID;
  597. if (h.saving)
  598. secondaryStringID = encode(primaryID, num);
  599. h & secondaryStringID;
  600. if (!h.saving)
  601. num = decode(primaryID, secondaryStringID);
  602. }
  603. };
  604. class DLL_LINKAGE MapLayerId : public EntityIdentifier<MapLayerId>
  605. {
  606. public:
  607. using EntityIdentifier<MapLayerId>::EntityIdentifier;
  608. static si32 decode(const std::string & identifier);
  609. static std::string encode(const si32 index);
  610. static std::string entityType();
  611. static const MapLayerId NONE;
  612. static const MapLayerId SURFACE;
  613. static const MapLayerId UNDERGROUND;
  614. static const MapLayerId UNKNOWN;
  615. const MapLayerType * toEntity(const Services * service) const;
  616. };
  617. class DLL_LINKAGE RoadId : public EntityIdentifier<RoadId>
  618. {
  619. public:
  620. using EntityIdentifier<RoadId>::EntityIdentifier;
  621. static si32 decode(const std::string & identifier);
  622. static std::string encode(const si32 index);
  623. static std::string entityType();
  624. static const RoadId NO_ROAD;
  625. static const RoadId DIRT_ROAD;
  626. static const RoadId GRAVEL_ROAD;
  627. static const RoadId COBBLESTONE_ROAD;
  628. const RoadType * toEntity(const Services * service) const;
  629. };
  630. class DLL_LINKAGE RiverId : public EntityIdentifier<RiverId>
  631. {
  632. public:
  633. using EntityIdentifier<RiverId>::EntityIdentifier;
  634. static si32 decode(const std::string & identifier);
  635. static std::string encode(const si32 index);
  636. static std::string entityType();
  637. static const RiverId NO_RIVER;
  638. static const RiverId WATER_RIVER;
  639. static const RiverId ICY_RIVER;
  640. static const RiverId MUD_RIVER;
  641. static const RiverId LAVA_RIVER;
  642. const RiverType * toEntity(const Services * service) const;
  643. };
  644. class DLL_LINKAGE EPathfindingLayerBase : public IdentifierBase
  645. {
  646. public:
  647. enum Type : int32_t
  648. {
  649. LAND = 0, SAIL = 1, WATER, AIR, NUM_LAYERS, WRONG, AUTO
  650. };
  651. };
  652. class EPathfindingLayer : public StaticIdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>
  653. {
  654. public:
  655. using StaticIdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>::StaticIdentifierWithEnum;
  656. };
  657. class ArtifactPositionBase : public IdentifierBase
  658. {
  659. public:
  660. enum Type
  661. {
  662. TRANSITION_POS = -3,
  663. FIRST_AVAILABLE = -2,
  664. PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack
  665. // Hero
  666. HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5
  667. RIGHT_RING, LEFT_RING, FEET, //8
  668. MISC1, MISC2, MISC3, MISC4, //12
  669. MACH1, MACH2, MACH3, MACH4, //16
  670. SPELLBOOK, MISC5, //18
  671. BACKPACK_START = 19,
  672. // Creatures
  673. CREATURE_SLOT = 0,
  674. // Commander
  675. COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6, COMMANDER7, COMMANDER8, COMMANDER9,
  676. // Altar
  677. ALTAR = BACKPACK_START
  678. };
  679. static_assert(MISC5 < BACKPACK_START, "incorrect number of artifact slots");
  680. DLL_LINKAGE static si32 decode(const std::string & identifier);
  681. DLL_LINKAGE static std::string encode(const si32 index);
  682. DLL_LINKAGE static std::string entityType();
  683. };
  684. class ArtifactPosition : public StaticIdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>
  685. {
  686. public:
  687. using StaticIdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>::StaticIdentifierWithEnum;
  688. // TODO: Remove
  689. constexpr operator int32_t () const
  690. {
  691. return num;
  692. }
  693. };
  694. class ArtifactIDBase : public IdentifierBase
  695. {
  696. public:
  697. enum Type
  698. {
  699. NONE = -1,
  700. SPELLBOOK = 0,
  701. SPELL_SCROLL = 1,
  702. GRAIL = 2,
  703. CATAPULT = 3,
  704. BALLISTA = 4,
  705. AMMO_CART = 5,
  706. FIRST_AID_TENT = 6,
  707. VIAL_OF_DRAGON_BLOOD = 127,
  708. ARMAGEDDONS_BLADE = 128,
  709. ANGELIC_ALLIANCE = 129,
  710. TITANS_THUNDER = 135,
  711. ART_SELECTION = 144,
  712. ART_LOCK = 145, // FIXME: We must get rid of this one since it's conflict with artifact from mods. See issue 2455
  713. };
  714. DLL_LINKAGE const CArtifact * toArtifact() const;
  715. DLL_LINKAGE const Artifact * toEntity(const Services * service) const;
  716. };
  717. class ArtifactID : public EntityIdentifierWithEnum<ArtifactID, ArtifactIDBase>
  718. {
  719. public:
  720. using EntityIdentifierWithEnum<ArtifactID, ArtifactIDBase>::EntityIdentifierWithEnum;
  721. ///json serialization helpers
  722. DLL_LINKAGE static si32 decode(const std::string & identifier);
  723. DLL_LINKAGE static std::string encode(const si32 index);
  724. static std::string entityType();
  725. };
  726. class CreatureIDBase : public IdentifierBase
  727. {
  728. public:
  729. enum Type
  730. {
  731. NONE = -1,
  732. ARCHER = 2, // for debug / fallback
  733. IMP = 42, // for Deity of Fire
  734. FAMILIAR = 43, // for Deity of Fire
  735. SKELETON = 56, // for Skeleton Transformer
  736. TROGLODYTES = 70, // for Abandoned Mine
  737. MEDUSA = 76, // for Siege UI workaround
  738. AIR_ELEMENTAL = 112, // for tests
  739. FIRE_ELEMENTAL = 114, // for tests
  740. PSYCHIC_ELEMENTAL = 120, // for hardcoded ability
  741. MAGIC_ELEMENTAL = 121, // for hardcoded ability
  742. AZURE_DRAGON = 132,
  743. CATAPULT = 145,
  744. BALLISTA = 146,
  745. FIRST_AID_TENT = 147,
  746. AMMO_CART = 148,
  747. ARROW_TOWERS = 149
  748. };
  749. DLL_LINKAGE const CCreature * toCreature() const;
  750. DLL_LINKAGE const Creature * toEntity(const Services * services) const;
  751. DLL_LINKAGE const Creature * toEntity(const CreatureService * creatures) const;
  752. };
  753. class DLL_LINKAGE CreatureID : public EntityIdentifierWithEnum<CreatureID, CreatureIDBase>
  754. {
  755. public:
  756. using EntityIdentifierWithEnum<CreatureID, CreatureIDBase>::EntityIdentifierWithEnum;
  757. ///json serialization helpers
  758. static si32 decode(const std::string & identifier);
  759. static std::string encode(const si32 index);
  760. static std::string entityType();
  761. };
  762. class DLL_LINKAGE SpellIDBase : public IdentifierBase
  763. {
  764. public:
  765. enum Type
  766. {
  767. // Special ID's
  768. SPELLBOOK_PRESET = -3,
  769. PRESET = -2,
  770. NONE = -1,
  771. // Adventure map spells
  772. SUMMON_BOAT [[deprecated("check for spell mechanics instead of spell ID")]] = 0,
  773. SCUTTLE_BOAT [[deprecated("check for spell mechanics instead of spell ID")]] = 1,
  774. VISIONS [[deprecated("check for spell mechanics instead of spell ID")]] = 2,
  775. VIEW_EARTH [[deprecated("check for spell mechanics instead of spell ID")]] = 3,
  776. DISGUISE [[deprecated("check for spell mechanics instead of spell ID")]] = 4,
  777. VIEW_AIR [[deprecated("check for spell mechanics instead of spell ID")]] = 5,
  778. FLY [[deprecated("check for spell mechanics instead of spell ID")]] = 6,
  779. WATER_WALK [[deprecated("check for spell mechanics instead of spell ID")]] = 7,
  780. DIMENSION_DOOR [[deprecated("check for spell mechanics instead of spell ID")]] = 8,
  781. TOWN_PORTAL [[deprecated("check for spell mechanics instead of spell ID")]] = 9,
  782. // Combat spells
  783. QUICKSAND = 10,
  784. LAND_MINE = 11,
  785. FORCE_FIELD = 12,
  786. FIRE_WALL = 13,
  787. EARTHQUAKE = 14,
  788. MAGIC_ARROW = 15,
  789. ICE_BOLT = 16,
  790. LIGHTNING_BOLT = 17,
  791. IMPLOSION = 18,
  792. CHAIN_LIGHTNING = 19,
  793. FROST_RING = 20,
  794. FIREBALL = 21,
  795. INFERNO = 22,
  796. METEOR_SHOWER = 23,
  797. DEATH_RIPPLE = 24,
  798. DESTROY_UNDEAD = 25,
  799. ARMAGEDDON = 26,
  800. SHIELD = 27,
  801. AIR_SHIELD = 28,
  802. FIRE_SHIELD = 29,
  803. PROTECTION_FROM_AIR = 30,
  804. PROTECTION_FROM_FIRE = 31,
  805. PROTECTION_FROM_WATER = 32,
  806. PROTECTION_FROM_EARTH = 33,
  807. ANTI_MAGIC = 34,
  808. DISPEL = 35,
  809. MAGIC_MIRROR = 36,
  810. CURE = 37,
  811. RESURRECTION = 38,
  812. ANIMATE_DEAD = 39,
  813. SACRIFICE = 40,
  814. BLESS = 41,
  815. CURSE = 42,
  816. BLOODLUST = 43,
  817. PRECISION = 44,
  818. WEAKNESS = 45,
  819. STONE_SKIN = 46,
  820. DISRUPTING_RAY = 47,
  821. PRAYER = 48,
  822. MIRTH = 49,
  823. SORROW = 50,
  824. FORTUNE = 51,
  825. MISFORTUNE = 52,
  826. HASTE = 53,
  827. SLOW = 54,
  828. SLAYER = 55,
  829. FRENZY = 56,
  830. TITANS_LIGHTNING_BOLT = 57,
  831. COUNTERSTRIKE = 58,
  832. BERSERK = 59,
  833. HYPNOTIZE = 60,
  834. FORGETFULNESS = 61,
  835. BLIND = 62,
  836. TELEPORT = 63,
  837. REMOVE_OBSTACLE = 64,
  838. CLONE = 65,
  839. SUMMON_FIRE_ELEMENTAL = 66,
  840. SUMMON_EARTH_ELEMENTAL = 67,
  841. SUMMON_WATER_ELEMENTAL = 68,
  842. SUMMON_AIR_ELEMENTAL = 69,
  843. // Creature abilities
  844. STONE_GAZE = 70,
  845. POISON = 71,
  846. BIND = 72,
  847. DISEASE = 73,
  848. PARALYZE = 74,
  849. AGE = 75,
  850. DEATH_CLOUD = 76,
  851. THUNDERBOLT = 77,
  852. DISPEL_HELPFUL_SPELLS = 78,
  853. DEATH_STARE = 79,
  854. ACID_BREATH_DEFENSE = 80,
  855. ACID_BREATH_DAMAGE = 81,
  856. // Special ID's
  857. FIRST_NON_SPELL = 70,
  858. AFTER_LAST = 82
  859. };
  860. const CSpell * toSpell() const; //deprecated
  861. const spells::Spell * toEntity(const Services * service) const;
  862. const spells::Spell * toEntity(const spells::Service * service) const;
  863. };
  864. class DLL_LINKAGE SpellID : public EntityIdentifierWithEnum<SpellID, SpellIDBase>
  865. {
  866. public:
  867. using EntityIdentifierWithEnum<SpellID, SpellIDBase>::EntityIdentifierWithEnum;
  868. ///json serialization helpers
  869. static si32 decode(const std::string & identifier);
  870. static std::string encode(const si32 index);
  871. static std::string entityType();
  872. };
  873. class BattleFieldInfo;
  874. class DLL_LINKAGE BattleField : public EntityIdentifier<BattleField>
  875. {
  876. public:
  877. using EntityIdentifier<BattleField>::EntityIdentifier;
  878. static const BattleField NONE;
  879. const BattleFieldInfo * getInfo() const;
  880. static si32 decode(const std::string & identifier);
  881. static std::string encode(const si32 index);
  882. };
  883. class DLL_LINKAGE BoatId : public EntityIdentifier<BoatId>
  884. {
  885. public:
  886. using EntityIdentifier<BoatId>::EntityIdentifier;
  887. static si32 decode(const std::string & identifier);
  888. static std::string encode(const si32 index);
  889. static const BoatId NONE;
  890. static const BoatId NECROPOLIS;
  891. static const BoatId CASTLE;
  892. static const BoatId FORTRESS;
  893. };
  894. class TerrainIdBase : public IdentifierBase
  895. {
  896. public:
  897. enum Type : int32_t
  898. {
  899. NATIVE_TERRAIN = -4,
  900. ANY_TERRAIN = -3,
  901. NONE = -1,
  902. FIRST_REGULAR_TERRAIN = 0,
  903. DIRT = 0,
  904. SAND,
  905. GRASS,
  906. SNOW,
  907. SWAMP,
  908. ROUGH,
  909. SUBTERRANEAN,
  910. LAVA,
  911. WATER,
  912. ROCK,
  913. ORIGINAL_REGULAR_TERRAIN_COUNT = ROCK
  914. };
  915. };
  916. class DLL_LINKAGE TerrainId : public EntityIdentifierWithEnum<TerrainId, TerrainIdBase>
  917. {
  918. public:
  919. using EntityIdentifierWithEnum<TerrainId, TerrainIdBase>::EntityIdentifierWithEnum;
  920. static si32 decode(const std::string & identifier);
  921. static std::string encode(const si32 index);
  922. static std::string entityType();
  923. const TerrainType * toEntity(const Services * service) const;
  924. };
  925. class ObstacleInfo;
  926. class Obstacle : public EntityIdentifier<Obstacle>
  927. {
  928. public:
  929. using EntityIdentifier<Obstacle>::EntityIdentifier;
  930. DLL_LINKAGE const ObstacleInfo * getInfo() const;
  931. };
  932. class DLL_LINKAGE SpellSchool : public StaticIdentifier<SpellSchool>
  933. {
  934. public:
  935. using StaticIdentifier<SpellSchool>::StaticIdentifier;
  936. static const SpellSchool ANY;
  937. static const SpellSchool AIR;
  938. static const SpellSchool FIRE;
  939. static const SpellSchool WATER;
  940. static const SpellSchool EARTH;
  941. static si32 decode(const std::string & identifier);
  942. static std::string encode(const si32 index);
  943. static std::string entityType();
  944. };
  945. class GameResIDBase : public IdentifierBase
  946. {
  947. public:
  948. enum Type : int32_t
  949. {
  950. WOOD = 0,
  951. MERCURY,
  952. ORE,
  953. SULFUR,
  954. CRYSTAL,
  955. GEMS,
  956. GOLD,
  957. COUNT,
  958. WOOD_AND_ORE = -4, // special case for town bonus resource
  959. COMMON = -3, // campaign bonus
  960. RARE = -2, // campaign bonus
  961. NONE = -1
  962. };
  963. };
  964. class DLL_LINKAGE GameResID : public StaticIdentifierWithEnum<GameResID, GameResIDBase>
  965. {
  966. public:
  967. using StaticIdentifierWithEnum<GameResID, GameResIDBase>::StaticIdentifierWithEnum;
  968. static si32 decode(const std::string & identifier);
  969. static std::string encode(const si32 index);
  970. static std::string entityType();
  971. const Resource * toResource() const;
  972. const ResourceType * toEntity(const Services * services) const;
  973. };
  974. class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
  975. {
  976. public:
  977. BuildingTypeUniqueID(FactionID faction, BuildingID building );
  978. static si32 decode(const std::string & identifier);
  979. static std::string encode(const si32 index);
  980. BuildingID getBuilding() const;
  981. FactionID getFaction() const;
  982. using Identifier<BuildingTypeUniqueID>::Identifier;
  983. template <typename Handler>
  984. void serialize(Handler & h)
  985. {
  986. FactionID faction = getFaction();
  987. BuildingID building = getBuilding();
  988. h & faction;
  989. h & building;
  990. if (!h.saving)
  991. *this = BuildingTypeUniqueID(faction, building);
  992. }
  993. };
  994. class DLL_LINKAGE CampaignScenarioID : public StaticIdentifier<CampaignScenarioID>
  995. {
  996. public:
  997. using StaticIdentifier<CampaignScenarioID>::StaticIdentifier;
  998. static si32 decode(const std::string & identifier);
  999. static std::string encode(int32_t index);
  1000. static const CampaignScenarioID NONE;
  1001. };
  1002. class DLL_LINKAGE CampaignRegionID : public StaticIdentifier<CampaignRegionID>
  1003. {
  1004. public:
  1005. using StaticIdentifier<CampaignRegionID>::StaticIdentifier;
  1006. };
  1007. // Deprecated
  1008. // TODO: remove
  1009. using Obj = MapObjectID;
  1010. using ETownType = FactionID;
  1011. using EGameResID = GameResID;
  1012. using River = RiverId;
  1013. using Road = RoadId;
  1014. using ETerrainId = TerrainId;
  1015. VCMI_LIB_NAMESPACE_END