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.hasClass("Structure"))
|
||||||
{
|
{
|
||||||
if (ent.owner() !== PlayerID)
|
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
|
else // small strength used only when we try to recover capture points
|
||||||
entStrength = 2;
|
entStrength = 2;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ m.Army.prototype.removeFoe = function (gameState, enemyId, enemyEntity)
|
|||||||
if (this.assignedTo[to] == enemyId)
|
if (this.assignedTo[to] == enemyId)
|
||||||
this.assignedTo[to] = undefined;
|
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)
|
if (ent) // TODO recompute strength when no entities (could happen if capture+destroy)
|
||||||
{
|
{
|
||||||
this.evaluateStrength(ent, false, true);
|
this.evaluateStrength(ent, false, true);
|
||||||
@ -209,7 +209,7 @@ m.Army.prototype.removeOwn = function (gameState, id, Entity)
|
|||||||
}
|
}
|
||||||
this.assignedTo[id] = undefined;
|
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)
|
if (ent) // TODO recompute strength when no entities (could happen if capture+destroy)
|
||||||
{
|
{
|
||||||
this.evaluateStrength(ent, true, true);
|
this.evaluateStrength(ent, true, true);
|
||||||
@ -219,7 +219,7 @@ m.Army.prototype.removeOwn = function (gameState, id, Entity)
|
|||||||
else
|
else
|
||||||
ent.setMetadata(PlayerID, "plan", undefined);
|
ent.setMetadata(PlayerID, "plan", undefined);
|
||||||
|
|
||||||
var formerSubrole = ent.getMetadata(PlayerID, "formerSubrole");
|
let formerSubrole = ent.getMetadata(PlayerID, "formerSubrole");
|
||||||
if (formerSubrole !== undefined)
|
if (formerSubrole !== undefined)
|
||||||
ent.setMetadata(PlayerID, "subrole", formerSubrole);
|
ent.setMetadata(PlayerID, "subrole", formerSubrole);
|
||||||
else
|
else
|
||||||
@ -252,7 +252,7 @@ m.Army.prototype.isCapturing = function (gameState)
|
|||||||
if (this.foeEntities.length != 1)
|
if (this.foeEntities.length != 1)
|
||||||
return false;
|
return false;
|
||||||
let ent = gameState.getEntityById(this.foeEntities[0]);
|
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.
|
// 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;
|
this.positionLastUpdate = gameState.ai.elapsedTime;
|
||||||
|
|
||||||
// Check for breakaways.
|
// 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];
|
let id = this.foeEntities[i];
|
||||||
var ent = gameState.getEntityById(id);
|
let ent = gameState.getEntityById(id);
|
||||||
if (!ent || !ent.position())
|
if (!ent || !ent.position())
|
||||||
continue;
|
continue;
|
||||||
if (API3.SquareVectorDistance(ent.position(), this.foePosition) > this.breakawaySize)
|
if (API3.SquareVectorDistance(ent.position(), this.foePosition) > this.breakawaySize)
|
||||||
|
@ -4,7 +4,7 @@ var PETRA = function(m)
|
|||||||
m.Config = function(difficulty)
|
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.
|
// 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
|
// debug level: 0=none, 1=sanity checks, 2=debug, 3=detailed debug, -100=serializatio debug
|
||||||
this.debug = 0;
|
this.debug = 0;
|
||||||
@ -127,14 +127,14 @@ m.Config.prototype.setConfig = function(gameState)
|
|||||||
this.Economy.cityPhase = 240000;
|
this.Economy.cityPhase = 240000;
|
||||||
this.Economy.supportRatio = 0.5;
|
this.Economy.supportRatio = 0.5;
|
||||||
this.Economy.provisionFields = 1;
|
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)
|
else if (this.difficulty < 3)
|
||||||
{
|
{
|
||||||
this.Economy.cityPhase = 1800;
|
this.Economy.cityPhase = 1800;
|
||||||
this.Economy.supportRatio = 0.4;
|
this.Economy.supportRatio = 0.4;
|
||||||
this.Economy.provisionFields = 1;
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -514,9 +514,9 @@ m.HQ.prototype.trainMoreWorkers = function(gameState, queues)
|
|||||||
m.HQ.prototype.findBestTrainableUnit = function(gameState, classes, requirements)
|
m.HQ.prototype.findBestTrainableUnit = function(gameState, classes, requirements)
|
||||||
{
|
{
|
||||||
var units;
|
var units;
|
||||||
if (classes.indexOf("Hero") != -1)
|
if (classes.indexOf("Hero") !== -1)
|
||||||
units = gameState.findTrainableUnits(classes, []);
|
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"]);
|
units = gameState.findTrainableUnits(classes, ["SiegeTower"]);
|
||||||
else // We do not want hero when not explicitely specified
|
else // We do not want hero when not explicitely specified
|
||||||
units = gameState.findTrainableUnits(classes, ["Hero"]);
|
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)
|
for (let j = 0; j < this.territoryMap.length; ++j)
|
||||||
{
|
{
|
||||||
if (this.territoryMap.getOwnerIndex(j) != 0)
|
if (this.territoryMap.getOwnerIndex(j) !== 0)
|
||||||
continue;
|
continue;
|
||||||
// with enough room around to build the cc
|
// with enough room around to build the cc
|
||||||
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
|
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)];
|
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
|
if (proximity) // this is our first cc, let's do it near our units
|
||||||
{
|
norm /= (1 + API3.SquareVectorDistance(proximity, pos) / scale);
|
||||||
let dist = API3.SquareVectorDistance(proximity, pos);
|
|
||||||
norm /= (1 + dist/scale);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let minDist = Math.min();
|
let minDist = Math.min();
|
||||||
@ -914,7 +911,7 @@ m.HQ.prototype.findStrategicCCLocation = function(gameState, template)
|
|||||||
|
|
||||||
for (let j = 0; j < this.territoryMap.length; ++j)
|
for (let j = 0; j < this.territoryMap.length; ++j)
|
||||||
{
|
{
|
||||||
if (this.territoryMap.getOwnerIndex(j) != 0)
|
if (this.territoryMap.getOwnerIndex(j) !== 0)
|
||||||
continue;
|
continue;
|
||||||
// with enough room around to build the cc
|
// with enough room around to build the cc
|
||||||
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
|
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 ownStructures = gameState.getOwnStructures().filter(API3.Filters.byClassesOr(["Fortress", "Tower"])).toEntityArray();
|
||||||
var enemyStructures = gameState.getEnemyStructures().filter(API3.Filters.byClassesOr(["CivCentre", "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 wonderDistmin;
|
||||||
|
var wonders;
|
||||||
if (wonderMode)
|
if (wonderMode)
|
||||||
{
|
{
|
||||||
var wonders = gameState.getOwnStructures().filter(API3.Filters.byClass("Wonder")).toEntityArray();
|
wonders = gameState.getOwnStructures().filter(API3.Filters.byClass("Wonder")).toEntityArray();
|
||||||
wonderMode = (wonders.length != 0);
|
wonderMode = wonders.length !== 0;
|
||||||
if (wonderMode)
|
if (wonderMode)
|
||||||
wonderDistmin = (50 + wonders[0].footprintRadius()) * (50 + wonders[0].footprintRadius());
|
wonderDistmin = (50 + wonders[0].footprintRadius()) * (50 + wonders[0].footprintRadius());
|
||||||
}
|
}
|
||||||
@ -1768,7 +1766,6 @@ m.HQ.prototype.canBuild = function(gameState, structure)
|
|||||||
{
|
{
|
||||||
if (this.stopBuilding.get(type) > gameState.ai.elapsedTime)
|
if (this.stopBuilding.get(type) > gameState.ai.elapsedTime)
|
||||||
return false;
|
return false;
|
||||||
else
|
|
||||||
this.stopBuilding.delete(type);
|
this.stopBuilding.delete(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ m.NavalManager.prototype.splitTransport = function(gameState, plan)
|
|||||||
API3.warn(">>>> previous plan left with units " + plan.units.length);
|
API3.warn(">>>> previous plan left with units " + plan.units.length);
|
||||||
if (nbUnits)
|
if (nbUnits)
|
||||||
this.transportPlans.push(newplan);
|
this.transportPlans.push(newplan);
|
||||||
return (nbUnits !== 0);
|
return nbUnits !== 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,6 @@ m.Queue.prototype.getNext = function()
|
|||||||
{
|
{
|
||||||
if (this.plans.length > 0)
|
if (this.plans.length > 0)
|
||||||
return this.plans[0];
|
return this.plans[0];
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ m.Queue.prototype.startNext = function(gameState)
|
|||||||
this.plans.shift().start(gameState);
|
this.plans.shift().start(gameState);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ m.Queue.prototype.startNext = function(gameState)
|
|||||||
// Currently all the cost of the first element and fraction of that of the second
|
// Currently all the cost of the first element and fraction of that of the second
|
||||||
m.Queue.prototype.maxAccountWanted = function(gameState, fraction)
|
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))
|
if (this.plans.length > 0 && this.plans[0].isGo(gameState))
|
||||||
cost.add(this.plans[0].getCost());
|
cost.add(this.plans[0].getCost());
|
||||||
if (this.plans.length > 1 && this.plans[1].isGo(gameState) && fraction > 0)
|
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()
|
m.Queue.prototype.queueCost = function()
|
||||||
{
|
{
|
||||||
var cost = new API3.Resources();
|
let cost = new API3.Resources();
|
||||||
for (let plan of this.plans)
|
for (let plan of this.plans)
|
||||||
cost.add(plan.getCost());
|
cost.add(plan.getCost());
|
||||||
return cost;
|
return cost;
|
||||||
@ -100,7 +98,7 @@ m.Queue.prototype.hasQueuedUnits = function()
|
|||||||
|
|
||||||
m.Queue.prototype.countQueuedUnits = function()
|
m.Queue.prototype.countQueuedUnits = function()
|
||||||
{
|
{
|
||||||
var count = 0;
|
let count = 0;
|
||||||
for (let plan of this.plans)
|
for (let plan of this.plans)
|
||||||
count += plan.number;
|
count += plan.number;
|
||||||
return count;
|
return count;
|
||||||
@ -113,7 +111,7 @@ m.Queue.prototype.hasQueuedUnitsWithClass = function(classe)
|
|||||||
|
|
||||||
m.Queue.prototype.countQueuedUnitsWithClass = function(classe)
|
m.Queue.prototype.countQueuedUnitsWithClass = function(classe)
|
||||||
{
|
{
|
||||||
var count = 0;
|
let count = 0;
|
||||||
for (let plan of this.plans)
|
for (let plan of this.plans)
|
||||||
if (plan.template && plan.template.hasClass(classe))
|
if (plan.template && plan.template.hasClass(classe))
|
||||||
count += plan.number;
|
count += plan.number;
|
||||||
@ -122,7 +120,7 @@ m.Queue.prototype.countQueuedUnitsWithClass = function(classe)
|
|||||||
|
|
||||||
m.Queue.prototype.countQueuedUnitsWithMetadata = function(data, value)
|
m.Queue.prototype.countQueuedUnitsWithMetadata = function(data, value)
|
||||||
{
|
{
|
||||||
var count = 0;
|
let count = 0;
|
||||||
for (let plan of this.plans)
|
for (let plan of this.plans)
|
||||||
if (plan.metadata[data] && plan.metadata[data] == value)
|
if (plan.metadata[data] && plan.metadata[data] == value)
|
||||||
count += plan.number;
|
count += plan.number;
|
||||||
|
Loading…
Reference in New Issue
Block a user