Ticket #799: patch_backtowork.diff
File patch_backtowork.diff, 5.8 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; 1851 1854 default: 1852 1855 break; 1853 1856 } … … 2110 2113 Engine.PostNetworkCommand({"type": "unload-all", "garrisonHolders": garrisonHolders}); 2111 2114 } 2112 2115 2116 function backToWork() 2117 { 2118 // Filter out all entities that can't go back to work. 2119 var workers = g_Selection.toList().filter(function(e) { 2120 var state = GetEntityState(e); 2121 if (state && hasClass(state, "Worker")) 2122 return true; 2123 return false; 2124 }); 2125 2126 Engine.PostNetworkCommand({"type": "back-to-work", "workers": workers}); 2127 2128 } 2129 2113 2130 function clearSelection() 2114 2131 { 2115 2132 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 (hasClass(entState, "Worker")) 298 { 299 commands.push({ 300 "name": "back-to-work", 301 "tooltip": "Back to Work", 302 "icon": "production.png" 303 }); 304 } 296 305 297 306 return commands; 298 307 } -
binaries/data/mods/public/simulation/components/ResourceGatherer.js
63 63 // each with an independent capacity, but the rest of the game currently 64 64 // ensures and assumes we'll only be carrying one type at once) 65 65 66 // The last exact type gathered, so we canrender appropriate props67 this.last CarriedType = undefined; // { generic, specific }66 // Informations needed to go back to work later and render appropriate props 67 this.lastWorkInformation = undefined; 68 68 }; 69 69 70 70 /** … … 119 119 */ 120 120 ResourceGatherer.prototype.GetLastCarriedType = function() 121 121 { 122 if (this.last CarriedType && this.lastCarriedType.generic in this.carrying)123 return this.last CarriedType;122 if (this.lastWorkInformation && this.lastWorkInformation.type && this.lastWorkInformation.type.generic in this.carrying) 123 return this.lastWorkInformation.type; 124 124 else 125 125 return undefined; 126 126 }; … … 194 194 195 195 var gatherAmount = 1; 196 196 197 // Remember what we are gathering to go back to it later 197 198 var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply); 198 199 var type = cmpResourceSupply.GetType(); 199 200 201 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 202 var template = cmpTemplateManager.GetCurrentTemplateName(target); 203 204 if (template.indexOf("resource|") != -1) 205 template = template.slice(9); 206 207 var lastPos = undefined; 208 var cmpPosition = Engine.QueryInterface(target, IID_Position); 209 if (cmpPosition && cmpPosition.IsInWorld()) 210 lastPos = cmpPosition.GetPosition(); 211 212 // "force" will be used when giving the "back to work" order 213 this.lastWorkInformation = {"target" : target, "type" : type, "template" : template, "lastPos" : lastPos, "force" : true}; 214 200 215 // Initialise the carried count if necessary 201 216 if (!this.carrying[type.generic]) 202 217 this.carrying[type.generic] = 0; … … 208 223 209 224 this.carrying[type.generic] += status.amount; 210 225 211 this.lastCarriedType = type;212 213 226 // Update stats of how much the player collected. 214 227 // (We have to do it here rather than at the dropsite, because we 215 228 // need to know what subtype it was) … … 339 352 Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); 340 353 }; 341 354 355 /** 356 * Re-gather the last type of resource we carried 357 */ 358 ResourceGatherer.prototype.BackToWork = function() 359 { 360 var cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); 361 362 if(cmpUnitAI && this.lastWorkInformation) 363 { 364 cmpUnitAI.AddOrder("Gather", this.lastWorkInformation, false); 365 return true; 366 } 367 else 368 return false; 369 } 370 371 342 372 Engine.RegisterComponentType(IID_ResourceGatherer, "ResourceGatherer", ResourceGatherer); -
binaries/data/mods/public/simulation/helpers/Commands.js
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 cmpResourceGatherer = Engine.QueryInterface(worker, IID_ResourceGatherer); 399 if (!cmpResourceGatherer || !cmpResourceGatherer.BackToWork()) 400 notifyBackToWorkFailure(player, worker) 401 } 402 break; 393 403 394 404 case "formation": 395 405 GetFormationUnitAIs(entities, player, cmd.name).forEach(function(cmpUnitAI) { … … 518 528 } 519 529 520 530 /** 531 * Sends a GUI notification about worker(s) that failed to go back to work. 532 */ 533 function notifyBackToWorkFailure(player, worker) 534 { 535 var cmpPlayer = QueryPlayerIDInterface(player, IID_Player); 536 var notification = {"player": cmpPlayer.GetPlayerID(), "message": "This worker can't go back to work" }; 537 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 538 cmpGUIInterface.PushNotification(notification); 539 } 540 541 /** 521 542 * Get some information about the formations used by entities. 522 543 * The entities must have a UnitAI component. 523 544 */