Package megamek.common.weapons
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
A basic, simple attack handler. May or may not work for any particular
weapon; must be overloaded
to support special rules.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected Entity
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected int
protected AmmoType
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
Used to store reports from calls tocalcDamagePerHit
.protected int
protected int
protected boolean
protected int
protected DamageType
protected boolean
Keeps track of whether we are processing the first hit in a series of hits (like for cluster weapons)protected Game
protected TWGameManager
protected int
protected HitData
protected boolean
protected boolean
Boolean flag that determines whether or not this attack is part of a strafing run.protected boolean
Boolean flag that determines if this shot was the first one by a particular weapon in a strafing run.protected boolean
protected int
protected int
protected int
protected boolean
protected int
protected int
protected int
protected int
protected WeaponHandler
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected String
protected int
protected Targetable
protected boolean
protected String
protected boolean
protected WeaponMounted
protected WeaponType
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WeaponHandler
(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 entityprotected void
addGlancingBlowReports
(Vector<Report> vPhaseReport) Worker function that adds the 'glancing blow' reportsprotected void
addHeat()
protected boolean
boolean
protected double
applyGlancingBlowModifier
(double initialValue, boolean roundup) Determine the "glancing blow" divider.protected int
applyGlancingBlowModifier
(int initialValue, boolean roundup) Determine the "glancing blow" divider.protected int[]
calcAeroDamage
(Entity entityTarget, Vector<Report> vPhaseReport) protected int
Calculate the attack value based on rangeprotected int
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)protected int
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 phaseprotected int
Calculate the damage per hit.protected int
Calculate the number of hitsprotected int
Calculate the clustering of the hitsprotected int
calcnClusterAero
(Entity entityTarget) protected boolean
canEngageCapitalMissile
(WeaponMounted counter) Checks to see if this point defense/AMS bay can engage a capital missile This should return true.boolean
Do we care about the specified phase?int
Check for Laser Inhibiting smoke clouds, does not work against PPCs, Plasma Weapons, or Flamers per TacOps:AUE (6th) pg.protected boolean
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 phaseint
checkTerrain
(int nDamage, Entity entityTarget, Vector<Report> vPhaseReport) 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 ammoprotected boolean
int
return theint
Id of the attackingEntity
protected double
* adjustment factor on attack value for fighter squadronsprotected int
protected int
Return the to-hit penalty inflicted on a capital missile attack by point defense fireprotected int
getClusterModifiers
(boolean clusterRangePenalty) protected int
Return the attack value of point defense weapons used against a missile bay attackprotected TargetRoll
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.protected int
protected WeaponHandler
Used with Aero Sanity mod Returns the handler for the BayWeapon this individual weapon belongs toint
protected double
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 blowgetWaa()
boolean
handle this weapons firingprotected 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.protected void
handleBuildingDamage
(Vector<Report> vPhaseReport, Building bldg, int nDamage, Coords coords) protected void
handleClearDamage
(Vector<Report> vPhaseReport, Building bldg, int nDamage) protected void
handleClearDamage
(Vector<Report> vPhaseReport, Building bldg, int nDamage, boolean hitReport) 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.protected void
handleIgnitionDamage
(Vector<Report> vPhaseReport, Building bldg, int hits) 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.protected boolean
handleSpecialMiss
(Entity entityTarget, boolean bldgDamagedOnMiss, Building bldg, Vector<Report> vPhaseReport) protected void
Worker function that initializes the actual hit, including a hit location and various other properties.protected void
insertAttacks
(GamePhase phase, Vector<Report> vPhaseReport) Insert any additional attacks that should occur before this attackprotected 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 rulesboolean
Used to determine if the AttackHandler is handling a strafing run.boolean
Used to determine if this is the firt time a weapon is firing as part of a strafing run.protected boolean
isTbolt()
Sets whether or not this weapon is considered a single, large missile for AMS resolutionprotected void
reportMiss
(Vector<Report> vPhaseReport) protected void
reportMiss
(Vector<Report> vPhaseReport, boolean singleNewline) void
restore()
Restores the equipment from the nameprotected void
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 phasevoid
setAnnouncedEntityFiring
(boolean announcedEntityFiring) protected void
setDone()
protected void
setGlancingBlowFlags
(Entity entityTarget) Worker function that sets the glancing blow flags for this attack for the target when appropriateprotected void
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 handlerprotected void
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 phasevoid
setStrafing
(boolean isStrafing) void
setStrafingFirstShot
(boolean isStrafingFirstShot) protected boolean
specialResolution
(Vector<Report> vPhaseReport, Entity entityTarget) special resolution, like minefields and artyprotected boolean
unitGainsPartialCoverFromWater
(Hex targetHex, Entity entityTarget) Worker function - does the entity gain partial cover from shallow water?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?protected void
useAmmo()
protected boolean
Does this attack use the cluster hit table? necessary to determine how Aero damage should be applied
-
Field Details
-
toHit
-
hit
-
waa
-
roll
-
isJammed
protected boolean isJammed -
game
-
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
-
atype
-
typeName
-
weapon
-
ae
-
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
-
generalDamageType
protected int generalDamageType -
insertedAttacks
-
nweapons
protected int nweapons -
nweaponsHit
protected int nweaponsHit -
secondShot
protected boolean secondShot -
numRapidFireHits
protected int numRapidFireHits -
sSalvoType
-
nSalvoBonus
protected int nSalvoBonus -
firstHit
protected boolean firstHitKeeps track of whether we are processing the first hit in a series of hits (like for cluster weapons) -
isStrafing
protected boolean isStrafingBoolean flag that determines whether or not this attack is part of a strafing run. -
isStrafingFirstShot
protected boolean isStrafingFirstShotBoolean 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
-
originalAV
protected int originalAV -
amsEngaged
protected boolean amsEngaged -
apdsEngaged
protected boolean apdsEngaged -
calcDmgPerHitReport
Used to store reports from calls tocalcDamagePerHit
. This is necessary because the method is called before the report needs to be added.
-
-
Constructor Details
-
WeaponHandler
protected WeaponHandler() -
WeaponHandler
-
-
Method Details
-
getSalvoBonus
public int getSalvoBonus() -
getLargeCraftHeat
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
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
Used with Aero Sanity mod Returns the handler for the BayWeapon this individual weapon belongs to -
setParentBayHandler
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
- - TheAttackHandler
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 theint
Id of the attackingEntity
- Specified by:
getAttackerId
in interfaceAttackHandler
-
getAttacker
- Specified by:
getAttacker
in interfaceAttackHandler
-
cares
Do we care about the specified phase?- Specified by:
cares
in interfaceAttackHandler
-
doChecks
- Parameters:
vPhaseReport
- - AVector
containing the phasereport.- Returns:
- a
boolean
value indicating wether or not the attack misses because of a failed check.
-
doAmmoFeedProblemCheck
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
-
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
Calculate the number of hits- Parameters:
vPhaseReport
- - theVector
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
-
calcAeroDamage
-
handle
handle this weapons firing- Specified by:
handle
in interfaceAttackHandler
- 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. TheToHitData
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 thehandleEntityDamage
method.- Parameters:
entityTarget
- The target EntityvPhaseReport
-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
Worker function - does the entity gain partial cover from shallow water? -
unitStickingOutOfBuilding
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
-
handleClearDamage
-
handleClearDamage
-
handleBuildingDamage
-
allShotsHit
protected boolean allShotsHit() -
reportMiss
-
reportMiss
-
initHit
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
special resolution, like minefields and arty- Parameters:
vPhaseReport
- - aVector
containing the phase reportentityTarget
- - theEntity
targeted, ornull
, if no Entity targeted- Returns:
- true when done with processing, false when not
-
announcedEntityFiring
public boolean announcedEntityFiring()- Specified by:
announcedEntityFiring
in interfaceAttackHandler
-
setAnnouncedEntityFiring
public void setAnnouncedEntityFiring(boolean announcedEntityFiring) - Specified by:
setAnnouncedEntityFiring
in interfaceAttackHandler
-
getWaa
- Specified by:
getWaa
in interfaceAttackHandler
-
checkTerrain
-
checkLI
Check for Laser Inhibiting smoke clouds, does not work against PPCs, Plasma Weapons, or Flamers per TacOps:AUE (6th) pg. 168 -
insertAttacks
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 interfaceAttackHandler
- Returns:
-
setStrafing
public void setStrafing(boolean isStrafing) - Specified by:
setStrafing
in interfaceAttackHandler
-
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 interfaceAttackHandler
- Returns:
-
setStrafingFirstShot
public void setStrafingFirstShot(boolean isStrafingFirstShot) - Specified by:
setStrafingFirstShot
in interfaceAttackHandler
-
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
Worker function that sets the glancing blow flags for this attack for the target when appropriate -
isLowProfileGlancingBlow
Worker function that determines if the given hit on the given entity is a glancing blow as per narrow/low profile quirk rules -
addGlancingBlowReports
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
-
-