Differential D2150 Diff 17818 ps/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | if (template.hasClass("CivCentre")) | ||||
if (gameState.ai.HQ.canBuild(gameState, templateName) && !gameState.isTemplateDisabled(templateName)) | if (gameState.ai.HQ.canBuild(gameState, templateName) && !gameState.isTemplateDisabled(templateName)) | ||||
{ | { | ||||
template = gameState.getTemplate(templateName); | template = gameState.getTemplate(templateName); | ||||
if (template && gameState.getResources().canAfford(new API3.Resources(template.cost()))) | if (template && gameState.getResources().canAfford(new API3.Resources(template.cost()))) | ||||
this.buildOverseaDock(gameState, template); | this.buildOverseaDock(gameState, template); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
else if (template.hasClass("Tower") || template.hasClass("Fortress") || template.hasClass("ArmyCamp")) | else if (template.hasClasses(["Tower", "Fortress", "ArmyCamp"])) | ||||
{ | { | ||||
let pos = HQ.findDefensiveLocation(gameState, template); | let pos = HQ.findDefensiveLocation(gameState, template); | ||||
if (pos) | if (pos) | ||||
return { "x": pos[0], "z": pos[1], "angle": 3*Math.PI/4, "base": pos[2] }; | return { "x": pos[0], "z": pos[1], "angle": 3*Math.PI/4, "base": pos[2] }; | ||||
// if this fortress is our first one, just try the standard placement | // if this fortress is our first one, just try the standard placement | ||||
if (!template.hasClass("Fortress") || gameState.getOwnEntitiesByClass("Fortress", true).hasEntities()) | if (!template.hasClass("Fortress") || gameState.getOwnEntitiesByClass("Fortress", true).hasEntities()) | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (!HQ.requireHouses || !template.hasClass("House")) | ||||
gameState.getOwnStructures().forEach(function(ent) { | gameState.getOwnStructures().forEach(function(ent) { | ||||
let pos = ent.position(); | let pos = ent.position(); | ||||
let x = Math.round(pos[0] / cellSize); | let x = Math.round(pos[0] / cellSize); | ||||
let z = Math.round(pos[1] / cellSize); | let z = Math.round(pos[1] / cellSize); | ||||
let struct = PETRA.getBuiltEntity(gameState, ent); | let struct = PETRA.getBuiltEntity(gameState, ent); | ||||
if (struct.resourceDropsiteTypes() && struct.resourceDropsiteTypes().indexOf("food") != -1) | if (struct.resourceDropsiteTypes() && struct.resourceDropsiteTypes().indexOf("food") != -1) | ||||
{ | { | ||||
if (template.hasClass("Field") || template.hasClass("Corral")) | if (template.hasClasses(["Field", "Corral"])) | ||||
placement.addInfluence(x, z, 80 / cellSize, 50); | placement.addInfluence(x, z, 80 / cellSize, 50); | ||||
else // If this is not a field add a negative influence because we want to leave this area for fields | else // If this is not a field add a negative influence because we want to leave this area for fields | ||||
placement.addInfluence(x, z, 80 / cellSize, -20); | placement.addInfluence(x, z, 80 / cellSize, -20); | ||||
} | } | ||||
else if (template.hasClass("House")) | else if (template.hasClass("House")) | ||||
{ | { | ||||
if (ent.hasClass("House")) | if (ent.hasClass("House")) | ||||
{ | { | ||||
placement.addInfluence(x, z, 60 / cellSize, 40); // houses are close to other houses | placement.addInfluence(x, z, 60 / cellSize, 40); // houses are close to other houses | ||||
alreadyHasHouses = true; | alreadyHasHouses = true; | ||||
} | } | ||||
else if (!ent.hasClass("Wall") || ent.hasClass("Gate")) | else if (ent.hasClasses(["Gate", "!Wall"])) | ||||
placement.addInfluence(x, z, 60 / cellSize, -40); // and further away from other stuffs | placement.addInfluence(x, z, 60 / cellSize, -40); // and further away from other stuffs | ||||
} | } | ||||
else if (template.hasClass("Farmstead") && (!ent.hasClass("Field") && !ent.hasClass("Corral") && | else if (template.hasClass("Farmstead") && !ent.hasClasses(["Field", "Corral"]) && | ||||
(!ent.hasClass("Wall") || ent.hasClass("Gate")))) | ent.hasClasses(["Gate", "!Wall"])) | ||||
placement.addInfluence(x, z, 100 / cellSize, -25); // move farmsteads away to make room (Wall test needed for iber) | placement.addInfluence(x, z, 100 / cellSize, -25); // move farmsteads away to make room (Wall test needed for iber) | ||||
else if (template.hasClass("GarrisonFortress") && ent.hasClass("House")) | else if (template.hasClass("GarrisonFortress") && ent.hasClass("House")) | ||||
placement.addInfluence(x, z, 120 / cellSize, -50); | placement.addInfluence(x, z, 120 / cellSize, -50); | ||||
else if (template.hasClass("Military")) | else if (template.hasClass("Military")) | ||||
placement.addInfluence(x, z, 40 / cellSize, -40); | placement.addInfluence(x, z, 40 / cellSize, -40); | ||||
else if (template.genericName() == "Rotary Mill" && ent.hasClass("Field")) | else if (template.genericName() == "Rotary Mill" && ent.hasClass("Field")) | ||||
placement.addInfluence(x, z, 60 / cellSize, 40); | placement.addInfluence(x, z, 60 / cellSize, 40); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | PETRA.ConstructionPlan.prototype.findGoodPosition = function(gameState) | ||||
// this allows room for units to walk between buildings. | // this allows room for units to walk between buildings. | ||||
// note: not for houses and dropsites who ought to be closer to either each other or a resource. | // note: not for houses and dropsites who ought to be closer to either each other or a resource. | ||||
// also not for fields who can be stacked quite a bit | // also not for fields who can be stacked quite a bit | ||||
let obstructions = PETRA.createObstructionMap(gameState, 0, template); | let obstructions = PETRA.createObstructionMap(gameState, 0, template); | ||||
// obstructions.dumpIm(template.buildPlacementType() + "_obstructions.png"); | // obstructions.dumpIm(template.buildPlacementType() + "_obstructions.png"); | ||||
let radius = 0; | let radius = 0; | ||||
if (template.hasClass("Fortress") || template.hasClass("Arsenal") || | if (template.hasClasses(["Fortress", "Arsenal"]) || | ||||
this.type == gameState.applyCiv("structures/{civ}/elephant_stable")) | this.type == gameState.applyCiv("structures/{civ}/elephant_stable")) | ||||
radius = Math.floor((template.obstructionRadius().max + 8) / obstructions.cellSize); | radius = Math.floor((template.obstructionRadius().max + 8) / obstructions.cellSize); | ||||
else if (template.resourceDropsiteTypes() === undefined && !template.hasClass("House") && | else if (template.resourceDropsiteTypes() === undefined && !template.hasClasses(["House", "Field", "Market"])) | ||||
!template.hasClass("Field") && !template.hasClass("Market")) | |||||
radius = Math.ceil((template.obstructionRadius().max + 4) / obstructions.cellSize); | radius = Math.ceil((template.obstructionRadius().max + 4) / obstructions.cellSize); | ||||
else | else | ||||
radius = Math.ceil(template.obstructionRadius().max / obstructions.cellSize); | radius = Math.ceil(template.obstructionRadius().max / obstructions.cellSize); | ||||
let bestTile; | let bestTile; | ||||
if (template.hasClass("House") && !alreadyHasHouses) | if (template.hasClass("House") && !alreadyHasHouses) | ||||
{ | { | ||||
// try to get some space to place several houses first | // try to get some space to place several houses first | ||||
▲ Show 20 Lines • Show All 616 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator