Ticket #799: patch_backtowork.4.diff
File patch_backtowork.4.diff, 10.0 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
1848 1848 Engine.CameraMoveTo(focusTarget.x, focusTarget.z); 1849 1849 1850 1850 break; 1851 case "back-to-work": 1852 backToWork(); 1853 break; 1854 case "unload-all-back-to-work": 1855 unloadAllBackToWork(); 1856 break; 1851 1857 default: 1852 1858 break; 1853 1859 } … … 2110 2116 Engine.PostNetworkCommand({"type": "unload-all", "garrisonHolders": garrisonHolders}); 2111 2117 } 2112 2118 2119 function backToWork() 2120 { 2121 // Filter out all entities that can't go back to work. 2122 var workers = g_Selection.toList().filter(function(e) { 2123 var state = GetEntityState(e); 2124 if (state && state.unitAI && state.unitAI.lastWorkOrder) 2125 return true; 2126 return false; 2127 }); 2128 2129 Engine.PostNetworkCommand({"type": "back-to-work", "workers": workers}); 2130 2131 } 2132 2133 function unloadAllBackToWork() 2134 { 2135 // Filter out all entities that aren't garrisonable. 2136 var garrisonHolders = g_Selection.toList().filter(function(e) { 2137 var state = GetEntityState(e); 2138 if (state && state.garrisonHolder) 2139 return true; 2140 return false; 2141 }); 2142 2143 Engine.PostNetworkCommand({"type": "unload-all-back-to-work", "garrisonHolders": garrisonHolders}); 2144 } 2145 2113 2146 function clearSelection() 2114 2147 { 2115 2148 if(inputState==INPUT_BUILDING_PLACEMENT || inputState==INPUT_BUILDING_WALL_PATHING) -
binaries/data/mods/public/gui/session/utility_functions.js
293 293 "icon": "focus-rally.png" 294 294 }); 295 295 } 296 297 if (entState.unitAI && entState.unitAI.lastWorkOrder) 298 { 299 commands.push({ 300 "name": "back-to-work", 301 "tooltip": "Back to Work", 302 "icon": "production.png" 303 }); 304 } 305 306 if (entState.garrisonHolder) 307 { 308 commands.push({ 309 "name": "unload-all-back-to-work", 310 "tooltip": "Unload All Units and Send the Workers Back to Work", 311 "icon": "production.png" 312 }); 313 } 296 314 297 315 return commands; 298 316 } -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
261 261 262 262 /** 263 263 * Ejects units and orders them to move to the Rally Point. 264 * If backToWork is set to true, ejects units, order the ones who can go back to work to do so, and the others to move to the Rally Point. 264 265 * Returns true if successful, false if not 265 266 */ 266 GarrisonHolder.prototype.PerformEject = function(entities, forced )267 GarrisonHolder.prototype.PerformEject = function(entities, forced, backToWork) 267 268 { 268 269 if (!this.IsGarrisoningAllowed() && !forced) 269 270 return false; … … 283 284 success = false; 284 285 } 285 286 286 this.OrderWalkToRallyPoint(ejectedEntities); 287 if (backToWork) 288 { 289 // Filter the entities who shall go back to work and those who shall not. 290 var workers = []; 291 var nonWorkers = []; 292 293 ejectedEntities.forEach(function(e) { 294 var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI); 295 if (cmpUnitAI && cmpUnitAI.GetLastWorkOrder()) 296 workers.push(e); 297 else 298 nonWorkers.push(e); 299 }); 300 301 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 302 ProcessCommand(cmpOwnership.GetOwner(), {"type": "back-to-work", "workers": workers}); 303 304 this.OrderWalkToRallyPoint(nonWorkers); 305 } 306 else 307 this.OrderWalkToRallyPoint(ejectedEntities); 308 287 309 this.UpdateGarrisonFlag(); 288 310 289 311 return success; … … 369 391 * and order them to move to the Rally Point 370 392 * Returns true if all successful, false if not 371 393 */ 372 GarrisonHolder.prototype.UnloadAll = function(forced )394 GarrisonHolder.prototype.UnloadAll = function(forced, backToWork) 373 395 { 374 396 var entities = this.entities.slice(0); 375 return this.PerformEject(entities, forced );397 return this.PerformEject(entities, forced, backToWork); 376 398 }; 377 399 378 400 /** -
binaries/data/mods/public/simulation/components/GuiInterface.js
348 348 ret.unitAI = { 349 349 "state": cmpUnitAI.GetCurrentState(), 350 350 "orders": cmpUnitAI.GetOrders(), 351 "lastWorkOrder": cmpUnitAI.GetLastWorkOrder(), 351 352 }; 352 353 // Add some information needed for ungarrisoning 353 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.SetLastWorkOrder(lastWorkOrder); 81 83 82 84 Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity }); 83 85 -
binaries/data/mods/public/simulation/components/UnitAI.js
2525 2525 this.isIdle = false; 2526 2526 this.lastFormationName = ""; 2527 2527 this.finishedOrder = false; // used to find if all formation members finished the order 2528 2529 // To go back to work later 2530 this.lastWorkOrder = undefined; 2528 2531 2529 2532 // For preventing increased action rate due to Stop orders or target death. 2530 2533 this.lastAttacked = undefined; … … 2801 2804 Engine.PostMessage(this.entity, MT_UnitAIStateChanged, { "to": state }); 2802 2805 }; 2803 2806 2807 UnitAI.prototype.BackToWork = function() 2808 { 2809 if(this.lastWorkOrder) 2810 { 2811 this.ReplaceOrder(this.lastWorkOrder.type, this.lastWorkOrder.data); 2812 return true; 2813 } 2814 else 2815 return false; 2816 }; 2817 2804 2818 /** 2805 2819 * Call when the current order has been completed (or failed). 2806 2820 * Removes the current order from the queue, and processes the … … 2817 2831 error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack); 2818 2832 } 2819 2833 2820 this.orderQueue.shift(); 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 var finishedOrder = this.orderQueue.shift(); 2836 if(finishedOrder.type == "Gather" || finishedOrder.type == "Trade" || finishedOrder.type == "Repair") 2837 this.lastWorkOrder = undefined; 2838 2821 2839 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; 2822 2845 2823 2846 if (this.orderQueue.length) 2824 2847 { … … 2869 2892 { 2870 2893 var order = { "type": type, "data": data }; 2871 2894 this.orderQueue.push(order); 2895 2896 if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource") 2897 this.lastWorkOrder = order; 2872 2898 2873 2899 // If we didn't already have an order, then process this new one 2874 2900 if (this.orderQueue.length == 1) … … 2972 2998 return orders; 2973 2999 }; 2974 3000 3001 UnitAI.prototype.GetLastWorkOrder = function() 3002 { 3003 return this.lastWorkOrder; 3004 }; 3005 3006 UnitAI.prototype.SetLastWorkOrder = function(order) 3007 { 3008 this.lastWorkOrder = order; 3009 }; 3010 2975 3011 UnitAI.prototype.TimerHandler = function(data, lateness) 2976 3012 { 2977 3013 // Reset the timer -
binaries/data/mods/public/simulation/helpers/Commands.js
386 386 for each (var garrisonHolder in entities) 387 387 { 388 388 var cmpGarrisonHolder = Engine.QueryInterface(garrisonHolder, IID_GarrisonHolder); 389 if (!cmpGarrisonHolder || !cmpGarrisonHolder.UnloadAll( ))389 if (!cmpGarrisonHolder || !cmpGarrisonHolder.UnloadAll(false, false)) 390 390 notifyUnloadFailure(player, garrisonHolder) 391 391 } 392 392 break; 393 394 case "back-to-work": 395 var entities = FilterEntityList(cmd.workers, player, controlAllUnits); 396 for each (var worker in entities) 397 { 398 var cmpUnitAI = Engine.QueryInterface(worker, IID_UnitAI); 399 if (!cmpUnitAI || !cmpUnitAI.BackToWork()) 400 notifyBackToWorkFailure(player, worker) 401 } 402 break; 403 404 case "unload-all-back-to-work": 405 var entities = FilterEntityList(cmd.garrisonHolders, player, controlAllUnits); 406 for each (var garrisonHolder in entities) 407 { 408 var cmpGarrisonHolder = Engine.QueryInterface(garrisonHolder, IID_GarrisonHolder); 409 if (!cmpGarrisonHolder || !cmpGarrisonHolder.UnloadAll(false, true)) 410 notifyUnloadFailure(player, garrisonHolder) 411 } 412 break; 393 413 394 414 case "formation": 395 415 GetFormationUnitAIs(entities, player, cmd.name).forEach(function(cmpUnitAI) { … … 518 538 } 519 539 520 540 /** 541 * Sends a GUI notification about worker(s) that failed to go back to work. 542 */ 543 function notifyBackToWorkFailure(player, worker) 544 { 545 var cmpPlayer = QueryPlayerIDInterface(player, IID_Player); 546 var notification = {"player": cmpPlayer.GetPlayerID(), "message": "Some unit(s) can't go back to work" }; 547 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 548 cmpGUIInterface.PushNotification(notification); 549 } 550 551 /** 521 552 * Get some information about the formations used by entities. 522 553 * The entities must have a UnitAI component. 523 554 */