mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Filter out hidden targets in CanAttack
Units should not be able to attack entities with "hidden" visibility. Visible and fogged (mirage/retainInFog) targets remain attackable.
This commit is contained in:
parent
2447d8d01c
commit
274e3fd594
3 changed files with 13 additions and 1 deletions
|
|
@ -271,6 +271,15 @@ Attack.prototype.CanAttack = function(target, wantedTypes)
|
|||
if (!cmpTargetPlayer || !cmpEntityPlayer)
|
||||
return false;
|
||||
|
||||
// Must be visible or miraged / with retainInFog flag, not completely hidden
|
||||
const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
if (cmpRangeManager)
|
||||
{
|
||||
const visibility = cmpRangeManager.GetLosVisibility(target, cmpEntityPlayer.GetPlayerID());
|
||||
if (visibility == "hidden")
|
||||
return false;
|
||||
}
|
||||
|
||||
const types = this.GetAttackTypes(wantedTypes);
|
||||
const entityOwner = cmpEntityPlayer.GetPlayerID();
|
||||
const targetOwner = cmpTargetPlayer.GetPlayerID();
|
||||
|
|
|
|||
|
|
@ -6399,6 +6399,8 @@ UnitAI.prototype.GetQueryRange = function(iid)
|
|||
}
|
||||
else if (this.GetStance().respondChase)
|
||||
// Chase stances: use full vision range (unit will chase anything it sees)
|
||||
// Range being sometimes parabolic, it could extend beyond vision range,
|
||||
// which can cause vision range to limit the effective attack range.
|
||||
ret.max = visionRange;
|
||||
else if (this.GetStance().respondHoldGround)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ function attackComponentTest(defenderClass, isEnemy, test_function)
|
|||
|
||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, {
|
||||
"GetEffectiveParabolicRange": () => 25,
|
||||
"GetMaxParabolicHeightDiff": () => 15
|
||||
"GetMaxParabolicHeightDiff": () => 15,
|
||||
"GetLosVisibility": (target, owner) => "visible"
|
||||
});
|
||||
|
||||
const attacker = entityID;
|
||||
|
|
|
|||
Loading…
Reference in a new issue