Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/trunk'
Browse files Browse the repository at this point in the history
  • Loading branch information
KieranP committed May 24, 2012
2 parents 391b854 + 4d216dd commit 9331caf
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 266 deletions.
10 changes: 3 additions & 7 deletions binaries/data/mods/public/gui/session/input.js
Expand Up @@ -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) // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
var targetState = GetEntityState(target); 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 the target entity is a resource, dropsite, foundation, or enemy unit.
// Check if any entities in the selection can gather the requested resource, // 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 // can return to the dropsite, can build the foundation, or can attack the enemy
Expand Down Expand Up @@ -1317,12 +1312,13 @@ function doAction(action, ev)
{ {
pos = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); 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 // Display rally point at the new coordinates, to avoid display lag
Engine.GuiInterfaceCall("DisplayRallyPoint", { Engine.GuiInterfaceCall("DisplayRallyPoint", {
"entities": selection, "entities": selection,
"x": pos.x, "x": pos.x,
"z": pos.z "z": pos.z,
"queued": queued
}); });
return true; return true;


Expand Down
Expand Up @@ -215,10 +215,14 @@ GarrisonHolder.prototype.OrderWalkToRallyPoint = function(entities)
var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint); var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint);
if (cmpRallyPoint) if (cmpRallyPoint)
{ {
var rallyPos = cmpRallyPoint.GetPosition(); var rallyPos = cmpRallyPoint.GetPositions()[0];
if (rallyPos) if (rallyPos)
{ {
ProcessCommand(cmpOwnership.GetOwner(), GetRallyPointCommand(cmpRallyPoint, entities)); var commands = GetRallyPointCommands(cmpRallyPoint, entities);
for each (var com in commands)
{
ProcessCommand(cmpOwnership.GetOwner(), com);
}
} }
} }
}; };
Expand Down Expand Up @@ -295,7 +299,7 @@ GarrisonHolder.prototype.OnHealthChanged = function(msg)
cmpHealth.Kill(); cmpHealth.Kill();
} }
} }
this.entities = []; this.entities = [];
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
} }
else else
Expand Down
12 changes: 8 additions & 4 deletions binaries/data/mods/public/simulation/components/GuiInterface.js
Expand Up @@ -259,7 +259,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
if (cmpRallyPoint) 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); var cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);
Expand Down Expand Up @@ -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 * 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 * be rendered, in order to support instantaneously rendering a rally point marker at a specified location
Expand Down Expand Up @@ -677,11 +677,15 @@ GuiInterface.prototype.DisplayRallyPoint = function(player, cmd)
if (cmd.x && cmd.z) if (cmd.x && cmd.z)
pos = cmd; pos = cmd;
else 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) 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); cmpRallyPointRenderer.SetDisplayed(true);


// remember which entities have their rally points displayed so we can hide them again // remember which entities have their rally points displayed so we can hide them again
Expand Down
Expand Up @@ -442,10 +442,14 @@ ProductionQueue.prototype.SpawnUnits = function(templateName, count, metadata)
// rally point is placed. // rally point is placed.
if (cmpRallyPoint) if (cmpRallyPoint)
{ {
var rallyPos = cmpRallyPoint.GetPosition(); var rallyPos = cmpRallyPoint.GetPositions()[0];
if (rallyPos) if (rallyPos)
{ {
ProcessCommand(cmpOwnership.GetOwner(), GetRallyPointCommand(cmpRallyPoint, spawnedEnts)); var commands = GetRallyPointCommands(cmpRallyPoint, spawnedEnts);
for each(var com in commands)
{
ProcessCommand(cmpOwnership.GetOwner(), com);
}
} }
} }


Expand Down
22 changes: 11 additions & 11 deletions binaries/data/mods/public/simulation/components/RallyPoint.js
Expand Up @@ -5,30 +5,31 @@ RallyPoint.prototype.Schema =


RallyPoint.prototype.Init = function() 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, "x": x,
"z": z "z": z
}; });
}; };


RallyPoint.prototype.GetPosition = function() RallyPoint.prototype.GetPositions = function()
{ {
return this.pos; return this.pos;
}; };


// Extra data for the rally point, should have a command property and then helpful data for that command // Extra data for the rally point, should have a command property and then helpful data for that command
// See getActionInfo in gui/input.js // 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 // {"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. // and resourceType (specific resource type) are optional, also target may be an invalid entity, check for existence.
RallyPoint.prototype.GetData = function() RallyPoint.prototype.GetData = function()
Expand All @@ -38,9 +39,8 @@ RallyPoint.prototype.GetData = function()


RallyPoint.prototype.Unset = function() RallyPoint.prototype.Unset = function()
{ {
this.pos = undefined; this.pos = [];
this.data = undefined; this.data = [];
}; };



Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint); Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);
7 changes: 5 additions & 2 deletions binaries/data/mods/public/simulation/helpers/Commands.js
Expand Up @@ -232,8 +232,11 @@ function ProcessCommand(player, cmd)
var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
if (cmpRallyPoint) if (cmpRallyPoint)
{ {
cmpRallyPoint.SetPosition(cmd.x, cmd.z); if (!cmd.queued)
cmpRallyPoint.SetData(cmd.data); cmpRallyPoint.Unset();

cmpRallyPoint.AddPosition(cmd.x, cmd.z);
cmpRallyPoint.AddData(cmd.data);
} }
} }
break; break;
Expand Down
121 changes: 65 additions & 56 deletions binaries/data/mods/public/simulation/helpers/RallyPointCommands.js
@@ -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. // 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 data = cmpRallyPoint.GetData();
var rallyPos = cmpRallyPoint.GetPosition(); var rallyPos = cmpRallyPoint.GetPositions();
var command = undefined; var ret = [];
if (data && data.command) for(var i = 0; i < rallyPos.length; ++i)
{ {
command = data.command; // Look and see if there is a command in the rally point data, otherwise just walk there.
} var command = undefined;
else if (data[i] && data[i].command)
{ {
command = "walk"; command = data[i].command;
} }

else
// 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())
{ {
command = "walk"; command = "walk";
} }
}


switch (command) // 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.
case "gather": if (data[i] && data[i].target)
return { {
"type": "gather-near-position", var cmpPosition = Engine.QueryInterface(data[i].target, IID_Position);
"entities": spawnedEnts, if (!cmpPosition || !cmpPosition.IsInWorld())
"x": rallyPos.x, {
"z": rallyPos.z, command = "walk";
"resourceType": data.resourceType, }
"queued": false }
};
case "repair": switch (command)
case "build": {
return { case "gather":
"type": "repair", ret.push( {
"entities": spawnedEnts, "type": "gather-near-position",
"target": data.target, "entities": spawnedEnts,
"queued": false, "x": rallyPos[i].x,
"autocontinue": true "z": rallyPos[i].z,
}; "resourceType": data[i].resourceType,
case "garrison": "queued": true
return { });
"type": "garrison", break;
"entities": spawnedEnts, case "repair":
"target": data.target, case "build":
"queued": false ret.push( {
}; "type": "repair",
default: "entities": spawnedEnts,
return { "target": data[i].target,
"type": "walk", "queued": true,
"entities": spawnedEnts, "autocontinue": (i == rallyPos.length-1)
"x": rallyPos.x, });
"z": rallyPos.z, break;
"queued": false 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);

0 comments on commit 9331caf

Please sign in to comment.