Skip to content

Commit

Permalink
Add in external control for enabling enhanced targeting, change top-l…
Browse files Browse the repository at this point in the history
…evel target type from Mech to Entity
  • Loading branch information
SuperStucco authored and SuperStucco committed Jun 23, 2024
1 parent 048a0c1 commit 4a1db55
Showing 1 changed file with 55 additions and 25 deletions.
80 changes: 55 additions & 25 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ public class Princess extends BotClient {
// Track entities that fired an AMS manually this round
private List<Integer> manualAMSIds;

// Limits types of units Princess will target and attack with enhanced aiming (aimed/called shots)
// Master switch to enable/disable use of enhanced targeting system (aimed/called shots)
private boolean enableEnhancedTargeting;

// Limits types of units Princess will target and attack with enhanced targeting
private List<Integer> enhancedTargetingTargetTypes;
private List<Integer> enhancedTargetingAttackerTypes;

Expand Down Expand Up @@ -181,26 +184,8 @@ public Princess(final String name, final String host, final int port) {
fireControlState = new FireControlState();
pathRankerState = new PathRankerState();

// Set default enhanced targeting target and attacker types
enhancedTargetingTargetTypes = new ArrayList<>(Arrays.asList(
UnitType.MEK
));
enhancedTargetingAttackerTypes = new ArrayList<>(Arrays.asList(
UnitType.MEK,
UnitType.TANK,
UnitType.BATTLE_ARMOR,
UnitType.INFANTRY,
UnitType.PROTOMEK,
UnitType.VTOL,
UnitType.GUN_EMPLACEMENT
));

// 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;
// Set up enhanced targeting
resetEnhancedTargeting(true);

// Start-up precog now, so that it can instantiate its game instance,
// and it will stay up-to date.
Expand Down Expand Up @@ -732,14 +717,14 @@ protected void calculateFiringTurn() {
(Entity) primaryFire.getTarget(),
primaryFire.getToHit().getCover())) {

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

// Check for an aimed shot
if (mechTarget.isImmobile() || shooter.hasTargComp()) {
if (aimTarget.isImmobile() || shooter.hasTargComp()) {
boolean rearShot = primaryFire.getToHit().getSideTable() == ToHitData.SIDE_REAR;

// Get the Mech location to aim at. Infantry and BA will go for the head
Expand All @@ -750,7 +735,8 @@ protected void calculateFiringTurn() {
// When aiming at a location, don't bother checking for called shots
if (aimLocation != Mech.LOC_NONE) {
isCalledShot = false;
locationDestruction = mechTarget.getArmor(aimLocation, rearShot) + mechTarget.getInternal(aimLocation);
// TODO: this should be adjusted to better handle multiple target types
locationDestruction = aimTarget.getArmor(aimLocation, rearShot) + aimTarget.getInternal(aimLocation);
}

}
Expand Down Expand Up @@ -1091,7 +1077,47 @@ protected Vector<Minefield> calculateMinefieldDeployment() {



// Enhanced targeting controls

public boolean getEnhancedTargetingControl () {
return enableEnhancedTargeting;
}

public void setEnableEnhancedTargeting (boolean newSetting) {
enableEnhancedTargeting = newSetting;
}

/**
* Sets all enhanced targeting controls to default values and optionally enables its use
* @param enable true to immediately enable enhanced targeting features after reset
*/
public void resetEnhancedTargeting (boolean enable) {

// Toggle enhanced targeting
enableEnhancedTargeting = enable;

// Set default enhanced targeting target and attacker types
enhancedTargetingTargetTypes = new ArrayList<>(Arrays.asList(
UnitType.MEK
));
enhancedTargetingAttackerTypes = new ArrayList<>(Arrays.asList(
UnitType.MEK,
UnitType.TANK,
UnitType.BATTLE_ARMOR,
UnitType.INFANTRY,
UnitType.PROTOMEK,
UnitType.VTOL,
UnitType.GUN_EMPLACEMENT
));

// 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;

}

/**
* Swap out current set of valid enhanced targeting target types for a new set. Automatically
Expand Down Expand Up @@ -1193,6 +1219,10 @@ protected boolean checkForEnhancedTargeting (Entity shooter,
Entity target,
int cover) {

if (!enableEnhancedTargeting) {
return false;
}

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

0 comments on commit 4a1db55

Please sign in to comment.