You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 lines
2.1 KiB

  1. using System;
  2. using SUISS.Scheduling;
  3. using UnityEngine;
  4. namespace SUISSEngine
  5. {
  6. public class ScriptedVehicle : Vehicle
  7. {
  8. protected override void FindDirection(bool dontTurnBack)
  9. {
  10. Vehicle.Direction direction = (Vehicle.Direction)(-1);
  11. switch (this._state)
  12. {
  13. case ScriptedVehicle.State.Idle:
  14. this.SetDirection(this.idleDirection);
  15. break;
  16. case ScriptedVehicle.State.MovingForwards:
  17. direction = this.path[this._index++];
  18. if (this._index == this.path.Length)
  19. {
  20. this._state = ScriptedVehicle.State.Waiting;
  21. this._waitUntil = Timing.UtcNow + this.waitTime;
  22. }
  23. break;
  24. case ScriptedVehicle.State.Waiting:
  25. if (Timing.UtcNow > this._waitUntil)
  26. {
  27. this._state = ScriptedVehicle.State.MovingBackwards;
  28. }
  29. break;
  30. case ScriptedVehicle.State.MovingBackwards:
  31. if (this._index == 0)
  32. {
  33. this._state = ScriptedVehicle.State.Idle;
  34. this.SetDirection(this.idleDirection);
  35. }
  36. else
  37. {
  38. direction = Vehicle.InvertDirection(this.path[--this._index]);
  39. }
  40. break;
  41. }
  42. this.stuck = false;
  43. GridIndex index = new GridIndex(Mathf.FloorToInt(this.location.u), Mathf.FloorToInt(this.location.v));
  44. if (direction >= Vehicle.Direction.North)
  45. {
  46. index = Vehicle.ApplyDirection(index, direction);
  47. this.targetLocation = new GridPoint(index);
  48. this.targetLocation.u = this.targetLocation.u + 0.5f;
  49. this.targetLocation.v = this.targetLocation.v + 0.5f;
  50. this.SetDirection(direction);
  51. }
  52. else
  53. {
  54. this.targetLocation = base.CurrentLocation;
  55. }
  56. }
  57. public void Launch()
  58. {
  59. this._state = ScriptedVehicle.State.MovingForwards;
  60. this._index = 0;
  61. }
  62. public bool IsIdle()
  63. {
  64. return this._state == ScriptedVehicle.State.Idle;
  65. }
  66. public Vehicle.Direction idleDirection;
  67. public Vehicle.Direction[] path;
  68. public double waitTime = 5.0;
  69. protected int _index;
  70. protected ScriptedVehicle.State _state;
  71. protected double _waitUntil;
  72. protected enum State
  73. {
  74. Idle,
  75. MovingForwards,
  76. Waiting,
  77. MovingBackwards
  78. }
  79. }
  80. }