EntityIdentifiers.h 27 KB

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