From 048a0c1475775b94d0c4cd9b66c0f8e67f66a4db Mon Sep 17 00:00:00 2001 From: SuperStucco Date: Sun, 23 Jun 2024 14:41:16 -0600 Subject: [PATCH] Add in external controls for filtering out targets with partial cover --- .../megamek/client/bot/princess/Princess.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/megamek/src/megamek/client/bot/princess/Princess.java b/megamek/src/megamek/client/bot/princess/Princess.java index 72a98df14a2..5f7eca9e05d 100644 --- a/megamek/src/megamek/client/bot/princess/Princess.java +++ b/megamek/src/megamek/client/bot/princess/Princess.java @@ -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. @@ -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); @@ -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) && @@ -1156,10 +1162,24 @@ 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 @@ -1167,16 +1187,14 @@ public void setAllowCalledShotsOnImmobile(boolean newSetting) { * @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; }