mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Changes related to #1444 — fixing affected savegames, assert to detect when things go wrong.
This commit is contained in:
@@ -1369,6 +1369,10 @@ void CGameState::init(StartInfo * si)
|
||||
}
|
||||
}
|
||||
|
||||
//Early check for #1444-like problems
|
||||
for(auto building : vti->builtBuildings)
|
||||
assert(vti->town->buildings[building]);
|
||||
|
||||
//town events
|
||||
for(CCastleEvent &ev : vti->events)
|
||||
{
|
||||
|
@@ -2685,7 +2685,6 @@ void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResu
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CGVisitableOPH::wasVisited (const CGHeroInstance * h) const
|
||||
{
|
||||
return vstd::contains(visitors, h->id);
|
||||
|
@@ -617,6 +617,17 @@ public:
|
||||
|
||||
h & town & townAndVis;
|
||||
BONUS_TREE_DESERIALIZATION_FIX
|
||||
|
||||
vstd::erase_if(builtBuildings, [this](BuildingID building) -> bool
|
||||
{
|
||||
if(!town->buildings.count(building) || !town->buildings.at(building))
|
||||
{
|
||||
logGlobal->errorStream() << boost::format("#1444-like issue in CGTownInstance::serialize. From town %s at %s removing the bogus builtBuildings item %s")
|
||||
% name % pos % building;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -205,7 +205,7 @@ public:
|
||||
//Fix #1444 corrupted save
|
||||
while(auto badElem = vstd::tryFindIf(buildings, findNull))
|
||||
{
|
||||
std::cout << "#1444-like bug encountered, fixing buildings list by removing bogus entry " << badElem->first << " from " << faction->name << std::endl;
|
||||
logGlobal->errorStream() << "#1444-like bug encountered in CTown::serialize, fixing buildings list by removing bogus entry " << badElem->first << " from " << faction->name;
|
||||
buildings.erase(badElem->first);
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "CCreatureHandler.h"
|
||||
#include "CGameState.h"
|
||||
#include "BattleState.h"
|
||||
#include "CTownHandler.h"
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
@@ -448,6 +449,7 @@ DLL_LINKAGE void NewStructures::applyGs( CGameState *gs )
|
||||
CGTownInstance *t = gs->getTown(tid);
|
||||
for(const auto & id : bid)
|
||||
{
|
||||
assert(t->town->buildings[id]);
|
||||
t->builtBuildings.insert(id);
|
||||
}
|
||||
t->builded = builded;
|
||||
|
Reference in New Issue
Block a user