org.mars_sim.msp.simulation.person.ai.mission
Class VehicleMission

java.lang.Object
  extended by org.mars_sim.msp.simulation.person.ai.mission.Mission
      extended by org.mars_sim.msp.simulation.person.ai.mission.TravelMission
          extended by org.mars_sim.msp.simulation.person.ai.mission.VehicleMission
All Implemented Interfaces:
java.io.Serializable, UnitListener
Direct Known Subclasses:
RoverMission

public abstract class VehicleMission
extends TravelMission
implements UnitListener

A mission that involves driving a vehicle along a series of navpoints.

See Also:
Serialized Form

Field Summary
static java.lang.String DISEMBARKING
           
static java.lang.String EMBARKING
           
protected  java.util.Map<java.lang.Class,java.lang.Integer> equipmentNeededCache
           
protected  boolean loadedFlag
           
static java.lang.String OPERATOR_EVENT
           
static java.lang.String TRAVELLING
           
static java.lang.String VEHICLE_EVENT
           
 
Fields inherited from class org.mars_sim.msp.simulation.person.ai.mission.TravelMission
AT_NAVPOINT, DISTANCE_EVENT, NAVPOINTS_EVENT, TRAVEL_STATUS_EVENT, TRAVEL_TO_NAVPOINT
 
Fields inherited from class org.mars_sim.msp.simulation.person.ai.mission.Mission
ADD_MEMBER_EVENT, ASSOCIATED_SETTLEMENT_EVENT, CAPACITY_EVENT, DESCRIPTION_EVENT, END_MISSION_EVENT, MIN_PEOPLE_EVENT, NAME_EVENT, PHASE_DESCRIPTION_EVENT, PHASE_EVENT, REMOVE_MEMBER_EVENT
 
Constructor Summary
protected VehicleMission(java.lang.String name, Person startingPerson, int minPeople)
          Constructor
protected VehicleMission(java.lang.String name, Person startingPerson, int minPeople, Vehicle vehicle)
          Constructor with vehicle.
 
Method Summary
protected  int compareVehicles(Vehicle firstVehicle, Vehicle secondVehicle)
          Compares the quality of two vehicles for use in this mission.
protected  void determineEmergencyDestination(Person person)
          Determines the emergency destination settlement for the mission if one is reachable, otherwise sets the emergency beacon and ends the mission.
protected  void determineNewPhase()
          Determines a new phase for the mission when the current phase has ended.
 void endMission(java.lang.String reason)
          Finalizes the mission
 Settlement findClosestSettlement()
          Finds the closest settlement to the mission.
protected  double getAverageVehicleSpeedForOperators()
          Gets the average operating speed of the mission vehicle for all of the mission members.
 java.util.Map<java.lang.Class,java.lang.Integer> getEquipmentToLoad()
          Gets the equipment needed for loading the vehicle.
 double getEstimatedRemainingMissionTime(boolean useBuffer)
          Gets the estimated time remaining for the mission.
 double getEstimatedTripTime(boolean useBuffer, double distance)
          Gets the estimated time for a trip.
static double getFuelNeededForTrip(double tripDistance, double fuelEfficiency, boolean useBuffer)
          Gets the amount of fuel (kg) needed for a trip of a given distance (km).
 MarsClock getLegETA()
          Gets the estimated time of arrival (ETA) for the current leg of the mission.
protected abstract  OperateVehicle getOperateVehicleTask(Person person, java.lang.String lastOperateVehicleTaskPhase)
          Gets a new instance of an OperateVehicle task for the person.
protected  java.util.Map<Resource,java.lang.Number> getPartsNeededForTrip(double distance)
          Gets the parts needed for the trip.
 java.util.Map<Resource,java.lang.Number> getResourcesNeededForRemainingMission(boolean useBuffer, boolean parts)
          Gets the number and amounts of resources needed for the mission.
 java.util.Map<Resource,java.lang.Number> getResourcesNeededForTrip(boolean useBuffer, boolean parts, double distance)
          Gets the number and amounts of resources needed for a trip.
 java.util.Map<Resource,java.lang.Number> getResourcesToLoad()
          Gets the resources needed for loading the vehicle.
 double getTotalDistanceTravelled()
          Gets the total distance travelled during the mission so far.
 Vehicle getVehicle()
          Gets the mission's vehicle if there is one.
protected static boolean hasEmbarkingMissions(Settlement settlement)
          Checks to see if there are any currently embarking missions at the settlement.
protected  boolean hasEnoughResourcesForRemainingMission(boolean useBuffers)
          Checks if there are enough resources available in the vehicle for the remaining mission.
 boolean hasVehicle()
          Checks if the mission has a vehicle.
