1
0
forked from 0ad/0ad

Adds hotkey for finding idle warriors (comma). See #792.

Updates finding idle units to be more flexible.
Resets finding idle units when unit is deselected.
Adds Warship class to relevant templates.

This was SVN commit r9791.
This commit is contained in:
historic_bruno 2011-07-10 02:11:51 +00:00
parent 20ebb2b829
commit bfef903c94
8 changed files with 40 additions and 21 deletions

View File

@ -136,7 +136,8 @@ hotkey.cut = "Ctrl+X" ; Cut selected text and copy to the clipboar
; > ENTITY SELECTION
hotkey.selection.add = Shift ; Add units to selection
hotkey.selection.remove = Ctrl ; Remove units from selection
hotkey.selection.idle = Period ; Select next idle unit
hotkey.selection.idleworker = Period ; Select next idle worker
hotkey.selection.idlewarrior = Comma ; Select next idle warrior
hotkey.selection.offscreen = Alt ; Include offscreen units in selection
hotkey.selection.group.select.0 = 0
hotkey.selection.group.save.0 = "Ctrl+0"

View File

@ -337,6 +337,7 @@ function tryPlaceBuilding(queued)
if (!ok)
{
// invalid location - don't build it
// TODO: play a sound?
return false;
}
@ -733,6 +734,7 @@ function handleInputAfterGui(ev)
if (!ents.length)
{
g_Selection.reset();
resetIdleUnit();
inputState = INPUT_NORMAL;
return true;
}
@ -918,7 +920,7 @@ function doAction(action, ev)
case "garrison":
Engine.PostNetworkCommand({"type": "garrison", "entities": selection, "target": action.target, "queued": queued});
//Need to play some sound here??
// TODO: Play a sound?
return true;
case "set-rallypoint":
@ -1195,34 +1197,41 @@ function setCameraFollow(entity)
Engine.CameraFollow(0);
}
var lastIdleWorker = 0;
var lastIdleUnit = 0;
var currIdleClass = 0;
function findIdleWorker()
function resetIdleUnit()
{
lastIdleUnit = 0;
currIdleClass = 0;
}
function findIdleUnit(classes)
{
// Cycle through idling classes before giving up
var idleClasses = ["Worker", "Trade", "CitizenSoldier"];
for (var i = 0; i <= idleClasses.length; ++i)
for (var i = 0; i <= classes.length; ++i)
{
var data = { prevWorker: lastIdleWorker, idleClass: idleClasses[currIdleClass] };
lastIdleWorker = Engine.GuiInterfaceCall("FindIdleWorker", data);
var data = { prevUnit: lastIdleUnit, idleClass: classes[currIdleClass] };
var newIdleUnit = Engine.GuiInterfaceCall("FindIdleUnit", data);
// Check if we have valid entity
if (lastIdleWorker)
// Check if we have new valid entity
if (newIdleUnit && newIdleUnit != lastIdleUnit)
{
lastIdleUnit = newIdleUnit;
g_Selection.reset()
g_Selection.addList([lastIdleWorker]);
Engine.CameraFollow(lastIdleWorker);
g_Selection.addList([lastIdleUnit]);
Engine.CameraFollow(lastIdleUnit);
return;
}
lastIdleWorker = 0;
currIdleClass = (currIdleClass + 1) % idleClasses.length;
lastIdleUnit = 0;
currIdleClass = (currIdleClass + 1) % classes.length;
}
// TODO: display a message or play a sound to indicate no more idle units, or something
// Reset for next cycle
currIdleClass = 0;
resetIdleUnit();
}
function unload(garrisonHolder, entity)

View File

@ -84,6 +84,11 @@
<action on="Press">setCameraFollow(g_Selection.toList()[0]);</action>
</object>
<!-- Find idle warrior - TODO: Potentially move this to own UI button? -->
<object hotkey="selection.idlewarrior">
<action on="Press">findIdleUnit(["Hero", "Super", "CitizenSoldier", "Siege", "Warship"]);</action>
</object>
<!-- ================================ ================================ -->
<!-- Developer / Debug items -->
<!-- ================================ ================================ -->
@ -445,11 +450,11 @@
style="iconButton"
tooltip_style="sessionToolTip"
tooltip="Find idle worker"
hotkey="selection.idle"
hotkey="selection.idleworker"
>
<!-- TODO: should highlight the button if there's non-zero idle workers -->
<object size="0 0 100% 100%" type="image" sprite="idleWorker" ghost="true" />
<action on="Press">findIdleWorker();</action>
<action on="Press">findIdleUnit(["Worker", "Trade", "CitizenSoldier"]);</action>
</object>
</object>
</object>

View File

@ -503,7 +503,7 @@ GuiInterface.prototype.PlaySound = function(player, data)
PlaySound(data.name, data.entity);
};
function isIdleWorker(ent, idleClass)
function isIdleUnit(ent, idleClass)
{
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
@ -512,7 +512,7 @@ function isIdleWorker(ent, idleClass)
return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned() && idleClass && cmpIdentity.HasClass(idleClass));
}
GuiInterface.prototype.FindIdleWorker = function(player, data)
GuiInterface.prototype.FindIdleUnit = function(player, data)
{
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
var playerEntities = rangeMan.GetEntitiesByPlayer(player);
@ -521,7 +521,7 @@ GuiInterface.prototype.FindIdleWorker = function(player, data)
// so that we cycle around in a predictable order
for each (var ent in playerEntities)
{
if (ent > data.prevWorker && isIdleWorker(ent, data.idleClass))
if (ent > data.prevUnit && isIdleUnit(ent, data.idleClass))
return ent;
}
@ -584,7 +584,7 @@ var exposedFunctions = {
"DisplayRallyPoint": 1,
"SetBuildingPlacementPreview": 1,
"PlaySound": 1,
"FindIdleWorker": 1,
"FindIdleUnit": 1,
"SetPathfinderDebugOverlay": 1,
"SetObstructionDebugOverlay": 1,

View File

@ -89,6 +89,7 @@ Identity.prototype.Schema =
"<value>Worker</value>" +
"<value>CitizenSoldier</value>" +
"<value>Trade</value>" +
"<value>Warship</value>" +
"<value a:help='Primary weapon type'>Bow</value>" + // TODO: what are these used for?
"<value a:help='Primary weapon type'>Javelin</value>" +
"<value a:help='Primary weapon type'>Spear</value>" +

View File

@ -3,6 +3,7 @@
<Identity>
<GenericName>Light Warship</GenericName>
<Tooltip>Light Warship.</Tooltip>
<Classes datatype="tokens">Warship</Classes>
</Identity>
<Cost>
<BuildTime>30</BuildTime>

View File

@ -3,6 +3,7 @@
<Identity>
<GenericName>Heavy Warship</GenericName>
<Tooltip>Heavy Warship.</Tooltip>
<Classes datatype="tokens">Warship</Classes>
</Identity>
<Cost>
<BuildTime>50</BuildTime>

View File

@ -3,6 +3,7 @@
<Identity>
<GenericName>Medium Warship</GenericName>
<Tooltip>Medium Warship.</Tooltip>
<Classes datatype="tokens">Warship</Classes>
</Identity>
<Cost>
<BuildTime>40</BuildTime>