Differential D4192 Diff 18509 ps/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | PETRA.returnResources = function(gameState, ent) | ||||
ent.returnResources(closestDropsite); | ent.returnResources(closestDropsite); | ||||
return true; | return true; | ||||
}; | }; | ||||
/** is supply full taking into account gatherers affected during this turn */ | /** is supply full taking into account gatherers affected during this turn */ | ||||
PETRA.IsSupplyFull = function(gameState, ent) | PETRA.IsSupplyFull = function(gameState, ent) | ||||
{ | { | ||||
return ent.isFull() === true || | return ent.isFull() === true || | ||||
ent.resourceSupplyNumGatherers() + gameState.ai.HQ.GetTCGatherer(ent.id()) >= ent.maxGatherers(); | ent.resourceSupplyNumGatherers() + gameState.ai.HQ.basesManager.GetTCGatherer(ent.id()) >= ent.maxGatherers(); | ||||
}; | }; | ||||
/** | /** | ||||
* Get the best base (in terms of distance and accessIndex) for an entity. | * Get the best base (in terms of distance and accessIndex) for an entity. | ||||
* It should be on the same accessIndex for structures. | * It should be on the same accessIndex for structures. | ||||
* If nothing found, return the base[0] for units and undefined for structures. | * If nothing found, return the noBase for units and undefined for structures. | ||||
* If exclude is given, we exclude the base with ID = exclude. | * If exclude is given, we exclude the base with ID = exclude. | ||||
*/ | */ | ||||
PETRA.getBestBase = function(gameState, ent, onlyConstructedBase = false, exclude = false) | PETRA.getBestBase = function(gameState, ent, onlyConstructedBase = false, exclude = false) | ||||
{ | { | ||||
let pos = ent.position(); | let pos = ent.position(); | ||||
let accessIndex; | let accessIndex; | ||||
if (!pos) | if (!pos) | ||||
{ | { | ||||
let holder = PETRA.getHolder(gameState, ent); | let holder = PETRA.getHolder(gameState, ent); | ||||
if (!holder || !holder.position()) | if (!holder || !holder.position()) | ||||
{ | { | ||||
API3.warn("Petra error: entity without position, but not garrisoned"); | API3.warn("Petra error: entity without position, but not garrisoned"); | ||||
PETRA.dumpEntity(ent); | PETRA.dumpEntity(ent); | ||||
return gameState.ai.HQ.baseManagers[0]; | return gameState.ai.HQ.basesManager.baselessBase(); | ||||
} | } | ||||
pos = holder.position(); | pos = holder.position(); | ||||
accessIndex = PETRA.getLandAccess(gameState, holder); | accessIndex = PETRA.getLandAccess(gameState, holder); | ||||
} | } | ||||
else | else | ||||
accessIndex = PETRA.getLandAccess(gameState, ent); | accessIndex = PETRA.getLandAccess(gameState, ent); | ||||
let distmin = Math.min(); | let distmin = Math.min(); | ||||
let dist; | let dist; | ||||
let bestbase; | let bestbase; | ||||
for (let base of gameState.ai.HQ.baseManagers) | for (const base of gameState.ai.HQ.baseManagers()) | ||||
{ | { | ||||
if (base.ID == gameState.ai.HQ.baseManagers[0].ID || exclude && base.ID == exclude) | if (base.ID == gameState.ai.HQ.basesManager.baselessBase().ID || exclude && base.ID == exclude) | ||||
continue; | continue; | ||||
if (onlyConstructedBase && (!base.anchor || base.anchor.foundationProgress() !== undefined)) | if (onlyConstructedBase && (!base.anchor || base.anchor.foundationProgress() !== undefined)) | ||||
continue; | continue; | ||||
if (ent.hasClass("Structure") && base.accessIndex != accessIndex) | if (ent.hasClass("Structure") && base.accessIndex != accessIndex) | ||||
continue; | continue; | ||||
if (base.anchor && base.anchor.position()) | if (base.anchor && base.anchor.position()) | ||||
dist = API3.SquareVectorDistance(base.anchor.position(), pos); | dist = API3.SquareVectorDistance(base.anchor.position(), pos); | ||||
else | else | ||||
Show All 15 Lines | for (const base of gameState.ai.HQ.baseManagers()) | ||||
if (!base.anchor) | if (!base.anchor) | ||||
dist += 50000000; | dist += 50000000; | ||||
if (dist > distmin) | if (dist > distmin) | ||||
continue; | continue; | ||||
distmin = dist; | distmin = dist; | ||||
bestbase = base; | bestbase = base; | ||||
} | } | ||||
if (!bestbase && !ent.hasClass("Structure")) | if (!bestbase && !ent.hasClass("Structure")) | ||||
bestbase = gameState.ai.HQ.baseManagers[0]; | bestbase = gameState.ai.HQ.basesManager.baselessBase(); | ||||
return bestbase; | return bestbase; | ||||
}; | }; | ||||
PETRA.getHolder = function(gameState, ent) | PETRA.getHolder = function(gameState, ent) | ||||
{ | { | ||||
for (let holder of gameState.getEntities().values()) | for (let holder of gameState.getEntities().values()) | ||||
{ | { | ||||
if (holder.isGarrisonHolder() && holder.garrisoned().indexOf(ent.id()) !== -1) | if (holder.isGarrisonHolder() && holder.garrisoned().indexOf(ent.id()) !== -1) | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator