TerrainLake

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object

A TerrainLake is one lake on a terrain: water at a level. TerrainWater holds a terrain's lakes, saves them, and draws each with a WaterSurface. The ground hides the water wherever it rises above it, so the shore follows the ground. A lake is one of two shapes: - a rectangle, centered on a point, set with Set; - a grid of water cells: square cells the terrain's sample spacing wide, each holding water or not. Fill makes one by filling a hollow from a point, as poured water would, up to the level or the hollow's rim, whichever is lower, so it never spills or floats; Paint adds or removes cells under a brush. Only the cells with water are drawn, so water never shows in a neighboring hollow. Its rectangle is kept around its cells. Painting into a lake with a level adds water only where the ground is below that level, so it never floats. A lake started by painting (StartFollowing) has no single level: it follows the ground, its water depth above it, thinning to the ground at its edge, like a stream or a puddle.

Example Code

use Libraries.Game.Graphics.Worlds.TerrainLake

TerrainLake pond
pond:Set(40, -20, 30, 24, 3.5)
pond:SetName("Mill pond")

Variables

  • integer FILL_TO_LEVEL: fills the same way.
  • integer MAXIMUM_FILL_CELLS: doesn't fill forever.
  • integer FILL_POURED: fills the same way.
  • integer MAXIMUM_DESCENT: so water poured on a long slope doesn't travel to a distant valley.

Actions

CopyFrom(Libraries.Game.Graphics.Worlds.TerrainLake other)

This action makes this lake the same as another: its name, level, shape and cells, but not its sheet. Undo uses it.

Parameters

Covers(number pointX, number pointZ)

This action returns true if the lake's rectangle reaches over a point, seen from above.

Parameters

  • pointX number: The point along x.
  • pointZ number: The point along z.

Returns

boolean: True if the lake covers it.

DidReachEdge()

This action returns true if the last fill reached the terrain's edge.

Returns

boolean: True if it reached the edge.

Fill(Libraries.Game.Graphics.Worlds.TerrainData data, number startX, number startZ, number height)

This action makes the lake a grid of water cells by filling a hollow from a point, as water poured there would. The water first runs downhill from the point to the bottom of its hollow, then rises, covering the lowest ground first. It stops at whichever comes first: - the level given; - the hollow's rim: the lowest place on its edge, where more water would spill over and run away downhill; - the terrain's edge, where the water would run off. The lake's level is where it stopped, so it never floats over ground that falls away. On a slope with no hollow, nothing fills. IsSpilled says whether the rim or edge stopped it below the level given.

Parameters

  • data Libraries.Game.Graphics.Worlds.TerrainData: The terrain's data.
  • startX number: Where the water is poured, along x.
  • startZ number: Where the water is poured, along z.
  • height number: The highest the water may rise.

Returns

integer: How many cells got water: 0 if none could hold any.

Fill(Libraries.Game.Graphics.Worlds.TerrainData data, number startX, number startZ, number height, integer mode)

This action makes the lake a grid of water cells from a point, either up to a level or as poured water. - FILL_TO_LEVEL: the water runs downhill to the bottom of its hollow, then every connected cell whose ground is lower than the level gets water, wherever the hollow's rim is. It stops at the level, and at the terrain's edge (DidReachEdge). - FILL_POURED: as Fill, it stops at the hollow's rim, the lowest place on its edge, where more water would spill. Rims lower than a quarter of a unit are ignored, so tiny dips don't stop it.

Parameters

  • data Libraries.Game.Graphics.Worlds.TerrainData: The terrain's data.
  • startX number: Where the water is poured, along x.
  • startZ number: Where the water is poured, along z.
  • height number: The level.
  • mode integer: FILL_TO_LEVEL or FILL_POURED.

Returns

integer: How many cells got water: 0 if none could hold any.

FindBottom(Libraries.Game.Graphics.Worlds.TerrainData data, number startX, number startZ)

This action returns where water poured at a place ends up: the height of the bottom of its hollow. The water runs downhill from the place, but at most MAXIMUM_DESCENT cells, so on a long slope it doesn't travel to a distant valley. With no ground there, it returns the place's ground, or 0.

Parameters

Returns

number: The bottom's height.

GetCellSize()

This action returns how wide each water cell is.

Returns

number: The width, in world units.

GetColumnAt(number world)

This action returns the column or row holding a world position, along x or z.

Parameters

  • world number: The position.

Returns

integer: The column or row.

GetColumnCount()

This action returns how many columns the grid has.

Returns

integer: The count.

GetDeepest(Libraries.Game.Graphics.Worlds.TerrainData data)

This action returns how deep the water is at its deepest: its level less the lowest ground under it.

Parameters

Returns

number: The depth, or 0.

GetDepth()

This action returns the lake's size along z.

Returns

number: The depth, in world units.

GetFillMode()

This action returns how the lake is filled.

Returns

integer: FILL_TO_LEVEL or FILL_POURED.

GetFirstColumn()

This action returns the grid's first column.

Returns

integer: The column.

GetFirstRow()

This action returns the grid's first row.

Returns

integer: The row.

GetLevel()

This action returns the water's height.

Returns

number: The level, in world units.

GetLevelAt(Libraries.Game.Graphics.Worlds.TerrainData data, number pointX, number pointZ)

This action returns the water's height at a point: the level, or for a lake that follows the ground, its depth above the ground there.

Parameters

Returns

number: The height.

GetLowestGround(Libraries.Game.Graphics.Worlds.TerrainData data)

This action returns the height of the lowest ground under a lake of water cells, or the lake's level if it has none.

Parameters

Returns

number: The height.

GetLowestX()

This action returns where the lowest ground under a lake of water cells is, along x, as found by GetLowestGround.

Returns

number: The place, in world units.

GetLowestZ()

This action returns where the lowest ground under the lake is, along z.

Returns

number: The place, in world units.

GetName()

This action returns the lake's name, such as "Mill pond".

Returns

text: The name, or "" for none.

GetRowCount()

This action returns how many rows the grid has.

Returns

integer: The count.

GetRuns()

This action returns the grid's water as runs, for saving: three numbers per run of water along a row, its row, first column and length.

Returns

Libraries.Containers.Array<integer>: The runs.

GetSpillX()

This action returns where the last poured fill would spill over its hollow's rim, or reached the terrain's edge, along x.

Returns

number: The place, in world units.

GetSpillZ()

This action returns where the last poured fill would spill, along z.

Returns

number: The place, in world units.

GetSurface()

This action returns the sheet drawing the lake.

Returns

Libraries.Game.Graphics.Worlds.WaterSurface: The surface, or undefined until it is drawn.

GetWaterCellCount()

This action returns how many cells hold water.

Returns

integer: The count.

GetWaterDepth()

This action returns how far above the ground a lake that follows the ground stands.

Returns

number: The depth.

GetWidth()

This action returns the lake's size along x.

Returns

number: The width, in world units.

GetX()

This action returns the lake's middle along x.

Returns

number: The x, in world units.

GetZ()

This action returns the lake's middle along z.

Returns

number: The z, in world units.

IsFollowingGround()

This action returns true if the lake follows the ground, its water depth above it, instead of having one level.

Returns

boolean: True for a lake that follows the ground.

IsMasked()

This action returns true if the lake is a grid of water cells, made by Fill or Paint, rather than a rectangle.

Returns

boolean: True for a grid of cells.

IsSpilled()

This action returns true if the last Fill stopped below the level it was given: at its hollow's rim, where more water would spill, or at the terrain's edge.

Returns

boolean: True if the water would have spilled.

IsWater(integer column, integer row)

This action returns true if a cell holds water.

Parameters

  • column integer: The cell's column, counted in cells from the world's origin along x.
  • row integer: The cell's row, along z.

Returns

boolean: True for water.

Paint(Libraries.Game.Graphics.Worlds.TerrainData data, number pointX, number pointZ, number radius, boolean add)

This action adds or removes water in the cells within a distance of a point, as a brush does. A lake that was a rectangle becomes a grid of cells first, holding the rectangle's water.

Parameters

  • data Libraries.Game.Graphics.Worlds.TerrainData: The terrain's data, for its sample spacing.
  • pointX number: The brush's middle along x.
  • pointZ number: The brush's middle along z.
  • radius number: The brush's radius, in world units.
  • add boolean: True to add water, false to remove it.

Returns

integer: How many cells changed.

Refill(Libraries.Game.Graphics.Worlds.TerrainData data, number height)

This action fills a lake of water cells again at a new level, as Fill does, from its lowest cell and the way it was filled (GetFillMode): it spreads or shrinks to match the hollow, and a poured lake stops at the hollow's rim, so raising the level never leaves water hanging over ground that falls away. The lake keeps its name. Nothing changes if no cell could hold water at that level, or for a lake that is a rectangle or follows the ground.

Parameters

Returns

integer: How many cells have water, or 0 if nothing changed.

Set(number middleX, number middleZ, number sizeX, number sizeZ, number height)

This action sets where the lake is, how big, and its water's height. For a lake of water cells (Fill and Paint), only the level is used.

Parameters

  • middleX number: The lake's middle along x, in world units.
  • middleZ number: The lake's middle along z, in world units.
  • sizeX number: Its size along x.
  • sizeZ number: Its size along z.
  • height number: The water's height.

SetFillMode(integer mode)

This action sets how the lake is filled again (Refill).

Parameters

  • mode integer: FILL_TO_LEVEL or FILL_POURED.

SetLevel(number height)

This action sets the water's height, keeping the lake's shape. A filled lake keeps its cells; fill it again to follow the hollow at the new level.

Parameters

  • height number: The level.

SetName(text value)

This action sets the lake's name.

Parameters

  • value text: The name.

SetRuns(number size, Libraries.Containers.Array<integer> runs)

This action makes the lake a grid of water cells from saved runs.

Parameters

SetSurface(Libraries.Game.Graphics.Worlds.WaterSurface value)

This action sets the sheet drawing the lake. TerrainWater calls it.

Parameters

SetWaterDepth(number value)

This action sets how far above the ground a lake that follows the ground stands.

Parameters

  • value number: The depth.

StartFollowing(Libraries.Game.Graphics.Worlds.TerrainData data, number standing)

This action makes the lake an empty grid of cells that follows the ground: painted water stands a depth above the ground in each cell, and thins to the ground at the lake's edge.

Parameters

StartFollowingSaved(number standing)

This action marks a lake being loaded as one that follows the ground, before its cells are set from the file.

Parameters

  • standing number: How far above the ground the water stands.

Inherited Actions

3 actions from Libraries.Language.Object