Class Crew

java.lang.Object
megamek.common.Crew
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
LAMPilot

public class Crew extends Object implements Serializable
Health status, skills, and miscellanea for an Entity crew. While vehicle and vessel crews are treated as a single collective, with one set of skills, some multi-crew cockpits (Tripod, QuadVee, dual, command console) require tracking the health and skills of each crew member independently. These are referred to as "slots" and the slot number corresponds to an array index for the appropriate field.
See Also:
  • Field Details

  • Constructor Details

    • Crew

      public Crew(CrewType crewType)
      Creates a nameless P5/G4 crew of the given size.
      Parameters:
      crewType - the crew type to use.
    • Crew

      public Crew(CrewType crewType, String name, int size, int gunnery, int piloting, Gender gender, boolean clanPilot, Map<Integer,Map<String,String>> extraData)
      Parameters:
      crewType - the type of crew
      name - the name of the crew or commander.
      size - the crew size.
      gunnery - the crew's Gunnery skill.
      piloting - the crew's Piloting or Driving skill.
      gender - the gender of the crew or commander
      clanPilot - if the crew or commander is a clanPilot
      extraData - any extra data passed to be stored with this Crew.
    • Crew

      public Crew(CrewType crewType, String name, int size, int gunneryL, int gunneryM, int gunneryB, int piloting, Gender gender, boolean clanPilot, Map<Integer,Map<String,String>> extraData)
      Parameters:
      crewType - the type of crew.
      name - the name of the crew or commander.
      size - the crew size.
      gunneryL - the crew's "laser" Gunnery skill.
      gunneryM - the crew's "missile" Gunnery skill.
      gunneryB - the crew's "ballistic" Gunnery skill.
      piloting - the crew's Piloting or Driving skill.
      gender - the gender of the crew or commander
      clanPilot - if the crew or commander is a clanPilot
      extraData - any extra data passed to be stored with this Crew.
  • Method Details

    • getNames

      public String[] getNames()
    • getName

      public String getName()
    • getName

      public String getName(int pos)
    • setName

      public void setName(String name, int pos)
    • getNicknames

      public String[] getNicknames()
    • getNickname

      public String getNickname()
    • getNickname

      public String getNickname(int pos)
    • setNickname

      public void setNickname(String nickname, int pos)
    • getGenders

      public Gender[] getGenders()
    • getGender

      public Gender getGender()
    • getGender

      public Gender getGender(int pos)
    • setGender

      public void setGender(Gender gender, int pos)
    • getClanPilots

      public boolean[] getClanPilots()
    • isClanPilot

      public boolean isClanPilot()
    • isClanPilot

      public boolean isClanPilot(int position)
    • setClanPilot

      public void setClanPilot(boolean clanPilot, int position)
    • getPortraits

      public Portrait[] getPortraits()
    • getPortrait

      public Portrait getPortrait(int pos)
    • setPortrait

      public void setPortrait(Portrait portrait, int pos)
    • getNameAndRole

      public String getNameAndRole(int pos)
      Parameters:
      pos - The slot index for multi-crewed cockpits
      Returns:
      For multi-slot crews, the crew member's name followed by the role. For-slot crews, the crew name only.
    • getSize

      public int getSize()
      The size of this crew.
      Returns:
      the number of crew members.
    • getCurrentSize

      public int getCurrentSize()
      The current size of this crew.
      Returns:
      the current number of crew members.
    • getCrewType

      public CrewType getCrewType()
    • getSlotCount

      public int getSlotCount()
      Returns:
      The number of crew members that are tracked individually
    • getGunnery

      public int getGunnery()
    • getGunnery

      public int getGunnery(int pos)
    • getGunneryL

      public int getGunneryL()
    • getGunneryL

      public int getGunneryL(int pos)
    • getGunneryM

      public int getGunneryM()
    • getGunneryM

      public int getGunneryM(int pos)
    • getGunneryB

      public int getGunneryB()
    • getGunneryB

      public int getGunneryB(int pos)
    • getArtillery

      public int getArtillery()
    • getArtillery

      public int getArtillery(int pos)
    • getPiloting

      public int getPiloting()
    • getPiloting

      public int getPiloting(int pos)
    • getPiloting

      public int getPiloting(EntityMovementType moveType)
      LAMs use a different skill in AirMEK mode depending on whether they are grounded or airborne.
    • getSkillsAsString

      public String getSkillsAsString(boolean rpgSkills)
      Returns:
      a String showing the overall skills in the format gunnery/piloting
    • getSkillsAsString

      public String getSkillsAsString(boolean showPiloting, boolean rpgSkills)
      Parameters:
      showPiloting - if false, only the gunnery skill is shown (used for ProtoMeks; may be ignored for other unit types)
      Returns:
      a String showing the overall skills in the format gunnery/piloting
    • getSkillsAsString

      public String getSkillsAsString(int pos, boolean rpgSkills)
      Returns:
      a String showing the skills for a particular slot in the format gunnery/piloting
    • getSkillsAsString

      public String getSkillsAsString(int pos, boolean showPiloting, boolean rpgSkills)
      Parameters:
      showPiloting - if false, only the gunnery skill is shown (used for ProtoMeks; may be ignored for other unit types)
      Returns:
      a String showing the skills for a particular slot in the format gunnery/piloting
    • getHits

      public int getHits()
      Used to determine whether the death threshold has been passed. As the crew is not dead until each crew member slot is dead, we return the lowest value.
      Returns:
      The damage level of the least damaged crew member.
    • calculateHits

      public int calculateHits()
      Uses the table on TO p206 to calculate the number of crew hits based on percentage of total casualties. Used for ejection, boarding actions and such
      Returns:
      The number of crew hits
    • getHits

      public int getHits(int pos)
    • getInitBonus

      public int getInitBonus()
    • getCommandBonus

      public int getCommandBonus()
    • setSize

      public void setSize(int newSize)
      Accessor method to set the crew size.
      Parameters:
      newSize - The new size of this crew.
    • setCurrentSize

      public void setCurrentSize(int newSize)
      Accessor method to set the current crew size.
      Parameters:
      newSize - The new size of this crew.
    • setGunnery

      public void setGunnery(int gunnery, int pos)
    • setGunneryL

      public void setGunneryL(int gunnery, int pos)
    • setGunneryM

      public void setGunneryM(int gunnery, int pos)
    • setGunneryB

      public void setGunneryB(int gunnery, int pos)
    • setArtillery

      public void setArtillery(int artillery, int pos)
    • setPiloting

      public void setPiloting(int piloting, int pos)
    • setHits

      public void setHits(int hits, int pos)
    • setInitBonus

      public void setInitBonus(int bonus)
    • setCommandBonus

      public void setCommandBonus(int bonus)
    • isUnconscious

      public boolean isUnconscious()
      The crew is considered unconscious as a whole if none are active and at least one is not dead.
      Returns:
      Whether at least one crew member is alive but none are conscious.
    • isUnconscious

      public boolean isUnconscious(int pos)
    • setUnconscious

      public void setUnconscious(boolean unconscious)
    • setUnconscious

      public void setUnconscious(boolean unconscious, int pos)
    • isDead

      public boolean isDead()
      The crew is considered dead as a whole if all members are dead.
      Returns:
      Whether all members of the crew are dead.
    • isDead

      public boolean isDead(int pos)
    • setDead

      public void setDead(boolean dead)
    • setDead

      public void setDead(boolean dead, int pos)
    • isMissing

      public boolean isMissing(int pos)
      Returns:
      Whether the unit was fielded without a crew member in the slot.
    • setMissing

      public void setMissing(boolean missing, int pos)
      Allows a unit with a multi-crew cockpit to fielded with less than a full crew. Does not apply to collective crew (vehicles, infantry, large craft).
    • isDoomed

      public boolean isDoomed()
      Doomed status only applies to the crew as a whole.
      Returns:
      Whether the crew is scheduled to die at the end of the phase.
    • setDoomed

      public void setDoomed(boolean doomed)
      Doomed status only applies to the crew as a whole.
      Parameters:
      doomed - Whether the crew is scheduled to die at the end of the phase.
    • isActive

      public boolean isActive()
      The crew as a whole is considered active if any member is active.
      Returns:
      Whether the crew has at least one active member.
    • isActive

      public boolean isActive(int pos)
    • isKoThisRound

      public boolean isKoThisRound()
      The crew as a whole is considered ko this round if all active members are ko this round.
      Returns:
      true if all active members of the crew as knocked out this round
    • isKoThisRound

      public boolean isKoThisRound(int pos)
    • setKoThisRound

      public void setKoThisRound(boolean koThisRound)
      Set ko value for all slots.
      Parameters:
      koThisRound - Whether the crew will go unconscious during this round.
    • setKoThisRound

      public void setKoThisRound(boolean koThisRound, int pos)
    • setOptions

      public void setOptions(PilotOptions options)
    • getOptions

      public PilotOptions getOptions()
    • clearOptions

      public void clearOptions(String grpKey)
    • countOptions

      public int countOptions()
    • countOptions

      public int countOptions(String grpKey)
    • getOptions

      public Enumeration<IOption> getOptions(String grpKey)
      Returns the options of the given category that this pilot has
    • getOptionList

      public String getOptionList(String sep, String grpKey)
      Returns a string of all the option "codes" for this pilot, for a given group, using sep as the separator
    • parseAdvantageName

      public static String parseAdvantageName(String s)
    • parseAdvantageValue

      public static Object parseAdvantageValue(String s)
    • getDesc

      public String getDesc()
      Overall crew description, using the name of the first crew member in the case of multi-crew cockpits.
    • getDesc

      public String getDesc(int pos)
    • getDescVector

      public Vector<Report> getDescVector(boolean gunneryOnly)
      Crew summary report used for victory phase.
      Parameters:
      gunneryOnly - Do not show the piloting skill
    • isCustom

      public boolean isCustom()
      Returns whether this pilot has non-standard piloting or gunnery values
    • hasEdgeRemaining

      public boolean hasEdgeRemaining()
    • decreaseEdge

      public void decreaseEdge()
    • isEjected

      public boolean isEjected()
      Determine if this pilot has abandoned her vehicle.
      Returns:
      true if the pilot has abandoned her vehicle, false if the pilot is still in the vehicle.
    • setEjected

      public void setEjected(boolean abandoned)
      Specify if this pilot has abandoned her vehicle.
      Parameters:
      abandoned - the boolean value to set.
    • getSensorOps

      public int getSensorOps()
      for sensor ops, so these might be easily expanded later for rpg
    • isPilotingFatigued

      public boolean isPilotingFatigued()
    • isGunneryFatigued

      public boolean isGunneryFatigued()
    • getStatusDesc

      public String getStatusDesc(int pos)
      Returns:
      A description of the status of a single crew member
    • setExternalIdAsString

      public void setExternalIdAsString(String i, int pos)
    • getExternalIdAsString

      public String getExternalIdAsString(int pos)
    • getExternalIdAsString

      public String getExternalIdAsString()
      Use the first assigned slot as a general id for the crew.
      Returns:
      The id of the first slot that is not set to "-1"
    • getExternalId

      public int getExternalId(int pos)
    • getToughness

      public int getToughness(int pos)
    • setToughness

      public void setToughness(int t, int pos)
    • getFatigue

      @Deprecated(since="0.50.04", forRemoval=true) public int getFatigue()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 0.50.04 - No references found in MegaMek
      This method is showing 0 references from within MegaMek. If not needed in other projects, it should be removed.
    • setFatigue

      @Deprecated(since="0.50.04", forRemoval=true) public void setFatigue(int fatigue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 0.50.04 - No references found in MegaMek
      This method is showing 0 references from within MegaMek. If not needed in other projects, it should be removed.
    • getCrewFatigue

      public int getCrewFatigue(int pos)
    • setCrewFatigue

      public void setCrewFatigue(int fatigue, int position)
    • incrementFatigueCount

      public void incrementFatigueCount()
    • resetGameState

      public void resetGameState()
      Sets crew state fields back to defaults. Used by MekHQ to clear game state.
    • rollGunnerySkill

      public Roll rollGunnerySkill()
    • rollPilotingSkill

      public Roll rollPilotingSkill()
    • getCurrentPilotIndex

      public int getCurrentPilotIndex()
    • getCurrentGunnerIndex

      public int getCurrentGunnerIndex()
    • getBackupPilotPos

      public int getBackupPilotPos()
    • setBackupPilotPos

      public void setBackupPilotPos(int pos)
    • getBackupGunnerPos

      public int getBackupGunnerPos()
    • setBackupGunnerPos

      public void setBackupGunnerPos(int pos)
    • setCurrentPilot

      public void setCurrentPilot(int pos)
      Set the pilot slot. If a multi-crew cockpit uses the same crew member as both pilot and gunner (i.e. cockpit command console), sets the gunner as well.
      Parameters:
      pos - The slot index to set as pilot.
    • sortRandomSkills

      public void sortRandomSkills()
      When assigning skills randomly, we want to make sure the skills are assigned to the most appropriate position in crews where the pilot and gunner are separate. We're going to do it the simpler way and reassign the piloting and gunnery skills individually, resulting in a more specialized crew.
    • hasDedicatedPilot

      public boolean hasDedicatedPilot()
      Tripods and QuadVees get special benefits if the dedicated pilot is active.
      Returns:
      Whether a Mek has a separate pilot who is active.
    • hasDedicatedGunner

      public boolean hasDedicatedGunner()
      Tripods and QuadVees get special benefits if the dedicated gunner is active.
      Returns:
      Whether a Mek has a separate gunner who is active.
    • hasActiveTechOfficer

      public boolean hasActiveTechOfficer()
      Super heavy tripods gain benefits from having a technical officer.
      Returns:
      Whether the tech officer is alive and conscious.
    • hasActiveCommandConsole

      public boolean hasActiveCommandConsole()
      Cockpit command console provides commander init bonus if both crew members are active (also requires advanced fire control and heavy/assault unit, which is not checked here). Though the positions are named "pilot" and "commander" they can switch positions in the end phase of any turn so we need to check whichever is not currently acting as pilot.
      Returns:
      Whether the unit has a commander that is not also acting as pilot currently or in the previous turn.
    • resetActedFlag

      public void resetActedFlag()
      Called after the initiative bonus for the round has been calculated.
    • getSwapConsoleRoles

      public boolean getSwapConsoleRoles()
      Returns:
      Whether the crew members in a command console-equipped unit are scheduled to swap roles at the end of the turn.
    • setSwapConsoleRoles

      public void setSwapConsoleRoles(boolean swap)
      Schedules or clears a scheduled swap of roles in a command console-equipped unit.
      Parameters:
      swap - true for crew slots in a command console to swap roles at the end of the turn, otherwise false
    • doConsoleRoleSwap

      public boolean doConsoleRoleSwap()
      Checks whether a role swap is scheduled for a command-console equipped unit and (if the new pilot is active) performs the swap. The swap flag is cleared regardless of whether a swap took place.
      Returns:
      True if a swap was performed, otherwise false.
    • setExtraData

      public void setExtraData(Map<Integer,Map<String,String>> extraData)
    • setExtraDataForCrewMember

      public void setExtraDataForCrewMember(int crewIndex, Map<String,String> dataMap)
    • getExtraData

      public Map<Integer,Map<String,String>> getExtraData()
    • getExtraDataForCrewMember

      public Map<String,String> getExtraDataForCrewMember(int crewIndex)
    • getExtraDataValue

      public String getExtraDataValue(int crewIndex, String key)
    • writeExtraDataToXMLLine

      public String writeExtraDataToXMLLine(int pos)
    • setHits

      @Deprecated(since="0.50.04", forRemoval=true) public void setHits(int hits)
      Deprecated, for removal: This API element is subject to removal in a future version.
      by multi-crew cockpits. Replaced by setHits(int, int)
    • setPiloting

      public void setPiloting(int piloting)
      Sets the piloting skill of the crew's default pilot.
    • setGunnery

      public void setGunnery(int gunnery)
      Sets the gunnery skill of the crew's default gunner.