Simple petra AI regicide support. Patch by Sandarac, refs #4142.

The AI will retreat the hero in regicide games once it reaches less than
70% health.
It will garrison it in healing structures. Elephant heroes will retreat
to the home base.
Once the hero has healed, it will be used for attacks again.

This was SVN commit r18731.
This commit is contained in:
elexis 2016-09-18 14:27:03 +00:00
parent caef42084d
commit 02848dcd17
2 changed files with 38 additions and 1 deletions

View File

@ -643,6 +643,8 @@ m.AttackPlan.prototype.assignUnits = function(gameState)
continue;
if (ent.hasClass("Ship") || ent.hasClass("Support") || ent.attackTypes() === undefined)
continue;
if (gameState.getGameType() === "regicide" && ent.hasClass("Hero") && (this.overseas || ent.healthLevel() < 0.8))
continue;
ent.setMetadata(PlayerID, "plan", plan);
this.unitCollection.updateEnt(ent);
added = true;

View File

@ -388,6 +388,8 @@ m.DefenseManager.prototype.assignDefenders = function(gameState)
return;
if (ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined)
return;
if (gameState.getGameType() === "regicide" && ent.hasClass("Hero") && ent.healthLevel() < 0.8)
return;
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") !== -1)
{
let subrole = ent.getMetadata(PlayerID, "subrole");
@ -475,8 +477,41 @@ m.DefenseManager.prototype.checkEvents = function(gameState, events)
if (target.hasClass("Ship")) // TODO integrate ships later need to be sure it is accessible
continue;
// If inside a started attack plan, let the plan deal with this unit
let plan = target.getMetadata(PlayerID, "plan");
// Retreat the hero in regicide mode if wounded
if (gameState.getGameType() == "regicide" && target.hasClass("Hero") && target.healthLevel() < 0.7)
{
target.stopMoving();
if (plan >= 0)
{
let attackPlan = gameState.ai.HQ.attackManager.getPlan(target.getMetadata(PlayerID, "plan"));
if (attackPlan)
attackPlan.removeUnit(target, true);
}
if (target.getMetadata(PlayerID, "PartOfArmy"))
{
let army = gameState.ai.HQ.defenseManager.getArmy(target.getMetadata(PlayerID, "PartOfArmy"));
if (army)
army.removeOwn(gameState, target.id());
}
this.garrisonUnitForHealing(gameState, target);
if (plan >= 0) // couldn't find a place to garrison, so the hero will flee from attacks
{
target.setStance("passive");
let accessIndex = gameState.ai.accessibility.getAccessValue(target.position());
let basePos = m.getBestBase(gameState, target);
if (basePos && basePos.accessIndex == accessIndex)
target.move(basePos.anchor.position()[0], basePos.anchor.position()[1]);
}
continue;
}
// If inside a started attack plan, let the plan deal with this unit
if (plan !== undefined && plan >= 0)
{
let attack = gameState.ai.HQ.attackManager.getPlan(plan);