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
626c91e02b
commit
402de88f25
2 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();
|
||||
|
|
|
|||
|
|
@ -6397,8 +6397,11 @@ UnitAI.prototype.GetQueryRange = function(iid)
|
|||
// before actually attacking.
|
||||
ret.parabolic = range.parabolic;
|
||||
}
|
||||
// In other stances, don't make the range parabolic, since they use vision/approach ranges
|
||||
// that are larger than attack range, so targets will be spotted as they chase/approach anyway.
|
||||
// TODO: With large height differences, the effective parabolic attack range can exceed
|
||||
// vision/approach ranges, causing targets to be spotted later than ideal.
|
||||
else if (this.GetStance().respondChase)
|
||||
// Chase stances: use full vision range (unit will chase anything it sees)
|
||||
ret.max = visionRange;
|
||||
else if (this.GetStance().respondHoldGround)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue