Ticket #2206: correct_backtowork.2.diff
File correct_backtowork.2.diff, 7.1 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
2108 2108 // Filter out all entities that can't go back to work. 2109 2109 var workers = g_Selection.toList().filter(function(e) { 2110 2110 var state = GetEntityState(e); 2111 return (state && state.unitAI && state.unitAI. lastWorkOrder);2111 return (state && state.unitAI && state.unitAI.hasWorkOrders); 2112 2112 }); 2113 2113 2114 2114 Engine.PostNetworkCommand({"type": "back-to-work", "workers": workers}); -
binaries/data/mods/public/gui/session/utility_functions.js
294 294 }); 295 295 } 296 296 297 if (entState.unitAI && entState.unitAI. lastWorkOrder)297 if (entState.unitAI && entState.unitAI.hasWorkOrders) 298 298 { 299 299 commands.push({ 300 300 "name": "back-to-work", -
binaries/data/mods/public/simulation/components/GuiInterface.js
347 347 { 348 348 ret.unitAI = { 349 349 "state": cmpUnitAI.GetCurrentState(), 350 "orders": cmpUnitAI.Get Orders(),351 " lastWorkOrder": cmpUnitAI.GetLastWorkOrder(),350 "orders": cmpUnitAI.GetWorkOrders(), 351 "hasWorkOrders": cmpUnitAI.HasWorkOrders(), 352 352 }; 353 353 // Add some information needed for ungarrisoning 354 354 if (cmpUnitAI.isGarrisoned && ret.player !== undefined) -
binaries/data/mods/public/simulation/components/Promotion.js
78 78 cmpPromotedUnitAI.Cheer(); 79 79 var orders = cmpCurrentUnitAI.GetOrders(); 80 80 cmpPromotedUnitAI.AddOrders(orders); 81 var lastWorkOrder = cmpCurrentUnitAI.GetLastWorkOrder();82 cmpPromotedUnitAI.Set LastWorkOrder(lastWorkOrder);81 var workOrders = cmpCurrentUnitAI.GetWorkOrders(); 82 cmpPromotedUnitAI.SetWorkOrders(workOrders); 83 83 84 84 Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity }); 85 85 -
binaries/data/mods/public/simulation/components/UnitAI.js
2526 2526 this.lastFormationName = ""; 2527 2527 this.finishedOrder = false; // used to find if all formation members finished the order 2528 2528 2529 // To go back to work later2530 this. lastWorkOrder = undefined;2529 // Queue of remembered works 2530 this.workOrders = []; 2531 2531 2532 2532 // For preventing increased action rate due to Stop orders or target death. 2533 2533 this.lastAttacked = undefined; … … 2806 2806 2807 2807 UnitAI.prototype.BackToWork = function() 2808 2808 { 2809 if(this. lastWorkOrder)2809 if(this.workOrders.length) 2810 2810 { 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 } 2812 2831 return true; 2813 2832 } 2814 2833 else … … 2831 2850 error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack); 2832 2851 } 2833 2852 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 2835 2854 var finishedOrder = this.orderQueue.shift(); 2855 this.order = this.orderQueue[0]; 2856 2857 // Update the back-to-work queue 2858 2836 2859 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(); 2840 2861 // If the worker was returning a resource, we shall 2841 2862 // -> (if the worker is gathering) keep remembering the "Gather" order which is this.order 2842 2863 // -> (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 2845 2867 2846 2868 if (this.orderQueue.length) 2847 2869 { … … 2894 2916 this.orderQueue.push(order); 2895 2917 2896 2918 if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource") 2897 this. lastWorkOrder = order;2919 this.workOrders.push(order); 2898 2920 2899 2921 // If we didn't already have an order, then process this new one 2900 2922 if (this.orderQueue.length == 1) … … 2950 2972 } 2951 2973 }; 2952 2974 2953 UnitAI.prototype. ReplaceOrder = function(type, data)2975 UnitAI.prototype.FlushOrders = function() 2954 2976 { 2955 2977 // Special cases of orders that shouldn't be replaced: 2956 2978 // 1. Cheering - we're invulnerable, add order after we finish … … 2960 2982 { 2961 2983 var order = { "type": type, "data": data }; 2962 2984 var cheeringOrder = this.orderQueue.shift(); 2963 this.orderQueue = [ cheeringOrder, order];2985 this.orderQueue = [cheeringOrder]; 2964 2986 } 2965 2987 else if (this.IsPacking() && type != "CancelPack" && type != "CancelUnpack") 2966 2988 { 2967 2989 var order = { "type": type, "data": data }; 2968 2990 var packingOrder = this.orderQueue.shift(); 2969 this.orderQueue = [ packingOrder, order];2991 this.orderQueue = [packingOrder]; 2970 2992 } 2971 2993 else 2972 {2973 2994 this.orderQueue = []; 2974 this.PushOrder(type, data);2975 }2976 2995 }; 2977 2996 2997 UnitAI.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 2978 3006 UnitAI.prototype.GetOrders = function() 2979 3007 { 2980 3008 return this.orderQueue.slice(); … … 2998 3026 return orders; 2999 3027 }; 3000 3028 3001 UnitAI.prototype. GetLastWorkOrder= function()3029 UnitAI.prototype.HasWorkOrders = function() 3002 3030 { 3003 return this.lastWorkOrder;3031 return (this.workOrders.length > 0); 3004 3032 }; 3005 3033 3006 UnitAI.prototype. SetLastWorkOrder = function(order)3034 UnitAI.prototype.GetWorkOrders = function() 3007 3035 { 3008 this.lastWorkOrder = order;3036 return this.workOrders; 3009 3037 }; 3010 3038 3039 UnitAI.prototype.SetWorkOrders = function(orders) 3040 { 3041 this.workOrders = orders; 3042 }; 3043 3011 3044 UnitAI.prototype.TimerHandler = function(data, lateness) 3012 3045 { 3013 3046 // Reset the timer