EntityIdentifiers.h 24 KB

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