EntityIdentifiers.h 29 KB

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