mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
[refactor]
+ crexp parser: parse mind immunity
This commit is contained in:
parent
10fbe7b11e
commit
2cb86d84fa
@ -451,6 +451,7 @@
|
||||
[
|
||||
{
|
||||
"type": "ALWAYS_MAXIMUM_DAMAGE",
|
||||
"subtype": -1, //any attack
|
||||
"valType":"INDEPENDENT_MAX",
|
||||
"duration": "N_TURNS"
|
||||
}
|
||||
@ -462,7 +463,8 @@
|
||||
"id": 42,
|
||||
"effect": -1,
|
||||
"anim": 40,
|
||||
"ranges": [ "0", "0", "0", "X" ], "counters" : [41],
|
||||
"ranges": [ "0", "0", "0", "X" ],
|
||||
"counters" : [41],
|
||||
"effects":
|
||||
[
|
||||
{
|
||||
@ -480,7 +482,8 @@
|
||||
"id": 43,
|
||||
"effect": 1,
|
||||
"anim": 4,
|
||||
"ranges": [ "0", "0", "0", "X" ], "counters" : [45],
|
||||
"ranges": [ "0", "0", "0", "X" ],
|
||||
"counters" : [45],
|
||||
"effects":
|
||||
[
|
||||
{
|
||||
@ -513,7 +516,8 @@
|
||||
"id": 45,
|
||||
"effect": -1,
|
||||
"anim": 56,
|
||||
"ranges": [ "0", "0", "0", "X" ], "counters" : [43],
|
||||
"ranges": [ "0", "0", "0", "X" ],
|
||||
"counters" : [43],
|
||||
"effects":
|
||||
[
|
||||
{
|
||||
@ -600,7 +604,8 @@
|
||||
"id": 50,
|
||||
"effect": -1,
|
||||
"anim": 30,
|
||||
"ranges": [ "0", "0", "0", "X" ], "counters" : [49],
|
||||
"ranges": [ "0", "0", "0", "X" ],
|
||||
"counters" : [49],
|
||||
"effects":
|
||||
[
|
||||
{
|
||||
|
@ -157,7 +157,7 @@ static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
|
||||
Bonus *nsf = new Bonus();
|
||||
std::string type = ability_vec[0].String();
|
||||
|
||||
std::map<std::string, Bonus::BonusType>::const_iterator it = bonusNameMap.find(type);
|
||||
auto it = bonusNameMap.find(type);
|
||||
|
||||
if (it == bonusNameMap.end()) {
|
||||
if (type == "DOUBLE_WIDE")
|
||||
@ -177,23 +177,19 @@ static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
|
||||
|
||||
nsf->type = it->second;
|
||||
|
||||
nsf->val = ability_vec[1].Float();
|
||||
JsonUtils::resolveIdentifier(ability_vec[2],nsf->subtype);
|
||||
nsf->additionalInfo = ability_vec[3].Float();
|
||||
JsonUtils::parseTypedBonusShort(ability_vec,nsf);
|
||||
|
||||
nsf->source = Bonus::CREATURE_ABILITY;
|
||||
nsf->sid = cre->idNumber;
|
||||
//nsf->duration = Bonus::ONE_BATTLE; //what the?
|
||||
nsf->duration = Bonus::PERMANENT;
|
||||
nsf->turnsRemain = 0;
|
||||
|
||||
cre->addNewBonus(nsf);
|
||||
}
|
||||
|
||||
static void RemoveAbility(CCreature *cre, const JsonNode &ability)
|
||||
{
|
||||
std::string type = ability.String();
|
||||
const std::string type = ability.String();
|
||||
|
||||
std::map<std::string, Bonus::BonusType>::const_iterator it = bonusNameMap.find(type);
|
||||
auto it = bonusNameMap.find(type);
|
||||
|
||||
if (it == bonusNameMap.end()) {
|
||||
if (type == "DOUBLE_WIDE")
|
||||
@ -204,7 +200,7 @@ static void RemoveAbility(CCreature *cre, const JsonNode &ability)
|
||||
return;
|
||||
}
|
||||
|
||||
int typeNo = it->second;
|
||||
const int typeNo = it->second;
|
||||
|
||||
Bonus::BonusType ecf = static_cast<Bonus::BonusType>(typeNo);
|
||||
|
||||
@ -214,7 +210,7 @@ static void RemoveAbility(CCreature *cre, const JsonNode &ability)
|
||||
|
||||
void CCreatureHandler::loadCreatures()
|
||||
{
|
||||
tlog5 << "\t\tReading config/cr_abils.json and ZCRTRAIT.TXT" << std::endl;
|
||||
tlog5 << "\t\tReading ZCRTRAIT.TXT" << std::endl;
|
||||
|
||||
////////////reading ZCRTRAIT.TXT ///////////////////
|
||||
CLegacyConfigParser parser("DATA/ZCRTRAIT.TXT");
|
||||
@ -263,24 +259,24 @@ void CCreatureHandler::loadCreatures()
|
||||
ncre.abilityRefs = parser.readString();
|
||||
|
||||
{ //adding abilities from ZCRTRAIT.TXT
|
||||
static const std::map<std::string,Bonus::BonusType> abilityMap =
|
||||
boost::assign::map_list_of
|
||||
("FLYING_ARMY", Bonus::FLYING)
|
||||
("SHOOTING_ARMY", Bonus::SHOOTER)
|
||||
("SIEGE_WEAPON", Bonus::SIEGE_WEAPON)
|
||||
("const_free_attack", Bonus::BLOCKS_RETALIATION)
|
||||
("IS_UNDEAD", Bonus::UNDEAD)
|
||||
("const_no_melee_penalty",Bonus::NO_MELEE_PENALTY)
|
||||
("const_jousting",Bonus::JOUSTING)
|
||||
("KING_1",Bonus::KING1)
|
||||
("KING_2",Bonus::KING2)
|
||||
("KING_3",Bonus::KING3)
|
||||
("const_no_wall_penalty",Bonus::NO_WALL_PENALTY)
|
||||
("CATAPULT",Bonus::CATAPULT)
|
||||
("MULTI_HEADED",Bonus::ATTACKS_ALL_ADJACENT)
|
||||
("IMMUNE_TO_MIND_SPELLS",Bonus::MIND_IMMUNITY)
|
||||
("IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY)
|
||||
("HAS_EXTENDED_ATTACK",Bonus::TWO_HEX_ATTACK_BREATH);
|
||||
static const std::pair < std::string,Bonus::BonusType> abilityMap [] =
|
||||
{{"FLYING_ARMY", Bonus::FLYING},
|
||||
{"SHOOTING_ARMY", Bonus::SHOOTER},
|
||||
{"SIEGE_WEAPON", Bonus::SIEGE_WEAPON},
|
||||
{"const_free_attack", Bonus::BLOCKS_RETALIATION},
|
||||
{"IS_UNDEAD", Bonus::UNDEAD},
|
||||
{"const_no_melee_penalty",Bonus::NO_MELEE_PENALTY},
|
||||
{"const_jousting",Bonus::JOUSTING},
|
||||
{"KING_1",Bonus::KING1},
|
||||
{"KING_2",Bonus::KING2},
|
||||
{"KING_3",Bonus::KING3},
|
||||
{"const_no_wall_penalty",Bonus::NO_WALL_PENALTY},
|
||||
{"CATAPULT",Bonus::CATAPULT},
|
||||
{"MULTI_HEADED",Bonus::ATTACKS_ALL_ADJACENT},
|
||||
{"IMMUNE_TO_MIND_SPELLS",Bonus::MIND_IMMUNITY},
|
||||
{"IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY},
|
||||
{"IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY},
|
||||
{"HAS_EXTENDED_ATTACK",Bonus::TWO_HEX_ATTACK_BREATH}};
|
||||
|
||||
auto hasAbility = [&ncre](const std::string name) -> bool
|
||||
{
|
||||
@ -351,10 +347,9 @@ void CCreatureHandler::loadCreatures()
|
||||
|
||||
BOOST_FOREACH(const JsonNode &bonus, config2["bonuses"].Vector())
|
||||
{
|
||||
std::map<std::string,Bonus::BonusType>::const_iterator it_map;
|
||||
std::string bonusID = bonus["id"].String();
|
||||
const std::string bonusID = bonus["id"].String();
|
||||
|
||||
it_map = bonusNameMap.find(bonusID);
|
||||
auto it_map = bonusNameMap.find(bonusID);
|
||||
if (it_map != bonusNameMap.end())
|
||||
stackBonuses[it_map->second] = std::pair<std::string, std::string>(bonus["name"].String(), bonus["description"].String());
|
||||
else
|
||||
@ -908,6 +903,9 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigPars
|
||||
case '0':
|
||||
b.type = Bonus::RECEPTIVE;
|
||||
break;
|
||||
case 'm':
|
||||
b.type = Bonus::MIND_IMMUNITY;
|
||||
break;
|
||||
default:
|
||||
tlog5 << "Not parsed bonus " << buf << mod << "\n";
|
||||
return;
|
||||
|
@ -672,7 +672,7 @@ inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, s
|
||||
return sf;
|
||||
}
|
||||
|
||||
//generates HeroBonus from given data
|
||||
///generates HeroBonus from given data
|
||||
inline Bonus * makeFeature(Bonus::BonusType type, ui8 duration, si16 subtype, si32 value, Bonus::BonusSource source, ui16 turnsRemain = 0, si32 additionalInfo = 0)
|
||||
{
|
||||
return new Bonus(makeFeatureVal(type, duration, subtype, value, source, turnsRemain, additionalInfo));
|
||||
|
@ -885,6 +885,18 @@ JsonValidator::JsonValidator(JsonNode &root, const JsonNode &schema, bool Minimi
|
||||
tlog3<<errors;
|
||||
}
|
||||
|
||||
///JsonUtils
|
||||
|
||||
void JsonUtils::parseTypedBonusShort(const JsonVector& source, Bonus *dest)
|
||||
{
|
||||
dest->val = source[1].Float();
|
||||
resolveIdentifier(source[2],dest->subtype);
|
||||
dest->additionalInfo = source[3].Float();
|
||||
dest->duration = Bonus::PERMANENT; //TODO: handle flags (as integer)
|
||||
dest->turnsRemain = 0;
|
||||
}
|
||||
|
||||
|
||||
Bonus * JsonUtils::parseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility, create universal parser for all bonus properties
|
||||
{
|
||||
Bonus * b = new Bonus();
|
||||
@ -892,15 +904,12 @@ Bonus * JsonUtils::parseBonus (const JsonVector &ability_vec) //TODO: merge with
|
||||
auto it = bonusNameMap.find(type);
|
||||
if (it == bonusNameMap.end())
|
||||
{
|
||||
tlog1 << "Error: invalid ability type " << type << " in creatures.txt" << std::endl;
|
||||
tlog1 << "Error: invalid ability type " << type << std::endl;
|
||||
return b;
|
||||
}
|
||||
b->type = it->second;
|
||||
b->val = ability_vec[1].Float();
|
||||
resolveIdentifier(ability_vec[2],b->subtype);
|
||||
b->additionalInfo = ability_vec[3].Float();
|
||||
b->duration = Bonus::PERMANENT; //TODO: handle flags (as integer)
|
||||
b->turnsRemain = 0;
|
||||
|
||||
parseTypedBonusShort(ability_vec, b);
|
||||
return b;
|
||||
}
|
||||
template <typename T>
|
||||
|
@ -114,21 +114,37 @@ public:
|
||||
|
||||
namespace JsonUtils
|
||||
{
|
||||
/**
|
||||
* @brief parse short bonus format, excluding type
|
||||
* @note sets duration to Permament
|
||||
*/
|
||||
DLL_LINKAGE void parseTypedBonusShort(const JsonVector &source, Bonus *dest);
|
||||
|
||||
///
|
||||
DLL_LINKAGE Bonus * parseBonus (const JsonVector &ability_vec);
|
||||
DLL_LINKAGE Bonus * parseBonus (const JsonNode &bonus);
|
||||
DLL_LINKAGE void unparseBonus (JsonNode &node, const Bonus * bonus);
|
||||
DLL_LINKAGE void resolveIdentifier (si32 &var, const JsonNode &node, std::string name);
|
||||
DLL_LINKAGE void resolveIdentifier (const JsonNode &node, si32 &var);
|
||||
|
||||
/// recursivly merges source into dest, replacing identical fields
|
||||
/// struct : recursively calls this function
|
||||
/// arrays : each entry will be merged recursively
|
||||
/// values : value in source will replace value in dest
|
||||
/// null : if value in source is present but set to null it will delete entry in dest
|
||||
|
||||
/// this function will destroy data in source
|
||||
/**
|
||||
* @brief recursivly merges source into dest, replacing identical fields
|
||||
* struct : recursively calls this function
|
||||
* arrays : each entry will be merged recursively
|
||||
* values : value in source will replace value in dest
|
||||
* null : if value in source is present but set to null it will delete entry in dest
|
||||
* @note this function will destroy data in source
|
||||
*/
|
||||
DLL_LINKAGE void merge(JsonNode & dest, JsonNode & source);
|
||||
/// this function will preserve data stored in source by creating copy
|
||||
|
||||
/**
|
||||
* @brief recursivly merges source into dest, replacing identical fields
|
||||
* struct : recursively calls this function
|
||||
* arrays : each entry will be merged recursively
|
||||
* values : value in source will replace value in dest
|
||||
* null : if value in source is present but set to null it will delete entry in dest
|
||||
* @note this function will preserve data stored in source by creating copy
|
||||
*/
|
||||
DLL_LINKAGE void mergeCopy(JsonNode & dest, JsonNode source);
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user