Improve Attack's GetBestAttackAgainst by only considering attack types that actually can attack the target.
Patch By: freagarach Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D2112 This was SVN commit r22569.
This commit is contained in:
parent
c03abd1e92
commit
9fcfdb0324
@ -408,20 +408,12 @@ Attack.prototype.GetBestAttackAgainst = function(target, allowCapture)
|
||||
if (isTargetClass("Domestic") && this.template.Slaughter)
|
||||
return "Slaughter";
|
||||
|
||||
let types = this.GetAttackTypes().filter(type => !this.GetRestrictedClasses(type).some(isTargetClass));
|
||||
let types = this.GetAttackTypes().filter(type => this.CanAttack(target, [type]));
|
||||
|
||||
// check if the target is capturable
|
||||
// Check whether the target is capturable and prefer that when it is allowed.
|
||||
let captureIndex = types.indexOf("Capture");
|
||||
if (captureIndex != -1)
|
||||
{
|
||||
let cmpCapturable = QueryMiragedInterface(target, IID_Capturable);
|
||||
|
||||
let cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
if (allowCapture && cmpPlayer && cmpCapturable && cmpCapturable.CanCapture(cmpPlayer.GetPlayerID()))
|
||||
if (captureIndex != -1 && allowCapture)
|
||||
return "Capture";
|
||||
// not capturable, so remove this attack
|
||||
types.splice(captureIndex, 1);
|
||||
}
|
||||
|
||||
let isPreferred = className => this.GetPreferredClasses(className).some(isTargetClass);
|
||||
|
||||
|
@ -205,7 +205,7 @@ attackComponentTest("Elephant", true, (attacker, cmpAttack, defender) => {
|
||||
TS_ASSERT_EQUALS(cmpAttack.CanAttack(defender), false);
|
||||
});
|
||||
|
||||
function testGetBestAttackAgainst(defenderClass, bestAttack, isBuilding = false)
|
||||
function testGetBestAttackAgainst(defenderClass, bestAttack, bestAllyAttack, isBuilding = false)
|
||||
{
|
||||
attackComponentTest(defenderClass, true, (attacker, cmpAttack, defender) => {
|
||||
|
||||
@ -259,21 +259,15 @@ function testGetBestAttackAgainst(defenderClass, bestAttack, isBuilding = false)
|
||||
if (!isBuilding)
|
||||
allowCapturing.push(false);
|
||||
|
||||
let attack;
|
||||
if (defenderClass == "Domestic")
|
||||
attack = "Slaughter";
|
||||
else if (defenderClass == "Structure")
|
||||
attack = "Capture";
|
||||
|
||||
for (let ac of allowCapturing)
|
||||
TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(defender, ac), bestAttack);
|
||||
TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(defender, ac), bestAllyAttack);
|
||||
});
|
||||
}
|
||||
|
||||
testGetBestAttackAgainst("FemaleCitizen", "Melee");
|
||||
testGetBestAttackAgainst("Archer", "Ranged");
|
||||
testGetBestAttackAgainst("Domestic", "Slaughter");
|
||||
testGetBestAttackAgainst("Structure", "Capture", true);
|
||||
testGetBestAttackAgainst("FemaleCitizen", "Melee", undefined);
|
||||
testGetBestAttackAgainst("Archer", "Ranged", undefined);
|
||||
testGetBestAttackAgainst("Domestic", "Slaughter", "Slaughter");
|
||||
testGetBestAttackAgainst("Structure", "Capture", "Capture", true);
|
||||
|
||||
function testPredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user