protected  boolean isUsableVehicle(Vehicle newVehicle)
          Checks if vehicle is usable for this mission.
 boolean isVehicleLoadable()
          Checks if a vehicle can load the supplies needed by the mission.
 boolean isVehicleLoaded()
          Determine if a vehicle is sufficiently loaded with fuel and supplies.
protected  void leaveVehicle()
          Leaves the mission's vehicle and unreserves it.
protected abstract  void performDisembarkToSettlementPhase(Person person, Settlement disembarkSettlement)
          Performs the disembark to settlement phase of the mission.
protected abstract  void performEmbarkFromSettlementPhase(Person person)
          Performs the embark from settlement phase of the mission.
protected  void performPhase(Person person)
          The person performs the current phase of the mission.
protected  void performTravelPhase(Person person)
          Performs the travel phase of the mission.
protected  boolean reserveVehicle(Person person)
          Reserves a vehicle for the mission if possible.
 void setEmergencyBeacon(Person person, Vehicle vehicle, boolean beaconOn)
          Sets the vehicle's emergency beacon on or off.
protected  void setVehicle(Vehicle newVehicle)
          Sets the vehicle for this mission.
 void timePassing(double time)
          Time passing for mission.
 void unitUpdate(UnitEvent event)
          Catch unit update event.
 void updateTravelDestination()
          Update mission to the next navpoint destination.
 
Methods inherited from class org.mars_sim.msp.simulation.person.ai.mission.TravelMission
addNavpoint, clearRemainingNavpoints, getCurrentLegDistance, getCurrentLegRemainingDistance, getCurrentLegStartingTime, getCurrentNavpoint, getCurrentNavpointIndex, getNavpoint, getNavpointIndex, getNextNavpoint, getNextNavpointIndex, getNumberOfNavpoints, getPreviousNavpoint, getTotalDistance, getTotalRemainingDistance, getTravelStatus, reachedNextNode, setNavpoint, setNextNavpointIndex, startTravelToNextNode
 
Methods inherited from class org.mars_sim.msp.simulation.person.ai.mission.Mission
addMissionListener, addPerson, addPhase, assignTask, associateAllMembersWithSettlement, fireMissionUpdate, fireMissionUpdate, getAssociatedSettlement, getCurrentMissionLocation, getDescription, getEquipmentNeededForRemainingMission, getMinPeople, getMissionCapacity, getMissionQualification, getName, getNewMissionProbability, getPeople, getPeopleNumber, getPhase, getPhaseDescription, getPhaseEnded, hasDangerousMedicalProblems, hasDangerousMedicalProblemsAllCrew, hasEmergency, hasEmergencyAllCrew, hasPerson, isCapableOfMission, isDone, performMission, recruitPeopleForMission, removeMissionListener, removePerson, setDescription, setMinPeople, setMissionCapacity, setName, setPhase, setPhaseDescription, setPhaseEnded, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VEHICLE_EVENT

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

OPERATOR_EVENT

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

EMBARKING

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

TRAVELLING

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

DISEMBARKING

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

loadedFlag

protected boolean loadedFlag

equipmentNeededCache

protected java.util.Map<java.lang.Class,java.lang.Integer> equipmentNeededCache
Constructor Detail

VehicleMission

protected VehicleMission(java.lang.String name,
                         Person startingPerson,
                         int minPeople)
                  throws MissionException
Constructor

Parameters:
name - the name of the mission.
startingPerson - the person starting the mission
minPeople - the minimum number of mission members allowed
Throws:
MissionException - if error constructing mission.

VehicleMission

protected VehicleMission(java.lang.String name,
                         Person startingPerson,
                         int minPeople,
                         Vehicle vehicle)
                  throws MissionException
Constructor with vehicle.

Parameters:
name - the name of the mission.
startingPerson - the person starting the mission
minPeople - the minimum number of mission members allowed
vehicle - the vehicle to use on the mission.
Throws:
MissionException - if error constructing mission.
Method Detail

getVehicle

public final Vehicle getVehicle()
Gets the mission's vehicle if there is one.

Returns:
vehicle or null if none.

setVehicle

protected final void setVehicle(Vehicle newVehicle)
                         throws MissionException
Sets the vehicle for this mission.

Parameters:
newVehicle - the vehicle to use.
Throws:
MissionException - if vehicle cannot be used.

hasVehicle

public final boolean hasVehicle()
Checks if the mission has a vehicle.

Returns:
true if vehicle.

leaveVehicle

protected final void leaveVehicle()
Leaves the mission's vehicle and unreserves it.


isUsableVehicle

protected boolean isUsableVehicle(Vehicle newVehicle)
                           throws MissionException
Checks if vehicle is usable for this mission. (This method should be added to by children)

Parameters:
newVehicle - the vehicle to check
Returns:
true if vehicle is usable.
Throws:
java.lang.IllegalArgumentException - if newVehicle is null.
MissionException - if problem checking vehicle is loadable.

compareVehicles

protected int compareVehicles(Vehicle firstVehicle,
                              Vehicle secondVehicle)
                       throws MissionException
Compares the quality of two vehicles for use in this mission. (This method should be added to by children)

Parameters:
firstVehicle - the first vehicle to compare
secondVehicle - the second vehicle to compare
Returns:
-1 if the second vehicle is better than the first vehicle, 0 if vehicle are equal in quality, and 1 if the first vehicle is better than the second vehicle.
Throws:
MissionException - if error determining vehicle range.

reserveVehicle

protected final boolean reserveVehicle(Person person)
                                throws MissionException
Reserves a vehicle for the mission if possible.

Parameters:
person - the person reserving the vehicle.
Returns:
true if vehicle is reserved, false if unable to.
Throws:
MissionException - if error reserving vehicle.

endMission

public void endMission(java.lang.String reason)
Finalizes the mission

Overrides:
endMission in class Mission
Parameters:
reason - the reason of ending the mission.

isVehicleLoaded

public final boolean isVehicleLoaded()
                              throws MissionException
Determine if a vehicle is sufficiently loaded with fuel and supplies.

Returns:
true if rover is loaded.
Throws:
MissionException - if error checking vehicle.

isVehicleLoadable

public final boolean isVehicleLoadable()
                                throws MissionException
Checks if a vehicle can load the supplies needed by the mission.

Returns:
true if vehicle is loadable.
Throws:
java.lang.Exception - if error checking vehicle.
MissionException

getFuelNeededForTrip

public static double getFuelNeededForTrip(double tripDistance,
                                          double fuelEfficiency,
                                          boolean useBuffer)
Gets the amount of fuel (kg) needed for a trip of a given distance (km).

Parameters:
tripDistance - the distance (km) of the trip.
fuelEfficiency - the vehicle's fuel efficiency (km/kg).
useBuffer - use time buffers in estimation if true.
Returns:
amount of fuel needed for trip (kg)

determineNewPhase

protected void determineNewPhase()
                          throws MissionException
Determines a new phase for the mission when the current phase has ended.

Specified by:
determineNewPhase in class Mission
Throws:
MissionException - if problem setting a new phase.

performPhase

protected void performPhase(Person person)
                     throws MissionException
The person performs the current phase of the mission.

Specified by:
performPhase in class Mission
Parameters:
person - the person performing the phase.
Throws:
MissionException - if problem performing the phase.

performTravelPhase

protected final void performTravelPhase(Person person)
                                 throws MissionException
Performs the travel phase of the mission.

Specified by:
performTravelPhase in class TravelMission
Parameters:
person - the person currently performing the mission.
Throws:
MissionException - if error performing phase.

getOperateVehicleTask

protected abstract OperateVehicle getOperateVehicleTask(Person person,
                                                        java.lang.String lastOperateVehicleTaskPhase)
                                                 throws MissionException
Gets a new instance of an OperateVehicle task for the person.

Parameters:
person - the person operating the vehicle.
Returns:
an OperateVehicle task for the person.
Throws:
MissionException - if error creating OperateVehicle task.

performEmbarkFromSettlementPhase

protected abstract void performEmbarkFromSettlementPhase(Person person)
                                                  throws MissionException
Performs the embark from settlement phase of the mission.

Parameters:
person - the person currently performing the mission.
Throws:
MissionException - if error performing phase.

performDisembarkToSettlementPhase

protected abstract void performDisembarkToSettlementPhase(Person person,
                                                          Settlement disembarkSettlement)
                                                   throws MissionException
Performs the disembark to settlement phase of the mission.

Parameters:
person - the person currently performing the mission.
disembarkSettlement - the settlement to be disembarked to.
Throws:
MissionException - if error performing phase.

getLegETA

public final MarsClock getLegETA()
Gets the estimated time of arrival (ETA) for the current leg of the mission.

Specified by:
getLegETA in class TravelMission
Returns:
time (MarsClock) or null if not applicable.

getEstimatedTripTime

public final double getEstimatedTripTime(boolean useBuffer,
                                         double distance)
                                  throws MissionException
Gets the estimated time for a trip.

Specified by:
getEstimatedTripTime in class TravelMission
Parameters:
useBuffer - use time buffers in estimation if true.
distance - the distance of the trip.
Returns:
time (millisols)
Throws:
MissionException

getEstimatedRemainingMissionTime

