Difference between revisions of "LuaWML/Tiles"
(Added link) |
(→wesnoth.set_terrain: enhanced set_terrain docs) |
||
Line 20: | Line 20: | ||
wesnoth.set_terrain(x, y, "Gg^Vh") | wesnoth.set_terrain(x, y, "Gg^Vh") | ||
end | end | ||
+ | {{DevFeature1.9}}: An optional 4th parameter can be passed (layer): overlay, base or both, default both: Change the specified layer only. An optional 5th boolean parameter (replace_if_failed) can be passed, see the documentation of the [terrain] tag. To pass the 5th parameter but not the 4th, pass nil for the 4th. | ||
==== wesnoth.get_terrain_info ==== | ==== wesnoth.get_terrain_info ==== |
Revision as of 19:23, 24 September 2010
This page describes the LuaWML functions for handling terrains and tiles.
Contents
wesnoth.get_map_size
Returns the width, the height, and the border size of the map.
local w,h,b = wesnoth.get_map_size()
wesnoth.get_terrain
Returns the terrain code for the given location.
local is_grassland = wesnoth.get_terrain(12, 15) == "Gg"
wesnoth.set_terrain
Modifies the terrain at the given location.
function create_village(x, y) wesnoth.set_terrain(x, y, "Gg^Vh") end
Template:DevFeature1.9: An optional 4th parameter can be passed (layer): overlay, base or both, default both: Change the specified layer only. An optional 5th boolean parameter (replace_if_failed) can be passed, see the documentation of the [terrain] tag. To pass the 5th parameter but not the 4th, pass nil for the 4th.
wesnoth.get_terrain_info
Returns the terrain details for the given terrain code.
local is_keep = wesnoth.get_terrain_info(wesnoth.get_terrain(12, 15)).keep
Terrain info is a plain table with the following fields:
- id: string
- name, description: translatable strings
- castle, keep, village: booleans
- healing: integer
wesnoth.get_selected_tile
Returns the two coordinates of the currently selected tile. This is mostly useful for defining command-mode helpers.
function chg_unit(attr, val) local x, y = wesnoth.get_selected_tile() if not x then wesnoth.message("Error", "No unit selected."); return end helper.modify_unit({ x = x, y = y }, { [attr] = val }) end -- Function chg_unit can be used in command mode to modify unit attributes on the fly: -- :lua chg_unit("status.poisoned", true)
wesnoth.get_locations
Returns a table containing all the locations matching the given filter. Locations are stored as pairs: tables of two elements. See StandardLocationFilter for details about location filters.
-- replace all grass terrains by roads for i,loc in ipairs(wesnoth.get_locations { terrain = "Gg" }) do wesnoth.set_terrain(loc[1], loc[2], "Rr") end
wesnoth.match_location
Returns true if the given location passes the filter.
bool b = wesnoth.match_location(x, y, { terrain = "Ww", { "filter_adjacent_location", terrain = "Ds,*^Bw*" } })