Changeset View
Standalone View
binaries/data/mods/public/maps/random/rmgen/library.js
Show All 11 Lines | |||||
Engine.LoadLibrary("rmgen/placer/noncentered"); | Engine.LoadLibrary("rmgen/placer/noncentered"); | ||||
/** | /** | ||||
* A Painter modifies an arbitrary feature in a given Area, for instance terrain textures, elevation or calling other painters on that Area. | * A Painter modifies an arbitrary feature in a given Area, for instance terrain textures, elevation or calling other painters on that Area. | ||||
* Typically the area is determined by a Placer called from createArea or createAreas. | * Typically the area is determined by a Placer called from createArea or createAreas. | ||||
*/ | */ | ||||
Engine.LoadLibrary("rmgen/painter"); | Engine.LoadLibrary("rmgen/painter"); | ||||
const TERRAIN_SEPARATOR = "|"; | |||||
const SEA_LEVEL = 20.0; | const SEA_LEVEL = 20.0; | ||||
const HEIGHT_UNITS_PER_METRE = 92; | const HEIGHT_UNITS_PER_METRE = 92; | ||||
/** | /** | ||||
* Number of impassable, unexplorable tiles at the map border. | * Number of impassable, unexplorable tiles at the map border. | ||||
*/ | */ | ||||
const MAP_BORDER_WIDTH = 3; | const MAP_BORDER_WIDTH = 3; | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | function createObjectGroupsByAreas(group, player, constraints, amount, retryFactor, areas, behaveDeprecated = false) | ||||
let placeFunc = function() { | let placeFunc = function() { | ||||
group.setCenterPosition(pickRandom(pickRandom(areas).getPoints())); | group.setCenterPosition(pickRandom(pickRandom(areas).getPoints())); | ||||
return createObjectGroup(group, player, constraints); | return createObjectGroup(group, player, constraints); | ||||
}; | }; | ||||
return retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated); | return retryPlacing(placeFunc, retryFactor, amount, behaveDeprecated); | ||||
} | } | ||||
function createTerrain(terrain) | function createTerrain(terrain) | ||||
lyv: Maybe this proxy ought to be removed too. | |||||
FeXoRUnsubmitted Not Done Inline ActionsIt's used 24 times, some in maps and some in libs. Or what do you mean? FeXoR: It's used 24 times, some in maps and some in libs.
If we want to stick to simple terrain (we… | |||||
elexisUnsubmitted Not Done Inline ActionsYes, it would be better to weed that out like the rest of the library.js functions and constants (#4804, #4964) and use the SimpleTerrain or RandomTerrain constructors to remove indirection (possibly extending RandomTerrain type to support string input, or not). There is no 0.5 in this function, we would only refactor the existing code, so still same mapgen with cleaner code. elexis: Yes, it would be better to weed that out like the rest of the `library.js` functions and… | |||||
elexisUnsubmitted Not Done Inline Actionsor actually setTexture to avoid some useless object construction (In particular as the g_Map constant shouldn't be hardcoded in the library). elexis: or actually `setTexture` to avoid some useless object construction (In particular as the g_Map… | |||||
FeXoRUnsubmitted Not Done Inline ActionsI'm for replacing the strings with object (or arrays but objects would be easier to check for when the object's values can be arrays). Yea, +0.5/randFloat() (shifting terrain entities to the center of the tile) is done somewhere else - so unrelated. FeXoR: I'm for replacing the strings with object (or arrays but objects would be easier to check for… | |||||
{ | { | ||||
return typeof terrain == "string" ? | if (typeof terrain == "object") | ||||
new SimpleTerrain(...terrain.split(TERRAIN_SEPARATOR)) : | return Array.isArray(terrain) ? new RandomTerrain(terrain.map(t => createTerrain(t))) : new SimpleTerrain(terrain.texture, terrain.entity); | ||||
new RandomTerrain(terrain.map(t => createTerrain(t))); | else if (typeof terrain == "string") | ||||
return new SimpleTerrain(terrain); | |||||
FeXoRUnsubmitted Not Done Inline ActionsThe function does not always return something. FeXoR: The function does not always return something.
If not clear what to do with the given argument… | |||||
elexisUnsubmitted Not Done Inline ActionsErroring in the third case sounds reasonable. elexis: Erroring in the third case sounds reasonable.
Also no else after return (if it doesnt change… | |||||
} | } | ||||
/** | /** | ||||
* Constructs a new Area shaped by the Placer meeting the Constraints and calls the Painters there. | * Constructs a new Area shaped by the Placer meeting the Constraints and calls the Painters there. | ||||
* Supports both Centered and Non-Centered Placers. | * Supports both Centered and Non-Centered Placers. | ||||
*/ | */ | ||||
function createArea(placer, painters, constraints) | function createArea(placer, painters, constraints) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |
Maybe this proxy ought to be removed too.