Fix checks for range existence following 6bc99c47e1

Function introduced in 6bc99c47e1, GetRange can return undefined when
required component does not exist. Fixing two oversights, when check is
needed.

Differential Revision: https://code.wildfiregames.com/D2608
Fixes: #5666

This was SVN commit r23471.
This commit is contained in:
Angen 2020-01-31 20:00:06 +00:00
parent 8def60082d
commit 39bfd15aca

View file

@ -4739,6 +4739,8 @@ UnitAI.prototype.FaceTowardsTarget = function(target)
UnitAI.prototype.CheckTargetDistanceFromHeldPosition = function(target, iid, type)
{
let range = this.GetRange(iid, type);
if (!range)
return false;
let cmpPosition = Engine.QueryInterface(target, IID_Position);
if (!cmpPosition || !cmpPosition.IsInWorld())
@ -5809,6 +5811,8 @@ UnitAI.prototype.GetQueryRange = function(iid)
else if (this.GetStance().respondHoldGround)
{
let range = this.GetRange(iid);
if (!range)
return ret;
ret.max = Math.min(range.max + visionRange / 2, visionRange);
}
// We probably have stance 'passive' and we wouldn't have a range,
@ -5912,7 +5916,7 @@ UnitAI.prototype.GetRange = function(iid, type)
{
let component = Engine.QueryInterface(this.entity, iid);
if (!component)
return;
return undefined;
return component.GetRange(type);
}