LuaMapGenerator
The page describes the api available for lua map generators that is differnt from the ingame lua api.
wesnoth.find_path
- wesnoth.find_path(src, dst, cost_function, mapsize_x, mapsize_y, include_border)
Behaves slightly differntly than in the ingame lua api with the same name in particular it no longer accepts unit arguments and explicitly nees the map size.
wesnoth.create_map
- wesnoth.create_map (map_data)
- wesnoth.find_path(width, height, terrain)
Creates a gamemap object, which has the following functions and properties
- get_terrain(loc)
- set_terrain(loc, terrain)
- get_locations(filter, locs_to_check)
- get_tiles_radius(locations, filter_radius)
- terrain_mask(x_offset, y_offset, data, optional_argeument_table)
- width number
- height number
- data string
The filters about use custom lua filter objects that can be constructed via wesnoth.create_filter
wesnoth.create_filter
creates a lua filter object from a table describing a lua terrainfilter, this is similar but not the same as wml filters, compiling these into lua objects makes it much faster. A lua filtertable is a table which at index 1 has the type of the filter and the rest depends on the type of the filter, for example wesnoth.create_filter { "terrain", "K*"} " will create a filter that matches keeps. THe follwing types of theilter are known:
- { "terrain", terraincode } matches for terrain terraincode
- { "all", <filter1>, <filter2>, <filter3>, ... } matches when all the subfilters match
- { "any", <filter1>, <filter2>, <filter3>, ... } matches when any the subfilters match
- { "none", <filter1>, <filter2>, <filter3>, ... } matches when none the subfilters match
- { "notall", <filter1>, <filter2>, <filter3>, ... } matches when not all the subfilters match
- { "adjacent", <subfilter>, [count = <count>], [adjacent = <adjacent>]} matches when count adjacent tiles matchthe subfilter ('adjacent=' defaults to 'n,nw,sw,s,se,ne')
- { "radius", <radius>, <subfilter>, filter_radius = <filter_radius> } radius: number, filter_radius: subfilter.
It is reccomended to create a helper function for filter construction for example:
f = {
terrain = function(terrain)
return { "terrain", terrain }
end,
all = function(...)
return { "all", ... }
end,
any = function(...)
return { "any", ... }
end,
none = function(...)
return { "none", ... }
end,
adjacent = function(f, ad, count)
return { "adjacent", f, adjacent = ad, count = count }
end,
radius = function(r, f, f_r)
return { "radius", r, f, filter_radius = f_r}
end,
}
wesnoth.create_filter(
f.all(
f.terrain("K*"),
f.radius(4, f.terrain("^V*"))
)
)
for a filter that matches keepos that are at most distance 4 to a village