CHeroHandler.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. #include "StdInc.h"
  2. #include "CHeroHandler.h"
  3. #include "CGeneralTextHandler.h"
  4. #include "filesystem/Filesystem.h"
  5. #include "VCMI_Lib.h"
  6. #include "JsonNode.h"
  7. #include "StringConstants.h"
  8. #include "BattleHex.h"
  9. #include "CCreatureHandler.h"
  10. #include "CModHandler.h"
  11. #include "CTownHandler.h"
  12. #include "mapObjects/CObjectHandler.h" //for hero specialty
  13. #include <math.h>
  14. #include "mapObjects/CObjectClassesHandler.h"
  15. /*
  16. * CHeroHandler.cpp, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const //picks secondary skill out from given possibilities
  25. {
  26. int totalProb = 0;
  27. for(auto & possible : possibles)
  28. {
  29. totalProb += secSkillProbability[possible];
  30. }
  31. if (totalProb != 0) // may trigger if set contains only banned skills (0 probability)
  32. {
  33. auto ran = rand.nextInt(totalProb - 1);
  34. for(auto & possible : possibles)
  35. {
  36. ran -= secSkillProbability[possible];
  37. if(ran < 0)
  38. {
  39. return possible;
  40. }
  41. }
  42. }
  43. // FIXME: select randomly? How H3 handles such rare situation?
  44. return *possibles.begin();
  45. }
  46. bool CHeroClass::isMagicHero() const
  47. {
  48. return affinity == MAGIC;
  49. }
  50. EAlignment::EAlignment CHeroClass::getAlignment() const
  51. {
  52. return EAlignment::EAlignment(VLC->townh->factions[faction]->alignment);
  53. }
  54. CHeroClass::CHeroClass()
  55. : commander(nullptr)
  56. {
  57. }
  58. std::vector<BattleHex> CObstacleInfo::getBlocked(BattleHex hex) const
  59. {
  60. std::vector<BattleHex> ret;
  61. if(isAbsoluteObstacle)
  62. {
  63. assert(!hex.isValid());
  64. range::copy(blockedTiles, std::back_inserter(ret));
  65. return ret;
  66. }
  67. for(int offset : blockedTiles)
  68. {
  69. BattleHex toBlock = hex + offset;
  70. if((hex.getY() & 1) && !(toBlock.getY() & 1))
  71. toBlock += BattleHex::LEFT;
  72. if(!toBlock.isValid())
  73. logGlobal->errorStream() << "Misplaced obstacle!";
  74. else
  75. ret.push_back(toBlock);
  76. }
  77. return ret;
  78. }
  79. bool CObstacleInfo::isAppropriate(ETerrainType terrainType, int specialBattlefield /*= -1*/) const
  80. {
  81. if(specialBattlefield != -1)
  82. return vstd::contains(allowedSpecialBfields, specialBattlefield);
  83. return vstd::contains(allowedTerrains, terrainType);
  84. }
  85. CHeroClass * CHeroClassHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
  86. {
  87. std::string affinityStr[2] = { "might", "magic" };
  88. auto heroClass = new CHeroClass();
  89. heroClass->identifier = identifier;
  90. heroClass->imageBattleFemale = node["animation"]["battle"]["female"].String();
  91. heroClass->imageBattleMale = node["animation"]["battle"]["male"].String();
  92. //MODS COMPATIBILITY FOR 0.96
  93. heroClass->imageMapFemale = node["animation"]["map"]["female"].String();
  94. heroClass->imageMapMale = node["animation"]["map"]["male"].String();
  95. heroClass->name = node["name"].String();
  96. heroClass->affinity = vstd::find_pos(affinityStr, node["affinity"].String());
  97. for(const std::string & pSkill : PrimarySkill::names)
  98. {
  99. heroClass->primarySkillInitial.push_back(node["primarySkills"][pSkill].Float());
  100. heroClass->primarySkillLowLevel.push_back(node["lowLevelChance"][pSkill].Float());
  101. heroClass->primarySkillHighLevel.push_back(node["highLevelChance"][pSkill].Float());
  102. }
  103. for(const std::string & secSkill : NSecondarySkill::names)
  104. {
  105. heroClass->secSkillProbability.push_back(node["secondarySkills"][secSkill].Float());
  106. }
  107. VLC->modh->identifiers.requestIdentifier ("creature", node["commander"],
  108. [=](si32 commanderID)
  109. {
  110. heroClass->commander = VLC->creh->creatures[commanderID];
  111. });
  112. heroClass->defaultTavernChance = node["defaultTavern"].Float();
  113. for(auto & tavern : node["tavern"].Struct())
  114. {
  115. int value = tavern.second.Float();
  116. VLC->modh->identifiers.requestIdentifier(tavern.second.meta, "faction", tavern.first,
  117. [=](si32 factionID)
  118. {
  119. heroClass->selectionProbability[factionID] = value;
  120. });
  121. }
  122. VLC->modh->identifiers.requestIdentifier("faction", node["faction"],
  123. [=](si32 factionID)
  124. {
  125. heroClass->faction = factionID;
  126. });
  127. return heroClass;
  128. }
  129. std::vector<JsonNode> CHeroClassHandler::loadLegacyData(size_t dataSize)
  130. {
  131. heroClasses.resize(dataSize);
  132. std::vector<JsonNode> h3Data;
  133. h3Data.reserve(dataSize);
  134. CLegacyConfigParser parser("DATA/HCTRAITS.TXT");
  135. parser.endLine(); // header
  136. parser.endLine();
  137. for (size_t i=0; i<dataSize; i++)
  138. {
  139. JsonNode entry;
  140. entry["name"].String() = parser.readString();
  141. parser.readNumber(); // unused aggression
  142. for (auto & name : PrimarySkill::names)
  143. entry["primarySkills"][name].Float() = parser.readNumber();
  144. for (auto & name : PrimarySkill::names)
  145. entry["lowLevelChance"][name].Float() = parser.readNumber();
  146. for (auto & name : PrimarySkill::names)
  147. entry["highLevelChance"][name].Float() = parser.readNumber();
  148. for (auto & name : NSecondarySkill::names)
  149. entry["secondarySkills"][name].Float() = parser.readNumber();
  150. for(auto & name : ETownType::names)
  151. entry["tavern"][name].Float() = parser.readNumber();
  152. parser.endLine();
  153. h3Data.push_back(entry);
  154. }
  155. return h3Data;
  156. }
  157. void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  158. {
  159. auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
  160. object->id = heroClasses.size();
  161. heroClasses.push_back(object);
  162. VLC->modh->identifiers.requestIdentifier(scope, "object", "hero", [=](si32 index)
  163. {
  164. JsonNode classConf = data["mapObject"];
  165. classConf["heroClass"].String() = name;
  166. classConf.setMeta(scope);
  167. VLC->objtypeh->loadSubObject(name, classConf, index, object->id);
  168. });
  169. VLC->modh->identifiers.registerObject(scope, "heroClass", name, object->id);
  170. }
  171. void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  172. {
  173. auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
  174. object->id = index;
  175. assert(heroClasses[index] == nullptr); // ensure that this id was not loaded before
  176. heroClasses[index] = object;
  177. VLC->modh->identifiers.requestIdentifier(scope, "object", "hero", [=](si32 index)
  178. {
  179. JsonNode classConf = data["mapObject"];
  180. classConf["heroClass"].String() = name;
  181. classConf.setMeta(scope);
  182. VLC->objtypeh->loadSubObject(name, classConf, index, object->id);
  183. });
  184. VLC->modh->identifiers.registerObject(scope, "heroClass", name, object->id);
  185. }
  186. void CHeroClassHandler::afterLoadFinalization()
  187. {
  188. // for each pair <class, town> set selection probability if it was not set before in tavern entries
  189. for (CHeroClass * heroClass : heroClasses)
  190. {
  191. for (CFaction * faction : VLC->townh->factions)
  192. {
  193. if (!faction->town)
  194. continue;
  195. if (heroClass->selectionProbability.count(faction->index))
  196. continue;
  197. float chance = heroClass->defaultTavernChance * faction->town->defaultTavernChance;
  198. heroClass->selectionProbability[faction->index] = static_cast<int>(sqrt(chance) + 0.5); //FIXME: replace with std::round once MVS supports it
  199. }
  200. }
  201. for (CHeroClass * hc : heroClasses)
  202. {
  203. if (!hc->imageMapMale.empty())
  204. {
  205. JsonNode templ;
  206. templ["animation"].String() = hc->imageMapMale;
  207. VLC->objtypeh->getHandlerFor(Obj::HERO, hc->id)->addTemplate(templ);
  208. }
  209. }
  210. }
  211. std::vector<bool> CHeroClassHandler::getDefaultAllowed() const
  212. {
  213. return std::vector<bool>(heroClasses.size(), true);
  214. }
  215. CHeroClassHandler::~CHeroClassHandler()
  216. {
  217. for(auto heroClass : heroClasses)
  218. {
  219. delete heroClass.get();
  220. }
  221. }
  222. CHeroHandler::~CHeroHandler()
  223. {
  224. for(auto hero : heroes)
  225. delete hero.get();
  226. }
  227. CHeroHandler::CHeroHandler()
  228. {
  229. VLC->heroh = this;
  230. for (int i = 0; i < GameConstants::SKILL_QUANTITY; ++i)
  231. {
  232. VLC->modh->identifiers.registerObject("core", "skill", NSecondarySkill::names[i], i);
  233. }
  234. loadObstacles();
  235. loadTerrains();
  236. for (int i = 0; i < GameConstants::TERRAIN_TYPES; ++i)
  237. {
  238. VLC->modh->identifiers.registerObject("core", "terrain", GameConstants::TERRAIN_NAMES[i], i);
  239. }
  240. loadBallistics();
  241. loadExperience();
  242. }
  243. CHero * CHeroHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
  244. {
  245. auto hero = new CHero;
  246. hero->identifier = identifier;
  247. hero->sex = node["female"].Bool();
  248. hero->special = node["special"].Bool();
  249. hero->name = node["texts"]["name"].String();
  250. hero->biography = node["texts"]["biography"].String();
  251. hero->specName = node["texts"]["specialty"]["name"].String();
  252. hero->specTooltip = node["texts"]["specialty"]["tooltip"].String();
  253. hero->specDescr = node["texts"]["specialty"]["description"].String();
  254. hero->iconSpecSmall = node["images"]["specialtySmall"].String();
  255. hero->iconSpecLarge = node["images"]["specialtyLarge"].String();
  256. hero->portraitSmall = node["images"]["small"].String();
  257. hero->portraitLarge = node["images"]["large"].String();
  258. loadHeroArmy(hero, node);
  259. loadHeroSkills(hero, node);
  260. loadHeroSpecialty(hero, node);
  261. VLC->modh->identifiers.requestIdentifier("heroClass", node["class"],
  262. [=](si32 classID)
  263. {
  264. hero->heroClass = classes.heroClasses[classID];
  265. });
  266. return hero;
  267. }
  268. void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node)
  269. {
  270. assert(node["army"].Vector().size() <= 3); // anything bigger is useless - army initialization uses up to 3 slots
  271. hero->initialArmy.resize(node["army"].Vector().size());
  272. for (size_t i=0; i< hero->initialArmy.size(); i++)
  273. {
  274. const JsonNode & source = node["army"].Vector()[i];
  275. hero->initialArmy[i].minAmount = source["min"].Float();
  276. hero->initialArmy[i].maxAmount = source["max"].Float();
  277. assert(hero->initialArmy[i].minAmount <= hero->initialArmy[i].maxAmount);
  278. VLC->modh->identifiers.requestIdentifier("creature", source["creature"], [=](si32 creature)
  279. {
  280. hero->initialArmy[i].creature = CreatureID(creature);
  281. });
  282. }
  283. }
  284. void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node)
  285. {
  286. for(const JsonNode &set : node["skills"].Vector())
  287. {
  288. int skillLevel = boost::range::find(NSecondarySkill::levels, set["level"].String()) - std::begin(NSecondarySkill::levels);
  289. if (skillLevel < SecSkillLevel::LEVELS_SIZE)
  290. {
  291. size_t currentIndex = hero->secSkillsInit.size();
  292. hero->secSkillsInit.push_back(std::make_pair(SecondarySkill(-1), skillLevel));
  293. VLC->modh->identifiers.requestIdentifier("skill", set["skill"], [=](si32 id)
  294. {
  295. hero->secSkillsInit[currentIndex].first = SecondarySkill(id);
  296. });
  297. }
  298. else
  299. {
  300. logGlobal->errorStream() << "Unknown skill level: " <<set["level"].String();
  301. }
  302. }
  303. // spellbook is considered present if hero have "spellbook" entry even when this is an empty set (0 spells)
  304. hero->haveSpellBook = !node["spellbook"].isNull();
  305. for(const JsonNode & spell : node["spellbook"].Vector())
  306. {
  307. VLC->modh->identifiers.requestIdentifier("spell", spell,
  308. [=](si32 spellID)
  309. {
  310. hero->spells.insert(SpellID(spellID));
  311. });
  312. }
  313. }
  314. void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
  315. {
  316. //deprecated, used only for original spciealties
  317. for(const JsonNode &specialty : node["specialties"].Vector())
  318. {
  319. SSpecialtyInfo spec;
  320. spec.type = specialty["type"].Float();
  321. spec.val = specialty["val"].Float();
  322. spec.subtype = specialty["subtype"].Float();
  323. spec.additionalinfo = specialty["info"].Float();
  324. hero->spec.push_back(spec); //put a copy of dummy
  325. }
  326. //new format, using bonus system
  327. for(const JsonNode &specialty : node["specialty"].Vector())
  328. {
  329. SSpecialtyBonus hs;
  330. hs.growsWithLevel = specialty["growsWithLevel"].Bool();
  331. for (const JsonNode & bonus : specialty["bonuses"].Vector())
  332. {
  333. auto b = JsonUtils::parseBonus(bonus);
  334. hs.bonuses.push_back (b);
  335. }
  336. hero->specialty.push_back (hs); //now, how to get CGHeroInstance from it?
  337. }
  338. }
  339. void CHeroHandler::loadExperience()
  340. {
  341. expPerLevel.push_back(0);
  342. expPerLevel.push_back(1000);
  343. expPerLevel.push_back(2000);
  344. expPerLevel.push_back(3200);
  345. expPerLevel.push_back(4600);
  346. expPerLevel.push_back(6200);
  347. expPerLevel.push_back(8000);
  348. expPerLevel.push_back(10000);
  349. expPerLevel.push_back(12200);
  350. expPerLevel.push_back(14700);
  351. expPerLevel.push_back(17500);
  352. expPerLevel.push_back(20600);
  353. expPerLevel.push_back(24320);
  354. expPerLevel.push_back(28784);
  355. expPerLevel.push_back(34140);
  356. while (expPerLevel[expPerLevel.size() - 1] > expPerLevel[expPerLevel.size() - 2])
  357. {
  358. int i = expPerLevel.size() - 1;
  359. expPerLevel.push_back (expPerLevel[i] + (expPerLevel[i] - expPerLevel[i-1]) * 1.2);
  360. }
  361. expPerLevel.pop_back();//last value is broken
  362. }
  363. void CHeroHandler::loadObstacles()
  364. {
  365. auto loadObstacles = [](const JsonNode &node, bool absolute, std::map<int, CObstacleInfo> &out)
  366. {
  367. for(const JsonNode &obs : node.Vector())
  368. {
  369. int ID = obs["id"].Float();
  370. CObstacleInfo & obi = out[ID];
  371. obi.ID = ID;
  372. obi.defName = obs["defname"].String();
  373. obi.width = obs["width"].Float();
  374. obi.height = obs["height"].Float();
  375. obi.allowedTerrains = obs["allowedTerrain"].convertTo<std::vector<ETerrainType> >();
  376. obi.allowedSpecialBfields = obs["specialBattlefields"].convertTo<std::vector<BFieldType> >();
  377. obi.blockedTiles = obs["blockedTiles"].convertTo<std::vector<si16> >();
  378. obi.isAbsoluteObstacle = absolute;
  379. }
  380. };
  381. const JsonNode config(ResourceID("config/obstacles.json"));
  382. loadObstacles(config["obstacles"], false, obstacles);
  383. loadObstacles(config["absoluteObstacles"], true, absoluteObstacles);
  384. //loadObstacles(config["moats"], true, moats);
  385. }
  386. /// convert h3-style ID (e.g. Gobin Wolf Rider) to vcmi (e.g. goblinWolfRider)
  387. static std::string genRefName(std::string input)
  388. {
  389. boost::algorithm::replace_all(input, " ", ""); //remove spaces
  390. input[0] = std::tolower(input[0]); // to camelCase
  391. return input;
  392. }
  393. void CHeroHandler::loadBallistics()
  394. {
  395. CLegacyConfigParser ballParser("DATA/BALLIST.TXT");
  396. ballParser.endLine(); //header
  397. ballParser.endLine();
  398. do
  399. {
  400. ballParser.readString();
  401. ballParser.readString();
  402. CHeroHandler::SBallisticsLevelInfo bli;
  403. bli.keep = ballParser.readNumber();
  404. bli.tower = ballParser.readNumber();
  405. bli.gate = ballParser.readNumber();
  406. bli.wall = ballParser.readNumber();
  407. bli.shots = ballParser.readNumber();
  408. bli.noDmg = ballParser.readNumber();
  409. bli.oneDmg = ballParser.readNumber();
  410. bli.twoDmg = ballParser.readNumber();
  411. bli.sum = ballParser.readNumber();
  412. ballistics.push_back(bli);
  413. assert(bli.noDmg + bli.oneDmg + bli.twoDmg == 100 && bli.sum == 100);
  414. }
  415. while (ballParser.endLine());
  416. }
  417. std::vector<JsonNode> CHeroHandler::loadLegacyData(size_t dataSize)
  418. {
  419. heroes.resize(dataSize);
  420. std::vector<JsonNode> h3Data;
  421. h3Data.reserve(dataSize);
  422. CLegacyConfigParser specParser("DATA/HEROSPEC.TXT");
  423. CLegacyConfigParser bioParser("DATA/HEROBIOS.TXT");
  424. CLegacyConfigParser parser("DATA/HOTRAITS.TXT");
  425. parser.endLine(); //ignore header
  426. parser.endLine();
  427. specParser.endLine(); //ignore header
  428. specParser.endLine();
  429. for (int i=0; i<GameConstants::HEROES_QUANTITY; i++)
  430. {
  431. JsonNode heroData;
  432. heroData["texts"]["name"].String() = parser.readString();
  433. heroData["texts"]["biography"].String() = bioParser.readString();
  434. heroData["texts"]["specialty"]["name"].String() = specParser.readString();
  435. heroData["texts"]["specialty"]["tooltip"].String() = specParser.readString();
  436. heroData["texts"]["specialty"]["description"].String() = specParser.readString();
  437. for(int x=0;x<3;x++)
  438. {
  439. JsonNode armySlot;
  440. armySlot["min"].Float() = parser.readNumber();
  441. armySlot["max"].Float() = parser.readNumber();
  442. armySlot["creature"].String() = genRefName(parser.readString());
  443. heroData["army"].Vector().push_back(armySlot);
  444. }
  445. parser.endLine();
  446. specParser.endLine();
  447. bioParser.endLine();
  448. h3Data.push_back(heroData);
  449. }
  450. return h3Data;
  451. }
  452. void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  453. {
  454. auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
  455. object->ID = HeroTypeID(heroes.size());
  456. object->imageIndex = heroes.size() + 30; // 2 special frames + some extra portraits
  457. heroes.push_back(object);
  458. VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID.getNum());
  459. }
  460. void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  461. {
  462. auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
  463. object->ID = HeroTypeID(index);
  464. object->imageIndex = index;
  465. assert(heroes[index] == nullptr); // ensure that this id was not loaded before
  466. heroes[index] = object;
  467. VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID.getNum());
  468. }
  469. ui32 CHeroHandler::level (ui64 experience) const
  470. {
  471. return boost::range::upper_bound(expPerLevel, experience) - std::begin(expPerLevel);
  472. }
  473. ui64 CHeroHandler::reqExp (ui32 level) const
  474. {
  475. if(!level)
  476. return 0;
  477. if (level <= expPerLevel.size())
  478. {
  479. return expPerLevel[level-1];
  480. }
  481. else
  482. {
  483. logGlobal->warnStream() << "A hero has reached unsupported amount of experience";
  484. return expPerLevel[expPerLevel.size()-1];
  485. }
  486. }
  487. void CHeroHandler::loadTerrains()
  488. {
  489. const JsonNode config(ResourceID("config/terrains.json"));
  490. terrCosts.reserve(GameConstants::TERRAIN_TYPES);
  491. for(const std::string & name : GameConstants::TERRAIN_NAMES)
  492. terrCosts.push_back(config[name]["moveCost"].Float());
  493. }
  494. std::vector<bool> CHeroHandler::getDefaultAllowed() const
  495. {
  496. // Look Data/HOTRAITS.txt for reference
  497. std::vector<bool> allowedHeroes;
  498. allowedHeroes.reserve(heroes.size());
  499. for(const CHero * hero : heroes)
  500. {
  501. allowedHeroes.push_back(!hero->special);
  502. }
  503. return allowedHeroes;
  504. }
  505. std::vector<bool> CHeroHandler::getDefaultAllowedAbilities() const
  506. {
  507. std::vector<bool> allowedAbilities;
  508. allowedAbilities.resize(GameConstants::SKILL_QUANTITY, true);
  509. return allowedAbilities;
  510. }
  511. si32 CHeroHandler::decodeHero(const std::string & identifier)
  512. {
  513. auto rawId = VLC->modh->identifiers.getIdentifier("core", "hero", identifier);
  514. if(rawId)
  515. return rawId.get();
  516. else
  517. return -1;
  518. }
  519. std::string CHeroHandler::encodeHero(const si32 index)
  520. {
  521. return VLC->heroh->heroes.at(index)->identifier;
  522. }
  523. si32 CHeroHandler::decodeSkill(const std::string & identifier)
  524. {
  525. auto rawId = VLC->modh->identifiers.getIdentifier("core", "skill", identifier);
  526. if(rawId)
  527. return rawId.get();
  528. else
  529. return -1;
  530. }
  531. std::string CHeroHandler::encodeSkill(const si32 index)
  532. {
  533. return NSecondarySkill::names[index];
  534. }