jfreerails.controller
Class TrainAccessor

java.lang.Object
  extended by jfreerails.controller.TrainAccessor

public class TrainAccessor
extends java.lang.Object

Provides convenience methods to access the properties of a train from the world object.

Author:
Luke

Field Summary
private  int id
           
private  FreerailsPrincipal p
           
private  ReadOnlyWorld w
           
 
Constructor Summary
TrainAccessor(ReadOnlyWorld w, FreerailsPrincipal p, int id)
           
 
Method Summary
 TrainMotion findCurrentMotion(double time)
           
 TrainPositionOnMap findPosition(double time)
           
 ImmutableCargoBundle getCargoBundle()
           
 int getId()
           
 ImmutableSchedule getSchedule()
           
 int getStationId(double time)
           
 SpeedTimeAndStatus.TrainActivity getStatus(double time)
           
 ImPoint getTarget()
           
 TrainModel getTrain()
           
 boolean isMoving(double time)
           
 boolean keepWaiting()
          Returns true iff all the following hold.
 java.util.HashSet<TrackSection> occupiedTrackSection(double time)
           
 ImInts spaceAvailable()
          The space available on the train measured in cargo units.
static ImInts spaceAvailable2(ReadOnlyWorld row, ImmutableCargoBundle onTrain, ImInts consist)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

w

private final ReadOnlyWorld w

p

private final FreerailsPrincipal p

id

private final int id
Constructor Detail

TrainAccessor

public TrainAccessor(ReadOnlyWorld w,
                     FreerailsPrincipal p,
                     int id)
Method Detail

getId

public int getId()

getStatus

public SpeedTimeAndStatus.TrainActivity getStatus(double time)

getStationId

public int getStationId(double time)
Returns:
the id of the station the train is currently at, or -1 if no current station.

findPosition

public TrainPositionOnMap findPosition(double time)

findCurrentMotion

public TrainMotion findCurrentMotion(double time)

getTrain

public TrainModel getTrain()

getSchedule

public ImmutableSchedule getSchedule()

getCargoBundle

public ImmutableCargoBundle getCargoBundle()

keepWaiting

public boolean keepWaiting()
Returns true iff all the following hold.
  1. The train is waiting for a full load at some station X.
  2. The current train order tells the train to goto station X.
  3. The current train order tells the train to wait for a full load.
  4. The current train order specifies a consist that matches the train's current consist.


getTarget

public ImPoint getTarget()
Returns:
the location of the station the train is currently heading towards.

occupiedTrackSection

public java.util.HashSet<TrackSection> occupiedTrackSection(double time)

isMoving

public boolean isMoving(double time)

spaceAvailable

public ImInts spaceAvailable()
The space available on the train measured in cargo units.


spaceAvailable2

public static ImInts spaceAvailable2(ReadOnlyWorld row,
                                     ImmutableCargoBundle onTrain,
                                     ImInts consist)