1
0
forked from 0ad/0ad

more petra cleanup following eslint

This was SVN commit r21460.
This commit is contained in:
mimo 2018-03-07 18:41:39 +00:00
parent 14da2f841f
commit 061371da92
7 changed files with 93 additions and 93 deletions

View File

@ -877,10 +877,12 @@ m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
// Don't repair if we're still under attack, unless it's a vital (civcentre or wall) building
// that's being destroyed.
if (gameState.ai.HQ.isNearInvadingArmy(target.position()))
{
if (target.healthLevel() > 0.5 ||
!target.hasClass("CivCentre") && !target.hasClass("StoneWall") &&
(!target.hasClass("Wonder") || !gameState.getVictoryConditions().has("wonder")))
continue;
}
else if (noRepair && !target.hasClass("CivCentre"))
continue;

View File

@ -46,28 +46,28 @@ m.Config = function(difficulty, behavior)
"armyMergeSize": 1400 // squared.
};
// Additional buildings that the AI does not yet know when to build
// and that it will try to build on phase 3 when enough resources.
this.buildings =
{
"advanced": {
"default": [],
"athen": ["structures/{civ}_gymnasion", "structures/{civ}_prytaneion",
"structures/{civ}_theatron", "structures/{civ}_royal_stoa"],
"brit": ["structures/{civ}_rotarymill"],
"cart": ["structures/{civ}_embassy_celtic", "structures/{civ}_embassy_iberian",
"structures/{civ}_embassy_italiote"],
"gaul": ["structures/{civ}_rotarymill", "structures/{civ}_tavern"],
"iber": ["structures/{civ}_monument"],
"kush": ["structures/{civ}_pyramid_large", "structures/{civ}_blemmye_camp",
"structures/{civ}_nuba_village"],
"mace": ["structures/{civ}_library", "structures/{civ}_theatron"],
"maur": ["structures/{civ}_pillar_ashoka"],
"pers": ["structures/{civ}_apadana", "structures/{civ}_hall"],
"ptol": ["structures/{civ}_library"],
"rome": ["structures/{civ}_army_camp"],
"sele": ["structures/{civ}_library"],
"spart": ["structures/{civ}_syssiton", "structures/{civ}_theatron",
"structures/{civ}_royal_stoa"]
}
"default": [],
"athen": ["structures/{civ}_gymnasion", "structures/{civ}_prytaneion",
"structures/{civ}_theatron", "structures/{civ}_royal_stoa"],
"brit": ["structures/{civ}_rotarymill"],
"cart": ["structures/{civ}_embassy_celtic", "structures/{civ}_embassy_iberian",
"structures/{civ}_embassy_italiote"],
"gaul": ["structures/{civ}_rotarymill", "structures/{civ}_tavern"],
"iber": ["structures/{civ}_monument"],
"kush": ["structures/{civ}_pyramid_large", "structures/{civ}_blemmye_camp",
"structures/{civ}_nuba_village"],
"mace": ["structures/{civ}_library", "structures/{civ}_theatron"],
"maur": ["structures/{civ}_pillar_ashoka"],
"pers": ["structures/{civ}_apadana", "structures/{civ}_hall"],
"ptol": ["structures/{civ}_library"],
"rome": ["structures/{civ}_army_camp"],
"sele": ["structures/{civ}_library"],
"spart": ["structures/{civ}_syssiton", "structures/{civ}_theatron",
"structures/{civ}_royal_stoa"]
};
this.priorities =

View File

