Ticket #2206: correct_backtowork_mod.diff

File correct_backtowork_mod.diff, 6.1 KB (added by mimo, 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        this.AddOrders(this.workOrders);
     2812        this.workOrders = [];
    28122813        return true;
    28132814    }
    28142815    else
     
    28312832        error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack);
    28322833    }
    28332834
    2834     // Remove the order from the queue, then forget it if it was a work to avoid trying to go back to it later.
     2835    // Remove the order from the queue
    28352836    var finishedOrder = this.orderQueue.shift();
    2836     if(finishedOrder.type == "Gather" || finishedOrder.type == "Trade" || finishedOrder.type == "Repair")
    2837         this.lastWorkOrder = undefined;
    2838    
    28392837    this.order = this.orderQueue[0];
    2840     // If the worker was returning a resource, we shall
    2841     //  -> (if the worker is gathering) keep remembering the "Gather" order which is this.order
    2842     //  -> (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;
    28452838
    28462839    if (this.orderQueue.length)
    28472840    {
     
    28922885{
    28932886    var order = { "type": type, "data": data };
    28942887    this.orderQueue.push(order);
    2895    
    2896     if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
    2897         this.lastWorkOrder = order;
    28982888
    28992889    // If we didn't already have an order, then process this new one
    29002890    if (this.orderQueue.length == 1)
     
    29522942
    29532943UnitAI.prototype.ReplaceOrder = function(type, data)
    29542944{
     2945    // Keep the previous orders if needed
     2946    if (data && data.force)
     2947    {
     2948        if (type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
     2949            this.workOrders = [];
     2950        else
     2951        {
     2952            var i0 = 0;
     2953            if (this.order && this.order.type == "Cheering")
     2954                i0 = 1;
     2955            for (var i = i0; i < this.orderQueue.length; ++i)
     2956            {
     2957                var ordertype = this.orderQueue[i].type;
     2958                if (ordertype == "Gather" || ordertype == "Trade" || ordertype == "Repair" || ordertype == "ReturnResource")
     2959                {
     2960                    this.workOrders = this.orderQueue.slice(i0);
     2961                    break;
     2962                }
     2963            }
     2964        }
     2965    }
     2966
    29552967    // Special cases of orders that shouldn't be replaced:
    29562968    // 1. Cheering - we're invulnerable, add order after we finish
    29572969    // 2. Packing/unpacking - we're immobile, add order after we finish (unless it's cancel)
     
    29983010    return orders;
    29993011};
    30003012
    3001 UnitAI.prototype.GetLastWorkOrder = function()
     3013UnitAI.prototype.HasWorkOrders = function()
    30023014{
    3003     return this.lastWorkOrder;
     3015    return (this.workOrders.length > 0);
    30043016};
    30053017
    3006 UnitAI.prototype.SetLastWorkOrder = function(order)
     3018UnitAI.prototype.GetWorkOrders = function()
    30073019{
    3008     this.lastWorkOrder = order;
     3020    return this.workOrders;
    30093021};
    30103022
     3023UnitAI.prototype.SetWorkOrders = function(orders)
     3024{
     3025    this.workOrders = orders;
     3026};
     3027
    30113028UnitAI.prototype.TimerHandler = function(data, lateness)
    30123029{
    30133030    // Reset the timer