Changeset View
Standalone View
binaries/data/mods/public/maps/random/rmgen/library.js
const PI = Math.PI; | const PI = Math.PI; | ||||
const TWO_PI = 2 * Math.PI; | const TWO_PI = 2 * Math.PI; | ||||
const TERRAIN_SEPARATOR = "|"; | 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; | ||||
const MAP_BORDER_WIDTH = 3; | const MAP_BORDER_WIDTH = 3; | ||||
const g_DamageTypes = new DamageTypes(); | |||||
/** | /** | ||||
elexis: (The last four are 0AD vocabulary, the other ones engine constants, so should be split later)… | |||||
* 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. | ||||
* Useful to transform footprint sizes of templates to the coordinate system used by getMapSize. | * Useful to transform footprint sizes of templates to the coordinate system used by getMapSize. | ||||
*/ | */ | ||||
const TERRAIN_TILE_SIZE = Engine.GetTerrainTileSize(); | const TERRAIN_TILE_SIZE = Engine.GetTerrainTileSize(); | ||||
const MAX_HEIGHT = MAX_HEIGHT_RANGE - SEA_LEVEL; | const MAX_HEIGHT = MAX_HEIGHT_RANGE - SEA_LEVEL; | ||||
// Default angle for buildings | // Default angle for buildings | ||||
const BUILDING_ORIENTATION = - PI / 4; | const BUILDING_ORIENTATION = - PI / 4; | ||||
const g_CivData = deepfreeze(loadCivFiles(false)); | const g_CivData = deepfreeze(loadCivFiles(false)); | ||||
Done Inline Actionsperhaps it's nicer to inline this, we do it in the simulation too (I wish to minimize the set of globals). Perhaps we could alternatively have it in globalscripts/ some day (unification thing) elexis: perhaps it's nicer to inline this, we do it in the simulation too (I wish to minimize the set… | |||||
function fractionToTiles(f) | function fractionToTiles(f) | ||||
Done Inline Actions(unneeded comments) elexis: (unneeded comments) | |||||
{ | { | ||||
return g_Map.size * f; | return g_Map.size * f; | ||||
} | } | ||||
function tilesToFraction(t) | function tilesToFraction(t) | ||||
{ | { | ||||
return t / g_Map.size; | return t / g_Map.size; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | if (painter instanceof Array) | ||||
painter = new MultiPainter(painter); | painter = new MultiPainter(painter); | ||||
painter.paint(area); | painter.paint(area); | ||||
return area; | return area; | ||||
} | } | ||||
/** | /** | ||||
* @param mode is one of the HeightPlacer constants determining whether to exclude the min/max elevation. | * @param mode is one of the HeightPlacer constants determining whether to exclude the min/max elevation. | ||||
Done Inline Actions((out-of-scope) Im wondering wheather we actually need that C++ function if we can just load the JSON files from here.) elexis: ((out-of-scope) Im wondering wheather we actually need that C++ function if we can just load… | |||||
*/ | */ | ||||
function paintTerrainBasedOnHeight(minHeight, maxHeight, mode, terrain) | function paintTerrainBasedOnHeight(minHeight, maxHeight, mode, terrain) | ||||
{ | { | ||||
Done Inline Actionsfor of elexis: for of | |||||
createArea( | createArea( | ||||
new HeightPlacer(mode, minHeight, maxHeight), | new HeightPlacer(mode, minHeight, maxHeight), | ||||
new TerrainPainter(terrain)); | new TerrainPainter(terrain)); | ||||
} | } | ||||
function paintTileClassBasedOnHeight(minHeight, maxHeight, mode, tileClass) | function paintTileClassBasedOnHeight(minHeight, maxHeight, mode, tileClass) | ||||
{ | { | ||||
createArea( | createArea( | ||||
Done Inline Actions(no deepfreeze?) elexis: (no deepfreeze?) | |||||
new HeightPlacer(mode, minHeight, maxHeight), | new HeightPlacer(mode, minHeight, maxHeight), | ||||
new TileClassPainter(getTileClass(tileClass))); | new TileClassPainter(getTileClass(tileClass))); | ||||
} | } | ||||
Done Inline ActionsWhat is to do here? elexis: What is to do here? | |||||
function unPaintTileClassBasedOnHeight(minHeight, maxHeight, mode, tileClass) | function unPaintTileClassBasedOnHeight(minHeight, maxHeight, mode, tileClass) | ||||
{ | { | ||||
createArea( | createArea( | ||||
new HeightPlacer(mode, minHeight, maxHeight), | new HeightPlacer(mode, minHeight, maxHeight), | ||||
new TileClassUnPainter(getTileClass(tileClass))); | new TileClassUnPainter(getTileClass(tileClass))); | ||||
Done Inline Actions(playerID more common) elexis: (playerID more common) | |||||
} | } | ||||
/** | /** | ||||
* Places the Entities of the given Group if they meet the Constraint | * Places the Entities of the given Group if they meet the Constraint | ||||
* and sets the given player as the owner. | * and sets the given player as the owner. | ||||
*/ | */ | ||||
function createObjectGroup(group, player, constraint) | function createObjectGroup(group, player, constraint) | ||||
{ | { | ||||
Show All 25 Lines | function getNumPlayers() | ||||
return g_MapSettings.PlayerData.length - 1; | return g_MapSettings.PlayerData.length - 1; | ||||
} | } | ||||
function getCivCode(playerID) | function getCivCode(playerID) | ||||
{ | { | ||||
return g_MapSettings.PlayerData[playerID].Civ; | return g_MapSettings.PlayerData[playerID].Civ; | ||||
} | } | ||||
function areAllies(playerID1, playerID2) | function areAllies(playerID1, playerID2) | ||||
Done Inline ActionsAbout to be deleted in D1062 I hope. (This move could have very well been in a separate diff as it's not related to the wall gen code) elexis: About to be deleted in D1062 I hope. (This move could have very well been in a separate diff… | |||||
{ | { | ||||
return ( | return ( | ||||
g_MapSettings.PlayerData[playerID1].Team !== undefined && | g_MapSettings.PlayerData[playerID1].Team !== undefined && | ||||
g_MapSettings.PlayerData[playerID2].Team !== undefined && | g_MapSettings.PlayerData[playerID2].Team !== undefined && | ||||
g_MapSettings.PlayerData[playerID1].Team != -1 && | g_MapSettings.PlayerData[playerID1].Team != -1 && | ||||
g_MapSettings.PlayerData[playerID2].Team != -1 && | g_MapSettings.PlayerData[playerID2].Team != -1 && | ||||
g_MapSettings.PlayerData[playerID1].Team === g_MapSettings.PlayerData[playerID2].Team); | g_MapSettings.PlayerData[playerID1].Team === g_MapSettings.PlayerData[playerID2].Team); | ||||
} | } | ||||
function getPlayerTeam(playerID) | function getPlayerTeam(playerID) | ||||
{ | { | ||||
Not Done Inline ActionsentPath is templateName? Can we avoid that return and error hard if someone ordered somthing that couldn't be answered (or is that useful somewhere?) elexis: `entPath` is `templateName`?
Can we avoid that `return` and error hard if someone ordered… | |||||
Done Inline Actionsnuke nuke elexis: nuke nuke | |||||
if (g_MapSettings.PlayerData[playerID].Team === undefined) | if (g_MapSettings.PlayerData[playerID].Team === undefined) | ||||
return -1; | return -1; | ||||
return g_MapSettings.PlayerData[playerID].Team; | return g_MapSettings.PlayerData[playerID].Team; | ||||
} | } | ||||
function getHeight(x, z) | function getHeight(x, z) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |
(The last four are 0AD vocabulary, the other ones engine constants, so should be split later)
g_Foo global style globally