Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
Show First 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | PETRA.DefenseArmy.prototype.assignUnit = function(gameState, entID) | ||||
let idMinAll; | let idMinAll; | ||||
let distMinAll; | let distMinAll; | ||||
for (let id of this.foeEntities) | for (let id of this.foeEntities) | ||||
{ | { | ||||
let eEnt = gameState.getEntityById(id); | let eEnt = gameState.getEntityById(id); | ||||
if (!eEnt || !eEnt.position()) // probably can't happen. | if (!eEnt || !eEnt.position()) // probably can't happen. | ||||
continue; | continue; | ||||
if (!ent.canAttackTarget(eEnt, PETRA.allowCapture(gameState, ent, eEnt))) | if (!ent.canAttackTarget(eEnt, false, PETRA.ignoreAttackEffects(gameState, ent, eEnt))) | ||||
continue; | continue; | ||||
if (eEnt.hasClass("Unit") && eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length && | if (eEnt.hasClass("Unit") && eEnt.unitAIOrderData() && eEnt.unitAIOrderData().length && | ||||
eEnt.unitAIOrderData()[0].target && eEnt.unitAIOrderData()[0].target == entID) | eEnt.unitAIOrderData()[0].target && eEnt.unitAIOrderData()[0].target == entID) | ||||
{ // being attacked >>> target the unit | { // being attacked >>> target the unit | ||||
idMin = id; | idMin = id; | ||||
break; | break; | ||||
} | } | ||||
Show All 29 Lines | PETRA.DefenseArmy.prototype.assignUnit = function(gameState, entID) | ||||
let ownIndex = PETRA.getLandAccess(gameState, ent); | let ownIndex = PETRA.getLandAccess(gameState, ent); | ||||
let foeEnt = gameState.getEntityById(idFoe); | let foeEnt = gameState.getEntityById(idFoe); | ||||
let foePosition = foeEnt.position(); | let foePosition = foeEnt.position(); | ||||
let foeIndex = gameState.ai.accessibility.getAccessValue(foePosition); | let foeIndex = gameState.ai.accessibility.getAccessValue(foePosition); | ||||
if (ownIndex == foeIndex || ent.hasClass("Ship")) | if (ownIndex == foeIndex || ent.hasClass("Ship")) | ||||
{ | { | ||||
this.assignedTo[entID] = idFoe; | this.assignedTo[entID] = idFoe; | ||||
this.assignedAgainst[idFoe].push(entID); | this.assignedAgainst[idFoe].push(entID); | ||||
ent.attack(idFoe, PETRA.allowCapture(gameState, ent, foeEnt), queued); | ent.attack(idFoe, PETRA.ignoreAttackEffects(gameState, ent, foeEnt), [], undefined, queued); | ||||
} | } | ||||
else | else | ||||
gameState.ai.HQ.navalManager.requireTransport(gameState, ent, ownIndex, foeIndex, foePosition); | gameState.ai.HQ.navalManager.requireTransport(gameState, ent, ownIndex, foeIndex, foePosition); | ||||
return true; | return true; | ||||
}; | }; | ||||
PETRA.DefenseArmy.prototype.getType = function() | PETRA.DefenseArmy.prototype.getType = function() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | PETRA.DefenseArmy.prototype.update = function(gameState) | ||||
for (let entId of this.ownEntities) | for (let entId of this.ownEntities) | ||||
{ | { | ||||
let ent = gameState.getEntityById(entId); | let ent = gameState.getEntityById(entId); | ||||
if (!ent) | if (!ent) | ||||
continue; | continue; | ||||
let orderData = ent.unitAIOrderData(); | let orderData = ent.unitAIOrderData(); | ||||
if (!orderData.length && !ent.getMetadata(PlayerID, "transport")) | if (!orderData.length && !ent.getMetadata(PlayerID, "transport")) | ||||
this.assignUnit(gameState, entId); | this.assignUnit(gameState, entId); | ||||
else if (orderData.length && orderData[0].target && orderData[0].attackType && orderData[0].attackType === "Capture") | else if (orderData.length && orderData[0].target && orderData[0].attackType) | ||||
{ | { | ||||
let target = gameState.getEntityById(orderData[0].target); | const target = gameState.getEntityById(orderData[0].target); | ||||
if (target && !PETRA.allowCapture(gameState, ent, target)) | if (!target) | ||||
ent.attack(orderData[0].target, false); | continue; | ||||
const ignoreAttackEffects = PETRA.ignoreAttackEffects(gameState, ent, target); | |||||
if (!ent.canAttackTarget(target, false, ignoreAttackEffects, [orderData[0].attackType])) | |||||
ent.attack(orderData[0].target, ignoreAttackEffects); | |||||
} | } | ||||
} | } | ||||
if (this.type == "capturing") | if (this.type == "capturing") | ||||
{ | { | ||||
if (this.foeEntities.length && gameState.getEntityById(this.foeEntities[0])) | if (this.foeEntities.length && gameState.getEntityById(this.foeEntities[0])) | ||||
{ | { | ||||
// Check if we still still some capturePoints to recover | // Check if we still still some capturePoints to recover | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator