EntityIdentifiers.h 26 KB

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