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