1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Cleanup old code, add compatibility for 1.5 mods

This commit is contained in:
Ivan Savenko 2024-08-16 13:39:36 +00:00
parent 01a9509ccb
commit abfb467f68
4 changed files with 23 additions and 45 deletions

View File

@ -58,7 +58,7 @@
"type" : "string"
},
"configuration" : {
"description" : "Configuration of building. Only used if 'type' is set to 'configurable'",
"description" : "Optional, configuration of building that can be activated by visiting hero",
"$ref" : "rewardable.json"
},
"cost" : {
@ -89,23 +89,9 @@
"gems" : { "type" : "number"}
}
},
"overrides" : {
"type" : "array",
"items" : [
{
"description" : "The buildings which bonuses should be overridden with bonuses of the current building",
"type" : "string"
}
]
},
"bonuses" : {
"type" : "array",
"description" : "Bonuses, provided by this special building on build using bonus system",
"items" : { "$ref" : "bonus.json" }
},
"onVisitBonuses" : {
"type" : "array",
"description" : "Bonuses, provided by this special building on hero visit and applied to the visiting hero",
"description" : "Bonuses that are provided by this building in any town where this building has been built. Only affects town itself (including siege), to propagate effect to player or team please use bonus propagators",
"items" : { "$ref" : "bonus.json" }
}
}

View File

@ -39,8 +39,7 @@ namespace BuildingSubID
MAGIC_UNIVERSITY,
TREASURY,
THIEVES_GUILD,
BANK,
CUSTOM_VISITING_BONUS
BANK
};
}

View File

@ -40,7 +40,6 @@ public:
BuildingSubID::EBuildingSubID subId; /// subtype for special buildings, -1 = the building is not special
std::set<BuildingID> overrideBids; /// the building which bonuses should be overridden with bonuses of the current building
BonusList buildingBonuses;
BonusList onVisitBonuses;
Rewardable::Info rewardableObjectInfo; ///configurable rewards for special buildings

View File

@ -254,6 +254,8 @@ void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList
bonus->description.appendTextID(building->getNameTextID());
//JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty.
assert(bonus->propagator == nullptr || bonus->propagator->getPropagatorType() != CBonusSystemNode::ENodeTypes::UNKNOWN);
if(bonus->propagator != nullptr
&& bonus->propagator->getPropagatorType() == CBonusSystemNode::ENodeTypes::UNKNOWN)
bonus->addPropagator(emptyPropagator());
@ -293,33 +295,19 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
VLC->generaltexth->registerString(source.getModScope(), ret->getNameTextID(), source["name"].String());
VLC->generaltexth->registerString(source.getModScope(), ret->getDescriptionTextID(), source["description"].String());
ret->subId = vstd::find_or(MappedKeys::SPECIAL_BUILDINGS, source["type"].String(), BuildingSubID::NONE);
ret->resources = TResources(source["cost"]);
ret->produce = TResources(source["produce"]);
if(ret->bid.IsSpecialOrGrail())
{
loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
if(ret->buildingBonuses.empty())
ret->subId = vstd::find_or(MappedKeys::SPECIAL_BUILDINGS, source["type"].String(), BuildingSubID::NONE);
loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret);
if(!ret->onVisitBonuses.empty())
{
if(ret->subId == BuildingSubID::NONE)
ret->subId = BuildingSubID::CUSTOM_VISITING_BONUS;
for(auto & bonus : ret->onVisitBonuses)
bonus->sid = BonusSourceID(ret->getUniqueTypeID());
}
if(!source["configuration"].isNull())
ret->rewardableObjectInfo.init(source["configuration"], ret->getBaseTextID());
}
//MODS COMPATIBILITY FOR 0.96
if(!ret->produce.nonZero() && ret->bid == BuildingID::RESOURCE_SILO)
loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
if(!source["configuration"].isNull())
ret->rewardableObjectInfo.init(source["configuration"], ret->getBaseTextID());
//MODS COMPATIBILITY FOR pre-1.6
if(ret->produce.empty() && ret->bid == BuildingID::RESOURCE_SILO)
{
logGlobal->warn("Resource silo in town '%s' does not produces any resources!", ret->town->faction->getJsonKey());
switch (ret->town->primaryRes.toEnum())
{
case EGameResID::GOLD:
@ -336,9 +324,6 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
}
loadBuildingRequirements(ret, source["requires"], requirementsToLoad);
if(ret->bid.IsSpecialOrGrail())
loadBuildingRequirements(ret, source["overrides"], overriddenBidsToLoad);
if (!source["upgrades"].isNull())
{
// building id and upgrades can't be the same
@ -843,6 +828,15 @@ void CTownHandler::beforeValidate(JsonNode & object)
inheritBuilding(building.first, building.second);
if (building.second.Struct().count("type"))
inheritBuilding(building.second["type"].String(), building.second);
// MODS COMPATIBILITY FOR pre-1.6
// convert old buildigns with onVisitBonuses into configurable building
if (building.second.Struct().count("onVisitBonuses"))
{
building.second["configuration"]["visitMode"] = JsonNode("bonus");
building.second["configuration"]["visitMode"]["rewards"][0]["message"] = building.second["description"];
building.second["configuration"]["visitMode"]["rewards"][0]["bonuses"] = building.second["onVisitBonuses"];
}
}
}