1
0
forked from 0ad/0ad

small fixes/improvments to the AI

This was SVN commit r15776.
This commit is contained in:
mimo 2014-09-21 12:02:33 +00:00
parent 357fa957c8
commit bce96c99bb
4 changed files with 17 additions and 13 deletions

View File

@ -17,7 +17,6 @@ m.PetraBot = function PetraBot(settings)
this.Config = new m.Config();
this.Config.updateDifficulty(settings.difficulty);
//this.Config.personality = settings.personality;
this.savedEvents = {};
};
@ -28,6 +27,9 @@ m.PetraBot.prototype.CustomInit = function(gameState, sharedScript)
{
this.initPersonality();
if (gameState.getPopulationMax() < 300)
this.Config.popScaling = Math.sqrt(gameState.getPopulationMax() / 300);
this.priorities = this.Config.priorities;
// this.queues can only be modified by the queue manager or things will go awry.
this.queues = {};
@ -109,8 +111,11 @@ m.PetraBot.prototype.initPersonality = function()
{
this.Config.personality.aggressive = Math.random();
this.Config.personality.cooperative = Math.random();
this.Config.personality.defensive = Math.random();
}
this.Config.Military.towerLapseTime += Math.round(20*(this.Config.personality.defensive - 0.5));
this.Config.Military.fortressLapseTime += Math.round(60*(this.Config.personality.defensive - 0.5));
if (this.Config.personality.aggressive > 0.7)
{
this.Config.Military.popForBarracks1 = 12;

View File

@ -114,13 +114,9 @@ m.AttackPlan = function(gameState, Config, uniqueID, type, data)
this.unitStat["Hero"] = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"],
"interests": [ ["strength",2], ["cost",1] ] };
this.neededShips = 5;
// decrease a bit the targetSize according to max population
if (gameState.getPopulationMax() < 300)
{
var reduc = Math.sqrt(gameState.getPopulationMax() / 300);
for (var unitCat in this.unitStat)
this.unitStat[unitCat]["targetSize"] = Math.floor(reduc * this.unitStat[unitCat]["targetSize"]);
}
// change the targetSize according to max population
for (var unitCat in this.unitStat)
this.unitStat[unitCat]["targetSize"] = Math.round(this.Config.popScaling * this.unitStat[unitCat]["targetSize"]);
}
else
{

View File

@ -7,9 +7,11 @@ m.Config = function() {
// debug level: 0=none, 1=sanity checks, 2=debug; 3=detailed debug
this.debug = 0;
this.popScaling = 1; // scale factor depending on the max population
this.Military = {
"towerLapseTime" : 90, // Time to wait between building 2 towers
"fortressLapseTime" : 420, // Time to wait between building 2 fortresses
"fortressLapseTime" : 390, // Time to wait between building 2 fortresses
"popForBarracks1" : 25,
"popForBarracks2" : 95,
"popForBlacksmith" : 65
@ -91,7 +93,8 @@ m.Config = function() {
this.personality =
{
"aggressive": 0.5,
"cooperative": 0.5
"cooperative": 0.5,
"defensive": 0.5
};
this.resources = ["food", "wood", "stone", "metal"];

View File

@ -129,7 +129,8 @@ m.HQ.prototype.init = function(gameState, queues)
var self = this;
var width = gameState.getMap().width;
gameState.getOwnEntities().forEach( function (ent) {
if (ent.hasClass("Trader"))
// do not affect merchant ship immediately to trade as they may-be useful for transport
if (ent.hasClass("Trader") && !ent.hasClass("Ship"))
self.tradeManager.assignTrader(ent);
var pos = ent.position();
if (!pos)
@ -417,7 +418,6 @@ m.HQ.prototype.checkEvents = function (gameState, events, queues)
this.baseManagers[base].buildings.updateEnt(ent);
this.updateTerritories(gameState);
// let us hope this new base will fix our resource shortage
// TODO check it really does so
this.saveResources = undefined;
}
else if (ent.hasTerritoryInfluence())
@ -1696,7 +1696,7 @@ m.HQ.prototype.canBuild = function(gameState, structure)
{
this.stopBuilding.push(type);
if (this.Config.debug > 0)
API3.warn("Petra error: trying to build " + structure + " for civ " + gameState.civ() + " but no template found ");
API3.warn("Petra error: trying to build " + structure + " for civ " + gameState.civ() + " but no template found.");
}
if (!template || !template.available(gameState))
return false;