Package megamek.common.weapons.handlers
Class WeaponHandler
java.lang.Object
megamek.common.weapons.handlers.WeaponHandler
- All Implemented Interfaces:
Serializable,AttackHandler
- Direct Known Subclasses:
AmmoWeaponHandler,BALBXHandler,BAMGHandler,BayWeaponHandler,BombAttackHandler,EnergyWeaponHandler,FireExtinguisherHandler,FirefightingSupportHandler,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 booleanprotected AmmoTypeprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected EntityAttacking Entity is theEntitywhere the attack is coming fromprotected intprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanUsed to store reports from calls tocalcDamagePerHit.protected intprotected intprotected booleanprotected intprotected DamageTypeprotected booleanKeeps track of whether we are processing the first hit in a series of hits (like for cluster weapons)protected Gameprotected TWGameManagerprotected intprotected HitDataprotected booleanprotected booleanBoolean flag that determines whether this attack is part of a strafing run.protected booleanBoolean flag that determines if this shot was the first one by a particular weapon in a strafing run.protected booleanprotected intprotected intprotected intprotected booleanprotected intprotected intprotected intprotected intprotected WeaponHandlerprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected Stringprotected intprotected Targetableprotected booleanprotected Stringprotected booleanprotected WeaponMountedprotected Entityprotected WeaponType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWeaponHandler(ToHitData toHitData, WeaponAttackAction weaponAttackAction, Game game, TWGameManager twGameManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected intabsorbBuildingDamage(int nDamage, Entity entityTarget, int bldgAbsorbs, Vector<Report> vPhaseReport, IBuilding bldg, boolean targetStickingOutOfBuilding) Worker function to (maybe) have a building absorb damage meant for the entityprotected voidaddGlancingBlowReports(Vector<Report> vPhaseReport) Worker function that adds the 'glancing blow' reportsprotected voidaddHeat()protected booleanbooleanprotected doubleapplyGlancingBlowModifier(double initialValue, boolean roundup) Determine the "glancing blow" divider.protected intapplyGlancingBlowModifier(int initialValue, boolean roundup) Determine the "glancing blow" divider.protected int[]calcAeroDamage(Entity entityTarget, Vector<Report> vPhaseReport) protected intCalculate the attack value based on rangeprotected intCalculates 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 intCalculates 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 intCalculate the damage per hit.protected intCalculate the number of hitsprotected intCalculate the clustering of the hitsprotected intcalculateNumClusterAero(Entity entityTarget) protected booleancanEngageCapitalMissile(WeaponMounted counter) Checks to see if this point defense/AMS bay can engage a capital missile This should return true.booleanDo we care about the specified phase?intCheck for Laser Inhibiting smoke clouds, does not work against PPCs, Plasma Weapons, or Flamers per TacOps:AUE (6th) pg.protected booleanChecks 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 phaseintcheckTerrain(int nDamage, Entity entityTarget, Vector<Report> vPhaseReport) protected booleandoAmmoFeedProblemCheck(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 booleanintreturn theintID of the attackingEntityprotected double* adjustment factor on attack value for fighter squadronsprotected intprotected intReturn the to-hit penalty inflicted on a capital missile attack by point defense fireprotected intgetClusterModifiers(boolean clusterRangePenalty) intReturn the attack value of point defense weapons used against a missile bay attackprotected TargetRollprotected intgetLargeCraftHeat(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 intprotected WeaponHandlerUsed with Aero Sanity mod Returns the handler for the BayWeapon this individual weapon belongs tointprotected doubleLogic 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 blowbooleanhandle this weapons firingprotected voidhandleArtilleryDriftMarker(Coords targetPos, Coords finalPos, ArtilleryAttackAction aaa, Vector<Integer> hitIds) Used by certain artillery handlers to draw a drift marker at the hex an artillery round actually landed on when it missed its target.protected voidhandleBuildingDamage(Vector<Report> vPhaseReport, IBuilding bldg, int nDamage, Coords coords) protected voidhandleClearDamage(Vector<Report> vPhaseReport, IBuilding bldg, int nDamage) protected voidhandleClearDamage(Vector<Report> vPhaseReport, IBuilding bldg, int nDamage, boolean hitReport) protected voidhandleEntityDamage(Entity entityTarget, Vector<Report> vPhaseReport, IBuilding bldg, int hits, int nCluster, int bldgAbsorbs) Handle damage against an entity, called once per hit by default.protected voidhandleIgnitionDamage(Vector<Report> vPhaseReport, IBuilding bldg, int hits) protected voidhandlePartialCoverHit(Entity entityTarget, Vector<Report> vPhaseReport, HitData pcHit, IBuilding bldg, int hits, int nCluster, int bldgAbsorbs) Handles potential damage to partial cover that absorbs a shot.protected booleanhandleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMiss, IBuilding bldg, Vector<Report> vPhaseReport) protected voidWorker function that initializes the actual hit, including a hit location and various other properties.protected voidinsertAttacks(GamePhase phase, Vector<Report> vPhaseReport) Insert any additional attacks that should occur before this attackprotected booleanisLowProfileGlancingBlow(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 rulesbooleanUsed to determine if the AttackHandler is handling a strafing run.booleanUsed to determine if this is the first time a weapon is firing as part of a strafing run.protected booleanSets whether this weapon is considered a single, large missile for AMS resolutionprotected voidreportMiss(Vector<Report> vPhaseReport) protected voidreportMiss(Vector<Report> vPhaseReport, boolean singleNewline) voidrestore()Restores the equipment from the nameprotected voidSets 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 phasevoidsetAnnouncedEntityFiring(boolean announcedEntityFiring) protected voidsetDone()protected voidsetGlancingBlowFlags(Entity entityTarget) Worker function that sets the glancing blow flags for this attack for the target when appropriatevoidSets 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 voidSets 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 phasevoidsetStrafing(boolean isStrafing) voidsetStrafingFirstShot(boolean isStrafingFirstShot) protected booleanspecialResolution(Vector<Report> vPhaseReport, Entity entityTarget) special resolution, like minefields and artyprotected booleanunitGainsPartialCoverFromWater(Hex targetHex, Entity entityTarget) Worker function - does the entity gain partial cover from shallow water?protected booleanunitStickingOutOfBuilding(Hex targetHex, Entity entityTarget) Worker function - is a part of this unit inside the hex's terrain features, but part sticking out?protected voiduseAmmo()protected booleanDoes this attack use the cluster hit table? necessary to determine how Aero damage should be appliedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface megamek.common.weapons.handlers.AttackHandler
getBuildingDamageAdjustment, producesReportThisPhase
-
Field Details
-
toHit
-
hit
-
weaponAttackAction
-
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 -
weaponType
-
ammoType
-
typeName
-
weapon
-
attackingEntity
Attacking Entity is theEntitywhere the attack is coming from -
weaponEntity
-
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
-
numWeapons
protected int numWeapons -
numWeaponsHit
protected int numWeaponsHit -
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 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
public WeaponHandler(ToHitData toHitData, WeaponAttackAction weaponAttackAction, Game game, TWGameManager twGameManager) throws EntityLoadingException - Throws:
EntityLoadingException
-
-
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 -
isThunderBolt
protected boolean isThunderBolt()Sets whether 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
public 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- - TheAttackHandlerfor 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 theintID of the attackingEntity- Specified by:
getAttackerIdin interfaceAttackHandler
-
getAttacker
- Specified by:
getAttackerin interfaceAttackHandler
-
cares
Do we care about the specified phase?- Specified by:
caresin interfaceAttackHandler- Parameters:
phase- The current game phase- Returns:
- True when this handler acts or might act in this phase. The handle() method of this handler is only called when this method returns true for the present phase.
-
doChecks
- Parameters:
vPhaseReport- - AVectorcontaining the phase report.- Returns:
- a
booleanvalue indicating whether 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, IBuilding bldg, Vector<Report> vPhaseReport) - Returns:
- a
booleanvalue indicating whether 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- - theVectorcontaining the phase report.- Returns:
- an
intcontaining the number of hits.
-
calculateNumCluster
protected int calculateNumCluster()Calculate the clustering of the hits- Returns:
- a
intvalue saying how much hits are in each cluster of damage.
-
calculateNumClusterAero
-
calcAeroDamage
-
handle
handle this weapons firing- Specified by:
handlein interfaceAttackHandler- Parameters:
phase- The present game phasereturnedReports- The reports list to add new reports to- Returns:
- a
booleanvalue indicating whether this should be kept or not
-
calcDamagePerHit
protected int calcDamagePerHit()Calculate the damage per hit.- Returns:
- an
intrepresenting the damage dealt per hit.
-
calcAttackValue
protected int calcAttackValue()Calculate the attack value based on range- Returns:
- an
intrepresenting 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, IBuilding bldg, int hits, int nCluster, int bldgAbsorbs) Handles potential damage to partial cover that absorbs a shot. TheToHitDatais 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 thehandleEntityDamagemethod.- Parameters:
entityTarget- The target Entity
-
handleEntityDamage
protected void handleEntityDamage(Entity entityTarget, Vector<Report> vPhaseReport, IBuilding 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, IBuilding 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- - aVectorcontaining the phase reportentityTarget- - theEntitytargeted, ornull, if no Entity targeted- Returns:
- true when done with processing, false when not
-
announcedEntityFiring
public boolean announcedEntityFiring()- Specified by:
announcedEntityFiringin interfaceAttackHandler
-
setAnnouncedEntityFiring
public void setAnnouncedEntityFiring(boolean announcedEntityFiring) - Specified by:
setAnnouncedEntityFiringin interfaceAttackHandler
-
getWeaponAttackAction
- Specified by:
getWeaponAttackActionin 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:AttackHandlerUsed to determine if the AttackHandler is handling a strafing run.- Specified by:
isStrafingin interfaceAttackHandler
-
setStrafing
public void setStrafing(boolean isStrafing) - Specified by:
setStrafingin interfaceAttackHandler
-
isStrafingFirstShot
public boolean isStrafingFirstShot()Description copied from interface:AttackHandlerUsed to determine if this is the first 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:
isStrafingFirstShotin interfaceAttackHandler
-
setStrafingFirstShot
public void setStrafingFirstShot(boolean isStrafingFirstShot) - Specified by:
setStrafingFirstShotin 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 a drift marker at the hex an artillery round actually landed on when it missed its target. The round is always marked as a drift: a drift that lands on a unit is still a drift, and the resulting damage is already shown in the combat report. (It must not be marked as a hit -SpecialHexDisplay.drawNow(megamek.common.enums.GamePhase, int, megamek.common.Player, megamek.client.ui.clientGUI.GUIPreferences)deliberately suppresses "hit" markers whose text says they drifted, which would leave the landing hex with no marker at all.) No-op for direct hits.- Parameters:
targetPos- The hex that was targetedfinalPos- The hex the round actually drifted toaaa- The artillery attackhitIds- Ids of units caught in the blast; retained because callers produce it as a side effect of resolving the blast damage, but no longer used to choose the marker type
-