Fixes AI error when building a new base, and improves the AI's early game and tendency to grab terrain. Fixes incorrect release of some units by the defense manager.

This was SVN commit r14738.
This commit is contained in:
wraitii 2014-02-07 18:36:37 +00:00
parent 05f13bb1d8
commit 01611c1675
6 changed files with 57 additions and 26 deletions

View File

@ -166,7 +166,8 @@ m.AegisBot.prototype.OnUpdate = function(sharedScript) {
m.debug ("Planning Town Phase");
} else if (this.gameState.canResearch(cityPhase,true) && this.gameState.getTimeElapsed() > (this.Config.Economy.cityPhase*1000)
&& this.gameState.getOwnEntitiesByRole("worker", true).length > 85
&& this.gameState.findResearchers(cityPhase, true).length != 0 && this.queues.majorTech.length() === 0) {
&& this.gameState.findResearchers(cityPhase, true).length != 0 && this.queues.majorTech.length() === 0
&& this.queues.civilCentre.length() === 0) {
m.debug ("Trying to reach city phase");
this.queues.majorTech.addItem(new m.ResearchPlan(this.gameState, cityPhase));
}

View File

@ -220,8 +220,12 @@ m.Army.prototype.removeOwn = function (gameState, ID, Entity)
var formerSubRole = ent.getMetadata(PlayerID, "formerSubRole");
if (formerRole !== undefined)
ent.setMetadata(PlayerID,"role", formerRole);
else
ent.setMetadata(PlayerID,"role", undefined);
if (formerSubRole !== undefined)
ent.setMetadata(PlayerID,"subrole", formerSubRole);
else
ent.setMetadata(PlayerID,"subrole", undefined);
return true;
}

View File

