1062 Commits

Author SHA1 Message Date
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
Elvish_Hunter
bfcbe279a2 [harm_unit]: replaced .__cfg.level with .level in unit objects 2020-10-12 20:57:21 +02:00
Elvish_Hunter
61f7fe4749 [harm_unit]: fixed damage calculation for 1.15.x liminal alignment 2020-10-12 20:53:22 +02:00
gfgtdf
116687c983
fix #5184 [modify_unit]profile 2020-10-04 03:06:33 +02:00
Celtic Minstrel
251e6c3f7a Apply the deprecation standard to the new GUI2 API
This also removes backwards-compatibility.lua altogether.
It's no longer correct in the general case to add backwards compatibility code to this file, so removing it entirely avoids situations where compatibility code is incorrectly added there.

In the C++, this removes the commented-out old GUI2 API entries, and
adds show_dialog to the gui module directly instead of moving it in core.lua
2020-09-27 16:44:28 -04:00
gfgtdf
ebc65c9b00
fix [micro_ai] when called from lua
fixes #5134
2020-09-07 18:10:41 +02:00
gfgtdf
661fc1d8ef refactoor lua gui2 callback code
this refactors the lua gui2 callback c++ implementation
Now the callback infrastructure also supports different
types of callbacks for a single widget. Furthermore
it also supports multiple open gui2 dialogs at the same time.

This now also makes the widget parameter of widget.find
manditory.
2020-09-03 22:08:53 +02:00
gfgtdf
90a5930f21 new lua gui2 widget userdata
lua now has a widget userdata that can be used
to set/get widgets properties as one would
expect, a lot of the set/get_dialog_xy function
were converted into modifiable properties of
the widget userdata. This in particular allows
us to get rid of the strange 'path to widget'
type of arguments of gui2 functions.

It currently generates lot of compiler wanrings,
I will fix this in a later commit.

One of the main advantage is that it makes it
much easier to add new api, previously a lot
of functions where overused, probably because
that was just easier than creatign a new
function. For example set_dialog_value returned
multiple value of listbox objects. (the
compatibility path doesn't support this
particular feature yet but i don't think it is
important, it probably wasn't even used at all,
since it also wasn't documented).

This also adds some new features, like an 'add_item'
function to add an item to a listbox, a 'type'
property of widgets to query the type of a
widget and a 'item_count' property to count the
number of children in an item.

Im still not 100% sure about the
property /function names, in particular:

1) i might rename 'items' to 'elements' or
   'children' in some functions. Not sure yet
2) I might rename the 'value' property to
   'value_compat' to make clear that its only
   supposed to be used by the
   backwards_compat.lua code.

A next step in improving this api might be
to introduce a (reusable!) 'window' userdata
so that the implementaion of wesnoth.show_dialog
would become:
```
function wesnoth.show_dialog(wml, preshow, postshow)
  local dialog = gui.create_dialog(wml)
  preshow(dialog)
  local res = dialog:show()
  postshow(dialog)
  return res
end
```

However this is currently not really possble
since the pure existance of a gui2::window
object blocks the gui1 code (the main game view)
from receiving events. So we clearly cannot luas
gc take ownership of gui2::window objects.
2020-09-03 22:08:53 +02:00
gfgtdf
2a5ba5ace7 add wesnoth.interface.get_items
returns all items on a locations, this allows is to
remove quite a bit of code in the dropping.lua file
of world conquest since that can now just use items.lua
instead
2020-08-26 14:52:07 +02:00
gfgtdf
3df569ae74
fix missing chunk name in [lua] tags with no name= attribute
reported here https://forums.wesnoth.org/viewtopic.php?p=656867#p656867
2020-07-29 18:52:41 +02:00
Gunter Labes
9d673fac2a
Fix typo in deprecation message 2020-04-21 11:13:36 +02:00