mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Mapping of deletable coordinates to objects on map start
This commit is contained in:
@@ -210,6 +210,7 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
|
||||
buildBonusSystemTree();
|
||||
initVisitingAndGarrisonedHeroes();
|
||||
initFogOfWar();
|
||||
initTimedEventsRemovableObjects();
|
||||
|
||||
for(auto & elem : teams)
|
||||
{
|
||||
@@ -951,6 +952,28 @@ 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))
|
||||
{
|
||||
for(const CGObjectInstance * object : getBlockingObjs(coordinate))
|
||||
{
|
||||
timedEvent.deletedObjectsInstances.insert(object);
|
||||
}
|
||||
|
||||
for(const CGObjectInstance * object : getVisitableObjs(coordinate))
|
||||
{
|
||||
timedEvent.deletedObjectsInstances.insert(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGameState::placeHeroesInTowns()
|
||||
{
|
||||
for(auto & player : players)
|
||||
|
||||
@@ -196,6 +196,7 @@ private:
|
||||
void initTowns();
|
||||
void initTownNames();
|
||||
void initMapObjects();
|
||||
void initTimedEventsRemovableObjects();
|
||||
void initVisitingAndGarrisonedHeroes();
|
||||
void initCampaign();
|
||||
|
||||
|
||||
@@ -44,8 +44,10 @@ public:
|
||||
ui32 nextOccurrence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
|
||||
|
||||
std::vector<int3> deletedObjectsCoordinates;
|
||||
std::set<const CGObjectInstance*> deletedObjectsInstances;
|
||||
|
||||
std::vector<int3> unused;
|
||||
std::set<const CGObjectInstance*> unused2;
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler & h)
|
||||
@@ -70,9 +72,15 @@ public:
|
||||
h & firstOccurrence;
|
||||
h & nextOccurrence;
|
||||
if(h.version >= Handler::Version::EVENT_OBJECTS_DELETION)
|
||||
{
|
||||
h & deletedObjectsCoordinates;
|
||||
h & deletedObjectsInstances;
|
||||
}
|
||||
else
|
||||
{
|
||||
h & unused;
|
||||
h & unused2;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void serializeJson(JsonSerializeFormat & handler);
|
||||
|
||||
@@ -62,16 +62,9 @@ void NewTurnProcessor::handleTimeEvents(PlayerColor color)
|
||||
}
|
||||
|
||||
//remove objects specified by event
|
||||
for(int3 coordinate : event.deletedObjectsCoordinates)
|
||||
for(const CGObjectInstance * objectToRemove : event.deletedObjectsInstances)
|
||||
{
|
||||
if(gameHandler->isInTheMap(coordinate))
|
||||
{
|
||||
auto objects = gameHandler->getBlockingObjs(coordinate);
|
||||
for(const CGObjectInstance * object : objects)
|
||||
{
|
||||
gameHandler->removeObject(object, PlayerColor::NEUTRAL);
|
||||
}
|
||||
}
|
||||
gameHandler->removeObject(objectToRemove, PlayerColor::NEUTRAL);
|
||||
}
|
||||
gameHandler->sendAndApply(&iw); //show dialog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user