From 993b7bf614ab034a2e9941cdaeb664fdabc265b4 Mon Sep 17 00:00:00 2001 From: Henning Koehler Date: Wed, 23 Aug 2017 00:40:15 +1200 Subject: [PATCH] skills are initialized properly (and file loading isn't actually working yet) --- lib/CSkillHandler.cpp | 26 +++++++++++++++++++------- lib/CSkillHandler.h | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index 267b9f388..3129ba570 100644 --- a/lib/CSkillHandler.cpp +++ b/lib/CSkillHandler.cpp @@ -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 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 diff --git a/lib/CSkillHandler.h b/lib/CSkillHandler.h index 26227f154..003fb9f91 100644 --- a/lib/CSkillHandler.h +++ b/lib/CSkillHandler.h @@ -24,7 +24,7 @@ protected: std::vector bonusByLevel; // bonuses provided by none, basic, advanced and expert level public: - CSkill(); + CSkill(SecondarySkill id = SecondarySkill::DEFAULT); ~CSkill(); void addNewBonus(const std::shared_ptr& b, int level);