EntityIdentifiers.h 27 KB

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