Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
Show First 20 Lines • Show All 462 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
// must be called every turn for all armies | // must be called every turn for all armies | ||||
for (let army of this.armies) | for (let army of this.armies) | ||||
army.checkEvents(gameState, events); | army.checkEvents(gameState, events); | ||||
for (let evt of events.Attacked) | for (let evt of events.Attacked) | ||||
{ | { | ||||
let target = gameState.getEntityById(evt.target); | let target = gameState.getEntityById(evt.target); | ||||
if (!target || !gameState.isEntityOwn(target) || !target.position()) | if (!target || !target.position()) | ||||
continue; | continue; | ||||
// If attacked by one of our allies (he must trying to recover capture points), do not react | |||||
let attacker = gameState.getEntityById(evt.attacker); | let attacker = gameState.getEntityById(evt.attacker); | ||||
if (attacker && gameState.isEntityOwn(attacker) && gameState.isEntityEnemy(target) && !attacker.hasClass("Ship")) | |||||
{ | |||||
// If enemies are in range of one of our defensive structures, garrison it for arrow multiplier | |||||
if (attacker.position() && attacker.isGarrisonHolder() && attacker.getArrowMultiplier()) | |||||
this.garrisonRangedUnitsInside(gameState, attacker, {"attacker": target}); | |||||
} | |||||
if (!gameState.isEntityOwn(target)) | |||||
continue; | |||||
// If attacked by one of our allies (he must trying to recover capture points), do not react | |||||
if (attacker && gameState.isEntityAlly(attacker)) | if (attacker && gameState.isEntityAlly(attacker)) | ||||
continue; | continue; | ||||
if (target.hasClass("Ship")) // TODO integrate ships later need to be sure it is accessible | if (target.hasClass("Ship")) // TODO integrate ships later need to be sure it is accessible | ||||
continue; | continue; | ||||
// If inside a started attack plan, let the plan deal with this unit | // If inside a started attack plan, let the plan deal with this unit | ||||
let plan = target.getMetadata(PlayerID, "plan"); | let plan = target.getMetadata(PlayerID, "plan"); | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | m.DefenseManager.prototype.garrisonRangedUnitsInside = function(gameState, target, data) | ||||
for (let ent of units.values()) | for (let ent of units.values()) | ||||
{ | { | ||||
if (garrisonManager.numberOfGarrisonedUnits(target) >= minGarrison) | if (garrisonManager.numberOfGarrisonedUnits(target) >= minGarrison) | ||||
break; | break; | ||||
if (!ent.position()) | if (!ent.position()) | ||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "transport") !== undefined) | if (ent.getMetadata(PlayerID, "transport") !== undefined) | ||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "plan") === -2 || ent.getMetadata(PlayerID, "plan") === -3) | 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)) | |||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") !== -1) | if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0) | ||||
{ | { | ||||
let subrole = ent.getMetadata(PlayerID, "subrole"); | let subrole = ent.getMetadata(PlayerID, "subrole"); | ||||
if (subrole && (subrole === "completing" || subrole === "walking" || subrole === "attacking")) | // 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")) | |||||
continue; | continue; | ||||
} | } | ||||
if (gameState.ai.accessibility.getAccessValue(ent.position()) !== index) | if (gameState.ai.accessibility.getAccessValue(ent.position()) !== index) | ||||
continue; | continue; | ||||
if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") >= 0) | |||||
{ | |||||
let attackPlan = gameState.ai.HQ.attackManager.getPlan(ent.getMetadata(PlayerID, "plan")); | |||||
if (attackPlan) | |||||
attackPlan.removeUnit(ent, true); | |||||
} | |||||
if (army) | |||||
army.removeOwn(gameState, ent.id()); | |||||
garrisonManager.garrison(gameState, ent, target, typeGarrison); | garrisonManager.garrison(gameState, ent, target, typeGarrison); | ||||
} | } | ||||
}; | }; | ||||
/** garrison a attacked siege ranged unit inside the nearest fortress */ | /** garrison a attacked siege ranged unit inside the nearest fortress */ | ||||
m.DefenseManager.prototype.garrisonSiegeUnit = function(gameState, unit) | m.DefenseManager.prototype.garrisonSiegeUnit = function(gameState, unit) | ||||
{ | { | ||||
let distmin = Math.min(); | let distmin = Math.min(); | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator