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

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
              extended by org.mars_sim.msp.simulation.person.ai.mission.RoverMission
                  extended by org.mars_sim.msp.simulation.person.ai.mission.Trade
All Implemented Interfaces:
java.io.Serializable, UnitListener

public class Trade
extends RoverMission
implements java.io.Serializable

A mission for trading between two settlements.

See Also:
Serialized Form

Field Summary
static java.lang.String BUY_LOAD_EVENT
           
static java.lang.String DEFAULT_DESCRIPTION
           
static java.lang.String LOAD_GOODS
           
static java.lang.String TRADE_DISEMBARKING
           
static java.lang.String TRADE_EMBARKING
           
static java.lang.String TRADE_NEGOTIATING
           
static java.lang.String UNLOAD_GOODS
           
 
Fields inherited from class org.mars_sim.msp.simulation.person.ai.mission.RoverMission
MIN_PEOPLE, STARTING_SETTLEMENT_EVENT
 
Fields inherited from class org.mars_sim.msp.simulation.person.ai.mission.VehicleMission
DISEMBARKING, EMBARKING, equipmentNeededCache, loadedFlag, OPERATOR_EVENT, TRAVELLING, 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
Trade(java.util.Collection<Person> members, Settlement startingSettlement, Settlement tradingSettlement, Rover rover, java.lang.String description, java.util.Map<Good,java.lang.Integer> sellGoods, java.util.Map<Good,java.lang.Integer> buyGoods)
          Constructor with explicit data.
Trade(Person startingPerson)
          Constructor.
 
Method Summary
protected  int compareVehicles(Vehicle firstVehicle, Vehicle secondVehicle)
          Compares the quality of two vehicles for use in this mission.
protected  void determineNewPhase()
          Determines a new phase for the mission when the current phase has ended.
 Settlement getAssociatedSettlement()
          Gets the settlement associated with the mission.
 java.util.Map<Good,java.lang.Integer> getBuyLoad()
          Gets the load that is being bought in the trade.
 java.util.Map<Good,java.lang.Integer> getDesiredBuyLoad()
          Gets the load that the starting settlement initially desires to buy.
 double getDesiredProfit()
          Gets the profit initially expected by the starting settlement.
 java.util.Map<java.lang.Class,java.lang.Integer> getEquipmentNeededForRemainingMission(boolean useBuffer)
          Gets the number and types of equipment needed for the mission.
static double getNewMissionProbability(Person person)
          Gets the weighted probability that a given person would start this mission.
 double getProfit()
          Gets the profit for the settlement initiating the trade.
 java.util.Map<Resource,java.lang.Number> getResourcesNeededForTrip(boolean useBuffer, boolean parts, double distance)
          Gets a map of all resources needed for the trip.
 java.util.Map<Good,java.lang.Integer> getSellLoad()
          Gets the load that is being sold in the trade.
 Settlement getTradingSettlement()
          Gets the settlement that the starting settlement is trading with.
protected  boolean isCapableOfMission(Person person)
          Checks to see if a person is capable of joining a mission.
protected  void performDisembarkToSettlementPhase(Person person, Settlement disembarkSettlement)
          Performs the disembark to settlement phase of the mission.
protected  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 recruitPeopleForMission(Person startingPerson)
          Recruits new people into the mission.
 
Methods inherited from class org.mars_sim.msp.simulation.person.ai.mission.RoverMission
areVehiclesAvailable, atLeastOnePersonRemainingAtSettlement, endMission, getOperateVehicleTask, getRover, getStartingSettlement, getVehicleWithGreatestRange, hasDangerousMedicalProblemAtAssociatedSettlement, hasEmergency, isEveryoneInRover, isNoOneInRover, isRoverInAGarage, isUsableVehicle, minAvailablePeopleAtSettlement, setStartingSettlement
 
Methods inherited from class org.mars_sim.msp.simulation.person.ai.mission.VehicleMission
determineEmergencyDestination, findClosestSettlement, getAverageVehicleSpeedForOperators, getEquipmentToLoad, getEstimatedRemainingMissionTime, getEstimatedTripTime, getFuelNeededForTrip, getLegETA, getPartsNeededForTrip, getResourcesNeededForRemainingMission, getResourcesToLoad, getTotalDistanceTravelled, getVehicle, hasEmbarkingMissions, hasEnoughResourcesForRemainingMission, hasVehicle, isVehicleLoadable, isVehicleLoaded, leaveVehicle, performTravelPhase, reserveVehicle, setEmergencyBeacon, setVehicle, timePassing, unitUpdate, updateTravelDestination
 
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, getCurrentMissionLocation, getDescription, getMinPeople, getMissionCapacity, getMissionQualification, getName, getPeople, getPeopleNumber, getPhase, getPhaseDescription, getPhaseEnded, hasDangerousMedicalProblems, hasDangerousMedicalProblemsAllCrew, hasEmergencyAllCrew, hasPerson, isDone, performMission, 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

