TerrainWater

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

TerrainWater is a terrain's water: a sea at a level, and any number of lakes. TerrainItem holds one, draws it as its children, and saves it beside the terrain's heights, in water.json, so games get the water with no code. The sea is one large WaterSurface that follows the camera, or the item the terrain follows, in steps of 100 units, so it always reaches the horizon. Where the ground is higher than the water, the ground hides it, so the shore follows the ground by itself. Past the terrain's edge, the sea is open deep water. Lakes are rectangles at their own level; they too are hidden where the ground rises above them. Rivers run downhill along a path, from or into a lake or the sea, their ripples flowing downstream. The sea and the lakes share one WaterShaderProgram, so they share one look, which GetWaterProgram changes. Water needs Vulkan; under OpenGL it isn't drawn.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.TerrainItem
use Libraries.Game.Graphics.Worlds.TerrainWater

class Main is Game
TerrainItem ground

action Main
    UseVulkan(true)
    StartGame()
end

action CreateGame
    ground:Load("Terrains/Island/terrain.json")
    TerrainWater water = ground:GetWater()
    water:SetSeaLevel(2)
    water:AddLake(40, -20, 30, 24, 6)
    ground:WaterChanged()
    Add(ground)
end
end

Variables

  • number NO_WATER: GetWaterLevelAt's answer where there is no water: below anything.

Actions

AddLake(integer index, Libraries.Game.Graphics.Worlds.TerrainLake lake)

This action adds a lake made elsewhere, such as one being put back by an undo, at a place in the list.

Parameters

AddLake(number x, number z, number width, number depth, number level)

This action adds a lake: a rectangle of water centered on a point, at a level. It shows on the terrain's next update.

Parameters

  • x number: The lake's middle along x.
  • z number: The lake's middle along z.
  • width number: Its size along x.
  • depth number: Its size along z.
  • level number: The water's height.

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

AddPaintedLake(number depth)

This action adds an empty lake that follows the ground, for painting into with PaintLake: its water stands a depth above the ground wherever it is painted, and thins to the ground at its edge.

Parameters

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

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

AddRiver(integer index, Libraries.Game.Graphics.Worlds.TerrainRiver river)

This action adds a river made elsewhere, such as one being put back by an undo, at a place in the list.

Parameters

AddRiver()

This action adds a new river with no points. Add its points with the river's AddPoint, then call RiverChanged.

Returns

Libraries.Game.Graphics.Worlds.TerrainRiver: The river.

Changed()

This action marks the water to be drawn again on the next update, after its look or its lakes were changed directly.

Clear(Libraries.Interface.Item3D owner)

This action takes every sheet out of the owner, and frees it. The water is drawn again on the next update.

Parameters

DidLastFillSpill()

This action returns true if the last FillLake stopped below the level it was given, at its hollow's rim or the terrain's edge, where more water would spill. With no lake made, it means there was no hollow to hold water there.

Returns

boolean: True if the water would have spilled.

FillLake(number x, number z, number level)

This action fills a hollow with water from a point, as water poured there would, up to a level or the hollow's rim, whichever is lower, so it never floats or runs away downhill (TerrainLake:Fill). If a lake made of cells already has water there, it is filled again; otherwise a new lake is made. Nothing happens where no hollow can hold water.

Parameters

  • x number: Where the water is poured, along x.
  • z number: Where the water is poured, along z.
  • level number: The highest the water may rise.

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake filled, or undefined if nothing could hold water there.

FillLake(number x, number z, number level, integer mode)

This action fills a hollow with water from a point, either up to a level, wherever the hollow's rim is, or as poured water, which stops at the rim (TerrainLake's Fill). Poured into a lake of water cells, that lake is filled again.

Parameters

  • x number: Where the water is poured, along x.
  • z number: Where the water is poured, along z.
  • level number: The level.
  • mode integer: TerrainLake's FILL_TO_LEVEL or FILL_POURED.

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake filled, or undefined if nothing could hold water there.

GetHighestLevel()

This action returns the highest water's height, for the owner's render box.

Returns

number: The height, or NO_WATER if there is no water.

GetLake(integer index)

This action returns a lake.

Parameters

  • index integer: Which lake, from 0.

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

GetLakeAt(number x, number z)

This action returns the lake with water at a point, of either shape, or undefined. The last added wins where lakes overlap.

Parameters

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

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

GetLakeCount()

This action returns how many lakes there are.

Returns

integer: The count.

GetLakeIndex(Libraries.Game.Graphics.Worlds.TerrainLake lake)

This action returns a lake's place in the list.

Parameters

Returns

integer: Its place, from 0, or -1 if it isn't one of the terrain's.

GetLowestLevel()

This action returns the lowest water's height, for the owner's render box.

Returns

number: The height, or NO_WATER if there is no water.

GetMaskedLakeAt(number x, number z)

This action returns the lake made of cells with water at a point, or undefined.

Parameters

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

Returns

Libraries.Game.Graphics.Worlds.TerrainLake: The lake.

GetNewRiverName()

This action returns a name for a new river, "River" and the first number no river has.

Returns

text: The name, such as "River 3".

GetRiver(integer index)

This action returns one of the rivers.

Parameters

  • index integer: The river, from 0.

Returns

Libraries.Game.Graphics.Worlds.TerrainRiver: The river.

