EntityIdentifiers.h 25 KB

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