forked from 0ad/0ad
Petra: minor tweaks in farming
This was SVN commit r16879.
This commit is contained in:
parent
4054e5cb04
commit
27de859f9b
@ -393,20 +393,22 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
|||||||
return {"quality": bestVal, "pos": [x, z]};
|
return {"quality": bestVal, "pos": [x, z]};
|
||||||
};
|
};
|
||||||
|
|
||||||
m.BaseManager.prototype.getResourceLevel = function (gameState, type)
|
m.BaseManager.prototype.getResourceLevel = function (gameState, type, nearbyOnly = false)
|
||||||
{
|
{
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var check = {};
|
var check = {};
|
||||||
var nearby = this.dropsiteSupplies[type]["nearby"];
|
var nearby = this.dropsiteSupplies[type]["nearby"];
|
||||||
for (var supply of nearby)
|
for (let supply of nearby)
|
||||||
{
|
{
|
||||||
if (check[supply.id]) // avoid double counting as same resource can appear several time
|
if (check[supply.id]) // avoid double counting as same resource can appear several time
|
||||||
continue;
|
continue;
|
||||||
check[supply.id] = true;
|
check[supply.id] = true;
|
||||||
count += supply.ent.resourceSupplyAmount();
|
count += supply.ent.resourceSupplyAmount();
|
||||||
}
|
}
|
||||||
|
if (nearbyOnly)
|
||||||
|
return count;
|
||||||
var medium = this.dropsiteSupplies[type]["medium"];
|
var medium = this.dropsiteSupplies[type]["medium"];
|
||||||
for (var supply of medium)
|
for (let supply of medium)
|
||||||
{
|
{
|
||||||
if (check[supply.id])
|
if (check[supply.id])
|
||||||
continue;
|
continue;
|
||||||
@ -425,7 +427,7 @@ m.BaseManager.prototype.checkResourceLevels = function (gameState, queues)
|
|||||||
{
|
{
|
||||||
if (gameState.ai.HQ.canBuild(gameState, "structures/{civ}_field")) // let's see if we need to add new farms.
|
if (gameState.ai.HQ.canBuild(gameState, "structures/{civ}_field")) // let's see if we need to add new farms.
|
||||||
{
|
{
|
||||||
var count = this.getResourceLevel(gameState, type); // TODO animals are not accounted, may-be we should
|
var count = this.getResourceLevel(gameState, type, (gameState.currentPhase() > 1)); // animals are not accounted
|
||||||
var numFarms = gameState.getOwnStructures().filter(API3.Filters.byClass("Field")).length; // including foundations
|
var numFarms = gameState.getOwnStructures().filter(API3.Filters.byClass("Field")).length; // including foundations
|
||||||
var numQueue = queues.field.countQueuedUnits();
|
var numQueue = queues.field.countQueuedUnits();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user