2012-05-24 20:25:31 +02:00
|
|
|
// Returns an array of commands suitable for ProcessCommand() based on the rally point data.
|
2011-12-16 17:08:26 +01:00
|
|
|
// This assumes that the rally point has a valid position.
|
2012-05-24 20:25:31 +02:00
|
|
|
function GetRallyPointCommands(cmpRallyPoint, spawnedEnts)
|
2011-12-16 17:08:26 +01:00
|
|
|
{
|
|
|
|
var data = cmpRallyPoint.GetData();
|
2012-05-24 20:25:31 +02:00
|
|
|
var rallyPos = cmpRallyPoint.GetPositions();
|
|
|
|
var ret = [];
|
|
|
|
for(var i = 0; i < rallyPos.length; ++i)
|
2011-12-16 17:08:26 +01:00
|
|
|
{
|
2012-05-24 20:25:31 +02:00
|
|
|
// Look and see if there is a command in the rally point data, otherwise just walk there.
|
|
|
|
var command = undefined;
|
|
|
|
if (data[i] && data[i].command)
|
|
|
|
{
|
|
|
|
command = data[i].command;
|
|
|
|
}
|
|
|
|
else
|
2011-12-16 17:08:26 +01:00
|
|
|
{
|
|
|
|
command = "walk";
|
|
|
|
}
|
|
|
|
|
2012-05-24 20:25:31 +02:00
|
|
|
// If a target was set and the target no longer exists, or no longer
|
|
|
|
// has a valid position, then just walk to the rally point.
|
|
|
|
if (data[i] && data[i].target)
|
|
|
|
{
|
|
|
|
var cmpPosition = Engine.QueryInterface(data[i].target, IID_Position);
|
|
|
|
if (!cmpPosition || !cmpPosition.IsInWorld())
|
|
|
|
{
|
|
|
|
command = "walk";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case "gather":
|
|
|
|
ret.push( {
|
|
|
|
"type": "gather-near-position",
|
|
|
|
"entities": spawnedEnts,
|
|
|
|
"x": rallyPos[i].x,
|
|
|
|
"z": rallyPos[i].z,
|
|
|
|
"resourceType": data[i].resourceType,
|
2012-05-27 22:23:08 +02:00
|
|
|
"resourceTemplate": data[i].resourceTemplate,
|
2012-05-24 20:25:31 +02:00
|
|
|
"queued": true
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "repair":
|
|
|
|
case "build":
|
|
|
|
ret.push( {
|
|
|
|
"type": "repair",
|
|
|
|
"entities": spawnedEnts,
|
|
|
|
"target": data[i].target,
|
|
|
|
"queued": true,
|
|
|
|
"autocontinue": (i == rallyPos.length-1)
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "garrison":
|
|
|
|
ret.push( {
|
|
|
|
"type": "garrison",
|
|
|
|
"entities": spawnedEnts,
|
|
|
|
"target": data[i].target,
|
|
|
|
"queued": true
|
|
|
|
});
|
|
|
|
break;
|
2012-07-25 23:38:56 +02:00
|
|
|
case "trade":
|
|
|
|
ret.push( {
|
|
|
|
"type": "setup-trade-route",
|
|
|
|
"entities": spawnedEnts,
|
|
|
|
"source": data[i].source,
|
|
|
|
"target": data[i].target,
|
|
|
|
"queued": true
|
|
|
|
});
|
|
|
|
break;
|
2012-05-24 20:25:31 +02:00
|
|
|
default:
|
|
|
|
ret.push( {
|
|
|
|
"type": "walk",
|
|
|
|
"entities": spawnedEnts,
|
|
|
|
"x": rallyPos[i].x,
|
|
|
|
"z": rallyPos[i].z,
|
|
|
|
"queued": true
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2011-12-16 17:08:26 +01:00
|
|
|
}
|
2012-05-24 20:25:31 +02:00
|
|
|
return ret;
|
2011-12-16 17:08:26 +01:00
|
|
|
}
|
|
|
|
|
2012-05-24 20:25:31 +02:00
|
|
|
Engine.RegisterGlobal("GetRallyPointCommands", GetRallyPointCommands);
|