Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 516 Lines • ▼ Show 20 Lines | units.sort((a, b) => { | ||||
{ | { | ||||
if (param[0] == "strength") | if (param[0] == "strength") | ||||
{ | { | ||||
aValue += PETRA.getMaxStrength(a[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance) * param[1]; | aValue += PETRA.getMaxStrength(a[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance) * param[1]; | ||||
bValue += PETRA.getMaxStrength(b[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance) * param[1]; | bValue += PETRA.getMaxStrength(b[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance) * param[1]; | ||||
} | } | ||||
else if (param[0] == "siegeStrength") | else if (param[0] == "siegeStrength") | ||||
{ | { | ||||
aValue += PETRA.getMaxStrength(a[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance, "Structure") * param[1]; | aValue += PETRA.getMaxStrength(a[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance, ["Structure"]) * param[1]; | ||||
bValue += PETRA.getMaxStrength(b[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance, "Structure") * param[1]; | bValue += PETRA.getMaxStrength(b[1], gameState.ai.Config.debug, gameState.ai.Config.DamageTypeImportance, ["Structure"]) * param[1]; | ||||
} | } | ||||
else if (param[0] == "speed") | else if (param[0] == "speed") | ||||
{ | { | ||||
aValue += a[1].walkSpeed() * param[1]; | aValue += a[1].walkSpeed() * param[1]; | ||||
bValue += b[1].walkSpeed() * param[1]; | bValue += b[1].walkSpeed() * param[1]; | ||||
} | } | ||||
else if (param[0] == "costsResource") | else if (param[0] == "costsResource") | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,540 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.classes(), target.civ()), | ||||
"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.classes(), target.civ()); | ||||
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; | |||||
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) | const ignoreAttackEffects = PETRA.ignoreAttackEffects(gameState, ent, target); | ||||
allowCapture = PETRA.allowCapture(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) | if (!ent.canAttackTarget(target, false, ignoreAttackEffects, [orderData[0].attackType])) | ||||
ent.attack(targetId, allowCapture); | ent.attack(targetId, ignoreAttackEffects); | ||||
} | } | ||||
} | } | ||||
this.capturableTargetsTime = gameState.ai.elapsedTime; | this.capturableTargetsTime = gameState.ai.elapsedTime; | ||||
}; | }; | ||||
/** | /** | ||||
* Check if a structure in blinking territory should/can be defended (currently if it has some attacking armies around) | * Check if a structure in blinking territory should/can be defended (currently if it has some attacking armies around) | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator