1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Fix problem with saving

This commit is contained in:
nordsoft
2022-09-07 01:44:22 +04:00
parent 59f38fc43a
commit 0849f93d88
2 changed files with 32 additions and 7 deletions

View File

@ -67,6 +67,17 @@ MinimapScene * MapController::miniScene(int level)
void MapController::setMap(std::unique_ptr<CMap> cmap) void MapController::setMap(std::unique_ptr<CMap> cmap)
{ {
_map = std::move(cmap); _map = std::move(cmap);
//fix map
for(auto obj : _map->objects)
if(obj->getOwner() == PlayerColor::UNFLAGGABLE)
if(dynamic_cast<CGMine*>(obj.get()) ||
dynamic_cast<CGDwelling*>(obj.get()) ||
dynamic_cast<CGTownInstance*>(obj.get()) ||
dynamic_cast<CGGarrison*>(obj.get()) ||
dynamic_cast<CGHeroInstance*>(obj.get()))
obj->tempOwner = PlayerColor::NEUTRAL;
_scenes[0].reset(new MapScene(0)); _scenes[0].reset(new MapScene(0));
_scenes[1].reset(new MapScene(1)); _scenes[1].reset(new MapScene(1));
_miniscenes[0].reset(new MinimapScene(0)); _miniscenes[0].reset(new MinimapScene(0));

View File

@ -61,10 +61,16 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
for(auto o : map->objects) for(auto o : map->objects)
{ {
if(auto * ins = dynamic_cast<CArmedInstance*>(o.get())) if(o->getOwner() == PlayerColor::UNFLAGGABLE)
{ {
if(ins->getOwner() == PlayerColor::UNFLAGGABLE) if(dynamic_cast<CGMine*>(o.get()) ||
issues.emplace_back(QString("Armored instance %1 is UNFLAGGABLE but must have NEUTRAL or player owner").arg(ins->instanceName.c_str()), true); dynamic_cast<CGDwelling*>(o.get()) ||
dynamic_cast<CGTownInstance*>(o.get()) ||
dynamic_cast<CGGarrison*>(o.get()) ||
dynamic_cast<CGHeroInstance*>(o.get()))
{
issues.emplace_back(QString("Armored instance %1 is UNFLAGGABLE but must have NEUTRAL or player owner").arg(o->instanceName.c_str()), true);
}
} }
if(auto * ins = dynamic_cast<CGTownInstance*>(o.get())) if(auto * ins = dynamic_cast<CGTownInstance*>(o.get()))
{ {
@ -75,6 +81,13 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
++amountOfCastles[ins->getOwner().getNum()]; ++amountOfCastles[ins->getOwner().getNum()];
} }
if(auto * ins = dynamic_cast<CGHeroInstance*>(o.get())) if(auto * ins = dynamic_cast<CGHeroInstance*>(o.get()))
{
if(ins->ID == Obj::PRISON)
{
if(ins->getOwner() != PlayerColor::NEUTRAL)
issues.emplace_back(QString("Prison %1 must be a NEUTRAL").arg(ins->instanceName.c_str()), true);
}
else
{ {
bool has = amountOfCastles.count(ins->getOwner().getNum()); bool has = amountOfCastles.count(ins->getOwner().getNum());
if(!has) if(!has)
@ -83,6 +96,7 @@ std::list<Validator::Issue> Validator::validate(const CMap * map)
issues.emplace_back(QString("Hero %1: heroes on map are not supported in current version").arg(ins->instanceName.c_str()), false); issues.emplace_back(QString("Hero %1: heroes on map are not supported in current version").arg(ins->instanceName.c_str()), false);
} }
} }
}
for(auto & mp : amountOfCastles) for(auto & mp : amountOfCastles)
if(mp.second == 0) if(mp.second == 0)