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

vcmi: remove vector speciality format

It is deprecated and will not be used anymore.
This commit is contained in:
Konstantin 2023-03-05 02:07:41 +03:00
parent 96c40eb36e
commit d9496dd9f7
4 changed files with 20 additions and 130 deletions

View File

@ -120,48 +120,24 @@
"additionalItems" : true "additionalItems" : true
}, },
"specialty": { "specialty": {
"anyOf" : [ "type" : "object",
{ "description": "Description of hero specialty using bonus system",
"type":"array", "additionalProperties" : false,
"description": "Description of hero specialty using bonus system (deprecated)", "properties" : {
"items": { "base" : {
"type" : "object",
"additionalProperties" : false,
"required" : [ "bonuses" ],
"properties" : {
"growsWithLevel" : {
"type" : "boolean",
"description" : "Specialty growth with level. Deprecated, use bonuses with updaters instead."
},
"bonuses" : {
"type" : "array",
"description" : "List of bonuses",
"items" : { "$ref" : "bonus.json" }
}
}
}
},
{
"type" : "object", "type" : "object",
"description": "Description of hero specialty using bonus system", "description" : "Will be merged with all bonuses."
"additionalProperties" : false, },
"properties" : { "bonuses" : {
"base" : { "type" : "object",
"type" : "object", "description" : "Set of bonuses",
"description" : "Will be merged with all bonuses." "additionalProperties" : { "$ref" : "bonus.json" }
}, },
"bonuses" : { "creature" : {
"type" : "object", "type" : "string",
"description" : "Set of bonuses", "description" : "Name of base creature to grant standard specialty to."
"additionalProperties" : { "$ref" : "bonus.json" }
},
"creature" : {
"type" : "string",
"description" : "Name of base creature to grant standard specialty to."
}
}
} }
] }
}, },
"spellbook": { "spellbook": {
"type":"array", "type":"array",

View File

@ -677,58 +677,6 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo
return result; return result;
} }
// convert deprecated format
std::vector<std::shared_ptr<Bonus>> SpecialtyBonusToBonuses(const SSpecialtyBonus & spec, int sid)
{
std::vector<std::shared_ptr<Bonus>> result;
for(std::shared_ptr<Bonus> oldBonus : spec.bonuses)
{
oldBonus->sid = sid;
if(oldBonus->type == Bonus::SPECIAL_SPELL_LEV || oldBonus->type == Bonus::SPECIAL_BLESS_DAMAGE)
{
// these bonuses used to auto-scale with hero level
std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*oldBonus);
newBonus->updater = std::make_shared<TimesHeroLevelUpdater>();
result.push_back(newBonus);
}
else if(spec.growsWithLevel)
{
std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*oldBonus);
switch(newBonus->type)
{
case Bonus::SECONDARY_SKILL_PREMY:
break; // ignore - used to be overwritten based on SPECIAL_SECONDARY_SKILL
case Bonus::SPECIAL_SECONDARY_SKILL:
newBonus->type = Bonus::SECONDARY_SKILL_PREMY;
newBonus->updater = std::make_shared<TimesHeroLevelUpdater>();
result.push_back(newBonus);
break;
case Bonus::PRIMARY_SKILL:
if((newBonus->subtype == PrimarySkill::ATTACK || newBonus->subtype == PrimarySkill::DEFENSE) && newBonus->limiter)
{
std::shared_ptr<CCreatureTypeLimiter> creatureLimiter = std::dynamic_pointer_cast<CCreatureTypeLimiter>(newBonus->limiter);
if(creatureLimiter)
{
const CCreature * cre = creatureLimiter->creature;
int creStat = newBonus->subtype == PrimarySkill::ATTACK ? cre->getAttack(false) : cre->getDefense(false);
int creLevel = cre->level ? cre->level : 5;
newBonus->updater = std::make_shared<GrowsWithLevelUpdater>(creStat, creLevel);
}
result.push_back(newBonus);
}
break;
default:
result.push_back(newBonus);
}
}
else
{
result.push_back(oldBonus);
}
}
return result;
}
void CHeroHandler::beforeValidate(JsonNode & object) void CHeroHandler::beforeValidate(JsonNode & object)
{ {
//handle "base" specialty info //handle "base" specialty info
@ -781,19 +729,7 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
} }
//new(er) format, using bonus system //new(er) format, using bonus system
const JsonNode & specialtyNode = node["specialty"]; const JsonNode & specialtyNode = node["specialty"];
if(specialtyNode.getType() == JsonNode::JsonType::DATA_VECTOR) if(specialtyNode.getType() == JsonNode::JsonType::DATA_STRUCT)
{
//deprecated middle-aged format
for(const JsonNode & specialty : node["specialty"].Vector())
{
SSpecialtyBonus hs;
hs.growsWithLevel = specialty["growsWithLevel"].Bool();
for (const JsonNode & bonus : specialty["bonuses"].Vector())
hs.bonuses.push_back(prepSpec(JsonUtils::parseBonus(bonus)));
hero->specialtyDeprecated.push_back(hs);
}
}
else if(specialtyNode.getType() == JsonNode::JsonType::DATA_STRUCT)
{ {
//creature specialty - alias for simplicity //creature specialty - alias for simplicity
if(!specialtyNode["creature"].isNull()) if(!specialtyNode["creature"].isNull())
@ -813,6 +749,8 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(keyValue.second))); hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(keyValue.second)));
} }
} }
else
logMod->error("Unsupported speciality format for hero %s!", hero->getNameTranslated());
} }
void CHeroHandler::loadExperience() void CHeroHandler::loadExperience()
@ -954,7 +892,7 @@ void CHeroHandler::afterLoadFinalization()
bonus->sid = hero->getIndex(); bonus->sid = hero->getIndex();
} }
if(hero->specDeprecated.size() > 0 || hero->specialtyDeprecated.size() > 0) if(hero->specDeprecated.size() > 0)
{ {
logMod->debug("Converting specialty format for hero %s(%s)", hero->getNameTranslated(), FactionID::encode(hero->heroClass->faction)); logMod->debug("Converting specialty format for hero %s(%s)", hero->getNameTranslated(), FactionID::encode(hero->heroClass->faction));
std::vector<std::shared_ptr<Bonus>> convertedBonuses; std::vector<std::shared_ptr<Bonus>> convertedBonuses;
@ -963,13 +901,7 @@ void CHeroHandler::afterLoadFinalization()
for(std::shared_ptr<Bonus> b : SpecialtyInfoToBonuses(spec, hero->ID.getNum())) for(std::shared_ptr<Bonus> b : SpecialtyInfoToBonuses(spec, hero->ID.getNum()))
convertedBonuses.push_back(b); convertedBonuses.push_back(b);
} }
for(const SSpecialtyBonus & spec : hero->specialtyDeprecated)
{
for(std::shared_ptr<Bonus> b : SpecialtyBonusToBonuses(spec, hero->ID.getNum()))
convertedBonuses.push_back(b);
}
hero->specDeprecated.clear(); hero->specDeprecated.clear();
hero->specialtyDeprecated.clear();
// store and create json for logging // store and create json for logging
std::vector<JsonNode> specVec; std::vector<JsonNode> specVec;
std::vector<std::string> specNames; std::vector<std::string> specNames;

