diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index 94fe950650..7815462b54 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -2101,7 +2101,12 @@ function findIdleUnit(classes) for (var i = 0; i < classes.length; ++i) { - var data = { idleClass: classes[currIdleClass], prevUnit: lastIdleUnit, limit: 1 }; + var data = { + "idleClass": classes[currIdleClass], + "prevUnit": lastIdleUnit, + "limit": 1, + "excludeUnits": [] + }; if (append) data.excludeUnits = g_Selection.toList(); @@ -2122,7 +2127,8 @@ function findIdleUnit(classes) { g_Selection.addList([lastIdleUnit]); var position = GetEntityState(lastIdleUnit).position; - Engine.CameraMoveTo(position.x, position.z); + if (position) + Engine.CameraMoveTo(position.x, position.z); return; } diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index dff6cedb81..079fc25f17 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -1738,40 +1738,29 @@ GuiInterface.prototype.PlaySound = function(player, data) PlaySound(data.name, data.entity); }; -function isIdleUnit(ent, idleClass) -{ - var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); - var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); - - // TODO: Do something with garrisoned idle units - return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned() && idleClass && cmpIdentity.HasClass(idleClass)); -}; - GuiInterface.prototype.FindIdleUnits = function(player, data) { - var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - var playerEntities = rangeMan.GetEntitiesByPlayer(player).filter( function(e) { + var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + var playerEntities = cmpRangeManager.GetEntitiesByPlayer(player).filter( function(e) { var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI); - if (cmpUnitAI) - return true; - return false; + if (!cmpUnitAI || !cmpUnitAI.IsIdle() || cmpUnitAI.IsGarrisoned()) + return false; + var cmpIdentity = Engine.QueryInterface(e, IID_Identity); + if (!cmpIdentity || !cmpIdentity.HasClass(data.idleClass)) + return false; + return true; }); var idleUnits = []; - var noFilter = (data.prevUnit == undefined && data.excludeUnits == undefined); for (var j = 0; j < playerEntities.length; ++j) { var ent = playerEntities[j]; - if (!isIdleUnit(ent, data.idleClass)) - continue; - if (noFilter || ((data.prevUnit == undefined || ent > data.prevUnit) && - (data.excludeUnits == undefined || data.excludeUnits.indexOf(ent) == -1))) - { - idleUnits.push(ent); - playerEntities.splice(j--, 1); - } + if (ent <= data.prevUnit|0 || data.excludeUnits.indexOf(ent) > -1) + continue; + idleUnits.push(ent); + playerEntities.splice(j--, 1); if (data.limit && idleUnits.length >= data.limit) break; diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 61023e1a27..d5ae55a32f 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -1636,7 +1636,7 @@ var UnitFsmSpec = { }, "Timer": function(msg) { - if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack)) + if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) { this.StopMoving(); this.FinishOrder(); @@ -1932,7 +1932,7 @@ var UnitFsmSpec = { }, "Timer": function(msg) { - if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack)) + if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Attack, this.order.data.attackType)) { this.StopMoving(); this.FinishOrder(); @@ -2330,7 +2330,7 @@ var UnitFsmSpec = { }, "Timer": function(msg) { - if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Heal)) + if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Heal, null)) { this.StopMoving(); this.FinishOrder(); @@ -2430,7 +2430,7 @@ var UnitFsmSpec = { this.StopTimer(); }, "Timer": function(msg) { - if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Heal)) + if (this.ShouldAbandonChase(this.order.data.target, this.order.data.force, IID_Heal, null)) { this.StopMoving(); this.FinishOrder(); @@ -4494,7 +4494,7 @@ UnitAI.prototype.RespondToHealableEntities = function(ents) /** * Returns true if we should stop following the target entity. */ -UnitAI.prototype.ShouldAbandonChase = function(target, force, iid) +UnitAI.prototype.ShouldAbandonChase = function(target, force, iid, type) { // Forced orders shouldn't be interrupted. if (force) @@ -4507,8 +4507,8 @@ UnitAI.prototype.ShouldAbandonChase = function(target, force, iid) var cmpAttack = Engine.QueryInterface(target, IID_Attack); if (cmpUnitAI && cmpAttack) { - for each (var type in cmpAttack.GetAttackTypes()) - if (cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)) + for each (var targetType in cmpAttack.GetAttackTypes()) + if (cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, targetType)) return false; } } @@ -4516,7 +4516,7 @@ UnitAI.prototype.ShouldAbandonChase = function(target, force, iid) // Stop if we're in hold-ground mode and it's too far from the holding point if (this.GetStance().respondHoldGround) { - if (!this.CheckTargetDistanceFromHeldPosition(target, iid, this.order.data.attackType)) + if (!this.CheckTargetDistanceFromHeldPosition(target, iid, type)) return true; }