EntityIdentifiers.h 28 KB

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