Skip to content

Commit

Permalink
Add in external controls for filtering out targets with partial cover
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperStucco authored and SuperStucco committed Jun 23, 2024
1 parent 6c3707a commit 048a0c1
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public class Princess extends BotClient {
// Controls whether Princess will use called shots on immobile targets
private boolean useCalledShotsOnImmobileTarget;

// Controls whether Princess will use enhanced targeting on targets that have partial cover
private boolean allowCoverEnhancedTargeting;

/**
* 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 @@ -195,6 +198,10 @@ public Princess(final String name, final String host, final int port) {
// Set default as not using called shots against immobile targets
useCalledShotsOnImmobileTarget = false;

// Set default as not allowing enhanced targeting if the target has partial cover.
// This prevents all sorts of issues, such as aiming for locations that are covered.
allowCoverEnhancedTargeting = 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 @@ -723,8 +730,7 @@ protected void calculateFiringTurn() {
plan.stream().allMatch(curFire -> primaryFire.getTarget().getId() == targetID) &&
checkForEnhancedTargeting(shooter,
(Entity) primaryFire.getTarget(),
primaryFire.getToHit().getCover(),
false)) {
primaryFire.getToHit().getCover())) {

Mech mechTarget = (Mech) primaryFire.getTarget();
if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_CALLED_SHOTS) &&
Expand Down Expand Up @@ -1156,27 +1162,39 @@ public boolean getAllowCalledShotsOnImmobile () {
return useCalledShotsOnImmobileTarget;
}

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

public boolean getPartialCoverEnhancedTargeting () {
return allowCoverEnhancedTargeting;
}

/**
* Controls whether enhanced targeting will be used against targets with partial cover from
* the shooter. Use with caution as this can result in situations like aiming for a location
* which is protected by intervening cover.
* @param newSetting true, to allow aimed/called shots against targets with partial cover
*/
public void setPartialCoverEnhancedTargeting (boolean newSetting) {
allowCoverEnhancedTargeting = 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
* targeting computers.
* @param shooter Entity doing the shooting
* @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
* @return true, if aimed or called shots should be checked
*/
protected boolean checkForEnhancedTargeting (Entity shooter,
Entity target,
int cover,
boolean partialCoverOK) {
int cover) {

// Partial cover adds all sorts of complications, don't bother unless enabled
if (cover != LosEffects.COVER_NONE && !partialCoverOK) {
if (cover != LosEffects.COVER_NONE && !allowCoverEnhancedTargeting) {
return false;
}

Expand Down

0 comments on commit 048a0c1

Please sign in to comment.