EntityIdentifiers.h 29 KB

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