-
Notifications
You must be signed in to change notification settings - Fork 334
Fix 5590: princess firing on 13s due to intervening trees, etc. #6477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rjhancock
merged 3 commits into
MegaMek:master
from
Sleet01:Fix_5590_Princess_firing_on_13s_due_to_intervening_trees
Feb 1, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,16 +354,22 @@ ToHitData guessToHitModifierHelperForAnyAttack(final Entity shooter, | |
| } | ||
|
|
||
| // terrain modifiers, since "compute" won't let me do these remotely | ||
| LosEffects los = LosEffects.calculateLOS(game, shooter, target); | ||
|
|
||
| // We want to check the target hex _and_ the intervening hexes for woods, smoke, etc. | ||
| final Hex targetHex = game.getBoard().getHex(targetState.getPosition()); | ||
| int woodsLevel = targetHex.terrainLevel(Terrains.WOODS); | ||
| int woodsLevel = targetHex.terrainLevel(Terrains.WOODS) + | ||
| ((los.thruWoods()) ? los.getLightWoods() + los.getHeavyWoods() + los.getUltraWoods() : 0); | ||
| if (targetHex.terrainLevel(Terrains.JUNGLE) > woodsLevel) { | ||
| woodsLevel = targetHex.terrainLevel(Terrains.JUNGLE); | ||
| } | ||
| if (1 <= woodsLevel) { | ||
| toHitData.addModifier(woodsLevel, TH_WOODS); | ||
| } | ||
|
|
||
| final int smokeLevel = targetHex.terrainLevel(Terrains.SMOKE); | ||
| // final int smokeLevel = targetHex.terrainLevel(Terrains.SMOKE); | ||
| final int smokeLevel = targetHex.terrainLevel(Terrains.SMOKE) + | ||
| los.getLightSmoke() + los.getHeavySmoke(); | ||
| if (1 <= smokeLevel) { | ||
| // Smoke level doesn't necessarily correspond to the to-hit modifier | ||
| // even levels are light smoke, odd are heavy smoke | ||
|
|
@@ -2837,22 +2843,35 @@ void loadAmmo(final Entity shooter, | |
|
|
||
| final AmmoMounted suggestedAmmo = info.getAmmo(); | ||
| final AmmoMounted mountedAmmo = getPreferredAmmo(shooter, info.getTarget(), currentWeapon, suggestedAmmo); | ||
|
|
||
| if (mountedAmmo == null) { | ||
| continue; | ||
| } | ||
|
|
||
| // If the selected ammo would cause the shot to miss, skip loading it. | ||
| final WeaponAttackAction cloneWAA = new WeaponAttackAction(info.getAction()); | ||
| cloneWAA.setAmmoId(shooter.getEquipmentNum(mountedAmmo)); | ||
| cloneWAA.setAmmoMunitionType(((AmmoType) mountedAmmo.getType()).getMunitionType()); | ||
| cloneWAA.setAmmoCarrier(mountedAmmo.getEntity().getId()); | ||
| if (cloneWAA.toHit(owner.getGame(), owner.getPrecognition().getECMInfo()).getValue() > 12) { | ||
| logger.warn(shooter.getDisplayName() + " tried to load " | ||
| + currentWeapon.getName() + " with ammo " + | ||
| mountedAmmo.getDesc() + " but this would have caused it to miss; skipping."); | ||
|
Comment on lines
+2857
to
+2859
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warn should support varargs with %s. |
||
| continue; | ||
| } | ||
|
|
||
| // if we found preferred ammo but can't apply it to the weapon, log it and | ||
| // continue. | ||
| if ((null != mountedAmmo) && !shooter.loadWeapon(currentWeapon, mountedAmmo)) { | ||
| if (!shooter.loadWeapon(currentWeapon, mountedAmmo)) { | ||
| logger.warn(shooter.getDisplayName() + " tried to load " | ||
| + currentWeapon.getName() + " with ammo " + | ||
| mountedAmmo.getDesc() + " but failed somehow."); | ||
| continue; | ||
| // if we didn't find preferred ammo after all, continue | ||
| } else if (mountedAmmo == null) { | ||
| continue; | ||
| } | ||
| final WeaponAttackAction action = info.getAction(); | ||
| action.setAmmoId(shooter.getEquipmentNum(mountedAmmo)); | ||
| action.setAmmoMunitionType(((AmmoType) mountedAmmo.getType()).getMunitionType()); | ||
| action.setAmmoCarrier(mountedAmmo.getEntity().getId()); | ||
| info.setAction(action); | ||
|
|
||
| // If everything looks okay, replace the old WAA with the updated copy | ||
| info.setAction(cloneWAA); | ||
| owner.sendAmmoChange(info.getShooter().getId(), shooter.getEquipmentNum(currentWeapon), | ||
| shooter.getEquipmentNum(mountedAmmo), mountedAmmo.getSwitchedReason()); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.