Here are the examples of the csharp api System.Collections.Generic.List.Contains(Waypoint) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : NavigationGraphManager.cs
with MIT License
from immersal
with MIT License
from immersal
public void AddWaypoint(Waypoint wp)
{
if (!m_Waypoints.Contains(wp))
{
m_Waypoints.Add(wp);
}
}
19
Source : NavigationGraphManager.cs
with MIT License
from immersal
with MIT License
from immersal
public void RemoveWaypoint(Waypoint wp)
{
if (m_Waypoints.Contains(wp))
{
m_Waypoints.Remove(wp);
}
}
19
Source : PathManager.cs
with GNU General Public License v3.0
from merschformann
with GNU General Public License v3.0
from merschformann
public void Update()
{
//no need for managing
if (_managedBots.Count == 0)
return;
//get locked way points
LockedWaypoints.Clear();
_botsInQueue.Clear();
//is elevator and elevator is in use => lock the destination waypoint
if (QueueWaypoint.Elevator != null && QueueWaypoint.Elevator.InUse)
LockedWaypoints.Add(QueueWaypoint, null);
//check bot states
for (int i = 0; i < _managedBots.Count; i++)
{
BotNormal bot = _managedBots[i];
var nextWaypoint = bot.NextWaypoint != null ? bot.NextWaypoint : bot.CurrentWaypoint;
var currentWaypointInQueue = Queue.Contains(bot.CurrentWaypoint);
var nextWaypointInQueue = Queue.Contains(nextWaypoint);
var locksCurrentWaypoint = currentWaypointInQueue && bot.CurrentWaypoint.GetDistance(bot) <= _maxEdgeLength[bot.CurrentWaypoint];
// Check whether bot is leaving the queue (only possible at the queue waypoint!)
if (// Check whether the bot has a new destination and its current waypoint is the end of the queue
(bot.DestinationWaypoint != QueueWaypoint && bot.CurrentWaypoint == QueueWaypoint && !locksCurrentWaypoint) ||
// Check whether the bot is already outside the queue area and has a different destination than the queue waypoint
(!currentWaypointInQueue && !nextWaypointInQueue && bot.DestinationWaypoint != QueueWaypoint))
{
//bot leaves elevator?
if (QueueWaypoint.Elevator != null && bot == QueueWaypoint.Elevator.usedBy)
{
QueueWaypoint.Elevator.InUse = false;
QueueWaypoint.Elevator.usedBy = null;
}
// Not in queue anymore - remove it
_managedBots.RemoveAt(i);
// Update index (we removed one)
i--;
// Mark queueing inactive (this is redundant - see below)
bot.IsQueueing = false;
// Proceed to next bot
continue;
}
//bot in Queue
if (currentWaypointInQueue)
{
_botsInQueue.Add(bot);
// Indicate queueing
bot.IsQueueing = true;
if (bot.CurrentWaypoint != QueueWaypoint)
bot.RequestReoptimization = false; //this bot will be managed by this manager
//add locks
if (locksCurrentWaypoint && !LockedWaypoints.ContainsKey(bot.CurrentWaypoint))
LockedWaypoints.Add(bot.CurrentWaypoint, bot);
if (nextWaypointInQueue && !LockedWaypoints.ContainsKey(nextWaypoint))
LockedWaypoints.Add(nextWaypoint, bot);
}
//bot reached end of the queue - no active queueing anymore
if (_queueWaypointIndices.ContainsKey(bot.CurrentWaypoint) && _queueWaypointIndices[bot.CurrentWaypoint] == 0)
{
// Mark queueing inactive
bot.IsQueueing = false;
_botsInQueue.Remove(bot);
}
}
//if this is an elevator queue, the first way point is locked, when the elevator is in use
if (QueueWaypoint.Elevator != null && QueueWaypoint.Elevator.InUse && !LockedWaypoints.ContainsKey(QueueWaypoint))
LockedWaypoints[QueueWaypoint] = null;
// Remove bots that finished their cruise
foreach (var bot in _queueCruisePaths.Where(kvp => kvp.Key.CurrentWaypoint == kvp.Value.Last()).Select(kvp => kvp.Key).ToArray())
_queueCruisePaths.Remove(bot);
// Reset places
_placeInQueue.Clear();
// Manage locks for cruising bots
HashSet<BotNormal> failedCruiseBots = null;
foreach (var bot in _queueCruisePaths.Keys)
{
// replacedert that the bot is in the queue
Debug.replacedert(_queueAreaXMin <= bot.X && bot.X <= _queueAreaXMax && _queueAreaYMin <= bot.Y && bot.Y <= _queueAreaYMax);
// Fetch the waypoint the bot is currently at
var realWP = GetNearestQueueWaypoint(bot.X, bot.Y);
int currentQueueIndex = _queueWaypointIndices[realWP];
// Lock waypoints that are left for the cruise
foreach (var cruiseWP in _queueCruisePaths[bot].Where(wp => _queueWaypointIndices[wp] <= currentQueueIndex))
{
// If bot is not moving and next waypoint is already blocked by another bot, something went wrong - discard the cruise and lineup regularly
if (LockedWaypoints.ContainsKey(cruiseWP) && LockedWaypoints[cruiseWP] != bot)
{
// Cruise failed - mark for removal
if (failedCruiseBots == null)
failedCruiseBots = new HashSet<BotNormal>() { bot };
else
failedCruiseBots.Add(bot);
}
else
{
// Lock waypoint for cruise
LockedWaypoints[cruiseWP] = bot;
}
}
}
// Cancel failed cruises
if (failedCruiseBots != null)
foreach (var failedBot in failedCruiseBots)
_queueCruisePaths.Remove(failedBot);
// replacedign already moving bots
foreach (var bot in _botsInQueue.Where(bot => bot.CurrentWaypoint != bot.NextWaypoint && bot.NextWaypoint != null))
_placeInQueue.Add(bot, bot.NextWaypoint);
//replacedign standing bots
foreach (var bot in _botsInQueue.Where(bot => !_placeInQueue.ContainsKey(bot)))
{
var queueIndex = _queueWaypointIndices[bot.CurrentWaypoint];
var newQueueIndex = -1;
if (queueIndex == 0 || LockedWaypoints.ContainsKey(Queue[queueIndex - 1]))
{
//locked => stay where you are
_placeInQueue.Add(bot, bot.CurrentWaypoint);
newQueueIndex = queueIndex;
}
else
{
//if almost there, just move one up
Path path = new Path();
if (queueIndex == 1)
{
LockedWaypoints.Add(Queue[queueIndex - 1], bot);
path.AddFirst(_pathManager.GetNodeIdByWaypoint(Queue[queueIndex - 1]), true, 0.0);
newQueueIndex = queueIndex - 1;
}
else
{
//go as far as you can
IEnumerable<Waypoint> lockedPredecessorWaypoints = LockedWaypoints.Keys.Where(q => _queueWaypointIndices[q] < queueIndex);
int targetQueueIndex = lockedPredecessorWaypoints.Any() ? lockedPredecessorWaypoints.Max(w => _queueWaypointIndices[w]) + 1 : QueueWaypoint.Elevator != null ? 1 : 0;
List<Waypoint> cruisePath = new List<Waypoint>();
int nextIndex = -1;
// Build cruise path through queue
for (int currentIndex = queueIndex; currentIndex >= targetQueueIndex;)
{
// Determine next waypoint in queue to go to after this one (consider shortcuts)
IEnumerable<Waypoint> shortCuts = Queue[currentIndex].Paths.Where(p => _queueWaypointIndices.ContainsKey(p) && _queueWaypointIndices[p] < currentIndex && targetQueueIndex <= _queueWaypointIndices[p]);
nextIndex = currentIndex > targetQueueIndex && shortCuts.Any() ? shortCuts.Min(p => _queueWaypointIndices[p]) : currentIndex - 1;
// Check whether a stop is required at the
double inboundOrientation = cruisePath.Count >= 1 && currentIndex > targetQueueIndex ? Circle.GetOrientation(cruisePath[cruisePath.Count - 1].X, cruisePath[cruisePath.Count - 1].Y, Queue[currentIndex].X, Queue[currentIndex].Y) : double.NaN;
double outboundOrientation = cruisePath.Count >= 1 && currentIndex > targetQueueIndex ? Circle.GetOrientation(Queue[currentIndex].X, Queue[currentIndex].Y, Queue[nextIndex].X, Queue[nextIndex].Y) : double.NaN;
bool stopRequired = !double.IsNaN(inboundOrientation) && Math.Abs(Circle.GetOrientationDifference(inboundOrientation, outboundOrientation)) >= bot.Instance.StraightOrientationTolerance;
// Add connection to the overall path
LockedWaypoints[Queue[currentIndex]] = bot;
bool stopAtNode = currentIndex == queueIndex || currentIndex == targetQueueIndex || stopRequired;
path.AddLast(
// The next waypoint to go to
_pathManager.GetNodeIdByWaypoint(Queue[currentIndex]),
// See whether we need to stop at the waypoint (either because it is the last one or the angles do not match - using 10 degrees in radians here, which should be in line with the Graph clreplaced of path planning)
stopAtNode,
// Don't wait at all
0.0);
// Add the step to the cruise path
cruisePath.Add(Queue[currentIndex]);
// Update to next index
currentIndex = nextIndex;
}
// Prepare for next node in queue
path.NextNodeToPrepareFor = queueIndex != nextIndex && nextIndex >= 0 ? _pathManager.GetNodeIdByWaypoint(Queue[nextIndex]) : -1;
// The new index in queue is the targeted one
newQueueIndex = targetQueueIndex;
// Save path for overwatch
_queueCruisePaths[bot] = cruisePath;
// Check path
for (int i = 0; i < cruisePath.Count - 1; i++)
{
if (!cruisePath[i].ContainsPath(cruisePath[i + 1]))
throw new InvalidOperationException();
}
}
// Set path
bot.Path = path;
_placeInQueue.Add(bot, Queue[newQueueIndex]);
//if the next place is an elevator set it
if (_placeInQueue[bot].Elevator != null)
{
QueueWaypoint.Elevator.InUse = true;
QueueWaypoint.Elevator.usedBy = bot;
}
}
}
//replacedign bots that are not in the queue
//search for the first free node in the queue
int firstFreeNode = Queue.Count - 1;
while (firstFreeNode > 0 && !LockedWaypoints.ContainsKey(Queue[firstFreeNode - 1]))
firstFreeNode--;
//if this is a queue for an elevator, then do not replacedign the elevator directly, because others might wait in a queue on a different tier
if (firstFreeNode == 0 && QueueWaypoint.Elevator != null)
firstFreeNode = 1;
//botsLeftToQueue
var botsLeftToQueue = _managedBots.Where(bot => !_placeInQueue.ContainsKey(bot)).ToList();
//while a bot exists with no place in queue
while (botsLeftToQueue.Count > 0)
{
var nearestBot = botsLeftToQueue[0];
var distance = Queue[firstFreeNode].GetDistance(nearestBot);
for (int i = 1; i < botsLeftToQueue.Count; i++)
{
if (Queue[firstFreeNode].GetDistance(botsLeftToQueue[i]) < distance)
{
nearestBot = botsLeftToQueue[i];
distance = Queue[firstFreeNode].GetDistance(nearestBot);
}
}
botsLeftToQueue.Remove(nearestBot);
_placeInQueue.Add(nearestBot, Queue[firstFreeNode]);
firstFreeNode = Math.Min(firstFreeNode + 1, Queue.Count - 1);
}
//Last Node should never be blocked
if (LockedWaypoints.ContainsKey(Queue.Last()))
LockedWaypoints.Remove(Queue.Last());
}