diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index ca67a06ec..31bd4e2de 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -210,7 +210,6 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog buildBonusSystemTree(); initVisitingAndGarrisonedHeroes(); initFogOfWar(); - initTimedEventsRemovableObjects(); for(auto & elem : teams) { @@ -952,24 +951,6 @@ void CGameState::initMapObjects() map->calculateGuardingGreaturePositions(); //calculate once again when all the guards are placed and initialized } -void CGameState::initTimedEventsRemovableObjects() -{ - for(auto & timedEvent : map->events) - { - for(int3 coordinate : timedEvent.deletedObjectsCoordinates) - { - if(isInTheMap(coordinate)) - { - auto * object = map->getObjectFrom(coordinate); - if(object) - { - timedEvent.deletedObjectsInstances.push_back(object->id); - } - } - } - } -} - void CGameState::placeHeroesInTowns() { for(auto & player : players) diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index caa6df740..d247eb47b 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -196,7 +196,6 @@ private: void initTowns(); void initTownNames(); void initMapObjects(); - void initTimedEventsRemovableObjects(); void initVisitingAndGarrisonedHeroes(); void initCampaign(); diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 52c5dea52..6a8f85913 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -376,7 +376,7 @@ void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const std::string CGTownInstance::getObjectName() const { - return getNameTranslated() + ", " + (ID == Obj::RANDOM_TOWN ? "Random town" :town->faction->getNameTranslated()); + return getNameTranslated() + ", " + (ID == Obj::RANDOM_TOWN ? "Random town" : town->faction->getNameTranslated()); } bool CGTownInstance::townEnvisagesBuilding(BuildingSubID::EBuildingSubID subId) const diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index fd4be6d4d..8a3c8a469 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -104,39 +104,8 @@ void CMapEvent::serializeJson(JsonSerializeFormat & handler) handler.serializeInt("nextOccurrence", nextOccurrence); resources.serializeJson(handler, "resources"); - if(handler.saving) - { - JsonNode deletedObjectsJson; - - for(const auto & entry : deletedObjectsCoordinates) - { - JsonNode values; - JsonNode valueX; - JsonNode valueY; - JsonNode valueZ; - valueX.Float() = static_cast(entry.x); - valueY.Float() = static_cast(entry.y); - valueZ.Float() = static_cast(entry.z); - values.Vector().push_back(valueX); - values.Vector().push_back(valueY); - values.Vector().push_back(valueZ); - deletedObjectsJson.Vector().push_back(values); - } - - handler.serializeRaw("deletedObjectsCoordinates", deletedObjectsJson, std::nullopt); - } - else - { - JsonNode deletedObjectsJson = handler.getCurrent()["deletedObjectsCoordinates"]; - for(auto const & entry : deletedObjectsJson.Vector()) - { - int3 position; - position.x = static_cast(entry[0].Float()); - position.y = static_cast(entry[1].Float()); - position.z = static_cast(entry[2].Float()); - deletedObjectsCoordinates.push_back(position); - } - } + auto deletedObjects = handler.enterArray("deletedObjectsInstances"); + deletedObjects.serializeArray(deletedObjectsInstances); } void CCastleEvent::serializeJson(JsonSerializeFormat & handler) @@ -489,16 +458,6 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type return bestMatch; } -const CGObjectInstance * CMap::getObjectFrom(const int3 & pos) -{ - for(CGObjectInstance * object : objects) - { - if(object->pos == pos) - return object; - } - return nullptr; -} - void CMap::checkForObjectives() { // NOTE: probably should be moved to MapFormatH3M.cpp diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index d8868c1fa..46a4fa1e0 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -132,7 +132,6 @@ public: /// Gets object of specified type on requested position const CGObjectInstance * getObjectiveObjectFrom(const int3 & pos, Obj type); - const CGObjectInstance * getObjectFrom(const int3 & pos); CGHeroInstance * getHero(HeroTypeID heroId); /// Sets the victory/loss condition objectives ?? diff --git a/mapeditor/mapsettings/eventsettings.cpp b/mapeditor/mapsettings/eventsettings.cpp index 83d8d0823..9348f1028 100644 --- a/mapeditor/mapsettings/eventsettings.cpp +++ b/mapeditor/mapsettings/eventsettings.cpp @@ -55,23 +55,23 @@ TResources resourcesFromVariant(const QVariant & v) return TResources(vJson); } -QVariant toVariant(std::vector positions) +QVariant toVariant(std::vector objects) { QVariantList result; - for(int3 position : positions) + for(auto obj : objects) { - result.push_back(QVariant::fromValue(position)); + result.push_back(QVariant::fromValue(obj.num)); } return result; } -std::vector deletedObjectsPositionsFromVariant(const QVariant & v) +std::vector deletedObjectsIdsFromVariant(const QVariant & v) { - std::vector result; - for (auto positionAsVariant : v.toList()) + std::vector result; + for(auto isAsVariant : v.toList()) { - int3 position = positionAsVariant.value(); - result.push_back(position); + auto id = isAsVariant.value(); + result.push_back(ObjectInstanceID(id)); } return result; @@ -88,7 +88,7 @@ QVariant toVariant(const CMapEvent & event) result["firstOccurrence"] = QVariant::fromValue(event.firstOccurrence); result["nextOccurrence"] = QVariant::fromValue(event.nextOccurrence); result["resources"] = toVariant(event.resources); - result["deletedObjectsPositions"] = toVariant(event.deletedObjectsCoordinates); + result["deletedObjectsInstances"] = toVariant(event.deletedObjectsInstances); return QVariant(result); } @@ -104,7 +104,7 @@ CMapEvent eventFromVariant(CMapHeader & mapHeader, const QVariant & variant) result.firstOccurrence = v.value("firstOccurrence").toInt(); result.nextOccurrence = v.value("nextOccurrence").toInt(); result.resources = resourcesFromVariant(v.value("resources")); - result.deletedObjectsCoordinates = deletedObjectsPositionsFromVariant(v.value("deletedObjectsPositions")); + result.deletedObjectsInstances = deletedObjectsIdsFromVariant(v.value("deletedObjectsInstances")); return result; } diff --git a/mapeditor/mapsettings/timedevent.cpp b/mapeditor/mapsettings/timedevent.cpp index 02689a50a..d159801a7 100644 --- a/mapeditor/mapsettings/timedevent.cpp +++ b/mapeditor/mapsettings/timedevent.cpp @@ -53,11 +53,11 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent) nval->setFlags(nval->flags() | Qt::ItemIsEditable); ui->resources->setItem(i, 1, nval); } - auto deletedObjectPositions = params.value("deletedObjectsPositions").toList(); - for(auto const & pos : deletedObjectPositions) + auto deletedObjectInstances = params.value("deletedObjectsInstances").toList(); + for(auto const & obj : deletedObjectInstances) { - int3 position = pos.value(); - auto obj = controller.map()->getObjectFrom(position); + auto id = ObjectInstanceID(obj.toInt()); + auto obj = controller.map()->objects[id]; if(obj) insertObjectToDelete(obj); } @@ -104,10 +104,9 @@ void TimedEvent::on_TimedEvent_finished(int result) auto const & item = ui->deletedObjects->item(i); auto data = item->data(MapEditorRoles::ObjectInstanceIDRole); auto id = ObjectInstanceID(data.value()); - auto position = controller.map()->objects[id]->pos; - deletedObjects.push_back(QVariant::fromValue(position)); + deletedObjects.push_back(QVariant::fromValue(id.num)); } - descriptor["deletedObjectsPositions"] = QVariant::fromValue(deletedObjects); + descriptor["deletedObjectsInstances"] = QVariant::fromValue(deletedObjects); target->setData(Qt::UserRole, descriptor); target->setText(ui->eventNameText->text());