EntityIdentifiers.h 24 KB

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