mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
petra now try to regain capture points of its own structure, plus some bug fixes
This was SVN commit r16652.
This commit is contained in:
@@ -621,6 +621,7 @@ m.Entity = m.Class({
|
||||
needsHeal: function() { return this.isHurt() && this.isHealable(); },
|
||||
needsRepair: function() { return this.isHurt() && this.isRepairable(); },
|
||||
decaying: function() { return ((this._entity.decaying !== undefined) ? this._entity.decaying : undefined); },
|
||||
capturePoints: function() {return ((this._entity.capturePoints !== undefined) ? this._entity.capturePoints : undefined); },
|
||||
|
||||
/**
|
||||
* Returns the current training queue state, of the form
|
||||
|
||||
@@ -123,7 +123,32 @@ m.DefenseManager.prototype.checkEnemyUnits = function(gameState)
|
||||
{
|
||||
var nbPlayers = gameState.sharedScript.playersData.length;
|
||||
var i = gameState.ai.playedTurn % nbPlayers;
|
||||
if (i === PlayerID || !gameState.isPlayerEnemy(i))
|
||||
|
||||
if (i === PlayerID)
|
||||
{
|
||||
if (this.armies.length == 0)
|
||||
{
|
||||
// check if we can recover capture points from any of our notdecaying structures
|
||||
for (let ent of gameState.getOwnStructures().values())
|
||||
{
|
||||
if (ent.decaying())
|
||||
continue;
|
||||
let capture = ent.capturePoints();
|
||||
if (capture === undefined)
|
||||
continue;
|
||||
let lost = 0;
|
||||
for (let j = 0; j < capture.length; ++j)
|
||||
if (gameState.isPlayerEnemy(j))
|
||||
lost += capture[j];
|
||||
if (lost < Math.ceil(0.2 * capture[i]))
|
||||
continue;
|
||||
this.makeIntoArmy(gameState, ent.id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (!gameState.isPlayerEnemy(i))
|
||||
return;
|
||||
|
||||
// loop through enemy units
|
||||
@@ -367,7 +392,28 @@ m.DefenseManager.prototype.checkEvents = function(gameState, events)
|
||||
{
|
||||
let army = this.getArmy(target.getMetadata(PlayerID, "PartOfArmy"));
|
||||
if (army.isCapturing(gameState))
|
||||
this.abortArmy(gameState, army);
|
||||
{
|
||||
var abort = false;
|
||||
// if one of the units trying to capture a structure is attacked,
|
||||
// abort the army so that the unit can defend itself
|
||||
if (army.ownEntities.indexOf(target.id()) != -1)
|
||||
abort = true;
|
||||
else if (army.foeEntities[0] == target.id() && target.owner() == PlayerID)
|
||||
{
|
||||
// else we may be trying to regain some capture point from one of our structure
|
||||
abort = true;
|
||||
let capture = target.capturePoints();
|
||||
for (let j = 0; j < capture.length; ++j)
|
||||
{
|
||||
if (!gameState.isPlayerEnemy(j) || capture[j] == 0)
|
||||
continue;
|
||||
abort = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (abort)
|
||||
this.abortArmy(gameState, army);
|
||||
}
|
||||
}
|
||||
|
||||
if (target.hasClass("Support") && target.healthLevel() < 0.55 && !target.getMetadata(PlayerID, "transport")
|
||||
|
||||
@@ -90,16 +90,19 @@ m.GarrisonManager.prototype.update = function(gameState, queues)
|
||||
var range = holder.attackRange("Ranged").max;
|
||||
else
|
||||
var range = 80;
|
||||
var enemiesAround = gameState.getEnemyEntities().toEntityArray().some(function(ent) {
|
||||
var enemiesAround = false;
|
||||
for (let ent of gameState.getEnemyEntities().values())
|
||||
{
|
||||
if (!ent.position())
|
||||
return false;
|
||||
continue;
|
||||
if (ent.owner() === 0 && (!ent.unitAIState() || ent.unitAIState().split(".")[1] !== "COMBAT"))
|
||||
return false;
|
||||
var dist = API3.SquareVectorDistance(ent.position(), holder.position());
|
||||
if (dist < range*range)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
continue;
|
||||
let dist = API3.SquareVectorDistance(ent.position(), holder.position());
|
||||
if (dist > range*range)
|
||||
continue;
|
||||
enemiesAround = true;
|
||||
break;
|
||||
}
|
||||
|
||||
for (var entId of holder.garrisoned())
|
||||
{
|
||||
|
||||
@@ -689,12 +689,12 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
|
||||
}
|
||||
if (!cc.ally)
|
||||
continue;
|
||||
if (dist < 30000) // Reject if too near from an allied cc
|
||||
if (dist < 40000) // Reject if too near from an allied cc
|
||||
{
|
||||
norm = 0
|
||||
break;
|
||||
}
|
||||
if (dist < 50000) // Disfavor if quite near an allied cc
|
||||
if (dist < 62000) // Disfavor if quite near an allied cc
|
||||
norm *= 0.5;
|
||||
if (dist < minDist)
|
||||
minDist = dist;
|
||||
@@ -842,7 +842,7 @@ m.HQ.prototype.findStrategicCCLocation = function(gameState, template)
|
||||
}
|
||||
if (!cc.ally)
|
||||
continue;
|
||||
if (dist < 40000) // Reject if quite near from ally cc
|
||||
if (dist < 62000) // Reject if quite near from ally cc
|
||||
{
|
||||
minDist = 0;
|
||||
break;
|
||||
@@ -1134,7 +1134,7 @@ m.HQ.prototype.buildMarket = function(gameState, queues)
|
||||
if (!this.navalMap && !queues.economicBuilding.paused)
|
||||
{
|
||||
// Put available resources in this market when not a naval map
|
||||
; let queueManager = gameState.ai.queueManager;
|
||||
let queueManager = gameState.ai.queueManager;
|
||||
let cost = queues.economicBuilding.queue[0].getCost();
|
||||
queueManager.setAccounts(gameState, cost, "economicBuilding");
|
||||
if (!queueManager.accounts["economicBuilding"].canAfford(cost))
|
||||
|
||||
@@ -194,6 +194,7 @@ AIProxy.prototype.OnTerritoryDecayChanged = function(msg)
|
||||
if (!this.NotifyChange())
|
||||
return;
|
||||
this.changes.decaying = msg.to;
|
||||
this.cmpAIInterface.PushEvent("TerritoryDecayChanged", msg);
|
||||
};
|
||||
|
||||
// TODO: event handlers for all the other things
|
||||
@@ -350,9 +351,4 @@ AIProxy.prototype.OnAIMetadata = function(msg)
|
||||
this.cmpAIInterface.PushEvent("AIMetadata", msg);
|
||||
};
|
||||
|
||||
AIProxy.prototype.OnTerritoryDecayChanged = function(msg)
|
||||
{
|
||||
this.cmpAIInterface.PushEvent("TerritoryDecayChanged", msg);
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_AIProxy, "AIProxy", AIProxy);
|
||||
|
||||
Reference in New Issue
Block a user