@ -521,7 +521,7 @@ m.BaseManager.prototype.updateDropsite = function (gameState, ent, type) {
{
medianPositionX /= divider;
medianPositionY /= divider;
if (API3.SquareVectorDistance([medianPositionX,medianPositionY], ent.position()) > 1800)
if (API3.SquareVectorDistance([medianPositionX,medianPositionY], ent.position()) > 600)
{
dropsite[6] = true;
gameState.ai.queues.dropsites.addItem(new m.ConstructionPlan(gameState, "structures/{civ}_storehouse", { "base" : this.ID }, [medianPositionX,medianPositionY]));
@ -673,20 +673,32 @@ m.BaseManager.prototype.checkResourceLevels = function (gameState,queues) {
numFarms++;
});
var numFd = gameState.countEntitiesByType(gameState.applyCiv("foundation|structures/{civ}_field"), true);
if (numFarms+numFd > 15)
{
warn("treu");
this.willGather["food"] = 2;
}
var numQueued = queues.field.countQueuedUnits();
numFarms += numFd + numQueued;
// let's see if we need to push new farms.
var maxGatherers = gameState.getTemplate(gameState.applyCiv("structures/{civ}_field")).maxGatherers();
if (numQueued < 3)
if (numFarms < Math.round(this.gatherersByType(gameState, "food").length / (maxGatherers*0.9))
&& numFarms < Math.round((this.workers.length*0.4)/maxGatherers))
if (numFarms < Math.round(this.gatherersByType(gameState, "food").length / (maxGatherers*0.9)))
queues.field.addItem(new m.ConstructionPlan(gameState, "structures/{civ}_field", { "base" : this.ID }));
// TODO: refine count to only count my base.
}
} else if (queues.dropsites.length() === 0 && gameState.countFoundationsByType(gameState.applyCiv("structures/{civ}_storehouse"), true) === 0) {
var workerCapacity = this.getWorkerCapacity(gameState, type); // only close;
var wantDropsite = (this.gatherersByType(gameState, type).length / workerCapacity) > 0.9;
// check how often we'll want new dropsites.
// if we're booming we'll aggressively grab terrain
if (gameState.currentPhase() >= 1 && gameState.ai.aggressiveness < 0.15)
var wantDropsite = (this.gatherersByType(gameState, type).length / workerCapacity) > 0.45;
else if (gameState.currentPhase() >= 1)
var wantDropsite = (this.gatherersByType(gameState, type).length / workerCapacity) > 0.6;
else
var wantDropsite = (this.gatherersByType(gameState, type).length / workerCapacity) > 0.9;
if (wantDropsite)
{
var pos = this.findBestDropsiteLocation(gameState, type);
@ -803,17 +815,22 @@ m.BaseManager.prototype.reassignIdleWorkers = function(gameState) {
}
if (ent.hasClass("Worker")) {
var types = gameState.ai.HQ.pickMostNeededResources(gameState);
//m.debug ("assigning " +ent.id() + " to " + types[0]);
ent.setMetadata(PlayerID, "subrole", "gatherer");
ent.setMetadata(PlayerID, "gather-type", types[0]);
m.AddTCRessGatherer(gameState,types[0]);
// Okay let's now check we can actually remain here for that
if (self.willGather[types[0]] !== 1)
for (var i = 0; i < 4; ++i)
{
// TODO: if fail, we should probably pick the second most needed resource.
gameState.ai.HQ.switchWorkerBase(gameState, ent, types[0]);
// Okay let's now check we can actually remain here for that
if (self.willGather[types[i]] !== 1)
{
if (!gameState.ai.HQ.switchWorkerBase(gameState, ent, types[i]))
continue;
else
break;
}
//m.debug ("assigning " +ent.id() + " to " + types[0]);
ent.setMetadata(PlayerID, "subrole", "gatherer");
ent.setMetadata(PlayerID, "gather-type", types[i]);
m.AddTCRessGatherer(gameState,types[i]);
break;
}
} else {
ent.setMetadata(PlayerID, "subrole", "hunter");

View File

@ -7,7 +7,7 @@ m.Config = function() {
this.Military = {
"fortressLapseTime" : 540, // Time to wait between building 2 fortresses
"defenceBuildingTime" : 600, // Time to wait before building towers or fortresses
"defenceBuildingTime" : 900, // Time to wait before building towers or fortresses
"attackPlansStartTime" : 0, // time to wait before attacking. Start as soon as possible.
"techStartTime" : 120, // time to wait before teching. Will only start after town phase so it's irrelevant.
"popForBarracks1" : 25,
@ -23,7 +23,7 @@ m.Config = function() {
"techStartTime" : 0, // time to wait before teching.
"targetNumBuilders" : 1.5, // Base number of builders per foundation.
"femaleRatio" : 0.5, // percent of females among the workforce.
"initialFields" : 2
"initialFields" : 5
};
// Note: attack settings are set directly in attack_plan.js
@ -73,7 +73,7 @@ m.Config = function() {
"economicBuilding" : 90,
"militaryBuilding" : 240, // set to something lower after the first barracks.
"defenceBuilding" : 70,
"civilCentre" : 750,
"civilCentre" : 950,
"majorTech" : 700,
"minorTech" : 40
};

View File

@ -838,9 +838,9 @@ m.HQ.prototype.buildMoreHouses = function(gameState,queues) {
m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
if (gameState.currentPhase() === 1 && !gameState.isResearching(gameState.townPhase()))
return;
var count = { "wood" : 0, "stone" : 0, "metal" : 0 }
var count = { "food" : 0, "wood" : 0, "stone" : 0, "metal" : 0 }
var capacity = { "wood" : 0, "stone" : 0, "metal" : 0 }
var need = { "wood" : true, "stone" : true, "metal" : true };
var need = { "food": false, "wood" : true, "stone" : true, "metal" : true };
var posss = [];
for (var i in this.baseManagers)
@ -848,7 +848,14 @@ m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
var base = this.baseManagers[i];
for (var type in count)
{
if (base.getResourceLevel(gameState, type, "all") > 2200*Math.max(this.Config.difficulty,2))
if (type == "food")
{
count[type] = 1;
capacity[type] = 20000;
need[type] = (base.willGather[type] !== 1);
continue;
}
if (base.getResourceLevel(gameState, type, "dropsites") > 4000*Math.max(this.Config.difficulty,2))
count[type]++;
capacity[type] += base.getWorkerCapacity(gameState, type, true);
if (base.willGather[type] === 1)
@ -870,7 +877,7 @@ m.HQ.prototype.checkBasesRessLevel = function(gameState,queues) {
// Okay so we'll set us as out of this.
this.outOf[type] = true;
} else {
warn ("planning new base ");
warn ("planning new base");
// base "-1" means new base.
queues.civilCentre.addItem(new m.ConstructionPlan(gameState, "structures/{civ}_civil_centre",{ "base" : -1 }, pos));
}

View File

@ -234,7 +234,9 @@ m.Worker.prototype.startGathering = function(baseManager, gameState) {
continue;
if (dropsiteInfo)
{
var coeff = dropsiteInfo[3] + (capacity-dropsiteInfo[5].length)*100;
var coeff = dropsiteInfo[3] + (capacity-dropsiteInfo[5].length)*1000;
if (gameState.getEntityById(id).hasClass("CivilCentre"))
coeff += 20000;
if (coeff > wantedDropsiteCoeff)
{
wantedDropsiteCoeff = coeff;
@ -287,7 +289,7 @@ m.Worker.prototype.startGathering = function(baseManager, gameState) {
if (dropsiteInfo && dropsiteInfo[3] > 600 && dropsiteInfo[5].length < capacity)
{
// we want to change bases.
this.ent.setMetadata(PlayerID,"base",this.baseID);
this.ent.setMetadata(PlayerID,"base",base.ID);
wantedDropsite = id;
break;
}
@ -315,7 +317,7 @@ m.Worker.prototype.startGathering = function(baseManager, gameState) {
continue;
if (dropsiteInfo && dropsiteInfo[4] > 600 && dropsiteInfo[5].length < capacity)
{
this.ent.setMetadata(PlayerID,"base",this.baseID);
this.ent.setMetadata(PlayerID,"base",base.ID);
wantedDropsite = id;
break; // here I'll break, TODO.
}
@ -325,6 +327,7 @@ m.Worker.prototype.startGathering = function(baseManager, gameState) {
if (wantedDropsite === 0)
{
//TODO: something.
// Okay so we haven't found any appropriate dropsite anywhere.
m.debug("No proper dropsite found for " + resource + ", waiting.");
return;
@ -412,8 +415,7 @@ m.Worker.prototype.pickResourceNearDropsite = function(gameState, resource, drop
if (resource === "food" && this.buildAnyField(gameState))
return true;
m.debug("Found a proper dropsite for " + resource + " but apparently no resources are available.");
m.debug("Please report this to wraitii on the wildfire games Forum");
//m.debug("Found a proper dropsite for " + resource + " but apparently no resources are available.");
return false;
}