GetRiverAt(number x, number z)

This action returns the river whose water is at a point, or undefined.

Parameters

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

Returns

Libraries.Game.Graphics.Worlds.TerrainRiver: The river.

GetRiverCount()

This action returns how many rivers there are.

Returns

integer: The count.

GetRiverIndex(Libraries.Game.Graphics.Worlds.TerrainRiver river)

This action returns a river's place in the list, or -1.

Parameters

Returns

integer: Its place, from 0, or -1.

GetSea()

This action returns the sea's sheet, for the owner's render box.

Returns

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

GetSeaLevel()

This action returns the sea's height.

Returns

number: The sea level.

GetSeaSize()

This action returns the size of the sea's sheet.

Returns

number: Its size along x and z, or 0 until it is drawn.

GetStillWaterLevelAt(number x, number z)

This action returns the level of the still water at a point: the sea, where the ground is below it or there is no ground, or a lake covering it, whichever is higher; NO_WATER where there is none. Rivers join still water at their ends.

Parameters

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

Returns

number: The level.

GetWaterDepthAt(number x, number z)

This action returns how deep the water is over the ground at a point.

Parameters

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

Returns

number: The depth, or 0 where there is no water over the ground.

GetWaterLevelAt(number x, number z)

This action returns the height of the water over a point: the highest of the sea and the lakes and rivers covering it, or NO_WATER where there is none.

Parameters

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

Returns

number: The water's height there.

GetWaterProgram()

This action returns the program the water is drawn with, to change its look: its colors, clearness, ripples and shore. Every sheet of the terrain's water shares it.

Returns

Libraries.Game.Graphics.Worlds.WaterShaderProgram: The water program.

HasSea()

This action returns true if there is a sea.

Returns

boolean: True after SetSeaLevel, until RemoveSea.

HasWater()

This action returns true if there is any water: a sea or a lake.

Returns

boolean: True if there is water.

IsUnderWater(number x, number y, number z)

This action returns true if a point is under water: below the water's height there, and above the ground, which hides water where it rises higher.

Parameters

  • x number: The point along x.
  • y number: The point's height.
  • z number: The point along z.

Returns

boolean: True if the point is in the water.

LakeChanged(Libraries.Game.Graphics.Worlds.TerrainLake lake)

This action draws one lake again on the next update, after its shape or level changed. It is quicker than Changed, which draws all the water again.

Parameters

Load(Libraries.System.File folder)

This action reads water.json from a terrain's folder, if it has one.

Parameters

PaintLake(Libraries.Game.Graphics.Worlds.TerrainLake lake, number x, number z, number radius, boolean add)

This action adds or removes a lake's water under a brush. A rectangle lake becomes a lake of cells.

Parameters

  • lake Libraries.Game.Graphics.Worlds.TerrainLake: The lake.
  • x number: The brush's middle along x.
  • z number: The brush's middle along z.
  • radius number: The brush's radius.
  • add boolean: True to add water, false to remove it.

Returns

integer: How many cells changed.

RemoveLake(Libraries.Game.Graphics.Worlds.TerrainLake lake)

This action takes a lake away.

Parameters

Returns

boolean: True if it was one of the terrain's lakes.

RemoveRiver(Libraries.Game.Graphics.Worlds.TerrainRiver river)

This action takes a river away, with its sheet. The ground it carved stays carved; call the river's Uncarve first to put it back.

Parameters

Returns

boolean: True if it was one of the terrain's rivers.

RemoveSea()

This action takes the sea away. SetSeaLevel brings it back.

RiverChanged(Libraries.Game.Graphics.Worlds.TerrainRiver river)

This action finds a river's line and water again, after its points changed, and draws it again on the next update. A river whose first point is in a lake or the sea starts at that water's level, and one whose last point is in one ends at its level.

Parameters

Save(Libraries.System.File folder)

This action writes water.json into a terrain's folder, if the terrain has water, or had a water file. A terrain that never had water writes nothing.

Parameters

SetLake(Libraries.Game.Graphics.Worlds.TerrainLake lake, number x, number z, number width, number depth, number level)

This action changes a lake's place, size or level. A lake filled into a hollow is filled again at the new level (TerrainLake:Refill), so it follows the hollow and stops at its rim; its place and size follow its water. DidLastFillSpill then says whether the rim stopped it.

Parameters

  • lake Libraries.Game.Graphics.Worlds.TerrainLake: The lake.
  • x number: Its middle along x.
  • z number: Its middle along z.
  • width number: Its size along x.
  • depth number: Its size along z.
  • level number: The water's height.

SetSeaLevel(number level)

This action puts a sea at a height, or moves it there. It shows on the terrain's next update.

Parameters

  • level number: The sea's height.

SetTerrainData(Libraries.Game.Graphics.Worlds.TerrainData terrainData)

This action sets the terrain data the water stands on, for IsUnderWater. TerrainItem calls it.

Parameters

Update(Libraries.Interface.Item3D owner, Libraries.Game.Layer3D layer, number targetX, number targetZ)

This action keeps the water drawn: the first time, and after any change, its sheets are made again as the owner's children, and the sea is moved under a place, in steps of 100 units. TerrainItem calls it every frame.

Parameters

Returns

boolean: True if the water's box changed, so the owner's render box should be refreshed.

Inherited Actions

3 actions from Libraries.Language.Object