EntityIdentifiers.h 25 KB

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