Index: ps/trunk/binaries/data/mods/public/simulation/components/Attack.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Attack.js +++ ps/trunk/binaries/data/mods/public/simulation/components/Attack.js @@ -408,20 +408,12 @@ 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())) - return "Capture"; - // not capturable, so remove this attack - types.splice(captureIndex, 1); - } + if (captureIndex != -1 && allowCapture) + return "Capture"; let isPreferred = className => this.GetPreferredClasses(className).some(isTargetClass); Index: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Attack.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Attack.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Attack.js @@ -205,7 +205,7 @@ 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 @@ 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) {