Parking/Assets/Scripts/Driver.cs

113 lines
3.2 KiB
C#
Raw Normal View History

2022-08-25 18:38:38 +02:00
using System;
using UnityEngine;
2022-09-05 22:01:52 +02:00
using Object = UnityEngine.Object;
2022-08-25 18:38:38 +02:00
namespace Parking
2022-08-25 18:38:38 +02:00
{
public class Driver
{
2022-09-03 21:27:31 +02:00
public readonly int Number;
2022-09-05 22:01:52 +02:00
public readonly ParkingPreference ParkingPreference;
2022-08-31 21:19:20 +02:00
public readonly Size Size;
2022-09-01 22:31:57 +02:00
public GameObject GameObject;
2022-09-05 22:01:52 +02:00
public bool Parked;
2022-09-04 00:35:45 +02:00
public int Priority;
2022-09-05 22:01:52 +02:00
public bool Rejected;
public Spot Spot;
public DateTime[] Times;
2022-09-04 00:35:45 +02:00
public int UpdateInterval;
2022-10-10 19:45:07 +02:00
public Spot ReservedSpot;
public bool Reserved;
public TimeSpan RealArrival => Times[2].TimeOfDay;
public TimeSpan RealDeparture => Times[3].TimeOfDay;
public TimeSpan PlannedArrival => Times[0].TimeOfDay;
public TimeSpan PlannedDeparture => Times[1].TimeOfDay;
2022-09-04 00:35:45 +02:00
public Driver(Size size, int number, ParkingPreference parkingPreference, int priority, int updateInterval)
{
Size = size;
2022-09-03 21:27:31 +02:00
Number = number;
ParkingPreference = parkingPreference;
2022-09-04 00:35:45 +02:00
Priority = priority;
UpdateInterval = updateInterval;
}
2022-09-05 22:01:52 +02:00
2022-09-03 21:27:31 +02:00
public void Reset()
{
Parked = false;
Rejected = false;
2022-10-10 22:13:42 +02:00
Reserved = false;
ReservedSpot = null;
if (Spot != null) {
2022-09-03 21:27:31 +02:00
Spot.Free = true;
2022-10-10 22:13:42 +02:00
Spot.Reserved = false;
}
2022-09-03 21:27:31 +02:00
Spot = null;
2022-09-05 22:01:52 +02:00
if (GameObject != null)
Object.Destroy(GameObject);
2022-09-03 21:27:31 +02:00
}
}
2022-08-25 18:38:38 +02:00
public class Spot : IComparable<Spot>
2022-08-25 18:38:38 +02:00
{
2022-09-05 22:01:52 +02:00
public bool AlignToTop = true;
public bool Flipped;
2022-09-01 22:31:57 +02:00
public bool Free = true;
2022-09-05 22:01:52 +02:00
public GameObject GameObject;
2022-09-05 22:00:15 +02:00
public int Lane = 0;
2022-10-05 21:56:02 +02:00
public TimeSpan LastReconfiguration = TimeSpan.Zero;
2022-09-05 22:01:52 +02:00
public ParkingPreference ParkingDirection = ParkingPreference.Any;
2022-09-05 22:00:15 +02:00
public bool Perpendicular = true;
2022-09-05 22:01:52 +02:00
public bool Reserved = false;
public int ReservedPriority = 0;
public Size Size;
public Driver OccupyingDriver;
public Spot(Size size, bool flipped)
{
Size = size;
Flipped = flipped;
}
2022-09-04 00:35:45 +02:00
public Spot()
{
2022-09-05 22:01:52 +02:00
2022-09-04 00:35:45 +02:00
}
2022-09-05 22:01:52 +02:00
2022-10-06 21:52:35 +02:00
public bool Vertical => Perpendicular;
2022-10-05 21:56:02 +02:00
public float LowerBorder => GameObject.transform.position.y -
2022-10-06 21:52:35 +02:00
(!Vertical ? 2.25f / 2.0f : ParkingManager.SpotHeights[(int) Size] / 2.0f);
public float RightBorder => GameObject.transform.position.x +
(Vertical ? 2.25f / 2.0f : ParkingManager.SpotHeights[(int) Size] / 2.0f);
public float LeftBorder => GameObject.transform.position.x -
(Vertical ? 2.25f / 2.0f : ParkingManager.SpotHeights[(int) Size] / 2.0f);
2022-10-05 21:56:02 +02:00
public Vector3 Position
{
get => GameObject.transform.position;
set => GameObject.transform.position = value;
}
public int CompareTo(Spot obj)
{
return Size.CompareTo(obj.Size);
}
2022-08-25 18:38:38 +02:00
}
2022-09-05 22:01:52 +02:00
public enum Size
{
A = 0,
B = 1,
C = 2,
D = 3
}
2022-08-25 18:38:38 +02:00
public enum ParkingPreference
{
Any = 0,
Front = 1,
Back = 2
}
2022-08-25 18:38:38 +02:00
}