File upandaway/lib/climbing.lua

Functions for adding, entering, exiting and failing (dying in) a cloud realm, as well as a few utility functions.

Functions

AddCloudLevel (data) Adds a new cloud level.
Climb (direction, cavenum) Climbs in a direction.
ClimbTo (height, cavenum) Climbs to the given height.
GetLevelHeight () Returns the height of the level we are currently in.
GetMaxHeight () Returns the maximum height among all registered levels.
GetMinHeight () Returns the minimum height among all registered levels (including default ones).
GetNextLevel () Returns the next level number (for climbing up).
GetPreviousLevel () Returns the previous level number (for climbing down).
GetRawLevelHeight () As GetLevelHeight(), but based on the level number alone.
IsCloudLevel () Returns whether we are in a cloud level or not.


Functions

AddCloudLevel (data)
Adds a new cloud level. Also embedded as TheMod:AddCloudLevel().

Parameters

  • data: A table describing the level, as in the second parameter of AddLevel.
Climb (direction, cavenum)
Climbs in a direction.

Parameters

  • direction: A number. Its sign dictates the direction. Calls ClimbTo to do the actual work.
  • cavenum:

See also:

ClimbTo (height, cavenum)
Climbs to the given height. It should be an integer.

Parameters

  • height: The target height.
  • cavenum: The number of the target "cave". If not given, the current cave number is used, raising an error if we're not in a cave level.

See also:

GetLevelHeight ()
Returns the height of the level we are currently in. The height is 0 for a survival map, 1 for the first cloud level, 2 for the second one, etc. For the first cave level, it is -1, for the second one it is -2, etc.

This is primarily meant to be used as a test for whether we are in a cloud level or not.

Works both under normal game and under worldgen (using different methods).

At worldgen, the level number is used. At normal game, we check for the existence of the upandaway_metadata component in the world entity. If it exists and has a field "height" stored, that value is adopted, otherwise the level number is used as in worldgen.
Savedata is given preference because the level number can possibly change, so this allows us to keep our system compatible with older saves.
GetMaxHeight ()
Returns the maximum height among all registered levels. This works even if there are no cloud levels (returning 0).
GetMinHeight ()
Returns the minimum height among all registered levels (including default ones).
GetNextLevel ()
Returns the next level number (for climbing up). Returns nil if there are none. 0 means survival map.
GetPreviousLevel ()
Returns the previous level number (for climbing down). Returns nil if there are none. 0 means survival map.
GetRawLevelHeight ()
As GetLevelHeight(), but based on the level number alone.

See also:

IsCloudLevel ()
Returns whether we are in a cloud level or not. First, it checks if the world entity has the "cloudrealm" tag. If it does, returns true. If not, checks if the level height is positive.

Return value:

A boolean

Valid XHTML 1.0!