mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-17 20:58:07 +02:00
store ObjectInstanceID of objects to remove instead of their position
This commit is contained in:
parent
e50ba14bbe
commit
d078c5ff2d
@ -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)
|
||||
|
@ -196,7 +196,6 @@ private:
|
||||
void initTowns();
|
||||
void initTownNames();
|
||||
void initMapObjects();
|
||||
void initTimedEventsRemovableObjects();
|
||||
void initVisitingAndGarrisonedHeroes();
|
||||
void initCampaign();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<int>(entry.x);
|
||||
valueY.Float() = static_cast<int>(entry.y);
|
||||
valueZ.Float() = static_cast<int>(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<int>(entry[0].Float());
|
||||
position.y = static_cast<int>(entry[1].Float());
|
||||
position.z = static_cast<int>(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
|
||||
|
@ -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 ??
|
||||
|
@ -55,23 +55,23 @@ TResources resourcesFromVariant(const QVariant & v)
|
||||
return TResources(vJson);
|
||||
}
|
||||
|
||||
QVariant toVariant(std::vector<int3> positions)
|
||||
QVariant toVariant(std::vector<ObjectInstanceID> objects)
|
||||
{
|
||||
QVariantList result;
|
||||
for(int3 position : positions)
|
||||
for(auto obj : objects)
|
||||
{
|
||||
result.push_back(QVariant::fromValue<int3>(position));
|
||||
result.push_back(QVariant::fromValue(obj.num));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<int3> deletedObjectsPositionsFromVariant(const QVariant & v)
|
||||
std::vector<ObjectInstanceID> deletedObjectsIdsFromVariant(const QVariant & v)
|
||||
{
|
||||
std::vector<int3> result;
|
||||
for (auto positionAsVariant : v.toList())
|
||||
std::vector<ObjectInstanceID> result;
|
||||
for(auto isAsVariant : v.toList())
|
||||
{
|
||||
int3 position = positionAsVariant.value<int3>();
|
||||
result.push_back(position);
|
||||
auto id = isAsVariant.value<int>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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<int3>();
|
||||
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<int>());
|
||||
auto position = controller.map()->objects[id]->pos;
|
||||
deletedObjects.push_back(QVariant::fromValue<int3>(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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user