1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

skills are initialized properly (and file loading isn't actually working yet)

This commit is contained in:
Henning Koehler 2017-08-23 00:40:15 +12:00
parent 05cf95400c
commit 993b7bf614
2 changed files with 20 additions and 8 deletions

View File

@ -27,8 +27,13 @@
#include "battle/CBattleInfoCallback.h"
///CSkill
CSkill::CSkill()
CSkill::CSkill(SecondarySkill id) : id(id)
{
if(id == SecondarySkill::DEFAULT)
identifier = "default";
else
identifier = NSecondarySkill::names[id];
// init bonus levels
BonusList emptyList;
for(auto level : NSecondarySkill::levels)
bonusByLevel.push_back(emptyList);
@ -56,7 +61,10 @@ CSkillHandler::CSkillHandler()
{
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
{
//TODO
CSkill * skill = new CSkill(SecondarySkill(id));
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
skill->addNewBonus(defaultBonus(SecondarySkill(id), level), level);
objects.push_back(skill);
}
}
@ -69,24 +77,28 @@ std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
const std::string CSkillHandler::getTypeName() const
{
return "secondarySkill";
return "secondarySkill";
}
CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
{
CSkill * skill = new CSkill();
skill->identifier = identifier;
CSkill * skill = NULL;
skill->id = SecondarySkill::DEFAULT;
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
{
if(NSecondarySkill::names[id].compare(identifier) == 0)
{
skill->id = SecondarySkill(id);
skill = new CSkill(SecondarySkill(id));
break;
}
}
if(!skill)
{
logGlobal->errorStream() << "unknown secondary skill " << identifier;
throw std::runtime_error("invalid skill");
}
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
{
const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert

View File

@ -24,7 +24,7 @@ protected:
std::vector<BonusList> bonusByLevel; // bonuses provided by none, basic, advanced and expert level
public:
CSkill();
CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
~CSkill();
void addNewBonus(const std::shared_ptr<Bonus>& b, int level);