Squirrel programming language is used for scripting.
You can find its documentation on http://www.squirrel-lang.org/


HMAP_SIZE
Size of the map, currently 256.

HMAP_SIZE_SHIFT
Power of 2 of the map size, currently 8.



vec4f
A vector of 4 floating point numbers.
It's usually used as XYZ0 for vectors and XYZ1 for points.
It can also be used for colors as RGBA with 0..1 component range.
Arithmetic operations work on it per-component.
You can use array indexing (v[i]) on it to get/set its components.

Some functions that work with vec4f:

make4f(s) or make4f(x, y, z, w)
Create vector from single scalar or four numbers.

cross(a, b)
Cross product.

dot3(a, b)
Returns 3D dot product as vector with all components having the same value.

norm3(v)
Returns normalized 3D vector.

len3(v)
Returns length of 3D vector.

len3Sq(v)
Returns squared length of 3D vector.

make_dir_2d(udir, vdir, a)
Used for random directions in 2D. The basis vectors should be orthogonal.
Value for "a" is in 0..1 range, usually specified as frnd().

make_dir_xz(a)
Similar to make_dir_2d() above, returns random direction in XZ (horizontal) plane.


Colors

Colors can be specified either as 32-bit integers or as vectors using make4f().
Integer form: 0xAARRGGBB. Hex number, so components are in 0..255 (0..0xFF) range.
When specifying as vec4f, 0..1 component range is assumed.



ColorRamp
It's a color gradient that can be used for various effects.
Internally it's stored as an array of 257 colors with linear interpolation between them.

ColorRamp(func)
Create ColorRamp using the provided function.
The function receives a single number in the 0..1 range and must return the corresponding color.

ColorRamp.constRamp(c)
Create constant gradient from provided color.

ColorRamp.linear(c0, c1)
Create linear gradient from c0 at 0 to c1 at 1.

ColorRamp.fadeInOut(c0, c1, c2, f0, f2)
Create gradient starting with c0, smoothly fading to c1 at f0 length,
then constant in the middle at c1, then fading smoothly to c2 at the last f2 length.

get(t)
Returns color at the specified position in the gradient.
If t is out of 0..1 range, it's clamped to that range.



FloatRamp
A scalar gradient similar to ColorRamp.



HmapMask
A floating-point mask of the HMAP_SIZE x HMAP_SIZE size.
Can be used as height map, masking areas of the map etc.
I use XZ coordinates to refer to it, because world up axis is Y.

HmapMask(number)
Create mask filled with the specified number.

HmapMask(func)
Create mask using the provided function.
The function is called with two arguments, the position in the map and must return a number.

getraw(x, z)
Returns value at the specified *integer* coordinates.
It does no interpolation, so the coordinates MUST be integers. It's quite fast.
If the coordinates are out of range, they'll be wrapped around.

get(x, z)
Returns the value at the specified coordinates.
It does bilinear interpolation.

calcMinMax()
Returns array of two values: [min, max].

HmapMask.fastNoise(height, roughness)
Create new HmapMask using a "fast noise" algorithm.
The "height" parameter scales the value, and "roughness" is usually 0.5

HmapMask.fromHeight()
Create new HmapMask from the current height map.

HmapMask.fromSlope()
Create new HmapMask from the current height map slope.
The slope is defined as the Y component of the surface normal.

HmapMask.fromWater()
Create new HmapMask from the current water amount.

HmapMask.fromSimplexNoise(height, tile, octaves, profile, roughness)
Create new HmapMask using tiled simplex noise:
  height - scales the map
  tile - tile size, must be integer and power of 2
  octaves - integer number of fractal noise octaves
  profile - optional FloatRamp to transform each octave for various effects
  roughness - octave scaling, usually 0.5

HmapMask.fromVoronoiHills(tile, min_height, max_height, hill_size)
Create new HmapMask using semi-random "hill" pattern.
  tile - tile size, must be integer and power of 2
  min_height, max_height - height range
  hill_size - usually 1.0, can be used to scale "hills" a bit

HmapMask.fromVoronoiFaults(tile, min_height, max_height,
  wrap_strength, wrap_scale, wrap_octaves, slope_k)
