EntityIdentifiers.h 24 KB

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