Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/defenseManager.js
Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | for (let i = 0; i < potentialDefenders.length; ++i) | ||||
for (let a = 0; a < armiesNeeding.length; ++a) | for (let a = 0; a < armiesNeeding.length; ++a) | ||||
{ | { | ||||
if (access && armiesNeeding[a].access != access) | if (access && armiesNeeding[a].access != access) | ||||
continue; | continue; | ||||
// Do not assign defender if it cannot attack at least part of the attacking army. | // Do not assign defender if it cannot attack at least part of the attacking army. | ||||
if (!armiesNeeding[a].army.foeEntities.some(eEnt => { | if (!armiesNeeding[a].army.foeEntities.some(eEnt => { | ||||
let eEntID = gameState.getEntityById(eEnt); | let eEntID = gameState.getEntityById(eEnt); | ||||
return ent.canAttackTarget(eEntID, PETRA.allowCapture(gameState, ent, eEntID)); | return ent.canAttackTarget(eEntID, false, PETRA.ignoreAttackEffects(gameState, ent, eEntID)); | ||||
})) | })) | ||||
continue; | continue; | ||||
let dist = API3.SquareVectorDistance(ent.position(), armiesNeeding[a].army.foePosition); | let dist = API3.SquareVectorDistance(ent.position(), armiesNeeding[a].army.foePosition); | ||||
if (aMin !== undefined && dist > distMin) | if (aMin !== undefined && dist > distMin) | ||||
continue; | continue; | ||||
aMin = a; | aMin = a; | ||||
distMin = dist; | distMin = dist; | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | if (target.hasClass("Unit") && attacker.hasClass("Unit")) | ||||
let minEnt; | let minEnt; | ||||
let pos = attacker.position(); | let pos = attacker.position(); | ||||
capturableTarget.ents.delete(target.id()); | capturableTarget.ents.delete(target.id()); | ||||
for (let entId of capturableTarget.ents) | for (let entId of capturableTarget.ents) | ||||
{ | { | ||||
if (allAttacked[entId]) | if (allAttacked[entId]) | ||||
continue; | continue; | ||||
let ent = gameState.getEntityById(entId); | let ent = gameState.getEntityById(entId); | ||||
if (!ent || !ent.position() || !ent.canAttackTarget(attacker, PETRA.allowCapture(gameState, ent, attacker))) | if (!ent || !ent.position() || !ent.canAttackTarget(attacker, false, PETRA.ignoreAttackEffects(gameState, ent, attacker))) | ||||
continue; | continue; | ||||
// Check that the unit is still attacking the structure (since the last played turn). | // Check that the unit is still attacking the structure (since the last played turn). | ||||
let state = ent.unitAIState(); | let state = ent.unitAIState(); | ||||
if (!state || !state.split(".")[1] || state.split(".")[1] != "COMBAT") | if (!state || !state.split(".")[1] || state.split(".")[1] != "COMBAT") | ||||
continue; | continue; | ||||
let entOrderData = ent.unitAIOrderData(); | let entOrderData = ent.unitAIOrderData(); | ||||
if (!entOrderData || !entOrderData.length || !entOrderData[0].target || | if (!entOrderData || !entOrderData.length || !entOrderData[0].target || | ||||
entOrderData[0].target != orderData[0].target) | entOrderData[0].target != orderData[0].target) | ||||
continue; | continue; | ||||
let dist = API3.SquareVectorDistance(pos, ent.position()); | let dist = API3.SquareVectorDistance(pos, ent.position()); | ||||
if (minEnt && dist > minDist) | if (minEnt && dist > minDist) | ||||
continue; | continue; | ||||
minDist = dist; | minDist = dist; | ||||
minEnt = ent; | minEnt = ent; | ||||
} | } | ||||
if (minEnt) | if (minEnt) | ||||
{ | { | ||||
capturableTarget.ents.delete(minEnt.id()); | capturableTarget.ents.delete(minEnt.id()); | ||||
minEnt.attack(attacker.id(), PETRA.allowCapture(gameState, minEnt, attacker)); | minEnt.attack(attacker.id(), PETRA.ignoreAttackEffects(gameState, minEnt, attacker)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
let allowCapture = PETRA.allowCapture(gameState, target, attacker); | const ignoreAttackEffects = PETRA.ignoreAttackEffects(gameState, target, attacker); | ||||
if (target.canAttackTarget(attacker, allowCapture)) | if (target.canAttackTarget(attacker, false, ignoreAttackEffects)) | ||||
target.attack(attacker.id(), allowCapture); | target.attack(attacker.id(), ignoreAttackEffects); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
PETRA.DefenseManager.prototype.garrisonUnitsInside = function(gameState, target, data) | PETRA.DefenseManager.prototype.garrisonUnitsInside = function(gameState, target, data) | ||||
{ | { | ||||
if (target.hitpoints() < target.garrisonEjectHealth() * target.maxHitpoints()) | if (target.hitpoints() < target.garrisonEjectHealth() * target.maxHitpoints()) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator