From 26729263d24642c004b20570989dd0ec7786ff9a Mon Sep 17 00:00:00 2001
From: "Sven (Sbte)" <svenb.linux@gmail.com>
Date: Fri, 22 Mar 2013 22:14:18 +0100
Subject: Don't call GetSimulationState unnecessarily often
---
binaries/data/mods/public/gui/session/input.js | 42 +++++++++++++-------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
index 328a220..8fd2e57 100644
a
|
b
|
function findGatherType(gatherer, supply)
|
159 | 159 | return undefined; |
160 | 160 | } |
161 | 161 | |
162 | | function getActionInfo(action, target) |
| 162 | function getActionInfo(action, target, simState) |
163 | 163 | { |
164 | 164 | var selection = g_Selection.toList(); |
165 | 165 | |
… |
… |
function getActionInfo(action, target)
|
202 | 202 | // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse) |
203 | 203 | var targetState = GetEntityState(target); |
204 | 204 | |
205 | | // Check if the target entity is a resource, dropsite, foundation, or enemy unit. |
206 | | // Check if any entities in the selection can gather the requested resource, |
207 | | // can return to the dropsite, can build the foundation, or can attack the enemy |
208 | | var simState = Engine.GuiInterfaceCall("GetSimulationState"); |
209 | | |
210 | 205 | // Look to see what type of command units going to the rally point should use |
211 | 206 | if (haveRallyPoints && action == "set-rallypoint") |
212 | 207 | { |
… |
… |
function getActionInfo(action, target)
|
288 | 283 | return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip}; |
289 | 284 | } |
290 | 285 | |
| 286 | // Check if the target entity is a resource, dropsite, foundation, or enemy unit. |
| 287 | // Check if any entities in the selection can gather the requested resource, |
| 288 | // can return to the dropsite, can build the foundation, or can attack the enemy |
291 | 289 | for each (var entityID in selection) |
292 | 290 | { |
293 | 291 | var entState = GetEntityState(entityID); |
… |
… |
function determineAction(x, y, fromMinimap)
|
459 | 457 | target = targets[0]; |
460 | 458 | } |
461 | 459 | |
| 460 | var simState = Engine.GuiInterfaceCall("GetSimulationState"); |
| 461 | |
462 | 462 | if (preSelectedAction != ACTION_NONE) |
463 | 463 | { |
464 | 464 | switch (preSelectedAction) |
465 | 465 | { |
466 | 466 | case ACTION_GARRISON: |
467 | | if (getActionInfo("garrison", target).possible) |
| 467 | if (getActionInfo("garrison", target, simState).possible) |
468 | 468 | return {"type": "garrison", "cursor": "action-garrison", "target": target}; |
469 | 469 | else |
470 | 470 | return {"type": "none", "cursor": "action-garrison-disabled", "target": undefined}; |
471 | 471 | break; |
472 | 472 | case ACTION_REPAIR: |
473 | | if (getActionInfo("repair", target).possible) |
| 473 | if (getActionInfo("repair", target, simState).possible) |
474 | 474 | return {"type": "repair", "cursor": "action-repair", "target": target}; |
475 | 475 | else |
476 | 476 | return {"type": "none", "cursor": "action-repair-disabled", "target": undefined}; |
477 | 477 | break; |
478 | 478 | } |
479 | 479 | } |
480 | | else if (Engine.HotkeyIsPressed("session.attack") && getActionInfo("attack", target).possible) |
| 480 | else if (Engine.HotkeyIsPressed("session.attack") && getActionInfo("attack", target, simState).possible) |
481 | 481 | { |
482 | 482 | return {"type": "attack", "cursor": "action-attack", "target": target}; |
483 | 483 | } |
484 | | else if (Engine.HotkeyIsPressed("session.garrison") && getActionInfo("garrison", target).possible) |
| 484 | else if (Engine.HotkeyIsPressed("session.garrison") && getActionInfo("garrison", target, simState).possible) |
485 | 485 | { |
486 | 486 | return {"type": "garrison", "cursor": "action-garrison", "target": target}; |
487 | 487 | } |
488 | | else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible) |
| 488 | else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target, simState).possible) |
489 | 489 | { |
490 | 490 | return {"type": "attack-move", "cursor": "action-attack-move"}; |
491 | 491 | } |
492 | 492 | else |
493 | 493 | { |
494 | 494 | var actionInfo = undefined; |
495 | | if ((actionInfo = getActionInfo("setup-trade-route", target)).possible) |
| 495 | if ((actionInfo = getActionInfo("setup-trade-route", target, simState)).possible) |
496 | 496 | return {"type": "setup-trade-route", "cursor": "action-setup-trade-route", "tooltip": actionInfo.tooltip, "target": target}; |
497 | | else if ((actionInfo = getActionInfo("gather", target)).possible) |
| 497 | else if ((actionInfo = getActionInfo("gather", target, simState)).possible) |
498 | 498 | return {"type": "gather", "cursor": actionInfo.cursor, "target": target}; |
499 | | else if ((actionInfo = getActionInfo("returnresource", target)).possible) |
| 499 | else if ((actionInfo = getActionInfo("returnresource", target, simState)).possible) |
500 | 500 | return {"type": "returnresource", "cursor": actionInfo.cursor, "target": target}; |
501 | | else if (getActionInfo("build", target).possible) |
| 501 | else if (getActionInfo("build", target, simState).possible) |
502 | 502 | return {"type": "build", "cursor": "action-build", "target": target}; |
503 | | else if (getActionInfo("repair", target).possible) |
| 503 | else if (getActionInfo("repair", target, simState).possible) |
504 | 504 | return {"type": "build", "cursor": "action-repair", "target": target}; |
505 | | else if ((actionInfo = getActionInfo("set-rallypoint", target)).possible) |
| 505 | else if ((actionInfo = getActionInfo("set-rallypoint", target, simState)).possible) |
506 | 506 | return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position}; |
507 | | else if (getActionInfo("heal", target).possible) |
| 507 | else if (getActionInfo("heal", target, simState).possible) |
508 | 508 | return {"type": "heal", "cursor": "action-heal", "target": target}; |
509 | | else if (getActionInfo("attack", target).possible) |
| 509 | else if (getActionInfo("attack", target, simState).possible) |
510 | 510 | return {"type": "attack", "cursor": "action-attack", "target": target}; |
511 | | else if (getActionInfo("unset-rallypoint", target).possible) |
| 511 | else if (getActionInfo("unset-rallypoint", target, simState).possible) |
512 | 512 | return {"type": "unset-rallypoint"}; |
513 | | else if (getActionInfo("move", target).possible) |
| 513 | else if (getActionInfo("move", target, simState).possible) |
514 | 514 | return {"type": "move"}; |
515 | 515 | } |
516 | 516 | return {"type": type, "cursor": cursor, "target": target}; |