Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 2,495 Lines • ▼ Show 20 Lines | for (let ent of gameState.getOwnUnits().values()) | ||||
if (!orderData || !orderData.length || !orderData[0].target) | if (!orderData || !orderData.length || !orderData[0].target) | ||||
continue; | continue; | ||||
let targetId = orderData[0].target; | let targetId = orderData[0].target; | ||||
let target = gameState.getEntityById(targetId); | let target = gameState.getEntityById(targetId); | ||||
if (!target || !target.isCapturable() || !ent.canCapture(target)) | if (!target || !target.isCapturable() || !ent.canCapture(target)) | ||||
continue; | continue; | ||||
if (!this.capturableTargets.has(targetId)) | if (!this.capturableTargets.has(targetId)) | ||||
this.capturableTargets.set(targetId, { | this.capturableTargets.set(targetId, { | ||||
"strength": ent.captureStrength() * PETRA.getAttackBonus(ent, target, "Capture"), | "strength": ent.captureStrength(target), | ||||
"ents": new Set([ent.id()]) | "ents": new Set([ent.id()]) | ||||
}); | }); | ||||
else | else | ||||
{ | { | ||||
let capturableTarget = this.capturableTargets.get(target.id()); | let capturableTarget = this.capturableTargets.get(target.id()); | ||||
capturableTarget.strength += ent.captureStrength() * PETRA.getAttackBonus(ent, target, "Capture"); | capturableTarget.strength += ent.captureStrength(target); | ||||
capturableTarget.ents.add(ent.id()); | capturableTarget.ents.add(ent.id()); | ||||
} | } | ||||
} | } | ||||
for (let [targetId, capturableTarget] of this.capturableTargets) | for (let [targetId, capturableTarget] of this.capturableTargets) | ||||
{ | { | ||||
let target = gameState.getEntityById(targetId); | let target = gameState.getEntityById(targetId); | ||||
let allowCapture; | let prefAttackForms; | ||||
for (let entId of capturableTarget.ents) | for (let entId of capturableTarget.ents) | ||||
{ | { | ||||
let ent = gameState.getEntityById(entId); | let ent = gameState.getEntityById(entId); | ||||
if (allowCapture === undefined) | if (prefAttackForms === undefined) | ||||
allowCapture = PETRA.allowCapture(gameState, ent, target); | prefAttackForms = PETRA.getPrefAttackForms(gameState, ent, target); | ||||
let orderData = ent.unitAIOrderData(); | let orderData = ent.unitAIOrderData(); | ||||
if (!orderData || !orderData.length || !orderData[0].attackType) | if (!orderData || !orderData.length || !orderData[0].attackType) | ||||
continue; | continue; | ||||
if ((orderData[0].attackType == "Capture") !== allowCapture) | ent.attack(targetId, prefAttackForms); | ||||
ent.attack(targetId, allowCapture); | |||||
} | } | ||||
} | } | ||||
this.capturableTargetsTime = gameState.ai.elapsedTime; | this.capturableTargetsTime = gameState.ai.elapsedTime; | ||||
}; | }; | ||||
/** Some functions that register that we assigned a gatherer to a resource this turn */ | /** Some functions that register that we assigned a gatherer to a resource this turn */ | ||||
▲ Show 20 Lines • Show All 360 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator