Parcourir la source

VCAI: add any newly found teleports to knownTeleportChannels

Now all new objects added to visitableObjs only using addVisitableObj so we can catch them for teleports handling.
I also simplified one of retreiveVisitableObjs functions because it's only used for inserting things into visitableObjs.
ArseniyShestakov il y a 10 ans
Parent
commit
665712c196
2 fichiers modifiés avec 14 ajouts et 7 suppressions
  1. 11 5
      AI/VCAI/VCAI.cpp
  2. 3 2
      AI/VCAI/VCAI.h

+ 11 - 5
AI/VCAI/VCAI.cpp

@@ -505,7 +505,7 @@ void VCAI::objectPropertyChanged(const SetObjectProperty * sop)
 			auto obj = myCb->getObj(sop->id, false);
 			if (obj)
 			{
-				visitableObjs.insert(obj);
+				addVisitableObj(obj);
 				erase_if_present(alreadyVisited, obj);
 			}
 		}
@@ -543,7 +543,7 @@ void VCAI::init(shared_ptr<CCallback> CB)
 	if(!fh)
 		fh = new FuzzyHelper();
 
-	retreiveVisitableObjs(visitableObjs);
+	retreiveVisitableObjs();
 }
 
 void VCAI::yourTurn()
@@ -667,7 +667,7 @@ void VCAI::makeTurn()
 			{
 				if (isWeeklyRevisitable(obj))
 				{
-					visitableObjs.insert(obj); //set doesn't need duplicate check
+					addVisitableObj(obj);
 					erase_if_present (alreadyVisited, obj);
 				}
 			}
@@ -1552,14 +1552,15 @@ void VCAI::retreiveVisitableObjs(std::vector<const CGObjectInstance *> &out, boo
 		}
 	});
 }
-void VCAI::retreiveVisitableObjs(std::set<const CGObjectInstance *> &out, bool includeOwned /*= false*/) const
+
+void VCAI::retreiveVisitableObjs()
 {
 	foreach_tile_pos([&](const int3 &pos)
 	{
 		for(const CGObjectInstance *obj : myCb->getVisitableObjs(pos, false))
 		{
 			if(includeOwned || obj->tempOwner != playerID)
-				out.insert(obj);
+				addVisitableObj(obj);
 		}
 	});
 }
@@ -1579,6 +1580,11 @@ void VCAI::addVisitableObj(const CGObjectInstance *obj)
 {
 	visitableObjs.insert(obj);
 	helperObjInfo[obj] = ObjInfo(obj);
+
+	// All teleport objects seen automatically assigned to appropriate channels
+	auto teleportObj = dynamic_cast<const CGTeleport *>(obj);
+	if(teleportObj)
+		CGTeleport::addToChannel(knownTeleportChannels, teleportObj);
 }
 
 const CGObjectInstance * VCAI::lookForArt(int aid) const

+ 3 - 2
AI/VCAI/VCAI.h

@@ -141,6 +141,7 @@ public:
 
 	friend class FuzzyHelper;
 
+	std::map<TeleportChannelID, shared_ptr<TeleportChannel> > knownTeleportChannels;
 	std::map<const CGObjectInstance *, const CGObjectInstance *> knownSubterraneanGates;
 	//std::vector<const CGObjectInstance *> visitedThisWeek; //only OPWs
 	std::map<HeroPtr, std::set<const CGTownInstance *> > townVisitsThisWeek;
@@ -293,7 +294,7 @@ public:
 	void validateObject(ObjectIdRef obj); //checks if object is still visible and if not, removes references to it
 	void validateVisitableObjs();
 	void retreiveVisitableObjs(std::vector<const CGObjectInstance *> &out, bool includeOwned = false) const;
-	void retreiveVisitableObjs(std::set<const CGObjectInstance *> &out, bool includeOwned = false) const;
+	void retreiveVisitableObjs();
 	std::vector<const CGObjectInstance *> getFlaggedObjects() const;
 
 	const CGObjectInstance *lookForArt(int aid) const;
@@ -346,7 +347,7 @@ public:
 
 	template <typename Handler> void serializeInternal(Handler &h, const int version)
 	{
-		h & knownSubterraneanGates & townVisitsThisWeek & lockedHeroes & reservedHeroesMap; //FIXME: cannot instantiate abstract class
+		h & knownTeleportChannels & knownSubterraneanGates & townVisitsThisWeek & lockedHeroes & reservedHeroesMap; //FIXME: cannot instantiate abstract class
 		h & visitableObjs & alreadyVisited & reservedObjs;
 		h & saving & status & battlename;
 		h & heroesUnableToExplore;