BUY_LOAD_EVENT

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

DEFAULT_DESCRIPTION

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

TRADE_DISEMBARKING

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

TRADE_NEGOTIATING

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

UNLOAD_GOODS

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

LOAD_GOODS

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

TRADE_EMBARKING

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

Trade

public Trade(Person startingPerson)
      throws MissionException
Constructor.

Parameters:
startingPerson - the person starting the settlement.
Throws:
MissionException - if error constructing mission.

Trade

public Trade(java.util.Collection<Person> members,
             Settlement startingSettlement,
             Settlement tradingSettlement,
             Rover rover,
             java.lang.String description,
             java.util.Map<Good,java.lang.Integer> sellGoods,
             java.util.Map<Good,java.lang.Integer> buyGoods)
      throws MissionException
Constructor with explicit data.

Parameters:
members - collection of mission members.
startingSettlement - the starting settlement.
tradingSettlement - the trading settlement.
rover - the rover to use.
description - the mission's description.
sellGoods - map of mission sell goods and integer amounts.
buyGoods - map of mission buy goods and integer amounts
Throws:
MissionException - if error constructing mission.
Method Detail

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

determineNewPhase

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

Overrides:
determineNewPhase in class VehicleMission
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.

Overrides:
performPhase in class RoverMission
Parameters:
person - the person performing the phase.
Throws:
MissionException - if problem performing the phase.

performEmbarkFromSettlementPhase

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

Overrides:
performEmbarkFromSettlementPhase in class RoverMission
Parameters:
person - the person currently performing the mission
Throws:
MissionException - if error performing phase.

performDisembarkToSettlementPhase

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

Overrides:
performDisembarkToSettlementPhase in class RoverMission
Parameters:
person - the person currently performing the mission.
disembarkSettlement - the settlement to be disembarked to.
Throws:
MissionException - if error performing phase.

getEquipmentNeededForRemainingMission

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

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

getResourcesNeededForTrip

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

Overrides:
getResourcesNeededForTrip in class RoverMission
Parameters:
useBuffer - should a buffer be used when determining resources?
parts - include parts.
distance - the distance of the trip.
Returns:
map of amount and item resources and their Double amount or Integer number.
Throws:
MissionException - if error determining resources.

getAssociatedSettlement

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

Specified by:
getAssociatedSettlement in class Mission
Returns:
settlement or null if none.

isCapableOfMission

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

Overrides:
isCapableOfMission in class Mission
Parameters:
person - the person to check.
Returns:
true if person could join mission.

recruitPeopleForMission

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

Overrides:
recruitPeopleForMission in class Mission
Parameters:
startingPerson - the person starting the mission.

compareVehicles

protected int compareVehicles(Vehicle firstVehicle,
                              Vehicle secondVehicle)
                       throws MissionException
Compares the quality of two vehicles for use in this mission.

Overrides:
compareVehicles in class VehicleMission
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:
java.lang.IllegalArgumentException - if firstVehicle or secondVehicle is null.
MissionException - if error comparing vehicles.

getSellLoad

public java.util.Map<Good,java.lang.Integer> getSellLoad()
Gets the load that is being sold in the trade.

Returns:
sell load.

getBuyLoad

public java.util.Map<Good,java.lang.Integer> getBuyLoad()
Gets the load that is being bought in the trade.

Returns:
buy load.

getProfit

public double getProfit()
Gets the profit for the settlement initiating the trade.

Returns:
profit (VP).

getDesiredBuyLoad

public java.util.Map<Good,java.lang.Integer> getDesiredBuyLoad()
Gets the load that the starting settlement initially desires to buy.

Returns:
desired buy load.

getDesiredProfit

public double getDesiredProfit()
Gets the profit initially expected by the starting settlement.

Returns:
desired profit (VP).

getTradingSettlement

public Settlement getTradingSettlement()
Gets the settlement that the starting settlement is trading with.

Returns:
trading settlement.