@ -721,28 +721,28 @@ m.DefenseManager.prototype.garrisonUnitsInside = function(gameState, target, dat
allowMelee = true;
}
let units = gameState.getOwnUnits().filter(ent => {
if (!ent.position())
if (!ent.position())
return false;
if (!MatchesClassList(ent.classes(), garrisonArrowClasses))
return false;
if (typeGarrison != "decay" && !allowMelee && ent.attackTypes().indexOf("Melee") != -1)
return false;
if (ent.getMetadata(PlayerID, "transport") !== undefined)
return false;
let army = ent.getMetadata(PlayerID, "PartOfArmy") ? this.getArmy(ent.getMetadata(PlayerID, "PartOfArmy")) : undefined;
if (!army && (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3))
return false;
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0)
{
let subrole = ent.getMetadata(PlayerID, "subrole");
// when structure decaying (usually because we've just captured it in enemy territory), also allow units from an attack plan
if (typeGarrison != "decay" && subrole && (subrole == "completing" || subrole == "walking" || subrole == "attacking"))
return false;
if (!MatchesClassList(ent.classes(), garrisonArrowClasses))
return false;
if (typeGarrison != "decay" && !allowMelee && ent.attackTypes().indexOf("Melee") != -1)
return false;
if (ent.getMetadata(PlayerID, "transport") !== undefined)
return false;
let army = ent.getMetadata(PlayerID, "PartOfArmy") ? this.getArmy(ent.getMetadata(PlayerID, "PartOfArmy")) : undefined;
if (!army && (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3))
return false;
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0)
{
let subrole = ent.getMetadata(PlayerID, "subrole");
// when structure decaying (usually because we've just captured it in enemy territory), also allow units from an attack plan
if (typeGarrison != "decay" && subrole && (subrole == "completing" || subrole == "walking" || subrole == "attacking"))
return false;
}
if (m.getLandAccess(gameState, ent) != access)
return false;
return true;
}).filterNearest(target.position());
}
if (m.getLandAccess(gameState, ent) != access)
return false;
return true;
}).filterNearest(target.position());
let ret = false;
for (let ent of units.values())

View File

