using Gley.UrbanSystem.Internal;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Gley.TrafficSystem.Internal
{
///
/// Stores waypoint properties
///
public class WaypointSettings : WaypointSettingsBase
{
public List otherLanes;
public List giveWayList;
public List allowedCars;
public float laneWidth;
public int maxSpeed;
public bool giveWay;
public bool enter;
public bool exit;
public bool speedLocked;
public bool carsLocked;
public bool complexGiveWay;
public bool zipperGiveWay;
public override void Initialize()
{
base.Initialize();
otherLanes = new List();
giveWayList = new List();
}
public void ResetProperties()
{
enter = false;
exit = false;
}
public override void VerifyAssignments(bool showPrevsWarning)
{
base.VerifyAssignments(showPrevsWarning);
if (showPrevsWarning)
{
if (prev.Count == 0)
{
Debug.LogWarning(UrbanSystemErrors.NoPrevs(name), gameObject);
}
}
if (otherLanes == null)
{
otherLanes = new List();
}
for (int j = otherLanes.Count - 1; j >= 0; j--)
{
if (otherLanes[j] == null)
{
otherLanes.RemoveAt(j);
}
}
if (giveWayList == null)
{
giveWayList = new List();
}
for (int j = giveWayList.Count - 1; j >= 0; j--)
{
if (giveWayList[j] == null)
{
giveWayList.RemoveAt(j);
}
}
if (allowedCars == null)
{
allowedCars = new List();
}
for (int i = allowedCars.Count - 1; i >= 0; i--)
{
if (!IsValid((int)allowedCars[i]))
{
allowedCars.RemoveAt(i);
}
}
if (laneWidth == 0)
{
if (name.Contains(Gley.UrbanSystem.Internal.UrbanSystemConstants.Connect))
{
laneWidth = 4;
}
else
{
laneWidth = transform.parent.parent.parent.GetComponent().laneWidth;
}
}
}
public void SetVehicleTypesForAllNeighbors(List allowedVehicles)
{
Queue queue = new Queue();
HashSet visited = new HashSet();
// Start with the current waypoint
queue.Enqueue(this);
visited.Add(this);
carsLocked = false;
while (queue.Count > 0)
{
WaypointSettings current = queue.Dequeue();
if (!current.carsLocked)
{
current.allowedCars = allowedVehicles;
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(current);
#endif
// Enqueue all unvisited neighbors
foreach (WaypointSettingsBase neighbor in current.neighbors)
{
if (!visited.Contains(neighbor))
{
queue.Enqueue((WaypointSettings)neighbor);
visited.Add(neighbor);
}
}
}
}
if (allowedVehicles.Count > 0)
{
carsLocked = true;
}
Debug.Log("Done");
}
public void SetSpeedForAllNeighbors(int newSpeed)
{
Queue queue = new Queue();
HashSet visited = new HashSet();
// Start with the current waypoint
queue.Enqueue(this);
visited.Add(this);
speedLocked = false;
while (queue.Count > 0)
{
WaypointSettings current = queue.Dequeue();
if (!current.speedLocked)
{
current.maxSpeed = newSpeed;
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(current);
#endif
// Enqueue all unvisited neighbors
foreach (WaypointSettingsBase neighbor in current.neighbors)
{
if (!visited.Contains(neighbor))
{
queue.Enqueue((WaypointSettings)neighbor);
visited.Add(neighbor);
}
}
}
}
if (newSpeed != 0)
{
speedLocked = true;
}
Debug.Log("Done");
}
private bool IsValid(int value)
{
return Enum.IsDefined(typeof(VehicleTypes), value);
}
}
}