1
0
forked from 0ad/0ad

Made terrain analysis pick better starting points and increased the distance check in economy to match the changed distance measure using distance to dropsite.

Terrain analysis now only picks a start point if it is within a region
of size >10.
The economy code only does a distance check if there are >100 entities
of that resource on the map so rare resources are gathered.
Modified some debug output as well.

This was SVN commit r10773.
This commit is contained in:
Jonathan Waller 2011-12-19 19:41:36 +00:00
parent e56a0edc2c
commit 436163a60f
3 changed files with 43 additions and 8 deletions

View File

@ -126,11 +126,15 @@ EconomyManager.prototype.reassignIdleWorkers = function(gameState) {
}
var types = self.pickMostNeededResources(gameState);
//debug("Most Needed Resources: " + uneval(types));
for ( var typeKey in types) {
var type = types[typeKey];
// Make sure there are actually some resources of that type
if (!resourceSupplies[type])
if (!resourceSupplies[type]){
debug("No " + type + " found!");
continue;
}
var numSupplies = resourceSupplies[type].length;
// TODO: we should care about gather rates of workers
@ -157,7 +161,7 @@ EconomyManager.prototype.reassignIdleWorkers = function(gameState) {
return;
}
// And don't go for the bloody fish!
// And don't go for the bloody fish! TODO: remove after alpha 8
if (supply.entity.hasClass("SeaCreature")){
return;
}
@ -175,8 +179,8 @@ EconomyManager.prototype.reassignIdleWorkers = function(gameState) {
}
// Skip targets that are far too far away (e.g. in the
// enemy base)
if (dist > 512){
// enemy base), only do this for common supplies
if (dist > 6072 && numSupplies > 100){
return;
}
@ -200,6 +204,8 @@ EconomyManager.prototype.reassignIdleWorkers = function(gameState) {
ent.setMetadata("subrole", "gatherer");
ent.setMetadata("gather-type", type);
return;
}else{
debug("No " + type + " found!");
}
}

View File

@ -162,7 +162,7 @@ String.prototype.rpad = function(padString, length) {
return str;
};
QueueManager.prototype.printQueues = function(){
QueueManager.prototype.printQueues = function(gameState){
debug("OUTQUEUES");
for (var i in this.queues){
var qStr = "";
@ -192,11 +192,12 @@ QueueManager.prototype.printQueues = function(){
}
}
debug("Accounts: " + uneval(this.account));
debug("Needed Resources:" + uneval(this.futureNeeds(gameState)));
};
QueueManager.prototype.update = function(gameState) {
Engine.ProfileStart("Queue Manager");
//this.printQueues();
//this.printQueues(gameState);
Engine.ProfileStart("Pick items from queues");
// See if there is a high priority item from last time.

View File

@ -40,7 +40,9 @@ TerrainAnalysis.prototype.findClosestPassablePoint = function(startPoint){
p[j] += direction;
if (p[0] + w*p[1] > 0 && p[0] + w*p[1] < this.length &&
this.map[p[0] + w*p[1]] != 0){
return p;
if (this.countConnected(p, 10) >= 10){
return p;
}
}
}
}
@ -50,6 +52,32 @@ TerrainAnalysis.prototype.findClosestPassablePoint = function(startPoint){
return undefined;
};
// Counts how many accessible tiles there are connected to the start Point. If there are >= maxCount then it stops.
// This is inefficient for large areas so maxCount should be kept small for efficiency.
TerrainAnalysis.prototype.countConnected = function(startPoint, maxCount, curCount, checked){
curCount = curCount || 0;
checked = checked || [];
var w = this.width;
var positions = [[0,1], [0,-1], [1,0], [-1,0]];
curCount += 1; // add 1 for the current point
checked.push(startPoint);
if (curCount >= maxCount){
return curCount;
}
for (var i in positions){
var p = [startPoint[0] + positions[i][0], startPoint[1] + positions[i][1]];
if (p[0] + w*p[1] > 0 && p[0] + w*p[1] < this.length &&
this.map[p[0] + w*p[1]] != 0 && !(p in checked)){
curCount += this.countConnected(p, maxCount, curCount, checked);
}
}
return curCount;
};
/*
* PathFinder inherits from TerrainAnalysis
*
@ -70,7 +98,7 @@ function PathFinder(gameState){
copyPrototype(PathFinder, TerrainAnalysis);
/*
* Returns a list of distinct paths to the destination. Curerntly paths are distinct if they are more than
* Returns a list of distinct paths to the destination. Currently paths are distinct if they are more than
* blockRadius apart at a distance of blockPlacementRadius from the destination. Where blockRadius and
* blockPlacementRadius are defined in walkGradient
*/