EntityIdentifiers.h 26 KB

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