Allow setting rallypoint on enemy entities. Patch by maveric, fixes #1046

This was SVN commit r16680.
This commit is contained in:
sanderd17 2015-05-26 10:59:09 +00:00
parent 84ba6c0719
commit b65c232e51
3 changed files with 35 additions and 3 deletions

View File

@ -560,6 +560,12 @@ var unitActions =
data.target = targetState.id;
cursor = "action-repair";
}
else if (playerCheck(entState, targetState, ["Enemy"]))
{
data.target = targetState.id;
data.command = "attack";
cursor = "action-attack";
}
// Don't allow the rally point to be set on any of the currently selected entities (used for unset)
// except if the autorallypoint hotkey is pressed and the target can produce entities

View File

@ -20,19 +20,24 @@ RallyPoint.prototype.AddPosition = function(x, z)
RallyPoint.prototype.GetPositions = function()
{
// Update positions for moving target entities
// TODO: If we target an enemy unit we should update its position
// as long as it is outside of FoW and SoD.
// We must not affect the simulation state here (modifications of the
// RallyPointRenderer are allowed though), so copy the state
var ret = [];
for (var i = 0; i < this.pos.length; i++)
{
ret.push(this.pos[i]);
if (!this.data[i] || !this.data[i].target)
continue;
if (this.data[i].command && this.data[i].command == "attack")
{
var cmpBuildingAI = Engine.QueryInterface(this.entity, IID_BuildingAI);
if (!cmpBuildingAI.CheckTargetVisible(this.data[i].target) || !this.TargetIsAlive(this.data[i].target))
continue;
}
// Get the actual position of the target entity
var cmpPosition = Engine.QueryInterface(this.data[i].target, IID_Position);
@ -97,4 +102,17 @@ RallyPoint.prototype.OnGlobalEntityRenamed = function(msg)
}
};
/**
* Returns true if the target exists and has non-zero hitpoints.
*/
RallyPoint.prototype.TargetIsAlive = function(ent)
{
var cmpFormation = Engine.QueryInterface(ent, IID_Formation);
if (cmpFormation)
return true;
var cmpHealth = QueryMiragedInterface(ent, IID_Health);
return cmpHealth && cmpHealth.GetHitpoints() != 0;
};
Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);

View File

@ -70,6 +70,14 @@ function GetRallyPointCommands(cmpRallyPoint, spawnedEnts)
"queued": true
});
break;
case "attack":
ret.push( {
"type": "attack",
"entities": spawnedEnts,
"target": data[i].target,
"queued": true,
});
break;
case "trade":
ret.push( {
"type": "setup-trade-route",