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 "NumericConstants.h"
  12. #include "IdentifierBase.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class Services;
  15. class Artifact;
  16. class ArtifactService;
  17. class Creature;
  18. class CreatureService;
  19. class HeroType;
  20. class CHero;
  21. class CHeroClass;
  22. class HeroClass;
  23. class HeroTypeService;
  24. class CFaction;
  25. class Faction;
  26. class Skill;
  27. class RoadType;
  28. class RiverType;
  29. class TerrainType;
  30. namespace spells
  31. {
  32. class Spell;
  33. class Service;
  34. }
  35. class CArtifact;
  36. class CArtifactInstance;
  37. class CCreature;
  38. class CHero;
  39. class CSpell;
  40. class CSkill;
  41. class CGameInfoCallback;
  42. class CNonConstInfoCallback;
  43. class ArtifactInstanceID : public StaticIdentifier<ArtifactInstanceID>
  44. {
  45. public:
  46. using StaticIdentifier<ArtifactInstanceID>::StaticIdentifier;
  47. };
  48. class QueryID : public StaticIdentifier<QueryID>
  49. {
  50. public:
  51. using StaticIdentifier<QueryID>::StaticIdentifier;
  52. DLL_LINKAGE static const QueryID NONE;
  53. DLL_LINKAGE static const QueryID CLIENT;
  54. };
  55. class BattleID : public StaticIdentifier<BattleID>
  56. {
  57. public:
  58. using StaticIdentifier<BattleID>::StaticIdentifier;
  59. DLL_LINKAGE static const BattleID NONE;
  60. };
  61. class DLL_LINKAGE ObjectInstanceID : public StaticIdentifier<ObjectInstanceID>
  62. {
  63. public:
  64. using StaticIdentifier<ObjectInstanceID>::StaticIdentifier;
  65. static const ObjectInstanceID NONE;
  66. static si32 decode(const std::string & identifier);
  67. static std::string encode(const si32 index);
  68. };
  69. class DLL_LINKAGE QuestInstanceID : public StaticIdentifier<QuestInstanceID>
  70. {
  71. public:
  72. using StaticIdentifier<QuestInstanceID>::StaticIdentifier;
  73. static const QuestInstanceID NONE;
  74. static si32 decode(const std::string & identifier);
  75. static std::string encode(const si32 index);
  76. };
  77. class HeroClassID : public EntityIdentifier<HeroClassID>
  78. {
  79. public:
  80. using EntityIdentifier<HeroClassID>::EntityIdentifier;
  81. ///json serialization helpers
  82. DLL_LINKAGE static si32 decode(const std::string & identifier);
  83. DLL_LINKAGE static std::string encode(const si32 index);
  84. static std::string entityType();
  85. const CHeroClass * toHeroClass() const;
  86. const HeroClass * toEntity(const Services * services) const;
  87. };
  88. class DLL_LINKAGE HeroTypeID : public EntityIdentifier<HeroTypeID>
  89. {
  90. public:
  91. using EntityIdentifier<HeroTypeID>::EntityIdentifier;
  92. ///json serialization helpers
  93. static si32 decode(const std::string & identifier);
  94. static std::string encode(const si32 index);
  95. static std::string entityType();
  96. const CHero * toHeroType() const;
  97. const HeroType * toEntity(const Services * services) const;
  98. static const HeroTypeID NONE;
  99. static const HeroTypeID RANDOM;
  100. static const HeroTypeID GEM; // aka Gem, Sorceress in campaign
  101. static const HeroTypeID SOLMYR; // aka Young Yog in campaigns
  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 const PrimarySkill EXPERIENCE;
  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. };
  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. BONE_DRAGON = 68, // for Skeleton Transformer
  722. TROGLODYTES = 70, // for Abandoned Mine
  723. MEDUSA = 76, // for Siege UI workaround
  724. HYDRA = 110, // for Skeleton Transformer
  725. CHAOS_HYDRA = 111, // for Skeleton Transformer
  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 = 0,
  761. SCUTTLE_BOAT = 1,
  762. VISIONS = 2,
  763. VIEW_EARTH = 3,
  764. DISGUISE = 4,
  765. VIEW_AIR = 5,
  766. FLY = 6,
  767. WATER_WALK = 7,
  768. DIMENSION_DOOR = 8,
  769. TOWN_PORTAL = 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. MITHRIL,
  946. COUNT,
  947. WOOD_AND_ORE = 127, // special case for town bonus resource
  948. COMMON = 0xFD, // campaign bonus
  949. RARE = 0xFE, // campaign bonus
  950. NONE = -1
  951. };
  952. };
  953. class DLL_LINKAGE GameResID : public StaticIdentifierWithEnum<GameResID, GameResIDBase>
  954. {
  955. public:
  956. using StaticIdentifierWithEnum<GameResID, GameResIDBase>::StaticIdentifierWithEnum;
  957. static si32 decode(const std::string & identifier);
  958. static std::string encode(const si32 index);
  959. static std::string entityType();
  960. static const std::array<GameResID, 7> & ALL_RESOURCES();
  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. // Deprecated
  991. // TODO: remove
  992. using Obj = MapObjectID;
  993. using ETownType = FactionID;
  994. using EGameResID = GameResID;
  995. using River = RiverId;
  996. using Road = RoadId;
  997. using ETerrainId = TerrainId;
  998. VCMI_LIB_NAMESPACE_END