Index: binaries/data/mods/public/simulation/components/GarrisonHolder.js =================================================================== --- binaries/data/mods/public/simulation/components/GarrisonHolder.js +++ binaries/data/mods/public/simulation/components/GarrisonHolder.js @@ -264,6 +264,10 @@ if (cmpProductionQueue) cmpProductionQueue.PauseProduction(); + let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); + if (cmpUnitAI) + cmpUnitAI.SetGarrisoned(true); + let cmpAura = Engine.QueryInterface(entity, IID_Auras); if (cmpAura && cmpAura.HasGarrisonAura()) cmpAura.ApplyGarrisonAura(this.entity); @@ -328,7 +332,10 @@ } if (cmpEntUnitAI) + { cmpEntUnitAI.Ungarrison(); + cmpEntUnitAI.SetGarrisoned(false); + } let cmpEntProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); if (cmpEntProductionQueue) 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 @@ -613,7 +613,7 @@ this.SetNextState("IDLE"); return; } - else if (this.IsGarrisoned()) + else if (this.isGarrisoned) { this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); return; @@ -633,7 +633,6 @@ "Order.Ungarrison": function() { this.FinishOrder(); - this.isGarrisoned = false; }, "Order.Cheering": function(msg) { @@ -2898,7 +2897,7 @@ return true; } - if (this.IsGarrisoned()) + if (this.isGarrisoned) return false; // Check that we can garrison here @@ -2910,8 +2909,6 @@ // Check that garrisoning succeeds if (cmpGarrisonHolder.Garrison(this.entity)) { - this.isGarrisoned = true; - if (this.formationController) { var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); @@ -3249,7 +3246,7 @@ UnitAI.prototype.IsTurret = function() { - if (!this.IsGarrisoned()) + if (!this.isGarrisoned) return false; var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); return cmpPosition && cmpPosition.GetTurretParent() != INVALID_ENTITY; @@ -3302,19 +3299,27 @@ return this.isIdle; }; +/** + * Whether the entity is garrisoned (according to UnitAI). + * This is only called from outside UnitAI for performance reasons, + * if in the future it should return anything else than just the member all calls to + * this.isGarrisoned here in UnitAI ought to be updated. + * + * @return {boolean} Whether the entity is garrisoned. + */ UnitAI.prototype.IsGarrisoned = function() { return this.isGarrisoned; }; -UnitAI.prototype.SetGarrisoned = function() +UnitAI.prototype.SetGarrisoned = function(garrisoned) { - this.isGarrisoned = true; + this.isGarrisoned = garrisoned; }; UnitAI.prototype.GetGarrisonHolder = function() { - if (this.IsGarrisoned()) + if (this.isGarrisoned) { for (let order of this.orderQueue) if (order.type == "Garrison") @@ -3577,7 +3582,7 @@ this.order = this.orderQueue[0]; let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); - if (this.orderQueue.length && (this.IsGarrisoned() || cmpPosition && cmpPosition.IsInWorld())) + if (this.orderQueue.length && (this.isGarrisoned || cmpPosition && cmpPosition.IsInWorld())) { let ret = this.UnitFsm.ProcessMessage(this, { "type": "Order."+this.order.type, "data": this.order.data } @@ -3724,7 +3729,7 @@ this.UpdateWorkOrders(type); } - let garrisonHolder = this.IsGarrisoned() && type != "Ungarrison" ? this.GetGarrisonHolder() : null; + let garrisonHolder = this.isGarrisoned && type != "Ungarrison" ? this.GetGarrisonHolder() : null; // Special cases of orders that shouldn't be replaced: // 1. Cheering - we're invulnerable, add order after we finish @@ -3822,7 +3827,7 @@ if (this.workOrders.length == 0) return false; - if (this.IsGarrisoned()) + if (this.isGarrisoned) { let cmpGarrisonHolder = Engine.QueryInterface(this.GetGarrisonHolder(), IID_GarrisonHolder); if (!cmpGarrisonHolder || !cmpGarrisonHolder.PerformEject([this.entity], false)) @@ -4892,7 +4897,7 @@ { // May happen if an order arrives on the same turn the unit is garrisoned // in that case, just forget the order as this will lead to an infinite loop - if (this.IsGarrisoned() && !this.IsTurret() && type != "Ungarrison") + if (this.isGarrisoned && !this.IsTurret() && type != "Ungarrison") return; this.ReplaceOrder(type, data); } @@ -5118,7 +5123,7 @@ */ UnitAI.prototype.Ungarrison = function() { - if (this.IsGarrisoned()) + if (this.isGarrisoned) this.AddOrder("Ungarrison", null, false); }; @@ -5127,7 +5132,6 @@ */ UnitAI.prototype.Autogarrison = function(target) { - this.isGarrisoned = true; this.PushOrderFront("Garrison", { "target": target }); }; Index: binaries/data/mods/public/simulation/helpers/Transform.js =================================================================== --- binaries/data/mods/public/simulation/helpers/Transform.js +++ binaries/data/mods/public/simulation/helpers/Transform.js @@ -74,7 +74,7 @@ } } if (cmpUnitAI.IsGarrisoned()) - cmpNewUnitAI.SetGarrisoned(); + cmpNewUnitAI.SetGarrisoned(true); } let cmpPromotion = Engine.QueryInterface(oldEnt, IID_Promotion);