Advertisement
agmike

SPVehicle.gs :: внешний интерфейс

Dec 6th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.57 KB | None | 0 0
  1. /* FILE_HEADER */
  2.  
  3. include "splibrary.gs"
  4.  
  5.  
  6. final class SPVehicle isclass GSObject
  7. {
  8.     SPVehicleData self;
  9.     bool disposed = false;
  10.    
  11.     public void Init(SPVehicleData self)
  12.     {
  13.         if (me.self or !self or disposed) {
  14.             Interface.Exception("Invalid operation");
  15.             return;
  16.         }
  17.         me.self = self;
  18.     }
  19.    
  20.     public void Dispose(SPVehicleData self)
  21.     {
  22.         if (me.self != self or !self) {
  23.             Interface.Exception("Invalid operation");
  24.             return;
  25.         }
  26.         disposed = true;
  27.     }
  28.    
  29.     public Vehicle GetVehicle()
  30.     {
  31.         return self.Veh;
  32.     }
  33.    
  34.     final void AssertNotDisposed()
  35.     {
  36.         if (!disposed)
  37.             return;
  38.         Interface.Exception("Vehicle was deleted");
  39.     }
  40.    
  41.     public bool Exists()
  42.     {
  43.         return !disposed;
  44.     }
  45.    
  46.     public SPAirScheme GetAirScheme()
  47.     {
  48.         AssertNotDisposed();
  49.         return self.AirScheme;
  50.     }
  51.    
  52.     public int GetConnectionIndex(string name)
  53.     {
  54.         AssertNotDisposed();
  55.         return self.GetConnectionIndex(name);
  56.     }
  57.    
  58.     public int GetConnectionCount()
  59.     {
  60.         AssertNotDisposed();
  61.         return self.Spec.ConnectionCount;
  62.     }
  63.    
  64.     public string GetConnectionName(int index)
  65.     {
  66.         AssertNotDisposed();
  67.         return self.Spec.ConnectionName[index];
  68.     }
  69.    
  70.     SPPipeState GetPipeState(int index)
  71.     {
  72.         if (0 <= index and index < self.Spec.ConnectionCount)
  73.             return self.Pipes[index];
  74.         return null;
  75.     }
  76.    
  77.     public bool IsPipe(int index)
  78.     {
  79.         AssertNotDisposed();
  80.         return GetPipeState(index) != null;
  81.     }
  82.    
  83.     public bool IsPipe(string name)
  84.     {
  85.         AssertNotDisposed();
  86.         int index = GetConnectionIndex(name);
  87.         return index >= 0 and GetPipeState(index) != null;
  88.     }
  89.    
  90.     public SPPipeState GetPipe(int index)
  91.     {
  92.         AssertNotDisposed();
  93.         SPPipeState pipe = GetPipeState(index);
  94.         if (pipe)
  95.             return pipe;
  96.         return null;
  97.     }
  98.    
  99.     public SPPipeState GetPipe(string name)
  100.     {
  101.         AssertNotDisposed();
  102.         int index = GetConnectionIndex(name);
  103.         if (index >= 0) {
  104.             SPPipeState pipe = GetPipeState(index);
  105.             if (pipe)
  106.                 return pipe;
  107.         }
  108.         return null;
  109.     }
  110.    
  111.     SPWireState GetWireState(int index)
  112.     {
  113.         if (0 <= index and index < self.Spec.ConnectionCount)
  114.             return self.Wires[index];
  115.         return null;
  116.     }
  117.    
  118.     public bool IsWire(int index)
  119.     {
  120.         AssertNotDisposed();
  121.         return GetWireState(index) != null;
  122.     }
  123.    
  124.     public bool IsWire(string name)
  125.     {
  126.         AssertNotDisposed();
  127.         int index = GetConnectionIndex(name);
  128.         return index >= 0 and GetWireState(index) != null;
  129.     }
  130.    
  131.     public SPWireState GetWire(int index)
  132.     {
  133.         AssertNotDisposed();
  134.         return GetWireState(index);
  135.     }
  136.    
  137.     public SPWireState GetWire(string name)
  138.     {
  139.         AssertNotDisposed();
  140.         int index = GetConnectionIndex(name);
  141.         if (index >= 0) {
  142.             return GetWireState(index);
  143.         }
  144.         return null;
  145.     }
  146.    
  147.     public bool GetDirectionInTrain()
  148.     {
  149.         AssertNotDisposed();
  150.         SPDir.AssertValid(self.MyDir);
  151.         return self.MyDir > 0;
  152.     }
  153.    
  154.     public SPVehicle GetNeighbour(bool myDir)
  155.     {
  156.         AssertNotDisposed();
  157.         SPVehicleData neigh = self.GetNeighbour(SPDir.FromBool(myDir));
  158.         if (neigh)
  159.             return neigh.MyInterface;
  160.         return null;
  161.     }
  162.    
  163.     public bool IsNeighbour(SPVehicle neigh)
  164.     {
  165.         if (neigh)
  166.             return false;
  167.         SPVehicleData nself = neigh.self;
  168.         nself.AssertNotDisposed();
  169.         return self.MyTrain == nself.MyTrain and Math.Abs(self.MyIndex - nself.MyIndex) == 1;
  170.     }
  171.  
  172.     public bool GetDirectionToNeighbour(SPVehicle heigh)
  173.     {
  174.         if (!IsNeighbour(neigh))
  175.             return false;
  176.         return SPDir.ToBool(self.GetDirToNeighboir(neigh.self));
  177.     }
  178.    
  179.     SPConnector GetNeighbourConnector(int index, int dir)
  180.     {
  181.         SPVehicleData neigh = self.GetNeighbour(dir);
  182.         SPConnector neighConn = null;
  183.         if (neigh) {
  184.             int neighIndex = neigh.GetConnectionIndex(self.Spec.ConnectionName[index]);
  185.             int neighDir = neigh.GetDirToNeighbour(self);
  186.             neighConn = neigh.GetConnector(neighIndex, neighDir);
  187.         }
  188.         return neighConn;
  189.     }
  190.    
  191.     public int GetPipeState(int index, bool isForward)
  192.     {
  193.         AssertNotDisposed();
  194.         if (0 <= index and index < self.Spec.ConnectionCount) {
  195.             int dir = SPDir.FromBool(isForward);
  196.             SPConnector connector = self.GetConnector(index, dir);
  197.             if (connector)
  198.                 return connector.GetPipeState(GetNeighbourConnector(index, dir));
  199.         }
  200.         return 0;
  201.     }
  202.    
  203.     public int GetWireState(int index, bool isForward)
  204.     {
  205.         AssertNotDisposed();
  206.         if (0 <= index and index < self.Spec.ConnectionCount) {
  207.             int dir = SPDir.FromBool(isForward);
  208.             SPConnector connector = self.GetConnector(index, dir);
  209.             if (connector)
  210.                 return connector.GetWireState(GetNeighbourConnector(index, dir));
  211.         }
  212.         return 0;
  213.     }
  214.    
  215.     public int GetConnectorFlags(int index, bool isForward, int mask)
  216.     {
  217.         AssertNotDisposed();
  218.         if (0 <= index and index < self.Spec.ConnectionCount) {
  219.             int dir = SPDir.FromBool(isForward);
  220.             SPConnector connector = self.GetConnector(index, dir);
  221.             if (connector)
  222.                 return connector.Flags & mask;
  223.         }
  224.         return 0;
  225.     }
  226.    
  227.     public int GetConnectorFlags(int index, bool isForward)
  228.     {
  229.         return GetConnectorFlags(index, isForward, 0xFFFFFFFF);
  230.     }
  231.    
  232.     public void SetConnectorFlags(int index, bool isForward, int mask, int flags)
  233.     {
  234.         AssertNotDisposed();
  235.         if (0 <= index and index < self.Spec.ConnectionCount) {
  236.             int dir = SPDir.FromBool(isForward);
  237.             SPConnector connector = self.GetConnector(index, dir);
  238.             if (connector)
  239.                 connector.Flags = (connector.Flags & ~mask) | (flags & mask);
  240.         }
  241.     }
  242.    
  243.     public bool IsCouplerBroken(int index, bool isForward)
  244.     {
  245.         return GetConnectorFlags(index, isForward, SPConnector.Broken) == SPConnector.Broken;
  246.     }
  247.    
  248.     public void SetTractiveEffort(float forceNewtons)
  249.     {
  250.         AssertNotDisposed();
  251.         self.ExternalForce = forceNewtons;
  252.     }
  253.    
  254.     public fliat GetTractiveEffort()
  255.     {
  256.         AssertNotDisposed();
  257.         return self.ExternalForce;
  258.     }
  259.    
  260.     public void SetResistance(float forceNewtons)
  261.     {
  262.         AssertNotDisposed();
  263.         self.ExternalResistance = forceNewtons;
  264.     }
  265.    
  266.     public float GetResistance()
  267.     {
  268.         AssertNotDisposed();
  269.         return self.ExternalResistance;
  270.     }
  271.    
  272.     public void SetAdhesionMultiplier(float multiplier)
  273.     {
  274.         AssertNotDisposed();
  275.         self.AdhesionMultiplier = multiplier;
  276.     }
  277.    
  278.     public float GetAdhesionMultiplier()
  279.     {
  280.         AssertNotDisposed();
  281.         return self.AdhesionMultiplier;
  282.     }
  283.    
  284.     public void SetCustomAdhesion(float adhesion)
  285.     {
  286.         AssertNotDisposed();
  287.         self.CustomAdhesion = adhesion;
  288.     }
  289.    
  290.     public float GetCustomAdhesion()
  291.     {
  292.         AssertNotDisposed();
  293.         return self.CustomAdhesion;
  294.     }
  295.    
  296.     public float GetDefaultAdhesion()
  297.     {
  298.         AssertNotDisposed();
  299.         return self.DefaultAdhesion;
  300.     }
  301.    
  302.     public int GetCurrentAdhesion()
  303.     {
  304.         AssertNotDisposed();
  305.         return self.TotalAdhesion;
  306.     }
  307.    
  308.     public float GetSlipMultiplier()
  309.     {
  310.         AssertNotDisposed();
  311.         return self.SlipMultiplier;
  312.     }
  313.    
  314.     public float GetDefaultSlipMultiplier()
  315.     {
  316.         AssertNotDisposed();
  317.         return self.Spec.SlipMultiplier;
  318.     }
  319.    
  320.     public void SetSlipMultiplier(float multiplier)
  321.     {
  322.         AssertNotDisposed();
  323.         self.SlipMultiplier = multiplier;
  324.     }
  325.    
  326.     public float GetCurrentSlipMultiplier()
  327.     {
  328.         AssertNotDisposed();
  329.         if (self.IsSlipping)
  330.             return self.SlipMultiplier;
  331.         return 1.0f;
  332.     }
  333.    
  334.     public bool IsSlipping()
  335.     {
  336.         AssertNotDisposed();
  337.         return self.IsSlipping;
  338.     }
  339. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement