add allowCapture argument to moveAttack (and patrol) commands

Discussed with elexis

Differential Revision: https://code.wildfiregames.com/D1150
This was SVN commit r20665.
This commit is contained in:
mimo 2017-12-19 19:24:48 +00:00
parent d2238ece6d
commit 5df1f4ec4c
6 changed files with 32 additions and 26 deletions

View File

@ -306,8 +306,9 @@ Trigger.prototype.StartAnEnemyWave = function()
"entities": entities,
"x": targetPos.x,
"z": targetPos.y,
"queued": true,
"targetClasses": undefined
"targetClasses": undefined,
"allowCapture": false,
"queued": true
});
if (attackerTemplate.hero)

View File

@ -22,8 +22,9 @@ Trigger.prototype.SpawnAndAttack = function()
continue;
cmd.type = "attack-walk";
cmd.entities = intruders[origin];
cmd.queued = true;
cmd.targetClasses = { "attack": ["Unit", "Structure"] };
cmd.allowCapture = false;
cmd.queued = true;
ProcessCommand(0, cmd);
}

View File

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

View File

@ -146,30 +146,28 @@ m.EntityCollection.prototype.hasEntities = function()
return this._entities.size !== 0;
};
m.EntityCollection.prototype.move = function(x, z, queued)
m.EntityCollection.prototype.move = function(x, z, queued = false)
{
queued = queued || false;
Engine.PostCommand(PlayerID,{"type": "walk", "entities": this.toIdArray(), "x": x, "z": z, "queued": queued});
return this;
};
m.EntityCollection.prototype.moveToRange = function(x, z, min, max, queued)
m.EntityCollection.prototype.moveToRange = function(x, z, min, max, queued = false)
{
queued = queued || false;
Engine.PostCommand(PlayerID,{"type": "walk-to-range", "entities": this.toIdArray(), "x": x, "z": z, "min": min, "max": max, "queued": queued });
Engine.PostCommand(PlayerID,{"type": "walk-to-range", "entities": this.toIdArray(), "x": x, "z": z,
"min": min, "max": max, "queued": queued });
return this;
};
m.EntityCollection.prototype.attackMove = function(x, z, targetClasses, queued)
m.EntityCollection.prototype.attackMove = function(x, z, targetClasses, allowCapture = true, queued = false)
{
queued = queued || false;
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": this.toIdArray(), "x": x, "z": z, "targetClasses": targetClasses, "queued": queued});
Engine.PostCommand(PlayerID,{"type": "attack-walk", "entities": this.toIdArray(), "x": x, "z": z,
"targetClasses": targetClasses, "allowCapture": allowCapture, "queued": queued});
return this;
};
m.EntityCollection.prototype.moveIndiv = function(x, z, queued)
m.EntityCollection.prototype.moveIndiv = function(x, z, queued = false)
{
queued = queued || false;
for (let id of this._entities.keys())
Engine.PostCommand(PlayerID,{"type": "walk", "entities": [id], "x": x, "z": z, "queued": queued});
return this;

View File

@ -1111,6 +1111,7 @@ UnitAI.prototype.UnitFsmSpec = {
{
this.patrolStartPosOrder = cmpPosition.GetPosition();
this.patrolStartPosOrder.targetClasses = this.order.data.targetClasses;
this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture;
}
this.StartTimer(0, 1000);
@ -1638,6 +1639,7 @@ UnitAI.prototype.UnitFsmSpec = {
{
this.patrolStartPosOrder = cmpPosition.GetPosition();
this.patrolStartPosOrder.targetClasses = this.order.data.targetClasses;
this.patrolStartPosOrder.allowCapture = this.order.data.allowCapture;
}
this.StartTimer(0, 1000);
@ -1655,7 +1657,7 @@ UnitAI.prototype.UnitFsmSpec = {
"MoveCompleted": function() {
if (this.orderQueue.length == 1)
this.PushOrder("Patrol",this.patrolStartPosOrder);
this.PushOrder("Patrol", this.patrolStartPosOrder);
this.PushOrder(this.order.type, this.order.data);
this.FinishOrder();
@ -5070,12 +5072,12 @@ UnitAI.prototype.WalkToTarget = function(target, queued)
* 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, targetClasses, queued)
UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, allowCapture = true, queued = false)
{
this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued);
};
UnitAI.prototype.Patrol = function(x, z, targetClasses, queued)
UnitAI.prototype.Patrol = function(x, z, targetClasses, allowCapture = true, queued = false)
{
if (!this.CanPatrol())
{
@ -5083,7 +5085,7 @@ UnitAI.prototype.Patrol = function(x, z, targetClasses, queued)
return;
}
this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "allowCapture": allowCapture, "force": true }, queued);
};
/**
@ -5104,7 +5106,7 @@ UnitAI.prototype.LeaveFoundation = function(target)
/**
* Adds attack order to the queue, forced by the player.
*/
UnitAI.prototype.Attack = function(target, queued, allowCapture)
UnitAI.prototype.Attack = function(target, allowCapture = true, queued = false)
{
if (!this.CanAttack(target))
{
@ -5541,7 +5543,7 @@ UnitAI.prototype.FindWalkAndFightTargets = function()
if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
continue;
}
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true });
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture });
return true;
}
}
@ -5567,7 +5569,7 @@ UnitAI.prototype.FindWalkAndFightTargets = function()
if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
continue;
}
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": true });
this.PushOrderFront("Attack", { "target": targ, "force": true, "allowCapture": this.order.data.allowCapture });
return true;
}

View File

@ -165,8 +165,10 @@ var g_Commands = {
"attack-walk": function(player, cmd, data)
{
let allowCapture = cmd.allowCapture || cmd.allowCapture == null;
GetFormationUnitAIs(data.entities, player).forEach(cmpUnitAI => {
cmpUnitAI.WalkAndFight(cmd.x, cmd.z, cmd.targetClasses, cmd.queued);
cmpUnitAI.WalkAndFight(cmd.x, cmd.z, cmd.targetClasses, allowCapture, cmd.queued);
});
},
@ -179,14 +181,16 @@ var g_Commands = {
warn("Invalid command: attack target is not owned by enemy of player "+player+": "+uneval(cmd));
GetFormationUnitAIs(data.entities, player).forEach(cmpUnitAI => {
cmpUnitAI.Attack(cmd.target, cmd.queued, allowCapture);
cmpUnitAI.Attack(cmd.target, allowCapture, cmd.queued);
});
},
"patrol": function(player, cmd, data)
{
let allowCapture = cmd.allowCapture || cmd.allowCapture == null;
GetFormationUnitAIs(data.entities, player).forEach(cmpUnitAI =>
cmpUnitAI.Patrol(cmd.x, cmd.z, cmd.targetClasses, cmd.queued)
cmpUnitAI.Patrol(cmd.x, cmd.z, cmd.targetClasses, allowCapture, cmd.queued)
);
},