Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/baseManager.js
Show First 20 Lines • Show All 505 Lines • ▼ Show 20 Lines | |||||
m.BaseManager.prototype.assignRolelessUnits = function(gameState, roleless) | m.BaseManager.prototype.assignRolelessUnits = function(gameState, roleless) | ||||
{ | { | ||||
if (!roleless) | if (!roleless) | ||||
roleless = this.units.filter(API3.Filters.not(API3.Filters.byHasMetadata(PlayerID, "role"))).values(); | roleless = this.units.filter(API3.Filters.not(API3.Filters.byHasMetadata(PlayerID, "role"))).values(); | ||||
for (let ent of roleless) | for (let ent of roleless) | ||||
{ | { | ||||
if (ent.hasClass("Worker") || ent.hasClass("CitizenSoldier") || ent.hasClass("FishingBoat")) | if (MatchesClassList(ent.classes(), ["Worker", "CitizenSoldier", "FishingBoat", ["Support+Elephant"]])) | ||||
ent.setMetadata(PlayerID, "role", "worker"); | |||||
else if (ent.hasClass("Support") && ent.hasClass("Elephant")) | |||||
ent.setMetadata(PlayerID, "role", "worker"); | ent.setMetadata(PlayerID, "role", "worker"); | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* If the numbers of workers on the resources is unbalanced then set some of workers to idle so | * If the numbers of workers on the resources is unbalanced then set some of workers to idle so | ||||
* they can be reassigned by reassignIdleWorkers. | * they can be reassigned by reassignIdleWorkers. | ||||
* TODO: actually this probably should be in the HQ. | * TODO: actually this probably should be in the HQ. | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | m.BaseManager.prototype.reassignIdleWorkers = function(gameState, idleWorkers) | ||||
} | } | ||||
for (let ent of idleWorkers) | for (let ent of idleWorkers) | ||||
{ | { | ||||
// Check that the worker isn't garrisoned | // Check that the worker isn't garrisoned | ||||
if (!ent.position()) | if (!ent.position()) | ||||
continue; | continue; | ||||
// Support elephant can only be builders | // Support elephant can only be builders | ||||
if (ent.hasClass("Support") && ent.hasClass("Elephant")) | if (MatchesClassList(ent.classes(), ["Elephant+Worker"])) | ||||
{ | { | ||||
ent.setMetadata(PlayerID, "subrole", "idle"); | ent.setMetadata(PlayerID, "subrole", "idle"); | ||||
continue; | continue; | ||||
} | } | ||||
if (ent.hasClass("Worker")) | if (ent.hasClass("Worker")) | ||||
{ | { | ||||
// Just emergency repairing here. It is better managed in assignToFoundations | // Just emergency repairing here. It is better managed in assignToFoundations | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair) | ||||
} | } | ||||
for (let target of foundations.values()) | for (let target of foundations.values()) | ||||
{ | { | ||||
if (target.hasClass("Field")) | if (target.hasClass("Field")) | ||||
continue; // we do not build fields | continue; // we do not build fields | ||||
if (gameState.ai.HQ.isNearInvadingArmy(target.position())) | if (gameState.ai.HQ.isNearInvadingArmy(target.position())) | ||||
if (!target.hasClass("CivCentre") && !target.hasClass("StoneWall") && | if (MatchesClassList(target.classes(), ["!CivCentre+!StoneWall"]) && | ||||
(!target.hasClass("Wonder") || !gameState.getVictoryConditions().has("wonder"))) | (!target.hasClass("Wonder") || !gameState.getVictoryConditions().has("wonder"))) | ||||
continue; | continue; | ||||
// if our territory has shrinked since this foundation was positioned, do not build it | // if our territory has shrinked since this foundation was positioned, do not build it | ||||
if (m.isNotWorthBuilding(gameState, target)) | if (m.isNotWorthBuilding(gameState, target)) | ||||
continue; | continue; | ||||
let assigned = gameState.getOwnEntitiesByMetadata("target-foundation", target.id()).length; | let assigned = gameState.getOwnEntitiesByMetadata("target-foundation", target.id()).length; | ||||
let maxTotalBuilders = Math.ceil(workers.length * builderRatio); | let maxTotalBuilders = Math.ceil(workers.length * builderRatio); | ||||
if (maxTotalBuilders < 2 && workers.length > 1) | if (maxTotalBuilders < 2 && workers.length > 1) | ||||
maxTotalBuilders = 2; | maxTotalBuilders = 2; | ||||
if (target.hasClass("House") && gameState.getPopulationLimit() < gameState.getPopulation() + 5 && | if (target.hasClass("House") && gameState.getPopulationLimit() < gameState.getPopulation() + 5 && | ||||
gameState.getPopulationLimit() < gameState.getPopulationMax()) | gameState.getPopulationLimit() < gameState.getPopulationMax()) | ||||
maxTotalBuilders += 2; | maxTotalBuilders += 2; | ||||
let targetNB = 2; | let targetNB = 2; | ||||
if (target.hasClass("Fortress") || target.hasClass("Wonder") || | if (MatchesClassList(target.classes(), ["Fortress", "Wonder"]) || | ||||
target.getMetadata(PlayerID, "phaseUp") == true) | target.getMetadata(PlayerID, "phaseUp") == true) | ||||
targetNB = 7; | targetNB = 7; | ||||
else if (target.hasClass("Barracks") || target.hasClass("Range") || target.hasClass("Stable") || | else if (MatchesClassList(target.classes(), ["Barracks", "Range", "Stable", "DefenseTower", "Market"])) | ||||
target.hasClass("DefenseTower") || target.hasClass("Market")) | |||||
targetNB = 4; | targetNB = 4; | ||||
else if (target.hasClass("House") || target.hasClass("DropsiteWood")) | else if (MatchesClassList(target.classes(), ["House", "DropsiteWood"])) | ||||
targetNB = 3; | targetNB = 3; | ||||
if (target.getMetadata(PlayerID, "baseAnchor") == true || | if (target.getMetadata(PlayerID, "baseAnchor") == true || | ||||
target.hasClass("Wonder") && gameState.getVictoryConditions().has("wonder")) | target.hasClass("Wonder") && gameState.getVictoryConditions().has("wonder")) | ||||
{ | { | ||||
targetNB = 15; | targetNB = 15; | ||||
maxTotalBuilders = Math.max(maxTotalBuilders, 15); | maxTotalBuilders = Math.max(maxTotalBuilders, 15); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | m.BaseManager.prototype.assignToFoundations = function(gameState, noRepair) | ||||
for (let target of damagedBuildings.values()) | for (let target of damagedBuildings.values()) | ||||
{ | { | ||||
// Don't repair if we're still under attack, unless it's a vital (civcentre or wall) building | // Don't repair if we're still under attack, unless it's a vital (civcentre or wall) building | ||||
// that's being destroyed. | // that's being destroyed. | ||||
if (gameState.ai.HQ.isNearInvadingArmy(target.position())) | if (gameState.ai.HQ.isNearInvadingArmy(target.position())) | ||||
{ | { | ||||
if (target.healthLevel() > 0.5 || | if (target.healthLevel() > 0.5 || | ||||
!target.hasClass("CivCentre") && !target.hasClass("StoneWall") && | MatchesClassList(target.classes(), ["!CivCentre+!StoneWall"]) && | ||||
(!target.hasClass("Wonder") || !gameState.getVictoryConditions().has("wonder"))) | (!target.hasClass("Wonder") || !gameState.getVictoryConditions().has("wonder"))) | ||||
continue; | continue; | ||||
} | } | ||||
else if (noRepair && !target.hasClass("CivCentre")) | else if (noRepair && !target.hasClass("CivCentre")) | ||||
continue; | continue; | ||||
if (target.decaying()) | if (target.decaying()) | ||||
continue; | continue; | ||||
let assigned = gameState.getOwnEntitiesByMetadata("target-foundation", target.id()).length; | let assigned = gameState.getOwnEntitiesByMetadata("target-foundation", target.id()).length; | ||||
let maxTotalBuilders = Math.ceil(workers.length * builderRatio); | let maxTotalBuilders = Math.ceil(workers.length * builderRatio); | ||||
let targetNB = 1; | let targetNB = 1; | ||||
if (target.hasClass("Fortress") || target.hasClass("Wonder")) | if (MatchesClassList(target.classes(), ["Fortress", "Wonder"])) | ||||
targetNB = 3; | targetNB = 3; | ||||
if (target.getMetadata(PlayerID, "baseAnchor") == true || | if (target.getMetadata(PlayerID, "baseAnchor") == true || | ||||
target.hasClass("Wonder") && gameState.getVictoryConditions().has("wonder")) | target.hasClass("Wonder") && gameState.getVictoryConditions().has("wonder")) | ||||
{ | { | ||||
maxTotalBuilders = Math.ceil(workers.length * Math.max(0.3, builderRatio)); | maxTotalBuilders = Math.ceil(workers.length * Math.max(0.3, builderRatio)); | ||||
targetNB = 5; | targetNB = 5; | ||||
if (target.healthLevel() < 0.3) | if (target.healthLevel() < 0.3) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator