EntityIdentifiers.h 27 KB

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