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

Restore save compatibility

This commit is contained in:
Ivan Savenko 2024-08-26 20:52:37 +00:00
parent ac271c09b9
commit f765f212bb
7 changed files with 57 additions and 7 deletions

View File

@ -35,6 +35,19 @@ public:
h & static_cast<CGObjectInstance&>(*this);
h & static_cast<IMarket&>(*this);
h & marketEfficiency;
if (h.version < Handler::Version::NEW_MARKETS)
{
std::string speech;
std::string title;
h & speech;
h & title;
}
}
template <typename Handler> void serializeArtifactsAltar(Handler &h)
{
serialize(h);
IMarket::serializeArtifactsAltar(h);
}
};
@ -71,8 +84,11 @@ public:
{
h & static_cast<CGMarket&>(*this);
h & skills;
h & speech;
h & title;
if (h.version >= Handler::Version::NEW_MARKETS)
{
h & speech;
h & title;
}
}
};

View File

@ -946,6 +946,14 @@ void CGTownInstance::addBuilding(const BuildingID & buildingID)
}
}
void CGTownInstance::postDeserializeMarketFix()
{
// re-add all buildings to recreate existing market modes
auto buildingsBak = builtBuildings;
for (auto building : buildingsBak)
addBuilding(building);
}
void CGTownInstance::removeBuilding(const BuildingID & buildingID)
{
if(!vstd::contains(builtBuildings, buildingID))

View File

@ -77,7 +77,9 @@ public:
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGDwelling&>(*this);
h & static_cast<IMarket&>(*this);
if (h.version >= Handler::Version::NEW_MARKETS)
h & static_cast<IMarket&>(*this);
h & nameTextId;
h & built;
h & destroyed;
@ -116,6 +118,9 @@ public:
town = faction ? faction->town : nullptr;
}
if (!h.saving && h.version < Handler::Version::NEW_MARKETS)
postDeserializeMarketFix();
h & townAndVis;
BONUS_TREE_DESERIALIZATION_FIX
@ -135,6 +140,7 @@ public:
void updateMoraleBonusFromArmy() override;
void deserializationFix();
void postDeserialize();
void postDeserializeMarketFix();
void recreateBuildingsBonuses();
void setVisitingHero(CGHeroInstance *h);
void setGarrisonedHero(CGHeroInstance *h);

View File

@ -42,8 +42,18 @@ public:
{
h & marketModes;
if(h.loadingGamestate && vstd::contains(marketModes, EMarketMode::ARTIFACT_EXP))
altarArtifactsStorage = std::make_shared<CArtifactSetAltar>();
if(vstd::contains(marketModes, EMarketMode::ARTIFACT_EXP))
{
if (!h.saving)
altarArtifactsStorage = std::make_shared<CArtifactSetAltar>();
h & *altarArtifactsStorage;
}
}
template <typename Handler> void serializeArtifactsAltar(Handler & h)
{
h & *altarArtifactsStorage;
}
private:

View File

@ -65,6 +65,7 @@ enum class ESerializationVersion : int32_t
EVENTS_PLAYER_SET, // 854 - map & town events use std::set instead of bitmask to store player list
NEW_TOWN_BUILDINGS, // 855 - old bonusing buildings have been removed
STATISTICS_SCREEN, // 856 - extent statistic functions
NEW_MARKETS, // 857 - reworked market classes
CURRENT = STATISTICS_SCREEN
CURRENT = NEW_MARKETS
};

View File

@ -139,7 +139,6 @@ void registerTypes(Serializer &s)
s.template registerType<CArtifactInstance>(78);
s.template registerType<CObstacleInstance>(79);
s.template registerType<SpellCreatedObstacle>(80);
//s.template registerType<CGArtifactsAltar>(81);
s.template registerType<CPack>(82);
s.template registerType<PackageApplied>(84);
s.template registerType<SystemMessage>(85);

View File

@ -63,6 +63,15 @@ class SerializerCompatibilityBonusingBuilding final : public SerializerCompatibi
}
};
class SerializerCompatibilityArtifactsAltar final : public SerializerCompatibility<CGMarket, ESerializationVersion::NEW_MARKETS>
{
void loadPtr(BinaryDeserializer &ar, IGameCallback * cb, Serializeable * data) const override
{
auto * realPtr = dynamic_cast<CGMarket *>(data);
realPtr->serializeArtifactsAltar(ar);
}
};
template<typename Type>
void CSerializationApplier::registerType(uint16_t ID)
{
@ -76,6 +85,7 @@ CSerializationApplier::CSerializationApplier()
apps[54].reset(new SerializerCompatibilityBonusingBuilding);
apps[55].reset(new SerializerCompatibilityBonusingBuilding);
apps[81].reset(new SerializerCompatibilityArtifactsAltar);
}
CSerializationApplier & CSerializationApplier::getInstance()