Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
Show All 26 Lines | PETRA.AttackPlan = function(gameState, Config, uniqueID, type, data) | ||||
} | } | ||||
this.uniqueTargetId = data && data.uniqueTargetId || undefined; | this.uniqueTargetId = data && data.uniqueTargetId || undefined; | ||||
// get a starting rallyPoint ... will be improved later | // get a starting rallyPoint ... will be improved later | ||||
let rallyPoint; | let rallyPoint; | ||||
let rallyAccess; | let rallyAccess; | ||||
let allAccesses = {}; | let allAccesses = {}; | ||||
for (let base of gameState.ai.HQ.baseManagers) | for (const base of gameState.ai.HQ.baseManagers()) | ||||
{ | { | ||||
if (!base.anchor || !base.anchor.position()) | if (!base.anchor || !base.anchor.position()) | ||||
continue; | continue; | ||||
let access = PETRA.getLandAccess(gameState, base.anchor); | let access = PETRA.getLandAccess(gameState, base.anchor); | ||||
if (!rallyPoint) | if (!rallyPoint) | ||||
{ | { | ||||
rallyPoint = base.anchor.position(); | rallyPoint = base.anchor.position(); | ||||
rallyAccess = access; | rallyAccess = access; | ||||
▲ Show 20 Lines • Show All 767 Lines • ▼ Show 20 Lines | PETRA.AttackPlan.prototype.chooseTarget = function(gameState) | ||||
let targetIndex = PETRA.getLandAccess(gameState, this.target); | let targetIndex = PETRA.getLandAccess(gameState, this.target); | ||||
let rallyIndex = gameState.ai.accessibility.getAccessValue(this.rallyPoint); | let rallyIndex = gameState.ai.accessibility.getAccessValue(this.rallyPoint); | ||||
if (targetIndex != rallyIndex) | if (targetIndex != rallyIndex) | ||||
{ | { | ||||
let distminSame = Math.min(); | let distminSame = Math.min(); | ||||
let rallySame; | let rallySame; | ||||
let distminDiff = Math.min(); | let distminDiff = Math.min(); | ||||
let rallyDiff; | let rallyDiff; | ||||
for (let base of gameState.ai.HQ.baseManagers) | for (const base of gameState.ai.HQ.baseManagers()) | ||||
{ | { | ||||
let anchor = base.anchor; | let anchor = base.anchor; | ||||
if (!anchor || !anchor.position()) | if (!anchor || !anchor.position()) | ||||
continue; | continue; | ||||
let dist = API3.SquareVectorDistance(anchor.position(), this.targetPos); | let dist = API3.SquareVectorDistance(anchor.position(), this.targetPos); | ||||
if (base.accessIndex == targetIndex) | if (base.accessIndex == targetIndex) | ||||
{ | { | ||||
if (dist >= distminSame) | if (dist >= distminSame) | ||||
▲ Show 20 Lines • Show All 1,168 Lines • ▼ Show 20 Lines | if (this.isStarted()) | ||||
let access = this.getAttackAccess(gameState); | let access = this.getAttackAccess(gameState); | ||||
let dist = Math.min(); | let dist = Math.min(); | ||||
if (this.rallyPoint && gameState.ai.accessibility.getAccessValue(this.rallyPoint) == access) | if (this.rallyPoint && gameState.ai.accessibility.getAccessValue(this.rallyPoint) == access) | ||||
{ | { | ||||
rallyPoint = this.rallyPoint; | rallyPoint = this.rallyPoint; | ||||
dist = API3.SquareVectorDistance(this.position, rallyPoint); | dist = API3.SquareVectorDistance(this.position, rallyPoint); | ||||
} | } | ||||
// Then check if we have a nearer base (in case this attack has captured one) | // Then check if we have a nearer base (in case this attack has captured one) | ||||
for (let base of gameState.ai.HQ.baseManagers) | for (const base of gameState.ai.HQ.baseManagers()) | ||||
{ | { | ||||
if (!base.anchor || !base.anchor.position()) | if (!base.anchor || !base.anchor.position()) | ||||
continue; | continue; | ||||
if (PETRA.getLandAccess(gameState, base.anchor) != access) | if (PETRA.getLandAccess(gameState, base.anchor) != access) | ||||
continue; | continue; | ||||
let newdist = API3.SquareVectorDistance(this.position, base.anchor.position()); | let newdist = API3.SquareVectorDistance(this.position, base.anchor.position()); | ||||
if (newdist > dist) | if (newdist > dist) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | PETRA.AttackPlan.prototype.checkEvents = function(gameState, events) | ||||
for (let evt of events.Create) | for (let evt of events.Create) | ||||
{ | { | ||||
let ent = gameState.getEntityById(evt.entity); | let ent = gameState.getEntityById(evt.entity); | ||||
if (!ent || !ent.position() || !ent.hasClass("Structure")) | if (!ent || !ent.position() || !ent.hasClass("Structure")) | ||||
continue; | continue; | ||||
if (!gameState.isPlayerEnemy(ent.owner())) | if (!gameState.isPlayerEnemy(ent.owner())) | ||||
continue; | continue; | ||||
let access = PETRA.getLandAccess(gameState, ent); | let access = PETRA.getLandAccess(gameState, ent); | ||||
for (let base of gameState.ai.HQ.baseManagers) | for (const base of gameState.ai.HQ.baseManagers()) | ||||
{ | { | ||||
if (!base.anchor || !base.anchor.position()) | if (!base.anchor || !base.anchor.position()) | ||||
continue; | continue; | ||||
if (base.accessIndex != access) | if (base.accessIndex != access) | ||||
continue; | continue; | ||||
this.overseas = 0; | this.overseas = 0; | ||||
this.rallyPoint = base.anchor.position(); | this.rallyPoint = base.anchor.position(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator