From a2c63e7ed2683f614b2ca2e425b79e16ccb89a79 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Wed, 7 Sep 2022 02:56:40 +0400 Subject: [PATCH] Some ideas to fix imported maps --- mapeditor/mapcontroller.cpp | 34 +++++++++++++++++++++++++++++----- mapeditor/mapcontroller.h | 2 ++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index 4d785f0c9..d9ddc5c05 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -7,6 +7,8 @@ #include "../lib/Terrain.h" #include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/rmg/ObstaclePlacer.h" +#include "../lib/CSkillHandler.h" +#include "../lib/spells/CSpellHandler.h" #include "mapview.h" #include "scenelayer.h" #include "maphandler.h" @@ -64,11 +66,9 @@ MinimapScene * MapController::miniScene(int level) return _miniscenes[level].get(); } -void MapController::setMap(std::unique_ptr cmap) +void MapController::repairMap() { - _map = std::move(cmap); - - //fix map + //fix owners for objects for(auto obj : _map->objects) if(obj->getOwner() == PlayerColor::UNFLAGGABLE) if(dynamic_cast(obj.get()) || @@ -77,7 +77,31 @@ void MapController::setMap(std::unique_ptr cmap) dynamic_cast(obj.get()) || dynamic_cast(obj.get()) || dynamic_cast(obj.get())) - obj->tempOwner = PlayerColor::NEUTRAL; + obj->tempOwner = PlayerColor::NEUTRAL; + + //there might be extra skills, arts and spells not imported from map + if(VLC->skillh->getDefaultAllowed().size() > map()->allowedAbilities.size()) + { + for(int i = map()->allowedAbilities.size(); i < VLC->skillh->getDefaultAllowed().size(); ++i) + map()->allowedAbilities.push_back(false); + } + if(VLC->arth->getDefaultAllowed().size() > map()->allowedArtifact.size()) + { + for(int i = map()->allowedArtifact.size(); i < VLC->arth->getDefaultAllowed().size(); ++i) + map()->allowedArtifact.push_back(false); + } + if(VLC->spellh->getDefaultAllowed().size() > map()->allowedSpell.size()) + { + for(int i = map()->allowedSpell.size(); i < VLC->spellh->getDefaultAllowed().size(); ++i) + map()->allowedSpell.push_back(false); + } +} + +void MapController::setMap(std::unique_ptr cmap) +{ + _map = std::move(cmap); + + repairMap(); _scenes[0].reset(new MapScene(0)); _scenes[1].reset(new MapScene(1)); diff --git a/mapeditor/mapcontroller.h b/mapeditor/mapcontroller.h index 4df0e93d6..e9470677d 100644 --- a/mapeditor/mapcontroller.h +++ b/mapeditor/mapcontroller.h @@ -17,6 +17,8 @@ public: void setMap(std::unique_ptr); + void repairMap(); + const std::unique_ptr & getMapUniquePtr() const; //to be used for map saving CMap * map(); MapHandler * mapHandler();