forked from 0ad/0ad
Tweaked attack code and fixed building liimit checks
This was SVN commit r10763.
This commit is contained in:
parent
286ce58b1c
commit
574c4135a3
@ -52,7 +52,8 @@ AttackMoveToLocation.prototype.defaultTargetFinder = function(gameState, militar
|
||||
// Executes the attack plan, after this is executed the update function will be run every turn
|
||||
AttackMoveToLocation.prototype.execute = function(gameState, militaryManager){
|
||||
var availableCount = militaryManager.countAvailableUnits();
|
||||
this.idList = militaryManager.getAvailableUnits(availableCount);
|
||||
var numWanted = Math.min(availableCount, this.maxAttackSize);
|
||||
this.idList = militaryManager.getAvailableUnits(numWanted);
|
||||
|
||||
var pending = EntityCollectionFromIds(gameState, this.idList);
|
||||
|
||||
|
@ -447,6 +447,7 @@ EconomyManager.prototype.update = function(gameState, queues, events) {
|
||||
//Later in the game we want to build stuff faster.
|
||||
if (gameState.countEntitiesWithType(gameState.applyCiv("units/{civ}_support_female_citizen")) > this.targetNumWorkers * 0.5) {
|
||||
this.targetNumBuilders = 10;
|
||||
gameState.ai.priorities.field = 20;
|
||||
}else{
|
||||
this.targetNumBuilders = 5;
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ MilitaryAttackManager.prototype.measureEnemyStrength = function(gameState){
|
||||
// Adds towers to the defenceBuilding queue
|
||||
MilitaryAttackManager.prototype.buildDefences = function(gameState, queues){
|
||||
if (gameState.countEntitiesAndQueuedWithType(gameState.applyCiv('structures/{civ}_scout_tower'))
|
||||
+ queues.defenceBuilding.totalLength() <= gameState.getBuildLimits()["ScoutTower"]) {
|
||||
+ queues.defenceBuilding.totalLength() < gameState.getBuildLimits()["ScoutTower"]) {
|
||||
|
||||
|
||||
gameState.getOwnEntities().forEach(function(dropsiteEnt) {
|
||||
@ -488,7 +488,8 @@ MilitaryAttackManager.prototype.buildDefences = function(gameState, queues){
|
||||
for (var i in this.bFort){
|
||||
numFortresses += gameState.countEntitiesAndQueuedWithType(gameState.applyCiv(this.bFort[i]));
|
||||
}
|
||||
if (numFortresses + queues.defenceBuilding.totalLength() <= gameState.getBuildLimits()["Fortress"]) {
|
||||
|
||||
if (numFortresses + queues.defenceBuilding.totalLength() < gameState.getBuildLimits()["Fortress"]) {
|
||||
if (gameState.countEntitiesWithType(gameState.applyCiv("units/{civ}_support_female_citizen")) > gameState.ai.modules[0].targetNumWorkers * 0.5){
|
||||
if (gameState.getTimeElapsed() > 200 * 1000 * numFortresses){
|
||||
if (gameState.ai.pathsToMe.length > 0){
|
||||
@ -563,26 +564,33 @@ MilitaryAttackManager.prototype.update = function(gameState, queues, events) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Look for attack plans which can be executed, only do this once every minute
|
||||
if (gameState.getTimeElapsed() - 60*1000 > this.lastAttackTime){
|
||||
this.lastAttackTime = gameState.getTimeElapsed();
|
||||
for (var i = 0; i < this.availableAttacks.length; i++){
|
||||
if (this.availableAttacks[i].canExecute(gameState, this)){
|
||||
// Make it so raids happen a bit randomly
|
||||
if (this.attackCount > 4 || Math.random() < 0.25){
|
||||
this.availableAttacks[i].execute(gameState, this);
|
||||
this.currentAttacks.push(this.availableAttacks[i]);
|
||||
if (gameState.getTimeElapsed() < 6.5*60*1000){
|
||||
if (gameState.getTimeElapsed() - 60*1000 > this.lastAttackTime){
|
||||
this.lastAttackTime = gameState.getTimeElapsed();
|
||||
for (var i = 0; i < this.availableAttacks.length; i++){
|
||||
if (this.availableAttacks[i].canExecute(gameState, this)){
|
||||
// Make it so raids happen a bit randomly
|
||||
if (Math.random() < 0.35){
|
||||
this.availableAttacks[i].execute(gameState, this);
|
||||
this.currentAttacks.push(this.availableAttacks[i]);
|
||||
debug("Raiding!");
|
||||
this.availableAttacks.splice(i, 1, new this.attackManagers[i](gameState, this, 10, 10, this.getEconomicTargets));
|
||||
}
|
||||
}
|
||||
if (this.attackCount < 4){
|
||||
this.availableAttacks.splice(i, 1, new this.attackManagers[i](gameState, this, 10, 10, this.getEconomicTargets));
|
||||
}else{
|
||||
this.availableAttacks.splice(i, 1, new this.attackManagers[i](gameState, this, 20, 40 + 10 * Math.max(this.attackCount, 8)));
|
||||
}
|
||||
this.attackCount++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (var i = 0; i < this.availableAttacks.length; i++){
|
||||
if (this.availableAttacks[i].canExecute(gameState, this)){
|
||||
this.availableAttacks[i].execute(gameState, this);
|
||||
this.currentAttacks.push(this.availableAttacks[i]);
|
||||
debug("Attacking!");
|
||||
}
|
||||
this.availableAttacks.splice(i, 1, new this.attackManagers[i](gameState, this, 20, 60));
|
||||
}
|
||||
}
|
||||
|
||||
// Keep current attacks updated
|
||||
for (i in this.currentAttacks){
|
||||
this.currentAttacks[i].update(gameState, this, events);
|
||||
|
@ -121,7 +121,7 @@ QBotAI.prototype.OnUpdate = function() {
|
||||
this.turn++;
|
||||
};
|
||||
|
||||
var debugOn = true;
|
||||
var debugOn = false;
|
||||
|
||||
function debug(output){
|
||||
if (debugOn){
|
||||
|
Loading…
Reference in New Issue
Block a user