Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/library.js
Context not available. | |||||
* Constants needed for heightmap_manipulation.js | * Constants needed for heightmap_manipulation.js | ||||
*/ | */ | ||||
const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE; // Engine limit, Roughly 700 meters | const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE; // Engine limit, Roughly 700 meters | ||||
const MIN_HEIGHT = - SEA_LEVEL; | const MIN_HEIGHT = -SEA_LEVEL; | ||||
/** | /** | ||||
* Length of one tile of the terrain grid in metres. | * Length of one tile of the terrain grid in metres. | ||||
Context not available. | |||||
let obstructionSize = | let obstructionSize = | ||||
obstruction.Static ? | obstruction.Static ? | ||||
new Vector2D(obstruction.Static["@depth"], obstruction.Static["@width"]) : | new Vector2D(obstruction.Static["@depth"], obstruction.Static["@width"]) : | ||||
// Used for gates, should consider the position too | // Used for gates, should consider the position too | ||||
obstruction.Obstructions ? | obstruction.Obstructions ? | ||||
new Vector2D( | new Vector2D( | ||||
Object.keys(obstruction.Obstructions).reduce((depth, key) => Math.max(depth, +obstruction.Obstructions[key]["@depth"]), 0), | Object.keys(obstruction.Obstructions).reduce((depth, key) => Math.max(depth, +obstruction.Obstructions[key]["@depth"]), 0), | ||||
Object.keys(obstruction.Obstructions).reduce((width, key) => width + +obstruction.Obstructions[key]["@width"], 0)) : | Object.keys(obstruction.Obstructions).reduce((width, key) => width + (+obstruction.Obstructions[key]["@width"]), 0)) : | ||||
new Vector2D(0, 0); | new Vector2D(0, 0); | ||||
return obstructionSize.div(TERRAIN_TILE_SIZE).add(new Vector2D(2, 2).mult(margin)); | return obstructionSize.div(TERRAIN_TILE_SIZE).add(new Vector2D(2, 2).mult(margin)); | ||||
} | } | ||||
Context not available. | |||||
} | } | ||||
/** | /** | ||||
* Create an avoid constraint for the given classes by the given distances | |||||
*/ | |||||
function avoidClasses(/*class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new AvoidTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a stay constraint for the given classes by the given distances | |||||
*/ | |||||
function stayClasses(/*class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new StayInTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a border constraint for the given classes by the given distances | |||||
*/ | |||||
function borderClasses(/*class1, idist1, odist1, class2, idist2, odist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/3; ++i) | |||||
ar.push(new BorderTileClassConstraint(arguments[3*i], arguments[3*i+1], arguments[3*i+2])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Returns a subset of the given heightmap. | * Returns a subset of the given heightmap. | ||||
*/ | */ | ||||
function extractHeightmap(heightmap, topLeft, size) | function extractHeightmap(heightmap, topLeft, size) | ||||
Context not available. |
Wildfire Games · Phabricator