org.mars_sim.msp.simulation.person.ai.task
Class OperateVehicle

java.lang.Object
  extended by org.mars_sim.msp.simulation.person.ai.task.Task
      extended by org.mars_sim.msp.simulation.person.ai.task.OperateVehicle
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
DriveGroundVehicle

public abstract class OperateVehicle
extends Task
implements java.io.Serializable

The OperateVehicle class is an abstract task for operating a vehicle, driving/flying it to a destination.

See Also:
Serialized Form

Field Summary
protected  double backingUpDistance
           
static double BASE_ACCIDENT_CHANCE
           
protected  boolean isBackingUp
           
static java.lang.String MOBILIZE
           
 
Fields inherited from class org.mars_sim.msp.simulation.person.ai.task.Task
effortDriven, hasDuration, person, phaseTimeCompleted, phaseTimeRequired, stressModifier, subTask, TASK_DESC_EVENT, TASK_ENDED_EVENT, TASK_NAME_EVENT, TASK_PHASE_EVENT, TASK_SUBTASK_EVENT
 
Constructor Summary
OperateVehicle(java.lang.String name, Person person, Vehicle vehicle, Coordinates destination, MarsClock startTripTime, double startTripDistance, double stressModifier, boolean hasDuration, double duration)
          Default Constructor
 
Method Summary
protected abstract  void checkForAccident(double time)
          Check if vehicle has had an accident.
 void endTask()
          Ends the task and performs any final actions.
static double getAverageVehicleSpeed(Vehicle vehicle, VehicleOperator operator)
          Gets the average operating speed of a vehicle for a given operator.
 Coordinates getDestination()
          Gets the location of the destination of the trip.
protected  double getDistanceToDestination()
          Gets the distance to the destination.
 MarsClock getETA()
          Determines the ETA (Estimated Time of Arrival) to the destination.
protected  double getSpeed(Direction direction)
          Determine vehicle speed for a given direction.
protected  double getSpeedSkillModifier()
          Determine the speed modifier based on the driver's skill level.
protected  double getStartTripDistance()
          Gets the distance to the destination at the start of the trip.
protected  MarsClock getStartTripTime()
          Gets the time/date the trip was started on.
 Vehicle getVehicle()
          Gets the vehicle operated with this task.
protected  double getVehicleElevation()
          Returns the elevation at the vehicle's position.
protected  double mobilizeVehicle(double time)
          Move the vehicle in its direction at its speed for the amount of time given.
protected  double mobilizeVehiclePhase(double time)
          Perform the mobilize vehicle phase for the amount of time given.
protected  double performMappedPhase(double time)
          Performs the method mapped to the task's current phase.
 void setDestination(Coordinates newDestination)
          Sets the location of the destination of this trip.
protected abstract  void updateVehicleElevationAltitude()
          Update vehicle with its current elevation or altitude.
 
Methods inherited from class org.mars_sim.msp.simulation.person.ai.task.Task
addExperience, addPhase, compareTo, getAssociatedSkills, getCreateEvents, getCrowdingProbabilityModifier, getDescription, getDuration, getEffectiveSkillLevel, getName, getPhase, getProbability, getRelationshipModifier, getSubTask, getTeacher, getTeachingExperienceModifier, getTimeCompleted, getTopPhase, hasTeacher, isDone, isEffortDriven, setCreateEvents, setDescription, setDuration, setName, setPhase, setStressModifier, setTeacher, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MOBILIZE

public static final java.lang.String MOBILIZE
See Also:
Constant Field Values

BASE_ACCIDENT_CHANCE

public static final double BASE_ACCIDENT_CHANCE
See Also:
Constant Field Values

backingUpDistance

protected double backingUpDistance

isBackingUp

protected boolean isBackingUp
Constructor Detail

OperateVehicle

public OperateVehicle(java.lang.String name,
                      Person person,
                      Vehicle vehicle,
                      Coordinates destination,
                      MarsClock startTripTime,
                      double startTripDistance,
                      double stressModifier,
                      boolean hasDuration,
                      double duration)
               throws java.lang.Exception
Default Constructor

Parameters:
name - the name of the particular task.
person - the person performing the task.
vehicle - the vehicle to operate.
destination - the location of destination of the trip.
startTripTime - the time/date the trip is starting.
startTripDistance - the distance (km) to the destination at the start of the trip.
stressModifier - the modifier for stress on the person performing the task.
hasDuration - does the task have a time duration?
duration - the time duration (millisols) of the task (or 0 if none).
Throws:
java.lang.Exception - if task cannot be constructed.
Method Detail

performMappedPhase

protected double performMappedPhase(double time)
                             throws java.lang.Exception
Performs the method mapped to the task's current phase.

Specified by:
performMappedPhase in class Task
Parameters:
time - the amount of time the phase is to be performed.
Returns:
the remaining time after the phase has been performed.
Throws:
java.lang.Exception - if error in performing phase or if phase cannot be found.

getVehicle

public Vehicle getVehicle()
Gets the vehicle operated with this task.

Returns:
vehicle

getDestination

public Coordinates getDestination()
Gets the location of the destination of the trip.

Returns:
location of destination

setDestination

public void setDestination(Coordinates newDestination)
Sets the location of the destination of this trip.

Parameters:
newDestination - location of the destination.

getStartTripTime

protected MarsClock getStartTripTime()
Gets the time/date the trip was started on.

Returns:
start time

getStartTripDistance

protected double getStartTripDistance()
Gets the distance to the destination at the start of the trip.

Returns:
distance (km) to destination.

mobilizeVehiclePhase

protected double mobilizeVehiclePhase(double time)
                               throws java.lang.Exception
Perform the mobilize vehicle phase for the amount of time given.

Parameters:
time - the amount of time (ms) to perform the phase.
Returns:
the amount of time left over after performing the phase.
Throws:
java.lang.Exception - if error while performing phase.

mobilizeVehicle

protected double mobilizeVehicle(double time)
                          throws java.lang.Exception
Move the vehicle in its direction at its speed for the amount of time given. Stop if reached destination.

Parameters:
time - the amount of time (ms) to drive.
Returns:
the amount of time (ms) left over after driving (if any)
Throws:
java.lang.Exception - if error while mobilizing vehicle.

updateVehicleElevationAltitude

protected abstract void updateVehicleElevationAltitude()
Update vehicle with its current elevation or altitude.


getETA

public MarsClock getETA()
Determines the ETA (Estimated Time of Arrival) to the destination.

Returns:
MarsClock instance of date/time for ETA

checkForAccident

protected abstract void checkForAccident(double time)
Check if vehicle has had an accident.

Parameters:
time - the amount of time vehicle is driven (millisols)

getSpeed

protected double getSpeed(Direction direction)
Determine vehicle speed for a given direction.

Parameters:
direction - the direction of travel
Returns:
speed in km/hr

getSpeedSkillModifier

protected double getSpeedSkillModifier()
Determine the speed modifier based on the driver's skill level.

Returns:
speed modifier (km/hr)

getDistanceToDestination

protected double getDistanceToDestination()
Gets the distance to the destination.

Returns:
distance (km)

getVehicleElevation

protected double getVehicleElevation()
Returns the elevation at the vehicle's position.

Returns:
elevation in km.

endTask

public void endTask()
Ends the task and performs any final actions.

Overrides:
endTask in class Task

getAverageVehicleSpeed

public static double getAverageVehicleSpeed(Vehicle vehicle,
                                            VehicleOperator operator)
Gets the average operating speed of a vehicle for a given operator.

Parameters:
vehicle - the vehicle.
operator - the vehicle operator.
Returns:
average operating speed (km/h)