<?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-11-08T18:57:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.11</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 &#039;&#039;items&#039;&#039; 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;
* &#039;&#039;&#039;wesnoth.get_map_size()&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.get_terrain(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.set_terrain(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, &#039;&#039;terrain_code&#039;&#039;, [&#039;&#039;layer&#039;&#039;], [&#039;&#039;replace_if_failed&#039;&#039;])&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.get_info(&#039;&#039;terrain_code&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;id&#039;&#039;&#039;: string&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039;, &#039;&#039;&#039;description&#039;&#039;&#039;, &#039;&#039;&#039;editor_name&#039;&#039;&#039;: translatable strings&lt;br /&gt;
* &#039;&#039;&#039;castle&#039;&#039;&#039;, &#039;&#039;&#039;keep&#039;&#039;&#039;, &#039;&#039;&#039;village&#039;&#039;&#039;: booleans&lt;br /&gt;
* &#039;&#039;&#039;healing&#039;&#039;&#039;: integer&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.get_selected_tile ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;wesnoth.get_selected_tile()&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.get_locations(&#039;&#039;filter&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.get_villages([&#039;&#039;filter&#039;&#039;])&#039;&#039;&#039;&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&#039;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;
* &#039;&#039;&#039;wesnoth.match_location(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, &#039;&#039;filter&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.add_tile_overlay(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, &#039;&#039;item_wml&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.remove_tile_overlay(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, [&#039;&#039;filename&#039;&#039;])&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.add_fog([&#039;&#039;sides&#039;&#039;], &#039;&#039;locations&#039;&#039;, [&#039;&#039;permanent&#039;&#039;])&#039;&#039;&#039;&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 &#039;&#039;permanent&#039;&#039; argument defaults to false, causing temporary fog overrides to be cleared; if true, it affects the team&#039;s permanent fog as well.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.remove_fog ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;wesnoth.remove_fog([&#039;&#039;sides&#039;&#039;], &#039;&#039;locations&#039;&#039;, [&#039;&#039;permanent&#039;&#039;])&#039;&#039;&#039;&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 &#039;&#039;permanent&#039;&#039; argument defaults to false, creating temporary fog overrides that disappear at the end of the turn; if true, it affects the team&#039;s permanent fog as well.&lt;br /&gt;
&lt;br /&gt;
==== wesnoth.add_sound_source ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;wesnoth.add_sound_source(&#039;&#039;cfg&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.remove_sound_source(&#039;&#039;id&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.get_sound_source(&#039;&#039;id&#039;&#039;)&#039;&#039;&#039;&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&#039;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;
* &#039;&#039;&#039;wesnoth.map.get_direction(&#039;&#039;from&#039;&#039;, &#039;&#039;dir&#039;&#039;, [&#039;&#039;count&#039;&#039;])&#039;&#039;&#039;&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 &#039;&#039;count&#039;&#039; is number of steps to travel to specified direction. Negative &#039;&#039;count&#039;&#039; 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;
* &#039;&#039;&#039;wesnoth.map.get_relative_dir(&#039;&#039;from&#039;&#039;, &#039;&#039;to&#039;&#039;)&#039;&#039;&#039;&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 &#039;&#039;from&#039;&#039; and &#039;&#039;to&#039;&#039; 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;
* &#039;&#039;&#039;wesnoth.map.rotate_right_around_center(&#039;&#039;loc&#039;&#039;, &#039;&#039;center&#039;&#039;, &#039;&#039;angle&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.map.get_adjacent_tiles(&#039;&#039;loc&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.map.tiles_adjacent(&#039;&#039;loc1&#039;&#039;, &#039;&#039;loc2&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;wesnoth.map.distance_between(&#039;&#039;loc1&#039;&#039;, &#039;&#039;loc2&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;items.place_image(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, &#039;&#039;filename&#039;&#039;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Places an image at a given location and registers it as a WML &#039;&#039;[item]&#039;&#039; 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;
* &#039;&#039;&#039;items.place_halo(&#039;&#039;x&#039;&#039;, &#039;&#039;y&#039;&#039;, &#039;&#039;filename&#039;&#039;)&#039;&#039;&#039;&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;
* &#039;&#039;&#039;items.remove(&#039;&#039;x&#039;&#039;, &#039;&#039;x&#039;&#039;, [&#039;&#039;filename&#039;&#039;])&#039;&#039;&#039;&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>