EntityIdentifiers.h 28 KB

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