EntityIdentifiers.h 27 KB

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