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