Skip to content

Commit

Permalink
Add in external controls for using called shots on immobile targets
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperStucco authored and SuperStucco committed Jun 23, 2024
1 parent 506edb5 commit 6c3707a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Princess extends BotClient {
private static final char PLUS = '+';
Expand Down Expand Up @@ -152,6 +151,9 @@ public class Princess extends BotClient {
private List<Integer> enhancedTargetingTargetTypes;
private List<Integer> enhancedTargetingAttackerTypes;

// Controls whether Princess will use called shots on immobile targets
private boolean useCalledShotsOnImmobileTarget;

/**
* Returns a new Princess Bot with the given behavior and name, configured for the given
* host and port. The new Princess Bot outputs its settings to its own logger.
Expand Down Expand Up @@ -190,6 +192,9 @@ public Princess(final String name, final String host, final int port) {
UnitType.GUN_EMPLACEMENT
));

// Set default as not using called shots against immobile targets
useCalledShotsOnImmobileTarget = false;

// Start-up precog now, so that it can instantiate its game instance,
// and it will stay up-to date.
precognition = new Precognition(this);
Expand Down Expand Up @@ -701,7 +706,6 @@ protected void calculateFiringTurn() {
// rule to adjust the hit table to something more favorable.

boolean isCalledShot = false;
boolean immobileCalledShotsOK = false;
int locationDestruction = Integer.MAX_VALUE;
int aimLocation = Mech.LOC_NONE;
int calledShotDirection = CalledShot.CALLED_NONE;
Expand All @@ -720,12 +724,11 @@ protected void calculateFiringTurn() {
checkForEnhancedTargeting(shooter,
(Entity) primaryFire.getTarget(),
primaryFire.getToHit().getCover(),
false,
immobileCalledShotsOK)) {
false)) {

Mech mechTarget = (Mech) primaryFire.getTarget();
if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_CALLED_SHOTS) &&
(!mechTarget.isImmobile() || immobileCalledShotsOK)) {
(!mechTarget.isImmobile() || useCalledShotsOnImmobileTarget)) {
isCalledShot = true;
}

Expand Down Expand Up @@ -1149,6 +1152,14 @@ public boolean isValidEnhancedTargetingAttacker (int testType) {
}
}

public boolean getAllowCalledShotsOnImmobile () {
return useCalledShotsOnImmobileTarget;
}

public void setAllowCalledShotsOnImmobile(boolean newSetting) {
useCalledShotsOnImmobileTarget = newSetting;
}

/**
* Determine if a shooter should consider using enhanced targeting - aimed or called shots -
* against a given target. This includes some basic filtering for unit types and equipment such
Expand All @@ -1157,14 +1168,12 @@ public boolean isValidEnhancedTargetingAttacker (int testType) {
* @param target Entity being shot at
* @param cover {@link LosEffects} constant for partial cover, derived from {@code ToHitData.getCover()}
* @param partialCoverOK true, to permit shots against targets with partial cover
* @param immobileCalledShotsOK true, to permit called shots against immobile targets
* @return true, if aimed or called shots should be checked
*/
protected boolean checkForEnhancedTargeting (Entity shooter,
Entity target,
int cover,
boolean partialCoverOK,
boolean immobileCalledShotsOK) {
boolean partialCoverOK) {

// Partial cover adds all sorts of complications, don't bother unless enabled
if (cover != LosEffects.COVER_NONE && !partialCoverOK) {
Expand Down Expand Up @@ -1206,7 +1215,7 @@ protected boolean checkForEnhancedTargeting (Entity shooter,
if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_CALLED_SHOTS)) {
// Called shots against immobile targets can be a little too effective, so only use
// when enabled
if (!target.isImmobile() || immobileCalledShotsOK) {
if (!target.isImmobile() || useCalledShotsOnImmobileTarget) {
useCalledShot = true;
}
}
Expand Down

0 comments on commit 6c3707a

Please sign in to comment.