Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | for (let entId of evt.entities) | ||||
} | } | ||||
// Check if this unit is no more needed in its attack plan | // Check if this unit is no more needed in its attack plan | ||||
// (happen when the training ends after the attack is started or aborted) | // (happen when the training ends after the attack is started or aborted) | ||||
let plan = ent.getMetadata(PlayerID, "plan"); | let plan = ent.getMetadata(PlayerID, "plan"); | ||||
if (plan !== undefined && plan >= 0) | if (plan !== undefined && plan >= 0) | ||||
{ | { | ||||
let attack = this.attackManager.getPlan(plan); | let attack = this.attackManager.getPlan(plan); | ||||
if (!attack || attack.state != "unexecuted") | if (!attack || attack.state != PETRA.AttackPlan.STATE_UNEXECUTED) | ||||
ent.setMetadata(PlayerID, "plan", -1); | ent.setMetadata(PlayerID, "plan", -1); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
for (let evt of events.TerritoryDecayChanged) | for (let evt of events.TerritoryDecayChanged) | ||||
{ | { | ||||
let ent = gameState.getEntityById(evt.entity); | let ent = gameState.getEntityById(evt.entity); | ||||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | PETRA.HQ.prototype.trainMoreWorkers = function(gameState, queues) | ||||
// So we take: supportRatio*targetNumWorkers*(1 - exp(-alfa*currentWorkers/supportRatio/targetNumWorkers)) | // So we take: supportRatio*targetNumWorkers*(1 - exp(-alfa*currentWorkers/supportRatio/targetNumWorkers)) | ||||
// This gives back supportRatio*targetNumWorkers when currentWorkers >> supportRatio*targetNumWorkers | // This gives back supportRatio*targetNumWorkers when currentWorkers >> supportRatio*targetNumWorkers | ||||
// and gives a ratio alfa at startup. | // and gives a ratio alfa at startup. | ||||
let supportRatio = this.supportRatio; | let supportRatio = this.supportRatio; | ||||
let alpha = 0.85; | let alpha = 0.85; | ||||
if (!gameState.isTemplateAvailable(gameState.applyCiv("structures/{civ}/field"))) | if (!gameState.isTemplateAvailable(gameState.applyCiv("structures/{civ}/field"))) | ||||
supportRatio = Math.min(this.supportRatio, 0.1); | supportRatio = Math.min(this.supportRatio, 0.1); | ||||
if (this.attackManager.rushNumber < this.attackManager.maxRushes || this.attackManager.upcomingAttacks.Rush.length) | if (this.attackManager.rushNumber < this.attackManager.maxRushes || this.attackManager.upcomingAttacks[PETRA.AttackPlan.TYPE_RUSH].length) | ||||
alpha = 0.7; | alpha = 0.7; | ||||
if (gameState.isCeasefireActive()) | if (gameState.isCeasefireActive()) | ||||
alpha += (1 - alpha) * Math.min(Math.max(gameState.ceasefireTimeRemaining - 120, 0), 180) / 180; | alpha += (1 - alpha) * Math.min(Math.max(gameState.ceasefireTimeRemaining - 120, 0), 180) / 180; | ||||
let supportMax = supportRatio * this.targetNumWorkers; | let supportMax = supportRatio * this.targetNumWorkers; | ||||
let supportNum = supportMax * (1 - Math.exp(-alpha*numberTotal/supportMax)); | let supportNum = supportMax * (1 - Math.exp(-alpha*numberTotal/supportMax)); | ||||
let template; | let template; | ||||
if (!templateDef || numberOfSupports + numberOfQueuedSupports > supportNum) | if (!templateDef || numberOfSupports + numberOfQueuedSupports > supportNum) | ||||
▲ Show 20 Lines • Show All 1,411 Lines • ▼ Show 20 Lines | for (let q in queueManager.queues) | ||||
continue; | continue; | ||||
queueManager.transferAccounts(cost, q, "emergency"); | queueManager.transferAccounts(cost, q, "emergency"); | ||||
if (queueManager.canAfford("emergency", cost)) | if (queueManager.canAfford("emergency", cost)) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
let metadata = { "role": "worker", "base": nearestAnchor.getMetadata(PlayerID, "base"), "plan": -1, "trainer": nearestAnchor.id() }; | let metadata = { "role": "worker", "base": nearestAnchor.getMetadata(PlayerID, "base"), "plan": -1, "trainer": nearestAnchor.id() }; | ||||
if (autogarrison) | if (autogarrison) | ||||
metadata.garrisonType = "protection"; | metadata.garrisonType = PETRA.GarrisonManager.TYPE_PROTECTION; | ||||
gameState.ai.queues.emergency.addPlan(new PETRA.TrainingPlan(gameState, templateFound[0], metadata, 1, 1)); | gameState.ai.queues.emergency.addPlan(new PETRA.TrainingPlan(gameState, templateFound[0], metadata, 1, 1)); | ||||
return true; | return true; | ||||
}; | }; | ||||
PETRA.HQ.prototype.canBuild = function(gameState, structure) | PETRA.HQ.prototype.canBuild = function(gameState, structure) | ||||
{ | { | ||||
let type = gameState.applyCiv(structure); | let type = gameState.applyCiv(structure); | ||||
if (this.buildManager.isUnbuildable(gameState, type)) | if (this.buildManager.isUnbuildable(gameState, type)) | ||||
▲ Show 20 Lines • Show All 518 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator