-
Notifications
You must be signed in to change notification settings - Fork 291
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
Fix 5229: Multi-Trac units not firing energy weapons #5248
Merged
Sleet01
merged 3 commits into
MegaMek:master
from
Sleet01:Fix_5229_Multi-Trac_units_not_firing_energy_weapons
Mar 18, 2024
Merged
Changes from 2 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 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 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
import megamek.common.*; | ||
import megamek.common.options.OptionsConstants; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
|
||
/** | ||
|
@@ -78,6 +79,10 @@ public FiringPlan getBestFiringPlan(final Entity shooter, | |
|
||
if (currentPlan.getUtility() > bestPlan.getUtility()) { | ||
bestPlan = currentPlan; | ||
|
||
// Debug logging; Princess does her own info-level logging | ||
LogManager.getLogger().debug(shooter.getDisplayName() + " - Best Firing Plan: " + | ||
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. As per the other logging comment - this is in a loop so we want to eliminate it. |
||
bestPlan.getDebugDescription(true)); | ||
} | ||
|
||
// check the plan where the shooter flips its arms | ||
|
@@ -111,29 +116,39 @@ WeaponFireInfo getBestShot(Entity shooter, Mounted weapon) { | |
WeaponFireInfo bestShot = null; | ||
|
||
for (Targetable target : getTargetableEnemyEntities(shooter, owner.getGame(), owner.getFireControlState())) { | ||
WeaponFireInfo betterShot = null; | ||
final int ownerID = (target instanceof Entity) ? ((Entity) target).getOwnerId() : -1; | ||
if (owner.getHonorUtil().isEnemyBroken(target.getId(), ownerID, owner.getBehaviorSettings().isForcedWithdrawal())) { | ||
LogManager.getLogger().info(target.getDisplayName() + " is broken - ignoring"); | ||
continue; | ||
} | ||
|
||
ArrayList<Mounted> ammos; | ||
if (weapon.getBayWeapons().isEmpty()) { | ||
ammos = shooter.getAmmo(weapon); | ||
if (effectivelyAmmoless((WeaponType) weapon.getType())) { | ||
betterShot = buildWeaponFireInfo(shooter, target, weapon, null, owner.getGame(), false); | ||
} else { | ||
ammos = new ArrayList<>(); | ||
ammos.add(null); | ||
} | ||
ArrayList<Mounted> ammos; | ||
if (weapon.getBayWeapons().isEmpty()) { | ||
ammos = shooter.getAmmo(weapon); | ||
} else { | ||
ammos = new ArrayList<>(); | ||
ammos.add(null); | ||
} | ||
|
||
for (Mounted ammo: ammos) { | ||
WeaponFireInfo shot = buildWeaponFireInfo(shooter, target, weapon, ammo, owner.getGame(), false); | ||
for (Mounted ammo : ammos) { | ||
WeaponFireInfo shot = buildWeaponFireInfo(shooter, target, weapon, ammo, owner.getGame(), false); | ||
|
||
// this is a better shot if it has a chance of doing damage and the damage is better than the previous best shot | ||
if ((shot.getExpectedDamage() > 0) && | ||
((bestShot == null) || (shot.getExpectedDamage() > bestShot.getExpectedDamage()))) { | ||
bestShot = shot; | ||
// this is a better shot if it has a chance of doing damage and the damage is better than the previous best shot | ||
if ((shot.getExpectedDamage() > 0) && | ||
((betterShot == null) || (shot.getExpectedDamage() > betterShot.getExpectedDamage()))) { | ||
betterShot = shot; | ||
} | ||
} | ||
} | ||
// Now do the same comparison for the better shot of all these shots to determine the *best* shot | ||
if ((betterShot != null && betterShot.getExpectedDamage() > 0) && | ||
((bestShot == null) || (betterShot.getExpectedDamage() > bestShot.getExpectedDamage()))) { | ||
bestShot = betterShot; | ||
} | ||
} | ||
|
||
return bestShot; | ||
|
@@ -176,7 +191,7 @@ void calculateUtility(final FiringPlan firingPlan, | |
firingPlan.setUtility(utility); | ||
} | ||
|
||
FiringPlan calculateFiringPlan(Entity shooter, List<Mounted> weaponList) { | ||
protected FiringPlan calculateFiringPlan(Entity shooter, List<Mounted> weaponList) { | ||
FiringPlan retVal = new FiringPlan(); | ||
|
||
List<WeaponFireInfo> shotList = new ArrayList<>(); | ||
|
@@ -199,7 +214,7 @@ FiringPlan calculateFiringPlan(Entity shooter, List<Mounted> weaponList) { | |
retVal = calculateIndividualWeaponFiringPlan(shooter, shotList, shooterIsLarge); | ||
} | ||
|
||
calculateUtility(retVal, calcHeatTolerance(shooter, shooter.isAero()), true); | ||
calculateUtility(retVal, calcHeatTolerance(shooter, shooter.isAero()), shooter.isAero()); | ||
return retVal; | ||
} | ||
|
||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General optimization suggestion: for methods that are called many times, calling logging methods (especially within a loop) leads to a performance decrease, even if the logging level doesn't result in the message being logged. Let's make the adjustment to comment this out as we don't really need the info outside of direct debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just do the debug logging alongside the Princess-level .info() logging, which is once per unit per round.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. This particular logging is is once per unit per enemy per round. Granted, it's during the firing phase which doesn't really have performance issues usually, but still.