forked from 0ad/0ad
petra cleanup
This was SVN commit r17831.
This commit is contained in:
parent
bcf2c75513
commit
5a8d7d1a58
@ -187,11 +187,12 @@ m.BaseManager.prototype.assignResourceToDropsite = function (gameState, dropsite
|
|||||||
warn("assignResourceToDropsite: dropsite already in the list. Should never happen");
|
warn("assignResourceToDropsite: dropsite already in the list. Should never happen");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.dropsites[dropsite.id()] = true;
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
let dropsitePos = dropsite.position();
|
|
||||||
let accessIndex = this.accessIndex;
|
let accessIndex = this.accessIndex;
|
||||||
|
let dropsitePos = dropsite.position();
|
||||||
|
let dropsiteId = dropsite.id();
|
||||||
|
this.dropsites[dropsiteId] = true;
|
||||||
|
|
||||||
if (this.ID === gameState.ai.HQ.baseManagers[0].ID)
|
if (this.ID === gameState.ai.HQ.baseManagers[0].ID)
|
||||||
{
|
{
|
||||||
accessIndex = dropsite.getMetadata(PlayerID, "access");
|
accessIndex = dropsite.getMetadata(PlayerID, "access");
|
||||||
@ -202,15 +203,16 @@ m.BaseManager.prototype.assignResourceToDropsite = function (gameState, dropsite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var type of dropsite.resourceDropsiteTypes())
|
let maxDistResourceSquare = this.maxDistResourceSquare;
|
||||||
|
for (let type of dropsite.resourceDropsiteTypes())
|
||||||
{
|
{
|
||||||
var resources = gameState.getResourceSupplies(type);
|
let resources = gameState.getResourceSupplies(type);
|
||||||
if (!resources.length)
|
if (!resources.length)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var nearby = this.dropsiteSupplies[type].nearby;
|
let nearby = this.dropsiteSupplies[type].nearby;
|
||||||
var medium = this.dropsiteSupplies[type].medium;
|
let medium = this.dropsiteSupplies[type].medium;
|
||||||
var faraway = this.dropsiteSupplies[type].faraway;
|
let faraway = this.dropsiteSupplies[type].faraway;
|
||||||
|
|
||||||
resources.forEach(function(supply)
|
resources.forEach(function(supply)
|
||||||
{
|
{
|
||||||
@ -233,14 +235,14 @@ m.BaseManager.prototype.assignResourceToDropsite = function (gameState, dropsite
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
let dist = API3.SquareVectorDistance(supply.position(), dropsitePos);
|
let dist = API3.SquareVectorDistance(supply.position(), dropsitePos);
|
||||||
if (dist < self.maxDistResourceSquare)
|
if (dist < maxDistResourceSquare)
|
||||||
{
|
{
|
||||||
if (dist < self.maxDistResourceSquare/16) // distmax/4
|
if (dist < maxDistResourceSquare/16) // distmax/4
|
||||||
nearby.push({ "dropsite": dropsite.id(), "id": supply.id(), "ent": supply, "dist": dist });
|
nearby.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
|
||||||
else if (dist < self.maxDistResourceSquare/4) // distmax/2
|
else if (dist < maxDistResourceSquare/4) // distmax/2
|
||||||
medium.push({ "dropsite": dropsite.id(), "id": supply.id(), "ent": supply, "dist": dist });
|
medium.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
|
||||||
else
|
else
|
||||||
faraway.push({ "dropsite": dropsite.id(), "id": supply.id(), "ent": supply, "dist": dist });
|
faraway.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -325,12 +327,12 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
|||||||
|
|
||||||
for (let j of this.territoryIndices)
|
for (let j of this.territoryIndices)
|
||||||
{
|
{
|
||||||
var i = territoryMap.getNonObstructedTile(j, radius, obstructions);
|
let i = territoryMap.getNonObstructedTile(j, radius, obstructions);
|
||||||
if (i < 0) // no room around
|
if (i < 0) // no room around
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// we add 3 times the needed resource and once the other two (not food)
|
// we add 3 times the needed resource and once the other two (not food)
|
||||||
var total = 0;
|
let total = 0;
|
||||||
for (let res in gameState.sharedScript.resourceMaps)
|
for (let res in gameState.sharedScript.resourceMaps)
|
||||||
{
|
{
|
||||||
if (res === "food")
|
if (res === "food")
|
||||||
@ -344,7 +346,7 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
|||||||
if (total <= bestVal)
|
if (total <= bestVal)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)];
|
let pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)];
|
||||||
|
|
||||||
for (let dp of dpEnts)
|
for (let dp of dpEnts)
|
||||||
{
|
{
|
||||||
@ -400,8 +402,7 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, nearbyOnly
|
|||||||
{
|
{
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var check = {};
|
var check = {};
|
||||||
var nearby = this.dropsiteSupplies[type].nearby;
|
for (let supply of this.dropsiteSupplies[type].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;
|
||||||
@ -410,8 +411,8 @@ m.BaseManager.prototype.getResourceLevel = function (gameState, type, nearbyOnly
|
|||||||
}
|
}
|
||||||
if (nearbyOnly)
|
if (nearbyOnly)
|
||||||
return count;
|
return count;
|
||||||
var medium = this.dropsiteSupplies[type].medium;
|
|
||||||
for (let supply of medium)
|
for (let supply of this.dropsiteSupplies[type].medium)
|
||||||
{
|
{
|
||||||
if (check[supply.id])
|
if (check[supply.id])
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user