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

java.lang.Object
  extended by org.mars_sim.msp.simulation.person.ai.task.Task
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
CookMeal, EnterAirlock, EVAOperation, ExitAirlock, LoadVehicle, MaintainGroundVehicleGarage, Maintenance, ManufactureGood, MedicalAssistance, NegotiateTrade, OperateVehicle, RepairEmergencyMalfunction, RepairMalfunction, ResearchScience, Teach, TendGreenhouse, UnloadVehicle, Workout

public abstract class Task
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

The Task class is an abstract parent class for tasks that allow people to do various things. A person's TaskManager keeps track of one current task for the person, but a task may use other tasks internally to accomplish things.

See Also:
Serialized Form

Field Summary
protected  boolean effortDriven
           
protected  boolean hasDuration
           
protected  Person person
           
protected  double phaseTimeCompleted
           
protected  double phaseTimeRequired
           
protected  double stressModifier
           
protected  Task subTask
           
static java.lang.String TASK_DESC_EVENT
           
static java.lang.String TASK_ENDED_EVENT
           
static java.lang.String TASK_NAME_EVENT
           
static java.lang.String TASK_PHASE_EVENT
           
static java.lang.String TASK_SUBTASK_EVENT
           
 
Constructor Summary
Task(java.lang.String name, Person person, boolean effort, boolean createEvents, double stressModifier, boolean hasDuration, double duration)
          Constructs a Task object.
 
Method Summary
protected abstract  void addExperience(double time)
          Adds experience to the person's skills used in this task.
protected  void addPhase(java.lang.String newPhase)
          Adds a phase to the task's collection of phases.
 int compareTo(java.lang.Object other)
          Compare this object to another for an ordering.
 void endTask()
          Ends the task and performs any final actions.
abstract  java.util.List<java.lang.String> getAssociatedSkills()
          Gets a list of the skills associated with this task.
 boolean getCreateEvents()
          Returns a boolean whether this task should generate events
protected static double getCrowdingProbabilityModifier(Person person, Building newBuilding)
          Gets the probability modifier for a task if person needs to go to a new building.
 java.lang.String getDescription()
          Returns a string that is a description of what the task is currently doing.
protected  double getDuration()
          Gets the duration of the task or 0 if none.
abstract  int getEffectiveSkillLevel()
          Gets the effective skill level a person has at this task.
 java.lang.String getName()
          Returns the name of the task.
 java.lang.String getPhase()
          Gets a string of the current phase of the task.
static double getProbability(Person person)
          Returns the weighted probability that a person might perform this task.
protected static double getRelationshipModifier(Person person, Building building)
          Gets the probability modifier for a person performing a task based on his/her relationships with the people in the room the task is to be performed in.
 Task getSubTask()
          Gets the task's subtask.
 Person getTeacher()
          Gets the person teaching this task.
protected  double getTeachingExperienceModifier()
          Gets the experience modifier when being taught by a teacher.
protected  double getTimeCompleted()
          Gets the amount of time the task has completed.
 java.lang.String getTopPhase()
          Gets a string of the current phase of this task, ignoring subtasks.
 boolean hasTeacher()
          Checks if someone is teaching this task to the person performing it.
 boolean isDone()
          Determines if task is still active.
 boolean isEffortDriven()
          Return the value of the effort driven flag.
protected abstract  double performMappedPhase(double time)
          Performs the method mapped to the task's current phase.
protected  void setCreateEvents(boolean create)
          SHould the start of this task create an historical event.
protected  void setDescription(java.lang.String description)
          Sets the task's description.
protected  void setDuration(double newDuration)
          Sets the duration of the task
protected  void setName(java.lang.String name)
          Sets the task's name.
protected  void setPhase(java.lang.String newPhase)
          Sets the task's current phase.
protected  void setStressModifier(double newStressModifier)
          Set the task's stress modifier.
 void setTeacher(Person newTeacher)
          Sets the person teaching this task.
 java.lang.String toString()
          Get a string representation of this Task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TASK_NAME_EVENT

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

TASK_DESC_EVENT

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

TASK_PHASE_EVENT

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

TASK_ENDED_EVENT

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

TASK_SUBTASK_EVENT

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

person

protected Person person

hasDuration

protected boolean hasDuration

subTask

protected Task subTask

phaseTimeRequired

protected double phaseTimeRequired

phaseTimeCompleted

protected double phaseTimeCompleted

effortDriven

protected boolean effortDriven

stressModifier

protected double stressModifier
Constructor Detail

Task

public Task(java.lang.String name,
            Person person,
            boolean effort,
            boolean createEvents,
            double stressModifier,
            boolean hasDuration,
            double duration)
     throws java.lang.Exception
Constructs a Task object.

Parameters:
name - the name of the task
person - the person performing the task
effort - Does this task require physical effort
createEvents - Does this task create events?
stressModifier - stress modified by person performing task per millisol.
hasDuration - Does the task have a time duration?
duration - the time duration (in millisols) of the task (or 0 if none)
Throws:
java.lang.Exception - if task could not be constructed.
Method Detail

endTask

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


