1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

[refactor]

+ crexp parser: parse mind immunity
This commit is contained in:
alexvins 2013-02-25 12:18:45 +00:00
parent 10fbe7b11e
commit 2cb86d84fa
5 changed files with 80 additions and 52 deletions

View File

@ -451,6 +451,7 @@
[ [
{ {
"type": "ALWAYS_MAXIMUM_DAMAGE", "type": "ALWAYS_MAXIMUM_DAMAGE",
"subtype": -1, //any attack
"valType":"INDEPENDENT_MAX", "valType":"INDEPENDENT_MAX",
"duration": "N_TURNS" "duration": "N_TURNS"
} }
@ -462,7 +463,8 @@
"id": 42, "id": 42,
"effect": -1, "effect": -1,
"anim": 40, "anim": 40,
"ranges": [ "0", "0", "0", "X" ], "counters" : [41], "ranges": [ "0", "0", "0", "X" ],
"counters" : [41],
"effects": "effects":
[ [
{ {
@ -480,7 +482,8 @@
"id": 43, "id": 43,
"effect": 1, "effect": 1,
"anim": 4, "anim": 4,
"ranges": [ "0", "0", "0", "X" ], "counters" : [45], "ranges": [ "0", "0", "0", "X" ],
"counters" : [45],
"effects": "effects":
[ [
{ {
@ -513,7 +516,8 @@
"id": 45, "id": 45,
"effect": -1, "effect": -1,
"anim": 56, "anim": 56,
"ranges": [ "0", "0", "0", "X" ], "counters" : [43], "ranges": [ "0", "0", "0", "X" ],
"counters" : [43],
"effects": "effects":
[ [
{ {
@ -600,7 +604,8 @@
"id": 50, "id": 50,
"effect": -1, "effect": -1,
"anim": 30, "anim": 30,
"ranges": [ "0", "0", "0", "X" ], "counters" : [49], "ranges": [ "0", "0", "0", "X" ],
"counters" : [49],
"effects": "effects":
[ [
{ {

View File

@ -157,7 +157,7 @@ static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
Bonus *nsf = new Bonus(); Bonus *nsf = new Bonus();
std::string type = ability_vec[0].String(); 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 (it == bonusNameMap.end()) {
if (type == "DOUBLE_WIDE") if (type == "DOUBLE_WIDE")
@ -177,23 +177,19 @@ static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
nsf->type = it->second; nsf->type = it->second;
nsf->val = ability_vec[1].Float(); JsonUtils::parseTypedBonusShort(ability_vec,nsf);
JsonUtils::resolveIdentifier(ability_vec[2],nsf->subtype);
nsf->additionalInfo = ability_vec[3].Float();
nsf->source = Bonus::CREATURE_ABILITY; nsf->source = Bonus::CREATURE_ABILITY;
nsf->sid = cre->idNumber; nsf->sid = cre->idNumber;
//nsf->duration = Bonus::ONE_BATTLE; //what the?
nsf->duration = Bonus::PERMANENT;
nsf->turnsRemain = 0;
cre->addNewBonus(nsf); cre->addNewBonus(nsf);
} }
static void RemoveAbility(CCreature *cre, const JsonNode &ability) 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 (it == bonusNameMap.end()) {
if (type == "DOUBLE_WIDE") if (type == "DOUBLE_WIDE")
@ -204,7 +200,7 @@ static void RemoveAbility(CCreature *cre, const JsonNode &ability)
return; return;
} }
int typeNo = it->second; const int typeNo = it->second;
Bonus::BonusType ecf = static_cast<Bonus::BonusType>(typeNo); Bonus::BonusType ecf = static_cast<Bonus::BonusType>(typeNo);
@ -214,7 +210,7 @@ static void RemoveAbility(CCreature *cre, const JsonNode &ability)
void CCreatureHandler::loadCreatures() 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 /////////////////// ////////////reading ZCRTRAIT.TXT ///////////////////
CLegacyConfigParser parser("DATA/ZCRTRAIT.TXT"); CLegacyConfigParser parser("DATA/ZCRTRAIT.TXT");
@ -263,24 +259,24 @@ void CCreatureHandler::loadCreatures()
ncre.abilityRefs = parser.readString(); ncre.abilityRefs = parser.readString();
{ //adding abilities from ZCRTRAIT.TXT { //adding abilities from ZCRTRAIT.TXT
static const std::map<std::string,Bonus::BonusType> abilityMap = static const std::pair < std::string,Bonus::BonusType> abilityMap [] =
boost::assign::map_list_of {{"FLYING_ARMY", Bonus::FLYING},
("FLYING_ARMY", Bonus::FLYING) {"SHOOTING_ARMY", Bonus::SHOOTER},
("SHOOTING_ARMY", Bonus::SHOOTER) {"SIEGE_WEAPON", Bonus::SIEGE_WEAPON},
("SIEGE_WEAPON", Bonus::SIEGE_WEAPON) {"const_free_attack", Bonus::BLOCKS_RETALIATION},
("const_free_attack", Bonus::BLOCKS_RETALIATION) {"IS_UNDEAD", Bonus::UNDEAD},
("IS_UNDEAD", Bonus::UNDEAD) {"const_no_melee_penalty",Bonus::NO_MELEE_PENALTY},
("const_no_melee_penalty",Bonus::NO_MELEE_PENALTY) {"const_jousting",Bonus::JOUSTING},
("const_jousting",Bonus::JOUSTING) {"KING_1",Bonus::KING1},
("KING_1",Bonus::KING1) {"KING_2",Bonus::KING2},
("KING_2",Bonus::KING2) {"KING_3",Bonus::KING3},
("KING_3",Bonus::KING3) {"const_no_wall_penalty",Bonus::NO_WALL_PENALTY},
("const_no_wall_penalty",Bonus::NO_WALL_PENALTY) {"CATAPULT",Bonus::CATAPULT},
("CATAPULT",Bonus::CATAPULT) {"MULTI_HEADED",Bonus::ATTACKS_ALL_ADJACENT},
("MULTI_HEADED",Bonus::ATTACKS_ALL_ADJACENT) {"IMMUNE_TO_MIND_SPELLS",Bonus::MIND_IMMUNITY},
("IMMUNE_TO_MIND_SPELLS",Bonus::MIND_IMMUNITY) {"IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY},
("IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY) {"IMMUNE_TO_FIRE_SPELLS",Bonus::FIRE_IMMUNITY},
("HAS_EXTENDED_ATTACK",Bonus::TWO_HEX_ATTACK_BREATH); {"HAS_EXTENDED_ATTACK",Bonus::TWO_HEX_ATTACK_BREATH}};
auto hasAbility = [&ncre](const std::string name) -> bool auto hasAbility = [&ncre](const std::string name) -> bool
{ {
@ -351,10 +347,9 @@ void CCreatureHandler::loadCreatures()
BOOST_FOREACH(const JsonNode &bonus, config2["bonuses"].Vector()) BOOST_FOREACH(const JsonNode &bonus, config2["bonuses"].Vector())
{ {
std::map<std::string,Bonus::BonusType>::const_iterator it_map; const std::string bonusID = bonus["id"].String();
std::string bonusID = bonus["id"].String();
it_map = bonusNameMap.find(bonusID); auto it_map = bonusNameMap.find(bonusID);
if (it_map != bonusNameMap.end()) if (it_map != bonusNameMap.end())
stackBonuses[it_map->second] = std::pair<std::string, std::string>(bonus["name"].String(), bonus["description"].String()); stackBonuses[it_map->second] = std::pair<std::string, std::string>(bonus["name"].String(), bonus["description"].String());
else else
@ -908,6 +903,9 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, CLegacyConfigPars
case '0': case '0':
b.type = Bonus::RECEPTIVE; b.type = Bonus::RECEPTIVE;
break; break;
case 'm':
b.type = Bonus::MIND_IMMUNITY;
break;
default: default:
tlog5 << "Not parsed bonus " << buf << mod << "\n"; tlog5 << "Not parsed bonus " << buf << mod << "\n";
return; return;

View File

@ -672,7 +672,7 @@ inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, s
return sf; 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) 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)); return new Bonus(makeFeatureVal(type, duration, subtype, value, source, turnsRemain, additionalInfo));

View File

@ -885,6 +885,18 @@ JsonValidator::JsonValidator(JsonNode &root, const JsonNode &schema, bool Minimi
tlog3<<errors; 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 * JsonUtils::parseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility, create universal parser for all bonus properties
{ {
Bonus * b = new Bonus(); Bonus * b = new Bonus();
@ -892,15 +904,12 @@ Bonus * JsonUtils::parseBonus (const JsonVector &ability_vec) //TODO: merge with
auto it = bonusNameMap.find(type); auto it = bonusNameMap.find(type);
if (it == bonusNameMap.end()) 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; return b;
} }
b->type = it->second; b->type = it->second;
b->val = ability_vec[1].Float();
resolveIdentifier(ability_vec[2],b->subtype); parseTypedBonusShort(ability_vec, b);
b->additionalInfo = ability_vec[3].Float();
b->duration = Bonus::PERMANENT; //TODO: handle flags (as integer)
b->turnsRemain = 0;
return b; return b;
} }
template <typename T> template <typename T>

View File

@ -114,21 +114,37 @@ public:
namespace JsonUtils 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 JsonVector &ability_vec);
DLL_LINKAGE Bonus * parseBonus (const JsonNode &bonus); DLL_LINKAGE Bonus * parseBonus (const JsonNode &bonus);
DLL_LINKAGE void unparseBonus (JsonNode &node, const Bonus * 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 (si32 &var, const JsonNode &node, std::string name);
DLL_LINKAGE void resolveIdentifier (const JsonNode &node, si32 &var); DLL_LINKAGE void resolveIdentifier (const JsonNode &node, si32 &var);
/// recursivly merges source into dest, replacing identical fields /**
/// struct : recursively calls this function * @brief recursivly merges source into dest, replacing identical fields
/// arrays : each entry will be merged recursively * struct : recursively calls this function
/// values : value in source will replace value in dest * arrays : each entry will be merged recursively
/// null : if value in source is present but set to null it will delete entry in dest * 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 * @note this function will destroy data in source
*/
DLL_LINKAGE void merge(JsonNode & dest, JsonNode & 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); DLL_LINKAGE void mergeCopy(JsonNode & dest, JsonNode source);
/** /**