Differential D2150 Diff 17818 ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | if (ent.hasClass("Unit")) | ||||
} | } | ||||
if (ent.hasClass("Worker")) | if (ent.hasClass("Worker")) | ||||
{ | { | ||||
ent.setMetadata(PlayerID, "role", "worker"); | ent.setMetadata(PlayerID, "role", "worker"); | ||||
ent.setMetadata(PlayerID, "subrole", "idle"); | ent.setMetadata(PlayerID, "subrole", "idle"); | ||||
} | } | ||||
if (ent.hasClass("Ship")) | if (ent.hasClass("Ship")) | ||||
PETRA.setSeaAccess(gameState, ent); | PETRA.setSeaAccess(gameState, ent); | ||||
if (!ent.hasClass("Support") && !ent.hasClass("Ship") && ent.attackTypes() !== undefined) | if (!ent.hasClasses(["Support", "Ship"]) && ent.attackTypes() !== undefined) | ||||
ent.setMetadata(PlayerID, "plan", -1); | ent.setMetadata(PlayerID, "plan", -1); | ||||
continue; | continue; | ||||
} | } | ||||
if (ent.hasClass("CivCentre")) // build a new base around it | if (ent.hasClass("CivCentre")) // build a new base around it | ||||
{ | { | ||||
let newbase; | let newbase; | ||||
if (ent.foundationProgress() !== undefined) | if (ent.foundationProgress() !== undefined) | ||||
newbase = this.createBase(gameState, ent, "unconstructed"); | newbase = this.createBase(gameState, ent, "unconstructed"); | ||||
▲ Show 20 Lines • Show All 588 Lines • ▼ Show 20 Lines | PETRA.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource, proximity, fromStrategic) | ||||
let obstructions = PETRA.createObstructionMap(gameState, 0, template); | let obstructions = PETRA.createObstructionMap(gameState, 0, template); | ||||
let halfSize = 0; | let halfSize = 0; | ||||
if (template.get("Footprint/Square")) | if (template.get("Footprint/Square")) | ||||
halfSize = Math.max(+template.get("Footprint/Square/@depth"), +template.get("Footprint/Square/@width")) / 2; | halfSize = Math.max(+template.get("Footprint/Square/@depth"), +template.get("Footprint/Square/@width")) / 2; | ||||
else if (template.get("Footprint/Circle")) | else if (template.get("Footprint/Circle")) | ||||
halfSize = +template.get("Footprint/Circle/@radius"); | halfSize = +template.get("Footprint/Circle/@radius"); | ||||
let ccEnts = gameState.updatingGlobalCollection("allCCs", API3.Filters.byClass("CivCentre")); | let ccEnts = gameState.updatingGlobalCollection("allCCs", API3.Filters.byClass("CivCentre")); | ||||
let dpEnts = gameState.getOwnDropsites().filter(API3.Filters.not(API3.Filters.byClassesOr(["CivCentre", "Unit"]))); | const dpEnts = gameState.getOwnDropsites().filter(API3.Filters.not(API3.Filters.byClasses(["CivCentre", "Unit"]))); | ||||
let ccList = []; | let ccList = []; | ||||
for (let cc of ccEnts.values()) | for (let cc of ccEnts.values()) | ||||
ccList.push({ "ent": cc, "pos": cc.position(), "ally": gameState.isPlayerAlly(cc.owner()) }); | ccList.push({ "ent": cc, "pos": cc.position(), "ally": gameState.isPlayerAlly(cc.owner()) }); | ||||
let dpList = []; | let dpList = []; | ||||
for (let dp of dpEnts.values()) | for (let dp of dpEnts.values()) | ||||
dpList.push({ "ent": dp, "pos": dp.position(), "territory": this.territoryMap.getOwner(dp.position()) }); | dpList.push({ "ent": dp, "pos": dp.position(), "territory": this.territoryMap.getOwner(dp.position()) }); | ||||
let bestIdx; | let bestIdx; | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | else if (template.get("Footprint/Circle")) | ||||
halfSize = +template.get("Footprint/Circle/@radius"); | halfSize = +template.get("Footprint/Circle/@radius"); | ||||
let bestIdx; | let bestIdx; | ||||
let bestJdx; | let bestJdx; | ||||
let bestVal; | let bestVal; | ||||
let bestDistSq; | let bestDistSq; | ||||
let bestGainMult; | let bestGainMult; | ||||
let radius = Math.ceil(template.obstructionRadius().max / obstructions.cellSize); | let radius = Math.ceil(template.obstructionRadius().max / obstructions.cellSize); | ||||
let isNavalMarket = template.hasClass("Naval") && template.hasClass("Trade"); | const isNavalMarket = template.hasClasses(["Naval+Trade"]); | ||||
let width = this.territoryMap.width; | let width = this.territoryMap.width; | ||||
let cellSize = this.territoryMap.cellSize; | let cellSize = this.territoryMap.cellSize; | ||||
let traderTemplatesGains = gameState.getTraderTemplatesGains(); | let traderTemplatesGains = gameState.getTraderTemplatesGains(); | ||||
for (let j = 0; j < this.territoryMap.length; ++j) | for (let j = 0; j < this.territoryMap.length; ++j) | ||||
{ | { | ||||
Show All 12 Lines | for (let j = 0; j < this.territoryMap.length; ++j) | ||||
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)]; | ||||
// checking distances to other markets | // checking distances to other markets | ||||
let maxVal = 0; | let maxVal = 0; | ||||
let maxDistSq; | let maxDistSq; | ||||
let maxGainMult; | let maxGainMult; | ||||
let gainMultiplier; | let gainMultiplier; | ||||
for (let market of markets) | for (let market of markets) | ||||
{ | { | ||||
if (isNavalMarket && template.hasClass("Naval") && template.hasClass("Trade")) | if (isNavalMarket && template.hasClasses(["Naval+Trade"])) | ||||
{ | { | ||||
if (PETRA.getSeaAccess(gameState, market) != gameState.ai.accessibility.getAccessValue(pos, true)) | if (PETRA.getSeaAccess(gameState, market) != gameState.ai.accessibility.getAccessValue(pos, true)) | ||||
continue; | continue; | ||||
gainMultiplier = traderTemplatesGains.navalGainMultiplier; | gainMultiplier = traderTemplatesGains.navalGainMultiplier; | ||||
} | } | ||||
else if (PETRA.getLandAccess(gameState, market) == index && | else if (PETRA.getLandAccess(gameState, market) == index && | ||||
!PETRA.isLineInsideEnemyTerritory(gameState, market.position(), pos)) | !PETRA.isLineInsideEnemyTerritory(gameState, market.position(), pos)) | ||||
gainMultiplier = traderTemplatesGains.landGainMultiplier; | gainMultiplier = traderTemplatesGains.landGainMultiplier; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
* Whose primary function is to defend our borders | * Whose primary function is to defend our borders | ||||
*/ | */ | ||||
PETRA.HQ.prototype.findDefensiveLocation = function(gameState, template) | PETRA.HQ.prototype.findDefensiveLocation = function(gameState, template) | ||||
{ | { | ||||
// We take the point in our territory which is the nearest to any enemy cc | // We take the point in our territory which is the nearest to any enemy cc | ||||
// but requiring a minimal distance with our other defensive structures | // but requiring a minimal distance with our other defensive structures | ||||
// and not in range of any enemy defensive structure to avoid building under fire. | // and not in range of any enemy defensive structure to avoid building under fire. | ||||
let ownStructures = gameState.getOwnStructures().filter(API3.Filters.byClassesOr(["Fortress", "Tower"])).toEntityArray(); | const ownStructures = gameState.getOwnStructures().filter(API3.Filters.byClasses(["Fortress", "Tower"])).toEntityArray(); | ||||
let enemyStructures = gameState.getEnemyStructures().filter(API3.Filters.not(API3.Filters.byOwner(0))). | let enemyStructures = gameState.getEnemyStructures().filter(API3.Filters.not(API3.Filters.byOwner(0))). | ||||
filter(API3.Filters.byClassesOr(["CivCentre", "Fortress", "Tower"])); | filter(API3.Filters.byClasses(["CivCentre", "Fortress", "Tower"])); | ||||
if (!enemyStructures.hasEntities()) // we may be in cease fire mode, build defense against neutrals | if (!enemyStructures.hasEntities()) // we may be in cease fire mode, build defense against neutrals | ||||
{ | { | ||||
enemyStructures = gameState.getNeutralStructures().filter(API3.Filters.not(API3.Filters.byOwner(0))). | enemyStructures = gameState.getNeutralStructures().filter(API3.Filters.not(API3.Filters.byOwner(0))). | ||||
filter(API3.Filters.byClassesOr(["CivCentre", "Fortress", "Tower"])); | filter(API3.Filters.byClasses(["CivCentre", "Fortress", "Tower"])); | ||||
if (!enemyStructures.hasEntities() && !gameState.getAlliedVictory()) | if (!enemyStructures.hasEntities() && !gameState.getAlliedVictory()) | ||||
enemyStructures = gameState.getAllyStructures().filter(API3.Filters.not(API3.Filters.byOwner(PlayerID))). | enemyStructures = gameState.getAllyStructures().filter(API3.Filters.not(API3.Filters.byOwner(PlayerID))). | ||||
filter(API3.Filters.byClassesOr(["CivCentre", "Fortress", "Tower"])); | filter(API3.Filters.byClasses(["CivCentre", "Fortress", "Tower"])); | ||||
if (!enemyStructures.hasEntities()) | if (!enemyStructures.hasEntities()) | ||||
return undefined; | return undefined; | ||||
} | } | ||||
enemyStructures = enemyStructures.toEntityArray(); | enemyStructures = enemyStructures.toEntityArray(); | ||||
let wonderMode = gameState.getVictoryConditions().has("wonder"); | let wonderMode = gameState.getVictoryConditions().has("wonder"); | ||||
let wonderDistmin; | let wonderDistmin; | ||||
let wonders; | let wonders; | ||||
▲ Show 20 Lines • Show All 708 Lines • ▼ Show 20 Lines | PETRA.HQ.prototype.trainEmergencyUnits = function(gameState, positions) | ||||
let templateFound; | let templateFound; | ||||
let trainables = nearestAnchor.trainableEntities(civ); | let trainables = nearestAnchor.trainableEntities(civ); | ||||
let garrisonArrowClasses = nearestAnchor.getGarrisonArrowClasses(); | let garrisonArrowClasses = nearestAnchor.getGarrisonArrowClasses(); | ||||
for (let trainable of trainables) | for (let trainable of trainables) | ||||
{ | { | ||||
if (gameState.isTemplateDisabled(trainable)) | if (gameState.isTemplateDisabled(trainable)) | ||||
continue; | continue; | ||||
let template = gameState.getTemplate(trainable); | let template = gameState.getTemplate(trainable); | ||||
if (!template || !template.hasClass("Infantry") || !template.hasClass("CitizenSoldier")) | if (!template || !template.hasClasses(["Infantry+CitizenSoldier"])) | ||||
continue; | continue; | ||||
if (autogarrison && !MatchesClassList(template.classes(), garrisonArrowClasses)) | if (autogarrison && !template.hasClasses(garrisonArrowClasses)) | ||||
continue; | continue; | ||||
if (!total.canAfford(new API3.Resources(template.cost()))) | if (!total.canAfford(new API3.Resources(template.cost()))) | ||||
continue; | continue; | ||||
templateFound = [trainable, template]; | templateFound = [trainable, template]; | ||||
if (template.hasClass("Ranged") == rangedWanted) | if (template.hasClass("Ranged") == rangedWanted) | ||||
break; | break; | ||||
} | } | ||||
if (!templateFound) | if (!templateFound) | ||||
▲ Show 20 Lines • Show All 752 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator