Petra: the AI now destroy captured buildings it can't keep

This was SVN commit r16746.
This commit is contained in:
mimo
2015-06-10 18:16:03 +00:00
parent 12d4209eed
commit 61f3d80ab0
2 changed files with 13 additions and 5 deletions
@@ -227,15 +227,16 @@ m.GarrisonManager.prototype.registerHolder = function(gameState, holder)
m.GarrisonManager.prototype.addDecayingStructure = function(gameState, entId)
{
if (this.decayingStructures.has(entId))
return;
return true;
let ent = gameState.getEntityById(entId);
// keep only useful buildings for defense
if (!ent || (!ent.hasClass("Barracks") && !ent.hasDefensiveFire()))
return;
return false;
if (!ent.territoryDecayRate() || !ent.garrisonRegenRate())
return;
return false;
let gmin = Math.ceil((ent.territoryDecayRate() - ent.defaultRegenRate()) / ent.garrisonRegenRate());
this.decayingStructures.set(entId, gmin);
return true;
};
m.GarrisonManager.prototype.removeDecayingStructure = function(entId)
@@ -246,8 +246,15 @@ m.HQ.prototype.checkEvents = function (gameState, events, queues)
m.getBestBase(gameState, ent).assignEntity(gameState, ent);
if (ent.hasTerritoryInfluence())
this.updateTerritories(gameState);
if (ent.decaying() && ent.isGarrisonHolder())
this.garrisonManager.addDecayingStructure(gameState, evt.entity);
if (ent.decaying())
{
if (ent.isGarrisonHolder())
if (this.garrisonManager.addDecayingStructure(gameState, evt.entity))
continue
let capture = ent.capturePoints();
if (capture[PlayerID] > 0.5 * capture.reduce((a, b) => a + b))
ent.destroy();
}
}
}