public double getEstimatedRemainingMissionTime(boolean useBuffer)
                                        throws MissionException
Gets the estimated time remaining for the mission.

Specified by:
getEstimatedRemainingMissionTime in class TravelMission
Parameters:
useBuffer - Use time buffer in estimations if true.
Returns:
time (millisols)
Throws:
MissionException

getAverageVehicleSpeedForOperators

protected final double getAverageVehicleSpeedForOperators()
Gets the average operating speed of the mission vehicle for all of the mission members.

Returns:
average operating speed (km/h)

getResourcesNeededForRemainingMission

public java.util.Map<Resource,java.lang.Number> getResourcesNeededForRemainingMission(boolean useBuffer,
                                                                                      boolean parts)
                                                                               throws MissionException
Gets the number and amounts of resources needed for the mission.

Specified by:
getResourcesNeededForRemainingMission in class Mission
Parameters:
useBuffer - use time buffers in estimation if true.
parts - include parts.
Returns:
map of amount and item resources and their Double amount or Integer number.
Throws:
MissionException - if error determining needed resources.

getResourcesNeededForTrip

public java.util.Map<Resource,java.lang.Number> getResourcesNeededForTrip(boolean useBuffer,
                                                                          boolean parts,
                                                                          double distance)
                                                                   throws MissionException
Gets the number and amounts of resources needed for a trip.

Parameters:
useBuffer - use time buffers in estimation if true.
parts - include parts.
distance - the distance (km) of the trip.
Returns:
map of amount and item resources and their Double amount or Integer number.
Throws:
MissionException - if error determining needed resources.

getPartsNeededForTrip

protected java.util.Map<Resource,java.lang.Number> getPartsNeededForTrip(double distance)
                                                                  throws MissionException
Gets the parts needed for the trip.

Parameters:
distance - the distance of the trip.
Returns:
map of part resources and their number.
Throws:
MissionException - if error determining parts.

hasEnoughResourcesForRemainingMission

protected final boolean hasEnoughResourcesForRemainingMission(boolean useBuffers)
                                                       throws MissionException
Checks if there are enough resources available in the vehicle for the remaining mission.

Parameters:
useBuffers - use time buffers for estimation if true.
Returns:
true if enough resources.
Throws:
MissionException - if error checking resources.

determineEmergencyDestination

protected final void determineEmergencyDestination(Person person)
                                            throws MissionException
Determines the emergency destination settlement for the mission if one is reachable, otherwise sets the emergency beacon and ends the mission.

Parameters:
person - the person performing the mission.
Throws:
MissionException - if error determining an emergency destination.

setEmergencyBeacon

public void setEmergencyBeacon(Person person,
                               Vehicle vehicle,
                               boolean beaconOn)
Sets the vehicle's emergency beacon on or off.

Parameters:
person - the person performing the mission.
vehicle - the vehicle on the mission.
beaconOn - true if beacon is on, false if not.

updateTravelDestination

public void updateTravelDestination()
Update mission to the next navpoint destination.

Specified by:
updateTravelDestination in class TravelMission

findClosestSettlement

public final Settlement findClosestSettlement()
                                       throws MissionException
Finds the closest settlement to the mission.

Returns:
settlement
Throws:
MissionException - if error finding closest settlement.

getTotalDistanceTravelled

public final double getTotalDistanceTravelled()
Gets the total distance travelled during the mission so far.

Specified by:
getTotalDistanceTravelled in class TravelMission
Returns:
distance (km)

timePassing

public void timePassing(double time)
                 throws java.lang.Exception
Time passing for mission.

Overrides:
timePassing in class Mission
Parameters:
time - the amount of time passing (in millisols)
Throws:
java.lang.Exception - if error during time passing.

unitUpdate

public void unitUpdate(UnitEvent event)
Catch unit update event.

Specified by:
unitUpdate in interface UnitListener
Parameters:
event - the unit event.

getResourcesToLoad

public java.util.Map<Resource,java.lang.Number> getResourcesToLoad()
                                                            throws MissionException
Gets the resources needed for loading the vehicle.

Returns:
resources and their number.
Throws:
MissionException - if error determining resources.

getEquipmentToLoad

public java.util.Map<java.lang.Class,java.lang.Integer> getEquipmentToLoad()
                                                                    throws MissionException
Gets the equipment needed for loading the vehicle.

Returns:
equipment and their number.
Throws:
MissionException - if error determining equipment.

hasEmbarkingMissions

protected static boolean hasEmbarkingMissions(Settlement settlement)
Checks to see if there are any currently embarking missions at the settlement.

Parameters:
settlement - the settlement.
Returns:
true if embarking missions.