Petra: adapt the AI to gaia now able to launch attacks (with triggers) + cleaning of unused functions

This was SVN commit r15490.
This commit is contained in:
mimo 2014-07-04 16:12:09 +00:00
parent 9d4665248b
commit 4852fad86a
3 changed files with 8 additions and 35 deletions

View File

@ -165,7 +165,7 @@ m.BaseManager.prototype.assignResourceToDropsite = function (gameState, dropsite
this.dropsites[dropsite.id()] = true;
var self = this;
for each (var type in dropsite.resourceDropsiteTypes())
for (var type of dropsite.resourceDropsiteTypes())
{
var resources = gameState.getResourceSupplies(type);
if (resources.length === 0)

View File

@ -60,7 +60,7 @@ m.DefenseManager.prototype.isDangerous = function(gameState, entity)
return false;
// check if the entity is trying to build a new base near our buildings, and if yes, add this base in our target list
if (entity.unitAIState() == "INDIVIDUAL.REPAIR.REPAIRING")
if (entity.unitAIState() && entity.unitAIState() == "INDIVIDUAL.REPAIR.REPAIRING")
{
var targetId = entity.unitAIOrderData()[0]["target"];
if (this.targetList.indexOf(targetId) !== -1)
@ -128,8 +128,8 @@ m.DefenseManager.prototype.isDangerous = function(gameState, entity)
m.DefenseManager.prototype.checkEnemyUnits = function(gameState)
{
var nbPlayers = gameState.sharedScript.playersData.length - 1;
var i = 1 + gameState.ai.playedTurn % nbPlayers;
var nbPlayers = gameState.sharedScript.playersData.length;
var i = gameState.ai.playedTurn % nbPlayers;
if (i === PlayerID || gameState.isPlayerAlly(i))
return;
@ -143,6 +143,10 @@ m.DefenseManager.prototype.checkEnemyUnits = function(gameState)
if (ent.getMetadata(PlayerID, "PartOfArmy") !== undefined)
return;
// TODO do not bother with animals for the time being
if (ent.hasClass("Animal"))
return;
// TODO what to do for ships ?
if (ent.hasClass("Ship") || ent.hasClass("Trader"))
return;

View File

@ -695,37 +695,6 @@ m.Worker.prototype.startFishing = function(gameState)
}
};
m.Worker.prototype.getResourceType = function(type){
if (!type || !type.generic)
return undefined;
if (type.generic === "treasure")
return type.specific;
else
return type.generic;
};
m.Worker.prototype.getGatherRate = function(gameState) {
if (this.ent.getMetadata(PlayerID,"subrole") !== "gatherer")
return 0;
var rates = this.ent.resourceGatherRates();
if (this.ent.unitAIOrderData().length && this.ent.unitAIState().split(".")[1] === "GATHER" && this.ent.unitAIOrderData()[0]["target"])
{
var ress = gameState.getEntityById(this.ent.unitAIOrderData()[0]["target"]);
if (!ress)
return 0;
var type = ress.resourceSupplyType();
if (type.generic == "treasure")
return 1000;
var tstring = type.generic + "." + type.specific;
if (rates[tstring])
return rates[tstring];
return 0;
}
return 0;
};
m.Worker.prototype.gatherNearestField = function(gameState, baseID)
{
var self = this;