net.kolls.railworld
Class Train

java.lang.Object
  extended by net.kolls.railworld.Train

public class Train
extends java.lang.Object

Represents a train (sequence of cars), including its position and controller.

Author:
Steve Kollmansberger

Field Summary
 boolean followMe
          Should the display track this train.
 boolean followMeOnce
          The display should jump to this train's location, but not continue to follow it.
static int MAX_SPEED_MPH
          Maximum speed (mph) for the train.
static int MAX_THROTTLE
          The maximum throttle setting for the train (not related to maximum speed)
 CLoc pos
          Trains position.
 boolean reverse
          Does this train request to be reversed? Controller must ensure train is stopped first.
 boolean split
          Does this train request to be split? Controller must ensure train is stopped and car other than the first selected.
 
Constructor Summary
Train(Car[] cars)
          Create a train from a given array of cars.
 
Method Summary
 void adjust()
          Calculates the trains acceleration and velocity based on the controls.
 Car[] array()
           
 double feetToSlow(double vel)
          Calculate, if the throttle were set to 0 and the brake applied, how many feet it would take for the train to slow to the requested velocity.
 boolean getBrake()
           
 TrainControl getController()
          Returns controller for this train.
 int getThrottle()
           
 boolean hasEngine()
           
 Distance length()
          The length is the length of all cars, with the distance between cars also added in.
 void setBrake(boolean b)
          Set or release the brake.
 void setController(TrainControl controller)
          Updates a train's controller.
 void setThrottle(int t)
          Update the throttle.
 void setVel(double v)
          Directly and immediately alter the train's velocity.
 double vel()
           
 int weight()
          The weight of the train is the sum of the weights of the cars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_THROTTLE

public static final int MAX_THROTTLE
The maximum throttle setting for the train (not related to maximum speed)

See Also:
Constant Field Values

pos

public CLoc pos
Trains position.


followMe

public boolean followMe
Should the display track this train. Only one train at a time should have this be true.


reverse

public boolean reverse
Does this train request to be reversed? Controller must ensure train is stopped first.


split

public boolean split
Does this train request to be split? Controller must ensure train is stopped and car other than the first selected.


followMeOnce

public boolean followMeOnce
The display should jump to this train's location, but not continue to follow it.


MAX_SPEED_MPH

public static final int MAX_SPEED_MPH
Maximum speed (mph) for the train.

See Also:
Constant Field Values
Constructor Detail

Train

public Train(Car[] cars)
Create a train from a given array of cars. A new MixController is assigned by default.

Parameters:
cars - Array of Cars.
Method Detail

hasEngine

public boolean hasEngine()
Returns:
true if the train has one or more engines.

weight

public int weight()
The weight of the train is the sum of the weights of the cars.

Returns:
Weight of the trains, in US Tons

getController

public TrainControl getController()
Returns controller for this train.

Returns:
The train's TrainControl.

setController

public void setController(TrainControl controller)
Updates a train's controller.

Parameters:
controller - The new controller to use.

length

public Distance length()
The length is the length of all cars, with the distance between cars also added in.

Returns:
A Distance measuring the length of the train.

vel

public double vel()
Returns:
Velocity, in MPH.

setVel

public void setVel(double v)
Directly and immediately alter the train's velocity. This should be used only sparingly. In general, you should alter the throttle and brake and let the train adjust its speed more naturally.

Parameters:
v - New velocity, MPH.

getThrottle

public int getThrottle()
Returns:
Current throttle setting.

getBrake

public boolean getBrake()
Returns:
true if the brake is active.

setThrottle

public void setThrottle(int t)
Update the throttle. Valid range is 0 (idle) to MAX_THROTTLE

Parameters:
t - Throttle setting

setBrake

public void setBrake(boolean b)
Set or release the brake.

Parameters:
b -

array

public Car[] array()
Returns:
Array of Cars that compose this train.

adjust

public void adjust()
Calculates the trains acceleration and velocity based on the controls. This should be called once every clock step. The amount of adjustment is proportional to the GameLoop.CLOCK_WAIT.


feetToSlow

public double feetToSlow(double vel)
Calculate, if the throttle were set to 0 and the brake applied, how many feet it would take for the train to slow to the requested velocity.

Parameters:
vel - Target velocity, in MPH. May be 0 for stopped.
Returns:
Number of feet that would be travered before reaching target velocity.