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