Commit graph

1122 commits

Author SHA1 Message Date
sigurdfdragon
f67f28d7a9 Fix deprecation message 2021-05-03 11:26:40 -04:00
Steve Cotton
24e2f8f767 Whitespace fixes for no newline at end of file
The new CI script whitespace-checking script changes these, but not on Linux.
2021-05-03 11:52:40 +02:00
Pentarctagon
454130fd94
Fix trailing whitespace. 2021-04-25 21:58:20 -05:00
Celtic Minstrel
31421f3558
Add a Lua unit_test module only available in [test] scenarios (#5708)
It contains fire_wml_menu_item along with a set of new assert functions
2021-04-25 21:04:50 -04:00
Pentarctagon
d203b061f9
Whitespace cleanup of lua files. 2021-04-25 15:11:09 -05:00
Hejnewar
f5ea3b0906
Update code of [unstore_unit] 2021-04-22 01:32:06 +02:00
Steve Cotton
ad1c42ca8f Make [store_reachable_locations]range=vision calculate vision
Previously it calculated max movement, and then added the adjacent hexes. This
version should correctly handle:
* units with vp different to max mp
* units with vision costs different to movement costs
* jamming by enemy units

Draft changelog entry for this:
* `[store_reachable_locations]range=vision` now calculates vision, instead of using movement costs and max movement points (issue #4179)
2021-04-16 02:05:42 +02:00
Steve Cotton
147cd90527 Move lua implementation of [store_reachable_locations] to its own file 2021-04-16 02:05:42 +02: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
e0c1ac2626
Fix [unstore_unit]x,y=recall,recall
Fixes #5604
2021-03-12 19:46:35 -05:00
Celtic Minstrel
37fde7aaee
Allow hex references to hold auxiliary user values 2021-03-06 18:44:29 -05:00
mattsc
cadb233d6c Update some deprecated Lua uses 2021-03-06 15:08:54 -08:00
Celtic Minstrel
a2d7a26365
Fix several Lua issues, mostly unintentional globals (#5587) 2021-03-06 17:01:53 -05:00
mattsc
44e279cb2f Lua location_set: fix a variable name 2021-03-06 10:53:02 -08:00
Celtic Minstrel
c7b2dcca3f Oh look, a deprecated thing that was missed sometime in the past 2021-02-28 18:16:33 -05:00
Celtic Minstrel
9d3bf196b0 Update everything to use the new wesnoth.map module
- get_terrain and set_terrain replaced with direct indexing operations
- get_map_size mostly replaced with either the iterator or an on_board call.
  Only a few cases really needed to know the size of the map for some other purpose.
- shroud and fog operations, village owner, time areas, and location filters
- get_terrain_info replaced with terrain_types table
- Map generation functions create_map and create_filter
2021-02-28 18:16:33 -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
Celtic Minstrel
f473aabe99 Add another note in [test_condition] for a simple case of using [have_location] to verify that a hex has a particular terrain 2021-02-27 21:24:01 -05:00
Celtic Minstrel
a97a04e2e9 Update [test_condition] to be a little more verbose and make use of newer features 2021-02-27 19:43:42 -05:00
Celtic Minstrel
1dca42ca0e
Fix [modify_side]reset_maps=true
I have no idea how this was missed...
2021-02-22 09:52:56 -05:00
Celtic Minstrel
862668911a Split core.lua up by module to make things easier to find
Core is now a directory instead of a file. The Lua kernel automatically loads all files in that directory when it starts up.
2021-02-20 21:32:29 -05:00
Celtic Minstrel
0802779f9e Found a deprecated thing not in WC 2021-02-20 16:12:49 -05:00
Celtic Minstrel
bb7483d456 Add a deprecated stub for math.pow 2021-02-20 16:12:48 -05:00
Celtic Minstrel
56bdd42815
Fix segfaults and a few other issues in wesnoth.find_path
Co-authored-by: mattsc
2021-02-18 22:15:31 -06:00
Celtic Minstrel
d2734973ed Add a command-line option that makes deprecated Lua stuff evaporate 2021-02-16 20:40:18 -05:00
Celtic Minstrel
a019edb26c
Fix cave map generator producing passages along the map border
Maps are 0-indexed even in Lua (so that 1 ends up as the lowest passable coordinate), so subtract 1 here

Closes #5407
2021-02-16 13:46:01 -05:00
Celtic Minstrel
a0ee38a49a
Use to-be-closed variables to scope WML variables in tag definitions (#5536) 2021-02-15 21:11:56 -05:00
Celtic Minstrel
438b661494 Avoid map borders in cave generator
Addresses #5407
2021-02-15 18:35:54 -05:00
Celtic Minstrel
7e699ca398 Fix a deprecate_api bug 2021-02-15 16:28:14 -05:00
Celtic Minstrel
c52b71bffd Add a deprecated declaration for unpack so that any older add-on code that uses it still works 2021-02-15 14:26:59 -05:00
Pentarctagon
7349ac65e0
lua unpack -> table.unpack
lua 5.4 apparently fully did away with the former.

Fixes #5546
2021-02-15 12:11:48 -06:00
Pentarctagon
093db78cc7 Add the Plan Unit Advance modification to mainline. 2021-02-13 19:16:37 -06:00
MrTitainin
8db66e8551
Fixed lua [teleport] code
And changed [unstore_unit] to use table.unpack for shorter code
2021-02-11 19:45:21 +01:00
MrTitainin
add999b9d5
Fixed unstore_unit lua code (issue #5519)
x,y were both binding to whole table instead of their expected values
2021-02-06 16:10:59 +01:00
doofus-01
2a8baa9590
various small fixes (#5495)
* units - set image_icon for sidebar display of Cataphract

* units - remove inactive ability description for Diversion

* add recruit/recall to event list triggering check for diversion animation (Dunefolk Falconer)
2021-01-24 16:59:54 -08:00
Celtic Minstrel
4b2599864a Add [set_variable]min|max= to calculate an extremum value 2020-12-28 15:56:36 -05:00
Celtic Minstrel
927fcbfb47 Add [set_variable]reverse=yes for string reversal operation 2020-12-28 15:56:36 -05:00
Celtic Minstrel
651090cf47 Fix erroneous deprecation warnings from [random_placement] 2020-12-20 15:17:26 -05:00
Steve Cotton
b8f03c40e6 Fix [store_unit_defense] and add [store_unit_defense_on], add unit test
The existing tag has a confusing name - it returns the chance to be hit rather
than the defense, for example 30 would be returned for a unit on 70% terrain.
The new tag returns a higher-is-better value.
2020-10-28 22:10:46 +01:00
Steve Cotton
28cd5f1e6e Show a deprecation message for [event]remove=yes, recommend [remove_event]
The remove attribute for [event] was never added to the validation schema,
and using [remove_event] seems easier to search WML for. Let's just recommend
the new key and deprecate the old one.
2020-10-19 00:05:45 +02:00
Celtic Minstrel
6a27473c11
Merge pull request #5188 from wesnoth/sota_zombie_trans
Refactor translatable strings for the SotA zombie recruit dialog
2020-10-12 15:38:54 -04:00
Celtic Minstrel
24d8a249fa Fix [set_variable][join] failing on boolean values 2020-10-12 15:37:37 -04:00