diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index d93305fb4f..a8466361d9 100644 --- a/binaries/data/mods/public/simulation/components/UnitAI.js +++ b/binaries/data/mods/public/simulation/components/UnitAI.js @@ -140,7 +140,7 @@ var UnitFsmSpec = { "Order.LeaveFoundation": function(msg) { // Default behaviour is to ignore the order since we're busy - this.FinishOrder(); + this.DiscardOrder(); }, // Individual orders: @@ -1378,6 +1378,23 @@ UnitAI.prototype.FinishOrder = function() } }; +/** + * Call when you want to drop an order inside a FSM order handler. + * Don't change the FSM state. + */ +UnitAI.prototype.DiscardOrder = function() +{ + if (!this.orderQueue.length) + error("DiscardOrder called when order queue is empty"); + + this.orderQueue.shift(); + this.order = this.orderQueue[0]; + if (!this.orderQueue.length) + { + this.SetNextState("IDLE"); + } +}; + /** * Add an order onto the back of the queue, * and execute it if we didn't already have an order.