EntityIdentifiers.h 24 KB

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