isEffortDriven

public boolean isEffortDriven()
Return the value of the effort driven flag.

Returns:
Effort driven.

getName

public java.lang.String getName()
Returns the name of the task.

Returns:
the task's name

setName

protected void setName(java.lang.String name)
Sets the task's name.

Parameters:
name - the task name.

getDescription

public java.lang.String getDescription()
Returns a string that is a description of what the task is currently doing. This is mainly for user interface purposes. Derived tasks should extend this if necessary. Defaults to just the name of the task.

Returns:
the description of what the task is currently doing

setDescription

protected void setDescription(java.lang.String description)
Sets the task's description.

Parameters:
description - the task description.

getCreateEvents

public boolean getCreateEvents()
Returns a boolean whether this task should generate events

Returns:
boolean flag.

getPhase

public java.lang.String getPhase()
Gets a string of the current phase of the task.

Returns:
the current phase of the task

getTopPhase

public java.lang.String getTopPhase()
Gets a string of the current phase of this task, ignoring subtasks.

Returns:
the current phase of this task.

setPhase

protected void setPhase(java.lang.String newPhase)
                 throws java.lang.Exception
Sets the task's current phase.

Parameters:
newPhase - the phase to set the a task at.
Throws:
java.lang.Exception - if newPhase is not in the task's collection of phases.

addPhase

protected void addPhase(java.lang.String newPhase)
Adds a phase to the task's collection of phases.

Parameters:
newPhase - the new phase to add.

isDone

public boolean isDone()
Determines if task is still active.

Returns:
true if task is completed

getSubTask

public Task getSubTask()
Gets the task's subtask. Returns null if none

Returns:
subtask

getProbability

public static double getProbability(Person person)
Returns the weighted probability that a person might perform this task. It should return a 0 if there is no chance to perform this task given the person and the situation.

Parameters:
person - the person to perform the task
Returns:
the weighted probability that a person might perform this task

performMappedPhase

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

Parameters:
time - the amount of time (millisol) the phase is to be performed.
Returns:
the remaining time (millisol) after the phase has been performed.
Throws:
java.lang.Exception - if error in performing phase or if phase cannot be found.

setCreateEvents

protected void setCreateEvents(boolean create)
SHould the start of this task create an historical event.

Parameters:
create - New flag value.

toString

public java.lang.String toString()
Get a string representation of this Task. It's content will consist of the description.

Overrides:
toString in class java.lang.Object
Returns:
Description of the task.

compareTo

public int compareTo(java.lang.Object other)
Compare this object to another for an ordering. THe ordering is based on the alphabetic ordering of the Name attribute.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - Object to compare against.
Returns:
integer comparasion of the two objects.
Throws:
java.lang.ClassCastException - if the object in not of a Task.

setStressModifier

protected void setStressModifier(double newStressModifier)
Set the task's stress modifier. Stress modifier can be positive (increase in stress) or negative (decrease in stress).

Parameters:
newStressModifier - stress modification per millisol.

getCrowdingProbabilityModifier

protected static double getCrowdingProbabilityModifier(Person person,
                                                       Building newBuilding)
                                                throws BuildingException
Gets the probability modifier for a task if person needs to go to a new building.

Parameters:
person - the person to perform the task.
newBuilding - the building the person is to go to.
Returns:
probability modifier
Throws:
BuildingException - if current or new building doesn't have life support function.

getEffectiveSkillLevel

public abstract int getEffectiveSkillLevel()
Gets the effective skill level a person has at this task.

Returns:
effective skill level

getAssociatedSkills

public abstract java.util.List<java.lang.String> getAssociatedSkills()
Gets a list of the skills associated with this task. May be empty list if no associated skills.

Returns:
list of skills as strings

hasTeacher

public boolean hasTeacher()
Checks if someone is teaching this task to the person performing it.

Returns:
true if teacher.

getTeacher

public Person getTeacher()
Gets the person teaching this task.

Returns:
teacher or null if none.

setTeacher

public void setTeacher(Person newTeacher)
Sets the person teaching this task.

Parameters:
newTeacher - the new teacher.

getTeachingExperienceModifier

protected double getTeachingExperienceModifier()
Gets the experience modifier when being taught by a teacher.

Returns:
modifier;

getRelationshipModifier

protected static double getRelationshipModifier(Person person,
                                                Building building)
                                         throws BuildingException
Gets the probability modifier for a person performing a task based on his/her relationships with the people in the room the task is to be performed in.

Parameters:
person - the person to check for.
building - the building the person will need to be in for the task.
Returns:
probability modifier
Throws:
BuildingException

addExperience

protected abstract void addExperience(double time)
Adds experience to the person's skills used in this task.

Parameters:
time - the amount of time (ms) the person performed this task.

getDuration

protected double getDuration()
Gets the duration of the task or 0 if none.

Returns:
duration (millisol)

setDuration

protected void setDuration(double newDuration)
Sets the duration of the task

Parameters:
newDuration - the new duration (millisol)

getTimeCompleted

protected double getTimeCompleted()
Gets the amount of time the task has completed.

Returns:
time (in millisols)