Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/baseManager.js
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | for (let type in this.dropsiteSupplies) | ||||
removeSupply(ent.id(), this.dropsiteSupplies[type].medium); | removeSupply(ent.id(), this.dropsiteSupplies[type].medium); | ||||
removeSupply(ent.id(), this.dropsiteSupplies[type].faraway); | removeSupply(ent.id(), this.dropsiteSupplies[type].faraway); | ||||
} | } | ||||
this.dropsites[ent.id()] = undefined; | this.dropsites[ent.id()] = undefined; | ||||
}; | }; | ||||
/** | /** | ||||
* Returns the position of the best place to build a new dropsite for the specified resource | * @return {Object} - The position of the best place to build a new dropsite for the specified resource, | ||||
* its quality and its template name. | |||||
wraitii: I'm unclear what "its value" is here? You mean the estimated value of the position? | |||||
Done Inline ActionsYeah, should be quality. Freagarach: Yeah, should be `quality`. | |||||
*/ | */ | ||||
Done Inline Actionstypo > available wraitii: typo > available | |||||
Done Inline Actionswhy dont do it here now? Silier: why dont do it here now? | |||||
Done Inline ActionsBecause it needs the currently available templates? (D3879) Freagarach: Because it needs the currently available templates? (D3879) | |||||
Done Inline Actionsyou mean something like this Silier: you mean something like this
PETRA.BuildManager.prototype.findStructureWithClass ? | |||||
Done Inline Actions
Nice :) Obviously I'm just a beginner in AI modding ^^' Would you prefer that ^ over my other diff? Freagarach: > PETRA.BuildManager.prototype.findStructureWithClass ?
Nice :) Obviously I'm just a beginner… | |||||
PETRA.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource) | PETRA.BaseManager.prototype.findBestDropsiteAndLocation = function(gameState, resource) | ||||
{ | { | ||||
let result; | |||||
let bestQuality = 0; | |||||
for (let templateName of gameState.ai.HQ.buildManager.findStructuresByFilter(gameState, API3.Filters.isDropsite(resource))) | |||||
{ | |||||
Done Inline Actionsnot needed line Silier: not needed line | |||||
let dp = this.findBestDropsiteLocation(gameState, resource, templateName); | |||||
if (dp.quality < bestQuality) | |||||
continue; | |||||
bestQuality = dp.quality; | |||||
result = dp; | |||||
result.template = templateName; | |||||
} | |||||
return result; | |||||
}; | |||||
/** | |||||
* Returns the position of the best place to build a new dropsite for the specified resource and dropsite template. | |||||
*/ | |||||
PETRA.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource, templateName) | |||||
{ | |||||
let template = gameState.getTemplate(gameState.applyCiv(templateName)); | |||||
// CCs and Docks are handled elsewhere. | |||||
if (template.hasClass("CivCentre") || template.hasClass("Dock")) | |||||
return { "quality": 0, "pos": [0, 0] }; | |||||
Done Inline Actionsdoes it cover colonies and superdocs ? Silier: does it cover colonies and superdocs ? | |||||
Done Inline ActionsAye. Freagarach: Aye. | |||||
let template = gameState.getTemplate(gameState.applyCiv("structures/{civ}/storehouse")); | |||||
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"); | ||||
// This builds a map. The procedure is fairly simple. It adds the resource maps | // This builds a map. The procedure is fairly simple. It adds the resource maps | ||||
// (which are dynamically updated and are made so that they will facilitate DP placement) | // (which are dynamically updated and are made so that they will facilitate DP placement) | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | for (let type of Resources.GetCodes()) | ||||
} | } | ||||
// TODO add also a test on remaining resources. | // TODO add also a test on remaining resources. | ||||
let total = this.gatherers[type].used + this.gatherers[type].lost; | let total = this.gatherers[type].used + this.gatherers[type].lost; | ||||
if (total > 150 || total > 60 && type != "wood") | if (total > 150 || total > 60 && type != "wood") | ||||
{ | { | ||||
let ratio = this.gatherers[type].lost / total; | let ratio = this.gatherers[type].lost / total; | ||||
if (ratio > 0.15) | if (ratio > 0.15) | ||||
{ | { | ||||
let newDP = this.findBestDropsiteLocation(gameState, type); | let newDP = this.findBestDropsiteAndLocation(gameState, type); | ||||
if (newDP.quality > 50 && gameState.ai.HQ.canBuild(gameState, "structures/{civ}/storehouse")) | if (newDP.quality > 50 && gameState.ai.HQ.canBuild(gameState, newDP.template)) | ||||
queues.dropsites.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/storehouse", { "base": this.ID, "type": type }, newDP.pos)); | queues.dropsites.addPlan(new PETRA.ConstructionPlan(gameState, newDP.template, { "base": this.ID, "type": type }, newDP.pos)); | ||||
Not Done Inline ActionsFeel like a good spot to use structured bindings over a dictionary. wraitii: Feel like a good spot to use structured bindings over a dictionary. | |||||
Not Done Inline ActionsI'm not sure what you mean here? Freagarach: I'm not sure what you mean here? | |||||
Not Done Inline ActionsRight in JS it's called 'Restructuring assignment': https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment So it would go let [template, pos] = this.findBestDropsiteAndLocation(gameState, type) wraitii: Right in JS it's called 'Restructuring assignment': https://developer.mozilla.org/en… | |||||
else if (!gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() && !queues.civilCentre.hasQueuedUnits()) | else if (!gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() && !queues.civilCentre.hasQueuedUnits()) | ||||
{ | { | ||||
// No good dropsite, try to build a new base if no base already planned, | // No good dropsite, try to build a new base if no base already planned, | ||||
// and if not possible, be less strict on dropsite quality. | // and if not possible, be less strict on dropsite quality. | ||||
if ((!gameState.ai.HQ.canExpand || !gameState.ai.HQ.buildNewBase(gameState, queues, type)) && | if ((!gameState.ai.HQ.canExpand || !gameState.ai.HQ.buildNewBase(gameState, queues, type)) && | ||||
newDP.quality > Math.min(25, 50*0.15/ratio) && | newDP.quality > Math.min(25, 50*0.15/ratio) && | ||||
gameState.ai.HQ.canBuild(gameState, "structures/{civ}/storehouse")) | gameState.ai.HQ.canBuild(gameState, newDP.template)) | ||||
queues.dropsites.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/storehouse", { "base": this.ID, "type": type }, newDP.pos)); | queues.dropsites.addPlan(new PETRA.ConstructionPlan(gameState, newDP.template, { "base": this.ID, "type": type }, newDP.pos)); | ||||
} | } | ||||
} | } | ||||
this.gatherers[type].nextCheck = gameState.ai.playedTurn + 20; | this.gatherers[type].nextCheck = gameState.ai.playedTurn + 20; | ||||
this.gatherers[type].used = 0; | this.gatherers[type].used = 0; | ||||
this.gatherers[type].lost = 0; | this.gatherers[type].lost = 0; | ||||
} | } | ||||
else if (total == 0) | else if (total == 0) | ||||
this.gatherers[type].nextCheck = gameState.ai.playedTurn + 10; | this.gatherers[type].nextCheck = gameState.ai.playedTurn + 10; | ||||
▲ Show 20 Lines • Show All 630 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I'm unclear what "its value" is here? You mean the estimated value of the position?