1131 Commits

Author SHA1 Message Date
Steve Cotton
6b516e8aa5 Fix deprecation warning when setting [endlevel]end_credits=
Change the Lua implementation to directly call the
non-deprecated function, this is related to 9daa10a9f2.

Clean up the C++ header files by removing the declarations of
functions that were removed in 3c8de46771.

Use [endlevel]end_credits=no in the test scenario (trigger it
by moving to hex 9,3). If you debug with :next_level without
triggering the moveto, "The End" will show; trigger the moveto
first, and it won't show the credits.
2024-02-02 16:04:27 +01:00
Toom
2056be55a3
Support [harm_unit]experience values kill/attack/defend/fight/yes/no (#8231) 2024-01-18 11:32:18 +01:00
gfgtdf
955a8bc445
use game_events.add in on_event.lua (#8082)
use game_events.add in on_event.lua

previously on_event.lua and game_events.add had separate priority lists, so that independent of the priority parameter (which both game_events.add and on_event.lua now support) on_event.lua events were always executed first. 

The set_undoable(true) call is there to match the previous behavior of on_event.lua where events implemented via on_event were undoable by default.
The higher default priority of 0.5 is there to match the previous behavior of on_event.lua where events implemented via on_event.lua were always run before wml events.
2023-12-15 21:28:45 +01:00
Gunter Labes
8b111a2a76 Avoid accessing data of potentially killed unit
Fixes #8019.
2023-11-12 22:12:17 +01:00
Celtic Minstrel
e3b3d08c3f Make wesnoth.allow_undo still work, even though it was explicitly internal and not meant to be used.
Fixes #8018
2023-11-04 22:40:18 -04:00
Celtic Minstrel
9183ee6791 Move the other game_events deprecations into the game_events file 2023-10-15 17:43:22 -04:00
Celtic Minstrel
857d7e120a Undeprecate on_event() for now 2023-10-14 19:26:36 -04:00
Celtic Minstrel
38ae304725 Move Lua undo API into experimental 2023-10-14 19:26:36 -04:00
Celtic Minstrel
10d67aa82a Implement a new Lua API to the undo system 2023-10-14 19:26:36 -04:00
Jonathan-Kelly
14c7382675
Add range support for [micro_ai]side= (#7853) 2023-08-18 20:04:05 -04:00
Celtic Minstrel
d05bc6e444
Update filesystem.lua (typo) 2023-07-23 11:58:21 -04:00
Celtic Minstrel
46ac2ff1de
Update filesystem.lua
The new include_file directive uses the "scenarios" directory as the asset type, so add it to `filesystem.asset_type`.
2023-07-23 11:58:02 -04:00
Toom
9f53c4fd11
fail if [kill] contains [filter], re #4316 (#7717) 2023-07-16 19:47:44 +02:00
Gunter Labes
639fb7158e
Remove obsolete comment 2023-06-13 10:46:15 +02:00
Pentarctagon
ad3f1c95b0 Add support for distinct sub-achievements.
This adds support for having up to 28 distinct sub-achievements within a single achievement. This limit exists since wesnoth's layout isn't smart enough to tell a horizontal listbox to actually use its scrollbar instead of forcing a horizontal scrollbar on the whole window.

Additionally this adds the [set_sub_achievement] and [has_sub_achievement] WML tags and their respective lua functions. [has_sub_achievement] is unsafe for use in MP, for the same reasons that [has_achievement] is.
2023-05-17 23:54:16 -05:00
Celtic Minstrel
d4adbdcf91 Fix [clear_variable] not working on a variable name that happens to be a number 2023-05-09 23:10:26 -04:00
Celtic Minstrel
f7fadba928 Fix compatibility path for helper.set_wml_var_metatable 2023-05-07 14:56:55 -04:00
Severin Glöckner
90df947efe stun: chaneg textdomain
other abilities are in wesnoth-help
the dirdctory containing the files is searched for wesnoth-help
2023-04-15 02:40:17 +02:00
Toranks
2de929e026
Typo hander > handler (#7464) 2023-03-20 19:36:52 -05:00
Pentarctagon
e61fca0bf4
Small achievements cleanup (#7368)
* Move logic into lua engine code.
* Don't let use of limit decrease an achievement's progress.
2023-02-09 18:36:45 -06:00
Pentarctagon
18838ecebc Give a better warning when amount isn't a number. 2023-02-05 09:42:35 -06:00
Steve Cotton
0a0263e54f Support [foreach]array=this_item, nested loops using the default name
Since a0ee38a49, the inner this_item was still in scope when the inner loop
writes changed data back to the outer loop's variable, which meant that
changes were silently ignored.

A lot of the changes in wml-flow.lua are just indentation because of the
extra block.
2023-02-05 04:34:23 +01:00
Steve Cotton
49ebbb9709 Make fix_whitespace complain about mixing tabs and spaces
Ensures that files either use tabs for indentation or spaces for indentation,
but don't switch between the two within the same file.

This doesn't fix the whitespace, it's a simple check to flag it up
on the assumption that it's better to use an editor or code formatter
to clean up the file.

Elsewhere in the CI we use the luacheck tool - while that can detect
mixing tabs and spaces in a single line's indent, it doesn't check for
inconsistent indentation within a file.
2023-02-05 02:22:53 +01:00
Pentarctagon
e3bb346b39 Add functionality for achievements to be partially complete.
Instead of being either complete or incomplete, achievements can now specify a value at which they will be considered complete. For such achievements that are not yet complete, a progress bar is added to the achievements dialog showing how close to completion the achievement is.
2023-02-04 15:43:28 -06:00
Celtic Minstrel
cc40d5c55b
Move the Merman Citizen and Brawler units to core (#7323) 2023-01-26 22:45:29 -05:00
Pentarctagon
d1465a9eb9
Add basic achievements functionality. (#7237)
* Add basic achievements functionality.

This reads the mainline achievements.cfg and then all the achievements of each installed add-on.

This is intentionally handled separately from other WML loading so that:
a) All achievements and their status are able to be displayed on the main menu right after Wesnoth starts and regardless of which add-ons are active.
b) Add-ons can add additional achievements to other content, whether UMC or mainline. For example, a modification that adds more achievements for mainline campaigns.

Marking something as achieved is handled by the new [set_achieved] tag and whether an achievement has been completed can be checked via [has_achievement].

There is no attempt to prevent people from manually editing which achievements they've accomplished.

NOTE: These are *not* in any way related to Steam achievements!
2023-01-21 10:32:45 -06:00
Celtic Minstrel
7d5fa80180
WML: Adjust the weapon selection logic for [kill] (#7196)
* WML: Adjust the weapon selection logic for [kill]

The previous logic simply did not make sense, especially for the secondary weapon.
For example, it would ignore the secondary weapon specification if the primary weapon was not found on the secondary unit, which does not make any sense.

The cases that this changes are:
- There is a secondary unit and a primary attack, but no matching attack was found. Previously it would use the default, now it pretends that attack exists.
- There is a secondary attack specified, but no primary attack, either because it was unspecified or because it didn't match any attack on the secondary unit

In both these cases, the animation runs as if a matching attack exists, rather than using no attack and choosing the default animation.

Adjust the log level too.
2022-12-24 16:52:57 +01:00
Celtic Minstrel
6d3dd6a175 Support as_type=weapon in [variable]formula= 2022-12-06 01:52:38 -05:00
Celtic Minstrel
6876695e66 Support as_type=unit in [variable]formula= 2022-11-27 13:12:47 -05:00
Celtic Minstrel
516f043e89 Support name= in [lua] ConditionalWML 2022-11-27 13:10:41 -05:00
Steve Cotton
e3deff8bfd Make undo work again, undeprecate on_event()
Fixes #6898. The issue is that non-WML events added through the new events API
always disable undo with no equivalent of WML's `[allow_undo]`. The long-term
fix is to add a way to do that; however until that's available then listeners
for `moveto` need to use the old `on_event` API. The old `on_event` API can't
be deprecated yet, and this is enforced by our unit tests (the build fails if
there are unexpected deprecation warnings during the tests).

Reverts most of 7e234f8833282424b3535b9c334c751748f7222b. Does not revert files
that only listen for non-undoable events such as `die` or `new turn`.

Reverts the deprecation part of #5663's 8cd133263058a5df85f64988e348d2cf54d13a48.
2022-11-19 05:23:30 +01:00
Severin Glöckner
640c08b7f5 Lua: crash peacefully with [move_unit]
If there is an issue with to_x or to_y, such as a missmatching number of values, or none,
then the function is aborted by the 2nd/3rd wml.error statement.

At that place, current_unit:extract() was already called, so the function
would not only fail, but also remove the unit.

This commit unstores the unit prior to aborting.
The alternative of extracting the unit later would break the tests,
as it is then still using the hex, which is then not available to pathfinding.
2022-10-26 23:32:10 -05:00
Severin Glöckner
a748126b75 Lua: don't trigger unit placed events by WML tags
If the last argument to the C++ function ( game_lua_kernel::intf_put_unit )
is false, event's won't be fired.

closes #5158
2022-10-26 23:32:10 -05:00
Pentarctagon
a5e7986b3e Updates for newer luacheck. 2022-08-06 03:03:17 -05:00
Wedge009
461fd5fff5 Replace deprecated wesnoth.fire_event with wesnoth.game_events.fire. 2022-07-30 16:32:31 +10:00
Celtic Minstrel
0f3d8388df Fix deprecation warning in [kill]
Fixes #6924
2022-07-29 23:37:36 -04:00
Tommy
3127178e17 Add a submerge value to items, to control submerge amount
It defaults to 0, which is no submersion.
2022-07-30 14:56:38 +12:00
Celtic Minstrel
e08451517a Fixup some event deprecations
No functionality change, just documentation
2022-07-26 00:08:00 -04:00
Celtic Minstrel
7e234f8833 Replace deprecated usages of on_event() 2022-07-18 21:56:42 -04:00
Celtic Minstrel
5a184bbb40 Split wesnoth.game_events.add into multiple functions
Basically this means each of the call modes of the old function is now a separate function.

- add_repeating and add_menu take an ID and a function
- add_wml takes variable substitution setting and a config
- add takes the full options table
2022-07-18 21:56:42 -04:00
Celtic Minstrel
19c62a083e Update [remove_event] to use new API 2022-07-18 21:56:42 -04:00
Celtic Minstrel
8aa2ee74a2 Move the event firing functions to wesnoth.game_events
* These functions take the full event data config as the final argument, rather than just the weapon info subconfigs.
* The [fire_event] tag now supports a [data] tag that can add additional data to the event, for example damage_inflicted. The [primary_attack]  and [secondary_attack] tags are still supported and are not deprecated.
* wesnoth.current.event_context now has a data child which holds the full event data. It still duplicates common info (weapons and damage inflicted) in the same way as before.
2022-07-18 21:56:42 -04:00
Celtic Minstrel
8cd1332630 Enable setting an arbitrary Lua function as an event handler.
Unlike the old wesnoth.game_events.on_event hook and the "convenient" on_event() wrapper for it, this new functionality supports all of the features of WML events, with the sole exception of serialization, since it's not possible to reliably serialize a Lua function.

This commit also divorces menu items from the event that they trigger. The undocumented wesnoth.interface.set_menu_item function no longer adds an event for the menu item; the caller needs to separately register an event using the new functionality.
2022-07-18 21:56:42 -04:00
Tommy
8144c06389
Add new [screen_fade] WML action (#6864)
* Add new [screen_fade] WML action

It takes (for now) the arguments:
 * red, green, blue = values between 0 and 255
 * alpha = value between 0 and 255
 * duration = time in ms over which to fade

The game display is faded to the given colour over the duration.
It will be left with an overlay of that colour and alpha until
a screen_fade to 0 alpha is performed.
2022-07-15 09:32:19 -04:00
larry_the_cow
8d91bc69a2 [harm_unit] fix secondary_attack animation 2022-06-27 23:17:31 -04:00
Celtic Minstrel
1af084515f Exclude deprecated things from dir() 2022-06-20 20:54:28 -04:00
Celtic Minstrel
d104a81269 Lua API: Make the WML module dir-friendly 2022-06-20 20:54:28 -04:00
Celtic Minstrel
e2875f34b2 Fix a bunch of luadoc errors 2022-06-11 00:15:18 -04:00
Celtic Minstrel
e635161957 fix wesnoth.type giving an error on tables or userdata without a metatable 2022-06-10 23:31:41 -04:00
Celtic Minstrel
a76aa9bddc
Add wesnoth.interface.add_floating_label as a replacement for wesnoth.print (#5837)
This returns a label handle which allows you to remove, reposition, or replace the label later.

In addition to all the features of wesnoth.print, you can now specify where the label appears onscreen, as well as a fadeout time separate from the duration.

You can also anchor the text to an edge or corner instead of centering in on the screen,
specify the maximum width it can occupy as an absolute width or a percentage,
and specify a background colour and transparency.

It includes a demo scenario that demonstrates many of the capabilities of the API.
To play the demo scenario, run with -toverlay_text_demo or select it from the in-game test list.
2022-04-10 13:00:29 -04:00