2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-06-08 17:58:04 +03:00
|
|
|
#include "CHeroHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
#include "CGeneralTextHandler.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "filesystem/CResourceLoader.h"
|
2012-08-25 11:44:51 +03:00
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include "JsonNode.h"
|
2012-12-14 18:32:53 +03:00
|
|
|
#include "StringConstants.h"
|
2012-04-23 22:56:37 +03:00
|
|
|
#include "BattleHex.h"
|
2012-12-03 19:00:17 +03:00
|
|
|
#include "CModHandler.h"
|
2012-12-15 11:47:02 +03:00
|
|
|
#include "CTownHandler.h"
|
2013-01-19 20:38:37 +03:00
|
|
|
#include "CObjectHandler.h" //for hero specialty
|
2009-08-31 18:57:15 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CHeroHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-12 22:49:40 +03:00
|
|
|
SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles) const //picks secondary skill out from given possibilities
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
|
|
|
if(possibles.size()==1)
|
|
|
|
return *possibles.begin();
|
|
|
|
int totalProb = 0;
|
2013-02-04 22:43:16 +03:00
|
|
|
for(auto i=possibles.begin(); i!=possibles.end(); i++)
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
2012-12-14 18:32:53 +03:00
|
|
|
totalProb += secSkillProbability[*i];
|
2008-08-04 18:56:36 +03:00
|
|
|
}
|
|
|
|
int ran = rand()%totalProb;
|
2013-02-04 22:43:16 +03:00
|
|
|
for(auto i=possibles.begin(); i!=possibles.end(); i++)
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
2012-12-14 18:32:53 +03:00
|
|
|
ran -= secSkillProbability[*i];
|
2008-08-04 18:56:36 +03:00
|
|
|
if(ran<0)
|
|
|
|
return *i;
|
|
|
|
}
|
2012-04-22 10:32:45 +03:00
|
|
|
throw std::runtime_error("Cannot pick secondary skill!");
|
2008-08-04 18:56:36 +03:00
|
|
|
}
|
|
|
|
|
2012-09-23 21:01:04 +03:00
|
|
|
EAlignment::EAlignment CHeroClass::getAlignment() const
|
2010-07-20 09:05:45 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
return EAlignment::EAlignment(VLC->townh->factions[faction]->alignment);
|
2010-07-20 09:05:45 +03:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:56:37 +03:00
|
|
|
std::vector<BattleHex> CObstacleInfo::getBlocked(BattleHex hex) const
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
std::vector<BattleHex> ret;
|
|
|
|
if(isAbsoluteObstacle)
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
assert(!hex.isValid());
|
|
|
|
range::copy(blockedTiles, std::back_inserter(ret));
|
|
|
|
return ret;
|
2009-02-09 16:50:32 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:56:37 +03:00
|
|
|
BOOST_FOREACH(int offset, blockedTiles)
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
BattleHex toBlock = hex + offset;
|
|
|
|
if((hex.getY() & 1) && !(toBlock.getY() & 1))
|
|
|
|
toBlock += BattleHex::LEFT;
|
|
|
|
|
|
|
|
if(!toBlock.isValid())
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Misplaced obstacle!";
|
2012-04-23 22:56:37 +03:00
|
|
|
else
|
|
|
|
ret.push_back(toBlock);
|
2009-02-09 16:50:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-13 01:24:48 +03:00
|
|
|
bool CObstacleInfo::isAppropriate(ETerrainType terrainType, int specialBattlefield /*= -1*/) const
|
2009-09-25 14:38:18 +03:00
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
if(specialBattlefield != -1)
|
|
|
|
return vstd::contains(allowedSpecialBfields, specialBattlefield);
|
|
|
|
|
|
|
|
return vstd::contains(allowedTerrains, terrainType);
|
2009-09-25 14:38:18 +03:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
CHeroClass *CHeroClassHandler::loadFromJson(const JsonNode & node)
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
CHeroClass * heroClass = new CHeroClass();
|
|
|
|
|
|
|
|
heroClass->imageBattleFemale = node["animation"]["battle"]["female"].String();
|
|
|
|
heroClass->imageBattleMale = node["animation"]["battle"]["male"].String();
|
|
|
|
heroClass->imageMapFemale = node["animation"]["map"]["female"].String();
|
|
|
|
heroClass->imageMapMale = node["animation"]["map"]["male"].String();
|
|
|
|
|
|
|
|
heroClass->name = node["name"].String();
|
|
|
|
|
|
|
|
BOOST_FOREACH(const std::string & pSkill, PrimarySkill::names)
|
|
|
|
{
|
|
|
|
heroClass->primarySkillInitial.push_back(node["primarySkills"][pSkill].Float());
|
|
|
|
heroClass->primarySkillLowLevel.push_back(node["lowLevelChance"][pSkill].Float());
|
|
|
|
heroClass->primarySkillHighLevel.push_back(node["highLevelChance"][pSkill].Float());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(const std::string & secSkill, NSecondarySkill::names)
|
|
|
|
{
|
|
|
|
heroClass->secSkillProbability.push_back(node["secondarySkills"][secSkill].Float());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(auto & tavern, node["tavern"].Struct())
|
|
|
|
{
|
|
|
|
int value = tavern.second.Float();
|
|
|
|
|
|
|
|
VLC->modh->identifiers.requestIdentifier("faction." + tavern.first,
|
|
|
|
[=](si32 factionID)
|
|
|
|
{
|
|
|
|
heroClass->selectionProbability[factionID] = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
VLC->modh->identifiers.requestIdentifier("faction." + node["faction"].String(),
|
|
|
|
[=](si32 factionID)
|
|
|
|
{
|
|
|
|
heroClass->faction = factionID;
|
|
|
|
});
|
|
|
|
|
|
|
|
return heroClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<JsonNode> CHeroClassHandler::loadLegacyData(size_t dataSize)
|
|
|
|
{
|
|
|
|
heroClasses.resize(GameConstants::F_NUMBER * 2);
|
|
|
|
std::vector<JsonNode> h3Data;
|
|
|
|
h3Data.reserve(dataSize);
|
|
|
|
|
2012-12-14 18:32:53 +03:00
|
|
|
CLegacyConfigParser parser("DATA/HCTRAITS.TXT");
|
|
|
|
|
|
|
|
parser.endLine(); // header
|
|
|
|
parser.endLine();
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
for (size_t i=0; i<dataSize; i++)
|
2012-12-14 18:32:53 +03:00
|
|
|
{
|
2013-03-12 17:56:23 +03:00
|
|
|
JsonNode entry;
|
|
|
|
|
|
|
|
entry["name"].String() = parser.readString();
|
|
|
|
|
|
|
|
parser.readNumber(); // unused aggression
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
for (size_t i=0; i < GameConstants::PRIMARY_SKILLS; i++)
|
|
|
|
entry["primarySkills"][PrimarySkill::names[i]].Float() = parser.readNumber();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
for (size_t i=0; i < GameConstants::PRIMARY_SKILLS; i++)
|
|
|
|
entry["lowLevelChance"][PrimarySkill::names[i]].Float() = parser.readNumber();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
for (size_t i=0; i < GameConstants::PRIMARY_SKILLS; i++)
|
|
|
|
entry["highLevelChance"][PrimarySkill::names[i]].Float() = parser.readNumber();
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
for (size_t i=0; i < GameConstants::SKILL_QUANTITY; i++)
|
|
|
|
entry["secondarySkills"][NSecondarySkill::names[i]].Float() = parser.readNumber();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2013-03-12 17:56:23 +03:00
|
|
|
for(size_t i = 0; i < GameConstants::F_NUMBER; i++)
|
|
|
|
entry["tavern"][ETownType::names[i]].Float() = parser.readNumber();
|
2012-12-14 18:32:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
parser.endLine();
|
2013-03-12 17:56:23 +03:00
|
|
|
h3Data.push_back(entry);
|
2012-12-14 18:32:53 +03:00
|
|
|
}
|
2013-04-21 15:49:26 +03:00
|
|
|
return h3Data;
|
2012-12-14 18:32:53 +03:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
2012-12-14 18:32:53 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
auto object = loadFromJson(data);
|
|
|
|
object->id = heroClasses.size();
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
heroClasses.push_back(object);
|
|
|
|
|
|
|
|
VLC->modh->identifiers.registerObject(scope, "heroClass", name, object->id);
|
2012-12-14 18:32:53 +03:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
2012-12-14 18:32:53 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
auto object = loadFromJson(data);
|
|
|
|
object->id = index;
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
assert(heroClasses[index] == nullptr); // ensure that this id was not loaded before
|
|
|
|
heroClasses[index] = object;
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
VLC->modh->identifiers.registerObject(scope, "heroClass", name, object->id);
|
|
|
|
}
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
std::vector<bool> CHeroClassHandler::getDefaultAllowed() const
|
|
|
|
{
|
|
|
|
return std::vector<bool>(heroClasses.size(), true);
|
2012-12-14 18:32:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CHeroClassHandler::~CHeroClassHandler()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(auto heroClass, heroClasses)
|
|
|
|
{
|
|
|
|
delete heroClass.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHeroHandler::~CHeroHandler()
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(auto hero, heroes)
|
|
|
|
delete hero.get();
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CHeroHandler::CHeroHandler()
|
2012-12-26 12:46:09 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
VLC->heroh = this;
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
for (int i = 0; i < GameConstants::SKILL_QUANTITY; ++i)
|
|
|
|
{
|
|
|
|
VLC->modh->identifiers.registerObject("core", "skill", NSecondarySkill::names[i], i);
|
|
|
|
}
|
|
|
|
loadObstacles();
|
|
|
|
loadTerrains();
|
|
|
|
loadBallistics();
|
|
|
|
loadExperience();
|
2012-12-15 11:47:02 +03:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
CHero * CHeroHandler::loadFromJson(const JsonNode & node)
|
2012-12-15 11:47:02 +03:00
|
|
|
{
|
2012-12-16 16:47:53 +03:00
|
|
|
CHero * hero = new CHero;
|
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
hero->sex = node["female"].Bool();
|
|
|
|
hero->special = node["special"].Bool();
|
|
|
|
|
2012-12-16 16:47:53 +03:00
|
|
|
hero->name = node["texts"]["name"].String();
|
|
|
|
hero->biography = node["texts"]["biography"].String();
|
|
|
|
hero->specName = node["texts"]["specialty"]["name"].String();
|
|
|
|
hero->specTooltip = node["texts"]["specialty"]["tooltip"].String();
|
|
|
|
hero->specDescr = node["texts"]["specialty"]["description"].String();
|
|
|
|
|
|
|
|
hero->iconSpecSmall = node["images"]["specialtySmall"].String();
|
|
|
|
hero->iconSpecLarge = node["images"]["specialtyLarge"].String();
|
|
|
|
hero->portraitSmall = node["images"]["small"].String();
|
|
|
|
hero->portraitLarge = node["images"]["large"].String();
|
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
loadHeroArmy(hero, node);
|
|
|
|
loadHeroSkills(hero, node);
|
|
|
|
loadHeroSpecialty(hero, node);
|
|
|
|
|
|
|
|
VLC->modh->identifiers.requestIdentifier("heroClass." + node["class"].String(),
|
|
|
|
[=](si32 classID)
|
|
|
|
{
|
|
|
|
hero->heroClass = classes.heroClasses[classID];
|
|
|
|
});
|
|
|
|
|
|
|
|
return hero;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node)
|
|
|
|
{
|
2012-12-16 16:47:53 +03:00
|
|
|
assert(node["army"].Vector().size() <= 3); // anything bigger is useless - army initialization uses up to 3 slots
|
2013-03-03 21:00:37 +03:00
|
|
|
|
2012-12-16 16:47:53 +03:00
|
|
|
hero->initialArmy.resize(node["army"].Vector().size());
|
|
|
|
|
|
|
|
for (size_t i=0; i< hero->initialArmy.size(); i++)
|
|
|
|
{
|
|
|
|
const JsonNode & source = node["army"].Vector()[i];
|
|
|
|
|
|
|
|
hero->initialArmy[i].minAmount = source["min"].Float();
|
|
|
|
hero->initialArmy[i].maxAmount = source["max"].Float();
|
|
|
|
|
|
|
|
assert(hero->initialArmy[i].minAmount <= hero->initialArmy[i].maxAmount);
|
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
VLC->modh->identifiers.requestIdentifier("creature." + source["creature"].String(), [=](si32 creature)
|
2012-12-16 16:47:53 +03:00
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
hero->initialArmy[i].creature = CreatureID(creature);
|
2012-12-16 16:47:53 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node)
|
2012-12-16 16:47:53 +03:00
|
|
|
{
|
|
|
|
BOOST_FOREACH(const JsonNode &set, node["skills"].Vector())
|
|
|
|
{
|
2013-02-12 22:49:40 +03:00
|
|
|
int skillLevel = boost::range::find(NSecondarySkill::levels, set["level"].String()) - boost::begin(NSecondarySkill::levels);
|
2013-04-23 12:16:20 +03:00
|
|
|
if (skillLevel < SecSkillLevel::LEVELS_SIZE)
|
|
|
|
{
|
|
|
|
size_t currentIndex = hero->secSkillsInit.size();
|
|
|
|
hero->secSkillsInit.push_back(std::make_pair(-1, skillLevel));
|
|
|
|
|
|
|
|
VLC->modh->identifiers.requestIdentifier("skill." + set["skill"].String(), [=](si32 id)
|
|
|
|
{
|
|
|
|
hero->secSkillsInit[currentIndex].first = SecondarySkill(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logGlobal->errorStream() << "Unknown skill level: " <<set["level"].String();
|
|
|
|
}
|
2012-12-16 16:47:53 +03:00
|
|
|
}
|
|
|
|
|
2013-03-02 19:55:51 +03:00
|
|
|
// spellbook is considered present if hero have "spellbook" entry even when this is an empty set (0 spells)
|
2013-03-03 21:00:37 +03:00
|
|
|
hero->haveSpellBook = !node["spellbook"].isNull();
|
2013-03-02 19:55:51 +03:00
|
|
|
|
2012-12-16 16:47:53 +03:00
|
|
|
BOOST_FOREACH(const JsonNode & spell, node["spellbook"].Vector())
|
|
|
|
{
|
2013-03-02 19:55:51 +03:00
|
|
|
if (spell.getType() == JsonNode::DATA_FLOAT) // for compatibility
|
|
|
|
{
|
|
|
|
hero->spells.insert(SpellID(spell.Float()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VLC->modh->identifiers.requestIdentifier("spell." + spell.String(),
|
|
|
|
[=](si32 spellID)
|
|
|
|
{
|
|
|
|
hero->spells.insert(SpellID(spellID));
|
|
|
|
});
|
|
|
|
}
|
2012-12-16 16:47:53 +03:00
|
|
|
}
|
2013-03-03 21:00:37 +03:00
|
|
|
}
|
2012-12-16 16:47:53 +03:00
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
|
|
|
{
|
2013-01-19 20:38:37 +03:00
|
|
|
//deprecated, used only for original spciealties
|
2012-12-16 16:47:53 +03:00
|
|
|
BOOST_FOREACH(const JsonNode &specialty, node["specialties"].Vector())
|
|
|
|
{
|
|
|
|
SSpecialtyInfo spec;
|
|
|
|
|
|
|
|
spec.type = specialty["type"].Float();
|
|
|
|
spec.val = specialty["val"].Float();
|
|
|
|
spec.subtype = specialty["subtype"].Float();
|
|
|
|
spec.additionalinfo = specialty["info"].Float();
|
|
|
|
|
|
|
|
hero->spec.push_back(spec); //put a copy of dummy
|
|
|
|
}
|
2013-01-19 20:38:37 +03:00
|
|
|
//new format, using bonus system
|
|
|
|
BOOST_FOREACH(const JsonNode &specialty, node["specialty"].Vector())
|
|
|
|
{
|
|
|
|
SSpecialtyBonus hs;
|
|
|
|
hs.growsWithLevel = specialty["growsWithLevel"].Bool();
|
|
|
|
BOOST_FOREACH (const JsonNode & bonus, specialty["bonuses"].Vector())
|
|
|
|
{
|
|
|
|
auto b = JsonUtils::parseBonus(bonus);
|
|
|
|
hs.bonuses.push_back (b);
|
|
|
|
}
|
|
|
|
hero->specialty.push_back (hs); //now, how to get CGHeroInstance from it?
|
|
|
|
}
|
2012-12-15 11:47:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroHandler::loadExperience()
|
|
|
|
{
|
|
|
|
expPerLevel.push_back(0);
|
|
|
|
expPerLevel.push_back(1000);
|
|
|
|
expPerLevel.push_back(2000);
|
|
|
|
expPerLevel.push_back(3200);
|
|
|
|
expPerLevel.push_back(4600);
|
|
|
|
expPerLevel.push_back(6200);
|
|
|
|
expPerLevel.push_back(8000);
|
|
|
|
expPerLevel.push_back(10000);
|
|
|
|
expPerLevel.push_back(12200);
|
|
|
|
expPerLevel.push_back(14700);
|
|
|
|
expPerLevel.push_back(17500);
|
|
|
|
expPerLevel.push_back(20600);
|
|
|
|
expPerLevel.push_back(24320);
|
|
|
|
expPerLevel.push_back(28784);
|
|
|
|
expPerLevel.push_back(34140);
|
|
|
|
while (expPerLevel[expPerLevel.size() - 1] > expPerLevel[expPerLevel.size() - 2])
|
|
|
|
{
|
|
|
|
int i = expPerLevel.size() - 1;
|
|
|
|
expPerLevel.push_back (expPerLevel[i] + (expPerLevel[i] - expPerLevel[i-1]) * 1.2);
|
|
|
|
}
|
|
|
|
expPerLevel.pop_back();//last value is broken
|
2012-12-14 18:32:53 +03:00
|
|
|
}
|
|
|
|
|
2009-02-07 18:07:29 +02:00
|
|
|
void CHeroHandler::loadObstacles()
|
|
|
|
{
|
2012-04-23 22:56:37 +03:00
|
|
|
auto loadObstacles = [](const JsonNode &node, bool absolute, std::map<int, CObstacleInfo> &out)
|
|
|
|
{
|
2013-02-05 00:58:42 +03:00
|
|
|
BOOST_FOREACH(const JsonNode &obs, node.Vector())
|
2012-04-23 22:56:37 +03:00
|
|
|
{
|
|
|
|
int ID = obs["id"].Float();
|
|
|
|
CObstacleInfo & obi = out[ID];
|
|
|
|
obi.ID = ID;
|
|
|
|
obi.defName = obs["defname"].String();
|
|
|
|
obi.width = obs["width"].Float();
|
|
|
|
obi.height = obs["height"].Float();
|
2013-02-13 01:24:48 +03:00
|
|
|
obi.allowedTerrains = obs["allowedTerrain"].convertTo<std::vector<ETerrainType> >();
|
|
|
|
obi.allowedSpecialBfields = obs["specialBattlefields"].convertTo<std::vector<BFieldType> >();
|
2012-12-02 15:21:44 +03:00
|
|
|
obi.blockedTiles = obs["blockedTiles"].convertTo<std::vector<si16> >();
|
2012-04-23 22:56:37 +03:00
|
|
|
obi.isAbsoluteObstacle = absolute;
|
|
|
|
}
|
|
|
|
};
|
2011-09-02 05:12:55 +03:00
|
|
|
|
2012-08-02 14:03:26 +03:00
|
|
|
const JsonNode config(ResourceID("config/obstacles.json"));
|
2012-04-23 22:56:37 +03:00
|
|
|
loadObstacles(config["obstacles"], false, obstacles);
|
|
|
|
loadObstacles(config["absoluteObstacles"], true, absoluteObstacles);
|
2012-05-18 23:50:16 +03:00
|
|
|
//loadObstacles(config["moats"], true, moats);
|
2009-02-07 18:07:29 +02:00
|
|
|
}
|
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
/// convert h3-style ID (e.g. Gobin Wolf Rider) to vcmi (e.g. goblinWolfRider)
|
|
|
|
static std::string genRefName(std::string input)
|
|
|
|
{
|
|
|
|
boost::algorithm::replace_all(input, " ", ""); //remove spaces
|
|
|
|
input[0] = std::tolower(input[0]); // to camelCase
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CHeroHandler::loadBallistics()
|
|
|
|
{
|
|
|
|
CLegacyConfigParser ballParser("DATA/BALLIST.TXT");
|
|
|
|
|
|
|
|
ballParser.endLine(); //header
|
|
|
|
ballParser.endLine();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ballParser.readString();
|
|
|
|
ballParser.readString();
|
|
|
|
|
|
|
|
CHeroHandler::SBallisticsLevelInfo bli;
|
|
|
|
bli.keep = ballParser.readNumber();
|
|
|
|
bli.tower = ballParser.readNumber();
|
|
|
|
bli.gate = ballParser.readNumber();
|
|
|
|
bli.wall = ballParser.readNumber();
|
|
|
|
bli.shots = ballParser.readNumber();
|
|
|
|
bli.noDmg = ballParser.readNumber();
|
|
|
|
bli.oneDmg = ballParser.readNumber();
|
|
|
|
bli.twoDmg = ballParser.readNumber();
|
|
|
|
bli.sum = ballParser.readNumber();
|
|
|
|
ballistics.push_back(bli);
|
|
|
|
}
|
|
|
|
while (ballParser.endLine());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<JsonNode> CHeroHandler::loadLegacyData(size_t dataSize)
|
2007-06-08 17:58:04 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
heroes.resize(dataSize);
|
|
|
|
std::vector<JsonNode> h3Data;
|
|
|
|
h3Data.reserve(dataSize);
|
|
|
|
|
2013-03-02 19:55:51 +03:00
|
|
|
CLegacyConfigParser specParser("DATA/HEROSPEC.TXT");
|
|
|
|
CLegacyConfigParser bioParser("DATA/HEROBIOS.TXT");
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/HOTRAITS.TXT");
|
|
|
|
|
|
|
|
parser.endLine(); //ignore header
|
|
|
|
parser.endLine();
|
2007-08-04 22:01:22 +03:00
|
|
|
|
2013-03-02 19:55:51 +03:00
|
|
|
specParser.endLine(); //ignore header
|
|
|
|
specParser.endLine();
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (int i=0; i<GameConstants::HEROES_QUANTITY; i++)
|
2007-06-08 17:58:04 +03:00
|
|
|
{
|
2013-03-03 21:00:37 +03:00
|
|
|
JsonNode heroData;
|
|
|
|
|
|
|
|
heroData["texts"]["name"].String() = parser.readString();
|
|
|
|
heroData["texts"]["biography"].String() = bioParser.readString();
|
|
|
|
heroData["texts"]["specialty"]["name"].String() = specParser.readString();
|
|
|
|
heroData["texts"]["specialty"]["tooltip"].String() = specParser.readString();
|
|
|
|
heroData["texts"]["specialty"]["description"].String() = specParser.readString();
|
2007-08-04 22:01:22 +03:00
|
|
|
|
2008-05-03 18:30:11 +03:00
|
|
|
for(int x=0;x<3;x++)
|
|
|
|
{
|
2013-03-03 21:00:37 +03:00
|
|
|
JsonNode armySlot;
|
|
|
|
armySlot["min"].Float() = parser.readNumber();
|
|
|
|
armySlot["max"].Float() = parser.readNumber();
|
|
|
|
armySlot["creature"].String() = genRefName(parser.readString());
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
heroData["army"].Vector().push_back(armySlot);
|
2008-05-03 18:30:11 +03:00
|
|
|
}
|
2012-08-25 11:44:51 +03:00
|
|
|
parser.endLine();
|
2013-03-02 19:55:51 +03:00
|
|
|
specParser.endLine();
|
|
|
|
bioParser.endLine();
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2013-03-03 21:00:37 +03:00
|
|
|
h3Data.push_back(heroData);
|
2007-06-08 17:58:04 +03:00
|
|
|
}
|
2013-04-21 15:49:26 +03:00
|
|
|
return h3Data;
|
|
|
|
}
|
2011-08-27 18:53:45 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
|
|
|
{
|
|
|
|
auto object = loadFromJson(data);
|
|
|
|
object->ID = heroes.size();
|
2013-04-22 22:51:22 +03:00
|
|
|
object->imageIndex = heroes.size() + 8; // 2 special frames + some extra portraits
|
2013-03-03 21:00:37 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
heroes.push_back(object);
|
2013-03-03 21:00:37 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID);
|
2012-12-16 16:47:53 +03:00
|
|
|
}
|
2011-08-27 20:33:07 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
2012-12-15 11:47:02 +03:00
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
auto object = loadFromJson(data);
|
|
|
|
object->ID = index;
|
2013-04-22 22:51:22 +03:00
|
|
|
object->imageIndex = index;
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
assert(heroes[index] == nullptr); // ensure that this id was not loaded before
|
|
|
|
heroes[index] = object;
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID);
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
2011-08-27 20:33:07 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 CHeroHandler::level (ui64 experience) const
|
2007-08-12 20:48:05 +03:00
|
|
|
{
|
2012-12-15 16:40:22 +03:00
|
|
|
return boost::range::upper_bound(expPerLevel, experience) - boost::begin(expPerLevel);
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
ui64 CHeroHandler::reqExp (ui32 level) const
|
2008-01-27 18:07:27 +02:00
|
|
|
{
|
2009-07-20 06:30:48 +03:00
|
|
|
if(!level)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-28 12:45:45 +02:00
|
|
|
if (level <= expPerLevel.size())
|
2009-07-20 06:30:48 +03:00
|
|
|
{
|
2009-10-28 12:45:45 +02:00
|
|
|
return expPerLevel[level-1];
|
2009-07-20 06:30:48 +03:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
else
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "A hero has reached unsupported amount of experience";
|
2010-08-16 12:54:09 +03:00
|
|
|
return expPerLevel[expPerLevel.size()-1];
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2007-08-12 20:48:05 +03:00
|
|
|
}
|
|
|
|
|
2011-09-02 06:39:49 +03:00
|
|
|
void CHeroHandler::loadTerrains()
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2012-08-02 14:03:26 +03:00
|
|
|
const JsonNode config(ResourceID("config/terrains.json"));
|
2009-06-30 15:28:22 +03:00
|
|
|
|
2012-09-05 15:49:23 +03:00
|
|
|
terrCosts.reserve(GameConstants::TERRAIN_TYPES);
|
|
|
|
BOOST_FOREACH(const std::string & name, GameConstants::TERRAIN_NAMES)
|
2012-12-10 17:28:27 +03:00
|
|
|
terrCosts.push_back(config[name]["moveCost"].Float());
|
2009-06-30 15:28:22 +03:00
|
|
|
}
|
2009-07-03 21:40:36 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
std::vector<bool> CHeroHandler::getDefaultAllowed() const
|
2012-11-20 20:53:45 +03:00
|
|
|
{
|
|
|
|
// Look Data/HOTRAITS.txt for reference
|
2013-02-05 00:58:42 +03:00
|
|
|
std::vector<bool> allowedHeroes;
|
2012-12-17 15:55:29 +03:00
|
|
|
allowedHeroes.reserve(heroes.size());
|
|
|
|
|
|
|
|
BOOST_FOREACH(const CHero * hero, heroes)
|
2012-11-20 20:53:45 +03:00
|
|
|
{
|
2012-12-17 15:55:29 +03:00
|
|
|
allowedHeroes.push_back(!hero->special);
|
2012-11-20 20:53:45 +03:00
|
|
|
}
|
2012-12-17 15:55:29 +03:00
|
|
|
|
2012-11-20 20:53:45 +03:00
|
|
|
return allowedHeroes;
|
2012-12-17 15:55:29 +03:00
|
|
|
}
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-02-05 00:58:42 +03:00
|
|
|
std::vector<bool> CHeroHandler::getDefaultAllowedAbilities() const
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-02-05 00:58:42 +03:00
|
|
|
std::vector<bool> allowedAbilities;
|
|
|
|
allowedAbilities.resize(GameConstants::SKILL_QUANTITY, true);
|
2013-01-06 22:30:12 +03:00
|
|
|
return allowedAbilities;
|
|
|
|
}
|