Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | PETRA.ConstructionPlan.prototype.findGoodPosition = function(gameState) | ||||
else // No position was specified so try and find a sensible place to build | else // No position was specified so try and find a sensible place to build | ||||
{ | { | ||||
// give a small > 0 level as the result of addInfluence is constrained to be > 0 | // give a small > 0 level as the result of addInfluence is constrained to be > 0 | ||||
// if we really need houses (i.e. Phasing without enough village building), do not apply these constraints | // if we really need houses (i.e. Phasing without enough village building), do not apply these constraints | ||||
if (this.metadata && this.metadata.base !== undefined) | if (this.metadata && this.metadata.base !== undefined) | ||||
{ | { | ||||
let base = this.metadata.base; | let base = this.metadata.base; | ||||
for (let j = 0; j < placement.map.length; ++j) | for (let j = 0; j < placement.map.length; ++j) | ||||
if (HQ.basesMap.map[j] == base) | if (HQ.baseAtIndex(j) == base) | ||||
placement.set(j, 45); | placement.set(j, 45); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
for (let j = 0; j < placement.map.length; ++j) | for (let j = 0; j < placement.map.length; ++j) | ||||
if (HQ.basesMap.map[j] != 0) | if (HQ.baseAtIndex(j) != 0) | ||||
placement.set(j, 45); | placement.set(j, 45); | ||||
} | } | ||||
if (!HQ.requireHouses || !template.hasClass("House")) | 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); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | PETRA.ConstructionPlan.prototype.findGoodPosition = function(gameState) | ||||
let disfavorBorder = gameState.currentPhase() > 1 && !template.hasDefensiveFire(); | let disfavorBorder = gameState.currentPhase() > 1 && !template.hasDefensiveFire(); | ||||
let favoredBase = this.metadata && (this.metadata.favoredBase || | let favoredBase = this.metadata && (this.metadata.favoredBase || | ||||
(this.metadata.militaryBase ? HQ.findBestBaseForMilitary(gameState) : undefined)); | (this.metadata.militaryBase ? HQ.findBestBaseForMilitary(gameState) : undefined)); | ||||
if (this.metadata && this.metadata.base !== undefined) | if (this.metadata && this.metadata.base !== undefined) | ||||
{ | { | ||||
let base = this.metadata.base; | let base = this.metadata.base; | ||||
for (let j = 0; j < placement.map.length; ++j) | for (let j = 0; j < placement.map.length; ++j) | ||||
{ | { | ||||
if (HQ.basesMap.map[j] != base) | if (HQ.baseAtIndex(j) != base) | ||||
placement.map[j] = 0; | placement.map[j] = 0; | ||||
else if (placement.map[j] > 0) | else if (placement.map[j] > 0) | ||||
{ | { | ||||
if (favorBorder && HQ.borderMap.map[j] & PETRA.border_Mask) | if (favorBorder && HQ.borderMap.map[j] & PETRA.border_Mask) | ||||
placement.set(j, placement.map[j] + 50); | placement.set(j, placement.map[j] + 50); | ||||
else if (disfavorBorder && !(HQ.borderMap.map[j] & PETRA.fullBorder_Mask)) | else if (disfavorBorder && !(HQ.borderMap.map[j] & PETRA.fullBorder_Mask)) | ||||
placement.set(j, placement.map[j] + 10); | placement.set(j, placement.map[j] + 10); | ||||
let x = (j % placement.width + 0.5) * cellSize; | let x = (j % placement.width + 0.5) * cellSize; | ||||
let z = (Math.floor(j / placement.width) + 0.5) * cellSize; | let z = (Math.floor(j / placement.width) + 0.5) * cellSize; | ||||
if (HQ.isNearInvadingArmy([x, z])) | if (HQ.isNearInvadingArmy([x, z])) | ||||
placement.map[j] = 0; | placement.map[j] = 0; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
for (let j = 0; j < placement.map.length; ++j) | for (let j = 0; j < placement.map.length; ++j) | ||||
{ | { | ||||
if (HQ.basesMap.map[j] == 0) | if (HQ.baseAtIndex(j) == 0) | ||||
placement.map[j] = 0; | placement.map[j] = 0; | ||||
else if (placement.map[j] > 0) | else if (placement.map[j] > 0) | ||||
{ | { | ||||
if (favorBorder && HQ.borderMap.map[j] & PETRA.border_Mask) | if (favorBorder && HQ.borderMap.map[j] & PETRA.border_Mask) | ||||
placement.set(j, placement.map[j] + 50); | placement.set(j, placement.map[j] + 50); | ||||
else if (disfavorBorder && !(HQ.borderMap.map[j] & PETRA.fullBorder_Mask)) | else if (disfavorBorder && !(HQ.borderMap.map[j] & PETRA.fullBorder_Mask)) | ||||
placement.set(j, placement.map[j] + 10); | placement.set(j, placement.map[j] + 10); | ||||
let x = (j % placement.width + 0.5) * cellSize; | let x = (j % placement.width + 0.5) * cellSize; | ||||
let z = (Math.floor(j / placement.width) + 0.5) * cellSize; | let z = (Math.floor(j / placement.width) + 0.5) * cellSize; | ||||
if (HQ.isNearInvadingArmy([x, z])) | if (HQ.isNearInvadingArmy([x, z])) | ||||
placement.map[j] = 0; | placement.map[j] = 0; | ||||
else if (favoredBase && HQ.basesMap.map[j] == favoredBase) | else if (favoredBase && HQ.baseAtIndex(j) == favoredBase) | ||||
placement.set(j, placement.map[j] + 100); | placement.set(j, placement.map[j] + 100); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Find the best non-obstructed: | // Find the best non-obstructed: | ||||
// Find target building's approximate obstruction radius, and expand by a bit to make sure we're not too close, | // Find target building's approximate obstruction radius, and expand by a bit to make sure we're not too close, | ||||
// this allows room for units to walk between buildings. | // this allows room for units to walk between buildings. | ||||
Show All 30 Lines | PETRA.ConstructionPlan.prototype.findGoodPosition = function(gameState) | ||||
let bestIdx = bestTile.idx; | let bestIdx = bestTile.idx; | ||||
let x = (bestIdx % obstructions.width + 0.5) * obstructions.cellSize; | let x = (bestIdx % obstructions.width + 0.5) * obstructions.cellSize; | ||||
let z = (Math.floor(bestIdx / obstructions.width) + 0.5) * obstructions.cellSize; | let z = (Math.floor(bestIdx / obstructions.width) + 0.5) * obstructions.cellSize; | ||||
let territorypos = placement.gamePosToMapPos([x, z]); | let territorypos = placement.gamePosToMapPos([x, z]); | ||||
let territoryIndex = territorypos[0] + territorypos[1]*placement.width; | let territoryIndex = territorypos[0] + territorypos[1]*placement.width; | ||||
// default angle = 3*Math.PI/4; | // default angle = 3*Math.PI/4; | ||||
return { "x": x, "z": z, "angle": 3*Math.PI/4, "base": HQ.basesMap.map[territoryIndex] }; | return { "x": x, "z": z, "angle": 3*Math.PI/4, "base": HQ.baseAtIndex(territoryIndex) }; | ||||
}; | }; | ||||
/** | /** | ||||
* Placement of buildings with Dock build category | * Placement of buildings with Dock build category | ||||
* metadata.proximity is defined when first dock without any territory | * metadata.proximity is defined when first dock without any territory | ||||
* => we try to minimize distance from our current point | * => we try to minimize distance from our current point | ||||
* metadata.oversea is defined for dock in oversea islands | * metadata.oversea is defined for dock in oversea islands | ||||
* => we try to maximize distance to our current docks (for trade) | * => we try to maximize distance to our current docks (for trade) | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | PETRA.ConstructionPlan.prototype.findDockPosition = function(gameState) | ||||
// if no good place with enough water around and still in first phase, wait for expansion at the next phase | // if no good place with enough water around and still in first phase, wait for expansion at the next phase | ||||
if (!this.metadata.proximity && bestWater < 10 && gameState.currentPhase() == 1) | if (!this.metadata.proximity && bestWater < 10 && gameState.currentPhase() == 1) | ||||
return false; | return false; | ||||
let x = (bestIdx % obstructions.width + 0.5) * obstructions.cellSize; | let x = (bestIdx % obstructions.width + 0.5) * obstructions.cellSize; | ||||
let z = (Math.floor(bestIdx / obstructions.width) + 0.5) * obstructions.cellSize; | let z = (Math.floor(bestIdx / obstructions.width) + 0.5) * obstructions.cellSize; | ||||
// Assign this dock to a base | // Assign this dock to a base | ||||
let baseIndex = gameState.ai.HQ.basesMap.map[bestJdx]; | let baseIndex = gameState.ai.HQ.baseAtIndex(bestJdx); | ||||
if (!baseIndex) | if (!baseIndex) | ||||
baseIndex = -2; // We'll do an anchorless base around it | baseIndex = -2; // We'll do an anchorless base around it | ||||
return { "x": x, "z": z, "angle": bestAngle, "base": baseIndex, "access": bestLand }; | return { "x": x, "z": z, "angle": bestAngle, "base": baseIndex, "access": bestLand }; | ||||
}; | }; | ||||
/** | /** | ||||
* Find a good island to build a dock. | * Find a good island to build a dock. | ||||
▲ Show 20 Lines • Show All 410 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator