petra: fight back when a cc is captured instead of retreating
Reviewed By: Sandarac Differential Revision: https://code.wildfiregames.com/D575 This was SVN commit r19698.
This commit is contained in:
parent
2e5138bad9
commit
72f6e02747
@ -89,6 +89,9 @@ m.Army.prototype.recalculateStrengths = function (gameState)
|
||||
/** adds or remove the strength of the entity either to the enemy or to our units. */
|
||||
m.Army.prototype.evaluateStrength = function (ent, isOwn, remove)
|
||||
{
|
||||
if (!ent)
|
||||
return;
|
||||
|
||||
let entStrength;
|
||||
if (ent.hasClass("Structure"))
|
||||
{
|
||||
@ -279,7 +282,7 @@ m.Army.prototype.assignUnit = function (gameState, entID)
|
||||
m.Army.prototype.clear = function (gameState)
|
||||
{
|
||||
while (this.foeEntities.length > 0)
|
||||
this.removeFoe(gameState,this.foeEntities[0]);
|
||||
this.removeFoe(gameState, this.foeEntities[0]);
|
||||
|
||||
// Go back to our territory, using the nearest (defensive if any) structure.
|
||||
let armyPos = [0, 0];
|
||||
|
@ -503,6 +503,54 @@ m.AttackManager.prototype.raidTargetEntity = function(gameState, ent)
|
||||
this.raidNumber++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Response to the capture of one of our structure:
|
||||
* transform all defense armies around into a new attack army and target this structure
|
||||
*/
|
||||
m.AttackManager.prototype.counterAttack = function(gameState, ent, range=150)
|
||||
{
|
||||
if (!ent || !ent.position())
|
||||
return false;
|
||||
let pos = ent.position();
|
||||
let attackType = "Attack";
|
||||
let attackPlan = new m.AttackPlan(gameState, this.Config, this.totalNumber, attackType);
|
||||
if (attackPlan.failed)
|
||||
return false;
|
||||
this.totalNumber++;
|
||||
attackPlan.init(gameState);
|
||||
this.startedAttacks[attackType].push(attackPlan);
|
||||
|
||||
for (let i = 0; i < gameState.ai.HQ.defenseManager.armies.length; ++i)
|
||||
{
|
||||
let army = gameState.ai.HQ.defenseManager.armies[i];
|
||||
army.recalculatePosition(gameState);
|
||||
if (API3.SquareVectorDistance(pos, army.foePosition) > range*range)
|
||||
continue;
|
||||
while (army.ownEntities.length > 0)
|
||||
{
|
||||
let unitId = army.ownEntities[0];
|
||||
army.removeOwn(gameState, unitId);
|
||||
let unit = gameState.getEntityById(unitId);
|
||||
if (unit && attackPlan.isAvailableUnit(gameState, unit))
|
||||
{
|
||||
unit.setMetadata(PlayerID, "plan", attackPlan.name);
|
||||
attackPlan.unitCollection.updateEnt(unit);
|
||||
}
|
||||
}
|
||||
gameState.ai.HQ.defenseManager.armies.splice(i--, 1);
|
||||
}
|
||||
if (!attackPlan.unitCollection.hasEntities())
|
||||
{
|
||||
attackPlan.Abort(gameState);
|
||||
return false;
|
||||
}
|
||||
attackPlan.targetPlayer = ent.owner();
|
||||
attackPlan.targetPos = pos;
|
||||
attackPlan.target = ent;
|
||||
attackPlan.state = "arrived";
|
||||
return true;
|
||||
};
|
||||
|
||||
m.AttackManager.prototype.Serialize = function()
|
||||
{
|
||||
let properties = {
|
||||
|
@ -213,6 +213,14 @@ m.HQ.prototype.checkEvents = function (gameState, events, queues)
|
||||
|
||||
for (let evt of events.OwnershipChanged) // capture events
|
||||
{
|
||||
if (gameState.isPlayerMutualAlly(evt.from) && evt.to > 0)
|
||||
{
|
||||
let ent = gameState.getEntityById(evt.entity);
|
||||
if (ent && ent.hasClass("CivCentre")) // one of our cc has been captured
|
||||
this.attackManager.counterAttack(gameState, ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (evt.to !== PlayerID)
|
||||
continue;
|
||||
let ent = gameState.getEntityById(evt.entity);
|
||||
|
Loading…
Reference in New Issue
Block a user