Ticket #2206: correct_backtowork.2.diff

File correct_backtowork.2.diff, 7.1 KB (added by Itms, 11 years ago)
  • binaries/data/mods/public/gui/session/input.js

     
    21082108    // Filter out all entities that can't go back to work.
    21092109    var workers = g_Selection.toList().filter(function(e) {
    21102110        var state = GetEntityState(e);
    2111         return (state && state.unitAI && state.unitAI.lastWorkOrder);
     2111        return (state && state.unitAI && state.unitAI.hasWorkOrders);
    21122112    });
    21132113   
    21142114    Engine.PostNetworkCommand({"type": "back-to-work", "workers": workers});
  • binaries/data/mods/public/gui/session/utility_functions.js

     
    294294        });
    295295    }
    296296   
    297     if (entState.unitAI && entState.unitAI.lastWorkOrder)
     297    if (entState.unitAI && entState.unitAI.hasWorkOrders)
    298298    {
    299299        commands.push({
    300300            "name": "back-to-work",
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    347347    {
    348348        ret.unitAI = {
    349349            "state": cmpUnitAI.GetCurrentState(),
    350             "orders": cmpUnitAI.GetOrders(),
    351             "lastWorkOrder": cmpUnitAI.GetLastWorkOrder(),
     350            "orders": cmpUnitAI.GetWorkOrders(),
     351            "hasWorkOrders": cmpUnitAI.HasWorkOrders(),
    352352        };
    353353        // Add some information needed for ungarrisoning
    354354        if (cmpUnitAI.isGarrisoned && ret.player !== undefined)
  • binaries/data/mods/public/simulation/components/Promotion.js

     
    7878    cmpPromotedUnitAI.Cheer();
    7979    var orders = cmpCurrentUnitAI.GetOrders();
    8080    cmpPromotedUnitAI.AddOrders(orders);
    81     var lastWorkOrder = cmpCurrentUnitAI.GetLastWorkOrder();
    82     cmpPromotedUnitAI.SetLastWorkOrder(lastWorkOrder);
     81    var workOrders = cmpCurrentUnitAI.GetWorkOrders();
     82    cmpPromotedUnitAI.SetWorkOrders(workOrders);
    8383
    8484    Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity });
    8585
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    25262526    this.lastFormationName = "";
    25272527    this.finishedOrder = false; // used to find if all formation members finished the order
    25282528   
    2529     // To go back to work later
    2530     this.lastWorkOrder = undefined;
     2529    // Queue of remembered works
     2530    this.workOrders = [];
    25312531
    25322532    // For preventing increased action rate due to Stop orders or target death.
    25332533    this.lastAttacked = undefined;
     
    28062806
    28072807UnitAI.prototype.BackToWork = function()
    28082808{
    2809     if(this.lastWorkOrder)
     2809    if(this.workOrders.length)
    28102810    {
    2811         this.ReplaceOrder(this.lastWorkOrder.type, this.lastWorkOrder.data);
     2811        // Replace the current order queue
     2812        this.FlushOrders();
     2813        for each (var order in this.workOrders)
     2814            this.orderQueue.push(order);
     2815       
     2816        // Then, process the first order
     2817       
     2818        this.order = this.orderQueue[0];
     2819        var ret = UnitFsm.ProcessMessage(this,
     2820            {"type": "Order."+this.order.type, "data": this.order.data}
     2821        );
     2822
     2823        Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
     2824
     2825        // If the order was rejected then immediately take it off
     2826        // and process the remaining queue
     2827        if (ret && ret.discardOrder)
     2828        {
     2829            this.FinishOrder();
     2830        }
    28122831        return true;
    28132832    }
    28142833    else
     
    28312850        error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack);
    28322851    }
    28332852
    2834     // Remove the order from the queue, then forget it if it was a work to avoid trying to go back to it later.
     2853    // Remove the order from the queue
    28352854    var finishedOrder = this.orderQueue.shift();
     2855    this.order = this.orderQueue[0];
     2856   
     2857    // Update the back-to-work queue
     2858   
    28362859    if(finishedOrder.type == "Gather" || finishedOrder.type == "Trade" || finishedOrder.type == "Repair")
    2837         this.lastWorkOrder = undefined;
    2838    
    2839     this.order = this.orderQueue[0];
     2860        this.workOrders.shift();
    28402861    // If the worker was returning a resource, we shall
    28412862    //  -> (if the worker is gathering) keep remembering the "Gather" order which is this.order
    28422863    //  -> (if the worker was directly ordered to return a resource) forget the "ReturnResource" order which is finished
    2843     if(finishedOrder.type == "ReturnResource" && (!this.order || this.order.type != "Gather"))
    2844         this.lastWorkOrder = undefined;
     2864    else if(finishedOrder.type == "ReturnResource" && (!this.order || this.order.type != "Gather"))
     2865        this.workOrders.shift();
     2866   
    28452867
    28462868    if (this.orderQueue.length)
    28472869    {
     
    28942916    this.orderQueue.push(order);
    28952917   
    28962918    if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
    2897         this.lastWorkOrder = order;
     2919        this.workOrders.push(order);
    28982920
    28992921    // If we didn't already have an order, then process this new one
    29002922    if (this.orderQueue.length == 1)
     
    29502972    }
    29512973};
    29522974
    2953 UnitAI.prototype.ReplaceOrder = function(type, data)
     2975UnitAI.prototype.FlushOrders = function()
    29542976{
    29552977    // Special cases of orders that shouldn't be replaced:
    29562978    // 1. Cheering - we're invulnerable, add order after we finish
     
    29602982    {
    29612983        var order = { "type": type, "data": data };
    29622984        var cheeringOrder = this.orderQueue.shift();
    2963         this.orderQueue = [ cheeringOrder, order ];
     2985        this.orderQueue = [cheeringOrder];
    29642986    }
    29652987    else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack")
    29662988    {
    29672989        var order = { "type": type, "data": data };
    29682990        var packingOrder = this.orderQueue.shift();
    2969         this.orderQueue = [ packingOrder, order ];
     2991        this.orderQueue = [packingOrder];
    29702992    }
    29712993    else
    2972     {
    29732994        this.orderQueue = [];
    2974         this.PushOrder(type, data);
    2975     }
    29762995};
    29772996
     2997UnitAI.prototype.ReplaceOrder = function(type, data)
     2998{
     2999    this.FlushOrders();
     3000    if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
     3001        this.workOrders = [];
     3002   
     3003    this.PushOrder(type, data);
     3004};
     3005
    29783006UnitAI.prototype.GetOrders = function()
    29793007{
    29803008    return this.orderQueue.slice();
     
    29983026    return orders;
    29993027};
    30003028
    3001 UnitAI.prototype.GetLastWorkOrder = function()
     3029UnitAI.prototype.HasWorkOrders = function()
    30023030{
    3003     return this.lastWorkOrder;
     3031    return (this.workOrders.length > 0);
    30043032};
    30053033
    3006 UnitAI.prototype.SetLastWorkOrder = function(order)
     3034UnitAI.prototype.GetWorkOrders = function()
    30073035{
    3008     this.lastWorkOrder = order;
     3036    return this.workOrders;
    30093037};
    30103038
     3039UnitAI.prototype.SetWorkOrders = function(orders)
     3040{
     3041    this.workOrders = orders;
     3042};
     3043
    30113044UnitAI.prototype.TimerHandler = function(data, lateness)
    30123045{
    30133046    // Reset the timer