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

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

public abstract class Mission
extends java.lang.Object
implements java.io.Serializable

The Mission class represents a large multi-person task There is at most one instance of a mission per person. A Mission may have one or more people associated with it.

See Also:
Serialized Form

Field Summary
static java.lang.String ADD_MEMBER_EVENT
           
static java.lang.String ASSOCIATED_SETTLEMENT_EVENT
           
static java.lang.String CAPACITY_EVENT
           
static java.lang.String DESCRIPTION_EVENT
           
static java.lang.String END_MISSION_EVENT
           
static java.lang.String MIN_PEOPLE_EVENT
           
static java.lang.String NAME_EVENT
           
static java.lang.String PHASE_DESCRIPTION_EVENT
           
static java.lang.String PHASE_EVENT
           
static java.lang.String REMOVE_MEMBER_EVENT
           
 
Constructor Summary
Mission(java.lang.String name, Person startingPerson, int minPeople)
          Constructs a Mission object
 
Method Summary
 void addMissionListener(MissionListener newListener)
          Adds a listener
 void addPerson(Person person)
          Adds a person to the mission.
 void addPhase(java.lang.String newPhase)
          Adds a phase to the mission's collection of phases.
protected  void assignTask(Person person, Task task)
          Adds a new task for a person in the mission.
 void associateAllMembersWithSettlement(Settlement settlement)
          Associate all mission members with a settlement.
protected abstract  void determineNewPhase()
          Determines a new phase for the mission when the current phase has ended.
 void endMission(java.lang.String reason)
          Finalizes the mission.
protected  void fireMissionUpdate(java.lang.String updateType)
          Fire a mission update event.
protected  void fireMissionUpdate(java.lang.String updateType, java.lang.Object target)
          Fire a mission update event.
abstract  Settlement getAssociatedSettlement()
          Gets the settlement associated with the mission.
 Coordinates getCurrentMissionLocation()
          Gets the current location of the mission.
 java.lang.String getDescription()
          Gets the mission's description.
abstract  java.util.Map<java.lang.Class,java.lang.Integer> getEquipmentNeededForRemainingMission(boolean useBuffer)
          Gets the number and types of equipment needed for the mission.
 int getMinPeople()
          Gets the minimum number of people required for mission.
 int getMissionCapacity()
          Gets the mission capacity for participating people.
protected  double getMissionQualification(Person person)
          Gets the mission qualification value for the person.
 java.lang.String getName()
          Gets the name of the mission.
static double getNewMissionProbability(Person person)
          Gets the weighted probability that a given person would start this mission.
 java.util.Collection<Person> getPeople()
          Gets a collection of the people in the mission.
 int getPeopleNumber()
          Gets the number of people in the mission.
 java.lang.String getPhase()
          Gets the current phase of the mission.
 java.lang.String getPhaseDescription()
          Gets the description of the current phase.
protected  boolean getPhaseEnded()
          Checks if the current phase has ended or not.
abstract  java.util.Map<Resource,java.lang.Number> getResourcesNeededForRemainingMission(boolean useBuffer, boolean parts)
          Gets the number and amounts of resources needed for the mission.
protected  boolean hasDangerousMedicalProblems()
          Checks to see if any of the people in the mission have any dangerous medical problems that require treatment at a settlement.
protected  boolean hasDangerousMedicalProblemsAllCrew()
          Checks to see if all of the people in the mission have any dangerous medical problems that require treatment at a settlement.
protected  boolean hasEmergency()
          Checks if the mission has an emergency situation.
protected  boolean hasEmergencyAllCrew()
          Checks if the mission has an emergency situation affecting all the crew.
 boolean hasPerson(Person person)
          Determines if a mission includes the given person
protected  boolean isCapableOfMission(Person person)
          Checks to see if a person is capable of joining a mission.
 boolean isDone()
          Determines if mission is completed.
 void performMission(Person person)
          Performs the mission.
protected abstract  void performPhase(Person person)
          The person performs the current phase of the mission.
protected  void recruitPeopleForMission(Person startingPerson)
          Recruits new people into the mission.
 void removeMissionListener(MissionListener oldListener)
          Removes a listener
 void removePerson(Person person)
          Removes a person from the mission
 void setDescription(java.lang.String description)
          Sets the mission's description.
