<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shrieker1</id>
	<title>The Battle for Wesnoth Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wesnoth.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Shrieker1"/>
	<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/Special:Contributions/Shrieker1"/>
	<updated>2026-05-03T21:45:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://wiki.wesnoth.org/index.php?title=LuaWML/Tiles&amp;diff=58902</id>
		<title>LuaWML/Tiles</title>
		<link rel="alternate" type="text/html" href="https://wiki.wesnoth.org/index.php?title=LuaWML/Tiles&amp;diff=58902"/>
		<updated>2017-09-14T22:28:33Z</updated>

		<summary type="html">&lt;p&gt;Shrieker1: Correct the descriptions for get_direction and get_relative_dir that had documentation switched compared to implementation. Also a few extra details added about functions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the [[LuaWML]] functions for handling terrains and tiles. The ''items'' library can be loaded by&lt;br /&gt;
&lt;br /&gt;
 items = wesnoth.require &amp;quot;lua/wml/items.lua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_map_size ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_map_size()'''&lt;br /&gt;
&lt;br /&gt;
Returns the width, the height, and the border size of the map.&lt;br /&gt;
&lt;br /&gt;
 local w,h,b = wesnoth.get_map_size()&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_terrain ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_terrain(''x'', ''y'')'''&lt;br /&gt;
&lt;br /&gt;
Returns the terrain code for the given location.&lt;br /&gt;
&lt;br /&gt;
 local is_grassland = wesnoth.get_terrain(12, 15) == &amp;quot;Gg&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.set_terrain ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.set_terrain(''x'', ''y'', ''terrain_code'', [''layer''], [''replace_if_failed''])'''&lt;br /&gt;
&lt;br /&gt;
Modifies the terrain at the given location.&lt;br /&gt;
&lt;br /&gt;
 function create_village(x, y)&lt;br /&gt;
     wesnoth.set_terrain(x, y, &amp;quot;Gg^Vh&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
An optional 4th parameter can be passed (layer): overlay, base or both, default both: Change the specified layer only.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_terrain_info ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_info(''terrain_code'')'''&lt;br /&gt;
&lt;br /&gt;
Returns the terrain details for the given terrain code.&lt;br /&gt;
&lt;br /&gt;
 local is_keep = wesnoth.get_terrain_info(wesnoth.get_terrain(12, 15)).keep&lt;br /&gt;
&lt;br /&gt;
Terrain info is a plain table with the following fields:&lt;br /&gt;
* '''id''': string&lt;br /&gt;
* '''name''', '''description''', '''editor_name''': translatable strings&lt;br /&gt;
* '''castle''', '''keep''', '''village''': booleans&lt;br /&gt;
* '''healing''': integer&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_selected_tile ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_selected_tile()'''&lt;br /&gt;
&lt;br /&gt;
Returns the two coordinates of the currently selected tile. This is mostly useful for defining command-mode helpers.&lt;br /&gt;
&lt;br /&gt;
 function chg_unit(attr, val)&lt;br /&gt;
    local x, y = wesnoth.get_selected_tile()&lt;br /&gt;
    if not x then wesnoth.message(&amp;quot;Error&amp;quot;, &amp;quot;No unit selected.&amp;quot;); return end&lt;br /&gt;
    helper.modify_unit({ x = x, y = y }, { [attr] = val })&lt;br /&gt;
 end&lt;br /&gt;
 -- Function chg_unit can be used in command mode to modify unit attributes on the fly:&lt;br /&gt;
 --   :lua chg_unit(&amp;quot;status.poisoned&amp;quot;, true)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_locations ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_locations(''filter'')'''&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 -- replace all grass terrains by roads&lt;br /&gt;
 for i,loc in ipairs(wesnoth.get_locations { terrain = &amp;quot;Gg&amp;quot; }) do&lt;br /&gt;
     wesnoth.set_terrain(loc[1], loc[2], &amp;quot;Rr&amp;quot;)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_villages ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_villages([''filter''])'''&lt;br /&gt;
&lt;br /&gt;
This function, when called without arguments, returns a table containing all the villages present on the map (as tables of two elements). If it's called with a WML table as argument, a table containing only the villages matching the supplied [[StandardLocationFilter]] is returned.&lt;br /&gt;
&lt;br /&gt;
 -- How many villages do we have on our map?&lt;br /&gt;
 v = #wesnoth.get_villages()&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.match_location ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.match_location(''x'', ''y'', ''filter'')'''&lt;br /&gt;
