mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-28 15:13:47 +00:00
petra: let the ai capture gaia structures
This was SVN commit r16602.
This commit is contained in:
@@ -91,7 +91,11 @@ 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)
|
||||
{
|
||||
var entStrength = m.getMaxStrength(ent);
|
||||
if (ent.hasClass("Structure"))
|
||||
var entStrength = (ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4);
|
||||
else
|
||||
var entStrength = m.getMaxStrength(ent);
|
||||
|
||||
if (remove)
|
||||
entStrength *= -1;
|
||||
|
||||
@@ -99,8 +103,6 @@ m.Army.prototype.evaluateStrength = function (ent, isOwn, remove)
|
||||
this.ownStrength += entStrength;
|
||||
else
|
||||
this.foeStrength += entStrength;
|
||||
|
||||
// todo: deal with specifics.
|
||||
};
|
||||
|
||||
// add an entity to the enemy army
|
||||
|
||||
@@ -31,7 +31,7 @@ m.DefenseArmy.prototype.assignUnit = function (gameState, entID)
|
||||
if (!eEnt || !eEnt.position()) // probably can't happen.
|
||||
continue;
|
||||
|
||||
if (eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length &&
|
||||
if (eEnt.hasClass("Unit") && eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length &&
|
||||
eEnt.unitAIOrderData()[0]["target"] && eEnt.unitAIOrderData()[0]["target"] == entID)
|
||||
{ // being attacked >>> target the unit
|
||||
idMin = id;
|
||||
|
||||
@@ -126,35 +126,46 @@ m.DefenseManager.prototype.checkEnemyUnits = function(gameState)
|
||||
if (i === PlayerID || gameState.isPlayerAlly(i))
|
||||
return;
|
||||
|
||||
var self = this;
|
||||
|
||||
// loop through enemy units
|
||||
gameState.getEnemyUnits(i).forEach( function (ent) {
|
||||
// first check: is this unit already part of an army.
|
||||
for (let ent of gameState.getEnemyUnits(i).values())
|
||||
{
|
||||
if (ent.getMetadata(PlayerID, "PartOfArmy") !== undefined)
|
||||
return;
|
||||
continue;
|
||||
|
||||
// keep animals attacking us or our allies
|
||||
if (ent.hasClass("Animal"))
|
||||
{
|
||||
if (!ent.unitAIState() || ent.unitAIState().split(".")[1] !== "COMBAT")
|
||||
return;
|
||||
continue;
|
||||
let orders = ent.unitAIOrderData();
|
||||
if (!orders || !orders.length || !orders[0]["target"])
|
||||
return;
|
||||
continue;
|
||||
let target = gameState.getEntityById(orders[0]["target"]);
|
||||
if (!target || !gameState.isPlayerAlly(target.owner()))
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO what to do for ships ?
|
||||
if (ent.hasClass("Ship") || ent.hasClass("Trader"))
|
||||
return;
|
||||
continue;
|
||||
|
||||
// check if unit is dangerous "a priori"
|
||||
if (self.isDangerous(gameState, ent))
|
||||
self.makeIntoArmy(gameState, ent.id());
|
||||
});
|
||||
if (this.isDangerous(gameState, ent))
|
||||
this.makeIntoArmy(gameState, ent.id());
|
||||
}
|
||||
|
||||
if ( i !== 0)
|
||||
return;
|
||||
// look for possible gaia buildings inside our territory (may happen when enemy resign or after structure decay)
|
||||
for (let ent of gameState.getEnemyStructures(i).values())
|
||||
{
|
||||
if (!ent.position() || ent.getMetadata(PlayerID, "PartOfArmy") !== undefined)
|
||||
continue;
|
||||
|
||||
let owner = this.territoryMap.getOwner(ent.position());;
|
||||
if (owner === PlayerID)
|
||||
this.makeIntoArmy(gameState, ent.id());
|
||||
}
|
||||
};
|
||||
|
||||
m.DefenseManager.prototype.checkEnemyArmies = function(gameState, events)
|
||||
|
||||
Reference in New Issue
Block a user