EntityIdentifiers.h 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * EntityIdentifiers.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "NumericConstants.h"
  12. #include "IdentifierBase.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class 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. HOLE = 124,
  412. RANDOM_MONSTER_L5 = 162,
  413. RANDOM_MONSTER_L6 = 163,
  414. RANDOM_MONSTER_L7 = 164,
  415. BORDER_GATE = 212,
  416. FREELANCERS_GUILD [[deprecated]] = 213,
  417. HERO_PLACEHOLDER = 214,
  418. QUEST_GUARD = 215,
  419. RANDOM_DWELLING = 216,
  420. RANDOM_DWELLING_LVL = 217, //subtype = creature level
  421. RANDOM_DWELLING_FACTION = 218, //subtype = faction
  422. GARRISON2 = 219,
  423. ABANDONED_MINE = 220,
  424. TRADING_POST_SNOW [[deprecated]] = 221,
  425. CLOVER_FIELD = 222,
  426. CURSED_GROUND2 = 223,
  427. EVIL_FOG = 224,
  428. FAVORABLE_WINDS = 225,
  429. FIERY_FIELDS = 226,
  430. HOLY_GROUNDS = 227,
  431. LUCID_POOLS = 228,
  432. MAGIC_CLOUDS = 229,
  433. MAGIC_PLAINS2 = 230,
  434. ROCKLANDS = 231,
  435. };
  436. };
  437. class DLL_LINKAGE MapObjectID : public EntityIdentifierWithEnum<MapObjectID, MapObjectBaseID>
  438. {
  439. public:
  440. using EntityIdentifierWithEnum<MapObjectID, MapObjectBaseID>::EntityIdentifierWithEnum;
  441. static std::string encode(int32_t index);
  442. static si32 decode(const std::string & identifier);
  443. // TODO: Remove
  444. constexpr operator int32_t () const
  445. {
  446. return num;
  447. }
  448. };
  449. class DLL_LINKAGE MapObjectSubID : public Identifier<MapObjectSubID>
  450. {
  451. public:
  452. constexpr MapObjectSubID(const IdentifierBase & value):
  453. Identifier<MapObjectSubID>(value.getNum())
  454. {}
  455. constexpr MapObjectSubID(int32_t value = -1):
  456. Identifier<MapObjectSubID>(value)
  457. {}
  458. MapObjectSubID & operator =(int32_t value)
  459. {
  460. this->num = value;
  461. return *this;
  462. }
  463. MapObjectSubID & operator =(const IdentifierBase & value)
  464. {
  465. this->num = value.getNum();
  466. return *this;
  467. }
  468. static si32 decode(MapObjectID primaryID, const std::string & identifier);
  469. static std::string encode(MapObjectID primaryID, si32 index);
  470. // TODO: Remove
  471. constexpr operator int32_t () const
  472. {
  473. return num;
  474. }
  475. template <typename Handler>
  476. void serializeIdentifier(Handler &h, const MapObjectID & primaryID)
  477. {
  478. std::string secondaryStringID;
  479. if (h.saving)
  480. secondaryStringID = encode(primaryID, num);
  481. h & secondaryStringID;
  482. if (!h.saving)
  483. num = decode(primaryID, secondaryStringID);
  484. }
  485. };
  486. class DLL_LINKAGE RoadId : public EntityIdentifier<RoadId>
  487. {
  488. public:
  489. using EntityIdentifier<RoadId>::EntityIdentifier;
  490. static si32 decode(const std::string & identifier);
  491. static std::string encode(const si32 index);
  492. static std::string entityType();
  493. static const RoadId NO_ROAD;
  494. static const RoadId DIRT_ROAD;
  495. static const RoadId GRAVEL_ROAD;
  496. static const RoadId COBBLESTONE_ROAD;
  497. const RoadType * toEntity(const Services * service) const;
  498. };
  499. class DLL_LINKAGE RiverId : public EntityIdentifier<RiverId>
  500. {
  501. public:
  502. using EntityIdentifier<RiverId>::EntityIdentifier;
  503. static si32 decode(const std::string & identifier);
  504. static std::string encode(const si32 index);
  505. static std::string entityType();
  506. static const RiverId NO_RIVER;
  507. static const RiverId WATER_RIVER;
  508. static const RiverId ICY_RIVER;
  509. static const RiverId MUD_RIVER;
  510. static const RiverId LAVA_RIVER;
  511. const RiverType * toEntity(const Services * service) const;
  512. };
  513. class DLL_LINKAGE EPathfindingLayerBase : public IdentifierBase
  514. {
  515. public:
  516. enum Type : int32_t
  517. {
  518. LAND = 0, SAIL = 1, WATER, AIR, NUM_LAYERS, WRONG, AUTO
  519. };
  520. };
  521. class EPathfindingLayer : public StaticIdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>
  522. {
  523. public:
  524. using StaticIdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>::StaticIdentifierWithEnum;
  525. };
  526. class ArtifactPositionBase : public IdentifierBase
  527. {
  528. public:
  529. enum Type
  530. {
  531. TRANSITION_POS = -3,
  532. FIRST_AVAILABLE = -2,
  533. PRE_FIRST = -1, //sometimes used as error, sometimes as first free in backpack
  534. // Hero
  535. HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, //5
  536. RIGHT_RING, LEFT_RING, FEET, //8
  537. MISC1, MISC2, MISC3, MISC4, //12
  538. MACH1, MACH2, MACH3, MACH4, //16
  539. SPELLBOOK, MISC5, //18
  540. BACKPACK_START = 19,
  541. // Creatures
  542. CREATURE_SLOT = 0,
  543. // Commander
  544. COMMANDER1 = 0, COMMANDER2, COMMANDER3, COMMANDER4, COMMANDER5, COMMANDER6,
  545. // Altar
  546. ALTAR = BACKPACK_START
  547. };
  548. static_assert(MISC5 < BACKPACK_START, "incorrect number of artifact slots");
  549. DLL_LINKAGE static si32 decode(const std::string & identifier);
  550. DLL_LINKAGE static std::string encode(const si32 index);
  551. };
  552. class ArtifactPosition : public StaticIdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>
  553. {
  554. public:
  555. using StaticIdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>::StaticIdentifierWithEnum;
  556. // TODO: Remove
  557. constexpr operator int32_t () const
  558. {
  559. return num;
  560. }
  561. };
  562. class ArtifactIDBase : public IdentifierBase
  563. {
  564. public:
  565. enum Type
  566. {
  567. NONE = -1,
  568. SPELLBOOK = 0,
  569. SPELL_SCROLL = 1,
  570. GRAIL = 2,
  571. CATAPULT = 3,
  572. BALLISTA = 4,
  573. AMMO_CART = 5,
  574. FIRST_AID_TENT = 6,
  575. VIAL_OF_DRAGON_BLOOD = 127,
  576. ARMAGEDDONS_BLADE = 128,
  577. ANGELIC_ALLIANCE = 129,
  578. TITANS_THUNDER = 135,
  579. ART_SELECTION = 144,
  580. ART_LOCK = 145, // FIXME: We must get rid of this one since it's conflict with artifact from mods. See issue 2455
  581. };
  582. DLL_LINKAGE const CArtifact * toArtifact() const;
  583. DLL_LINKAGE const Artifact * toEntity(const Services * service) const;
  584. };
  585. class ArtifactID : public EntityIdentifierWithEnum<ArtifactID, ArtifactIDBase>
  586. {
  587. public:
  588. using EntityIdentifierWithEnum<ArtifactID, ArtifactIDBase>::EntityIdentifierWithEnum;
  589. ///json serialization helpers
  590. DLL_LINKAGE static si32 decode(const std::string & identifier);
  591. DLL_LINKAGE static std::string encode(const si32 index);
  592. static std::string entityType();
  593. };
  594. class CreatureIDBase : public IdentifierBase
  595. {
  596. public:
  597. enum Type
  598. {
  599. NONE = -1,
  600. ARCHER = 2, // for debug / fallback
  601. IMP = 42, // for Deity of Fire
  602. FAMILIAR = 43, // for Deity of Fire
  603. SKELETON = 56, // for Skeleton Transformer
  604. BONE_DRAGON = 68, // for Skeleton Transformer
  605. TROGLODYTES = 70, // for Abandoned Mine
  606. MEDUSA = 76, // for Siege UI workaround
  607. HYDRA = 110, // for Skeleton Transformer
  608. CHAOS_HYDRA = 111, // for Skeleton Transformer
  609. AIR_ELEMENTAL = 112, // for tests
  610. FIRE_ELEMENTAL = 114, // for tests
  611. PSYCHIC_ELEMENTAL = 120, // for hardcoded ability
  612. MAGIC_ELEMENTAL = 121, // for hardcoded ability
  613. AZURE_DRAGON = 132,
  614. CATAPULT = 145,
  615. BALLISTA = 146,
  616. FIRST_AID_TENT = 147,
  617. AMMO_CART = 148,
  618. ARROW_TOWERS = 149
  619. };
  620. DLL_LINKAGE const CCreature * toCreature() const;
  621. DLL_LINKAGE const Creature * toEntity(const Services * services) const;
  622. DLL_LINKAGE const Creature * toEntity(const CreatureService * creatures) const;
  623. };
  624. class DLL_LINKAGE CreatureID : public EntityIdentifierWithEnum<CreatureID, CreatureIDBase>
  625. {
  626. public:
  627. using EntityIdentifierWithEnum<CreatureID, CreatureIDBase>::EntityIdentifierWithEnum;
  628. ///json serialization helpers
  629. static si32 decode(const std::string & identifier);
  630. static std::string encode(const si32 index);
  631. static std::string entityType();
  632. };
  633. class DLL_LINKAGE SpellIDBase : public IdentifierBase
  634. {
  635. public:
  636. enum Type
  637. {
  638. // Special ID's
  639. SPELLBOOK_PRESET = -3,
  640. PRESET = -2,
  641. NONE = -1,
  642. // Adventure map spells
  643. SUMMON_BOAT = 0,
  644. SCUTTLE_BOAT = 1,
  645. VISIONS = 2,
  646. VIEW_EARTH = 3,
  647. DISGUISE = 4,
  648. VIEW_AIR = 5,
  649. FLY = 6,
  650. WATER_WALK = 7,
  651. DIMENSION_DOOR = 8,
  652. TOWN_PORTAL = 9,
  653. // Combat spells
  654. QUICKSAND = 10,
  655. LAND_MINE = 11,
  656. FORCE_FIELD = 12,
  657. FIRE_WALL = 13,
  658. EARTHQUAKE = 14,
  659. MAGIC_ARROW = 15,
  660. ICE_BOLT = 16,
  661. LIGHTNING_BOLT = 17,
  662. IMPLOSION = 18,
  663. CHAIN_LIGHTNING = 19,
  664. FROST_RING = 20,
  665. FIREBALL = 21,
  666. INFERNO = 22,
  667. METEOR_SHOWER = 23,
  668. DEATH_RIPPLE = 24,
  669. DESTROY_UNDEAD = 25,
  670. ARMAGEDDON = 26,
  671. SHIELD = 27,
  672. AIR_SHIELD = 28,
  673. FIRE_SHIELD = 29,
  674. PROTECTION_FROM_AIR = 30,
  675. PROTECTION_FROM_FIRE = 31,
  676. PROTECTION_FROM_WATER = 32,
  677. PROTECTION_FROM_EARTH = 33,
  678. ANTI_MAGIC = 34,
  679. DISPEL = 35,
  680. MAGIC_MIRROR = 36,
  681. CURE = 37,
  682. RESURRECTION = 38,
  683. ANIMATE_DEAD = 39,
  684. SACRIFICE = 40,
  685. BLESS = 41,
  686. CURSE = 42,
  687. BLOODLUST = 43,
  688. PRECISION = 44,
  689. WEAKNESS = 45,
  690. STONE_SKIN = 46,
  691. DISRUPTING_RAY = 47,
  692. PRAYER = 48,
  693. MIRTH = 49,
  694. SORROW = 50,
  695. FORTUNE = 51,
  696. MISFORTUNE = 52,
  697. HASTE = 53,
  698. SLOW = 54,
  699. SLAYER = 55,
  700. FRENZY = 56,
  701. TITANS_LIGHTNING_BOLT = 57,
  702. COUNTERSTRIKE = 58,
  703. BERSERK = 59,
  704. HYPNOTIZE = 60,
  705. FORGETFULNESS = 61,
  706. BLIND = 62,
  707. TELEPORT = 63,
  708. REMOVE_OBSTACLE = 64,
  709. CLONE = 65,
  710. SUMMON_FIRE_ELEMENTAL = 66,
  711. SUMMON_EARTH_ELEMENTAL = 67,
  712. SUMMON_WATER_ELEMENTAL = 68,
  713. SUMMON_AIR_ELEMENTAL = 69,
  714. // Creature abilities
  715. STONE_GAZE = 70,
  716. POISON = 71,
  717. BIND = 72,
  718. DISEASE = 73,
  719. PARALYZE = 74,
  720. AGE = 75,
  721. DEATH_CLOUD = 76,
  722. THUNDERBOLT = 77,
  723. DISPEL_HELPFUL_SPELLS = 78,
  724. DEATH_STARE = 79,
  725. ACID_BREATH_DEFENSE = 80,
  726. ACID_BREATH_DAMAGE = 81,
  727. // Special ID's
  728. FIRST_NON_SPELL = 70,
  729. AFTER_LAST = 82
  730. };
  731. const CSpell * toSpell() const; //deprecated
  732. const spells::Spell * toEntity(const Services * service) const;
  733. const spells::Spell * toEntity(const spells::Service * service) const;
  734. };
  735. class DLL_LINKAGE SpellID : public EntityIdentifierWithEnum<SpellID, SpellIDBase>
  736. {
  737. public:
  738. using EntityIdentifierWithEnum<SpellID, SpellIDBase>::EntityIdentifierWithEnum;
  739. ///json serialization helpers
  740. static si32 decode(const std::string & identifier);
  741. static std::string encode(const si32 index);
  742. static std::string entityType();
  743. };
  744. class BattleFieldInfo;
  745. class DLL_LINKAGE BattleField : public EntityIdentifier<BattleField>
  746. {
  747. public:
  748. using EntityIdentifier<BattleField>::EntityIdentifier;
  749. static const BattleField NONE;
  750. const BattleFieldInfo * getInfo() const;
  751. static si32 decode(const std::string & identifier);
  752. static std::string encode(const si32 index);
  753. };
  754. class DLL_LINKAGE BoatId : public EntityIdentifier<BoatId>
  755. {
  756. public:
  757. using EntityIdentifier<BoatId>::EntityIdentifier;
  758. static si32 decode(const std::string & identifier);
  759. static std::string encode(const si32 index);
  760. static const BoatId NONE;
  761. static const BoatId NECROPOLIS;
  762. static const BoatId CASTLE;
  763. static const BoatId FORTRESS;
  764. };
  765. class TerrainIdBase : public IdentifierBase
  766. {
  767. public:
  768. enum Type : int32_t
  769. {
  770. NATIVE_TERRAIN = -4,
  771. ANY_TERRAIN = -3,
  772. NONE = -1,
  773. FIRST_REGULAR_TERRAIN = 0,
  774. DIRT = 0,
  775. SAND,
  776. GRASS,
  777. SNOW,
  778. SWAMP,
  779. ROUGH,
  780. SUBTERRANEAN,
  781. LAVA,
  782. WATER,
  783. ROCK,
  784. ORIGINAL_REGULAR_TERRAIN_COUNT = ROCK
  785. };
  786. };
  787. class DLL_LINKAGE TerrainId : public EntityIdentifierWithEnum<TerrainId, TerrainIdBase>
  788. {
  789. public:
  790. using EntityIdentifierWithEnum<TerrainId, TerrainIdBase>::EntityIdentifierWithEnum;
  791. static si32 decode(const std::string & identifier);
  792. static std::string encode(const si32 index);
  793. static std::string entityType();
  794. const TerrainType * toEntity(const Services * service) const;
  795. };
  796. class ObstacleInfo;
  797. class Obstacle : public EntityIdentifier<Obstacle>
  798. {
  799. public:
  800. using EntityIdentifier<Obstacle>::EntityIdentifier;
  801. DLL_LINKAGE const ObstacleInfo * getInfo() const;
  802. };
  803. class DLL_LINKAGE SpellSchool : public StaticIdentifier<SpellSchool>
  804. {
  805. public:
  806. using StaticIdentifier<SpellSchool>::StaticIdentifier;
  807. static const SpellSchool ANY;
  808. static const SpellSchool AIR;
  809. static const SpellSchool FIRE;
  810. static const SpellSchool WATER;
  811. static const SpellSchool EARTH;
  812. static si32 decode(const std::string & identifier);
  813. static std::string encode(const si32 index);
  814. static std::string entityType();
  815. };
  816. class GameResIDBase : public IdentifierBase
  817. {
  818. public:
  819. enum Type : int32_t
  820. {
  821. WOOD = 0,
  822. MERCURY,
  823. ORE,
  824. SULFUR,
  825. CRYSTAL,
  826. GEMS,
  827. GOLD,
  828. MITHRIL,
  829. COUNT,
  830. WOOD_AND_ORE = 127, // special case for town bonus resource
  831. NONE = -1
  832. };
  833. };
  834. class DLL_LINKAGE GameResID : public StaticIdentifierWithEnum<GameResID, GameResIDBase>
  835. {
  836. public:
  837. using StaticIdentifierWithEnum<GameResID, GameResIDBase>::StaticIdentifierWithEnum;
  838. static si32 decode(const std::string & identifier);
  839. static std::string encode(const si32 index);
  840. static std::string entityType();
  841. static const std::array<GameResID, 7> & ALL_RESOURCES();
  842. };
  843. class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
  844. {
  845. public:
  846. BuildingTypeUniqueID(FactionID faction, BuildingID building );
  847. static si32 decode(const std::string & identifier);
  848. static std::string encode(const si32 index);
  849. BuildingID getBuilding() const;
  850. FactionID getFaction() const;
  851. using Identifier<BuildingTypeUniqueID>::Identifier;
  852. template <typename Handler>
  853. void serialize(Handler & h)
  854. {
  855. FactionID faction = getFaction();
  856. BuildingID building = getBuilding();
  857. h & faction;
  858. h & building;
  859. if (!h.saving)
  860. *this = BuildingTypeUniqueID(faction, building);
  861. }
  862. };
  863. class DLL_LINKAGE CampaignScenarioID : public StaticIdentifier<CampaignScenarioID>
  864. {
  865. public:
  866. using StaticIdentifier<CampaignScenarioID>::StaticIdentifier;
  867. static si32 decode(const std::string & identifier);
  868. static std::string encode(int32_t index);
  869. static const CampaignScenarioID NONE;
  870. };
  871. // Deprecated
  872. // TODO: remove
  873. using Obj = MapObjectID;
  874. using ETownType = FactionID;
  875. using EGameResID = GameResID;
  876. using River = RiverId;
  877. using Road = RoadId;
  878. using ETerrainId = TerrainId;
  879. VCMI_LIB_NAMESPACE_END