EntityIdentifiers.h 23 KB

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