Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/attackManager.js
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | PETRA.AttackManager.prototype.assignBombers = function(gameState) | ||||
{ | { | ||||
if (!ent.position() || !ent.isIdle() || !ent.attackRange("Ranged")) | if (!ent.position() || !ent.isIdle() || !ent.attackRange("Ranged")) | ||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3) | if (ent.getMetadata(PlayerID, "plan") == -2 || ent.getMetadata(PlayerID, "plan") == -3) | ||||
continue; | continue; | ||||
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)) | ||||
continue; | continue; | ||||
} | } | ||||
let alreadyBombing = false; | let alreadyBombing = false; | ||||
for (let unitIds of this.bombingAttacks.values()) | for (let unitIds of this.bombingAttacks.values()) | ||||
{ | { | ||||
if (!unitIds.has(ent.id())) | if (!unitIds.has(ent.id())) | ||||
continue; | continue; | ||||
alreadyBombing = true; | alreadyBombing = true; | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | for (let targetId of gameState.ai.HQ.defenseManager.targetList) | ||||
break; | break; | ||||
target = undefined; | target = undefined; | ||||
} | } | ||||
if (target) // prepare a raid against this target | if (target) // prepare a raid against this target | ||||
this.raidTargetEntity(gameState, target); | this.raidTargetEntity(gameState, target); | ||||
} | } | ||||
// Check if we have some unused ranged siege unit which could do something useful while waiting | // Check if we have some unused ranged siege unit which could do something useful while waiting | ||||
if (this.Config.difficulty > 1 && gameState.ai.playedTurn % 5 == 0) | if (this.Config.difficulty > PETRA.DIFFICULTY_VERY_EASY && gameState.ai.playedTurn % 5 == 0) | ||||
this.assignBombers(gameState); | this.assignBombers(gameState); | ||||
}; | }; | ||||
PETRA.AttackManager.prototype.getPlan = function(planName) | PETRA.AttackManager.prototype.getPlan = function(planName) | ||||
{ | { | ||||
for (let attackType in this.upcomingAttacks) | for (let attackType in this.upcomingAttacks) | ||||
{ | { | ||||
for (let attack of this.upcomingAttacks[attackType]) | for (let attack of this.upcomingAttacks[attackType]) | ||||
▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | while (army.ownEntities.length > 0) | ||||
let unitId = army.ownEntities[0]; | let unitId = army.ownEntities[0]; | ||||
army.removeOwn(gameState, unitId); | army.removeOwn(gameState, unitId); | ||||
let unit = gameState.getEntityById(unitId); | let unit = gameState.getEntityById(unitId); | ||||
let accessOk = unit.getMetadata(PlayerID, "transport") !== undefined || | let accessOk = unit.getMetadata(PlayerID, "transport") !== undefined || | ||||
unit.position() && PETRA.getLandAccess(gameState, unit) == targetAccess; | unit.position() && PETRA.getLandAccess(gameState, unit) == targetAccess; | ||||
if (unit && accessOk && attackPlan.isAvailableUnit(gameState, unit)) | if (unit && accessOk && attackPlan.isAvailableUnit(gameState, unit)) | ||||
{ | { | ||||
unit.setMetadata(PlayerID, "plan", attackPlan.name); | unit.setMetadata(PlayerID, "plan", attackPlan.name); | ||||
unit.setMetadata(PlayerID, "role", "attack"); | unit.setMetadata(PlayerID, "role", PETRA.Worker.ROLE_ATTACK); | ||||
attackPlan.unitCollection.updateEnt(unit); | attackPlan.unitCollection.updateEnt(unit); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!attackPlan.unitCollection.hasEntities()) | if (!attackPlan.unitCollection.hasEntities()) | ||||
{ | { | ||||
attackPlan.Abort(gameState); | attackPlan.Abort(gameState); | ||||
return false; | return false; | ||||
} | } | ||||
for (let unit of attackPlan.unitCollection.values()) | for (let unit of attackPlan.unitCollection.values()) | ||||
unit.setMetadata(PlayerID, "role", "attack"); | unit.setMetadata(PlayerID, "role", PETRA.Worker.ROLE_ATTACK); | ||||
attackPlan.targetPlayer = target.owner(); | attackPlan.targetPlayer = target.owner(); | ||||
attackPlan.targetPos = pos; | attackPlan.targetPos = pos; | ||||
attackPlan.target = target; | attackPlan.target = target; | ||||
attackPlan.state = "arrived"; | attackPlan.state = "arrived"; | ||||
return true; | return true; | ||||
}; | }; | ||||
PETRA.AttackManager.prototype.Serialize = function() | PETRA.AttackManager.prototype.Serialize = function() | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator