EntityIdentifiers.h 25 KB

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