&lt;br /&gt;
Returns true if the given location passes the filter.&lt;br /&gt;
&lt;br /&gt;
 bool b = wesnoth.match_location(x, y, { terrain = &amp;quot;Ww&amp;quot;, { &amp;quot;filter_adjacent_location&amp;quot;, terrain = &amp;quot;Ds,*^Bw*&amp;quot; } })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_tile_overlay ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.add_tile_overlay(''x'', ''y'', ''item_wml'')'''&lt;br /&gt;
&lt;br /&gt;
Places a tile overlay (either an image or a halo) at a given location. The overlay is described by a table supporting the same fields as [[InterfaceActionsWML|[item]]]. Note that the overlay is not kept over save/load cycles.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.add_tile_overlay(17, 42, { image = &amp;quot;items/orcish-flag.png&amp;quot; })&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_tile_overlay ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.remove_tile_overlay(''x'', ''y'', [''filename''])'''&lt;br /&gt;
&lt;br /&gt;
Removes all the overlays at the given location. If a filename is passed as a third argument, only this overlay (either image or halo) is removed.&lt;br /&gt;
&lt;br /&gt;
 wesnoth.remove_tile_overlay(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_fog ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.add_fog([''sides''], ''locations'', [''permanent''])'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} Fogs over the specified locations for the specified sides (or all sides, if no sides are specified). You can specify sides either as a single integer or a list of integers. The ''permanent'' argument defaults to false, causing temporary fog overrides to be cleared; if true, it affects the team's permanent fog as well.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_fog ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.remove_fog([''sides''], ''locations'', [''permanent''])'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} Unfogs the specified locations for the specified sides (or all sides, if no sides are specified). You can specify sides either as a single integer or a list of integers. The ''permanent'' argument defaults to false, creating temporary fog overrides that disappear at the end of the turn; if true, it affects the team's permanent fog as well.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_sound_source ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.add_sound_source(''cfg'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} Adds a sound source. Input parameters are the same as for the [add_sound_source] tag. If a sound source with the same ID already exists, it is replaced.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_sound_source ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.remove_sound_source(''id'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} Removes a sound source.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_sound_source ====&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.get_sound_source(''id'')'''&lt;br /&gt;
&lt;br /&gt;
{{DevFeature1.13|5}} Retrieves the parameters of an existing sound source. The result of this function is suitable for feeding back to add_sound_source. The table returned by this function is a copy of the sound source's parameters, so if you change any of them, you must call add_sound_source to update the source.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.get_direction ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.get_direction(''from'', ''dir'', [''count''])'''&lt;br /&gt;
&lt;br /&gt;
Calculates the hex reached by travelling in the specified direction, which should be a string such as &amp;quot;ne&amp;quot; or &amp;quot;s&amp;quot;. The optional third parameter ''count'' is number of steps to travel to specified direction. Negative ''count'' is supported to travel opposite direction.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.get_relative_dir ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.get_relative_dir(''from'', ''to'')'''&lt;br /&gt;
&lt;br /&gt;
Calculates the direction from one hex to another. Possible returns are strings &amp;quot;n&amp;quot;, &amp;quot;ne&amp;quot;, &amp;quot;nw&amp;quot;, &amp;quot;s&amp;quot;, &amp;quot;se&amp;quot;, &amp;quot;sw&amp;quot; or &amp;quot;&amp;quot;. The empty string means no direction which happens if ''from'' and ''to'' are same.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.rotate_right_around_center ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.rotate_right_around_center(''loc'', ''center'', ''angle'')'''&lt;br /&gt;
&lt;br /&gt;
Calculates the hex obtained from rotating the specified location around the specified center by the specified angle. The angle is an integer in the range 1..6.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.get_adjacent_tiles ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.get_adjacent_tiles(''loc'')'''&lt;br /&gt;
&lt;br /&gt;
Return all hexes adjacent to the specified hex, as six separate return values.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.tiles_adjacent ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.tiles_adjacent(''loc1'', ''loc2'')'''&lt;br /&gt;
&lt;br /&gt;
Tests if two hexes are adjacent.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.map.distance_between ====&lt;br /&gt;
{{DevFeature1.13|8}}&lt;br /&gt;
&lt;br /&gt;
* '''wesnoth.map.distance_between(''loc1'', ''loc2'')'''&lt;br /&gt;
&lt;br /&gt;
Calculates the distance between two hexes.&lt;br /&gt;
&lt;br /&gt;
==== items.place_image ====&lt;br /&gt;
&lt;br /&gt;
* '''items.place_image(''x'', ''y'', ''filename'')'''&lt;br /&gt;
&lt;br /&gt;
Places an image at a given location and registers it as a WML ''[item]'' would do, so that it can be restored after save/load.&lt;br /&gt;
&lt;br /&gt;
 local items = wesnoth.require &amp;quot;lua/wml/items.lua&amp;quot;&lt;br /&gt;
 items.place_image(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==== items.place_halo ====&lt;br /&gt;
&lt;br /&gt;
* '''items.place_halo(''x'', ''y'', ''filename'')'''&lt;br /&gt;
&lt;br /&gt;
Behaves the same as [[#items.place_image]] but for halos.&lt;br /&gt;
&lt;br /&gt;
==== items.remove ====&lt;br /&gt;
&lt;br /&gt;
* '''items.remove(''x'', ''x'', [''filename''])'''&lt;br /&gt;
&lt;br /&gt;
Removes an overlay set by [[#items.place_image]] or [[#items.place_halo]]. If no filename is provided, all the overlays on a given tile are removed.&lt;br /&gt;
&lt;br /&gt;
 items.remove(17, 42, &amp;quot;items/orcish-flag.png&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
[[Category: Lua Reference]]&lt;/div&gt;</summary>
		<author><name>Shrieker1</name></author>
		
	</entry>
</feed>