Permalink
Browse files

Merge remote-tracking branch 'remotes/trunk'

  • Loading branch information...
KieranP committed May 24, 2012
2 parents 391b854 + 4d216dd commit 9331caf8dadb04cb50eab3885ff107b4733a408b
@@ -191,11 +191,6 @@ function getActionInfo(action, target)
// e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
var targetState = GetEntityState(target);
- // If we selected buildings with rally points, and then click on one of those selected
- // buildings, we should remove the rally point
- //if (haveRallyPoints && selection.indexOf(target) != -1)
- // return {"type": "unset-rallypoint"};
-
// Check if the target entity is a resource, dropsite, foundation, or enemy unit.
// Check if any entities in the selection can gather the requested resource,
// can return to the dropsite, can build the foundation, or can attack the enemy
@@ -1317,12 +1312,13 @@ function doAction(action, ev)
{
pos = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
}
- Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": pos.x, "z": pos.z, "data": action.data});
+ Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": pos.x, "z": pos.z, "data": action.data, "queued": queued});
// Display rally point at the new coordinates, to avoid display lag
Engine.GuiInterfaceCall("DisplayRallyPoint", {
"entities": selection,
"x": pos.x,
- "z": pos.z
+ "z": pos.z,
+ "queued": queued
});
return true;
@@ -215,10 +215,14 @@ GarrisonHolder.prototype.OrderWalkToRallyPoint = function(entities)
var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint);
if (cmpRallyPoint)
{
- var rallyPos = cmpRallyPoint.GetPosition();
+ var rallyPos = cmpRallyPoint.GetPositions()[0];
if (rallyPos)
{
- ProcessCommand(cmpOwnership.GetOwner(), GetRallyPointCommand(cmpRallyPoint, entities));
+ var commands = GetRallyPointCommands(cmpRallyPoint, entities);
+ for each (var com in commands)
+ {
+ ProcessCommand(cmpOwnership.GetOwner(), com);
+ }
}
}
};
@@ -295,7 +299,7 @@ GarrisonHolder.prototype.OnHealthChanged = function(msg)
cmpHealth.Kill();
}
}
- this.entities = [];
+ this.entities = [];
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
}
else
@@ -259,7 +259,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
if (cmpRallyPoint)
{
- ret.rallyPoint = {'position': cmpRallyPoint.GetPosition()}; // undefined or {x,z} object
+ ret.rallyPoint = {'position': cmpRallyPoint.GetPositions()[0]}; // undefined or {x,z} object
}
var cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);
@@ -629,7 +629,7 @@ GuiInterface.prototype.SetStatusBars = function(player, cmd)
};
/**
- * Displays the rally point of a given list of entities (carried in cmd.entities).
+ * Displays the rally points of a given list of entities (carried in cmd.entities).
*
* The 'cmd' object may carry its own x/z coordinate pair indicating the location where the rally point should
* be rendered, in order to support instantaneously rendering a rally point marker at a specified location
@@ -677,11 +677,15 @@ GuiInterface.prototype.DisplayRallyPoint = function(player, cmd)
if (cmd.x && cmd.z)
pos = cmd;
else
- pos = cmpRallyPoint.GetPosition(); // may return undefined if no rally point is set
+ pos = cmpRallyPoint.GetPositions()[0]; // may return undefined if no rally point is set
if (pos)
{
- cmpRallyPointRenderer.SetPosition({'x': pos.x, 'y': pos.z}); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z
+ // Only update the position if we changed it (cmd.queued is set)
+ if (cmd.queued == true)
+ cmpRallyPointRenderer.AddPosition({'x': pos.x, 'y': pos.z}); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z
+ else if (cmd.queued == false)
+ cmpRallyPointRenderer.SetPosition({'x': pos.x, 'y': pos.z}); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z
cmpRallyPointRenderer.SetDisplayed(true);
// remember which entities have their rally points displayed so we can hide them again
@@ -442,10 +442,14 @@ ProductionQueue.prototype.SpawnUnits = function(templateName, count, metadata)
// rally point is placed.
if (cmpRallyPoint)
{
- var rallyPos = cmpRallyPoint.GetPosition();
+ var rallyPos = cmpRallyPoint.GetPositions()[0];
if (rallyPos)
{
- ProcessCommand(cmpOwnership.GetOwner(), GetRallyPointCommand(cmpRallyPoint, spawnedEnts));
+ var commands = GetRallyPointCommands(cmpRallyPoint, spawnedEnts);
+ for each(var com in commands)
+ {
+ ProcessCommand(cmpOwnership.GetOwner(), com);
+ }
}
}
@@ -5,30 +5,31 @@ RallyPoint.prototype.Schema =
RallyPoint.prototype.Init = function()
{
- this.pos = undefined;
+ this.pos = [];
+ this.data = [];
};
-RallyPoint.prototype.SetPosition = function(x, z)
+RallyPoint.prototype.AddPosition = function(x, z)
{
- this.pos = {
+ this.pos.push({
"x": x,
"z": z
- };
+ });
};
-RallyPoint.prototype.GetPosition = function()
+RallyPoint.prototype.GetPositions = function()
{
return this.pos;
};
// Extra data for the rally point, should have a command property and then helpful data for that command
// See getActionInfo in gui/input.js
-RallyPoint.prototype.SetData = function(data)
+RallyPoint.prototype.AddData = function(data)
{
- this.data = data;
+ this.data.push(data);
};
-// Returns the data associated with this rally point. Uses the data structure:
+// Returns an array with the data associated with this rally point. Each element has the structure:
// {"type": "walk/gather/garrison/...", "target": targetEntityId, "resourceType": "tree/fruit/ore/..."} where target
// and resourceType (specific resource type) are optional, also target may be an invalid entity, check for existence.
RallyPoint.prototype.GetData = function()
@@ -38,9 +39,8 @@ RallyPoint.prototype.GetData = function()
RallyPoint.prototype.Unset = function()
{
- this.pos = undefined;
- this.data = undefined;
+ this.pos = [];
+ this.data = [];
};
-
Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);
@@ -232,8 +232,11 @@ function ProcessCommand(player, cmd)
var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
if (cmpRallyPoint)
{
- cmpRallyPoint.SetPosition(cmd.x, cmd.z);
- cmpRallyPoint.SetData(cmd.data);
+ if (!cmd.queued)
+ cmpRallyPoint.Unset();
+
+ cmpRallyPoint.AddPosition(cmd.x, cmd.z);
+ cmpRallyPoint.AddData(cmd.data);
}
}
break;
@@ -1,67 +1,76 @@
-// Returns an command suitable for ProcessCommand() based on the rally point data.
+// Returns an array of commands suitable for ProcessCommand() based on the rally point data.
// This assumes that the rally point has a valid position.
-function GetRallyPointCommand(cmpRallyPoint, spawnedEnts)
+function GetRallyPointCommands(cmpRallyPoint, spawnedEnts)
{
- // Look and see if there is a command in the rally point data, otherwise just walk there.
var data = cmpRallyPoint.GetData();
- var rallyPos = cmpRallyPoint.GetPosition();
- var command = undefined;
- if (data && data.command)
+ var rallyPos = cmpRallyPoint.GetPositions();
+ var ret = [];
+ for(var i = 0; i < rallyPos.length; ++i)
{
- command = data.command;
- }
- else
- {
- command = "walk";
- }
-
- // 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 && data.target)
- {
- var cmpPosition = Engine.QueryInterface(data.target, IID_Position);
- if (!cmpPosition || !cmpPosition.IsInWorld())
+ // 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
{
command = "walk";
}
- }
- switch (command)
- {
- case "gather":
- return {
- "type": "gather-near-position",
- "entities": spawnedEnts,
- "x": rallyPos.x,
- "z": rallyPos.z,
- "resourceType": data.resourceType,
- "queued": false
- };
- case "repair":
- case "build":
- return {
- "type": "repair",
- "entities": spawnedEnts,
- "target": data.target,
- "queued": false,
- "autocontinue": true
- };
- case "garrison":
- return {
- "type": "garrison",
- "entities": spawnedEnts,
- "target": data.target,
- "queued": false
- };
- default:
- return {
- "type": "walk",
- "entities": spawnedEnts,
- "x": rallyPos.x,
- "z": rallyPos.z,
- "queued": false
- };
+ // 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,
+ "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;
+ default:
+ ret.push( {
+ "type": "walk",
+ "entities": spawnedEnts,
+ "x": rallyPos[i].x,
+ "z": rallyPos[i].z,
+ "queued": true
+ });
+ break;
+ }
}
+ return ret;
}
-Engine.RegisterGlobal("GetRallyPointCommand", GetRallyPointCommand);
+Engine.RegisterGlobal("GetRallyPointCommands", GetRallyPointCommands);
Oops, something went wrong.

0 comments on commit 9331caf

Please sign in to comment.