EntityIdentifiers.h 29 KB

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