Преглед на файлове

Mapping of deletable coordinates to objects on map start

Dydzio преди 1 година
родител
ревизия
9004b88c7e
променени са 4 файла, в които са добавени 34 реда и са изтрити 9 реда
  1. 23 0
      lib/gameState/CGameState.cpp
  2. 1 0
      lib/gameState/CGameState.h
  3. 8 0
      lib/mapping/CMapDefines.h
  4. 2 9
      server/processors/NewTurnProcessor.cpp

+ 23 - 0
lib/gameState/CGameState.cpp

@@ -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)

+ 1 - 0
lib/gameState/CGameState.h

@@ -196,6 +196,7 @@ private:
 	void initTowns();
 	void initTownNames();
 	void initMapObjects();
+	void initTimedEventsRemovableObjects();
 	void initVisitingAndGarrisonedHeroes();
 	void initCampaign();
 

+ 8 - 0
lib/mapping/CMapDefines.h

@@ -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);

+ 2 - 9
server/processors/NewTurnProcessor.cpp

@@ -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
 	}