Skip to content
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 5870: princess engaging targets outside visual range in heavy fog #6457

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions megamek/src/megamek/client/bot/princess/FireControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public class FireControl {
static final TargetRollModifier TH_SWARM_STOPPED = new TargetRollModifier(TargetRoll.AUTOMATIC_SUCCESS,
"stops swarming");
static final TargetRollModifier TH_OUT_OF_RANGE = new TargetRollModifier(TargetRoll.IMPOSSIBLE, "out of range");
static final TargetRollModifier TH_OUT_OF_VISUAL = new TargetRollModifier(TargetRoll.IMPOSSIBLE, "out of visual targeting range");
static final TargetRollModifier TH_SHORT_RANGE = new TargetRollModifier(0, "Short Range");
static final TargetRollModifier TH_MEDIUM_RANGE = new TargetRollModifier(2, "Medium Range");
static final TargetRollModifier TH_LONG_RANGE = new TargetRollModifier(4, "Long Range");
Expand Down Expand Up @@ -305,6 +306,11 @@ ToHitData guessToHitModifierHelperForAnyAttack(final Entity shooter,
return new ToHitData(TH_RNG_TOO_FAR);
}

final int maxVisRange = game.getPlanetaryConditions().getVisualRange(shooter, shooter.isUsingSearchlight());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will Princess still be able to consider Entities illuminated by a different source as valid - like a different Mek with a searchlight illuminating the enemy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

She will, but for the fast approximation path she's only going to consider the current unit's searchlight state and any cached illumination state on target units.

This path is used when planning where to move a unit, not just for the moving unit but for predicting the likely actions of all known enemies and allies as well.
So I wanted to add the planetary environment check but keep it as minimal as possible to avoid introducing a big slowdown.

The attack planning code switches to using the same to-hit calc code as player sees when using the GUI; there should be fewer options at that point, so it's fast enough.
And that contains the full illumination check code.

if (distance > maxVisRange) {
return new ToHitData(TH_OUT_OF_VISUAL);
}

final ToHitData toHitData = new ToHitData();

// If people are moving or lying down, there are consequences
Expand Down
4 changes: 3 additions & 1 deletion megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,9 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
// c3 units can fire if any other unit in their network is in
// visual or sensor range
for (Entity en : game.getEntitiesVector()) {
if (!en.isEnemyOf(ae) && en.onSameC3NetworkAs(ae) && Compute.canSee(game, en, target)) {
// We got here because ae can't see the target, so we need a C3 buddy that _can_
// or there's no shot.
if (!en.isEnemyOf(ae) && en.onSameC3NetworkAs(ae) && Compute.canSee(game, en, target, false, null, null)) {
networkSee = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import java.util.Set;
import java.util.Vector;

import megamek.common.planetaryconditions.Atmosphere;
import megamek.common.planetaryconditions.PlanetaryConditions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -234,6 +236,11 @@ void beforeEach() {
when(mockGame.getOptions()).thenReturn(mockGameOptions);
when(mockGame.getBoard()).thenReturn(mockBoard);

// Base planetary conditions
PlanetaryConditions planetaryConditions = new PlanetaryConditions();
planetaryConditions.setAtmosphere(Atmosphere.STANDARD);
when(mockGame.getPlanetaryConditions()).thenReturn(planetaryConditions);

mockTarget = mock(BipedMek.class);
when(mockTarget.getDisplayName()).thenReturn("mock target");
when(mockTarget.getId()).thenReturn(MOCK_TARGET_ID);
Expand Down