Lua API

Map module

Functions for working with the current map.

There is only ever one map loaded at a given time.

Usage

local Map = ELONA.require("core.Map")

Functions

width () Returns the current map's width.
height () Returns the current map's height.
integer_id () Returns the current map's integer ID.
id () Returns the current map's ID.
instance_id () Returns the ID of the current map's instance.
current_dungeon_level () Returns the current dungeon level.
is_overworld () Returns true if this map is the overworld.
valid (position) Checks if a position is inside the map.
is_solid (position) Returns true if the map tile at the given position is solid.
is_blocked (position) Checks if a position is blocked and cannot be reached by walking.
random_pos () Returns a random position in the current map.
generate_tile (tile_kind) Generates a random tile ID from the current map's tileset.
chip_type () Returns the type of chip for the given tile kind.
get_tile (position) Gets the tile type of a tile position.
get_memory (position) Gets the player's memory of a tile position.
get_feat (position) Returns a table containing map feature information at the given tile position.
get_mef (position) Returns the ID of the map effect at the given position.
get_chara (position) Gets the character standing at a tile position.
set_tile (position, id) Sets a tile of the current map.
set_memory (position, id) Sets the player's memory of a tile position to the given tile kind.
set_feat (position, tile, param1, param2) Sets a feat at the given position.
clear_feat (position) Clears the feat at the given position.
spray_tile () Randomly sprays the map with the given tile type;
area () Returns the area in the world map that corresponds to this map.

Fields

data [R] The map data for the current map.

Functions

# width ()

Returns the current map's width.

This is only valid until the map changes.

Returns:
  • (num) the current map's width in tiles
# height ()

Returns the current map's height.

This is only valid until the map changes.

Returns:
  • (num) the current map's height in tiles
# integer_id ()

Returns the current map's integer ID.

Returns:
  • (num) the current map's integer ID
Or
# id ()

Returns the current map's ID.

Returns:
  • (string) the current map's ID
Or
# instance_id ()

Returns the ID of the current map's instance.

There can be more than one instance of a map of the same kind, like player-owned buildings.

Returns:
  • (num) the current map's instance ID
# current_dungeon_level ()

Returns the current dungeon level.

TODO: unify with World.data or Map.data

# is_overworld ()

Returns true if this map is the overworld.

Returns:
  • (bool)
# valid (position)

Checks if a position is inside the map.

It might be blocked by something.

Parameters: Returns:
  • (bool) true if the position is inside the map.
# is_solid (position)

Returns true if the map tile at the given position is solid.

Parameters: Returns:
  • (bool)
# is_blocked (position)

Checks if a position is blocked and cannot be reached by walking.

Parameters: Returns:
  • (bool)
# random_pos ()

Returns a random position in the current map.

It might be blocked by something.

Returns:
# generate_tile (tile_kind)

Generates a random tile ID from the current map's tileset.

Tile kinds can contain one of several different tile variations.

Parameters: Returns:
  • (num) the generated tile ID
See also:
# chip_type ()

Returns the type of chip for the given tile kind.

# get_tile (position)

Gets the tile type of a tile position.

Parameters: Returns:
  • (num)
# get_memory (position)

Gets the player's memory of a tile position.

Parameters: Returns:
  • (num)
# get_feat (position)

Returns a table containing map feature information at the given tile position.

  • id: Feature id.
  • param1: Extra parameter.
  • param2: Extra parameter.
  • param3: Extra parameter. (unused)

Parameters: Returns:
# get_mef (position)

Returns the ID of the map effect at the given position.

Parameters: Returns:
  • (num)
# get_chara (position)

Gets the character standing at a tile position.

Parameters: Returns:
# set_tile (position, id)

Sets a tile of the current map.

Only checks if the position is valid, not things like blocking objects.

Parameters:
  • position : (LuaPosition)
  • id : (num) the tile ID to set
Usage:
Map.set_tile(10, 10, Map.generate_tile(Enums.TileKind.Room))
# set_memory (position, id)

Sets the player's memory of a tile position to the given tile kind.

Parameters:
  • position : (LuaPosition)
  • id : (num) the tile ID to set
Usage:
Map.set_memory(10, 10, Map.generate_tile(Enums.TileKind.Room))
# set_feat (position, tile, param1, param2)

Sets a feat at the given position.

Parameters:
  • position : (LuaPosition) (const) the map position
  • tile : (num) the tile ID of the feat
  • param1 : (num) a parameter of the feat
  • param2 : (num) a parameter of the feat
# clear_feat (position)

Clears the feat at the given position.

Parameters:
# spray_tile ()

Randomly sprays the map with the given tile type;

# area ()

Returns the area in the world map that corresponds to this map.

Fields

# data

[R] The map data for the current map.

This contains serialized values controlling various aspects of the current map.