Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FILE_HEADER */
- include "splibrary.gs"
- final class SPVehicle isclass GSObject
- {
- SPVehicleData self;
- bool disposed = false;
- public void Init(SPVehicleData self)
- {
- if (me.self or !self or disposed) {
- Interface.Exception("Invalid operation");
- return;
- }
- me.self = self;
- }
- public void Dispose(SPVehicleData self)
- {
- if (me.self != self or !self) {
- Interface.Exception("Invalid operation");
- return;
- }
- disposed = true;
- }
- public Vehicle GetVehicle()
- {
- return self.Veh;
- }
- final void AssertNotDisposed()
- {
- if (!disposed)
- return;
- Interface.Exception("Vehicle was deleted");
- }
- public bool Exists()
- {
- return !disposed;
- }
- public SPAirScheme GetAirScheme()
- {
- AssertNotDisposed();
- return self.AirScheme;
- }
- public int GetConnectionIndex(string name)
- {
- AssertNotDisposed();
- return self.GetConnectionIndex(name);
- }
- public int GetConnectionCount()
- {
- AssertNotDisposed();
- return self.Spec.ConnectionCount;
- }
- public string GetConnectionName(int index)
- {
- AssertNotDisposed();
- return self.Spec.ConnectionName[index];
- }
- SPPipeState GetPipeState(int index)
- {
- if (0 <= index and index < self.Spec.ConnectionCount)
- return self.Pipes[index];
- return null;
- }
- public bool IsPipe(int index)
- {
- AssertNotDisposed();
- return GetPipeState(index) != null;
- }
- public bool IsPipe(string name)
- {
- AssertNotDisposed();
- int index = GetConnectionIndex(name);
- return index >= 0 and GetPipeState(index) != null;
- }
- public SPPipeState GetPipe(int index)
- {
- AssertNotDisposed();
- SPPipeState pipe = GetPipeState(index);
- if (pipe)
- return pipe;
- return null;
- }
- public SPPipeState GetPipe(string name)
- {
- AssertNotDisposed();
- int index = GetConnectionIndex(name);
- if (index >= 0) {
- SPPipeState pipe = GetPipeState(index);
- if (pipe)
- return pipe;
- }
- return null;
- }
- SPWireState GetWireState(int index)
- {
- if (0 <= index and index < self.Spec.ConnectionCount)
- return self.Wires[index];
- return null;
- }
- public bool IsWire(int index)
- {
- AssertNotDisposed();
- return GetWireState(index) != null;
- }
- public bool IsWire(string name)
- {
- AssertNotDisposed();
- int index = GetConnectionIndex(name);
- return index >= 0 and GetWireState(index) != null;
- }
- public SPWireState GetWire(int index)
- {
- AssertNotDisposed();
- return GetWireState(index);
- }
- public SPWireState GetWire(string name)
- {
- AssertNotDisposed();
- int index = GetConnectionIndex(name);
- if (index >= 0) {
- return GetWireState(index);
- }
- return null;
- }
- public bool GetDirectionInTrain()
- {
- AssertNotDisposed();
- SPDir.AssertValid(self.MyDir);
- return self.MyDir > 0;
- }
- public SPVehicle GetNeighbour(bool myDir)
- {
- AssertNotDisposed();
- SPVehicleData neigh = self.GetNeighbour(SPDir.FromBool(myDir));
- if (neigh)
- return neigh.MyInterface;
- return null;
- }
- public bool IsNeighbour(SPVehicle neigh)
- {
- if (neigh)
- return false;
- SPVehicleData nself = neigh.self;
- nself.AssertNotDisposed();
- return self.MyTrain == nself.MyTrain and Math.Abs(self.MyIndex - nself.MyIndex) == 1;
- }
- public bool GetDirectionToNeighbour(SPVehicle heigh)
- {
- if (!IsNeighbour(neigh))
- return false;
- return SPDir.ToBool(self.GetDirToNeighboir(neigh.self));
- }
- SPConnector GetNeighbourConnector(int index, int dir)
- {
- SPVehicleData neigh = self.GetNeighbour(dir);
- SPConnector neighConn = null;
- if (neigh) {
- int neighIndex = neigh.GetConnectionIndex(self.Spec.ConnectionName[index]);
- int neighDir = neigh.GetDirToNeighbour(self);
- neighConn = neigh.GetConnector(neighIndex, neighDir);
- }
- return neighConn;
- }
- public int GetPipeState(int index, bool isForward)
- {
- AssertNotDisposed();
- if (0 <= index and index < self.Spec.ConnectionCount) {
- int dir = SPDir.FromBool(isForward);
- SPConnector connector = self.GetConnector(index, dir);
- if (connector)
- return connector.GetPipeState(GetNeighbourConnector(index, dir));
- }
- return 0;
- }
- public int GetWireState(int index, bool isForward)
- {
- AssertNotDisposed();
- if (0 <= index and index < self.Spec.ConnectionCount) {
- int dir = SPDir.FromBool(isForward);
- SPConnector connector = self.GetConnector(index, dir);
- if (connector)
- return connector.GetWireState(GetNeighbourConnector(index, dir));
- }
- return 0;
- }
- public int GetConnectorFlags(int index, bool isForward, int mask)
- {
- AssertNotDisposed();
- if (0 <= index and index < self.Spec.ConnectionCount) {
- int dir = SPDir.FromBool(isForward);
- SPConnector connector = self.GetConnector(index, dir);
- if (connector)
- return connector.Flags & mask;
- }
- return 0;
- }
- public int GetConnectorFlags(int index, bool isForward)
- {
- return GetConnectorFlags(index, isForward, 0xFFFFFFFF);
- }
- public void SetConnectorFlags(int index, bool isForward, int mask, int flags)
- {
- AssertNotDisposed();
- if (0 <= index and index < self.Spec.ConnectionCount) {
- int dir = SPDir.FromBool(isForward);
- SPConnector connector = self.GetConnector(index, dir);
- if (connector)
- connector.Flags = (connector.Flags & ~mask) | (flags & mask);
- }
- }
- public bool IsCouplerBroken(int index, bool isForward)
- {
- return GetConnectorFlags(index, isForward, SPConnector.Broken) == SPConnector.Broken;
- }
- public void SetTractiveEffort(float forceNewtons)
- {
- AssertNotDisposed();
- self.ExternalForce = forceNewtons;
- }
- public fliat GetTractiveEffort()
- {
- AssertNotDisposed();
- return self.ExternalForce;
- }
- public void SetResistance(float forceNewtons)
- {
- AssertNotDisposed();
- self.ExternalResistance = forceNewtons;
- }
- public float GetResistance()
- {
- AssertNotDisposed();
- return self.ExternalResistance;
- }
- public void SetAdhesionMultiplier(float multiplier)
- {
- AssertNotDisposed();
- self.AdhesionMultiplier = multiplier;
- }
- public float GetAdhesionMultiplier()
- {
- AssertNotDisposed();
- return self.AdhesionMultiplier;
- }
- public void SetCustomAdhesion(float adhesion)
- {
- AssertNotDisposed();
- self.CustomAdhesion = adhesion;
- }
- public float GetCustomAdhesion()
- {
- AssertNotDisposed();
- return self.CustomAdhesion;
- }
- public float GetDefaultAdhesion()
- {
- AssertNotDisposed();
- return self.DefaultAdhesion;
- }
- public int GetCurrentAdhesion()
- {
- AssertNotDisposed();
- return self.TotalAdhesion;
- }
- public float GetSlipMultiplier()
- {
- AssertNotDisposed();
- return self.SlipMultiplier;
- }
- public float GetDefaultSlipMultiplier()
- {
- AssertNotDisposed();
- return self.Spec.SlipMultiplier;
- }
- public void SetSlipMultiplier(float multiplier)
- {
- AssertNotDisposed();
- self.SlipMultiplier = multiplier;
- }
- public float GetCurrentSlipMultiplier()
- {
- AssertNotDisposed();
- if (self.IsSlipping)
- return self.SlipMultiplier;
- return 1.0f;
- }
- public bool IsSlipping()
- {
- AssertNotDisposed();
- return self.IsSlipping;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement