EntityIdentifiers.h 28 KB

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