Commit graph

37 commits

Author SHA1 Message Date
Celtic Minstrel
2a26a68025 Some updates to Lua map location operations
* Rename the vector operations to hex_vector (to emphasize that they are NOT standard vector ops) and document them as official API
* Add new get_hexes_at_radius, which returns an unfilled ring (as opposed to get_hexes_in_radius which returns a filled circle)
* Expose the new cubic coordinate conversions
2024-09-15 15:27:39 -04:00
Celtic Minstrel
542581916f [Lua] Suppress some diagnostics and also recommend suppressing certain diagnostics globally 2024-08-13 08:54:04 -04:00
Celtic Minstrel
a9948d3fff [Lua.MapGen] Accept both comma-separated lists and arrays for f.adjacent 2024-07-21 19:58:03 -04:00
Celtic Minstrel
19f3682bdf [Lua.Mapgen] Add a few more ways to pass a location set to f.find_in
These may be less efficient in some cases, and there's even a couple of degenerate cases, but it's definitely easier to use like this.

This also adds an example of the original method, using a string to reference a separate list.
2024-07-21 19:58:03 -04:00
Celtic Minstrel
a72ec39f79 [Lua] Make f.is_loc work either with a location object or with separate x,y parameters 2024-07-21 19:58:03 -04:00
Celtic Minstrel
95bfd07286 [Lua.MapGen] Exposed previously-unused wesnoth.map.filter_tags.onborder filter since it seems useful 2024-07-21 19:58:03 -04:00
Celtic Minstrel
ab008161f1 [Lua.MapGen] Add wesnoth.map.filter_tags.formula that takes a WFL formula to match against locations 2024-07-21 19:58:03 -04:00
Celtic Minstrel
d734bfb9e2 [Lua] Make wesnoth.read_location return its result in standard named tuple format 2024-04-11 23:48:21 -04:00
Celtic Minstrel
bb3c95ebbc [Lua] Remove nonexistent parameter 2024-02-26 13:24:38 -05:00
Celtic Minstrel
4b5a8e25e8 [LuaDoc] Suppress some diagnostics 2024-02-13 19:29:21 -05:00
Celtic Minstrel
c7741907c2 [LuaDoc] Fix several errors in the inline documentation 2024-02-06 19:04:00 -05:00
Celtic Minstrel
14865d0afd Lua: Fix incorrect check for string type 2022-02-17 13:49:01 -05:00
Celtic Minstrel
e518fe622b Lua: Fix a deprecation warning in the hex reference API 2022-02-17 13:48:58 -05:00
Celtic Minstrel
e1300e29b0
Lua API: Add inline documentation for pretty much everything and convert existing docs (#6483)
The new format is EmmyLua-based and can be used with (at least) Visual Studio Code.
2022-02-17 13:43:31 -05:00
Celtic Minstrel
35fce3fa3b Lua API: Fix an error in the terrain hex API
Attempting to access a non-string key was an error.
2021-09-04 22:20:28 -04:00
Celtic Minstrel
23bfa4c896 fix whitespace 2021-07-30 19:22:57 -04:00
Celtic Minstrel
eb1bd1af6c Lua API: Add wesnoth.map.filter_tags for the mapgen kernel
This was supposed to be added for 1.16, but it was forgotten; anyone wishing to use it in 1.16 will have to copy it from World Conquest.
2021-07-30 19:22:57 -04:00
Celtic Minstrel
5951a63d3e Lua API: Fix wesnoth.map.find(filter, unit) ignoring the unit 2021-07-30 19:22:57 -04:00
Celtic Minstrel
30a3619202 Lua API: Fix bug in wesnoth.map.iter_adjacent
Fixes #5972
2021-07-30 19:22:57 -04:00
Celtic Minstrel
771f472dd7 Lua API: Add wesnoth.map.iter_adjacent
This replaces helper.adjacent_tiles
2021-07-07 01:32:05 -04:00
Celtic Minstrel
96b5bf43ef Move shroud/fog ops to wesnoth.sides and change the API somewhat
- place_shroud and remove_shroud no longer accept a shroud data string or the special string "all"
- new functions are added to convert between lists of locations and shroud data strings
- place_fog, remove_fog, is_fogged, and is_shrouded aren't changed, only moved
2021-06-19 11:07:53 -04:00
Celtic Minstrel
a03d59d7eb Lua: Add a new schedule module
The primary components of this are:
- wesnoth.current.schedule
- wesnoth.map.get_time_area()
- wesnoth.schedule module
2021-06-19 11:07:53 -04:00
Hejnewar
e1a79988b4 Fix deprecation message 2021-05-10 11:23:54 +02:00
Celtic Minstrel
900c576fe8 Fix bug in wesnoth.map.read_location 2021-05-08 17:15:02 -04:00
Pentarctagon
d203b061f9
Whitespace cleanup of lua files. 2021-04-25 15:11:09 -05:00
Celtic Minstrel
f737013203 Fix some issues with wesnoth.map.read_location and wesnoth.map.get 2021-03-28 10:55:03 -04:00
Celtic Minstrel
96fba6b833
Fix wesnoth.set_terrain without a mode 2021-03-19 21:02:56 -04:00
Celtic Minstrel
37fde7aaee
Allow hex references to hold auxiliary user values 2021-03-06 18:44:29 -05:00
Celtic Minstrel
a2d7a26365
Fix several Lua issues, mostly unintentional globals (#5587) 2021-03-06 17:01:53 -05:00
Celtic Minstrel
6558c7981b Add a wesnoth.terrain_types table 2021-02-28 18:16:33 -05:00
Celtic Minstrel
cf71af4e11 Add a terrain hex reference API
This adds a metatable to all locations returned from wesnoth.map.find.
2021-02-28 18:16:32 -05:00
Celtic Minstrel
90e6db0330 Rename two functions for consistency of terminology 2021-02-28 18:16:31 -05:00
Celtic Minstrel
7e1414e249 Rename existing map functions in the map generation kernel 2021-02-28 18:16:31 -05:00
Celtic Minstrel
2d5ea6312e Move various functions into the map module 2021-02-28 18:16:31 -05:00
Celtic Minstrel
e6efc7de6c Refactor the game map to permit exposing it to Lua via wesnoth.current.map
The method of accessing terrain on the map has drastically changed.
- wesnoth.get_terrain and wesnoth.set_terrain are both deprecated
- wesnoth.terrain_mask still works but is moved into the wesnoth.map module and now takes the map object as the first parameter
- The map's terrain is now accessed exclusively via indexing on the map object, ie map[{x,y}]
- You set terrain by assigning a terrain code; the position of ^ in the terrain code now determines the merge mode
- The replace_if_failed option is now manifested as a function that converts any terrain code into a special value that, when assigned to a location on the map, uses the replace if failed logic.

The map object has a few attributes in it:
- width and height are the total size, including borders
- playable_width and playable_height are the values returned from wesnoth.get_map_size, which is now deprecated
- border_size is the third value from wesnoth.get_map_size
- data converts the map to a string
- Special locations are now part of the map object. The length operator is deprecated.
- other than that, wesnoth.map is treated as if it were the metatable of the map object
2021-02-28 18:16:30 -05:00
Celtic Minstrel
51cf2621f7 Add a utility function to extract a location from the front of a variadic parameter pack
The purpose of this is to make it easy for functions implemented in Lua to handle locations
in the same way as functions implemented in C++.

The location_set module has been updated to make use of this functionality in its setter functions.

Usage example:

Imagine a function foo with the following signature:

foo(bar : string, home : location, mode : string, target : location, moo : boolean) -> boolean

With the new read_location function it could be implemented as follows:

function foo(...)
	-- First argument goes in bar
	local bar = ...
	-- Read location starting at the second argument
	local home, n = wesnoth.mP.read_location(select(2, ...))
	-- note: n will be 0 if a location wasn't found at that position
	-- This could be an error, or it could be handled as an optional parameter
	-- Next argument after that goes in mode
	local mode = select(n + 2, ...)
	-- Then read a location into target
	local target, m = wesnoth.map.read_location(select(n + 2, ...))
	-- Finally, read a parameter into moo
	local moo = select(m + n + 2, ...)
	-- Do stuff with all these parameters
	return true
end

With that code, all the following invocations of foo work:

foo('a', 'b', true) -- both optional locations omitted
foo('a', 1, 2, 'q', 5, 6, false) -- locations given as separate integer parameters
foo('a', 'm', {1, 7},  true) -- first location omitted, second given as 2-element array
foo('a', some_unit, 'z', {x = 5, y = 10}, false) -- a unit also functions as a location
foo('a', 7, 12, 'q', my_leader, true) -- mixing different forms also works
2021-02-28 18:16:30 -05:00
Celtic Minstrel
dacd5b323e Add some utility functions to help clarify the merge mode being used when assigning terrains 2021-02-28 18:16:30 -05:00