EntityIdentifiers.h 23 KB

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