View File

@ -44,18 +44,6 @@ struct SSpecialtyInfo
} }
}; };
struct SSpecialtyBonus
/// temporary hold
{
ui8 growsWithLevel;
BonusList bonuses;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & growsWithLevel;
h & bonuses;
}
};
class DLL_LINKAGE CHero : public HeroType class DLL_LINKAGE CHero : public HeroType
{ {
friend class CHeroHandler; friend class CHeroHandler;
@ -85,7 +73,6 @@ public:
CHeroClass * heroClass; CHeroClass * heroClass;
std::vector<std::pair<SecondarySkill, ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert) std::vector<std::pair<SecondarySkill, ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
std::vector<SSpecialtyInfo> specDeprecated; std::vector<SSpecialtyInfo> specDeprecated;
std::vector<SSpecialtyBonus> specialtyDeprecated;
BonusList specialty; BonusList specialty;
std::set<SpellID> spells; std::set<SpellID> spells;
bool haveSpellBook; bool haveSpellBook;
@ -147,7 +134,6 @@ public:
// convert deprecated format // convert deprecated format
std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo & spec, int sid = 0); std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo & spec, int sid = 0);
std::vector<std::shared_ptr<Bonus>> SpecialtyBonusToBonuses(const SSpecialtyBonus & spec, int sid = 0);
class DLL_LINKAGE CHeroClass : public HeroClass class DLL_LINKAGE CHeroClass : public HeroClass
{ {

View File

@ -509,10 +509,6 @@ void CGHeroInstance::initObj(CRandomGenerator & rand)
//copy active (probably growing) bonuses from hero prototype to hero object //copy active (probably growing) bonuses from hero prototype to hero object
for(const std::shared_ptr<Bonus> & b : type->specialty) for(const std::shared_ptr<Bonus> & b : type->specialty)
addNewBonus(b); addNewBonus(b);
//dito for old-style bonuses -> compatibility for old savegames
for(SSpecialtyBonus & sb : type->specialtyDeprecated)
for(const std::shared_ptr<Bonus> & b : sb.bonuses)
addNewBonus(b);
for(SSpecialtyInfo & spec : type->specDeprecated) for(SSpecialtyInfo & spec : type->specDeprecated)
for(const std::shared_ptr<Bonus> & b : SpecialtyInfoToBonuses(spec, type->getIndex())) for(const std::shared_ptr<Bonus> & b : SpecialtyInfoToBonuses(spec, type->getIndex()))
addNewBonus(b); addNewBonus(b);