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 @@ -3431,6 +3431,17 @@ this.isGarrisoned = true; }; +UnitAI.prototype.GetGarrisonHolder = function() +{ + if (this.IsGarrisoned()) + { + for (let order of this.orderQueue) + if (order.type == "Garrison" || order.type == "Autogarrison") + return order.data.target; + } + return INVALID_ENTITY; +}; + UnitAI.prototype.IsFleeing = function() { var state = this.GetCurrentState().split(".").pop(); @@ -3930,6 +3941,13 @@ if (this.workOrders.length == 0) return false; + if (this.IsGarrisoned()) + { + let cmpGarrisonHolder = Engine.QueryInterface(this.GetGarrisonHolder(), IID_GarrisonHolder); + if (!cmpGarrisonHolder || !cmpGarrisonHolder.PerformEject([this.entity], false)) + return false; + } + // Clear the order queue considering special orders not to avoid if (this.order && this.order.type == "Cheering") {