Create new HmapMask using semi-random cellular pattern with a bit of noise wrapping.
  tile - tile size, must be integer and power of 2
  min_height, max_height - height range
  wrap_strength - typical value 0.05, distorts cells
  wrap_scale - integer power of 2, relative to "tile", typical value 4
  wrap_octave - fractal noise octaves, typical value 3
  slope_k - slope factor, typically 8


Some functions related to HmapMask:


apply_height_mask(mask, func)
Apply HmapMask to the current height map. Any parameter can be null, but not both.
(mask, null):
  The mask value is just added to the height map.
(null, func):
  The function receives the current height and returns the new one.
(mask, func):
  The function receives current height and mask value and returns the new height.

apply_water_mask(mask, func)
The same as apply_height_mask() above, but applied to the amount of water.

recolor_by_height(ramp, mask)
Recolor the surface using the height color gradient (ColorRamp).
The gradient is applied from the minimum height to the maximum one.
If mask is null, current height is used instead.

repaint_land(func)
Recolor land using the provided function.
The function is called with (x, z, base_color, surface_color), both colors as vec4f.
The function must return an array of either 2 or 4 values:
  [base_color, base_type, surface_color, surface_type]
If surface color (and type) is not returned, it's set as transparent.
Surface types are not used yet and might change, so just use 0 for now.

recolor_land4(cr, cg, cb, ca)
Treats current base color as 4 weights for the specified colors.
It's used to change "chemical" representation to the visual one.



Various utility functions:


irnd()
Returns random positive integer.

frnd()
Returns random floating point number in the range 0..1

srnd()
Returns random floating point number in the range -1..1

rndf(min, max)
Returns random floating point number in the specified range.

hmrnd()
Returns random integer in the range 0..HMAP_SIZE-1

hmfrnd()
Returns random floating point number in the range 0..HMAP_SIZE

hmsrnd()
Returns random floating point number in the range -HMAP_SIZE/2..HMAP_SIZE/2

set_rnd_seed(seed)
Set the random numbers seed. Use to fix random number generator for testing etc.

randomize_rnd_seed()
Randomize the random numbers seed using current time.

lerpcolor(a, b, t)
Interpolates between a and b based on t.

lch2rgba(l, c, h, alpha)
Converts LCH color to RGB, and attaches specified alpha.

hsv2rgba(h, s, v, alpha)
Converts HSV color to RGB, and attaches specified alpha.

wrap(dx)
Wraps the specified delta around the HMAP_SIZE map,
bringing it to -HMAP_SIZE/2..HMAP_SIZE/2 range.

mix3colors(ac, aw, bc, bw, cc, cw)
Multiplies the three colors by their weights and adds them together.

mix4colors(ac, aw, bc, bw, cc, cw, dc, dw)
Similar to mix3colors() above.



Some land generation functions:


place_house(x, z, type)

gen_fault(px, py, dx, dy, height, balance, amplitude, ramp, base_type)

gen_crater(px, py, radius, depth_k)
Carve crater at the specified position.
  depth_k - relative depth, 1.0 is one radius deep.

gen_droplet_erosion(num_droplets, params)
"params" is a table that may contain any of the following parameters:
  Kq - carry capacity factor
  Kr - erosion factor
  Kd - deposition factor
  Kw - evaporation speed
  Ki - inertia, higher values makes droplet paths smoother
  minSlope - minimum slope when calculating carry capacity
  g - gravity, default is 20
  depositBlend - how much color is blended over when depositing
  reactionTime - maximum time for reactions, default is 100
  reactions - array of optional "chemical" reactions, each one is:
    [left, right, speed]
    "left" and "right" are vec4f representing amount of each chemical, should be integer values.

add_voronoi_hills(tile, min_ht, max_ht, hill_size)
See HmapMask.fromVoronoiHills().

recenter_hmap()
Calculates min/max height and shifts height map so that it's centered around 0.



1D/2D noise:


reseed_noise()
Refills internal tables used to generate noise.
Affects some functions above that use noise functions internally.

noise1(x)
1D noise, with -1..1 output range.

fractal_noise1(x, octaves, profile, roughness)
1D fractal noise with optional FloatRamp profile.

tiled_noise2(x, y, tile)
2D tiled noise, with -1..1 output range. "tile" must be power of 2.

tiled_fractal_noise2(x, y, tile, octaves, profile, roughness)
2D tiled fractal noise, see HmapMask.fromSimplexNoise().
