a few fixes and tweaks for petra

This was SVN commit r16651.
This commit is contained in:
mimo 2015-05-13 15:37:49 +00:00
parent d41671044a
commit 4b9e11eedd
5 changed files with 36 additions and 12 deletions

View File

@ -233,11 +233,12 @@ m.Army.prototype.removeOwn = function (gameState, id, Entity)
return true;
};
// Special army set to capture a gaia building
// Special army set to capture a gaia building.
// It must only contain one foe (the building to capture) and never be merged
m.Army.prototype.isCapturing = function (gameState)
{
if (this.foeEntities.length != 1)
return false;
return false;
let ent = gameState.getEntityById(this.foeEntities[0]);
return (ent && ent.hasClass("Structure"));
};

View File

@ -28,7 +28,7 @@ m.DefenseManager.prototype.makeIntoArmy = function(gameState, entityID)
{
// Try to add it to an existing army.
for (let army of this.armies)
if (army.addFoe(gameState, entityID))
if (!army.isCapturing(gameState) && army.addFoe(gameState, entityID))
return; // over
// Create a new army for it.

View File

@ -166,7 +166,7 @@ m.dumpEntity = function(ent)
+ " state " + ent.unitAIState());
API3.warn(" base " + ent.getMetadata(PlayerID, "base") + " >>> role " + ent.getMetadata(PlayerID, "role")
+ " subrole " + ent.getMetadata(PlayerID, "subrole"));
API3.warn(" health " + ent.hitpoints() + " healthMax " + ent.maxHitpoints());
API3.warn("owner " + ent.owner() + " health " + ent.hitpoints() + " healthMax " + ent.maxHitpoints());
API3.warn(" garrisoning " + ent.getMetadata(PlayerID, "garrisoning") + " garrisonHolder " + ent.getMetadata(PlayerID, "garrisonHolder")
+ " plan " + ent.getMetadata(PlayerID, "plan") + " transport " + ent.getMetadata(PlayerID, "transport")
+ " gather-type " + ent.getMetadata(PlayerID, "gather-type") + " target-foundation " + ent.getMetadata(PlayerID, "target-foundation")

View File

@ -1125,12 +1125,35 @@ m.HQ.prototype.buildTemple = function(gameState, queues)
m.HQ.prototype.buildMarket = function(gameState, queues)
{
if (gameState.getPopulation() < this.Config.Economy.popForMarket ||
queues.economicBuilding.countQueuedUnitsWithClass("BarterMarket") != 0 ||
gameState.getOwnEntitiesByClass("BarterMarket", true).length != 0)
if (gameState.getOwnEntitiesByClass("BarterMarket", true).length > 0 ||
!this.canBuild(gameState, "structures/{civ}_market"))
return;
if (!this.canBuild(gameState, "structures/{civ}_market"))
if (queues.economicBuilding.countQueuedUnitsWithClass("BarterMarket") > 0)
{
if (!this.navalMap && !queues.economicBuilding.paused)
{
// Put available resources in this market when not a naval map
; let queueManager = gameState.ai.queueManager;
let cost = queues.economicBuilding.queue[0].getCost();
queueManager.setAccounts(gameState, cost, "economicBuilding");
if (!queueManager.accounts["economicBuilding"].canAfford(cost))
{
for (let p in queueManager.queues)
{
if (p === "economicBuilding")
continue;
queueManager.transferAccounts(cost, p, "economicBuilding");
if (queueManager.accounts["economicBuilding"].canAfford(cost))
break;
}
}
}
return;
}
if (gameState.getPopulation() < this.Config.Economy.popForMarket)
return;
gameState.ai.queueManager.changePriority("economicBuilding", 3*this.Config.priorities.economicBuilding);
var plan = new m.ConstructionPlan(gameState, "structures/{civ}_market");
plan.onStart = function(gameState) { gameState.ai.queueManager.changePriority("economicBuilding", gameState.ai.Config.priorities.economicBuilding); };

View File

@ -79,7 +79,7 @@ m.Worker.prototype.update = function(ent, gameState)
&& supplyId !== this.ent.getMetadata(PlayerID, "supply"))
{
var nbGatherers = supply.resourceSupplyNumGatherers() + m.GetTCGatherer(gameState, supplyId);
if (nbGatherers > 0 && supply.resourceSupplyAmount()/nbGatherers < 40)
if (nbGatherers > 1 && supply.resourceSupplyAmount()/nbGatherers < 30)
{
m.RemoveTCGatherer(gameState, supplyId);
this.startGathering(gameState);
@ -256,7 +256,7 @@ m.Worker.prototype.startGathering = function(gameState)
// check if available resource is worth one additionnal gatherer (except for farms)
var nbGatherers = supplies[i].ent.resourceSupplyNumGatherers() + m.GetTCGatherer(gameState, supplies[i].id);
if (supplies[i].ent.resourceSupplyType()["specific"] !== "grain"
&& nbGatherers > 0 && supplies[i].ent.resourceSupplyAmount()/(1+nbGatherers) < 40)
&& nbGatherers > 0 && supplies[i].ent.resourceSupplyAmount()/(1+nbGatherers) < 30)
continue;
// not in ennemy territory
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(supplies[i].ent.position());
@ -532,7 +532,7 @@ m.Worker.prototype.startHunting = function(gameState, position)
return;
// check if available resource is worth one additionnal gatherer (except for farms)
var nbGatherers = supply.resourceSupplyNumGatherers() + m.GetTCGatherer(gameState, supply.id());
if (nbGatherers > 0 && supply.resourceSupplyAmount()/(1+nbGatherers) < 40)
if (nbGatherers > 0 && supply.resourceSupplyAmount()/(1+nbGatherers) < 30)
return;
var canFlee = (!supply.hasClass("Domestic") && supply.templateName().indexOf("resource|") == -1);
@ -630,7 +630,7 @@ m.Worker.prototype.startFishing = function(gameState)
return;
// check if available resource is worth one additionnal gatherer (except for farms)
var nbGatherers = supply.resourceSupplyNumGatherers() + m.GetTCGatherer(gameState, supply.id());
if (nbGatherers > 0 && supply.resourceSupplyAmount()/(1+nbGatherers) < 40)
if (nbGatherers > 0 && supply.resourceSupplyAmount()/(1+nbGatherers) < 30)
return;
// check that it is accessible