EntityIdentifiers.h 24 KB

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