Fix Capture oversight in GetBestAttackAgainst in 9fcfdb0324

This fixes units always using capture attack on a building, since
rp22569 forgot to eliminate Capture from the attack types when not
allowed.

Reported by: minohaka
Patch by: Freagarach
Reviewed by: wraitii
Fixes #5544

Differential Revision: https://code.wildfiregames.com/D2134
This was SVN commit r22575.
This commit is contained in:
wraitii 2019-07-29 18:51:50 +00:00
parent 82f1d2718b
commit fee7dba38f
2 changed files with 7 additions and 2 deletions

View file

@ -412,8 +412,12 @@ Attack.prototype.GetBestAttackAgainst = function(target, allowCapture)
// Check whether the target is capturable and prefer that when it is allowed.
let captureIndex = types.indexOf("Capture");
if (captureIndex != -1 && allowCapture)
return "Capture";
if (captureIndex != -1)
{
if (allowCapture)
return "Capture";
types.splice(captureIndex, 1);
}
let isPreferred = className => this.GetPreferredClasses(className).some(isTargetClass);

View file

@ -268,6 +268,7 @@ testGetBestAttackAgainst("FemaleCitizen", "Melee", undefined);
testGetBestAttackAgainst("Archer", "Ranged", undefined);
testGetBestAttackAgainst("Domestic", "Slaughter", "Slaughter");
testGetBestAttackAgainst("Structure", "Capture", "Capture", true);
testGetBestAttackAgainst("Structure", "Ranged", undefined, false);
function testPredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity)
{