Forgot to fix a few things before committing.

This was SVN commit r12268.
This commit is contained in:
wraitii
2012-08-03 16:12:45 +00:00
parent 45ee419171
commit 2ee61750b4
4 changed files with 19 additions and 12 deletions
@@ -436,10 +436,11 @@ CityAttack.prototype.update = function(gameState, militaryManager, events){
if (IDs.indexOf(e.msg.target) !== -1) {
var attacker = gameState.getEntityById(e.msg.attacker);
if (attacker && attacker.position() && attacker.hasClass("Unit") && attacker.owner() != 0) {
toProcess[attacker.id()] = attacker;
var armyID = militaryManager.enemyWatchers[attacker.owner()].getArmyFromMember(attacker.id());
armyToProcess[armyID[0]] = armyID[1];
if (militaryManager.enemyWatchers[attacker.owner()]) {
toProcess[attacker.id()] = attacker;
var armyID = militaryManager.enemyWatchers[attacker.owner()].getArmyFromMember(attacker.id());
armyToProcess[armyID[0]] = armyID[1];
}
}
}
}
@@ -236,6 +236,8 @@ Defence.prototype.defendFromEnemyArmies = function(gameState, events, militaryMa
newSoldiers.forEach(function(ent) {
if (ent.getMetadata("subrole","attacking"))
return;
if (nbOfAttackers <= 0)
return;
// okaaay we attack
for (o in self.listOfEnemies) {
if (self.attackerCache[o].length === 0) {
@@ -255,6 +257,8 @@ Defence.prototype.defendFromEnemyArmies = function(gameState, events, militaryMa
if (nbOfAttackers > 0) {
var newSoldiers = gameState.getOwnEntitiesByRole("worker");
newSoldiers.forEach(function(ent) {
if (nbOfAttackers <= 0)
return;
// If we're not female, we attack
if (ent.hasClass("CitizenSoldier"))
for (o in self.listOfEnemies) {
@@ -263,6 +267,7 @@ Defence.prototype.defendFromEnemyArmies = function(gameState, events, militaryMa
ent.setMetadata("role","defence");
ent.setMetadata("subrole","defending");
ent.attack(+o);
nbOfAttackers--;
break;
}
}
@@ -235,10 +235,6 @@ EconomyManager.prototype.assignToFoundations = function(gameState) {
};
EconomyManager.prototype.buildMoreFields = function(gameState, queues) {
// give time for treasures to be gathered
if (gameState.getTimeElapsed() < 30 * 1000)
return;
var numFood = 0;
gameState.updatingCollection("active-dropsite-food", Filters.byMetadata("active-dropsite-food", true),
@@ -543,9 +539,11 @@ EconomyManager.prototype.update = function(gameState, queues, events) {
}
Engine.ProfileStart("Update Resource Maps and Concentrations");
this.updateResourceMaps(gameState, events);
this.updateResourceConcentrations(gameState);
this.updateNearbyResources(gameState);
if (gameState.ai.playedTurn % 2 === 0) {
this.updateResourceMaps(gameState, events);
this.updateResourceConcentrations(gameState);
this.updateNearbyResources(gameState);
}
Engine.ProfileStop();
Engine.ProfileStart("Build new Dropsites");
@@ -4,6 +4,8 @@ function QBotAI(settings) {
this.turn = 0;
this.playedTurn = 0;
this.modules = {
"economy": new EconomyManager(),
"military": new MilitaryAttackManager(),
@@ -93,8 +95,9 @@ QBotAI.prototype.OnUpdate = function() {
// Run the update every n turns, offset depending on player ID to balance
// the load
if ((this.turn + this.player) % 10 == 0) {
Engine.ProfileStart("qBot");
Engine.ProfileStart("qBot-xp");
this.playedTurn++;
var gameState = new GameState(this);
if (gameState.getOwnEntities().length === 0){