|
- using System;
- using SUISS.Scheduling;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- public class ScriptedVehicle : Vehicle
- {
- protected override void FindDirection(bool dontTurnBack)
- {
- Vehicle.Direction direction = (Vehicle.Direction)(-1);
- switch (this._state)
- {
- case ScriptedVehicle.State.Idle:
- this.SetDirection(this.idleDirection);
- break;
- case ScriptedVehicle.State.MovingForwards:
- direction = this.path[this._index++];
- if (this._index == this.path.Length)
- {
- this._state = ScriptedVehicle.State.Waiting;
- this._waitUntil = Timing.UtcNow + this.waitTime;
- }
- break;
- case ScriptedVehicle.State.Waiting:
- if (Timing.UtcNow > this._waitUntil)
- {
- this._state = ScriptedVehicle.State.MovingBackwards;
- }
- break;
- case ScriptedVehicle.State.MovingBackwards:
- if (this._index == 0)
- {
- this._state = ScriptedVehicle.State.Idle;
- this.SetDirection(this.idleDirection);
- }
- else
- {
- direction = Vehicle.InvertDirection(this.path[--this._index]);
- }
- break;
- }
- this.stuck = false;
- GridIndex index = new GridIndex(Mathf.FloorToInt(this.location.u), Mathf.FloorToInt(this.location.v));
- if (direction >= Vehicle.Direction.North)
- {
- index = Vehicle.ApplyDirection(index, direction);
- this.targetLocation = new GridPoint(index);
- this.targetLocation.u = this.targetLocation.u + 0.5f;
- this.targetLocation.v = this.targetLocation.v + 0.5f;
- this.SetDirection(direction);
- }
- else
- {
- this.targetLocation = base.CurrentLocation;
- }
- }
-
- public void Launch()
- {
- this._state = ScriptedVehicle.State.MovingForwards;
- this._index = 0;
- }
-
- public bool IsIdle()
- {
- return this._state == ScriptedVehicle.State.Idle;
- }
-
- public Vehicle.Direction idleDirection;
-
- public Vehicle.Direction[] path;
-
- public double waitTime = 5.0;
-
- protected int _index;
-
- protected ScriptedVehicle.State _state;
-
- protected double _waitUntil;
-
- protected enum State
- {
- Idle,
- MovingForwards,
- Waiting,
- MovingBackwards
- }
- }
- }
|