protected  void setMinPeople(int minPeople)
          Sets the minimum number of people required for a mission.
protected  void setMissionCapacity(int newCapacity)
          Sets the mission capacity to a given value.
protected  void setName(java.lang.String name)
          Sets the name of the mission.
protected  void setPhase(java.lang.String newPhase)
          Sets the mission phase.
protected  void setPhaseDescription(java.lang.String description)
          Sets the description of the current phase.
protected  void setPhaseEnded(boolean phaseEnded)
          Sets if the current phase has ended or not.
 void timePassing(double time)
          Time passing for mission.
 java.lang.String toString()
          Gets the string representation of this mission.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_EVENT

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

DESCRIPTION_EVENT

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

PHASE_EVENT

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

PHASE_DESCRIPTION_EVENT

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

MIN_PEOPLE_EVENT

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

ASSOCIATED_SETTLEMENT_EVENT

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

CAPACITY_EVENT

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

ADD_MEMBER_EVENT

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

REMOVE_MEMBER_EVENT

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

END_MISSION_EVENT

public static final java.lang.String END_MISSION_EVENT
See Also:
Constant Field Values
Constructor Detail

Mission

public Mission(java.lang.String name,
               Person startingPerson,
               int minPeople)
        throws MissionException
Constructs a Mission object

Parameters:
name - the name of the mission
startingPerson - the person starting the mission.
minPeople - the minimum number of people required for mission.
Throws:
MissionException - if error constructing mission.
Method Detail

addMissionListener

public final void addMissionListener(MissionListener newListener)
Adds a listener

Parameters:
newListener - the listener to add.

removeMissionListener

public final void removeMissionListener(MissionListener oldListener)
Removes a listener

Parameters:
oldListener - the listener to remove.

fireMissionUpdate

protected final void fireMissionUpdate(java.lang.String updateType)
Fire a mission update event.

Parameters:
updateType - the update type.

fireMissionUpdate

protected final void fireMissionUpdate(java.lang.String updateType,
                                       java.lang.Object target)
Fire a mission update event.

Parameters:
updateType - the update type.
target - the event target or null if none.

toString

public java.lang.String toString()
Gets the string representation of this mission.

Overrides:
toString in class java.lang.Object

addPerson

public final void addPerson(Person person)
Adds a person to the mission.

Parameters:
person - to be added

removePerson

public final void removePerson(Person person)
Removes a person from the mission

Parameters:
person - to be removed

hasPerson

public final boolean hasPerson(Person person)
Determines if a mission includes the given person

Parameters:
person - person to be checked
Returns:
true if person is member of mission

getPeopleNumber

public final int getPeopleNumber()
Gets the number of people in the mission.

Returns:
number of people

getMinPeople

public final int getMinPeople()
Gets the minimum number of people required for mission.

Returns:
minimum number of people

setMinPeople

protected final void setMinPeople(int minPeople)
Sets the minimum number of people required for a mission.

Parameters:
minPeople - minimum number of people

getPeople

public final java.util.Collection<Person> getPeople()
Gets a collection of the people in the mission.

Returns:
collection of people

isDone

public final boolean isDone()
Determines if mission is completed.

Returns:
true if mission is completed

getName

public final java.lang.String getName()
Gets the name of the mission.

Returns:
name of mission

setName

protected final void setName(java.lang.String name)
Sets the name of the mission.

Parameters:
name - the new mission name

getDescription

public final java.lang.String getDescription()
Gets the mission's description.

Returns:
mission description

setDescription

public final void setDescription(java.lang.String description)
Sets the mission's description.

Parameters:
description - the new description.

getPhase

public final java.lang.String getPhase()
Gets the current phase of the mission.

Returns:
phase

setPhase

protected final void setPhase(java.lang.String newPhase)
                       throws MissionException
Sets the mission phase.

Parameters:
newPhase - the new mission phase.
Throws:
MissionException - if newPhase is not in the mission's collection of phases.

addPhase

public final void addPhase(java.lang.String newPhase)
Adds a phase to the mission's collection of phases.

Parameters:
newPhase - the new phase to add.

getPhaseDescription

public final java.lang.String getPhaseDescription()
Gets the description of the current phase.

Returns:
phase description.

setPhaseDescription

