EntityIdentifiers.h 28 KB

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