Difference between revisions of "LuaWML/Tiles"

From The Battle for Wesnoth Wiki
(Split LuaWML page)
 
(Moved village handling to the "sides" page)
Line 1: Line 1:
This page describes the [[LuaWML]] functions for handling terrains, villages, and tiles.  
+
This page describes the [[LuaWML]] functions for handling terrains and tiles.  
  
 
==== wesnoth.get_map_size ====
 
==== wesnoth.get_map_size ====
Line 32: Line 32:
 
* '''castle''', '''keep''', '''village''': booleans
 
* '''castle''', '''keep''', '''village''': booleans
 
* '''healing''': integer
 
* '''healing''': integer
 
==== wesnoth.get_village_owner ====
 
 
Returns the side that owns the village at the given location.
 
 
local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1
 
 
==== wesnoth.set_village_owner ====
 
 
Gives ownership of the village at the given location to the given side (or remove ownership if none).
 
 
wesnoth.set_village_owner(12, 15, 1)
 
  
 
==== wesnoth.get_selected_tile ====
 
==== wesnoth.get_selected_tile ====

Revision as of 08:33, 16 March 2010

This page describes the LuaWML functions for handling terrains and tiles.

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

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)