Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 896 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Pick the resource which most needs another worker | * Pick the resource which most needs another worker | ||||
* How this works: | * How this works: | ||||
* We get the rates we would want to have to be able to deal with our plans | * We get the rates we would want to have to be able to deal with our plans | ||||
* We get our current rates | * We get our current rates | ||||
* We compare; we pick the one where the discrepancy is highest. | * We compare; we pick the one where the discrepancy is highest. | ||||
* Need to balance long-term needs and possible short-term needs. | * Need to balance long-term needs and possible short-term needs. | ||||
*/ | */ | ||||
m.HQ.prototype.pickMostNeededResources = function(gameState) | m.HQ.prototype.pickMostNeededResources = function(gameState, property = undefined) | ||||
{ | { | ||||
let wantedRates = this.GetWantedGatherRates(gameState); | let wantedRates = this.GetWantedGatherRates(gameState); | ||||
let currentRates = this.GetCurrentGatherRates(gameState); | let currentRates = this.GetCurrentGatherRates(gameState); | ||||
let resCodes = Resources.GetCodes(property); | |||||
let needed = []; | let needed = []; | ||||
for (let res in wantedRates) | for (let res of resCodes) | ||||
needed.push({ "type": res, "wanted": wantedRates[res], "current": currentRates[res] }); | needed.push({ "type": res, "wanted": wantedRates[res], "current": currentRates[res] }); | ||||
needed.sort((a, b) => { | needed.sort((a, b) => { | ||||
if (a.current < a.wanted && b.current < b.wanted) | if (a.current < a.wanted && b.current < b.wanted) | ||||
{ | { | ||||
if (a.current && b.current) | if (a.current && b.current) | ||||
return b.wanted / b.current - a.wanted / a.current; | return b.wanted / b.current - a.wanted / a.current; | ||||
if (a.current) | if (a.current) | ||||
▲ Show 20 Lines • Show All 365 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
let markets = gameState.updatingCollection("diplo-ExclusiveAllyMarkets", API3.Filters.byClass("Market"), gameState.getExclusiveAllyEntities()).toEntityArray(); | let markets = gameState.updatingCollection("diplo-ExclusiveAllyMarkets", API3.Filters.byClass("Market"), gameState.getExclusiveAllyEntities()).toEntityArray(); | ||||
if (!markets.length) | if (!markets.length) | ||||
markets = gameState.updatingCollection("OwnMarkets", API3.Filters.byClass("Market"), gameState.getOwnStructures()).toEntityArray(); | markets = gameState.updatingCollection("OwnMarkets", API3.Filters.byClass("Market"), gameState.getOwnStructures()).toEntityArray(); | ||||
if (!markets.length) // this is the first market. For the time being, place it arbitrarily by the ConstructionPlan | if (!markets.length) // this is the first market. For the time being, place it arbitrarily by the ConstructionPlan | ||||
return [-1, -1, -1, 0]; | return [-1, -1, -1, 0]; | ||||
// No need for more than one market when we cannot trade. | |||||
if (!Resources.GetCodes("tradable").length) | |||||
return false; | |||||
// obstruction map | // obstruction map | ||||
let obstructions = m.createObstructionMap(gameState, 0, template); | let obstructions = m.createObstructionMap(gameState, 0, template); | ||||
let halfSize = 0; | let halfSize = 0; | ||||
if (template.get("Footprint/Square")) | if (template.get("Footprint/Square")) | ||||
halfSize = Math.max(+template.get("Footprint/Square/@depth"), +template.get("Footprint/Square/@width")) / 2; | halfSize = Math.max(+template.get("Footprint/Square/@depth"), +template.get("Footprint/Square/@width")) / 2; | ||||
else if (template.get("Footprint/Circle")) | else if (template.get("Footprint/Circle")) | ||||
halfSize = +template.get("Footprint/Circle/@radius"); | halfSize = +template.get("Footprint/Circle/@radius"); | ||||
▲ Show 20 Lines • Show All 1,596 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator