Changeset View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | for (let evt of events.ConstructionFinished) | |||||||||||
if (ent.hasClass("Market") && this.maxFields) | if (ent.hasClass("Market") && this.maxFields) | |||||||||||
this.maxFields = false; | this.maxFields = false; | |||||||||||
} | } | |||||||||||
for (let evt of events.OwnershipChanged) // capture events | for (let evt of events.OwnershipChanged) // capture events | |||||||||||
{ | { | |||||||||||
if (evt.to != PlayerID) | if (evt.to != PlayerID) | |||||||||||
continue; | continue; | |||||||||||
let ent = gameState.getEntityById(evt.entity); | let ent = gameState.getEntityById(evt.entity); | |||||||||||
if (!ent) | if (!ent) | |||||||||||
continue; | continue; | |||||||||||
if (evt.from === PlayerID && ent.getMetadata(evt.from, "upgrading") !== undefined) | ||||||||||||
ent.setMetadata(evt.from, "upgrading", undefined); | ||||||||||||
StanUnsubmitted Not Done Inline Actions
Stan: | ||||||||||||
Done Inline ActionsMaybe we should enable https://eslint.org/docs/latest/rules/eqeqeq ? lyv: Maybe we should enable https://eslint.org/docs/latest/rules/eqeqeq ? | ||||||||||||
Not Done Inline ActionsCould be nice but will result in a lot of warnings at first. Stan: Could be nice but will result in a lot of warnings at first. | ||||||||||||
if (!ent.hasClass("Unit")) | if (!ent.hasClass("Unit")) | |||||||||||
{ | { | |||||||||||
if (ent.decaying()) | if (ent.decaying()) | |||||||||||
{ | { | |||||||||||
if (ent.isGarrisonHolder() && this.garrisonManager.addDecayingStructure(gameState, evt.entity, true)) | if (ent.isGarrisonHolder() && this.garrisonManager.addDecayingStructure(gameState, evt.entity, true)) | |||||||||||
continue; | continue; | |||||||||||
if (!this.decayingStructures.has(evt.entity)) | if (!this.decayingStructures.has(evt.entity)) | |||||||||||
this.decayingStructures.add(evt.entity); | this.decayingStructures.add(evt.entity); | |||||||||||
▲ Show 20 Lines • Show All 1,420 Lines • ▼ Show 20 Lines | if (this.canBuild(gameState, "structures/{civ}/fortress")) | |||||||||||
let plan = new PETRA.ConstructionPlan(gameState, "structures/{civ}/fortress"); | let plan = new PETRA.ConstructionPlan(gameState, "structures/{civ}/fortress"); | |||||||||||
plan.queueToReset = "defenseBuilding"; | plan.queueToReset = "defenseBuilding"; | |||||||||||
queues.defenseBuilding.addPlan(plan); | queues.defenseBuilding.addPlan(plan); | |||||||||||
return; | return; | |||||||||||
} | } | |||||||||||
} | } | |||||||||||
} | } | |||||||||||
// Check for possible upgrades | ||||||||||||
if (!this.saveResource) | ||||||||||||
{ | ||||||||||||
// TODO: Sort by most active defences, tracked via by how recently they last attacked an enemy. | ||||||||||||
Not Done Inline ActionsThis would be probably nicer in config file Silier: This would be probably nicer in config file | ||||||||||||
const upgradableDefenses = gameState.getOwnEntitiesByClass("Defensive", true).filter(ent => ent.upgradableEntities() && !ent.getMetadata(PlayerID, "upgrading")); | ||||||||||||
for (const ent of upgradableDefenses.values()) | ||||||||||||
{ | ||||||||||||
const upgradableEnts = ent.upgradableEntities(); | ||||||||||||
let bestAttack = PETRA.getMaxStrength(ent, this.Config.debug, this.Config.DefensiveStructureDamageTypeImportance); | ||||||||||||
let chosenUpgrade; | ||||||||||||
for (const choice in upgradableEnts) | ||||||||||||
{ | ||||||||||||
const template = gameState.getTemplate(gameState.applyCiv(upgradableEnts[choice].Entity)); | ||||||||||||
Done Inline ActionsIn fact it's not safe, because Petra won't update sentry towers into stone towers as they have the same Pierce damage. When this was originally written, stone towers had greater damage. lyv: In fact it's not safe, because Petra won't update sentry towers into stone towers as they have… | ||||||||||||
Done Inline ActionsThe new heuristic should actually be DPS. lyv: The new heuristic should actually be DPS. | ||||||||||||
Not Done Inline ActionsWhy not use getMaxStrength? Silier: Why not use getMaxStrength? | ||||||||||||
Not Done Inline ActionsAh, yes, that's much nicer. lyv: Ah, yes, that's much nicer. | ||||||||||||
if (!template) | ||||||||||||
continue; | ||||||||||||
// Notice that AI entities are derived from templates and can be passed to most entityExtend functions. | ||||||||||||
const templateAttackStrength = PETRA.getMaxStrength(template, this.Config.debug, this.Config.DefensiveStructureDamageTypeImportance); | ||||||||||||
Done Inline ActionsIt's somewhat weird that for (const choice in undefined) does not fire any errors in JS. lyv: It's somewhat weird that `for (const choice in undefined)` does not fire any errors in JS. | ||||||||||||
// Dont want a weaker upgrade here since this concerns defense. | ||||||||||||
if (templateAttackStrength < bestAttack) | ||||||||||||
continue; | ||||||||||||
// If the upgraded entity's strength is the same but has less health, we don't want it. | ||||||||||||
if (templateAttackStrength == bestAttack && template.maxHitpoints() < ent.maxHitpoints()) | ||||||||||||
continue; | ||||||||||||
bestAttack = templateAttackStrength; | ||||||||||||
chosenUpgrade = upgradableEnts[choice]; | ||||||||||||
} | ||||||||||||
if (chosenUpgrade) | ||||||||||||
queues.defenseBuilding.addPlan(new PETRA.UpgradePlan(gameState, ent.id(), chosenUpgrade)); | ||||||||||||
FreagarachUnsubmitted Not Done Inline ActionsShould we return hereafter? Freagarach: Should we return hereafter?
Somewhat a design question, whether we allow to upgrade as much as… | ||||||||||||
SilierUnsubmitted Not Done Inline ActionsIn theory you are free to flood ai with upgrades since it does not need to check placement. However depending on priority, it could block other queues for a long time depending on how many towers are there. Silier: In theory you are free to flood ai with upgrades since it does not need to check placement. | ||||||||||||
} | ||||||||||||
} | ||||||||||||
if (this.Config.Military.numSentryTowers && this.currentPhase < 2 && this.canBuild(gameState, "structures/{civ}/sentry_tower")) | if (this.Config.Military.numSentryTowers && this.currentPhase < 2 && this.canBuild(gameState, "structures/{civ}/sentry_tower")) | |||||||||||
{ | { | |||||||||||
// Count all towers + wall towers. | // Count all towers + wall towers. | |||||||||||
let numTowers = gameState.getOwnEntitiesByClass("Tower", true).length + gameState.getOwnEntitiesByClass("WallTower", true).length; | let numTowers = gameState.getOwnEntitiesByClass("Tower", true).length + gameState.getOwnEntitiesByClass("WallTower", true).length; | |||||||||||
let towerLapseTime = this.saveResource ? (1 + 0.5 * numTowers) * this.towerLapseTime : this.towerLapseTime; | let towerLapseTime = this.saveResource ? (1 + 0.5 * numTowers) * this.towerLapseTime : this.towerLapseTime; | |||||||||||
if (numTowers < this.Config.Military.numSentryTowers && gameState.ai.elapsedTime > towerLapseTime + this.fortStartTime) | if (numTowers < this.Config.Military.numSentryTowers && gameState.ai.elapsedTime > towerLapseTime + this.fortStartTime) | |||||||||||
{ | { | |||||||||||
this.fortStartTime = gameState.ai.elapsedTime; | this.fortStartTime = gameState.ai.elapsedTime; | |||||||||||
▲ Show 20 Lines • Show All 819 Lines • Show Last 20 Lines |