mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Merge pull request #4433 from IvanSavenko/spell_cleanup
Minor cleanup of SpellHandler
This commit is contained in:
commit
6ab97bad7e
@ -505,62 +505,14 @@ std::set<BattleHex> BattleSpellMechanics::spellRangeInHexes(BattleHex centralHex
|
||||
using namespace SRSLPraserHelpers;
|
||||
|
||||
std::set<BattleHex> ret;
|
||||
std::string rng = owner->getLevelInfo(getRangeLevel()).range + ','; //copy + artificial comma for easier handling
|
||||
std::vector<int> rng = owner->getLevelInfo(getRangeLevel()).range;
|
||||
|
||||
if(rng.size() >= 2 && rng[0] != 'X') //there is at least one hex in range (+artificial comma)
|
||||
for(auto & elem : rng)
|
||||
{
|
||||
std::string number1;
|
||||
std::string number2;
|
||||
int beg = 0;
|
||||
int end = 0;
|
||||
bool readingFirst = true;
|
||||
for(auto & elem : rng)
|
||||
{
|
||||
if(std::isdigit(elem) ) //reading number
|
||||
{
|
||||
if(readingFirst)
|
||||
number1 += elem;
|
||||
else
|
||||
number2 += elem;
|
||||
}
|
||||
else if(elem == ',') //comma
|
||||
{
|
||||
//calculating variables
|
||||
if(readingFirst)
|
||||
{
|
||||
beg = std::stoi(number1);
|
||||
number1 = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
end = std::stoi(number2);
|
||||
number2 = "";
|
||||
}
|
||||
//obtaining new hexes
|
||||
std::set<ui16> curLayer;
|
||||
if(readingFirst)
|
||||
{
|
||||
curLayer = getInRange(centralHex, beg, beg);
|
||||
}
|
||||
else
|
||||
{
|
||||
curLayer = getInRange(centralHex, beg, end);
|
||||
readingFirst = true;
|
||||
}
|
||||
//adding obtained hexes
|
||||
for(const auto & curLayer_it : curLayer)
|
||||
{
|
||||
ret.insert(curLayer_it);
|
||||
}
|
||||
|
||||
}
|
||||
else if(elem == '-') //dash
|
||||
{
|
||||
beg = std::stoi(number1);
|
||||
number1 = "";
|
||||
readingFirst = false;
|
||||
}
|
||||
}
|
||||
std::set<ui16> curLayer = getInRange(centralHex, elem, elem);
|
||||
//adding obtained hexes
|
||||
for(const auto & curLayer_it : curLayer)
|
||||
ret.insert(curLayer_it);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -562,7 +562,7 @@ CSpell::TargetInfo::TargetInfo(const CSpell * spell, const int level, spells::Mo
|
||||
const auto & levelInfo = spell->getLevelInfo(level);
|
||||
|
||||
smart = levelInfo.smartTarget;
|
||||
massive = levelInfo.range == "X";
|
||||
massive = levelInfo.range.empty();
|
||||
clearAffected = levelInfo.clearAffected;
|
||||
clearTarget = levelInfo.clearTarget;
|
||||
}
|
||||
@ -682,6 +682,64 @@ const std::vector<std::string> & CSpellHandler::getTypeNames() const
|
||||
return typeNames;
|
||||
}
|
||||
|
||||
std::vector<int> CSpellHandler::spellRangeInHexes(std::string input) const
|
||||
{
|
||||
std::set<BattleHex> ret;
|
||||
std::string rng = input + ','; //copy + artificial comma for easier handling
|
||||
|
||||
if(rng.size() >= 2 && rng[0] != 'X') //there is at least one hex in range (+artificial comma)
|
||||
{
|
||||
std::string number1;
|
||||
std::string number2;
|
||||
int beg = 0;
|
||||
int end = 0;
|
||||
bool readingFirst = true;
|
||||
for(auto & elem : rng)
|
||||
{
|
||||
if(std::isdigit(elem) ) //reading number
|
||||
{
|
||||
if(readingFirst)
|
||||
number1 += elem;
|
||||
else
|
||||
number2 += elem;
|
||||
}
|
||||
else if(elem == ',') //comma
|
||||
{
|
||||
//calculating variables
|
||||
if(readingFirst)
|
||||
{
|
||||
beg = std::stoi(number1);
|
||||
number1 = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
end = std::stoi(number2);
|
||||
number2 = "";
|
||||
}
|
||||
//obtaining new hexes
|
||||
std::set<ui16> curLayer;
|
||||
if(readingFirst)
|
||||
{
|
||||
ret.insert(beg);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = beg; i <= end; ++i)
|
||||
ret.insert(i);
|
||||
}
|
||||
}
|
||||
else if(elem == '-') //dash
|
||||
{
|
||||
beg = std::stoi(number1);
|
||||
number1 = "";
|
||||
readingFirst = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::vector<int>(ret.begin(), ret.end());
|
||||
}
|
||||
|
||||
std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
|
||||
{
|
||||
assert(identifier.find(':') == std::string::npos);
|
||||
@ -936,7 +994,7 @@ std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, c
|
||||
levelObject.smartTarget = levelNode["targetModifier"]["smart"].Bool();
|
||||
levelObject.clearTarget = levelNode["targetModifier"]["clearTarget"].Bool();
|
||||
levelObject.clearAffected = levelNode["targetModifier"]["clearAffected"].Bool();
|
||||
levelObject.range = levelNode["range"].String();
|
||||
levelObject.range = spellRangeInHexes(levelNode["range"].String());
|
||||
|
||||
for(const auto & elem : levelNode["effects"].Struct())
|
||||
{
|
||||
|
@ -67,12 +67,6 @@ public:
|
||||
|
||||
///resource name
|
||||
AnimationPath resourceName;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & minimumAngle;
|
||||
h & resourceName;
|
||||
}
|
||||
};
|
||||
|
||||
struct AnimationItem
|
||||
@ -83,14 +77,6 @@ public:
|
||||
int pause;
|
||||
|
||||
AnimationItem();
|
||||
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & resourceName;
|
||||
h & effectName;
|
||||
h & verticalPosition;
|
||||
h & pause;
|
||||
}
|
||||
};
|
||||
|
||||
using TAnimation = AnimationItem;
|
||||
@ -111,14 +97,6 @@ public:
|
||||
///use selectProjectile to access
|
||||
std::vector<ProjectileInfo> projectile;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & projectile;
|
||||
h & hit;
|
||||
h & cast;
|
||||
h & affect;
|
||||
}
|
||||
|
||||
AnimationPath selectProjectile(const double angle) const;
|
||||
} animationInfo;
|
||||
|
||||
@ -132,27 +110,13 @@ public:
|
||||
bool smartTarget = true;
|
||||
bool clearTarget = false;
|
||||
bool clearAffected = false;
|
||||
std::string range = "0";
|
||||
std::vector<int> range = { 0 };
|
||||
|
||||
//TODO: remove these two when AI will understand special effects
|
||||
std::vector<std::shared_ptr<Bonus>> effects; //deprecated
|
||||
std::vector<std::shared_ptr<Bonus>> cumulativeEffects; //deprecated
|
||||
|
||||
JsonNode battleEffects;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & cost;
|
||||
h & power;
|
||||
h & AIValue;
|
||||
h & smartTarget;
|
||||
h & range;
|
||||
h & effects;
|
||||
h & cumulativeEffects;
|
||||
h & clearTarget;
|
||||
h & clearAffected;
|
||||
h & battleEffects;
|
||||
}
|
||||
};
|
||||
|
||||
/** \brief Low level accessor. Don`t use it if absolutely necessary
|
||||
@ -342,6 +306,8 @@ bool DLL_LINKAGE isInScreenRange(const int3 ¢er, const int3 &pos); //for spe
|
||||
|
||||
class DLL_LINKAGE CSpellHandler: public CHandlerBase<SpellID, spells::Spell, CSpell, spells::Service>
|
||||
{
|
||||
std::vector<int> spellRangeInHexes(std::string rng) const;
|
||||
|
||||
public:
|
||||
///IHandler base
|
||||
std::vector<JsonNode> loadLegacyData() override;
|
||||
|
Loading…
Reference in New Issue
Block a user