@ -663,25 +663,25 @@ m.GameTypeManager.prototype.captureGaiaRelic = function(gameState, relic)
let relicPosition = relic.position();
let access = m.getLandAccess(gameState, relic);
let units = gameState.getOwnUnits().filter(ent => {
if (!ent.position() || !ent.canCapture(relic))
if (!ent.position() || !ent.canCapture(relic))
return false;
if (ent.getMetadata(PlayerID, "transport") !== undefined)
return false;
if (ent.getMetadata(PlayerID, "PartOfArmy") !== undefined)
return false;
let plan = ent.getMetadata(PlayerID, "plan");
if (plan == -2 || plan == -3)
return false;
if (plan !== undefined && plan >= 0)
{
let attack = gameState.ai.HQ.attackManager.getPlan(plan);
if (attack && (attack.state != "unexecuted" || attack.type == "Raid"))
return false;
if (ent.getMetadata(PlayerID, "transport") !== undefined)
return false;
if (ent.getMetadata(PlayerID, "PartOfArmy") !== undefined)
return false;
let plan = ent.getMetadata(PlayerID, "plan");
if (plan == -2 || plan == -3)
return false;
if (plan !== undefined && plan >= 0)
{
let attack = gameState.ai.HQ.attackManager.getPlan(plan);
if (attack && (attack.state != "unexecuted" || attack.type == "Raid"))
return false;
}
if (m.getLandAccess(gameState, ent) != access)
return false;
return true;
}).filterNearest(relicPosition);
}
if (m.getLandAccess(gameState, ent) != access)
return false;
return true;
}).filterNearest(relicPosition);
let expedition = [];
for (let ent of units.values())
{

View File

@ -189,26 +189,25 @@ m.NavalManager.prototype.getFishSea = function(gameState, fish)
sea = gameState.ai.accessibility.navalPassMap[k];
fish.setMetadata(PlayerID, "sea", sea);
let radius = 120 / gameState.ai.accessibility.cellSize / ntry;
if (around.every(a =>
if (around.every(a => {
for (let t = 0; t < ntry; ++t)
{
for (let t = 0; t < ntry; ++t)
let i = pos[0] + Math.round(a[0]*radius*(ntry-t));
let j = pos[1] + Math.round(a[1]*radius*(ntry-t));
if (i < 0 || i >= width || j < 0 || j >= width)
continue;
if (gameState.ai.accessibility.landPassMap[i + j*width] === 1)
{
let i = pos[0] + Math.round(a[0]*radius*(ntry-t));
let j = pos[1] + Math.round(a[1]*radius*(ntry-t));
if (i < 0 || i >= width || j < 0 || j >= width)
let navalPass = gameState.ai.accessibility.navalPassMap[i + j*width];
if (navalPass == sea)
return true;
else if (navalPass == 1) // we could be outside the map
continue;
if (gameState.ai.accessibility.landPassMap[i + j*width] === 1)
{
let navalPass = gameState.ai.accessibility.navalPassMap[i + j*width];
if (navalPass == sea)
return true;
else if (navalPass == 1) // we could be outside the map
continue;
}
return false;
}
return true;
}))
return false;
}
return true;
}))
fish.setMetadata(PlayerID, "opensea", true);
return sea;
};
@ -224,20 +223,19 @@ m.NavalManager.prototype.canFishSafely = function(gameState, fish)
let width = territoryMap.width;
let radius = 120 / territoryMap.cellSize / ntry;
let pos = territoryMap.gamePosToMapPos(fish.position());
return around.every(a =>
return around.every(a => {
for (let t = 0; t < ntry; ++t)
{
for (let t = 0; t < ntry; ++t)
{
let i = pos[0] + Math.round(a[0]*radius*(ntry-t));
let j = pos[1] + Math.round(a[1]*radius*(ntry-t));
if (i < 0 || i >= width || j < 0 || j >= width)
continue;
let owner = territoryMap.getOwnerIndex(i + j*width);
if (owner != 0 && gameState.isPlayerEnemy(owner))
return false;
}
return true;
});
let i = pos[0] + Math.round(a[0]*radius*(ntry-t));
let j = pos[1] + Math.round(a[1]*radius*(ntry-t));
if (i < 0 || i >= width || j < 0 || j >= width)
continue;
let owner = territoryMap.getOwnerIndex(i + j*width);
if (owner != 0 && gameState.isPlayerEnemy(owner))
return false;
}
return true;
});
};
/** get the list of seas (or lands) around this region not connected by a dock */

View File

@ -618,7 +618,7 @@ m.ConstructionPlan.prototype.checkDockPlacement = function(gameState, x, z, half
* if wantedSea is given, this tile should be inside this sea
*/
const around = [[ 1.0, 0.0], [ 0.87, 0.50], [ 0.50, 0.87], [ 0.0, 1.0], [-0.50, 0.87], [-0.87, 0.50],
[-1.0, 0.0], [-0.87,-0.50], [-0.50,-0.87], [ 0.0,-1.0], [ 0.50,-0.87], [ 0.87,-0.50]];
[-1.0, 0.0], [-0.87,-0.50], [-0.50,-0.87], [ 0.0,-1.0], [ 0.50,-0.87], [ 0.87,-0.50]];
m.ConstructionPlan.prototype.isDockLocation = function(gameState, j, dimension, wantedLand, wantedSea)
{

View File

@ -234,11 +234,11 @@ m.HQ.prototype.regionAnalysis = function(gameState)
m.HQ.prototype.structureAnalysis = function(gameState)
{
let civref = gameState.playerData.civ;
let civ = civref in this.Config.buildings.advanced ? civref : 'default';
let civ = civref in this.Config.buildings ? civref : 'default';
this.bAdvanced = [];
for (let advanced of this.Config.buildings.advanced[civ])
if (gameState.isTemplateAvailable(gameState.applyCiv(advanced)))
this.bAdvanced.push(gameState.applyCiv(advanced));
for (let building of this.Config.buildings[civ])
if (gameState.isTemplateAvailable(gameState.applyCiv(building)))
this.bAdvanced.push(gameState.applyCiv(building));
};
/**