EntityIdentifiers.h 26 KB

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