forked from 0ad/0ad
some cleanup in petra
This was SVN commit r18170.
This commit is contained in:
parent
f5cfda84b8
commit
ac525fcd2a
@ -95,7 +95,7 @@ m.Army.prototype.evaluateStrength = function (ent, isOwn, remove)
|
||||
if (ent.hasClass("Structure"))
|
||||
{
|
||||
if (ent.owner() !== PlayerID)
|
||||
entStrength = (ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4);
|
||||
entStrength = ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4;
|
||||
else // small strength used only when we try to recover capture points
|
||||
entStrength = 2;
|
||||
}
|
||||
@ -156,7 +156,7 @@ m.Army.prototype.removeFoe = function (gameState, enemyId, enemyEntity)
|
||||
if (this.assignedTo[to] == enemyId)
|
||||
this.assignedTo[to] = undefined;
|
||||
|
||||
let ent = (enemyEntity ? enemyEntity : gameState.getEntityById(enemyId));
|
||||
let ent = enemyEntity ? enemyEntity : gameState.getEntityById(enemyId);
|
||||
if (ent) // TODO recompute strength when no entities (could happen if capture+destroy)
|
||||
{
|
||||
this.evaluateStrength(ent, false, true);
|
||||
@ -209,7 +209,7 @@ m.Army.prototype.removeOwn = function (gameState, id, Entity)
|
||||
}
|
||||
this.assignedTo[id] = undefined;
|
||||
|
||||
let ent = (Entity ? Entity : gameState.getEntityById(id));
|
||||
let ent = Entity ? Entity : gameState.getEntityById(id);
|
||||
if (ent) // TODO recompute strength when no entities (could happen if capture+destroy)
|
||||
{
|
||||
this.evaluateStrength(ent, true, true);
|
||||
@ -219,7 +219,7 @@ m.Army.prototype.removeOwn = function (gameState, id, Entity)
|
||||
else
|
||||
ent.setMetadata(PlayerID, "plan", undefined);
|
||||
|
||||
var formerSubrole = ent.getMetadata(PlayerID, "formerSubrole");
|
||||
let formerSubrole = ent.getMetadata(PlayerID, "formerSubrole");
|
||||
if (formerSubrole !== undefined)
|
||||
ent.setMetadata(PlayerID, "subrole", formerSubrole);
|
||||
else
|
||||
@ -252,7 +252,7 @@ m.Army.prototype.isCapturing = function (gameState)
|
||||
if (this.foeEntities.length != 1)
|
||||
return false;
|
||||
let ent = gameState.getEntityById(this.foeEntities[0]);
|
||||
return (ent && ent.hasClass("Structure"));
|
||||
return ent && ent.hasClass("Structure");
|
||||
};
|
||||
|
||||
// this one is "undefined entity" proof because it's called at odd times.
|
||||
@ -397,10 +397,10 @@ m.Army.prototype.onUpdate = function (gameState)
|
||||
this.positionLastUpdate = gameState.ai.elapsedTime;
|
||||
|
||||
// Check for breakaways.
|
||||
for (var i = 0; i < this.foeEntities.length; ++i)
|
||||
for (let i = 0; i < this.foeEntities.length; ++i)
|
||||
{
|
||||
var id = this.foeEntities[i];
|
||||
var ent = gameState.getEntityById(id);
|
||||
let id = this.foeEntities[i];
|
||||
let ent = gameState.getEntityById(id);
|
||||
if (!ent || !ent.position())
|
||||
continue;
|
||||
if (API3.SquareVectorDistance(ent.position(), this.foePosition) > this.breakawaySize)
|
||||
|
@ -4,7 +4,7 @@ var PETRA = function(m)
|
||||
m.Config = function(difficulty)
|
||||
{
|
||||
// 0 is sandbox, 1 is very easy, 2 is easy, 3 is medium, 4 is hard and 5 is very hard.
|
||||
this.difficulty = (difficulty !== undefined) ? difficulty : 3;
|
||||
this.difficulty = difficulty !== undefined ? difficulty : 3;
|
||||
|
||||
// debug level: 0=none, 1=sanity checks, 2=debug, 3=detailed debug, -100=serializatio debug
|
||||
this.debug = 0;
|
||||
@ -127,14 +127,14 @@ m.Config.prototype.setConfig = function(gameState)
|
||||
this.Economy.cityPhase = 240000;
|
||||
this.Economy.supportRatio = 0.5;
|
||||
this.Economy.provisionFields = 1;
|
||||
this.Military.numWoodenTowers = (this.personality.defensive > 0.66) ? 1 : 0;
|
||||
this.Military.numWoodenTowers = this.personality.defensive > 0.66 ? 1 : 0;
|
||||
}
|
||||
else if (this.difficulty < 3)
|
||||
{
|
||||
this.Economy.cityPhase = 1800;
|
||||
this.Economy.supportRatio = 0.4;
|
||||
this.Economy.provisionFields = 1;
|
||||
this.Military.numWoodenTowers = (this.personality.defensive > 0.66) ? 1 : 0;
|
||||
this.Military.numWoodenTowers = this.personality.defensive > 0.66 ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -514,9 +514,9 @@ m.HQ.prototype.trainMoreWorkers = function(gameState, queues)
|
||||
m.HQ.prototype.findBestTrainableUnit = function(gameState, classes, requirements)
|
||||
{
|
||||
var units;
|
||||
if (classes.indexOf("Hero") != -1)
|
||||
if (classes.indexOf("Hero") !== -1)
|
||||
units = gameState.findTrainableUnits(classes, []);
|
||||
else if (classes.indexOf("Siege") != -1) // We do not want siege tower as AI does not know how to use it
|
||||
else if (classes.indexOf("Siege") !== -1) // We do not want siege tower as AI does not know how to use it
|
||||
units = gameState.findTrainableUnits(classes, ["SiegeTower"]);
|
||||
else // We do not want hero when not explicitely specified
|
||||
units = gameState.findTrainableUnits(classes, ["Hero"]);
|
||||
@ -744,7 +744,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
|
||||
|
||||
for (let j = 0; j < this.territoryMap.length; ++j)
|
||||
{
|
||||
if (this.territoryMap.getOwnerIndex(j) != 0)
|
||||
if (this.territoryMap.getOwnerIndex(j) !== 0)
|
||||
continue;
|
||||
// with enough room around to build the cc
|
||||
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
|
||||
@ -762,10 +762,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource,
|
||||
let pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)];
|
||||
|
||||
if (proximity) // this is our first cc, let's do it near our units
|
||||
{
|
||||
let dist = API3.SquareVectorDistance(proximity, pos);
|
||||
norm /= (1 + dist/scale);
|
||||
}
|
||||
norm /= (1 + API3.SquareVectorDistance(proximity, pos) / scale);
|
||||
else
|
||||
{
|
||||
let minDist = Math.min();
|
||||
@ -914,7 +911,7 @@ m.HQ.prototype.findStrategicCCLocation = function(gameState, template)
|
||||
|
||||
for (let j = 0; j < this.territoryMap.length; ++j)
|
||||
{
|
||||
if (this.territoryMap.getOwnerIndex(j) != 0)
|
||||
if (this.territoryMap.getOwnerIndex(j) !== 0)
|
||||
continue;
|
||||
// with enough room around to build the cc
|
||||
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
|
||||
@ -1119,12 +1116,13 @@ m.HQ.prototype.findDefensiveLocation = function(gameState, template)
|
||||
var ownStructures = gameState.getOwnStructures().filter(API3.Filters.byClassesOr(["Fortress", "Tower"])).toEntityArray();
|
||||
var enemyStructures = gameState.getEnemyStructures().filter(API3.Filters.byClassesOr(["CivCentre", "Fortress", "Tower"])).toEntityArray();
|
||||
|
||||
var wonderMode = (gameState.getGameType() === "wonder");
|
||||
var wonderMode = gameState.getGameType() === "wonder";
|
||||
var wonderDistmin;
|
||||
var wonders;
|
||||
if (wonderMode)
|
||||
{
|
||||
var wonders = gameState.getOwnStructures().filter(API3.Filters.byClass("Wonder")).toEntityArray();
|
||||
wonderMode = (wonders.length != 0);
|
||||
wonders = gameState.getOwnStructures().filter(API3.Filters.byClass("Wonder")).toEntityArray();
|
||||
wonderMode = wonders.length !== 0;
|
||||
if (wonderMode)
|
||||
wonderDistmin = (50 + wonders[0].footprintRadius()) * (50 + wonders[0].footprintRadius());
|
||||
}
|
||||
@ -1768,8 +1766,7 @@ m.HQ.prototype.canBuild = function(gameState, structure)
|
||||
{
|
||||
if (this.stopBuilding.get(type) > gameState.ai.elapsedTime)
|
||||
return false;
|
||||
else
|
||||
this.stopBuilding.delete(type);
|
||||
this.stopBuilding.delete(type);
|
||||
}
|
||||
|
||||
if (gameState.isDisabledTemplates(type))
|
||||
|
@ -403,7 +403,7 @@ m.NavalManager.prototype.splitTransport = function(gameState, plan)
|
||||
API3.warn(">>>> previous plan left with units " + plan.units.length);
|
||||
if (nbUnits)
|
||||
this.transportPlans.push(newplan);
|
||||
return (nbUnits !== 0);
|
||||
return nbUnits !== 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -49,8 +49,7 @@ m.Queue.prototype.getNext = function()
|
||||
{
|
||||
if (this.plans.length > 0)
|
||||
return this.plans[0];
|
||||
else
|
||||
return null;
|
||||
return null;
|
||||
};
|
||||
|
||||
m.Queue.prototype.startNext = function(gameState)
|
||||
@ -60,15 +59,14 @@ m.Queue.prototype.startNext = function(gameState)
|
||||
this.plans.shift().start(gameState);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
};
|
||||
|
||||
// returns the maximal account we'll accept for this queue.
|
||||
// Currently all the cost of the first element and fraction of that of the second
|
||||
m.Queue.prototype.maxAccountWanted = function(gameState, fraction)
|
||||
{
|
||||
var cost = new API3.Resources();
|
||||
let cost = new API3.Resources();
|
||||
if (this.plans.length > 0 && this.plans[0].isGo(gameState))
|
||||
cost.add(this.plans[0].getCost());
|
||||
if (this.plans.length > 1 && this.plans[1].isGo(gameState) && fraction > 0)
|
||||
@ -82,7 +80,7 @@ m.Queue.prototype.maxAccountWanted = function(gameState, fraction)
|
||||
|
||||
m.Queue.prototype.queueCost = function()
|
||||
{
|
||||
var cost = new API3.Resources();
|
||||
let cost = new API3.Resources();
|
||||
for (let plan of this.plans)
|
||||
cost.add(plan.getCost());
|
||||
return cost;
|
||||
@ -100,7 +98,7 @@ m.Queue.prototype.hasQueuedUnits = function()
|
||||
|
||||
m.Queue.prototype.countQueuedUnits = function()
|
||||
{
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
for (let plan of this.plans)
|
||||
count += plan.number;
|
||||
return count;
|
||||
@ -113,7 +111,7 @@ m.Queue.prototype.hasQueuedUnitsWithClass = function(classe)
|
||||
|
||||
m.Queue.prototype.countQueuedUnitsWithClass = function(classe)
|
||||
{
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
for (let plan of this.plans)
|
||||
if (plan.template && plan.template.hasClass(classe))
|
||||
count += plan.number;
|
||||
@ -122,7 +120,7 @@ m.Queue.prototype.countQueuedUnitsWithClass = function(classe)
|
||||
|
||||
m.Queue.prototype.countQueuedUnitsWithMetadata = function(data, value)
|
||||
{
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
for (let plan of this.plans)
|
||||
if (plan.metadata[data] && plan.metadata[data] == value)
|
||||
count += plan.number;
|
||||
|
Loading…
Reference in New Issue
Block a user