Class WeaponHandler

java.lang.Object
megamek.common.weapons.WeaponHandler
All Implemented Interfaces:
Serializable, AttackHandler
Direct Known Subclasses:
AmmoWeaponHandler, BALBXHandler, BAMGHandler, BayWeaponHandler, BombAttackHandler, EnergyWeaponHandler, FireExtinguisherHandler, FlamerHandler, InfantryWeaponHandler, LegAttackHandler, SpaceBombAttackHandler, StopSwarmAttackHandler, SwarmAttackHandler, SwarmWeaponAttackHandler, TAGHandler

public class WeaponHandler extends Object implements AttackHandler, Serializable
A basic, simple attack handler. May or may not work for any particular weapon; must be overloaded to support special rules.
See Also:
  • Field Details

    • toHit

      public ToHitData toHit
    • hit

      protected HitData hit
    • waa

      public WeaponAttackAction waa
    • roll

      public Roll roll
    • isJammed

      protected boolean isJammed
    • game

      protected Game game
    • gameManager

      protected transient TWGameManager gameManager
    • bMissed

      protected boolean bMissed
    • bSalvo

      protected boolean bSalvo
    • bGlancing

      protected boolean bGlancing
    • bDirect

      protected boolean bDirect
    • bLowProfileGlancing

      protected boolean bLowProfileGlancing
    • nukeS2S

      protected boolean nukeS2S
    • wtype

      protected WeaponType wtype
    • atype

      protected AmmoType atype
    • typeName

      protected String typeName
    • weapon

      protected WeaponMounted weapon
    • ae

      protected Entity ae
    • target

      protected Targetable target
    • subjectId

      protected int subjectId
    • nRange

      protected int nRange
    • nDamPerHit

      protected int nDamPerHit
    • attackValue

      protected int attackValue
    • throughFront

      protected boolean throughFront
    • underWater

      protected boolean underWater
    • announcedEntityFiring

      protected boolean announcedEntityFiring
    • missed

      protected boolean missed
    • damageType

      protected DamageType damageType
    • generalDamageType

      protected int generalDamageType
    • insertedAttacks

      protected Vector<Integer> insertedAttacks
    • nweapons

      protected int nweapons
    • nweaponsHit

      protected int nweaponsHit
    • secondShot

      protected boolean secondShot
    • numRapidFireHits

      protected int numRapidFireHits
    • sSalvoType

      protected String sSalvoType
    • nSalvoBonus

      protected int nSalvoBonus
    • firstHit

      protected boolean firstHit
      Keeps track of whether we are processing the first hit in a series of hits (like for cluster weapons)
    • isStrafing

      protected boolean isStrafing
      Boolean flag that determines whether or not this attack is part of a strafing run.
    • isStrafingFirstShot

      protected boolean isStrafingFirstShot
      Boolean flag that determines if this shot was the first one by a particular weapon in a strafing run. Used to ensure that heat is only added once.
    • CounterAV

      protected int CounterAV
    • CapMissileArmor

      protected int CapMissileArmor
    • CapMissileAMSMod

      protected int CapMissileAMSMod
    • CapMissileMissed

      protected boolean CapMissileMissed
    • amsBayEngaged

      protected boolean amsBayEngaged
    • pdBayEngaged

      protected boolean pdBayEngaged
    • pdOverheated

      protected boolean pdOverheated
    • amsBayEngagedCap

      protected boolean amsBayEngagedCap
    • pdBayEngagedCap

      protected boolean pdBayEngagedCap
    • amsBayEngagedMissile

      protected boolean amsBayEngagedMissile
    • pdBayEngagedMissile

      protected boolean pdBayEngagedMissile
    • advancedPD

      protected boolean advancedPD
    • parentBayHandler

      protected WeaponHandler parentBayHandler
    • originalAV

      protected int originalAV
    • amsEngaged

      protected boolean amsEngaged
    • apdsEngaged

      protected boolean apdsEngaged
    • calcDmgPerHitReport

      protected Vector<Report> calcDmgPerHitReport
      Used to store reports from calls to calcDamagePerHit. This is necessary because the method is called before the report needs to be added.
  • Constructor Details

  • Method Details

    • getSalvoBonus

      public int getSalvoBonus()
    • getLargeCraftHeat

      protected int getLargeCraftHeat(Entity entity)
      Returns the heat generated by a large craft's weapons fire declarations during the round Used to determine whether point defenses can engage.
      Parameters:
      entity - the entity you wish to get heat data from
      See Also:
    • checkPDConditions

      protected boolean checkPDConditions()
      Checks to see if the basic conditions needed for point defenses to work are in place Artillery weapons need to change this slightly See also TeleMissileAttackAction, which contains a modified version of this to work against a TeleMissile entity in the physical phase
    • canEngageCapitalMissile

      protected boolean canEngageCapitalMissile(WeaponMounted counter)
      Checks to see if this point defense/AMS bay can engage a capital missile This should return true. Only when handling capital missile attacks can this be false. See also TeleMissileAttackAction, which contains a modified version of this to work against a TeleMissile entity in the physical phase
    • setAMSBayReportingFlag

      protected void setAMSBayReportingFlag()
      Sets the appropriate AMS Bay reporting flag depending on what type of missile this is See also TeleMissileAttackAction, which contains a modified version of this to work against a TeleMissile entity in the physical phase
    • setPDBayReportingFlag

      protected void setPDBayReportingFlag()
      Sets the appropriate PD Bay reporting flag depending on what type of missile this is See also TeleMissileAttackAction, which contains a modified version of this to work against a TeleMissile entity in the physical phase
    • isTbolt

      protected boolean isTbolt()
      Sets whether or not this weapon is considered a single, large missile for AMS resolution
    • calcCounterAV

      protected int calcCounterAV()
      Calculates the attack value of point defense weapons used against a missile bay attack This is the main large craft point defense method See also TeleMissileAttackAction, which contains a modified version of this to work against a TeleMissile entity in the physical phase
    • getCounterAV

      protected int getCounterAV()
      Return the attack value of point defense weapons used against a missile bay attack
    • getParentBayHandler

      protected WeaponHandler getParentBayHandler()
      Used with Aero Sanity mod Returns the handler for the BayWeapon this individual weapon belongs to
    • setParentBayHandler

      protected void setParentBayHandler(WeaponHandler bh)
      Sets the parent handler for each sub-weapon handler called when looping through bay weapons Used with Aero Sanity to pass counterAV through to the individual missile handler from the bay handler
      Parameters:
      bh - - The AttackHandler for the BayWeapon this individual weapon belongs to
    • calcCapMissileAMSMod

      protected int calcCapMissileAMSMod()
      Calculates the to-hit penalty inflicted on a capital missile attack by point defense fire this should return 0 unless this is a capital missile attack (otherwise, reporting and to-hit get screwed up)
    • getCapMissileAMSMod

      protected int getCapMissileAMSMod()
      Return the to-hit penalty inflicted on a capital missile attack by point defense fire
    • getAttackerId

      public int getAttackerId()
      return the int Id of the attacking Entity
      Specified by:
      getAttackerId in interface AttackHandler
    • getAttacker

      public Entity getAttacker()
      Specified by:
      getAttacker in interface AttackHandler
    • cares

      public boolean cares(GamePhase phase)
      Do we care about the specified phase?
      Specified by:
      cares in interface AttackHandler
    • doChecks

      protected boolean doChecks(Vector<Report> vPhaseReport)
      Parameters:
      vPhaseReport - - A Vector containing the phasereport.
      Returns:
      a boolean value indicating wether or not the attack misses because of a failed check.
    • doAmmoFeedProblemCheck

      protected boolean doAmmoFeedProblemCheck(Vector<Report> vPhaseReport)
      Carries out a check to see if the weapon in question explodes due to the 'ammo feed problem' quirk Not the case for weapons without ammo
    • getFireTNRoll

      protected TargetRoll getFireTNRoll()
    • handleSpecialMiss

      protected boolean handleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMiss, Building bldg, Vector<Report> vPhaseReport)
      Returns:
      a boolean value indicating whether or not this attack needs further calculating, like a missed shot hitting a building, or an AMS only shooting down some missiles.
    • calcHits

      protected int calcHits(Vector<Report> vPhaseReport)
      Calculate the number of hits
      Parameters:
      vPhaseReport - - the Vector containing the phase report.
      Returns:
      an int containing the number of hits.
    • calcnCluster

      protected int calcnCluster()
      Calculate the clustering of the hits
      Returns:
      a int value saying how much hits are in each cluster of damage.
    • calcnClusterAero

      protected int calcnClusterAero(Entity entityTarget)
    • calcAeroDamage

      protected int[] calcAeroDamage(Entity entityTarget, Vector<Report> vPhaseReport)
    • handle

      public boolean handle(GamePhase phase, Vector<Report> returnedReports)
      handle this weapons firing
      Specified by:
      handle in interface AttackHandler
      Returns:
      a boolean value indicating whether this should be kept or not
    • calcDamagePerHit

      protected int calcDamagePerHit()
      Calculate the damage per hit.
      Returns:
      an int representing the damage dealt per hit.
    • calcAttackValue

      protected int calcAttackValue()
      Calculate the attack value based on range
      Returns:
      an int representing the attack value at that range.
    • getBracketingMultiplier

      protected double getBracketingMultiplier()
      * adjustment factor on attack value for fighter squadrons
    • getCapMisMod

      protected int getCapMisMod()
    • handlePartialCoverHit

      protected void handlePartialCoverHit(Entity entityTarget, Vector<Report> vPhaseReport, HitData pcHit, Building bldg, int hits, int nCluster, int bldgAbsorbs)
      Handles potential damage to partial cover that absorbs a shot. The ToHitData is checked to what if there is any damagable cover to be hit, and if so which cover gets hit (there are two possibilities in some cases, such as 75% partial cover). The method then takes care of assigning damage to the cover. Buildings are damaged directly, while dropships call the handleEntityDamage method.
      Parameters:
      entityTarget - The target Entity
      vPhaseReport -
      pcHit -
      bldg -
      hits -
      nCluster -
      bldgAbsorbs -
    • handleEntityDamage

      protected void handleEntityDamage(Entity entityTarget, Vector<Report> vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs)
      Handle damage against an entity, called once per hit by default.
    • unitGainsPartialCoverFromWater

      protected boolean unitGainsPartialCoverFromWater(Hex targetHex, Entity entityTarget)
      Worker function - does the entity gain partial cover from shallow water?
    • unitStickingOutOfBuilding

      protected boolean unitStickingOutOfBuilding(Hex targetHex, Entity entityTarget)
      Worker function - is a part of this unit inside the hex's terrain features, but part sticking out?
    • absorbBuildingDamage

      protected int absorbBuildingDamage(int nDamage, Entity entityTarget, int bldgAbsorbs, Vector<Report> vPhaseReport, Building bldg, boolean targetStickingOutOfBuilding)
      Worker function to (maybe) have a building absorb damage meant for the entity
    • handleIgnitionDamage

      protected void handleIgnitionDamage(Vector<Report> vPhaseReport, Building bldg, int hits)
    • handleClearDamage

      protected void handleClearDamage(Vector<Report> vPhaseReport, Building bldg, int nDamage)
    • handleClearDamage

      protected void handleClearDamage(Vector<Report> vPhaseReport, Building bldg, int nDamage, boolean hitReport)
    • handleBuildingDamage

      protected void handleBuildingDamage(Vector<Report> vPhaseReport, Building bldg, int nDamage, Coords coords)
    • allShotsHit

      protected boolean allShotsHit()
    • reportMiss

      protected void reportMiss(Vector<Report> vPhaseReport)
    • reportMiss

      protected void reportMiss(Vector<Report> vPhaseReport, boolean singleNewline)
    • initHit

      protected void initHit(Entity entityTarget)
      Worker function that initializes the actual hit, including a hit location and various other properties.
      Parameters:
      entityTarget - Entity being hit.
    • useAmmo

      protected void useAmmo()
    • setDone

      protected void setDone()
    • addHeat

      protected void addHeat()
    • usesClusterTable

      protected boolean usesClusterTable()
      Does this attack use the cluster hit table? necessary to determine how Aero damage should be applied
    • specialResolution

      protected boolean specialResolution(Vector<Report> vPhaseReport, Entity entityTarget)
      special resolution, like minefields and arty
      Parameters:
      vPhaseReport - - a Vector containing the phase report
      entityTarget - - the Entity targeted, or null, if no Entity targeted
      Returns:
      true when done with processing, false when not
    • announcedEntityFiring

      public boolean announcedEntityFiring()
      Specified by:
      announcedEntityFiring in interface AttackHandler
    • setAnnouncedEntityFiring

      public void setAnnouncedEntityFiring(boolean announcedEntityFiring)
      Specified by:
      setAnnouncedEntityFiring in interface AttackHandler
    • getWaa

      public WeaponAttackAction getWaa()
      Specified by:
      getWaa in interface AttackHandler
    • checkTerrain

      public int checkTerrain(int nDamage, Entity entityTarget, Vector<Report> vPhaseReport)
    • checkLI

      public int checkLI(int nDamage, Entity entityTarget, Vector<Report> vPhaseReport)
      Check for Laser Inhibiting smoke clouds, does not work against PPCs, Plasma Weapons, or Flamers per TacOps:AUE (6th) pg. 168
    • insertAttacks

      protected void insertAttacks(GamePhase phase, Vector<Report> vPhaseReport)
      Insert any additional attacks that should occur before this attack
    • getNumberWeapons

      protected int getNumberWeapons()
      Returns:
      the number of weapons of this type firing (for squadron weapon groups)
    • restore

      public void restore()
      Restores the equipment from the name
    • getClusterModifiers

      protected int getClusterModifiers(boolean clusterRangePenalty)
    • isStrafing

      public boolean isStrafing()
      Description copied from interface: AttackHandler
      Used to determine if the AttackHandler is handling a strafing run.
      Specified by:
      isStrafing in interface AttackHandler
      Returns:
    • setStrafing

      public void setStrafing(boolean isStrafing)
      Specified by:
      setStrafing in interface AttackHandler
    • isStrafingFirstShot

      public boolean isStrafingFirstShot()
      Description copied from interface: AttackHandler
      Used to determine if this is the firt time a weapon is firing as part of a strafing run. This is used for handling heat, to prevent shots after the first one from generating heat.
      Specified by:
      isStrafingFirstShot in interface AttackHandler
      Returns:
    • setStrafingFirstShot

      public void setStrafingFirstShot(boolean isStrafingFirstShot)
      Specified by:
      setStrafingFirstShot in interface AttackHandler
    • applyGlancingBlowModifier

      protected int applyGlancingBlowModifier(int initialValue, boolean roundup)
      Determine the "glancing blow" divider. 2 if the shot is "glancing" or "glancing due to low profile" 4 if both int version
    • applyGlancingBlowModifier

      protected double applyGlancingBlowModifier(double initialValue, boolean roundup)
      Determine the "glancing blow" divider. 2 if the shot is "glancing" or "glancing due to low profile" 4 if both double version
    • getTotalGlancingBlowFactor

      protected double getTotalGlancingBlowFactor()
      Logic to determine the glancing blow multiplier: 1 if no glancing blow 2 if one type of glancing blow (either usual or narrow/low profile) 4 if both types of glancing blow
    • setGlancingBlowFlags

      protected void setGlancingBlowFlags(Entity entityTarget)
      Worker function that sets the glancing blow flags for this attack for the target when appropriate
    • isLowProfileGlancingBlow

      protected boolean isLowProfileGlancingBlow(Entity entityTarget, ToHitData hitData)
      Worker function that determines if the given hit on the given entity is a glancing blow as per narrow/low profile quirk rules
    • addGlancingBlowReports

      protected void addGlancingBlowReports(Vector<Report> vPhaseReport)
      Worker function that adds the 'glancing blow' reports
    • handleArtilleryDriftMarker

      protected void handleArtilleryDriftMarker(Coords targetPos, Coords finalPos, ArtilleryAttackAction aaa, Vector<Integer> hitIds)
      Used by certain artillery handlers to draw drift markers with "hit" graphics if anything is caught in the blast, or "drift" marker if nothing is damaged. No-op for direct hits.
      Parameters:
      targetPos -
      finalPos -
      aaa -
      hitIds -