Skip to content

Commit

Permalink
fix: merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Feb 4, 2025
1 parent 918cfca commit 54b383d
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 61 deletions.
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/bot/ChatProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
}

String hex = arguments[0];
if (!StringUtil.isPositiveInteger(hex) && (hex.length() % 2 == 1)) {
if (!StringUtil.isPositiveInteger(hex) || (hex.length() % 2 == 1)) {
msg = "Invalid hex number: " + hex;
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ public double getBonusFactor() {
}

public double getExpectedDamage() {
return cacheDamage().takenDamage();
return cacheDamage().takenDamage;
}

public double getTotalDamage() {
return cacheDamage().getMaximumDamageEstimate();
}

public double getFiringDamage() {
return cacheDamage().firingDamage();
return cacheDamage().firingDamage;
}

public double getPhysicalDamage() {
return cacheDamage().physicalDamage();
return cacheDamage().physicalDamage;
}

private FiringPhysicalDamage cacheDamage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public FiringPhysicalDamage damageCalculator(MovePath path, List<Entity> enemies
EntityEvaluationResponse eval = evaluateEnemy(enemy, path, pathCopy, extremeRange, losRange);

if (!owner.getBehaviorSettings().getIgnoredUnitTargets().contains(enemy.getId())) {
damageEstimate = updateDamageEstimate(damageEstimate, eval);
updateDamageEstimate(damageEstimate, eval);
}

expectedDamageTaken += eval.getEstimatedEnemyDamage();
Expand All @@ -66,11 +66,10 @@ public FiringPhysicalDamage damageCalculator(MovePath path, List<Entity> enemies
damageEstimate = calcDamageToStrategicTargets(pathCopy, game, owner.getFireControlState(), damageEstimate);

if (shouldDisablePhysicalDamage(path)) {
damageEstimate = damageEstimate.withPhysicalDamage(0);
damageEstimate.physicalDamage = 0;
}

return new FiringPhysicalDamage().withTakenDamage(expectedDamageTaken).withFiringDamage(damageEstimate.firingDamage())
.withPhysicalDamage(damageEstimate.physicalDamage());
return new FiringPhysicalDamage(damageEstimate.firingDamage, damageEstimate.physicalDamage, expectedDamageTaken);
}

private boolean shouldSkipEnemy(Entity enemy) {
Expand All @@ -86,14 +85,13 @@ private EntityEvaluationResponse evaluateEnemy(Entity enemy, MovePath path, Move
}
}

private FiringPhysicalDamage updateDamageEstimate(FiringPhysicalDamage damageEstimate, EntityEvaluationResponse eval) {
if (damageEstimate.firingDamage() < eval.getMyEstimatedDamage()) {
damageEstimate = damageEstimate.withFiringDamage(eval.getMyEstimatedDamage());
private void updateDamageEstimate(FiringPhysicalDamage damageEstimate, EntityEvaluationResponse eval) {
if (damageEstimate.firingDamage < eval.getMyEstimatedDamage()) {
damageEstimate.firingDamage = eval.getMyEstimatedDamage();
}
if (damageEstimate.physicalDamage() < eval.getMyEstimatedPhysicalDamage()) {
damageEstimate = damageEstimate.withPhysicalDamage(eval.getMyEstimatedPhysicalDamage());
if (damageEstimate.physicalDamage < eval.getMyEstimatedPhysicalDamage()) {
damageEstimate.physicalDamage = eval.getMyEstimatedPhysicalDamage();
}
return damageEstimate;
}

private double calculateFriendlyArtilleryDamage(MovePath path) {
Expand Down
32 changes: 13 additions & 19 deletions megamek/src/megamek/client/bot/princess/BasicPathRanker.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import megamek.client.bot.princess.BotGeometry.CoordFacingCombo;
import megamek.client.bot.princess.BotGeometry.HexLine;
import megamek.client.bot.princess.UnitBehavior.BehaviorType;
import megamek.codeUtilities.MathUtility;
import megamek.common.*;
import megamek.common.options.OptionsConstants;
import megamek.common.planetaryconditions.PlanetaryConditions;
Expand Down Expand Up @@ -63,13 +62,8 @@ public class BasicPathRanker extends PathRanker {
protected int blackIce = -1;

public BasicPathRanker(Princess owningPrincess) {
this(owningPrincess, owningPrincess.getPrecognition().getPathEnumerator());
}

public BasicPathRanker(Princess owningPrincess, PathEnumerator pathEnumerator) {
super(owningPrincess);
bestDamageByEnemies = new TreeMap<>();
this.pathEnumerator = pathEnumerator;
logger.debug("Using %s behavior.", getOwner().getBehaviorSettings().getDescription());
}

Expand Down Expand Up @@ -102,9 +96,9 @@ boolean isInMyLoS(Entity unit, HexLine leftBounds, HexLine rightBounds) {
&& (rightBounds.judgeArea(pathEnumerator.getUnitMovableAreas().get(unit.getId())) < 0);
}

double getMaxDamageAtRange(FireControl fireControl, Entity shooter, int range, boolean useExtremeRange,
double getMaxDamageAtRange(Entity shooter, int range, boolean useExtremeRange,
boolean useLOSRange) {
return fireControl.getMaxDamageAtRange(shooter, range, useExtremeRange, useLOSRange);
return FireControl.getMaxDamageAtRange(shooter, range, useExtremeRange, useLOSRange);
}

boolean canFlankAndKick(Entity enemy, Coords behind, Coords leftFlank, Coords rightFlank, int myFacing) {
Expand Down Expand Up @@ -173,7 +167,7 @@ public EntityEvaluationResponse evaluateUnmovedEnemy(Entity enemy, MovePath path

if (isInMyLoS(enemy, leftBounds, rightBounds)) {
returnResponse.addToMyEstimatedDamage(
getMaxDamageAtRange(getFireControl(path.getEntity()),
getMaxDamageAtRange(
path.getEntity(),
range,
useExtremeRange,
Expand All @@ -182,7 +176,7 @@ public EntityEvaluationResponse evaluateUnmovedEnemy(Entity enemy, MovePath path

// in general if an enemy can end its position in range, it can hit me
returnResponse.addToEstimatedEnemyDamage(
getMaxDamageAtRange(getFireControl(enemy),
getMaxDamageAtRange(
enemy,
range,
useExtremeRange,
Expand Down Expand Up @@ -551,11 +545,11 @@ protected RankedPath rankPath(MovePath path, Game game, int maxRange, double fal
// however, just because we're ignoring them doesn't mean they won't shoot at
// us.
if (!getOwner().getBehaviorSettings().getIgnoredUnitTargets().contains(enemy.getId())) {
if (damageEstimate.firingDamage() < eval.getMyEstimatedDamage()) {
damageEstimate = damageEstimate.withFiringDamage(eval.getMyEstimatedDamage());
if (damageEstimate.firingDamage < eval.getMyEstimatedDamage()) {
damageEstimate.firingDamage = eval.getMyEstimatedDamage();
}
if (damageEstimate.physicalDamage() < eval.getMyEstimatedPhysicalDamage()) {
damageEstimate = damageEstimate.withFiringDamage(eval.getMyEstimatedPhysicalDamage());
if (damageEstimate.physicalDamage < eval.getMyEstimatedPhysicalDamage()) {
damageEstimate.physicalDamage = eval.getMyEstimatedPhysicalDamage();
}
}

Expand Down Expand Up @@ -585,7 +579,7 @@ protected RankedPath rankPath(MovePath path, Game game, int maxRange, double fal
// is enabled, set maximum physical damage for this path to zero.
if (game.getOptions().booleanOption(OptionsConstants.ALLOWED_NO_CLAN_PHYSICAL)
&& path.getEntity().getCrew().isClanPilot()) {
damageEstimate = damageEstimate.withPhysicalDamage(0);
damageEstimate.physicalDamage = 0;
}

// I can kick a different target than I shoot, so add physical to
Expand Down Expand Up @@ -766,8 +760,8 @@ public FiringPhysicalDamage calcDamageToStrategicTargets(MovePath path, Game gam
FiringPlan myFiringPlan = getFireControl(path.getEntity()).determineBestFiringPlan(guess);

double myDamagePotential = myFiringPlan.getUtility();
if (myDamagePotential > damageStructure.firingDamage()) {
damageStructure = damageStructure.withFiringDamage(myDamagePotential);
if (myDamagePotential > damageStructure.firingDamage) {
damageStructure.firingDamage = myDamagePotential;
}

if (path.getEntity() instanceof Mek) {
Expand All @@ -778,8 +772,8 @@ PhysicalAttackType.RIGHT_KICK, game, getOwner(),
true);
double expectedKickDamage = myKick.getExpectedDamageOnHit() *
myKick.getProbabilityToHit();
if (expectedKickDamage > damageStructure.physicalDamage()) {
damageStructure = damageStructure.withPhysicalDamage(expectedKickDamage);
if (expectedKickDamage > damageStructure.physicalDamage) {
damageStructure.physicalDamage = expectedKickDamage;
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions megamek/src/megamek/client/bot/princess/FiringPhysicalDamage.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package megamek.client.bot.princess;

public record FiringPhysicalDamage(double firingDamage, double physicalDamage, double takenDamage) {
public FiringPhysicalDamage() {
this(0, 0, 0);
}
public class FiringPhysicalDamage {
public double firingDamage;
public double physicalDamage;
public double takenDamage;

public FiringPhysicalDamage withFiringDamage(double firingDamage) {
return new FiringPhysicalDamage(firingDamage, physicalDamage, takenDamage);
}

public FiringPhysicalDamage withPhysicalDamage(double physicalDamage) {
return new FiringPhysicalDamage(firingDamage, physicalDamage, takenDamage);
public FiringPhysicalDamage() {
firingDamage = 0;
physicalDamage = 0;
takenDamage = 0;
}

public FiringPhysicalDamage withTakenDamage(double takenDamage) {
return new FiringPhysicalDamage(firingDamage, physicalDamage, takenDamage);
public FiringPhysicalDamage(double firingDamage, double physicalDamage, double takenDamage) {
this.firingDamage = firingDamage;
this.physicalDamage = physicalDamage;
this.takenDamage = takenDamage;
}

public double getMaximumDamageEstimate() {
return firingDamage + physicalDamage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ protected RankedPath rankPath(MovePath path, Game game, int maxRange, double fal
eval = evaluateUnmovedEnemy(enemy, pathCopy, extremeRange, losRange);
}

if (damageEstimate.firingDamage() < eval.getMyEstimatedDamage()) {
damageEstimate = damageEstimate.withFiringDamage(eval.getMyEstimatedDamage());
if (damageEstimate.firingDamage < eval.getMyEstimatedDamage()) {
damageEstimate.firingDamage = eval.getMyEstimatedDamage();
}

expectedDamageTaken += eval.getEstimatedEnemyDamage();
}

calcDamageToStrategicTargets(pathCopy, game, getOwner().getFireControlState(), damageEstimate);
double maximumDamageDone = damageEstimate.firingDamage();
double maximumDamageDone = damageEstimate.firingDamage;

// My bravery modifier is based on my chance of getting to the
// firing position (successProbability), how much damage I can do
Expand Down Expand Up @@ -144,7 +144,7 @@ protected RankedPath rankPath(MovePath path, Game game, int maxRange, double fal
}

@Override
EntityEvaluationResponse evaluateUnmovedEnemy(Entity enemy, MovePath path, boolean useExtremeRange, boolean useLOSRange) {
public EntityEvaluationResponse evaluateUnmovedEnemy(Entity enemy, MovePath path, boolean useExtremeRange, boolean useLOSRange) {
//some preliminary calculations
final double damageDiscount = 0.25;
EntityEvaluationResponse returnResponse =
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/bot/princess/PathRanker.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected double getMovePathSuccessProbability(MovePath movePath) {
* @param path
* @return
*/
protected double calculateMovePathPSRDamage(Entity movingEntity, MovePath path) {
public double calculateMovePathPSRDamage(Entity movingEntity, MovePath path) {
double damage = 0.0;

List<TargetRoll> pilotingRolls = getPSRList(path);
Expand Down
3 changes: 3 additions & 0 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2728,12 +2728,15 @@ public void initializePathRankers() {
pathRankers = new HashMap<>();

BasicPathRanker basicPathRanker = new BasicPathRanker(this);
basicPathRanker.setPathEnumerator(getPrecognition().getPathEnumerator());
pathRankers.put(PathRankerType.Basic, basicPathRanker);

InfantryPathRanker infantryPathRanker = new InfantryPathRanker(this);
infantryPathRanker.setPathEnumerator(getPrecognition().getPathEnumerator());
pathRankers.put(PathRankerType.Infantry, infantryPathRanker);

NewtonianAerospacePathRanker newtonianAerospacePathRanker = new NewtonianAerospacePathRanker(this);
newtonianAerospacePathRanker.setPathEnumerator(getPrecognition().getPathEnumerator());
pathRankers.put(PathRankerType.NewtonianAerospace, newtonianAerospacePathRanker);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void testEvaluateUnmovedAeroEnemy() {
final Entity mockMyUnit = MockGenerators.generateMockBipedMek(0, 0);
when(mockMyUnit.canChangeSecondaryFacing()).thenReturn(true);

doReturn(10.0).when(testRanker).getMaxDamageAtRange(nullable(FireControl.class),
doReturn(10.0).when(testRanker).getMaxDamageAtRange(
eq(mockMyUnit), anyInt(), anyBoolean(), anyBoolean());

final MovePath mockPath = MockGenerators.generateMockPath(testCoords, mockMyUnit);
Expand All @@ -207,7 +207,7 @@ void testEvaluateUnmovedEnemyInLOSAndUnableToKick() {
final Entity mockMyUnit = MockGenerators.generateMockBipedMek(0, 0);
when(mockMyUnit.canChangeSecondaryFacing()).thenReturn(true);

doReturn(10.0).when(testRanker).getMaxDamageAtRange(nullable(FireControl.class),
doReturn(10.0).when(testRanker).getMaxDamageAtRange(
eq(mockMyUnit), anyInt(), anyBoolean(), anyBoolean());

final MovePath mockPath = MockGenerators.generateMockPath(testCoords, mockMyUnit);
Expand All @@ -226,7 +226,7 @@ void testEvaluateUnmovedEnemyInLOSAndUnableToKick() {
.isInMyLoS(eq(mockEnemyMek), any(HexLine.class), any(HexLine.class));
doReturn(8.5)
.when(testRanker)
.getMaxDamageAtRange(nullable(FireControl.class), eq(mockEnemyMek), anyInt(),
.getMaxDamageAtRange(eq(mockEnemyMek), anyInt(),
anyBoolean(),
anyBoolean());
doReturn(false)
Expand All @@ -252,7 +252,7 @@ void testEvaluateUnmovedEnemyNotInLOS() {
final Entity mockMyUnit = MockGenerators.generateMockBipedMek(0, 0);
when(mockMyUnit.canChangeSecondaryFacing()).thenReturn(true);

doReturn(10.0).when(testRanker).getMaxDamageAtRange(nullable(FireControl.class),
doReturn(10.0).when(testRanker).getMaxDamageAtRange(
eq(mockMyUnit), anyInt(), anyBoolean(), anyBoolean());

final MovePath mockPath = MockGenerators.generateMockPath(testCoords, mockMyUnit);
Expand All @@ -271,7 +271,7 @@ void testEvaluateUnmovedEnemyNotInLOS() {
.isInMyLoS(eq(mockEnemyMek), any(HexLine.class), any(HexLine.class));
doReturn(8.5)
.when(testRanker)
.getMaxDamageAtRange(nullable(FireControl.class), eq(mockEnemyMek), anyInt(),
.getMaxDamageAtRange(eq(mockEnemyMek), anyInt(),
anyBoolean(), anyBoolean());
doReturn(false)
.when(testRanker)
Expand All @@ -294,7 +294,7 @@ void testEvaluateUnmovedEnemyNotInLOSAndAbleToKick() {
final Entity mockMyUnit = MockGenerators.generateMockBipedMek(0, 0);
when(mockMyUnit.canChangeSecondaryFacing()).thenReturn(true);

doReturn(10.0).when(testRanker).getMaxDamageAtRange(nullable(FireControl.class),
doReturn(10.0).when(testRanker).getMaxDamageAtRange(
eq(mockMyUnit), anyInt(), anyBoolean(), anyBoolean());

final MovePath mockPath = MockGenerators.generateMockPath(testCoords, mockMyUnit);
Expand All @@ -313,7 +313,7 @@ void testEvaluateUnmovedEnemyNotInLOSAndAbleToKick() {
.isInMyLoS(eq(mockEnemyMek), any(HexLine.class), any(HexLine.class));
doReturn(8.5)
.when(testRanker)
.getMaxDamageAtRange(nullable(FireControl.class), eq(mockEnemyMek), anyInt(),
.getMaxDamageAtRange(eq(mockEnemyMek), anyInt(),
anyBoolean(), anyBoolean());
doReturn(true)
.when(testRanker)
Expand Down
22 changes: 19 additions & 3 deletions megamek/unittests/megamek/logging/MMLoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,33 @@ public void testDebugLoggingWithException() {

@Test
public void testErrorLogging() {
if (GraphicsEnvironment.isHeadless()) {
// Skip this test if running in headless mode
return;
}
automaticallyDismissDialog();
testMMLogger.errorDialog("test", "Error message: %s", "test");
verifyLog(Level.ERROR, "Error message: test");
}

@Test

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
MMLogger.error
should be avoided because it has been deprecated.
public void testErrorLoggingWithExceptionNoParams() {
if (GraphicsEnvironment.isHeadless()) {
// Skip this test if running in headless mode
return;
}
automaticallyDismissDialog();
Exception e = new Exception("Test exception");
testMMLogger.error(e, "Error message: noparameter accepted", "test");
verifyLog(Level.ERROR, "Error message: test", e);
verifyLog(Level.ERROR, "Error message: noparameter accepted", e);
}

@Test
public void testErrorLoggingWithException() {
if (GraphicsEnvironment.isHeadless()) {
// Skip this test if running in headless mode
return;
}
automaticallyDismissDialog();
Exception e = new Exception("Test exception");
testMMLogger.errorDialog(e, "Error message: {}", "test", "test");
Expand All @@ -108,9 +120,13 @@ public void testFatalLogging() {

@Test
public void testFatalLoggingWithDialog() {
if (GraphicsEnvironment.isHeadless()) {
// Skip this test if running in headless mode
return;
}
automaticallyDismissDialog();
testMMLogger.fatalDialog("Fatal with dialog without exception", "Fatal dialog title");
verifyLog(Level.FATAL, "Fatal without dialog without exception");
testMMLogger.fatalDialog("Fatal with dialog with exception", "Fatal dialog title");
verifyLog(Level.FATAL, "Fatal with dialog with exception");
}

@Test
Expand Down

0 comments on commit 54b383d

Please sign in to comment.