2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2007-06-09 16:28:03 +03:00
|
|
|
#include "CSpellHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
#include "CGeneralTextHandler.h"
|
2012-08-01 15:02:54 +03:00
|
|
|
#include "Filesystem/CResourceLoader.h"
|
2012-08-25 11:44:51 +03:00
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include "JsonNode.h"
|
2009-04-14 17:48:57 +03:00
|
|
|
#include <cctype>
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "GameConstants.h"
|
2012-05-18 23:50:16 +03:00
|
|
|
#include "BattleHex.h"
|
2012-12-18 13:32:11 +03:00
|
|
|
#include "CModHandler.h"
|
2009-04-14 17:48:57 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CSpellHandler.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
|
|
|
|
*
|
|
|
|
*/
|
2011-06-25 09:55:35 +03:00
|
|
|
using namespace boost::assign;
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2009-04-14 17:48:57 +03:00
|
|
|
namespace SRSLPraserHelpers
|
|
|
|
{
|
2009-05-24 01:57:39 +03:00
|
|
|
static int XYToHex(int x, int y)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return x + 17 * y;
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static int XYToHex(std::pair<int, int> xy)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return XYToHex(xy.first, xy.second);
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static int hexToY(int battleFieldPosition)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return battleFieldPosition/17;
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static int hexToX(int battleFieldPosition)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
int pos = battleFieldPosition - hexToY(battleFieldPosition) * 17;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static std::pair<int, int> hexToPair(int battleFieldPosition)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return std::make_pair(hexToX(battleFieldPosition), hexToY(battleFieldPosition));
|
|
|
|
}
|
|
|
|
|
|
|
|
//moves hex by one hex in given direction
|
|
|
|
//0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left
|
2009-05-24 01:57:39 +03:00
|
|
|
static std::pair<int, int> gotoDir(int x, int y, int direction)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
switch(direction)
|
|
|
|
{
|
|
|
|
case 0: //top left
|
2012-09-26 16:13:39 +03:00
|
|
|
return std::make_pair((y%2) ? x-1 : x, y-1);
|
2009-04-14 17:48:57 +03:00
|
|
|
case 1: //top right
|
2012-09-26 16:13:39 +03:00
|
|
|
return std::make_pair((y%2) ? x : x+1, y-1);
|
2009-04-14 17:48:57 +03:00
|
|
|
case 2: //right
|
|
|
|
return std::make_pair(x+1, y);
|
|
|
|
case 3: //right bottom
|
2012-09-26 16:13:39 +03:00
|
|
|
return std::make_pair((y%2) ? x : x+1, y+1);
|
2009-04-14 17:48:57 +03:00
|
|
|
case 4: //left bottom
|
2012-09-26 16:13:39 +03:00
|
|
|
return std::make_pair((y%2) ? x-1 : x, y+1);
|
2009-04-14 17:48:57 +03:00
|
|
|
case 5: //left
|
|
|
|
return std::make_pair(x-1, y);
|
2009-06-23 11:14:49 +03:00
|
|
|
default:
|
2012-04-22 10:32:45 +03:00
|
|
|
throw std::runtime_error("Disaster: wrong direction in SRSLPraserHelpers::gotoDir!\n");
|
2009-04-14 17:48:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static std::pair<int, int> gotoDir(std::pair<int, int> xy, int direction)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return gotoDir(xy.first, xy.second, direction);
|
|
|
|
}
|
|
|
|
|
2009-05-24 01:57:39 +03:00
|
|
|
static bool isGoodHex(std::pair<int, int> xy)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
return xy.first >=0 && xy.first < 17 && xy.second >= 0 && xy.second < 11;
|
|
|
|
}
|
|
|
|
|
|
|
|
//helper fonction for std::set<ui16> CSpell::rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const
|
2009-05-24 01:57:39 +03:00
|
|
|
static std::set<ui16> getInRange(unsigned int center, int low, int high)
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
|
|
|
std::set<ui16> ret;
|
|
|
|
if(low == 0)
|
|
|
|
{
|
|
|
|
ret.insert(center);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<int, int> mainPointForLayer[6]; //A, B, C, D, E, F points
|
|
|
|
for(int b=0; b<6; ++b)
|
|
|
|
mainPointForLayer[b] = hexToPair(center);
|
|
|
|
|
|
|
|
for(int it=1; it<=high; ++it) //it - distance to the center
|
2013-01-15 17:20:48 +03:00
|
|
|
{
|
2009-04-14 17:48:57 +03:00
|
|
|
for(int b=0; b<6; ++b)
|
|
|
|
mainPointForLayer[b] = gotoDir(mainPointForLayer[b], b);
|
|
|
|
|
|
|
|
if(it>=low)
|
|
|
|
{
|
|
|
|
std::pair<int, int> curHex;
|
|
|
|
|
|
|
|
//adding lines (A-b, B-c, C-d, etc)
|
|
|
|
for(int v=0; v<6; ++v)
|
|
|
|
{
|
|
|
|
curHex = mainPointForLayer[v];
|
|
|
|
for(int h=0; h<it; ++h)
|
|
|
|
{
|
|
|
|
if(isGoodHex(curHex))
|
|
|
|
ret.insert(XYToHex(curHex));
|
|
|
|
curHex = gotoDir(curHex, (v+2)%6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} //if(it>=low)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 17:20:48 +03:00
|
|
|
|
2009-04-14 17:48:57 +03:00
|
|
|
using namespace SRSLPraserHelpers;
|
2009-09-24 20:54:02 +03:00
|
|
|
CSpellHandler::CSpellHandler()
|
|
|
|
{
|
|
|
|
}
|
2013-01-15 17:20:48 +03:00
|
|
|
|
|
|
|
CSpell::CSpell()
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
isDamage = false;
|
|
|
|
isMind = false;
|
|
|
|
isRising = false;
|
|
|
|
isOffensive = false;
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
std::vector<BattleHex> CSpell::rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes) const
|
2009-04-14 17:48:57 +03:00
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
std::vector<BattleHex> ret;
|
|
|
|
|
|
|
|
if(id == Spells::FIRE_WALL || id == Spells::FORCE_FIELD)
|
|
|
|
{
|
|
|
|
//Special case - shape of obstacle depends on caster's side
|
|
|
|
//TODO make it possible through spell_info config
|
|
|
|
|
|
|
|
BattleHex::EDir firstStep, secondStep;
|
|
|
|
if(side)
|
|
|
|
{
|
|
|
|
firstStep = BattleHex::TOP_LEFT;
|
|
|
|
secondStep = BattleHex::TOP_RIGHT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstStep = BattleHex::TOP_RIGHT;
|
|
|
|
secondStep = BattleHex::TOP_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Adds hex to the ret if it's valid. Otherwise sets output arg flag if given.
|
|
|
|
auto addIfValid = [&](BattleHex hex)
|
|
|
|
{
|
|
|
|
if(hex.isValid())
|
|
|
|
ret.push_back(hex);
|
|
|
|
else if(outDroppedHexes)
|
|
|
|
*outDroppedHexes = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
ret.push_back(centralHex);
|
|
|
|
addIfValid(centralHex.moveInDir(firstStep, false));
|
|
|
|
if(schoolLvl >= 2) //advanced versions of fire wall / force field cotnains of 3 hexes
|
|
|
|
addIfValid(centralHex.moveInDir(firstStep, false).moveInDir(secondStep, false));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-14 17:48:57 +03:00
|
|
|
|
|
|
|
std::string rng = range[schoolLvl] + ','; //copy + artificial comma for easier handling
|
|
|
|
|
|
|
|
if(rng.size() >= 1 && rng[0] != 'X') //there is at lest one hex in range
|
|
|
|
{
|
|
|
|
std::string number1, number2;
|
|
|
|
int beg, end;
|
|
|
|
bool readingFirst = true;
|
|
|
|
for(int it=0; it<rng.size(); ++it)
|
|
|
|
{
|
|
|
|
if( std::isdigit(rng[it]) ) //reading numer
|
|
|
|
{
|
|
|
|
if(readingFirst)
|
|
|
|
number1 += rng[it];
|
|
|
|
else
|
|
|
|
number2 += rng[it];
|
|
|
|
}
|
|
|
|
else if(rng[it] == ',') //comma
|
|
|
|
{
|
|
|
|
//calculating variables
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
beg = atoi(number1.c_str());
|
|
|
|
number1 = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
end = atoi(number2.c_str());
|
|
|
|
number2 = "";
|
|
|
|
}
|
|
|
|
//obtaining new hexes
|
|
|
|
std::set<ui16> curLayer;
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
curLayer = getInRange(centralHex, beg, beg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curLayer = getInRange(centralHex, beg, end);
|
|
|
|
readingFirst = true;
|
|
|
|
}
|
|
|
|
//adding abtained hexes
|
|
|
|
for(std::set<ui16>::iterator it = curLayer.begin(); it != curLayer.end(); ++it)
|
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
ret.push_back(*it);
|
2009-04-14 17:48:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(rng[it] == '-') //dash
|
|
|
|
{
|
|
|
|
beg = atoi(number1.c_str());
|
|
|
|
number1 = "";
|
|
|
|
readingFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
//remove duplicates (TODO check if actually needed)
|
|
|
|
range::unique(ret);
|
2009-04-14 17:48:57 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-28 18:18:21 +03:00
|
|
|
CSpell::ETargetType CSpell::getTargetType() const //TODO: parse these at game launch
|
2011-02-21 18:53:23 +02:00
|
|
|
{
|
|
|
|
if(attributes.find("CREATURE_TARGET_1") != std::string::npos
|
|
|
|
|| attributes.find("CREATURE_TARGET_2") != std::string::npos)
|
|
|
|
return CREATURE_EXPERT_MASSIVE;
|
|
|
|
|
|
|
|
if(attributes.find("CREATURE_TARGET") != std::string::npos)
|
|
|
|
return CREATURE;
|
|
|
|
|
|
|
|
if(attributes.find("OBSTACLE_TARGET") != std::string::npos)
|
|
|
|
return OBSTACLE;
|
2013-01-15 17:20:48 +03:00
|
|
|
|
2011-02-21 18:53:23 +02:00
|
|
|
return NO_TARGET;
|
|
|
|
}
|
|
|
|
|
2012-02-17 00:19:07 +03:00
|
|
|
bool CSpell::isPositive() const
|
|
|
|
{
|
|
|
|
return positiveness == POSITIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::isNegative() const
|
|
|
|
{
|
|
|
|
return positiveness == NEGATIVE;
|
|
|
|
}
|
|
|
|
|
2012-03-31 00:36:07 +03:00
|
|
|
bool CSpell::isRisingSpell() const
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
return isRising;
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
|
|
|
|
2012-08-26 12:07:48 +03:00
|
|
|
bool CSpell::isDamageSpell() const
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
return isDamage;
|
2012-08-26 12:07:48 +03:00
|
|
|
}
|
2013-01-15 17:20:48 +03:00
|
|
|
|
|
|
|
bool CSpell::isMindSpell() const
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
return isMind;
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
bool CSpell::isOffensiveSpell() const
|
2013-01-15 17:20:48 +03:00
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
return isOffensive;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::hasEffects() const
|
|
|
|
{
|
|
|
|
return !effects[0].empty();
|
|
|
|
}
|
|
|
|
|
2013-01-15 17:20:48 +03:00
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
void CSpell::getEffects(std::vector<Bonus>& lst, const int level) const
|
|
|
|
{
|
|
|
|
if (level < 0 || level>3)
|
2013-01-15 17:20:48 +03:00
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
tlog1 << __FUNCTION__ << " invalid school level " << level;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lst.reserve(lst.size() + effects[level].size());
|
|
|
|
|
|
|
|
BOOST_FOREACH (Bonus b, effects[level])
|
|
|
|
{
|
|
|
|
//TODO: value, add value
|
2013-01-15 17:20:48 +03:00
|
|
|
lst.push_back(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
bool CSpell::isImmuneBy(const IBonusBearer* obj) const
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(auto b, limiters)
|
|
|
|
{
|
|
|
|
if (!obj->hasBonusOfType(b))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(auto b, immunities)
|
|
|
|
{
|
|
|
|
if (obj->hasBonusOfType(b))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMindSpell() && obj->hasBonusOfType(Bonus::MIND_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isDamageSpell() && obj->hasBonusOfType(Bonus::DIRECT_DAMAGE_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto battleTestElementalImmunity = [&,this](Bonus::BonusType element) -> bool
|
|
|
|
{
|
|
|
|
if (!isPositive()) //negative or indifferent
|
|
|
|
{
|
|
|
|
if ((isDamageSpell() && obj->hasBonusOfType(element, 2)) || obj->hasBonusOfType(element, 1))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (isPositive()) //positive
|
|
|
|
{
|
|
|
|
if (obj->hasBonusOfType(element, 0)) //must be immune to all spells
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fire)
|
|
|
|
{
|
|
|
|
if (battleTestElementalImmunity(Bonus::FIRE_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (water)
|
|
|
|
{
|
|
|
|
if (battleTestElementalImmunity(Bonus::WATER_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (earth)
|
|
|
|
{
|
|
|
|
if (battleTestElementalImmunity(Bonus::EARTH_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (air)
|
|
|
|
{
|
|
|
|
if (battleTestElementalImmunity(Bonus::AIR_IMMUNITY))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TBonusListPtr immunities = obj->getBonuses(Selector::type(Bonus::LEVEL_SPELL_IMMUNITY));
|
|
|
|
if(obj->hasBonusOfType(Bonus::NEGATE_ALL_NATURAL_IMMUNITIES))
|
|
|
|
{
|
|
|
|
immunities->remove_if([](const Bonus* b){ return b->source == Bonus::CREATURE_ABILITY; });
|
|
|
|
}
|
|
|
|
|
|
|
|
if(obj->hasBonusOfType(Bonus::SPELL_IMMUNITY, id)
|
|
|
|
|| ( immunities->size() > 0 && immunities->totalValue() >= level && level))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-15 17:20:48 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
bool DLL_LINKAGE isInScreenRange(const int3 ¢er, const int3 &pos)
|
2010-03-21 00:17:19 +02:00
|
|
|
{
|
|
|
|
int3 diff = pos - center;
|
|
|
|
if(diff.x >= -9 && diff.x <= 9 && diff.y >= -8 && diff.y <= 8)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
CSpell * CSpellHandler::loadSpell(CLegacyConfigParser & parser)
|
|
|
|
{
|
|
|
|
CSpell * spell = new CSpell; //new currently being read spell
|
|
|
|
|
|
|
|
spell->name = parser.readString();
|
|
|
|
spell->abbName = parser.readString();
|
|
|
|
spell->level = parser.readNumber();
|
|
|
|
spell->earth = parser.readString() == "x";
|
|
|
|
spell->water = parser.readString() == "x";
|
|
|
|
spell->fire = parser.readString() == "x";
|
|
|
|
spell->air = parser.readString() == "x";
|
|
|
|
|
2012-12-18 13:32:11 +03:00
|
|
|
spell->costs = parser.readNumArray<si32>(4);
|
2012-08-25 11:44:51 +03:00
|
|
|
|
|
|
|
spell->power = parser.readNumber();
|
2012-12-18 13:32:11 +03:00
|
|
|
spell->powers = parser.readNumArray<si32>(4);
|
2012-08-25 11:44:51 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < 9 ; i++)
|
2012-12-18 13:32:11 +03:00
|
|
|
spell->probabilities[i] = parser.readNumber();
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2012-12-18 13:32:11 +03:00
|
|
|
spell->AIVals = parser.readNumArray<si32>(4);
|
2012-08-25 11:44:51 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < 4 ; i++)
|
|
|
|
spell->descriptions.push_back(parser.readString());
|
|
|
|
|
|
|
|
spell->attributes = parser.readString();
|
|
|
|
spell->mainEffectAnim = -1;
|
|
|
|
return spell;
|
|
|
|
}
|
|
|
|
|
2007-06-09 16:28:03 +03:00
|
|
|
void CSpellHandler::loadSpells()
|
|
|
|
{
|
2012-08-25 11:44:51 +03:00
|
|
|
CLegacyConfigParser parser("DATA/SPTRAITS.TXT");
|
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
auto read = [&,this](bool combat, bool alility)
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
CSpell * spell = loadSpell(parser);
|
|
|
|
spell->id = spells.size();
|
|
|
|
spell->combatSpell = combat;
|
|
|
|
spell->creatureAbility = alility;
|
|
|
|
spells.push_back(spell);
|
|
|
|
}
|
|
|
|
while (parser.endLine() && !parser.isNextEntryEmpty());
|
|
|
|
};
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
auto skip = [&](int cnt)
|
2012-08-25 11:44:51 +03:00
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
for(int i=0; i<cnt; i++)
|
|
|
|
parser.endLine();
|
|
|
|
};
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
skip(5);// header
|
|
|
|
read(false,false); //read adventure map spells
|
|
|
|
skip(3);
|
|
|
|
read(true,false); //read battle spells
|
|
|
|
skip(3);
|
|
|
|
read(true,true);//read creature abilities
|
2012-08-25 11:44:51 +03:00
|
|
|
|
2013-01-15 17:20:48 +03:00
|
|
|
boost::replace_first (spells[Spells::DISRUPTING_RAY]->attributes, "2", ""); // disrupting ray will now affect single creature
|
|
|
|
|
|
|
|
|
|
|
|
spells.push_back(spells[Spells::ACID_BREATH_DEFENSE]); //clone Acid Breath attributes for Acid Breath damage effect
|
2011-09-04 05:26:56 +03:00
|
|
|
|
2008-12-20 19:08:51 +02:00
|
|
|
//loading of additional spell traits
|
2012-08-02 14:03:26 +03:00
|
|
|
const JsonNode config(ResourceID("config/spell_info.json"));
|
2011-09-04 05:26:56 +03:00
|
|
|
|
2012-12-18 13:32:11 +03:00
|
|
|
BOOST_FOREACH(auto &spell, config["spells"].Struct())
|
2008-12-20 19:08:51 +02:00
|
|
|
{
|
|
|
|
//reading exact info
|
2012-12-18 13:32:11 +03:00
|
|
|
int spellID = spell.second["id"].Float();
|
2012-09-14 02:41:03 +03:00
|
|
|
CSpell *s = spells[spellID];
|
2011-09-04 05:26:56 +03:00
|
|
|
|
2012-12-18 13:32:11 +03:00
|
|
|
s->positiveness = spell.second["effect"].Float();
|
|
|
|
s->mainEffectAnim = spell.second["anim"].Float();
|
2011-09-04 05:26:56 +03:00
|
|
|
|
2012-09-14 02:41:03 +03:00
|
|
|
s->range.resize(4);
|
2011-09-04 05:26:56 +03:00
|
|
|
int idx = 0;
|
2012-12-18 13:32:11 +03:00
|
|
|
BOOST_FOREACH(const JsonNode &range, spell.second["ranges"].Vector())
|
2012-09-14 02:41:03 +03:00
|
|
|
s->range[idx++] = range.String();
|
|
|
|
|
2012-12-18 13:32:11 +03:00
|
|
|
s->counteredSpells = spell.second["counters"].convertTo<std::vector<TSpell> >();
|
|
|
|
|
|
|
|
s->identifier = spell.first;
|
|
|
|
VLC->modh->identifiers.registerObject("spell." + spell.first, spellID);
|
|
|
|
|
2013-01-15 17:20:48 +03:00
|
|
|
const JsonNode & flags_node = spell.second["flags"];
|
|
|
|
if (!flags_node.isNull())
|
|
|
|
{
|
|
|
|
auto flags = flags_node.convertTo<std::vector<std::string> >();
|
|
|
|
|
|
|
|
BOOST_FOREACH (const auto & flag, flags)
|
|
|
|
{
|
|
|
|
if (flag == "damage")
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
s->isDamage = true;
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
else if (flag == "rising")
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
s->isRising = true;
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
else if (flag == "mind")
|
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
s->isMind = true;
|
|
|
|
}
|
|
|
|
else if (flag == "offensive")
|
|
|
|
{
|
|
|
|
s->isOffensive = true;
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & effects_node = spell.second["effects"];
|
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
BOOST_FOREACH (const JsonNode & bonus_node, effects_node.Vector())
|
2013-01-15 17:20:48 +03:00
|
|
|
{
|
2013-01-16 14:19:04 +03:00
|
|
|
auto &v_node = bonus_node["values"];
|
|
|
|
auto &a_node = bonus_node["ainfos"];
|
|
|
|
|
|
|
|
auto v = v_node.convertTo<std::vector<int> >();
|
|
|
|
auto a = a_node.convertTo<std::vector<int> >();
|
|
|
|
|
|
|
|
for (int i=0; i<4 ; i++)
|
2013-01-15 17:20:48 +03:00
|
|
|
{
|
|
|
|
Bonus * b = JsonUtils::parseBonus(bonus_node);
|
2013-01-16 14:19:04 +03:00
|
|
|
b->sid = s->id; //for all
|
|
|
|
b->source = Bonus::SPELL_EFFECT;//for all
|
|
|
|
b->val = s->powers[i];
|
|
|
|
|
|
|
|
if (!v.empty())
|
|
|
|
b->val = v[i];
|
|
|
|
if (!a.empty())
|
|
|
|
b->additionalInfo = a[i];
|
|
|
|
|
|
|
|
s->effects[i].push_back(*b);
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
2013-01-16 14:19:04 +03:00
|
|
|
|
2013-01-15 17:20:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-16 14:19:04 +03:00
|
|
|
|
|
|
|
auto find_in_map = [](std::string name, std::vector<Bonus::BonusType> &vec)
|
|
|
|
{
|
|
|
|
auto it = bonusNameMap.find(name);
|
|
|
|
if (it == bonusNameMap.end())
|
|
|
|
{
|
|
|
|
tlog1 << "Error: invalid bonus name" << name << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vec.push_back((Bonus::BonusType)it->second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto read_node = [&](std::string name, std::vector<Bonus::BonusType> &vec)
|
|
|
|
{
|
|
|
|
const JsonNode & node = spell.second[name];
|
|
|
|
|
|
|
|
if (!node.isNull())
|
|
|
|
{
|
|
|
|
auto names = node.convertTo<std::vector<std::string> >();
|
|
|
|
BOOST_FOREACH(auto name, names)
|
|
|
|
find_in_map(name, vec);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
read_node("immunity",s->immunities);
|
|
|
|
read_node("limit",s->limiters);
|
|
|
|
|
2008-12-20 19:08:51 +02:00
|
|
|
}
|
2013-01-15 17:20:48 +03:00
|
|
|
|
2012-11-14 17:27:18 +03:00
|
|
|
//spell fixes
|
2011-09-04 05:26:56 +03:00
|
|
|
|
|
|
|
//forgetfulness needs to get targets automatically on expert level
|
2013-01-15 17:20:48 +03:00
|
|
|
boost::replace_first(spells[Spells::FORGETFULNESS]->attributes, "CREATURE_TARGET", "CREATURE_TARGET_2"); //TODO: use flags instead?
|
2008-12-20 19:08:51 +02:00
|
|
|
}
|
2013-01-06 22:30:12 +03:00
|
|
|
|
|
|
|
std::vector<ui8> CSpellHandler::getDefaultAllowedSpells() const
|
|
|
|
{
|
|
|
|
std::vector<ui8> allowedSpells;
|
|
|
|
allowedSpells.resize(GameConstants::SPELLS_QUANTITY, 1);
|
|
|
|
return allowedSpells;
|
|
|
|
}
|