forked from 0ad/0ad
some fixes (i.e.building placement) and cleanings of petra
This was SVN commit r14871.
This commit is contained in:
parent
52af5b29a1
commit
bc428e1649
@ -139,14 +139,14 @@ m.PetraBot.prototype.OnUpdate = function(sharedScript)
|
||||
|
||||
// try going up phases.
|
||||
// TODO: softcode this more
|
||||
if (this.gameState.canResearch(townPhase,true) && this.gameState.getPopulation() >= this.Config.Economy.villagePopCap - 10
|
||||
if (this.gameState.canResearch(townPhase,true) && this.gameState.getPopulation() >= this.Config.Economy.popForTown - 10
|
||||
&& this.gameState.findResearchers(townPhase,true).length != 0 && this.queues.majorTech.length() === 0)
|
||||
{
|
||||
var plan = new m.ResearchPlan(this.gameState, townPhase, true);
|
||||
plan.lastIsGo = false;
|
||||
plan.onStart = function (gameState) { gameState.ai.HQ.econState = "growth"; gameState.ai.HQ.OnTownPhase(gameState) };
|
||||
plan.isGo = function (gameState) {
|
||||
var ret = gameState.getPopulation() >= gameState.Config.Economy.villagePopCap
|
||||
var ret = gameState.getPopulation() >= gameState.Config.Economy.popForTown;
|
||||
if (ret && !this.lastIsGo)
|
||||
this.onGo(gameState);
|
||||
else if (!ret && this.lastIsGo)
|
||||
@ -243,7 +243,7 @@ m.PetraBot.prototype.initPersonality = function()
|
||||
if (this.Config.personality.aggressive > 0.7)
|
||||
{
|
||||
this.Config.Military.popForBarracks1 = 0;
|
||||
this.Config.Economy.villagePopCap = 75;
|
||||
this.Config.Economy.popForTown = 70;
|
||||
this.Config.Economy.cityPhase = 900;
|
||||
this.Config.Economy.popForMarket = 80;
|
||||
this.Config.Economy.targetNumBuilders = 2;
|
||||
|
@ -196,15 +196,20 @@ m.AttackManager.prototype.update = function(gameState, queues, events)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.upcomingAttacks["Raid"].length === 999)
|
||||
{
|
||||
var enemyCC = gameState.getEnemyStructures().filter(API3.Filters.and(API3.Filters.byClass("CivCentre"), API3.Filters.isFoundation()));
|
||||
if (enemyCC.length > 0)
|
||||
if (this.upcomingAttacks["Raid"].length === 0 && gameState.ai.HQ.defenseManager.targetList.length)
|
||||
{
|
||||
var target = undefined;
|
||||
for each (var targetId in gameState.ai.HQ.defenseManager.targetList)
|
||||
{
|
||||
// prepare some raid on this CC
|
||||
var enemy = enemyCC.toEntityArray()[0].owner();
|
||||
var attackPlan = new m.AttackPlan(gameState, this.Config, this.totalNumber, enemy, "Raid");
|
||||
if (this.Config.debug)
|
||||
target = gameState.getEntityById(targetId);
|
||||
if (target)
|
||||
break;
|
||||
}
|
||||
if (target)
|
||||
{
|
||||
// prepare a raid against this target
|
||||
var attackPlan = new m.AttackPlan(gameState, this.Config, this.totalNumber, target.owner(), "Raid");
|
||||
if (this.Config.debug > 0)
|
||||
warn("Headquarters: Raiding plan " + this.totalNumber);
|
||||
this.raidNumber++;
|
||||
this.totalNumber++;
|
||||
|
@ -89,8 +89,8 @@ m.AttackPlan = function(gameState, Config, uniqueID, targetEnemy, type , targetF
|
||||
}
|
||||
else if (type === "Raid")
|
||||
{
|
||||
priority = 300;
|
||||
this.unitStat["Cavalry"] = { "priority": 1, "minSize": 3, "targetSize": 6, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], "interests": [ ["strength",1], ["cost",1] ] };
|
||||
priority = 150;
|
||||
this.unitStat["Cavalry"] = { "priority": 1, "minSize": 3, "targetSize": 4, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], "interests": [ ["strength",1], ["cost",1] ] };
|
||||
}
|
||||
else if (type === "superSized")
|
||||
{
|
||||
@ -323,26 +323,35 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
|
||||
var self = this;
|
||||
|
||||
if (this.path == undefined || this.target == undefined || this.path === "toBeContinued") {
|
||||
if (this.path == undefined || this.target == undefined || this.path === "toBeContinued")
|
||||
{
|
||||
// find our target
|
||||
if (this.target == undefined)
|
||||
{
|
||||
var targets = undefined;
|
||||
if (this.type === "Rush")
|
||||
var targets = this.rushTargetFinder(gameState);
|
||||
else if (this.type === "Raid")
|
||||
var targets = this.raidTargetFinder(gameState);
|
||||
if (!targets || targets.length === 0)
|
||||
if (this.type === "Raid")
|
||||
{
|
||||
if (this.type !== "Raid")
|
||||
var targets = this.targetFinder(gameState);
|
||||
else
|
||||
var targetList = gameState.ai.HQ.defenseManager.targetList;
|
||||
for each (var targetId in targetList)
|
||||
{
|
||||
this.target = gameState.getEntityById(targetId);
|
||||
if (this.target && this.target.position())
|
||||
break;
|
||||
}
|
||||
if (!this.target || !this.target.position())
|
||||
return 0;
|
||||
}
|
||||
if (targets.length === 0)
|
||||
targets = this.defaultTargetFinder(gameState);
|
||||
else
|
||||
{
|
||||
var targets = undefined;
|
||||
if (this.type === "Rush")
|
||||
var targets = this.rushTargetFinder(gameState);
|
||||
if (!targets || targets.length === 0)
|
||||
var targets = this.targetFinder(gameState);
|
||||
if (targets.length === 0)
|
||||
targets = this.defaultTargetFinder(gameState);
|
||||
if (targets.length === 0)
|
||||
return 0;
|
||||
|
||||
if (targets.length !== 0) {
|
||||
// picking a target
|
||||
var maxDist = -1;
|
||||
var index = 0;
|
||||
@ -357,8 +366,8 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
}
|
||||
}
|
||||
this.target = targets._entities[index];
|
||||
this.targetPos = this.target.position();
|
||||
}
|
||||
this.targetPos = this.target.position();
|
||||
}
|
||||
// when we have a target, we path to it.
|
||||
// I'd like a good high width sampling first.
|
||||
@ -398,8 +407,7 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
{
|
||||
// my pathfinder returns arrays in arrays in arrays.
|
||||
var waypointPos = this.path[i][0];
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
if (territory.getOwner(waypointPos) !== PlayerID || this.path[i][1] === true)
|
||||
if (gameState.ai.HQ.territoryMap.getOwner(waypointPos) !== PlayerID || this.path[i][1] === true)
|
||||
{
|
||||
// if we're suddenly out of our territory or this is the point where we change transportation method.
|
||||
if (i !== 0)
|
||||
@ -424,8 +432,7 @@ m.AttackPlan.prototype.updatePreparation = function(gameState, events)
|
||||
{
|
||||
// my pathfinder returns arrays in arrays in arrays.
|
||||
var waypointPos = this.path[i][0];
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
if (territory.getOwner(waypointPos) !== PlayerID || this.path[i][1] === true)
|
||||
if (gameState.ai.HQ.territoryMap.getOwner(waypointPos) !== PlayerID || this.path[i][1] === true)
|
||||
{
|
||||
// if we're suddenly out of our territory or this is the point where we change transportation method.
|
||||
if (i !== 0)
|
||||
@ -667,12 +674,11 @@ m.AttackPlan.prototype.rushTargetFinder = function(gameState)
|
||||
return targets;
|
||||
|
||||
this.position = this.unitCollection.getCentrePosition();
|
||||
if (!this.position)
|
||||
{
|
||||
warn(" no position for rushTargetFinder " + this.unitCollection.length);
|
||||
var ourCC = gameState.getEnemyStructures().filter(API3.Filters.byClass("CivCentre")).toEntityArray();
|
||||
this.position = ourCC[0].position();
|
||||
}
|
||||
if (!this.position)
|
||||
{
|
||||
var ourCC = gameState.getOwnStructures().filter(API3.Filters.byClass("CivCentre")).toEntityArray();
|
||||
this.position = ourCC[0].position();
|
||||
}
|
||||
|
||||
var minDist = Math.min();
|
||||
var target = undefined;
|
||||
@ -707,10 +713,10 @@ m.AttackPlan.prototype.rushTargetFinder = function(gameState)
|
||||
return targets;
|
||||
};
|
||||
|
||||
// Raid target finder aims at isolated non-defended units or foundations
|
||||
// Raid target finder aims at destructing foundations from which our defenseManager has attacked the builders
|
||||
m.AttackPlan.prototype.raidTargetFinder = function(gameState)
|
||||
{
|
||||
return gameState.getEnemyStructures().filter(API3.Filters.and(API3.Filters.byClass("CivCentre"), API3.Filters.isFoundation()));
|
||||
return gameState.ai.HQ.defenseManager.targetList;
|
||||
};
|
||||
|
||||
// Raid target finder aims at isolated non-defended units or foundations
|
||||
@ -799,19 +805,18 @@ m.AttackPlan.prototype.StartAttack = function(gameState)
|
||||
if (this.Config.debug)
|
||||
warn("start attack " + this.name + " with type " + this.type);
|
||||
|
||||
if (this.type === "Raid")
|
||||
if (this.type === "Raid" && !this.target) // in case our target was already destroyed
|
||||
{
|
||||
var targets = this.raidTargetFinder(gameState);
|
||||
if (targets.length !== 0)
|
||||
var targetList = gameState.ai.HQ.defenseManager.targetList;
|
||||
for each (var targetId in targetList)
|
||||
{
|
||||
for (var i in targets._entities)
|
||||
this.target = targets._entities[i];
|
||||
this.target = gameState.getEntityById(targetId);
|
||||
this.targetPos = this.target.position();
|
||||
if (this.target && this.targetPos)
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (!this.target || !this.targetPos)
|
||||
return false;
|
||||
if (this.Config.debug > 0)
|
||||
warn("startAttack du Raid avec target foundation " + this.target.foundationProgress() + " and path " + this.path);
|
||||
}
|
||||
|
||||
// check we have a target and a path.
|
||||
@ -880,9 +885,8 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
if (attacker && ourUnit && attacker.hasClass("Structure"))
|
||||
ourUnit.flee(attacker);
|
||||
}
|
||||
var territoryMap = m.createTerritoryMap(gameState);
|
||||
// Are we arrived at destination ?
|
||||
if ((territoryMap.getOwner(this.position) === this.targetPlayer && attackedNB > 1) || attackedNB > 4)
|
||||
if ((gameState.ai.HQ.territoryMap.getOwner(this.position) === this.targetPlayer && attackedNB > 1) || attackedNB > 4)
|
||||
this.state = "arrived";
|
||||
}
|
||||
|
||||
@ -1047,7 +1051,6 @@ m.AttackPlan.prototype.update = function(gameState, events)
|
||||
else
|
||||
{
|
||||
// some stuffs for locality and speed
|
||||
var territoryMap = m.createTerritoryMap(gameState);
|
||||
var timeElapsed = gameState.getTimeElapsed();
|
||||
|
||||
// Let's check a few units each time we update. Currently 10
|
||||
|
@ -275,8 +275,7 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
||||
var obstructions = m.createObstructionMap(gameState, this.accessIndex, storeHousePlate);
|
||||
obstructions.expandInfluences();
|
||||
|
||||
// copy the resource map as initialization.
|
||||
var locateMap = new API3.Map(gameState.sharedScript, gameState.sharedScript.resourceMaps[resource].map, true);
|
||||
var locateMap = new API3.Map(gameState.sharedScript);
|
||||
|
||||
var DPFoundations = gameState.getOwnFoundations().filter(API3.Filters.byType(gameState.applyCiv("foundation|structures/{civ}_storehouse")));
|
||||
|
||||
@ -284,20 +283,25 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
||||
|
||||
// TODO: might be better to check dropsites someplace else.
|
||||
// loop over this in this.terrytoryindices. It's usually a little too much, but it's always enough.
|
||||
var width = locateMap.width;
|
||||
for (var p = 0; p < this.territoryIndices.length; ++p)
|
||||
{
|
||||
var j = this.territoryIndices[p];
|
||||
locateMap.map[j] *= 2;
|
||||
|
||||
// only add where the map is currently not null, ie in our territory and some "Resource" would be close.
|
||||
// This makes the placement go from "OK" to "human-like".
|
||||
// we add 3 times the needed resource and once the other two (not food)
|
||||
var total = 0;
|
||||
for (var i in gameState.sharedScript.resourceMaps)
|
||||
if (locateMap.map[j] !== 0 && i !== "food")
|
||||
locateMap.map[j] += gameState.sharedScript.resourceMaps[i].map[j];
|
||||
{
|
||||
if (i === "food")
|
||||
continue;
|
||||
total += gameState.sharedScript.resourceMaps[i].map[j];
|
||||
if (i === resource)
|
||||
total += 2*gameState.sharedScript.resourceMaps[i].map[j];
|
||||
}
|
||||
|
||||
locateMap.map[j] *= 0.7; // Just a normalisation factor as the max is 255
|
||||
total = 0.7*total; // Just a normalisation factor as the locateMap is limited to 255
|
||||
|
||||
var pos = [j%locateMap.width+0.5, Math.floor(j/locateMap.width)+0.5];
|
||||
var pos = [j%width+0.5, Math.floor(j/width)+0.5];
|
||||
pos = [gameState.cellSize*pos[0], gameState.cellSize*pos[1]];
|
||||
for (var i in this.dropsites)
|
||||
{
|
||||
@ -309,13 +313,13 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
||||
var dist = API3.SquareVectorDistance(dpPos, pos);
|
||||
if (dist < 3600)
|
||||
{
|
||||
locateMap.map[j] = 0;
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
else if (dist < 6400)
|
||||
locateMap.map[j] /= 2;
|
||||
total /= 2;
|
||||
}
|
||||
if (locateMap.map[j] == 0)
|
||||
if (total == 0)
|
||||
continue;
|
||||
|
||||
for (var i in DPFoundations._entities)
|
||||
@ -326,13 +330,13 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
||||
var dist = API3.SquareVectorDistance(dpPos, pos);
|
||||
if (dist < 3600)
|
||||
{
|
||||
locateMap.map[j] = 0;
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
else if (dist < 6400)
|
||||
locateMap.map[j] /= 2;
|
||||
total /= 2;
|
||||
}
|
||||
if (locateMap.map[j] == 0)
|
||||
if (total == 0)
|
||||
continue;
|
||||
|
||||
for each (var cc in ccEnts)
|
||||
@ -343,34 +347,27 @@ m.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource)
|
||||
var dist = API3.SquareVectorDistance(ccPos, pos);
|
||||
if (dist < 3600)
|
||||
{
|
||||
locateMap.map[j] = 0;
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
else if (dist < 6400)
|
||||
locateMap.map[j] /= 2;
|
||||
total /= 2;
|
||||
}
|
||||
|
||||
locateMap.map[j] = total;
|
||||
}
|
||||
|
||||
var best = locateMap.findBestTile(2, obstructions); // try to find a spot to place a DP.
|
||||
var best = locateMap.findBestTile(2, obstructions);
|
||||
var bestIdx = best[0];
|
||||
|
||||
if (this.Config.debug == 2)
|
||||
warn("for dropsite best is " + best[1] + " at " + gameState.getTimeElapsed());
|
||||
|
||||
// tell the dropsite builder we haven't found anything satisfactory.
|
||||
// var cutbest = 60;
|
||||
// // being less demanding for first dropsite
|
||||
// if (gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_storehouse")) == 0)
|
||||
// var cutbest = 50;
|
||||
|
||||
// if (best[1] < cutbest)
|
||||
// return false;
|
||||
warn(" for dropsite best is " + best[1]);
|
||||
|
||||
var quality = best[1];
|
||||
if (quality <= 0)
|
||||
return {"quality": quality, "pos": [0, 0]};
|
||||
var x = ((bestIdx % locateMap.width) + 0.5) * gameState.cellSize;
|
||||
var z = (Math.floor(bestIdx / locateMap.width) + 0.5) * gameState.cellSize;
|
||||
var x = ((bestIdx % width) + 0.5) * gameState.cellSize;
|
||||
var z = (Math.floor(bestIdx / width) + 0.5) * gameState.cellSize;
|
||||
return {"quality": quality, "pos": [x, z]};
|
||||
};
|
||||
|
||||
@ -770,8 +767,8 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
|
||||
} else if (noRepair && !target.hasClass("CivCentre"))
|
||||
continue;
|
||||
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
if (territory.getOwner(target.position()) !== PlayerID || territory.getOwner([target.position()[0] + 5, target.position()[1]]) !== PlayerID)
|
||||
if (gameState.ai.HQ.territoryMap.getOwner(target.position()) !== PlayerID ||
|
||||
gameState.ai.HQ.territoryMap.getOwner([target.position()[0] + 5, target.position()[1]]) !== PlayerID)
|
||||
continue;
|
||||
|
||||
var assigned = gameState.getOwnEntitiesByMetadata("target-foundation", target.id()).length;
|
||||
@ -804,7 +801,7 @@ m.BaseManager.prototype.update = function(gameState, queues, events)
|
||||
|
||||
if (this.constructing && this.anchor)
|
||||
{
|
||||
var owner = m.createTerritoryMap(gameState).getOwner(this.anchor.position());
|
||||
var owner = gameState.ai.HQ.territoryMap.getOwner(this.anchor.position());
|
||||
if(owner !== 0 && !gameState.isPlayerAlly(owner))
|
||||
{
|
||||
// we're in enemy territory. If we're too close from the enemy, destroy us.
|
||||
|
@ -11,10 +11,10 @@ m.Config = function() {
|
||||
"fortressLapseTime" : 420, // Time to wait between building 2 fortresses
|
||||
"popForBarracks1" : 25,
|
||||
"popForBarracks2" : 95,
|
||||
"timeForBlacksmith" : 900,
|
||||
"popForBlacksmith" : 65
|
||||
};
|
||||
this.Economy = {
|
||||
"villagePopCap" : 40, // How many units we want before aging to town.
|
||||
"popForTown" : 40, // How many units we want before aging to town.
|
||||
"cityPhase" : 840, // time to start trying to reach city phase
|
||||
"popForMarket" : 50,
|
||||
"dockStartTime" : 240, // Time to wait before building the dock
|
||||
|
@ -127,9 +127,8 @@ m.DefenseArmy.prototype.getState = function (gameState)
|
||||
// check if we should remain at state 2 or drift away
|
||||
m.DefenseArmy.prototype.checkDangerosity = function (gameState)
|
||||
{
|
||||
this.territoryMap = m.createTerritoryMap(gameState);
|
||||
// right now we'll check if our position is "enemy" or not.
|
||||
if (this.territoryMap.getOwner(this.ownPosition) !== PlayerID)
|
||||
if (gameState.ai.HQ.territoryMap.getOwner(this.ownPosition) !== PlayerID)
|
||||
this.state = 1;
|
||||
else if (this.state === 1)
|
||||
this.state = 2;
|
||||
|
@ -15,7 +15,7 @@ m.DefenseManager.prototype.init = function(gameState)
|
||||
|
||||
m.DefenseManager.prototype.update = function(gameState, events)
|
||||
{
|
||||
this.territoryMap = m.createTerritoryMap(gameState);
|
||||
this.territoryMap = gameState.ai.HQ.territoryMap;
|
||||
|
||||
this.checkEnemyArmies(gameState, events);
|
||||
this.checkEnemyUnits(gameState);
|
||||
|
@ -55,6 +55,7 @@ m.HQ = function(Config)
|
||||
// More initialisation for stuff that needs the gameState
|
||||
m.HQ.prototype.init = function(gameState, queues)
|
||||
{
|
||||
this.territoryMap = m.createTerritoryMap(gameState);
|
||||
// initialize base map. Each pixel is a base ID, or 0 if not or not accessible
|
||||
this.basesMap = new API3.Map(gameState.sharedScript);
|
||||
// area of 10 cells on the border of the map : 0=inside map, 1=border map, 2=outside map
|
||||
@ -282,24 +283,30 @@ m.HQ.prototype.trainMoreWorkers = function(gameState, queues)
|
||||
// If we have too few, train more
|
||||
// should plan enough to always have females…
|
||||
// TODO: 15 here should be changed to something more sensible, such as nb of producing buildings.
|
||||
if (numTotal > this.targetNumWorkers || numQueued > 50 || (numQueuedF > 20 && numQueuedS > 20) || numInTraining > 15)
|
||||
return;
|
||||
|
||||
if (numTotal >= this.Config.Economy.villagePopCap && gameState.currentPhase() === 1 && !gameState.isResearching(gameState.townPhase()))
|
||||
return;
|
||||
if (!this.boostedSoldiers)
|
||||
{
|
||||
if (numTotal > this.targetNumWorkers || (numTotal >= this.Config.Economy.popForTown
|
||||
&& gameState.currentPhase() === 1 && !gameState.isResearching(gameState.townPhase())))
|
||||
return;
|
||||
if (numQueued > 50 || (numQueuedF > 20 && numQueuedS > 20) || numInTraining > 15)
|
||||
return;
|
||||
}
|
||||
else if (numQueuedS > 20)
|
||||
return;
|
||||
|
||||
// default template and size
|
||||
var template = gameState.applyCiv("units/{civ}_support_female_citizen");
|
||||
var size = Math.min(5, Math.ceil(numTotal / 10));
|
||||
|
||||
// Choose whether we want soldiers instead.
|
||||
// TODO: we might want to adjust our female ratio.
|
||||
if ((numFemales+numQueuedF)/numTotal > this.femaleRatio && numQueuedS < 20) {
|
||||
if ((numFemales+numQueuedF)/numTotal > this.femaleRatio || this.boostedSoldiers)
|
||||
{
|
||||
if (numTotal < 35)
|
||||
template = this.findBestTrainableUnit(gameState, ["CitizenSoldier", "Infantry"], [ ["cost",1], ["speed",0.5], ["costsResource", 0.5, "stone"], ["costsResource", 0.5, "metal"]]);
|
||||
else
|
||||
template = this.findBestTrainableUnit(gameState, ["CitizenSoldier", "Infantry"], [ ["strength",1] ]);
|
||||
|
||||
if (!template && this.boostedSoldiers)
|
||||
return;
|
||||
if (!template)
|
||||
template = gameState.applyCiv("units/{civ}_support_female_citizen");
|
||||
}
|
||||
@ -528,8 +535,6 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, resource)
|
||||
// obstruction map
|
||||
var obstructions = m.createObstructionMap(gameState, 0);
|
||||
obstructions.expandInfluences();
|
||||
// territory map
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
|
||||
var ccEnts = gameState.getEntities().filter(API3.Filters.byClass("CivCentre")).toEntityArray();
|
||||
var dpEnts = gameState.getOwnDropsites().toEntityArray();
|
||||
@ -540,7 +545,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, resource)
|
||||
// This ensures territorial continuity.
|
||||
|
||||
var norm = 0.5; // TODO adjust it, knowing that we will sum 5 maps
|
||||
if (territory.getOwnerIndex(j) !== 0 || this.borderMap.map[j] === 2)
|
||||
if (this.territoryMap.getOwnerIndex(j) !== 0 || this.borderMap.map[j] === 2)
|
||||
{
|
||||
norm = 0;
|
||||
continue;
|
||||
@ -663,15 +668,13 @@ m.HQ.prototype.findStrategicCCLocation = function(gameState)
|
||||
// obstruction map
|
||||
var obstructions = m.createObstructionMap(gameState, 0);
|
||||
obstructions.expandInfluences();
|
||||
// territory map
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
|
||||
var map = {};
|
||||
var width = territory.width;
|
||||
var width = this.territoryMap.width;
|
||||
|
||||
for (var j = 0; j < territory.length; ++j)
|
||||
for (var j = 0; j < this.territoryMap.length; ++j)
|
||||
{
|
||||
if (territory.getOwnerIndex(j) !== 0 || this.borderMap.map[j] === 2)
|
||||
if (this.territoryMap.getOwnerIndex(j) !== 0 || this.borderMap.map[j] === 2)
|
||||
continue;
|
||||
|
||||
var ix = j%width;
|
||||
@ -759,12 +762,10 @@ m.HQ.prototype.findDefensiveLocation = function(gameState, template)
|
||||
// obstruction map
|
||||
var obstructions = m.createObstructionMap(gameState, 0);
|
||||
obstructions.expandInfluences();
|
||||
// territory map
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
|
||||
var map = {};
|
||||
var width = territory.width;
|
||||
for (var j = 0; j < territory.length; ++j)
|
||||
var width = this.territoryMap.width;
|
||||
for (var j = 0; j < this.territoryMap.length; ++j)
|
||||
{
|
||||
// do not try if well inside or outside territory
|
||||
if (this.frontierMap.map[j] === 0)
|
||||
@ -861,7 +862,7 @@ m.HQ.prototype.buildTemple = function(gameState, queues)
|
||||
|
||||
m.HQ.prototype.buildMarket = function(gameState, queues)
|
||||
{
|
||||
if (gameState.getPopulation() < this.Config.Economy.popForMarket || gameState.currentPhase() < 2 ||
|
||||
if (gameState.getPopulation() < this.Config.Economy.popForMarket ||
|
||||
queues.economicBuilding.countQueuedUnitsWithClass("BarterMarket") !== 0 ||
|
||||
gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_market"), true) !== 0)
|
||||
return;
|
||||
@ -1112,7 +1113,6 @@ m.HQ.prototype.buildTradeRoute = function(gameState, queues)
|
||||
// kinda ugly, lots of special cases to both build enough houses but not tooo many…
|
||||
m.HQ.prototype.buildMoreHouses = function(gameState,queues)
|
||||
{
|
||||
|
||||
if (gameState.getPopulationMax() < gameState.getPopulationLimit())
|
||||
{
|
||||
var numPlanned = queues.house.length();
|
||||
@ -1234,7 +1234,9 @@ m.HQ.prototype.buildDefenses = function(gameState, queues)
|
||||
}
|
||||
}
|
||||
|
||||
if (gameState.currentPhase() < 2 || queues.defenseBuilding.length() !== 0 || !this.canBuild(gameState, "structures/{civ}_defense_tower"))
|
||||
if (gameState.currentPhase() < 2
|
||||
|| queues.defenseBuilding.length() !== 0
|
||||
|| !this.canBuild(gameState, "structures/{civ}_defense_tower"))
|
||||
return;
|
||||
|
||||
var numTowers = gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_defense_tower"), true);
|
||||
@ -1248,7 +1250,8 @@ m.HQ.prototype.buildDefenses = function(gameState, queues)
|
||||
|
||||
m.HQ.prototype.buildBlacksmith = function(gameState, queues)
|
||||
{
|
||||
if (gameState.getTimeElapsed() < this.Config.Military.timeForBlacksmith*1000 || queues.militaryBuilding.length() !== 0
|
||||
if (gameState.getPopulation() < this.Config.Military.popForBlacksmith
|
||||
|| queues.militaryBuilding.length() !== 0
|
||||
|| gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_blacksmith"), true) > 0)
|
||||
return;
|
||||
|
||||
@ -1408,14 +1411,13 @@ m.HQ.prototype.updateTerritories = function(gameState)
|
||||
return;
|
||||
this.lastTerritoryUpdate = gameState.ai.playedTurn;
|
||||
|
||||
var territory = m.createTerritoryMap(gameState);
|
||||
var width = territory.width;
|
||||
var width = this.territoryMap.width;
|
||||
var expansion = false;
|
||||
for (var j = 0; j < territory.length; ++j)
|
||||
for (var j = 0; j < this.territoryMap.length; ++j)
|
||||
{
|
||||
if (this.borderMap.map[j] === 2)
|
||||
continue;
|
||||
if (territory.getOwnerIndex(j) !== PlayerID)
|
||||
if (this.territoryMap.getOwnerIndex(j) !== PlayerID)
|
||||
{
|
||||
if (this.basesMap.map[j] === 0)
|
||||
continue;
|
||||
@ -1510,6 +1512,8 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
||||
{
|
||||
Engine.ProfileStart("Headquarters update");
|
||||
|
||||
this.territoryMap = m.createTerritoryMap(gameState);
|
||||
|
||||
if (this.Config.debug > 0)
|
||||
{
|
||||
gameState.getOwnUnits().forEach (function (ent) {
|
||||
@ -1559,26 +1563,33 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
||||
|
||||
if (gameState.ai.playedTurn % 2 === 0)
|
||||
this.buildMoreHouses(gameState,queues);
|
||||
else
|
||||
this.buildFarmstead(gameState, queues);
|
||||
|
||||
if (this.waterMap)
|
||||
this.buildDock(gameState, queues);
|
||||
|
||||
if (queues.minorTech.length() === 0 && gameState.ai.playedTurn % 5 === 1)
|
||||
this.tryResearchTechs(gameState,queues);
|
||||
|
||||
this.buildFarmstead(gameState, queues);
|
||||
this.buildMarket(gameState, queues);
|
||||
this.buildTemple(gameState, queues);
|
||||
this.buildDock(gameState, queues); // not if not a water map.
|
||||
|
||||
if (this.Config.difficulty > 1)
|
||||
if (gameState.currentPhase() > 1)
|
||||
{
|
||||
this.tryBartering(gameState);
|
||||
if (!this.tradeManager.hasTradeRoute() && gameState.ai.playedTurn % 5 === 2)
|
||||
this.buildTradeRoute(gameState, queues);
|
||||
this.tradeManager.update(gameState, queues);
|
||||
this.buildMarket(gameState, queues);
|
||||
this.buildBlacksmith(gameState, queues);
|
||||
this.buildTemple(gameState, queues);
|
||||
|
||||
if (this.Config.difficulty > 1)
|
||||
{
|
||||
this.tryBartering(gameState);
|
||||
if (!this.tradeManager.hasTradeRoute() && gameState.ai.playedTurn % 5 === 2)
|
||||
this.buildTradeRoute(gameState, queues);
|
||||
this.tradeManager.update(gameState, queues);
|
||||
}
|
||||
}
|
||||
|
||||
this.constructTrainingBuildings(gameState, queues);
|
||||
this.defenseManager.update(gameState, events);
|
||||
|
||||
this.buildBlacksmith(gameState, queues);
|
||||
this.constructTrainingBuildings(gameState, queues);
|
||||
|
||||
if (this.Config.difficulty > 0)
|
||||
this.buildDefenses(gameState, queues);
|
||||
@ -1592,8 +1603,6 @@ m.HQ.prototype.update = function(gameState, queues, events)
|
||||
|
||||
this.navalManager.update(gameState, queues, events);
|
||||
|
||||
this.defenseManager.update(gameState, events, this);
|
||||
|
||||
if (this.Config.difficulty > 0)
|
||||
this.attackManager.update(gameState, queues, events);
|
||||
|
||||
|
@ -19,7 +19,6 @@ m.Queue.prototype.empty = function()
|
||||
|
||||
m.Queue.prototype.addItem = function(plan)
|
||||
{
|
||||
if (!plan) warn(" essaie d'ajout d un plan vide");
|
||||
if (!plan)
|
||||
return;
|
||||
for (var i in this.queue)
|
||||
|
@ -174,7 +174,7 @@ m.ConstructionPlan.prototype.findGoodPosition = function(gameState)
|
||||
else
|
||||
friendlyTiles.addInfluence(x, z, 15, -40); // and further away from other stuffs
|
||||
}
|
||||
else if (template.hasClass("Farmstead") && !ent.hasClass("Field"))
|
||||
else if (template.hasClass("Farmstead") && !ent.hasClass("Field"))
|
||||
friendlyTiles.addInfluence(x, z, 25, -25); // move farmsteads away to make room.
|
||||
else if (template.hasClass("GarrisonFortress") && ent.genericName() == "House")
|
||||
friendlyTiles.addInfluence(x, z, 30, -50);
|
||||
@ -219,7 +219,7 @@ m.ConstructionPlan.prototype.findGoodPosition = function(gameState)
|
||||
radius = Math.floor(template.obstructionRadius() / cellSize) + 3;
|
||||
else if (template.buildCategory() === "Dock")
|
||||
radius = 1;
|
||||
else if (template.resourceDropsiteTypes() === undefined)
|
||||
else if (template.resourceDropsiteTypes() === undefined && !template.hasClass("House") && !template.hasClass("Field"))
|
||||
radius = Math.ceil(template.obstructionRadius() / cellSize) + 1;
|
||||
else
|
||||
radius = Math.ceil(template.obstructionRadius() / cellSize);
|
||||
|
@ -36,9 +36,6 @@ m.ResearchPlan.prototype.start = function(gameState)
|
||||
//m.debug ("Starting the research plan for " + this.type);
|
||||
var trainers = gameState.findResearchers(this.type).toEntityArray();
|
||||
|
||||
//for (var i in trainers)
|
||||
// warn (this.type + " - " +trainers[i].genericName());
|
||||
|
||||
// Prefer training buildings with short queues
|
||||
// (TODO: this should also account for units added to the queue by
|
||||
// plans that have already been executed this turn)
|
||||
|
@ -57,7 +57,7 @@ m.TrainingPlan.prototype.start = function(gameState)
|
||||
trainers[0].train(this.type, this.number, this.metadata);
|
||||
}
|
||||
else
|
||||
warn("pas de trainers for this queue " + this.type);
|
||||
warn(" no trainers for this queue " + this.type);
|
||||
this.onStart(gameState);
|
||||
};
|
||||
|
||||
|
@ -155,7 +155,7 @@ m.Worker.prototype.startGathering = function(gameState, baseManager)
|
||||
&& nbGatherers > 0 && supply[i].ent.resourceSupplyAmount()/(1+nbGatherers) < 40)
|
||||
continue;
|
||||
// not in ennemy territory
|
||||
var territoryOwner = m.createTerritoryMap(gameState).getOwner(supply[i].ent.position());
|
||||
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(supply[i].ent.position());
|
||||
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally
|
||||
continue;
|
||||
m.AddTCGatherer(gameState, supply[i].id);
|
||||
@ -239,6 +239,11 @@ m.Worker.prototype.startGathering = function(gameState, baseManager)
|
||||
}
|
||||
}
|
||||
|
||||
if (gameState.ai.HQ.Config.debug > 0)
|
||||
{
|
||||
warn(" >>>>> worker with gather-type " + resource + " with nothing to gather ");
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -346,7 +351,7 @@ m.Worker.prototype.startHunting = function(gameState, baseManager)
|
||||
}
|
||||
|
||||
// Avoid ennemy territory
|
||||
var territoryOwner = m.createTerritoryMap(gameState).getOwner(supply.position());
|
||||
var territoryOwner = gameState.ai.HQ.territoryMap.getOwner(supply.position());
|
||||
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally
|
||||
return;
|
||||
|
||||
@ -404,7 +409,6 @@ m.Worker.prototype.getGatherRate = function(gameState) {
|
||||
if (type.generic == "treasure")
|
||||
return 1000;
|
||||
var tstring = type.generic + "." + type.specific;
|
||||
//m.debug (+rates[tstring] + " for " + tstring + " for " + this.ent._templateName);
|
||||
if (rates[tstring])
|
||||
return rates[tstring];
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user