From c08fce4d65313cb862ea404199be323dcd5c3fd2 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Tue, 20 Sep 2022 02:38:10 +0400 Subject: [PATCH] Fix map export --- mapeditor/inspector/inspector.cpp | 2 ++ mapeditor/mapcontroller.cpp | 25 ++++++++++++++++++++++--- mapeditor/validator.cpp | 7 +++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index 59683de63..2084d97e1 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -325,6 +325,8 @@ void Inspector::updateProperties(CGPandoraBox * o) { if(!o) return; + addProperty("Message", o->message, new MessageDelegate, false); + auto * delegate = new RewardsPandoraDelegate(*map, *o); addProperty("Reward", PropertyEditorPlaceholder(), delegate, false); } diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index 4167007ad..2ff9408b6 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -72,6 +72,14 @@ void MapController::repairMap() //fix owners for objects for(auto obj : _map->objects) { + //setup proper names (hero name will be fixed later + if(obj->ID != Obj::HERO && (obj->typeName.empty() || obj->subTypeName.empty())) + { + auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID); + obj->typeName = handler->typeName; + obj->subTypeName = handler->subTypeName; + } + //fix flags if(obj->getOwner() == PlayerColor::UNFLAGGABLE) { if(dynamic_cast(obj.get()) || @@ -86,13 +94,21 @@ void MapController::repairMap() if(auto * nih = dynamic_cast(obj.get())) { auto type = VLC->heroh->objects[nih->subID]; + assert(type->heroClass); + //TODO: find a way to get proper type name + if(obj->ID == Obj::HERO) + nih->typeName = "hero"; + if(obj->ID == Obj::PRISON) + nih->typeName = "prison"; + nih->subTypeName = type->heroClass->identifier; + nih->type = type; if(nih->name.empty()) nih->name = nih->type->name; if(nih->biography.empty()) nih->biography = nih->type->biography; - if(nih->ID == Obj::HERO) + if(nih->ID == Obj::HERO) //not prison nih->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, type->heroClass->getIndex())->getTemplates().front(); //fix spells if(nih->spellbookContainsSpell(SpellID::PRESET)) @@ -123,7 +139,6 @@ void MapController::repairMap() }); } } - } //there might be extra skills, arts and spells not imported from map @@ -144,9 +159,11 @@ void MapController::repairMap() } } -void MapController::setMap(std::unique_ptr cmap) +EMapFormat::EMapFormat MapController::setMap(std::unique_ptr cmap) { _map = std::move(cmap); + auto version = _map->version; + _map->version = EMapFormat::VCMI; repairMap(); @@ -165,6 +182,8 @@ void MapController::setMap(std::unique_ptr cmap) main->enableRedo(allowRedo); } ); + + return version; } void MapController::sceneForceUpdate() diff --git a/mapeditor/validator.cpp b/mapeditor/validator.cpp index 766912723..80bc1a867 100644 --- a/mapeditor/validator.cpp +++ b/mapeditor/validator.cpp @@ -78,6 +78,11 @@ std::list Validator::validate(const CMap * map) issues.emplace_back(QString("Armored instance %1 is UNFLAGGABLE but must have NEUTRAL or player owner").arg(o->instanceName.c_str()), true); } } + if(o->getOwner() != PlayerColor::NEUTRAL && o->getOwner().getNum() < map->players.size()) + { + if(!map->players[o->getOwner().getNum()].canAnyonePlay()) + issues.emplace_back(QString("Object %1 is assinged to non-playable player %2").arg(o->instanceName.c_str(), o->getOwner().getStr().c_str()), true); + } //checking towns if(auto * ins = dynamic_cast(o.get())) { @@ -100,8 +105,6 @@ std::list Validator::validate(const CMap * map) bool has = amountOfCastles.count(ins->getOwner().getNum()); if(!has) issues.emplace_back(QString("Hero %1 must have an owner").arg(ins->instanceName.c_str()), true); - else - issues.emplace_back(QString("Hero %1: heroes on map are not supported in current version").arg(ins->instanceName.c_str()), false); } if(ins->type) {