using System; using System.Collections.Generic; using System.Text; namespace OpenTraffic.Model.Simulator.Queue { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] public class TurnQueue { LinkedList> queue; Turning turn; Shockwave shockwave; public TurnQueue(Turning turn) { queue = new LinkedList>(); shockwave = new Shockwave(); this.turn = turn; } public int Count { get { return queue.Count; } } public void Clear() { queue.Clear(); shockwave.Clear(); } public void AddVehicle(float time, Vehicle v) { queue.AddLast(new KeyValuePair(time,v)); } public void RemoveNext(out float time, out Vehicle v) { v = queue.First.Value.Value; time = queue.First.Value.Key; queue.RemoveFirst(); } public Vehicle First { get { return queue.First.Value.Value; } } public void TryToStartShockwave(float time, float pos) { if (!shockwave.Active || !shockwave.HasPassed(time, pos)) { shockwave.start(time, pos, turn.Origin.Simulator as Link, turn.Destination.Simulator as Link); }; } public bool HasWaitingVehicles(float stopTime, int maxVehicleIndex) { if (turn.Block) return false; if (queue.Count == 0) return false; // No cars. Should never happend if (turn.Destination.Simulator.IsFull()) return false; if (queue.First.Value.Key > stopTime) return false; // First car not arrvied float time = queue.First.Value.Key; if (time > stopTime) return false; if (queue.First.Value.Value.LinkPos > (maxVehicleIndex)) return false; if (!shockwave.HasPassed(stopTime, 5.6f * queue.First.Value.Value.LinkPos)) return false; return true; } } }