From 26862b4c518f11005f3a12949af3633e1b93fecf Mon Sep 17 00:00:00 2001 From: Henning Koehler Date: Tue, 12 Sep 2017 20:56:59 +1200 Subject: [PATCH] improved/fixed specialty json encoding --- lib/CHeroHandler.cpp | 2 +- lib/HeroBonus.cpp | 43 ++++++++++++++++++++++++++++++------------- lib/HeroBonus.h | 2 +- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 51aa94f77..34a699530 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -549,7 +549,7 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node) if (!specialties.isNull()) { logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier); - JsonNode specVec(JsonNode::DATA_VECTOR); + JsonNode specVec(JsonNode::JsonType::DATA_VECTOR); for(const JsonNode &specialty : node["specialties"].Vector()) { SSpecialtyInfo spec; diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 8c77a6193..a9cf550f2 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1166,31 +1166,48 @@ std::string Bonus::Description() const JsonNode subtypeToJson(Bonus::BonusType type, int subtype) { - JsonNode node; - switch(type) { case Bonus::PRIMARY_SKILL: - node.String() = PrimarySkill::names[subtype]; - break; + return JsonUtils::stringNode(PrimarySkill::names[subtype]); case Bonus::SECONDARY_SKILL_PREMY: - node.String() = NSecondarySkill::names[subtype]; - break; + return JsonUtils::stringNode(NSecondarySkill::names[subtype]); + case Bonus::SPECIAL_SPELL_LEV: + case Bonus::SPECIFIC_SPELL_DAMAGE: + case Bonus::SPECIAL_BLESS_DAMAGE: + case Bonus::MAXED_SPELL: + case Bonus::SPECIAL_PECULIAR_ENCHANT: + //return JsonUtils::stringNode((*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier); + return JsonUtils::intNode(subtype); //Issue 2790 + case Bonus::SPECIAL_UPGRADE: + return JsonUtils::stringNode(CreatureID::encode(subtype)); + case Bonus::GENERATE_RESOURCE: + return JsonUtils::stringNode(GameConstants::RESOURCE_NAMES[subtype]); default: - node.Integer() = subtype; - break; + return JsonUtils::intNode(subtype); } +} - return node; +JsonNode additionalInfoToJson(Bonus::BonusType type, int addInfo) +{ + switch(type) + { + case Bonus::SPECIAL_UPGRADE: + return JsonUtils::stringNode(CreatureID::encode(addInfo)); + default: + return JsonUtils::intNode(addInfo); + } } JsonNode Bonus::toJsonNode() const { - JsonNode root(JsonNode::DATA_STRUCT); + JsonNode root(JsonNode::JsonType::DATA_STRUCT); root["type"].String() = vstd::findKey(bonusNameMap, type); if(subtype != -1) root["subtype"] = subtypeToJson(type, subtype); + if(additionalInfo != -1) + root["addInfo"] = additionalInfoToJson(type, additionalInfo); if(val != 0) root["val"].Integer() = val; if(valType != ADDITIVE_VALUE) @@ -1413,7 +1430,7 @@ std::string ILimiter::toString() const JsonNode ILimiter::toJsonNode() const { - JsonNode root(JsonNode::DATA_STRUCT); + JsonNode root(JsonNode::JsonType::DATA_STRUCT); root["type"].String() = toString(); return root; } @@ -1454,7 +1471,7 @@ std::string CCreatureTypeLimiter::toString() const JsonNode CCreatureTypeLimiter::toJsonNode() const { - JsonNode root(JsonNode::DATA_STRUCT); + JsonNode root(JsonNode::JsonType::DATA_STRUCT); root["type"].String() = "CREATURE_TYPE_LIMITER"; root["parameters"].Vector().push_back(JsonUtils::stringNode(creature->identifier)); @@ -1692,7 +1709,7 @@ std::string ScalingUpdater::toString() const JsonNode ScalingUpdater::toJsonNode() const { - JsonNode root(JsonNode::DATA_STRUCT); + JsonNode root(JsonNode::JsonType::DATA_STRUCT); root["type"].String() = "GROWS_WITH_LEVEL"; root["parameters"].Vector().push_back(JsonUtils::intNode(valPer20)); diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 5ff40cbef..9d69e0d5e 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -214,7 +214,7 @@ private: BONUS_NAME(SPECIAL_BLESS_DAMAGE) /*val = spell (bless), additionalInfo = value per level in percent*/\ BONUS_NAME(MAXED_SPELL) /*val = id*/\ BONUS_NAME(SPECIAL_PECULIAR_ENCHANT) /*blesses and curses with id = val dependent on unit's level, subtype = 0 or 1 for Coronius*/\ - BONUS_NAME(SPECIAL_UPGRADE) /*val = base, additionalInfo = target */\ + BONUS_NAME(SPECIAL_UPGRADE) /*subtype = base, additionalInfo = target */\ BONUS_NAME(DRAGON_NATURE) \ BONUS_NAME(CREATURE_DAMAGE)/*subtype 0 = both, 1 = min, 2 = max*/\ BONUS_NAME(EXP_MULTIPLIER)/* val - percent of additional exp gained by stack/commander (base value 100)*/\