Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/defenseManager.js
Show First 20 Lines • Show All 423 Lines • ▼ Show 20 Lines | gameState.getOwnUnits().forEach(function(ent) { | ||||
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; | ||||
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 === PETRA.Worker.SUBROLE_COMPLETING || subrole === PETRA.Worker.SUBROLE_WALKING || subrole === PETRA.Worker.SUBROLE_ATTACKING)) | |||||
nani: Break the check in multiple lines if too long (like in the "transport" above. | |||||
return; | return; | ||||
} | } | ||||
potentialDefenders.push(ent.id()); | potentialDefenders.push(ent.id()); | ||||
}); | }); | ||||
for (let ipass = 0; ipass < 2; ++ipass) | for (let ipass = 0; ipass < 2; ++ipass) | ||||
{ | { | ||||
// First pass only assign defenders with the right access. | // First pass only assign defenders with the right access. | ||||
▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | if (ent.getMetadata(PlayerID, "transport") !== undefined) | ||||
return false; | return false; | ||||
let army = ent.getMetadata(PlayerID, "PartOfArmy") ? this.getArmy(ent.getMetadata(PlayerID, "PartOfArmy")) : undefined; | let army = ent.getMetadata(PlayerID, "PartOfArmy") ? this.getArmy(ent.getMetadata(PlayerID, "PartOfArmy")) : undefined; | ||||
if (!army && (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3)) | if (!army && (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3)) | ||||
return false; | return false; | ||||
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0) | if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0) | ||||
{ | { | ||||
let subrole = ent.getMetadata(PlayerID, "subrole"); | let subrole = ent.getMetadata(PlayerID, "subrole"); | ||||
// When structure decaying (usually because we've just captured it in enemy territory), also allow units from an attack plan. | // When structure decaying (usually because we've just captured it in enemy territory), also allow units from an attack plan. | ||||
if (typeGarrison != "decay" && subrole && (subrole == "completing" || subrole == "walking" || subrole == "attacking")) | if (typeGarrison != "decay" && subrole && | ||||
(subrole === PETRA.Worker.SUBROLE_COMPLETING || subrole === PETRA.Worker.SUBROLE_WALKING || subrole === PETRA.Worker.SUBROLE_ATTACKING)) | |||||
Done Inline ActionsSame, break into lines. nani: Same, break into lines. | |||||
Not Done Inline ActionsFeels like that check could be a function since it's used twice; Stan: Feels like that check could be a function since it's used twice; | |||||
Not Done Inline ActionsAye, but it could be delayed to another patch. (I foresee naming and/or positioning problems of such a function (after a quick thought).) Freagarach: Aye, but it could be delayed to another patch. (I foresee naming and/or positioning problems of… | |||||
return false; | return false; | ||||
} | } | ||||
if (PETRA.getLandAccess(gameState, ent) != access) | if (PETRA.getLandAccess(gameState, ent) != access) | ||||
return false; | return false; | ||||
return true; | return true; | ||||
}).filterNearest(target.position()); | }).filterNearest(target.position()); | ||||
let ret = false; | let ret = false; | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Break the check in multiple lines if too long (like in the "transport" above.