1
0
forked from 0ad/0ad

give possibility to choose type of targets in moveAttack, fixes #2740

This was SVN commit r15671.
This commit is contained in:
mimo 2014-08-24 11:51:03 +00:00
parent ac9d4f1036
commit 2f1d143dc2
6 changed files with 40 additions and 21 deletions

View File

@ -278,6 +278,7 @@ hotkey.session.kill = Delete ; Destroy selected units
hotkey.session.stop = "H" ; Stop the current action
hotkey.session.attack = "Ctrl+Alt" ; Modifier to force attack instead of another action
hotkey.session.attackmove = Ctrl ; Modifier to attackmove when clicking on a point
hotkey.session.attackmoveUnit = "Ctrl+Q" ; Modifier to attackmove targeting only units when clicking on a point
hotkey.session.garrison = Ctrl ; Modifier to garrison when clicking on building
hotkey.session.autorallypoint = Ctrl ; Modifier to set the rally point on the building itself
hotkey.session.guard = "G" ; Modifier to escort/guard when clicking on unit/building

View File

@ -60,7 +60,12 @@ var unitActions =
{
"execute": function(target, action, selection, queued)
{
Engine.PostNetworkCommand({"type": "attack-walk", "entities": selection, "x": target.x, "z": target.z, "queued": queued});
if (Engine.HotkeyIsPressed("session.attackmoveUnit"))
var targetClasses = { "attack": ["Unit"] };
else
var targetClasses = { "attack": ["Unit", "Structure"] };
Engine.PostNetworkCommand({"type": "attack-walk", "entities": selection, "x": target.x, "z": target.z, "targetClasses": targetClasses, "queued": queued});
Engine.GuiInterfaceCall("PlaySound", { "name": "order_walk", "entity": selection[0] });
return true;
},

View File

@ -720,9 +720,9 @@ m.Entity = m.Class({
return this;
},
attackMove: function(x, z, queued) {
attackMove: function(x, z, targetClasses, queued) {
queued = queued || false;
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": [this.id()], "x": x, "z": z, "queued": queued });
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": [this.id()], "x": x, "z": z, "targetClasses": targetClasses, "queued": queued });
return this;
},

View File

@ -228,10 +228,10 @@ m.EntityCollection.prototype.move = function(x, z, queued)
return this;
};
m.EntityCollection.prototype.attackMove = function(x, z, queued)
m.EntityCollection.prototype.attackMove = function(x, z, targetClasses, queued)
{
queued = queued || false;
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": this.toIdArray(), "x": x, "z": z, "queued": queued});
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": this.toIdArray(), "x": x, "z": z, "targetClasses": targetClasses, "queued": queued});
return this;
};

View File

@ -4920,10 +4920,11 @@ UnitAI.prototype.WalkToTarget = function(target, queued)
/**
* Adds walk-and-fight order to queue, this only occurs in response
* to a player order, and so is forced.
* If targetClasses is given, only entities matching the targetClasses can be attacked.
*/
UnitAI.prototype.WalkAndFight = function(x, z, queued)
UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, queued)
{
this.AddOrder("WalkAndFight", { "x": x, "z": z, "force": true }, queued);
this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
};
/**
@ -5328,29 +5329,41 @@ UnitAI.prototype.FindWalkAndFightTargets = function()
var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
for each (var ent in cmpFormation.members)
{
if (!(cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI)))
if (!(cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI)))
continue;
var targets = cmpUnitAI.GetTargetsFromUnit();
for each (var targ in targets)
for (var targ of targets)
{
if (cmpUnitAI.CanAttack(targ))
{
this.PushOrderFront("Attack", { "target": targ, "force": true });
return true;
}
if (!cmpUnitAI.CanAttack(targ))
continue;
var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
if (cmpIdentity && this.order.data.targetClasses.attack
&& !MatchesClassList(cmpIdentity.GetClassesList(), this.order.data.targetClasses.attack))
continue;
if (cmpIdentity && this.order.data.targetClasses.avoid
&& MatchesClassList(cmpIdentity.GetClassesList(), this.order.data.targetClasses.avoid))
continue;
this.PushOrderFront("Attack", { "target": targ, "force": true });
return true;
}
}
return false;
}
var targets = this.GetTargetsFromUnit();
for each (var targ in targets)
for (var targ of targets)
{
if (this.CanAttack(targ))
{
this.PushOrderFront("Attack", { "target": targ, "force": true });
return true;
}
if (!this.CanAttack(targ))
continue;
var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
if (cmpIdentity && this.order.data.targetClasses.attack
&& !MatchesClassList(cmpIdentity.GetClassesList(), this.order.data.targetClasses.attack))
continue;
if (cmpIdentity && this.order.data.targetClasses.avoid
&& MatchesClassList(cmpIdentity.GetClassesList(), this.order.data.targetClasses.avoid))
continue;
this.PushOrderFront("Attack", { "target": targ, "force": true });
return true;
}
return false;
};

View File

@ -130,7 +130,7 @@ var commands = {
"attack-walk": function(player, cmd, data)
{
GetFormationUnitAIs(data.entities, player).forEach(function(cmpUnitAI) {
cmpUnitAI.WalkAndFight(cmd.x, cmd.z, cmd.queued);
cmpUnitAI.WalkAndFight(cmd.x, cmd.z, cmd.targetClasses, cmd.queued);
});
},