forked from mirrors/0ad
Idle worker button now cycles through Worker, Trade, and CitizenSoldier classes in that order (then by increasing entity ID). Fixes #209.
This was SVN commit r9349.
This commit is contained in:
@@ -1151,19 +1151,33 @@ function setCameraFollow(entity)
|
||||
}
|
||||
|
||||
var lastIdleWorker = 0;
|
||||
var currIdleClass = 0;
|
||||
function findIdleWorker()
|
||||
{
|
||||
lastIdleWorker = Engine.GuiInterfaceCall("FindIdleWorker", lastIdleWorker);
|
||||
if (lastIdleWorker)
|
||||
// Cycle through idling classes before giving up
|
||||
var idleClasses = ["Worker", "Trade", "CitizenSoldier"];
|
||||
for (var i = 0; i <= idleClasses.length; ++i)
|
||||
{
|
||||
g_Selection.reset()
|
||||
g_Selection.addList([lastIdleWorker]);
|
||||
Engine.CameraFollow(lastIdleWorker);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: display a message or play a sound to indicate no more idle units, or something
|
||||
var data = { prevWorker: lastIdleWorker, idleClass: idleClasses[currIdleClass] };
|
||||
lastIdleWorker = Engine.GuiInterfaceCall("FindIdleWorker", data);
|
||||
|
||||
// Check if we have valid entity
|
||||
if (lastIdleWorker)
|
||||
{
|
||||
g_Selection.reset()
|
||||
g_Selection.addList([lastIdleWorker]);
|
||||
Engine.CameraFollow(lastIdleWorker);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
lastIdleWorker = 0;
|
||||
currIdleClass = (currIdleClass + 1) % idleClasses.length;
|
||||
}
|
||||
|
||||
// TODO: display a message or play a sound to indicate no more idle units, or something
|
||||
// Reset for next cycle
|
||||
currIdleClass = 0;
|
||||
}
|
||||
|
||||
function unload(garrisonHolder, entity)
|
||||
|
||||
@@ -445,32 +445,28 @@ GuiInterface.prototype.PlaySound = function(player, data)
|
||||
PlaySound(data.name, data.entity);
|
||||
};
|
||||
|
||||
function isIdleWorker(ent)
|
||||
function isIdleWorker(ent, idleClass)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
|
||||
return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && cmpIdentity.HasClass("Worker"));
|
||||
return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && idleClass && cmpIdentity.HasClass(idleClass));
|
||||
}
|
||||
|
||||
GuiInterface.prototype.FindIdleWorker = function(player, prevWorker)
|
||||
GuiInterface.prototype.FindIdleWorker = function(player, data)
|
||||
{
|
||||
var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
||||
var playerEntities = rangeMan.GetEntitiesByPlayer(player);
|
||||
|
||||
var firstUnit = 0;
|
||||
|
||||
// Find the first matching entity that is after the previous selection,
|
||||
// so that we cycle around in a predictable order
|
||||
for each (var ent in playerEntities)
|
||||
{
|
||||
if (ent > prevWorker && isIdleWorker(ent))
|
||||
if (ent > data.prevWorker && isIdleWorker(ent, data.idleClass))
|
||||
return ent;
|
||||
else if (!firstUnit && isIdleWorker(ent))
|
||||
firstUnit = ent;
|
||||
}
|
||||
|
||||
// Nothing after the selection - just return the first entity
|
||||
return firstUnit;
|
||||
// No idle entities left in the class
|
||||
return 0;
|
||||
};
|
||||
|
||||
GuiInterface.prototype.SetPathfinderDebugOverlay = function(player, enabled)
|
||||
|
||||
@@ -86,6 +86,8 @@ Identity.prototype.Schema =
|
||||
"<value>City</value>" +
|
||||
"<value>ConquestCritical</value>" +
|
||||
"<value>Worker</value>" +
|
||||
"<value>CitizenSoldier</value>" +
|
||||
"<value>Trade</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>" +
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Entity parent="template_unit">
|
||||
<Identity>
|
||||
<GenericName>Cavalry</GenericName>
|
||||
<Classes datatype="tokens">Cavalry Organic</Classes>
|
||||
<Classes datatype="tokens">Cavalry CitizenSoldier Organic</Classes>
|
||||
<Rank>Basic</Rank>
|
||||
</Identity>
|
||||
<Promotion>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Entity parent="template_unit">
|
||||
<Identity>
|
||||
<GenericName>Infantry</GenericName>
|
||||
<Classes datatype="tokens">Infantry Organic</Classes>
|
||||
<Classes datatype="tokens">Infantry CitizenSoldier Organic</Classes>
|
||||
<Rank>Basic</Rank>
|
||||
</Identity>
|
||||
<Promotion>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<GenericName>Trader</GenericName>
|
||||
<Rollover>Trade was a very important part of ancient civilisation - effective trading and control of trade routes equaled wealth. Trade took place by many forms from foot to caravans to merchant ships. One of the most notorious examples of the power of trade was the Silk Road.</Rollover>
|
||||
<Tooltip>Trades resources between allied Markets.</Tooltip>
|
||||
<Classes datatype="tokens">Trade</Classes>
|
||||
</Identity>
|
||||
<Cost>
|
||||
<Resources>
|
||||
|
||||
Reference in New Issue
Block a user