protected final void setPhaseDescription(java.lang.String description)
Sets the description of the current phase.

Parameters:
description - the phase description.

performMission

public void performMission(Person person)
                    throws MissionException
Performs the mission.

Parameters:
person - the person performing the mission.
Throws:
MissionException - if problem performing the mission.

determineNewPhase

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

Throws:
MissionException - if problem setting a new phase.

performPhase

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

Parameters:
person - the person performing the phase.
Throws:
MissionException - if problem performing the phase.

getNewMissionProbability

public static double getNewMissionProbability(Person person)
Gets the weighted probability that a given person would start this mission.

Parameters:
person - the given person
Returns:
the weighted probability

getMissionCapacity

public final int getMissionCapacity()
Gets the mission capacity for participating people.

Returns:
mission capacity

setMissionCapacity

protected final void setMissionCapacity(int newCapacity)
Sets the mission capacity to a given value.

Parameters:
newCapacity - the new mission capacity

endMission

public void endMission(java.lang.String reason)
Finalizes the mission. String reason Reason for ending mission. Mission can override this to perform necessary finalizing operations.


assignTask

protected void assignTask(Person person,
                          Task task)
Adds a new task for a person in the mission. Task may be not assigned if it is effort-driven and person is too ill to perform it.

Parameters:
person - the person to assign to the task
task - the new task to be assigned

hasDangerousMedicalProblems

protected final boolean hasDangerousMedicalProblems()
Checks to see if any of the people in the mission have any dangerous medical problems that require treatment at a settlement. Also any environmental problems, such as suffocation.

Returns:
true if dangerous medical problems

hasDangerousMedicalProblemsAllCrew

protected final boolean hasDangerousMedicalProblemsAllCrew()
Checks to see if all of the people in the mission have any dangerous medical problems that require treatment at a settlement. Also any environmental problems, such as suffocation.

Returns:
true if all have dangerous medical problems

hasEmergency

protected boolean hasEmergency()
Checks if the mission has an emergency situation.

Returns:
true if emergency.

hasEmergencyAllCrew

protected boolean hasEmergencyAllCrew()
Checks if the mission has an emergency situation affecting all the crew.

Returns:
true if emergency affecting all.

recruitPeopleForMission

protected void recruitPeopleForMission(Person startingPerson)
Recruits new people into the mission.

Parameters:
startingPerson - the person starting the mission.

isCapableOfMission

protected boolean isCapableOfMission(Person person)
Checks to see if a person is capable of joining a mission.

Parameters:
person - the person to check.
Returns:
true if person could join mission.

getMissionQualification

protected double getMissionQualification(Person person)
                                  throws MissionException
Gets the mission qualification value for the person. Person is qualified and interested in joining the mission if the value is larger than 0. The larger the qualification value, the more likely the person will be picked for the mission.

Parameters:
person - the person to check.
Returns:
mission qualification value.
Throws:
MissionException - if error determining mission qualification.

getPhaseEnded

protected final boolean getPhaseEnded()
Checks if the current phase has ended or not.

Returns:
true if phase has ended

setPhaseEnded

protected final void setPhaseEnded(boolean phaseEnded)
Sets if the current phase has ended or not.

Parameters:
phaseEnded - true if phase has ended

getAssociatedSettlement

public abstract Settlement getAssociatedSettlement()
Gets the settlement associated with the mission.

Returns:
settlement or null if none.

getResourcesNeededForRemainingMission

public abstract 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.

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.

getEquipmentNeededForRemainingMission

public abstract java.util.Map<java.lang.Class,java.lang.Integer> getEquipmentNeededForRemainingMission(boolean useBuffer)
                                                                                                throws MissionException
Gets the number and types of equipment needed for the mission.

Parameters:
useBuffer - use time buffers in estimation if true.
Returns:
map of equipment class and Integer number.
Throws:
MissionException - if error determining needed equipment.

timePassing

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

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

associateAllMembersWithSettlement

public void associateAllMembersWithSettlement(Settlement settlement)
Associate all mission members with a settlement.

Parameters:
settlement - the associated settlement.

getCurrentMissionLocation

public final Coordinates getCurrentMissionLocation()
                                            throws MissionException
Gets the current location of the mission.

Returns:
coordinate location.
Throws:
MissionException - if error determining location.