Skip to content

Commit

Permalink
Merge branch 'master' into SpiderMonkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves-G committed Mar 20, 2014
2 parents 6d29391 + 47ac312 commit 9605909
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions binaries/data/mods/public/simulation/ai/aegis/headquarters.js
Expand Up @@ -530,8 +530,6 @@ m.HQ.prototype.findBestEcoCCLocation = function(gameState, resource){
// Then checks for a good spot in the territory. If none, and town/city phase, checks outside
// The AI will currently not build a CC if it wouldn't connect with an existing CC.

var territory = m.createTerritoryMap(gameState);

var obstructions = m.createObstructionMap(gameState, 0);
obstructions.expandInfluences();

Expand Down Expand Up @@ -869,9 +867,20 @@ m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
|| capacity[type] < gameState.getOwnUnits().filter(API3.Filters.and(API3.Filters.byMetadata(PlayerID, "subrole", "gatherer"), API3.Filters.byMetadata(PlayerID, "gather-type", type))).length * 1.05)
{
// plan a new base.
if (gameState.countFoundationsByType(gameState.applyCiv("structures/{civ}_civil_centre"), true) === 0 && queues.civilCentre.length() === 0) {
if (this.outOf[type] && gameState.ai.playedTurn % 10 !== 0)
if (gameState.countFoundationsByType(gameState.applyCiv("structures/{civ}_civil_centre"), true) === 0 && queues.civilCentre.length() === 0) {
// In endgame when the whole map is claimed by players, we won't find a spot for a new CC.
// findBestEcoCCLocation needs to search the whole map for a good spot and is currently way too slow, so we wait quite long
// until we check again. The "PlayerID * 10" part is to distribute the load across multiple turns.
// TODO: this is a workaround. the current solution is bad for various reasons:
// 1. findBestEcoCCLocation could be much more efficient for the case when nearly all territory is occupied.
// 2. It doesn't make sense to check the whole map for a good spot for all resource types if we could see in the beginning
// that no free territory is available to build a CC.
// 3. Trying to build a new CC should not only be triggered by the need for more resources.
// Opportunity (having destroyed an enemy CC and some soldiers standing around) is also a good reason for a new CC.
// 4. Last but not least it causes the AI to react slowly when new territory becomes available.
if (this.outOf[type] && gameState.ai.playedTurn % 100 !== PlayerID * 10)
continue;

var pos = this.findBestEcoCCLocation(gameState, type);
if (!pos)
{
Expand Down
Expand Up @@ -321,7 +321,7 @@ m.Accessibility.prototype.init = function(rawState, terrainAnalyser){

//Engine.DumpImage("LandPassMap.png", this.landPassMap, this.width, this.height, 255);
//Engine.DumpImage("NavalPassMap.png", this.navalPassMap, this.width, this.height, 255);
}
};

m.Accessibility.prototype.getAccessValue = function(position, onWater) {
var gamePos = this.gamePosToMapPos(position);
Expand All @@ -334,8 +334,12 @@ m.Accessibility.prototype.getAccessValue = function(position, onWater) {
var indx = [ [-1,-1],[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1]]
for (var i in indx)
{
ret = this.landPassMap[gamePos[0]+indx[0] + this.width*(gamePos[1]+indx[0])]
if (ret !== undefined && ret !== 1)
var id0 = gamePos[0] + indx[i][0];
var id1 = gamePos[1] + indx[i][1];
if (id0 < 0 || id0 >= this.width || id1 < 0 || id1 >= this.width)
continue;
ret = this.landPassMap[id0 + this.width*id1];
if (ret !== 1)
return ret;
}
}
Expand Down Expand Up @@ -553,9 +557,8 @@ m.Accessibility.prototype.getRegionSizei = function(index, onWater) {
m.Accessibility.prototype.floodFill = function(startIndex, value, onWater)
{
this.s = startIndex;
if ((!onWater && this.landPassMap[this.s] !== 0) || (onWater && this.navalPassMap[this.s] !== 0) ) {
if ((!onWater && this.landPassMap[this.s] !== 0) || (onWater && this.navalPassMap[this.s] !== 0) )
return false; // already painted.
}

this.floodFor = "land";
if (this.map[this.s] === 0)
Expand Down

0 comments on commit 9605909

Please sign in to comment.