EntityIdentifiers.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /*
  2. * EntityIdentifiers.cpp, 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. #include "StdInc.h"
  11. #ifndef VCMI_NO_EXTRA_VERSION
  12. #include "../Version.h"
  13. #endif
  14. #include <vcmi/Artifact.h>
  15. #include <vcmi/ArtifactService.h>
  16. #include <vcmi/Faction.h>
  17. #include <vcmi/FactionService.h>
  18. #include <vcmi/HeroType.h>
  19. #include <vcmi/HeroTypeService.h>
  20. #include <vcmi/HeroClass.h>
  21. #include <vcmi/HeroClassService.h>
  22. #include <vcmi/ResourceType.h>
  23. #include <vcmi/ResourceTypeService.h>
  24. #include <vcmi/Services.h>
  25. #include <vcmi/spells/Spell.h>
  26. #include <vcmi/spells/Service.h>
  27. #include "modding/IdentifierStorage.h"
  28. #include "modding/ModScope.h"
  29. #include "GameLibrary.h"
  30. #include "CCreatureHandler.h"
  31. #include "spells/CSpellHandler.h"
  32. #include "spells/SpellSchoolHandler.h"
  33. #include "CSkillHandler.h"
  34. #include "entities/artifact/CArtifact.h"
  35. #include "entities/faction/CFaction.h"
  36. #include "entities/hero/CHero.h"
  37. #include "entities/hero/CHeroClass.h"
  38. #include "entities/ResourceTypeHandler.h"
  39. #include "mapObjectConstructors/AObjectTypeHandler.h"
  40. #include "constants/StringConstants.h"
  41. #include "texts/CGeneralTextHandler.h"
  42. #include "TerrainHandler.h"
  43. #include "RiverHandler.h"
  44. #include "RoadHandler.h"
  45. #include "BattleFieldHandler.h"
  46. #include "ObstacleHandler.h"
  47. #include "MapLayerHandler.h"
  48. #include "mapObjectConstructors/CObjectClassesHandler.h"
  49. VCMI_LIB_NAMESPACE_BEGIN
  50. const CampaignScenarioID CampaignScenarioID::NONE(-1);
  51. const BattleID BattleID::NONE(-1);
  52. const QueryID QueryID::NONE(-1);
  53. const QueryID QueryID::CLIENT(-2);
  54. const HeroTypeID HeroTypeID::NONE(-1);
  55. const HeroTypeID HeroTypeID::RANDOM(-2);
  56. const HeroTypeID HeroTypeID::CAMP_STRONGEST(-3);
  57. const HeroTypeID HeroTypeID::CAMP_GENERATED(-2);
  58. const HeroTypeID HeroTypeID::CAMP_RANDOM(-1);
  59. const ObjectInstanceID ObjectInstanceID::NONE(-1);
  60. const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER(-2);
  61. const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER(-3);
  62. const SlotID SlotID::WAR_MACHINES_SLOT(-4);
  63. const SlotID SlotID::ARROW_TOWERS_SLOT(-5);
  64. const PlayerColor PlayerColor::SPECTATOR(-4);
  65. const PlayerColor PlayerColor::CANNOT_DETERMINE(-3);
  66. const PlayerColor PlayerColor::UNFLAGGABLE(-2);
  67. const PlayerColor PlayerColor::NEUTRAL(-1);
  68. const PlayerColor PlayerColor::PLAYER_LIMIT(PLAYER_LIMIT_I);
  69. const TeamID TeamID::NO_TEAM(-1);
  70. const SpellSchool SpellSchool::ANY(-1);
  71. const SpellSchool SpellSchool::AIR(0);
  72. const SpellSchool SpellSchool::FIRE(1);
  73. const SpellSchool SpellSchool::EARTH(2);
  74. const SpellSchool SpellSchool::WATER(3);
  75. const FactionID FactionID::NONE(-2);
  76. const FactionID FactionID::DEFAULT(-1);
  77. const FactionID FactionID::RANDOM(-1);
  78. const FactionID FactionID::ANY(-1);
  79. const FactionID FactionID::CASTLE(0);
  80. const FactionID FactionID::RAMPART(1);
  81. const FactionID FactionID::TOWER(2);
  82. const FactionID FactionID::INFERNO(3);
  83. const FactionID FactionID::NECROPOLIS(4);
  84. const FactionID FactionID::DUNGEON(5);
  85. const FactionID FactionID::STRONGHOLD(6);
  86. const FactionID FactionID::FORTRESS(7);
  87. const FactionID FactionID::CONFLUX(8);
  88. const FactionID FactionID::NEUTRAL(9);
  89. const PrimarySkill PrimarySkill::NONE(-1);
  90. const PrimarySkill PrimarySkill::ATTACK(0);
  91. const PrimarySkill PrimarySkill::DEFENSE(1);
  92. const PrimarySkill PrimarySkill::SPELL_POWER(2);
  93. const PrimarySkill PrimarySkill::KNOWLEDGE(3);
  94. const BoatId BoatId::NONE(-1);
  95. const BoatId BoatId::NECROPOLIS(0);
  96. const BoatId BoatId::CASTLE(1);
  97. const BoatId BoatId::FORTRESS(2);
  98. const RiverId RiverId::NO_RIVER(0);
  99. const RiverId RiverId::WATER_RIVER(1);
  100. const RiverId RiverId::ICY_RIVER(2);
  101. const RiverId RiverId::MUD_RIVER(3);
  102. const RiverId RiverId::LAVA_RIVER(4);
  103. const RoadId RoadId::NO_ROAD(0);
  104. const RoadId RoadId::DIRT_ROAD(1);
  105. const RoadId RoadId::GRAVEL_ROAD(2);
  106. const RoadId RoadId::COBBLESTONE_ROAD(3);
  107. const MapLayerId MapLayerId::NONE(-1);
  108. const MapLayerId MapLayerId::SURFACE(0);
  109. const MapLayerId MapLayerId::UNDERGROUND(1);
  110. const MapLayerId MapLayerId::UNKNOWN(2);
  111. namespace GameConstants
  112. {
  113. #ifdef VCMI_NO_EXTRA_VERSION
  114. const std::string VCMI_VERSION = "VCMI " VCMI_VERSION_STRING;
  115. #else
  116. const std::string VCMI_VERSION = "VCMI " VCMI_VERSION_STRING "." + std::string{GIT_SHA1};
  117. #endif
  118. }
  119. BuildingTypeUniqueID::BuildingTypeUniqueID(FactionID factionID, BuildingID buildingID ):
  120. BuildingTypeUniqueID(factionID.getNum() * 0x10000 + buildingID.getNum())
  121. {
  122. assert(factionID.getNum() >= 0);
  123. assert(factionID.getNum() < 0x10000);
  124. assert(buildingID.getNum() >= 0);
  125. assert(buildingID.getNum() < 0x10000);
  126. }
  127. std::string ArtifactInstanceID::encode(const si32 index)
  128. {
  129. return "";
  130. }
  131. BuildingID BuildingTypeUniqueID::getBuilding() const
  132. {
  133. return BuildingID(getNum() % 0x10000);
  134. }
  135. FactionID BuildingTypeUniqueID::getFaction() const
  136. {
  137. return FactionID(getNum() / 0x10000);
  138. }
  139. int32_t IdentifierBase::resolveIdentifier(const std::string & entityType, const std::string identifier)
  140. {
  141. if (identifier.empty())
  142. return -1;
  143. auto rawId = LIBRARY->identifiers()->getIdentifier(ModScope::scopeGame(), entityType, identifier);
  144. if (rawId)
  145. return rawId.value();
  146. size_t semicolon = identifier.find(':');
  147. if (semicolon != std::string::npos)
  148. {
  149. auto rawId2 = LIBRARY->identifiers()->getIdentifier(ModScope::scopeGame(), entityType, identifier.substr(semicolon + 1));
  150. if (rawId2)
  151. return rawId2.value();
  152. }
  153. throw IdentifierResolutionException(identifier);
  154. }
  155. si32 HeroClassID::decode(const std::string & identifier)
  156. {
  157. return resolveIdentifier("heroClass", identifier);
  158. }
  159. std::string HeroClassID::encode(const si32 index)
  160. {
  161. if (index == -1)
  162. return "";
  163. return LIBRARY->heroClasses()->getByIndex(index)->getJsonKey();
  164. }
  165. std::string HeroClassID::entityType()
  166. {
  167. return "heroClass";
  168. }
  169. const CHeroClass * HeroClassID::toHeroClass() const
  170. {
  171. return dynamic_cast<const CHeroClass*>(toEntity(LIBRARY));
  172. }
  173. const HeroClass * HeroClassID::toEntity(const Services * services) const
  174. {
  175. return services->heroClasses()->getByIndex(num);
  176. }
  177. si32 ObjectInstanceID::decode(const std::string & identifier)
  178. {
  179. return std::stoi(identifier);
  180. }
  181. std::string ObjectInstanceID::encode(const si32 index)
  182. {
  183. return std::to_string(index);
  184. }
  185. si32 CampaignScenarioID::decode(const std::string & identifier)
  186. {
  187. return std::stoi(identifier);
  188. }
  189. std::string CampaignScenarioID::encode(const si32 index)
  190. {
  191. return std::to_string(index);
  192. }
  193. std::string MapObjectID::encode(int32_t index)
  194. {
  195. if (index == -1)
  196. return "";
  197. return LIBRARY->objtypeh->getJsonKey(MapObjectID(index));
  198. }
  199. si32 MapObjectID::decode(const std::string & identifier)
  200. {
  201. return resolveIdentifier("object", identifier);
  202. }
  203. std::string MapObjectSubID::encode(MapObjectID primaryID, int32_t index)
  204. {
  205. if (index == -1)
  206. return "";
  207. if(primaryID == Obj::PRISON || primaryID == Obj::HERO)
  208. return HeroTypeID::encode(index);
  209. if (primaryID == Obj::SPELL_SCROLL)
  210. return SpellID::encode(index);
  211. return LIBRARY->objtypeh->getHandlerFor(primaryID, index)->getJsonKey();
  212. }
  213. si32 MapObjectSubID::decode(MapObjectID primaryID, const std::string & identifier)
  214. {
  215. if(primaryID == Obj::PRISON || primaryID == Obj::HERO)
  216. return HeroTypeID::decode(identifier);
  217. if (primaryID == Obj::SPELL_SCROLL)
  218. return SpellID::decode(identifier);
  219. return resolveIdentifier(LIBRARY->objtypeh->getJsonKey(primaryID), identifier);
  220. }
  221. std::string BoatId::encode(int32_t index)
  222. {
  223. if (index == -1)
  224. return "";
  225. return LIBRARY->objtypeh->getHandlerFor(MapObjectID::BOAT, index)->getJsonKey();
  226. }
  227. si32 BoatId::decode(const std::string & identifier)
  228. {
  229. return resolveIdentifier("core:boat", identifier);
  230. }
  231. si32 HeroTypeID::decode(const std::string & identifier)
  232. {
  233. if (identifier == "random")
  234. return -2;
  235. if (identifier == "strongest")
  236. return -3;
  237. return resolveIdentifier("hero", identifier);
  238. }
  239. std::string HeroTypeID::encode(const si32 index)
  240. {
  241. if (index == -1)
  242. return "";
  243. if (index == -2)
  244. return "random";
  245. if (index == -3)
  246. return "strongest";
  247. return LIBRARY->heroTypes()->getByIndex(index)->getJsonKey();
  248. }
  249. std::string HeroTypeID::entityType()
  250. {
  251. return "hero";
  252. }
  253. const CArtifact * ArtifactIDBase::toArtifact() const
  254. {
  255. return dynamic_cast<const CArtifact*>(toEntity(LIBRARY));
  256. }
  257. const Artifact * ArtifactIDBase::toEntity(const Services * services) const
  258. {
  259. return services->artifacts()->getByIndex(num);
  260. }
  261. si32 ArtifactID::decode(const std::string & identifier)
  262. {
  263. return resolveIdentifier("artifact", identifier);
  264. }
  265. std::string ArtifactID::encode(const si32 index)
  266. {
  267. if (index == -1)
  268. return "";
  269. return LIBRARY->artifacts()->getByIndex(index)->getJsonKey();
  270. }
  271. std::string ArtifactID::entityType()
  272. {
  273. return "artifact";
  274. }
  275. si32 SecondarySkill::decode(const std::string& identifier)
  276. {
  277. return resolveIdentifier("secondarySkill", identifier);
  278. }
  279. std::string SecondarySkill::encode(const si32 index)
  280. {
  281. if (index == -1)
  282. return "";
  283. return LIBRARY->skills()->getById(SecondarySkill(index))->getJsonKey();
  284. }
  285. const CSkill * SecondarySkill::toSkill() const
  286. {
  287. return dynamic_cast<const CSkill *>(toEntity(LIBRARY));
  288. }
  289. const Skill * SecondarySkill::toEntity(const Services * services) const
  290. {
  291. return services->skills()->getByIndex(num);
  292. }
  293. const CCreature * CreatureIDBase::toCreature() const
  294. {
  295. return (*LIBRARY->creh)[num];
  296. }
  297. const Creature * CreatureIDBase::toEntity(const Services * services) const
  298. {
  299. return toEntity(services->creatures());
  300. }
  301. const Creature * CreatureIDBase::toEntity(const CreatureService * creatures) const
  302. {
  303. return creatures->getByIndex(num);
  304. }
  305. si32 CreatureID::decode(const std::string & identifier)
  306. {
  307. return resolveIdentifier("creature", identifier);
  308. }
  309. std::string CreatureID::encode(const si32 index)
  310. {
  311. if (index == -1)
  312. return "";
  313. return LIBRARY->creatures()->getById(CreatureID(index))->getJsonKey();
  314. }
  315. std::string CreatureID::entityType()
  316. {
  317. return "creature";
  318. }
  319. const CSpell * SpellIDBase::toSpell() const
  320. {
  321. return dynamic_cast<const CSpell*>(toEntity(LIBRARY));
  322. }
  323. const spells::Spell * SpellIDBase::toEntity(const Services * services) const
  324. {
  325. return toEntity(services->spells());
  326. }
  327. const spells::Spell * SpellIDBase::toEntity(const spells::Service * service) const
  328. {
  329. return service->getByIndex(num);
  330. }
  331. const CHero * HeroTypeID::toHeroType() const
  332. {
  333. return dynamic_cast<const CHero*>(toEntity(LIBRARY));
  334. }
  335. const HeroType * HeroTypeID::toEntity(const Services * services) const
  336. {
  337. return services->heroTypes()->getByIndex(num);
  338. }
  339. const Resource * GameResID::toResource() const
  340. {
  341. return dynamic_cast<const Resource*>(toEntity(LIBRARY));
  342. }
  343. const ResourceType * GameResID::toEntity(const Services * services) const
  344. {
  345. return services->resources()->getByIndex(num);
  346. }
  347. si32 SpellID::decode(const std::string & identifier)
  348. {
  349. if (identifier == "preset")
  350. return SpellID::PRESET;
  351. if (identifier == "spellbook_preset")
  352. return SpellID::SPELLBOOK_PRESET;
  353. return resolveIdentifier("spell", identifier);
  354. }
  355. std::string SpellID::encode(const si32 index)
  356. {
  357. if (index == -1)
  358. return "";
  359. if (index == SpellID::PRESET)
  360. return "preset";
  361. if (index == SpellID::SPELLBOOK_PRESET)
  362. return "spellbook_preset";
  363. return LIBRARY->spells()->getByIndex(index)->getJsonKey();
  364. }
  365. si32 BattleField::decode(const std::string & identifier)
  366. {
  367. return resolveIdentifier("battlefield", identifier);
  368. }
  369. std::string BattleField::encode(const si32 index)
  370. {
  371. return LIBRARY->battlefields()->getByIndex(index)->getJsonKey();
  372. }
  373. std::string SpellID::entityType()
  374. {
  375. return "spell";
  376. }
  377. bool PlayerColor::isValidPlayer() const
  378. {
  379. return num >= 0 && num < PLAYER_LIMIT_I;
  380. }
  381. bool PlayerColor::isSpectator() const
  382. {
  383. return num == SPECTATOR.num;
  384. }
  385. std::string PlayerColor::toString() const
  386. {
  387. return encode(num);
  388. }
  389. si32 PlayerColor::decode(const std::string & identifier)
  390. {
  391. return vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, identifier);
  392. }
  393. std::string PlayerColor::encode(const si32 index)
  394. {
  395. if (index == -1)
  396. return "neutral";
  397. if (index < 0 || index >= std::size(GameConstants::PLAYER_COLOR_NAMES))
  398. {
  399. assert(0);
  400. return "invalid";
  401. }
  402. return GameConstants::PLAYER_COLOR_NAMES[index];
  403. }
  404. std::string PlayerColor::entityType()
  405. {
  406. return "playerColor";
  407. }
  408. si32 PrimarySkill::decode(const std::string& identifier)
  409. {
  410. return resolveIdentifier(entityType(), identifier);
  411. }
  412. std::string PrimarySkill::encode(const si32 index)
  413. {
  414. return NPrimarySkill::names[index];
  415. }
  416. std::string PrimarySkill::entityType()
  417. {
  418. return "primarySkill";
  419. }
  420. si32 FactionID::decode(const std::string & identifier)
  421. {
  422. return resolveIdentifier(entityType(), identifier);
  423. }
  424. std::string FactionID::encode(const si32 index)
  425. {
  426. if (index == -1)
  427. return "";
  428. return LIBRARY->factions()->getByIndex(index)->getJsonKey();
  429. }
  430. std::string FactionID::entityType()
  431. {
  432. return "faction";
  433. }
  434. const CFaction * FactionID::toFaction() const
  435. {
  436. return dynamic_cast<const CFaction*>(toEntity(LIBRARY));
  437. }
  438. const Faction * FactionID::toEntity(const Services * service) const
  439. {
  440. return service->factions()->getByIndex(num);
  441. }
  442. si32 TerrainId::decode(const std::string & identifier)
  443. {
  444. if (identifier == "native")
  445. return TerrainId::NATIVE_TERRAIN;
  446. return resolveIdentifier(entityType(), identifier);
  447. }
  448. std::string TerrainId::encode(const si32 index)
  449. {
  450. if (index == TerrainId::NONE)
  451. return "";
  452. if (index == TerrainId::NATIVE_TERRAIN)
  453. return "native";
  454. return LIBRARY->terrainTypeHandler->getByIndex(index)->getJsonKey();
  455. }
  456. std::string TerrainId::entityType()
  457. {
  458. return "terrain";
  459. }
  460. si32 RoadId::decode(const std::string & identifier)
  461. {
  462. if (identifier.empty())
  463. return RoadId::NO_ROAD.getNum();
  464. return resolveIdentifier(entityType(), identifier);
  465. }
  466. std::string RoadId::encode(const si32 index)
  467. {
  468. if (index == RoadId::NO_ROAD.getNum())
  469. return "";
  470. return LIBRARY->roadTypeHandler->getByIndex(index)->getJsonKey();
  471. }
  472. std::string RoadId::entityType()
  473. {
  474. return "road";
  475. }
  476. si32 RiverId::decode(const std::string & identifier)
  477. {
  478. if (identifier.empty())
  479. return RiverId::NO_RIVER.getNum();
  480. return resolveIdentifier(entityType(), identifier);
  481. }
  482. std::string RiverId::encode(const si32 index)
  483. {
  484. if (index == RiverId::NO_RIVER.getNum())
  485. return "";
  486. return LIBRARY->riverTypeHandler->getByIndex(index)->getJsonKey();
  487. }
  488. std::string RiverId::entityType()
  489. {
  490. return "river";
  491. }
  492. si32 MapLayerId::decode(const std::string & identifier)
  493. {
  494. if (identifier.empty())
  495. return MapLayerId::NONE.getNum();
  496. return resolveIdentifier(entityType(), identifier);
  497. }
  498. std::string MapLayerId::encode(const si32 index)
  499. {
  500. if (index == MapLayerId::NONE.getNum())
  501. return "";
  502. return LIBRARY->mapLayerHandler->getByIndex(index)->getJsonKey();
  503. }
  504. std::string MapLayerId::entityType()
  505. {
  506. return "mapLayer";
  507. }
  508. const MapLayerType * MapLayerId::toEntity(const Services * services) const
  509. {
  510. return LIBRARY->mapLayerHandler->getByIndex(num);
  511. }
  512. const TerrainType * TerrainId::toEntity(const Services * service) const
  513. {
  514. return LIBRARY->terrainTypeHandler->getByIndex(num);
  515. }
  516. const RoadType * RoadId::toEntity(const Services * service) const
  517. {
  518. return LIBRARY->roadTypeHandler->getByIndex(num);
  519. }
  520. const RiverType * RiverId::toEntity(const Services * service) const
  521. {
  522. return LIBRARY->riverTypeHandler->getByIndex(num);
  523. }
  524. const BattleField BattleField::NONE;
  525. const BattleFieldInfo * BattleField::getInfo() const
  526. {
  527. return LIBRARY->battlefields()->getById(*this);
  528. }
  529. const ObstacleInfo * Obstacle::getInfo() const
  530. {
  531. return LIBRARY->obstacles()->getById(*this);
  532. }
  533. si32 SpellSchool::decode(const std::string & identifier)
  534. {
  535. return resolveIdentifier(entityType(), identifier);
  536. }
  537. std::string SpellSchool::encode(const si32 index)
  538. {
  539. if (index == ANY.getNum())
  540. return "any";
  541. return LIBRARY->spellSchoolHandler->getById(SpellSchool(index))->getJsonKey();
  542. }
  543. std::string SpellSchool::entityType()
  544. {
  545. return "spellSchool";
  546. }
  547. si32 GameResID::decode(const std::string & identifier)
  548. {
  549. return resolveIdentifier(entityType(), identifier);
  550. }
  551. std::string GameResID::encode(const si32 index)
  552. {
  553. return GameResID(index).toResource()->getJsonKey();
  554. }
  555. si32 BuildingTypeUniqueID::decode(const std::string & identifier)
  556. {
  557. assert(0); //TODO
  558. return -1;
  559. }
  560. std::string BuildingTypeUniqueID::encode(const si32 index)
  561. {
  562. assert(0); // TODO
  563. return "";
  564. }
  565. std::string GameResID::entityType()
  566. {
  567. return "resource";
  568. }
  569. const std::array<PlayerColor, PlayerColor::PLAYER_LIMIT_I> & PlayerColor::ALL_PLAYERS()
  570. {
  571. static const std::array allPlayers = {
  572. PlayerColor(0),
  573. PlayerColor(1),
  574. PlayerColor(2),
  575. PlayerColor(3),
  576. PlayerColor(4),
  577. PlayerColor(5),
  578. PlayerColor(6),
  579. PlayerColor(7)
  580. };
  581. return allPlayers;
  582. }
  583. const std::array<PrimarySkill, 4> & PrimarySkill::ALL_SKILLS()
  584. {
  585. static const std::array allSkills = {
  586. PrimarySkill(ATTACK),
  587. PrimarySkill(DEFENSE),
  588. PrimarySkill(SPELL_POWER),
  589. PrimarySkill(KNOWLEDGE)
  590. };
  591. return allSkills;
  592. }
  593. std::string SecondarySkill::entityType()
  594. {
  595. return "secondarySkill";
  596. }
  597. std::string BuildingID::encode(int32_t index)
  598. {
  599. return std::to_string(index);
  600. }
  601. si32 BuildingID::decode(const std::string & identifier)
  602. {
  603. return std::stoi(identifier);
  604. }
  605. VCMI_LIB_NAMESPACE_END