Index: binaries/data/mods/public/simulation/components/Turretable.js =================================================================== --- binaries/data/mods/public/simulation/components/Turretable.js +++ binaries/data/mods/public/simulation/components/Turretable.js @@ -76,10 +76,7 @@ let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); if (cmpUnitAI) - { - cmpUnitAI.SetGarrisoned(); cmpUnitAI.SetTurretStance(); - } let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); if (cmpUnitMotion) @@ -138,7 +135,6 @@ if (cmpUnitAI) { cmpUnitAI.Ungarrison(); - cmpUnitAI.UnsetGarrisoned(); cmpUnitAI.ResetTurretStance(); } Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -3451,9 +3451,7 @@ UnitAI.prototype.IsTurret = function() { - if (!this.isGarrisoned) - return false; - let cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable); + const cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable); return cmpTurretable && cmpTurretable.HolderID() != INVALID_ENTITY; }; @@ -3868,9 +3866,8 @@ this.orderQueue.shift(); this.order = this.orderQueue[0]; - let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); if (this.orderQueue.length && (this.isGarrisoned || this.IsFormationController() || - cmpPosition && cmpPosition.IsInWorld())) + Engine.QueryInterface(this.entity, IID_Position)?.cmpPosition.IsInWorld())) { let ret = this.UnitFsm.ProcessMessage(this, { "type": "Order."+this.order.type, @@ -4157,15 +4154,15 @@ if (this.workOrders.length == 0) return false; + if (this.IsTurret()) + { + const cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable); + if (!cmpTurretable || !cmpTurretable.LeaveTurret()) + return false; + } if (this.isGarrisoned) { - if (this.IsTurret()) - { - let cmpTurretable = Engine.QueryInterface(this.entity, IID_Turretable); - if (!cmpTurretable || !cmpTurretable.LeaveTurret()) - return false; - } - let cmpGarrisonable = Engine.QueryInterface(this.entity, IID_Garrisonable); + const cmpGarrisonable = Engine.QueryInterface(this.entity, IID_Garrisonable); if (!cmpGarrisonable || !cmpGarrisonable.UnGarrison(false)) return false; } @@ -4870,16 +4867,19 @@ */ UnitAI.prototype.CheckTargetVisible = function(target) { - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + if (this.isGarrisoned) + return false; + + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership) return false; - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); if (!cmpRangeManager) return false; // Entities that are hidden and miraged are considered visible - var cmpFogging = Engine.QueryInterface(target, IID_Fogging); + const cmpFogging = Engine.QueryInterface(target, IID_Fogging); if (cmpFogging && cmpFogging.IsMiraged(cmpOwnership.GetOwner())) return true; @@ -5540,7 +5540,7 @@ UnitAI.prototype.Garrison = function(target, queued, pushFront) { // Not allowed to garrison when occupying a turret, at the moment. - if (this.isGarrisoned) + if (this.IsTurret()) return; if (target == this.entity) return; @@ -5557,7 +5557,7 @@ */ UnitAI.prototype.Ungarrison = function() { - if (!this.isGarrisoned) + if (!this.isGarrisoned && !this.IsTurret()) return; this.AddOrder("Ungarrison", null, false); }; @@ -5927,6 +5927,7 @@ UnitAI.prototype.SetTurretStance = function() { + this.SetImmobile(); this.previousStance = undefined; if (this.GetStance().respondStandGround) return; @@ -5942,6 +5943,7 @@ UnitAI.prototype.ResetTurretStance = function() { + this.SetMobile(); if (!this.previousStance) return; this.SwitchToStance(this.previousStance); Index: binaries/data/mods/public/simulation/components/tests/test_UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_UnitAI.js +++ binaries/data/mods/public/simulation/components/tests/test_UnitAI.js @@ -14,6 +14,7 @@ Engine.LoadComponentScript("interfaces/ResourceSupply.js"); Engine.LoadComponentScript("interfaces/ResourceGatherer.js"); Engine.LoadComponentScript("interfaces/Timer.js"); +Engine.LoadComponentScript("interfaces/Turretable.js"); Engine.LoadComponentScript("interfaces/UnitAI.js"); Engine.LoadComponentScript("Formation.js"); Engine.LoadComponentScript("UnitAI.js");