diff --git a/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js b/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js index b885e1e0e7..23b8e7a813 100755 --- a/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js +++ b/binaries/data/mods/public/simulation/ai/qbot-wc/attack_plan.js @@ -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]; + } } } } diff --git a/binaries/data/mods/public/simulation/ai/qbot-wc/defence.js b/binaries/data/mods/public/simulation/ai/qbot-wc/defence.js index 3cc4561db5..92925dd487 100755 --- a/binaries/data/mods/public/simulation/ai/qbot-wc/defence.js +++ b/binaries/data/mods/public/simulation/ai/qbot-wc/defence.js @@ -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; } } diff --git a/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js b/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js index 625861886b..16b195cf07 100644 --- a/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js +++ b/binaries/data/mods/public/simulation/ai/qbot-wc/economy.js @@ -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"); diff --git a/binaries/data/mods/public/simulation/ai/qbot-wc/qbot.js b/binaries/data/mods/public/simulation/ai/qbot-wc/qbot.js index a383bb43cf..5f8167f8b1 100644 --- a/binaries/data/mods/public/simulation/ai/qbot-wc/qbot.js +++ b/binaries/data/mods/public/simulation/ai/qbot-wc/qbot.js @@ -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){