diff --git a/config/spell_info.json b/config/spell_info.json index 8ce13a934..bb4ed554e 100644 --- a/config/spell_info.json +++ b/config/spell_info.json @@ -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": [ { diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index ca91f9e39..4c98b53b7 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -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::const_iterator it = bonusNameMap.find(type); + auto it = bonusNameMap.find(type); if (it == bonusNameMap.end()) { if (type == "DOUBLE_WIDE") @@ -176,24 +176,20 @@ static void AddAbility(CCreature *cre, const JsonVector &ability_vec) } nsf->type = it->second; + + JsonUtils::parseTypedBonusShort(ability_vec,nsf); - nsf->val = ability_vec[1].Float(); - JsonUtils::resolveIdentifier(ability_vec[2],nsf->subtype); - nsf->additionalInfo = ability_vec[3].Float(); 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::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(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 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::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(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; diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 7d7d11fc6..383a0cd37 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -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)); diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 5e2b3e0b5..d5886b5a0 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -885,6 +885,18 @@ JsonValidator::JsonValidator(JsonNode &root, const JsonNode &schema, bool Minimi tlog3<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 diff --git a/lib/JsonNode.h b/lib/JsonNode.h index eb9a784b3..5bf5491e1 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -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); /**