2
0
Эх сурвалжийг харах

CGameInfoCallback: refactoring of getTeleportChannelEntraces / getTeleportChannelExits

Move shared filtering code into getVisibleTeleportObjects.
Also remove excludeId as it's not currently used.
ArseniyShestakov 10 жил өмнө
parent
commit
861104f493

+ 12 - 20
lib/CGameInfoCallback.cpp

@@ -688,32 +688,24 @@ const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid
 	return gs->map->objects[oid.num];
 	return gs->map->objects[oid.num];
 }
 }
 
 
-std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor Player) const
+std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const
 {
 {
-	std::vector<ObjectInstanceID> ret;
-	auto channel = gs->map->teleportChannels[id];
-	for(auto entrance : channel->entrances)
+	vstd::erase_if(ids, [&](ObjectInstanceID id) -> bool
 	{
 	{
-		auto obj = getObj(entrance);
-		if(obj && (Player == PlayerColor::UNFLAGGABLE || isVisible(obj->pos, Player)))
-			ret.push_back(entrance);
-	}
-
-	return ret;
+		auto obj = getObj(id);
+		return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisible(obj->pos, player));
+	});
+	return ids;
 }
 }
 
 
-std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor Player) const
+std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor player) const
 {
 {
-	std::vector<ObjectInstanceID> ret;
-	auto channel = gs->map->teleportChannels[id];
-	for(auto exit : channel->exits)
-	{
-		auto obj = getObj(exit);
-		if(obj && (Player == PlayerColor::UNFLAGGABLE || isVisible(obj->pos, Player)))
-			ret.push_back(exit);
-	}
+	return getVisibleTeleportObjects(gs->map->teleportChannels[id]->entrances, player);
+}
 
 
-	return ret;
+std::vector<ObjectInstanceID> CGameInfoCallback::getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor player) const
+{
+	return getVisibleTeleportObjects(gs->map->teleportChannels[id]->exits, player);
 }
 }
 
 
 ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID id, PlayerColor player) const
 ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID id, PlayerColor player) const

+ 1 - 0
lib/CGameInfoCallback.h

@@ -109,6 +109,7 @@ public:
 	EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
 	EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
 
 
 	//teleport
 	//teleport
+	std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player)  const;
 	std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
 	std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
 	std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
 	std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
 	ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
 	ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;