Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/defenseManager.js
Show First 20 Lines • Show All 434 Lines • ▼ Show 20 Lines | if (ent.hasClass("Catapult")) | ||||
return; | return; | ||||
if (ent.hasClass("FishingBoat") || ent.hasClass("Trader")) | if (ent.hasClass("FishingBoat") || ent.hasClass("Trader")) | ||||
return; | return; | ||||
if (ent.getMetadata(PlayerID, "transport") !== undefined || | if (ent.getMetadata(PlayerID, "transport") !== undefined || | ||||
ent.getMetadata(PlayerID, "transporter") !== undefined) | ent.getMetadata(PlayerID, "transporter") !== undefined) | ||||
return; | return; | ||||
if (gameState.ai.HQ.victoryManager.criticalEnts.has(ent.id())) | if (gameState.ai.HQ.victoryManager.criticalEnts.has(ent.id())) | ||||
return; | return; | ||||
// Do not assign defender if it cannot attack at least part of the attacking army. | |||||
for (let i = 0; i < armiesNeeding.length; ++i) | |||||
{ | |||||
let canAttack = armiesNeeding[i].army.foeEntities.some(eEnt => { | |||||
let eEntID = gameState.getEntityById(eEnt); | |||||
return ent.canAttackTarget(eEntID); | |||||
}); | |||||
if (!canAttack) | |||||
return; | |||||
}; | |||||
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") != -1) | if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") != -1) | ||||
{ | { | ||||
let subrole = ent.getMetadata(PlayerID, "subrole"); | let subrole = ent.getMetadata(PlayerID, "subrole"); | ||||
if (subrole && (subrole == "completing" || subrole == "walking" || subrole == "attacking")) | if (subrole && (subrole == "completing" || subrole == "walking" || subrole == "attacking")) | ||||
return; | return; | ||||
} | } | ||||
potentialDefenders.push(ent.id()); | potentialDefenders.push(ent.id()); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 249 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()) | if (!ent || !ent.position() || !ent.canAttackTarget(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(), m.allowCapture(gameState, minEnt, attacker)); | minEnt.attack(attacker.id(), m.allowCapture(gameState, minEnt, attacker)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (target.canAttackTarget(attacker)) | |||||
target.attack(attacker.id(), m.allowCapture(gameState, target, attacker)); | target.attack(attacker.id(), m.allowCapture(gameState, target, attacker)); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
m.DefenseManager.prototype.garrisonUnitsInside = function(gameState, target, data) | m.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 218 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator