EntityIdentifiers.h 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. DLL_LINKAGE static si32 decode(const std::string & identifier);
  344. DLL_LINKAGE static std::string encode(const si32 index);
  345. static std::string entityType();
  346. };
  347. class MapObjectBaseID : public IdentifierBase
  348. {
  349. public:
  350. enum Type
  351. {
  352. NO_OBJ = -1,
  353. ALTAR_OF_SACRIFICE [[deprecated]] = 2,
  354. ANCHOR_POINT = 3,
  355. ARENA = 4,
  356. ARTIFACT = 5,
  357. PANDORAS_BOX = 6,
  358. BLACK_MARKET [[deprecated]] = 7,
  359. BOAT = 8,
  360. BORDERGUARD = 9,
  361. KEYMASTER = 10,
  362. BUOY = 11,
  363. CAMPFIRE = 12,
  364. CARTOGRAPHER = 13,
  365. SWAN_POND = 14,
  366. COVER_OF_DARKNESS = 15,
  367. CREATURE_BANK = 16,
  368. CREATURE_GENERATOR1 = 17,
  369. CREATURE_GENERATOR2 = 18,
  370. CREATURE_GENERATOR3 = 19,
  371. CREATURE_GENERATOR4 = 20,
  372. CURSED_GROUND1 = 21,
  373. CORPSE = 22,
  374. MARLETTO_TOWER = 23,
  375. DERELICT_SHIP = 24,
  376. DRAGON_UTOPIA = 25,
  377. EVENT = 26,
  378. EYE_OF_MAGI = 27,
  379. FAERIE_RING = 28,
  380. FLOTSAM = 29,
  381. FOUNTAIN_OF_FORTUNE = 30,
  382. FOUNTAIN_OF_YOUTH = 31,
  383. GARDEN_OF_REVELATION = 32,
  384. GARRISON = 33,
  385. HERO = 34,
  386. HILL_FORT = 35,
  387. GRAIL = 36,
  388. HUT_OF_MAGI = 37,
  389. IDOL_OF_FORTUNE = 38,
  390. LEAN_TO = 39,
  391. LIBRARY_OF_ENLIGHTENMENT = 41,
  392. LIGHTHOUSE = 42,
  393. MONOLITH_ONE_WAY_ENTRANCE = 43,
  394. MONOLITH_ONE_WAY_EXIT = 44,
  395. MONOLITH_TWO_WAY = 45,
  396. MAGIC_PLAINS1 = 46,
  397. SCHOOL_OF_MAGIC = 47,
  398. MAGIC_SPRING = 48,
  399. MAGIC_WELL = 49,
  400. MARKET_OF_TIME = 50,
  401. MERCENARY_CAMP = 51,
  402. MERMAID = 52,
  403. MINE = 53,
  404. MONSTER = 54,
  405. MYSTICAL_GARDEN = 55,
  406. OASIS = 56,
  407. OBELISK = 57,
  408. REDWOOD_OBSERVATORY = 58,
  409. OCEAN_BOTTLE = 59,
  410. PILLAR_OF_FIRE = 60,
  411. STAR_AXIS = 61,
  412. PRISON = 62,
  413. PYRAMID = 63,//subtype 0
  414. WOG_OBJECT = 63,//subtype > 0
  415. RALLY_FLAG = 64,
  416. RANDOM_ART = 65,
  417. RANDOM_TREASURE_ART = 66,
  418. RANDOM_MINOR_ART = 67,
  419. RANDOM_MAJOR_ART = 68,
  420. RANDOM_RELIC_ART = 69,
  421. RANDOM_HERO = 70,
  422. RANDOM_MONSTER = 71,
  423. RANDOM_MONSTER_L1 = 72,
  424. RANDOM_MONSTER_L2 = 73,
  425. RANDOM_MONSTER_L3 = 74,
  426. RANDOM_MONSTER_L4 = 75,
  427. RANDOM_RESOURCE = 76,
  428. RANDOM_TOWN = 77,
  429. REFUGEE_CAMP = 78,
  430. RESOURCE = 79,
  431. SANCTUARY = 80,
  432. SCHOLAR = 81,
  433. SEA_CHEST = 82,
  434. SEER_HUT = 83,
  435. CRYPT = 84,
  436. SHIPWRECK = 85,
  437. SHIPWRECK_SURVIVOR = 86,
  438. SHIPYARD = 87,
  439. SHRINE_OF_MAGIC_INCANTATION = 88,
  440. SHRINE_OF_MAGIC_GESTURE = 89,
  441. SHRINE_OF_MAGIC_THOUGHT = 90,
  442. SIGN = 91,
  443. SIRENS = 92,
  444. SPELL_SCROLL = 93,
  445. STABLES = 94,
  446. TAVERN = 95,
  447. TEMPLE = 96,
  448. DEN_OF_THIEVES = 97,
  449. TOWN = 98,
  450. TRADING_POST [[deprecated]] = 99,
  451. LEARNING_STONE = 100,
  452. TREASURE_CHEST = 101,
  453. TREE_OF_KNOWLEDGE = 102,
  454. SUBTERRANEAN_GATE = 103,
  455. UNIVERSITY [[deprecated]] = 104,
  456. WAGON = 105,
  457. WAR_MACHINE_FACTORY = 106,
  458. SCHOOL_OF_WAR = 107,
  459. WARRIORS_TOMB = 108,
  460. WATER_WHEEL = 109,
  461. WATERING_HOLE = 110,
  462. WHIRLPOOL = 111,
  463. WINDMILL = 112,
  464. WITCH_HUT = 113,
  465. HOLE = 124,
  466. RANDOM_MONSTER_L5 = 162,
  467. RANDOM_MONSTER_L6 = 163,
  468. RANDOM_MONSTER_L7 = 164,
  469. BORDER_GATE = 212,
  470. FREELANCERS_GUILD [[deprecated]] = 213,
  471. HERO_PLACEHOLDER = 214,
  472. QUEST_GUARD = 215,
  473. RANDOM_DWELLING = 216,
  474. RANDOM_DWELLING_LVL = 217, //subtype = creature level
  475. RANDOM_DWELLING_FACTION = 218, //subtype = faction
  476. GARRISON2 = 219,
  477. ABANDONED_MINE = 220,
  478. TRADING_POST_SNOW [[deprecated]] = 221,
  479. CLOVER_FIELD = 222,
  480. CURSED_GROUND2 = 223,
  481. EVIL_FOG = 224,
  482. FAVORABLE_WINDS = 225,
  483. FIERY_FIELDS = 226,
  484. HOLY_GROUNDS = 227,
  485. LUCID_POOLS = 228,
  486. MAGIC_CLOUDS = 229,
  487. MAGIC_PLAINS2 = 230,
  488. ROCKLANDS = 231,
  489. };
  490. };
  491. class DLL_LINKAGE MapObjectID : public IdentifierWithEnum<MapObjectID, MapObjectBaseID>
  492. {
  493. public:
  494. using IdentifierWithEnum<MapObjectID, MapObjectBaseID>::IdentifierWithEnum;
  495. static std::string encode(int32_t index);
  496. static si32 decode(const std::string & identifier);
  497. };
  498. class MapObjectSubID : public Identifier<MapObjectSubID>
  499. {
  500. public:
  501. constexpr MapObjectSubID(const IdentifierBase & value):
  502. Identifier<MapObjectSubID>(value.getNum())
  503. {}
  504. constexpr MapObjectSubID(int32_t value = -1):
  505. Identifier<MapObjectSubID>(value)
  506. {}
  507. MapObjectSubID & operator =(int32_t value)
  508. {
  509. this->num = value;
  510. return *this;
  511. }
  512. MapObjectSubID & operator =(const IdentifierBase & value)
  513. {
  514. this->num = value.getNum();
  515. return *this;
  516. }
  517. };
  518. class DLL_LINKAGE RoadId : public Identifier<RoadId>
  519. {
  520. public:
  521. using Identifier<RoadId>::Identifier;
  522. static const RoadId NO_ROAD;
  523. static const RoadId DIRT_ROAD;
  524. static const RoadId GRAVEL_ROAD;
  525. static const RoadId COBBLESTONE_ROAD;
  526. };
  527. class DLL_LINKAGE RiverId : public Identifier<RiverId>
  528. {
  529. public:
  530. using Identifier<RiverId>::Identifier;
  531. static const RiverId NO_RIVER;
  532. static const RiverId WATER_RIVER;
  533. static const RiverId ICY_RIVER;
  534. static const RiverId MUD_RIVER;
  535. static const RiverId LAVA_RIVER;
  536. };
  537. class DLL_LINKAGE EPathfindingLayerBase : public IdentifierBase
  538. {
  539. public:
  540. enum Type : int32_t
  541. {
  542. LAND = 0, SAIL = 1, WATER, AIR, NUM_LAYERS, WRONG, AUTO
  543. };
  544. };
  545. class EPathfindingLayer : public IdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>
  546. {
  547. public:
  548. using IdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>::IdentifierWithEnum;
  549. };
  550. class ArtifactPositionBase : public IdentifierBase
  551. {
  552. public:
  553. enum Type
  554. {
  555. TRANSITION_POS = -3,
  556. FIRST_AVAILABLE = -2,
  557. PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack
  558. // Hero
  559. HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5
  560. RIGHT_RING, LEFT_RING, FEET, //8
  561. MISC1, MISC2, MISC3, MISC4, //12
  562. MACH1, MACH2, MACH3, MACH4, //16
  563. SPELLBOOK, MISC5, //18
  564. BACKPACK_START = 19,
  565. // Creatures
  566. CREATURE_SLOT = 0,
  567. // Commander
  568. COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6
  569. };
  570. static_assert(MISC5 < BACKPACK_START, "incorrect number of artifact slots");
  571. DLL_LINKAGE static si32 decode(const std::string & identifier);
  572. DLL_LINKAGE static std::string encode(const si32 index);
  573. };
  574. class ArtifactPosition : public IdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>
  575. {
  576. public:
  577. using IdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>::IdentifierWithEnum;
  578. };
  579. class ArtifactIDBase : public IdentifierBase
  580. {
  581. public:
  582. enum Type
  583. {
  584. NONE = -1,
  585. SPELLBOOK = 0,
  586. SPELL_SCROLL = 1,
  587. GRAIL = 2,
  588. CATAPULT = 3,
  589. BALLISTA = 4,
  590. AMMO_CART = 5,
  591. FIRST_AID_TENT = 6,
  592. VIAL_OF_DRAGON_BLOOD = 127,
  593. ARMAGEDDONS_BLADE = 128,
  594. TITANS_THUNDER = 135,
  595. ART_SELECTION = 144,
  596. ART_LOCK = 145, // FIXME: We must get rid of this one since it's conflict with artifact from mods. See issue 2455
  597. };
  598. DLL_LINKAGE const CArtifact * toArtifact() const;
  599. DLL_LINKAGE const Artifact * toArtifact(const ArtifactService * service) const;
  600. };
  601. class ArtifactID : public IdentifierWithEnum<ArtifactID, ArtifactIDBase>
  602. {
  603. public:
  604. using IdentifierWithEnum<ArtifactID, ArtifactIDBase>::IdentifierWithEnum;
  605. ///json serialization helpers
  606. DLL_LINKAGE static si32 decode(const std::string & identifier);
  607. DLL_LINKAGE static std::string encode(const si32 index);
  608. static std::string entityType();
  609. };
  610. class CreatureIDBase : public IdentifierBase
  611. {
  612. public:
  613. enum Type
  614. {
  615. NONE = -1,
  616. ARCHER = 2, // for debug / fallback
  617. IMP = 42, // for Deity of Fire
  618. SKELETON = 56, // for Skeleton Transformer
  619. BONE_DRAGON = 68, // for Skeleton Transformer
  620. TROGLODYTES = 70, // for Abandoned Mine
  621. MEDUSA = 76, // for Siege UI workaround
  622. HYDRA = 110, // for Skeleton Transformer
  623. CHAOS_HYDRA = 111, // for Skeleton Transformer
  624. AIR_ELEMENTAL = 112, // for tests
  625. FIRE_ELEMENTAL = 114, // for tests
  626. PSYCHIC_ELEMENTAL = 120, // for hardcoded ability
  627. MAGIC_ELEMENTAL = 121, // for hardcoded ability
  628. CATAPULT = 145,
  629. BALLISTA = 146,
  630. FIRST_AID_TENT = 147,
  631. AMMO_CART = 148,
  632. ARROW_TOWERS = 149
  633. };
  634. DLL_LINKAGE const CCreature * toCreature() const;
  635. DLL_LINKAGE const Creature * toCreature(const CreatureService * creatures) const;
  636. };
  637. class DLL_LINKAGE CreatureID : public IdentifierWithEnum<CreatureID, CreatureIDBase>
  638. {
  639. public:
  640. using IdentifierWithEnum<CreatureID, CreatureIDBase>::IdentifierWithEnum;
  641. ///json serialization helpers
  642. static si32 decode(const std::string & identifier);
  643. static std::string encode(const si32 index);
  644. static std::string entityType();
  645. };
  646. class DLL_LINKAGE SpellIDBase : public IdentifierBase
  647. {
  648. public:
  649. enum Type
  650. {
  651. // Special ID's
  652. SPELLBOOK_PRESET = -3,
  653. PRESET = -2,
  654. NONE = -1,
  655. // Adventure map spells
  656. SUMMON_BOAT = 0,
  657. SCUTTLE_BOAT = 1,
  658. VISIONS = 2,
  659. VIEW_EARTH = 3,
  660. DISGUISE = 4,
  661. VIEW_AIR = 5,
  662. FLY = 6,
  663. WATER_WALK = 7,
  664. DIMENSION_DOOR = 8,
  665. TOWN_PORTAL = 9,
  666. // Combar spells
  667. QUICKSAND = 10,
  668. LAND_MINE = 11,
  669. FORCE_FIELD = 12,
  670. FIRE_WALL = 13,
  671. EARTHQUAKE = 14,
  672. MAGIC_ARROW = 15,
  673. ICE_BOLT = 16,
  674. LIGHTNING_BOLT = 17,
  675. IMPLOSION = 18,
  676. CHAIN_LIGHTNING = 19,
  677. FROST_RING = 20,
  678. FIREBALL = 21,
  679. INFERNO = 22,
  680. METEOR_SHOWER = 23,
  681. DEATH_RIPPLE = 24,
  682. DESTROY_UNDEAD = 25,
  683. ARMAGEDDON = 26,
  684. SHIELD = 27,
  685. AIR_SHIELD = 28,
  686. FIRE_SHIELD = 29,
  687. PROTECTION_FROM_AIR = 30,
  688. PROTECTION_FROM_FIRE = 31,
  689. PROTECTION_FROM_WATER = 32,
  690. PROTECTION_FROM_EARTH = 33,
  691. ANTI_MAGIC = 34,
  692. DISPEL = 35,
  693. MAGIC_MIRROR = 36,
  694. CURE = 37,
  695. RESURRECTION = 38,
  696. ANIMATE_DEAD = 39,
  697. SACRIFICE = 40,
  698. BLESS = 41,
  699. CURSE = 42,
  700. BLOODLUST = 43,
  701. PRECISION = 44,
  702. WEAKNESS = 45,
  703. STONE_SKIN = 46,
  704. DISRUPTING_RAY = 47,
  705. PRAYER = 48,
  706. MIRTH = 49,
  707. SORROW = 50,
  708. FORTUNE = 51,
  709. MISFORTUNE = 52,
  710. HASTE = 53,
  711. SLOW = 54,
  712. SLAYER = 55,
  713. FRENZY = 56,
  714. TITANS_LIGHTNING_BOLT = 57,
  715. COUNTERSTRIKE = 58,
  716. BERSERK = 59,
  717. HYPNOTIZE = 60,
  718. FORGETFULNESS = 61,
  719. BLIND = 62,
  720. TELEPORT = 63,
  721. REMOVE_OBSTACLE = 64,
  722. CLONE = 65,
  723. SUMMON_FIRE_ELEMENTAL = 66,
  724. SUMMON_EARTH_ELEMENTAL = 67,
  725. SUMMON_WATER_ELEMENTAL = 68,
  726. SUMMON_AIR_ELEMENTAL = 69,
  727. // Creature abilities
  728. STONE_GAZE = 70,
  729. POISON = 71,
  730. BIND = 72,
  731. DISEASE = 73,
  732. PARALYZE = 74,
  733. AGE = 75,
  734. DEATH_CLOUD = 76,
  735. THUNDERBOLT = 77,
  736. DISPEL_HELPFUL_SPELLS = 78,
  737. DEATH_STARE = 79,
  738. ACID_BREATH_DEFENSE = 80,
  739. ACID_BREATH_DAMAGE = 81,
  740. // Special ID's
  741. FIRST_NON_SPELL = 70,
  742. AFTER_LAST = 82
  743. };
  744. const CSpell * toSpell() const; //deprecated
  745. const spells::Spell * toSpell(const spells::Service * service) const;
  746. };
  747. class DLL_LINKAGE SpellID : public IdentifierWithEnum<SpellID, SpellIDBase>
  748. {
  749. public:
  750. using IdentifierWithEnum<SpellID, SpellIDBase>::IdentifierWithEnum;
  751. ///json serialization helpers
  752. static si32 decode(const std::string & identifier);
  753. static std::string encode(const si32 index);
  754. static std::string entityType();
  755. };
  756. class BattleFieldInfo;
  757. class DLL_LINKAGE BattleField : public Identifier<BattleField>
  758. {
  759. public:
  760. using Identifier<BattleField>::Identifier;
  761. static const BattleField NONE;
  762. const BattleFieldInfo * getInfo() const;
  763. static si32 decode(const std::string & identifier);
  764. static std::string encode(const si32 index);
  765. };
  766. class DLL_LINKAGE BoatId : public Identifier<BoatId>
  767. {
  768. public:
  769. using Identifier<BoatId>::Identifier;
  770. static const BoatId NONE;
  771. static const BoatId NECROPOLIS;
  772. static const BoatId CASTLE;
  773. static const BoatId FORTRESS;
  774. };
  775. class TerrainIdBase : public IdentifierBase
  776. {
  777. public:
  778. enum Type : int32_t
  779. {
  780. NATIVE_TERRAIN = -4,
  781. ANY_TERRAIN = -3,
  782. NONE = -1,
  783. FIRST_REGULAR_TERRAIN = 0,
  784. DIRT = 0,
  785. SAND,
  786. GRASS,
  787. SNOW,
  788. SWAMP,
  789. ROUGH,
  790. SUBTERRANEAN,
  791. LAVA,
  792. WATER,
  793. ROCK,
  794. ORIGINAL_REGULAR_TERRAIN_COUNT = ROCK
  795. };
  796. };
  797. class TerrainId : public IdentifierWithEnum<TerrainId, TerrainIdBase>
  798. {
  799. public:
  800. using IdentifierWithEnum<TerrainId, TerrainIdBase>::IdentifierWithEnum;
  801. DLL_LINKAGE static si32 decode(const std::string & identifier);
  802. DLL_LINKAGE static std::string encode(const si32 index);
  803. static std::string entityType();
  804. };
  805. class ObstacleInfo;
  806. class Obstacle : public Identifier<Obstacle>
  807. {
  808. public:
  809. using Identifier<Obstacle>::Identifier;
  810. DLL_LINKAGE const ObstacleInfo * getInfo() const;
  811. };
  812. class DLL_LINKAGE SpellSchool : public Identifier<SpellSchool>
  813. {
  814. public:
  815. using Identifier<SpellSchool>::Identifier;
  816. static const SpellSchool ANY;
  817. static const SpellSchool AIR;
  818. static const SpellSchool FIRE;
  819. static const SpellSchool WATER;
  820. static const SpellSchool EARTH;
  821. static si32 decode(const std::string & identifier);
  822. static std::string encode(const si32 index);
  823. static std::string entityType();
  824. };
  825. class GameResIDBase : public IdentifierBase
  826. {
  827. public:
  828. enum Type : int32_t
  829. {
  830. WOOD = 0,
  831. MERCURY,
  832. ORE,
  833. SULFUR,
  834. CRYSTAL,
  835. GEMS,
  836. GOLD,
  837. MITHRIL,
  838. COUNT,
  839. WOOD_AND_ORE = 127, // special case for town bonus resource
  840. NONE = -1
  841. };
  842. };
  843. class DLL_LINKAGE GameResID : public IdentifierWithEnum<GameResID, GameResIDBase>
  844. {
  845. public:
  846. using IdentifierWithEnum<GameResID, GameResIDBase>::IdentifierWithEnum;
  847. static si32 decode(const std::string & identifier);
  848. static std::string encode(const si32 index);
  849. static std::string entityType();
  850. static const std::array<GameResID, 7> & ALL_RESOURCES();
  851. };
  852. class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
  853. {
  854. public:
  855. BuildingTypeUniqueID(FactionID faction, BuildingID building );
  856. static si32 decode(const std::string & identifier);
  857. static std::string encode(const si32 index);
  858. BuildingID getBuilding() const;
  859. FactionID getFaction() const;
  860. using Identifier<BuildingTypeUniqueID>::Identifier;
  861. };
  862. class DLL_LINKAGE CampaignScenarioID : public Identifier<CampaignScenarioID>
  863. {
  864. public:
  865. using Identifier<CampaignScenarioID>::Identifier;
  866. static si32 decode(const std::string & identifier);
  867. static std::string encode(int32_t index);
  868. static const CampaignScenarioID NONE;
  869. };
  870. // Deprecated
  871. // TODO: remove
  872. using Obj = MapObjectID;
  873. using ETownType = FactionID;
  874. using EGameResID = GameResID;
  875. using River = RiverId;
  876. using Road = RoadId;
  877. using ETerrainId = TerrainId;
  878. VCMI_LIB_NAMESPACE_END