|
@@ -12,7 +12,6 @@
|
|
|
|
|
|
#include <cctype>
|
|
|
|
|
|
-#include "CBonusTypeHandler.h"
|
|
|
#include "CSpellHandler.h"
|
|
|
#include "Problem.h"
|
|
|
|
|
@@ -22,56 +21,23 @@
|
|
|
|
|
|
#include "../constants/StringConstants.h"
|
|
|
|
|
|
-#include "../battle/BattleInfo.h"
|
|
|
+#include "../CBonusTypeHandler.h"
|
|
|
#include "../battle/CBattleInfoCallback.h"
|
|
|
#include "../battle/Unit.h"
|
|
|
#include "../json/JsonBonus.h"
|
|
|
#include "../json/JsonUtils.h"
|
|
|
#include "../GameLibrary.h"
|
|
|
-#include "../mapObjects/CGHeroInstance.h" //todo: remove
|
|
|
#include "../modding/IdentifierStorage.h"
|
|
|
-#include "../modding/ModUtility.h"
|
|
|
-#include "../serializer/CSerializer.h"
|
|
|
#include "../texts/CLegacyConfigParser.h"
|
|
|
#include "../texts/CGeneralTextHandler.h"
|
|
|
|
|
|
#include "ISpellMechanics.h"
|
|
|
+#include "bonuses/BonusSelector.h"
|
|
|
+#include "spells/SpellSchoolHandler.h"
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
-namespace SpellConfig
|
|
|
-{
|
|
|
-static const std::string LEVEL_NAMES[] = {"none", "basic", "advanced", "expert"};
|
|
|
-
|
|
|
-const spells::SchoolInfo SCHOOL[4] =
|
|
|
-{
|
|
|
- {
|
|
|
- SpellSchool::AIR,
|
|
|
- "air"
|
|
|
- },
|
|
|
- {
|
|
|
- SpellSchool::FIRE,
|
|
|
- "fire"
|
|
|
- },
|
|
|
- {
|
|
|
- SpellSchool::WATER,
|
|
|
- "water"
|
|
|
- },
|
|
|
- {
|
|
|
- SpellSchool::EARTH,
|
|
|
- "earth"
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-//order as described in http://bugs.vcmi.eu/view.php?id=91
|
|
|
-static const SpellSchool SCHOOL_ORDER[4] =
|
|
|
-{
|
|
|
- SpellSchool::AIR, //=0
|
|
|
- SpellSchool::FIRE, //=1
|
|
|
- SpellSchool::EARTH,//=3(!)
|
|
|
- SpellSchool::WATER //=2(!)
|
|
|
-};
|
|
|
-} //namespace SpellConfig
|
|
|
+static constexpr std::array LEVEL_NAMES = {"none", "basic", "advanced", "expert"};
|
|
|
|
|
|
///CSpell
|
|
|
CSpell::CSpell():
|
|
@@ -133,7 +99,7 @@ int64_t CSpell::calculateDamage(const spells::Caster * caster) const
|
|
|
|
|
|
bool CSpell::hasSchool(SpellSchool which) const
|
|
|
{
|
|
|
- return school.count(which) && school.at(which);
|
|
|
+ return schools.count(which);
|
|
|
}
|
|
|
|
|
|
bool CSpell::canBeCast(const CBattleInfoCallback * cb, spells::Mode mode, const spells::Caster * caster) const
|
|
@@ -159,13 +125,11 @@ spells::AimType CSpell::getTargetType() const
|
|
|
void CSpell::forEachSchool(const std::function<void(const SpellSchool &, bool &)>& cb) const
|
|
|
{
|
|
|
bool stop = false;
|
|
|
- for(auto iter : SpellConfig::SCHOOL_ORDER)
|
|
|
+ for(auto schoolID : LIBRARY->spellSchoolHandler->getAllObjects())
|
|
|
{
|
|
|
- const spells::SchoolInfo & cnf = SpellConfig::SCHOOL[iter.getNum()];
|
|
|
- if(school.at(cnf.id))
|
|
|
+ if(schools.count(schoolID))
|
|
|
{
|
|
|
- cb(cnf.id, stop);
|
|
|
-
|
|
|
+ cb(schoolID, stop);
|
|
|
if(stop)
|
|
|
break;
|
|
|
}
|
|
@@ -190,7 +154,7 @@ std::string CSpell::getNameTranslated() const
|
|
|
|
|
|
std::string CSpell::getDescriptionTextID(int32_t level) const
|
|
|
{
|
|
|
- TextIdentifier id("spell", modScope, identifier, "description", SpellConfig::LEVEL_NAMES[level]);
|
|
|
+ TextIdentifier id("spell", modScope, identifier, "description", LEVEL_NAMES[level]);
|
|
|
return id.get();
|
|
|
}
|
|
|
|
|
@@ -581,7 +545,6 @@ bool DLL_LINKAGE isInScreenRange(const int3 & center, const int3 & pos)
|
|
|
///CSpellHandler
|
|
|
std::vector<JsonNode> CSpellHandler::loadLegacyData()
|
|
|
{
|
|
|
- using namespace SpellConfig;
|
|
|
std::vector<JsonNode> legacyData;
|
|
|
|
|
|
CLegacyConfigParser parser(TextPath::builtin("DATA/SPTRAITS.TXT"));
|
|
@@ -757,8 +720,6 @@ std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, c
|
|
|
assert(identifier.find(':') == std::string::npos);
|
|
|
assert(!scope.empty());
|
|
|
|
|
|
- using namespace SpellConfig;
|
|
|
-
|
|
|
SpellID id(static_cast<si32>(index));
|
|
|
|
|
|
auto spell = std::make_shared<CSpell>();
|
|
@@ -783,11 +744,15 @@ std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, c
|
|
|
|
|
|
logMod->trace("%s: loading spell %s", __FUNCTION__, spell->getNameTranslated());
|
|
|
|
|
|
- const auto schoolNames = json["school"];
|
|
|
-
|
|
|
- for(const spells::SchoolInfo & info : SpellConfig::SCHOOL)
|
|
|
+ for(const auto & schoolJson : json["school"].Struct())
|
|
|
{
|
|
|
- spell->school[info.id] = schoolNames[info.jsonName].Bool();
|
|
|
+ if (schoolJson.second.Bool())
|
|
|
+ {
|
|
|
+ LIBRARY->identifiers()->requestIdentifier(schoolJson.second.getModScope(), "spellSchool", schoolJson.first, [=](si32 schoolID)
|
|
|
+ {
|
|
|
+ spell->schools.emplace(schoolID);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
spell->castOnSelf = json["canCastOnSelf"].Bool();
|