Class Crossing

From TrainzOnline
Revision as of 15:02, 26 February 2024 by Pw3r (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


  • A script class to represent a level crossing or similar object.
  • By default a crossing is automatically controlled by Trainz native code.
  • The crossing will close when a train is within the trigger distance of the crossing (as specified by the asset).
  • The crossing will reopen to road traffic when there are no trains within the trigger disance.


Contents

Constants & Messages


Crossing States


  • These values define the possible state of a crossing.
public define int CROSSING_STATE_OPEN = 0 Crossing is open to road traffic.
public define int CROSSING_STATE_CLOSING = 1 Crossing is in the act of closing.
public define int CROSSING_STATE_CLOSED = 2 Crossing is closed to road traffic.
public define int CROSSING_STATE_OPENING = 3 Crossing is in the act of opening.


Related Messages


  • Messages sent to and from Crossings objects are listed below:
  • Note that more messages are also posted by the parent SceneryWithTrack class.


Major Minor Source Destination
Object Enter Crossing Crossing
Object Leave Crossing Crossing
Crossing StateChanged Crossing Crossing


Methods

GetCrossingAutomatic

public native bool GetCrossingAutomatic(void)
Parameters
  • None
Returned Value
  • Whether the crossing operating in automatic mode.
Syntax
bool bIsAutomaticMode = crossing.GetCrossingAutomatic();
Notes


GetCrossingHasNearbyTrain

public native bool GetCrossingHasNearbyTrain(void)
Parameters
  • None
Returned Value
  • Whether any trains are within the trigger radius (default 200m, overridable by the asset).
Syntax
bool bHasNearbyTrain = crossing.GetCrossingHasNearbyTrain();
Notes
  • This function will continue to operate when the crossing is in manual script mode.
  • The default crossing trigger distance is 200 metres, but this can be overridden by the asset config.
  • The crossing trigger distance cannot be overridden by script.


GetCrossingOwner

public native TrainzGameObject GetCrossingOwner(void)
Parameters
  • None
Returned Value
  • The crossing owner, or null.
Syntax;
if (crossing.GetCrossingOwner())
 return; // The crossing is owned, so we cannot alter state.
Notes
  • Returns the crossing owner, if any.
  • Owned crossings cannot have their state altered by any script except the owner, including the crossing itself.
  • Introduced for Interlocking Towers.


GetCrossingState

public native int GetCrossingState(void)
Parameters
  • None
Returned Value
  • One of the crossing state constants indicating the current condition of the crossing.
Syntax
switch(GetCrossingState())
{
case CROSSING_STATE_OPEN:
  // Crossing is open to road traffic.
  break;

case CROSSING_STATE_CLOSING:
case CROSSING_STATE_CLOSED:
case CROSSING_STATE_OPENING:
  // Crossing is NOT open to road traffic.
  break;
}
Notes
  • A "Crossing","StateChanged" message will be posted to the crossing whenever this value changes.


SetCrossingAutomatic

public native void SetCrossingAutomatic(SecurityToken token, bool auto)
Parameters
  • token = A token for the crossing owner with rights "crossing-state", or null.
  • auto = True to select automatic mode, false to disable automatic control.
Returned Value
  • None
Syntax
SetCrossingAutomatic(null, false);
Notes
  • The token is unused if the crossing is unowned, and can be passed as null.


SetCrossingOwner

public native void SetCrossingOwner(SecurityToken token, TrainzGameObject owner)
Parameters
  • token - A token for the crossing owner (new and current, if applicable) with rights "crossing-owner".
  • owner - New owner to set, may be null.
Returned Value
  • Whether the call succeeded, and the crossing owner was changed.
Syntax;
string[] rights = new string[1];
rights[0] = "crossing-owner";
SecurityToken token = IssueSecurityToken(GetAsset().GetKUID(), rights);
crossing.SetCrossingOwner(token, me);
Notes
  • Updates the crossing 'owner', which is used to lock access to various functions.
  • Owned crossings cannot have their state altered by any script except the owner, including the crossing itself.
  • Introduced for Interlocking Towers.


SetCrossingState

public native void SetCrossingState(SecurityToken token, int state)
Parameters
  • token = A token for the crossing owner with rights "crossing-state", or null.
  • state = One of the crossing state constants indicating which state to set.
Returned Value
  • None
Syntax
SetCrossingState(null, Crossing.CROSSING_STATE_CLOSED);
Notes
  • If you intend to alter the crossing state you should first disable automatic control (See SetCrossingAutomatic)
  • The crossing state will be altered as requested even if the crossing is under automatic control, but native code may quickly change it back.
  • The token is unused if the crossing is unowned, and can be passed as null.


Categories

Personal tools