EntityIdentifiers.h 23 KB

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