1099 Commits

Author SHA1 Message Date
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
Pentarctagon
a0d787d08e
Fix typo in deprecation message. 2020-04-19 11:58:22 -05:00
Pentarctagon
9a0b95f9a0 Separate unit test results from scenario victory/defeat.
This adds an additional `test_result` attribute to [endlevel], intended for use with the automated unit tests. This allows for the unit tests to differentiate a pass/fail result separately from scenario victory or defeat, which allows for more accurately determining the outcome of a test as well as addresses the potential, for example, for a scenario to be expect to pass because of the {SUCCEED} macro but instead passes because the scenario ended as a victory through some other method.

Additional unit tests which were the original motivation for this change are also added as part of this.  They test, as much as possible, that events are executed at all, and are then also executed in the expected order.
2020-04-07 16:45:34 -05:00
doofus-01
182a7bb602
Units - Dunefolk - Falconer branch of Skirmisher line (#4779)
* Units - Dunefolk - first draft at Falconer branch of skirmisher

* Dunefolk - revision to Falconer line

* Units - dunefolk - some progress on falconer standing animation

* Units - dunefolk - attack animations for falconer

* Units - dunefolk - defense and melee (partial) attack anims

* units - dunefolk - WIP lvl3 falconer

* units - dunefolk - revise falconer

* units - dunefolk - animation work on Falconer line

* units - dunefolk - falconer ability diversion revised to affect enemy chance-to-hit. Animation filter/trigger not yet resolved

* units/abilities - dunefolk falconer diversion ability-related animations mechanism

* units - dunefolk - sky_hunter animation frames

* dunefolk/abilities - fix diversion animations to work on die event

* abilities - schema validation induced correction

* abilities - diversion animations - attempt to fix case of undo movement

* units - dunefolk - finish some cosmetic issues for Falconer line

* units - dunefolk - wmlindent

* use on_undo over select in diversionability

undoing can only change the 'diversion' state if the original action also did,
so there is no reason to check it in all 'select' events.

* fixup

* minor clean-up

Co-authored-by: gfgtdf <daniel.gfgtdf@gmail.com>
2020-03-23 17:59:53 -07:00
Gunter Labes
5699db6117
Typo fix 2020-03-11 11:10:03 +01:00
gfgtdf
cd75931f7f
don't call error() on invalid toplevel tag
this code handles wesnoth.persistent_tags which is used by all addons. The previous behviour would mean that an addon that uses wesnoth.persistent_tags wrongly would also break other code that uses wesnoth.persistent_tags like the [item] implementation.
2020-03-08 00:04:25 +01:00
mattsc
705b576c2a data/lua/core.lua: remove trailing white spaces 2019-12-19 07:06:02 -08:00
mattsc
a1de3a0d72 wesnoth.units.find_attack: also return attack index 2019-12-19 07:05:10 -08:00
Celtic Minstrel
55fa2759a1 Fix the test_move_unit_in_circle test
Just needed to extract the unit earlier, so that it wouldn't be counted as blocking itself

Closes #4635
2019-12-14 12:12:29 -05:00
jostephd
bb583c8e98
Merge pull request #4612 from jostephd/lua-deprecate_api-__index-__newindex-simplify
lua: Simplify the __index and __newindex wrappers in wesnoth.deprecate_api
2019-12-14 14:15:09 +00:00
josteph
1df045fba0 fixup! lua: Simplify the __index and __newindex wrappers in wesnoth.deprecate_api 2019-12-14 14:14:12 +00:00
Celtic Minstrel
b8759f8c19 Add some additional cases to the move_unit test, and fix a few issues that they revealed
One of the cases fails due to something in find_vacant_tile - perhaps someone else can figure out how to fix this?

If nothing else, setting check_passability=no in the [move_unit] should do it, but I'd prefer not to have to do that...
2019-12-10 21:16:06 -05:00
Celtic Minstrel
cbd88814c3 Fix #4622 2019-12-09 22:12:39 -05:00
Celtic Minstrel
c366998021 Fix an issue with items and location sets
Fixes #4621
2019-12-07 17:21:03 -05:00