Differential D2150 Diff 17818 ps/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Assign the starting entities to the different bases | * Assign the starting entities to the different bases | ||||
*/ | */ | ||||
PETRA.HQ.prototype.assignStartingEntities = function(gameState) | PETRA.HQ.prototype.assignStartingEntities = function(gameState) | ||||
{ | { | ||||
for (let ent of gameState.getOwnEntities().values()) | for (let ent of gameState.getOwnEntities().values()) | ||||
{ | { | ||||
// do not affect merchant ship immediately to trade as they may-be useful for transport | // do not affect merchant ship immediately to trade as they may-be useful for transport | ||||
if (ent.hasClass("Trader") && !ent.hasClass("Ship")) | if (ent.hasClasses(["Trader+!Ship"])) | ||||
this.tradeManager.assignTrader(ent); | this.tradeManager.assignTrader(ent); | ||||
let pos = ent.position(); | let pos = ent.position(); | ||||
if (!pos) | if (!pos) | ||||
{ | { | ||||
// TODO should support recursive garrisoning. Make a warning for now | // TODO should support recursive garrisoning. Make a warning for now | ||||
if (ent.isGarrisonHolder() && ent.garrisoned().length) | if (ent.isGarrisonHolder() && ent.garrisoned().length) | ||||
API3.warn("Petra warning: support for garrisoned units inside garrisoned holders not yet implemented"); | API3.warn("Petra warning: support for garrisoned units inside garrisoned holders not yet implemented"); | ||||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | PETRA.HQ.prototype.dispatchUnits = function(gameState) | ||||
{ | { | ||||
if (this.Config.debug > 1) | if (this.Config.debug > 1) | ||||
API3.warn(" We have allied cc " + allycc.length + " and " + gameState.getOwnUnits().length + " units "); | API3.warn(" We have allied cc " + allycc.length + " and " + gameState.getOwnUnits().length + " units "); | ||||
let units = gameState.getOwnUnits(); | let units = gameState.getOwnUnits(); | ||||
let num = Math.max(Math.min(Math.round(0.08*(1+this.Config.personality.cooperative)*units.length), 20), 5); | let num = Math.max(Math.min(Math.round(0.08*(1+this.Config.personality.cooperative)*units.length), 20), 5); | ||||
let num1 = Math.floor(num / 2); | let num1 = Math.floor(num / 2); | ||||
let num2 = num1; | let num2 = num1; | ||||
// first pass to affect ranged infantry | // first pass to affect ranged infantry | ||||
units.filter(API3.Filters.byClassesAnd(["Infantry", "Ranged"])).forEach(ent => { | units.filter(API3.Filters.byClasses(["Infantry+Ranged"])).forEach(ent => { | ||||
if (!num || !num1) | if (!num || !num1) | ||||
return; | return; | ||||
if (ent.getMetadata(PlayerID, "allied")) | if (ent.getMetadata(PlayerID, "allied")) | ||||
return; | return; | ||||
let access = PETRA.getLandAccess(gameState, ent); | let access = PETRA.getLandAccess(gameState, ent); | ||||
for (let cc of allycc) | for (let cc of allycc) | ||||
{ | { | ||||
if (!cc.position() || PETRA.getLandAccess(gameState, cc) != access) | if (!cc.position() || PETRA.getLandAccess(gameState, cc) != access) | ||||
continue; | continue; | ||||
--num; | --num; | ||||
--num1; | --num1; | ||||
ent.setMetadata(PlayerID, "allied", true); | ent.setMetadata(PlayerID, "allied", true); | ||||
let range = 1.5 * cc.footprintRadius(); | let range = 1.5 * cc.footprintRadius(); | ||||
ent.moveToRange(cc.position()[0], cc.position()[1], range, range + 5); | ent.moveToRange(cc.position()[0], cc.position()[1], range, range + 5); | ||||
break; | break; | ||||
} | } | ||||
}); | }); | ||||
// second pass to affect melee infantry | // second pass to affect melee infantry | ||||
units.filter(API3.Filters.byClassesAnd(["Infantry", "Melee"])).forEach(ent => { | units.filter(API3.Filters.byClasses(["Infantry+Melee"])).forEach(ent => { | ||||
if (!num || !num2) | if (!num || !num2) | ||||
return; | return; | ||||
if (ent.getMetadata(PlayerID, "allied")) | if (ent.getMetadata(PlayerID, "allied")) | ||||
return; | return; | ||||
let access = PETRA.getLandAccess(gameState, ent); | let access = PETRA.getLandAccess(gameState, ent); | ||||
for (let cc of allycc) | for (let cc of allycc) | ||||
{ | { | ||||
if (!cc.position() || PETRA.getLandAccess(gameState, cc) != access) | if (!cc.position() || PETRA.getLandAccess(gameState, cc) != access) | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator