Commit graph

194 commits

Author SHA1 Message Date
newfrenchy83
b5805eca8f
Add priority and filter to overwrite specials (#7746)
using overwrite_specials alone means that we have only two possibilities, either one_side is chosen and in this case if the ability used as a weapon carrying the attribute is applied to the unit (apply_to=self), the other abilities are the same type applied also to 'self' not carrying the attribute will be overwritten, but those of the opponent with apply_to=opponent will be kept in the list; or else both_sides is chosen and all abilities of the same type that do not carry the attribute will be overwritten. To be able to use the attribute in abilities like [damage] for example, it is necessary to be able to be even more selective as for a 'charge' type leadership with multiply=2.5 but which must not be combined with the classic charge and without overwriting the aute [damage] as backstab, [overwrite_filter] to only match damage with apply_to=both and active_on=offense is then interesting.

adding priority allows you to select that it ability can use its overwrite_specials attribute while the others can be overwritten in the same way as an ability without the attribute. Finally, this system makes it unnecessary to limit the use of the attribute to abilities used as weapons but also to special weapons.
2023-10-08 10:09:31 -05:00
newfrenchy83
2a4a073da4 Add tests for ranges and negative values in ability filters
Changed to use "-" instead of ".." as the separator by octalot,
but I believe newfrenchy83 prefers "..".
2023-08-11 21:59:06 +02:00
Steve Cotton
cc8dddea6e Support negative numbers in ranges
Adds support for using these in the weapons and ability filters:
* "-1", which was previously treated as an parse error (no number before the separator).
* "-3--1"
* "-infinity" as the lower number in the range, provided a different upper number is given.

This treats "-infinity" (with no other number), "-infinity--infinity",
"infinity" (with no other number) and "infinity-infinity" as errors. It seems
unlikely that someone would intend to use a filter that can't match any
reasonable number.

The range "-infinity-infinity" will be parsed successfully. I don't see a use
case for that, but nor do I see a reason to add extra C++ to reject it.
However, it's not added to the schema, as I think it's good for the schema to
give a warning when someone creates a filter which will accept every value
(including accepting the default, so "-infinity-infinity" accepts the unset
value too).

Includes new unit tests for the C++ and the Lua stringx.parse_range functions.
The next commit adds more WML tests, but is kept separate to credit the author.

This started as a change to move common filter functions from unit.cpp to
somewhere that they could be reused for other config-based filters. In the
process a missing feature was found and added, the move is still included in a
single Git commit because the move was required in order to make these
functions accessible to the Boost unit tests.

Two CodeBlocks project files additionally get src/utils/any.hpp added,
which was in one of them but missing from the other two. I noticed because
these are alphabetically at the start of the src/utils file list.

Thanks to @CelticMinstrel for the review comments and Xcode project updates.
2023-08-11 21:59:06 +02:00
Ivo Julca
5ebc9a790a Implement event priority
For any given event name, events execute in order of decreasing priority.

Priority is a real number, and may be assigned via the `priority` attribute for
the WML [event] tag, or through the Lua APIs:

- wesnoth.game_events.add({priority = number})
- wesnoth.game_events.add_repeating(name, action, [priority])

Note that delayed variable substitution is not currently supported in the WML attribute.
2023-08-11 08:34:43 +02:00
Cody Burchell
71e83f7b85
Prevent duplicate advancements from being added to unit type (#7743)
* Add myself to Miscellaneous Contributors

* types: Add unit tests over adding advancements
2023-07-09 05:08:10 +02:00
Steve Cotton
1efa0c8c54 Add a test for formulas in taught abilities
Originally by gfgtdf, this was cherry-picked from gfgtdf's PR #7589, with
modifications.

COMMON_KEEP_A_B_UNIT_TEST gains support for optional args
SIDE1_LEADER and SIDE2_LEADER.
2023-07-06 16:57:27 +02:00
Toom
b86b6efd0e
Create test for special_id_active in the style of eoma_beam (#7713)
Test created to verify that special_id_active does not work in 1.16.0.

https://github.com/inferno8/wesnoth-Era_of_Magic/issues/30
https://github.com/inferno8/wesnoth-Era_of_Magic/pull/54
2023-07-04 11:28:39 +02:00
Steve Cotton
1ecc30972e Test weapon-special plague vs taught plague
The expectation is that the a unit's own weapon special will take
priority over a teacher's ability.
2023-07-02 18:54:17 +02:00
newfrenchy83
f9a94e1312 [1.17] add [filter_ability] in [filter] events and [effect]remove_ability and [filter_ability_active] in [filter] events
see https://forums.wesnoth.org/viewtopic.php?p=681371#p681371 in forum

the type of ability used is also filtered.
2023-05-09 19:26:10 +02:00
gfgtdf
9530ad1bc7 add test for no [side]s in [scenario] 2023-05-09 16:50:50 +02:00
Steve Cotton
7540c8f471 Rename test_terrain_mask_simple_name_fail to ..._ignore
I want to reserve names ending `_fail` or containing `_fail_` for tests
that do not expect the `TEST_PASS` status.
2023-05-07 11:10:06 +02:00
Miguel Magno
5e1d9ba600
Fix modify_unit recall_cost indexing issue
Fix issue #7159 apply_to recall_cost to use 0 based side index instead of 1 based side

Add test for issue #7159 modify_unit recall_cost
2023-04-21 13:32:02 +02:00
Steve Cotton
e5b4f5f8a3 More unit tests for attack_filter
Add `first_time_only=no` to some existing tests, and verify that events that
should only trigger once do trigger exactly once.

A new test of `[filter_attack]` when an event lacks attack data. In testing,
I found that it used to trigger a warning that I thought was useless code, and
had removed during 88439d6427a81a6b131acd8b0f7bf04b2d981d71's review. I think
removing it is still good, at the time that the filter was checked it would have
warned "attempt to filter attack for an event with no attack data."
2023-04-19 01:17:06 +02:00
Steve Cotton
eb12a752f4 Add a test for attack_filter with melee-only vs ranged-only units
A new test of what happens when a unit with only a ranged weapon fights a
unit with only a melee weapon. This commit is just the test, it depends on
the engine fix in a previous commit.

This only tests the filtering so far. There should probably be another
additional test to check what the combat results are, however that would need
an ability such as the Deep Elves' Stardust that passively affects the amount
of damage taken. It can't be tested with Slows, as that needs the defender to
hit with a weapon first.
2023-04-18 17:29:49 +02:00
newfrenchy83
88439d6427
Fix a bug in [event][filter_attack] when trying to use special_id/type_active to detect a special whose activity is conditional. (#7509)
When we try to trigger an event conditioned by the use of a special whose activity is subject to a condition, we cannot use special_active because the specials are always considered inactive. Additionally, abilities used as weapons possessed or taught by a leadership are also not detectable in [event][filter_attack]. This PR is there to remedy this double problem.

Also remove matches_special_filter and directly use matches_filter.
2023-04-11 19:34:28 +02: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
Celtic Minstrel
cbbd34a79e
Add new attacks_used key to [attack] (#7351) 2023-02-04 19:55:04 +01:00
Toranks
ec8ad5f26f
Unit tests to evaluate behavior with max_experience=0 and with no advancements (#7344) 2023-02-04 13:14:44 +01:00
Steve Cotton
fba0970509 Add a unit test for scoped arrays
The existing test for scoped vars is both copied and renamed.
2023-01-24 21:02:35 +01: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
Kingofd
492c20baa6
Add exclusive unit traits handling similar to require_amla (#7109) 2023-01-19 13:49:39 -05:00
Toranks
092fd23758
Test fire_event of kill unit on recall list (#7283) 2023-01-16 13:25:09 +01:00
Steve Cotton
e28f29b4ac Add unit tests for weapon-special calculations
Covers the math for [attack]add=, [attack]divide=, [attack]multiply= and
[attack]sub=. The behavior is the same in 1.16.

* 5 + 2 = 7
* 5 - 3 = 2
* 5 + 2 - 3 = 2. Yes it does, that's half of why this unit test exists ...
* 5 + 2 + 3 = 8
* 5 + 3 + 2 = 8
* 5 + 2 - (-3) = 7
* 3 * 3.34 = 10
* 3 * 3.334 = 9. ... and that's the other half of why this unit test exists.
2022-12-29 15:40:01 +01:00
Steve Cotton
a9d5c6ac6d Handle out-of-bounds side numbers in Lua's sync.evaluate_multiple
Change the C++ to show a Lua error instead of crashing with an assert.
2022-12-16 16:40:46 +01:00
Pentarctagon
12a7f018e0 Document last batch of unit tests. 2022-12-03 23:29:47 -06:00
Steve Cotton
38fdf06fa9 Fix [special_note] duplication when unstoring units
The movetype's special notes were becoming a new note for the individual unit.

Clean up the documentation on some of movetype's functions, as they had
documentation in both the .hpp and the .cpp.
2022-11-29 11:40:11 +01:00
Steve Cotton
3d4812ebc8 Add a unit test for the preprocessor's #ifdef handling
This one's surprising, but it's the behavior of 1.16, so add a test for the
current behavior even though I wonder if it should change in 1.17.
2022-11-26 14:55:33 +01:00
Steve Cotton
710867e010 Add unit tests for interpolated event names and end_turn
Move `event_name_variable_substitution` to the top of the file, as it's testing
that the event triggers at all, before the tests that check which order the
events are triggered in.

The old `order_of_variable_events1` seemed to be a combination of two tests that
should exist, but the code didn't quite test either of them. This replaces it
with a new `order_of_variable_events1` and `order_of_variable_events3`.

Docs partially written by Pentarctagon, this started as a review comment
on the documentation PR.
2022-11-25 12:16:46 +01:00
Pentarctagon
a2491d3aa4 More unit test documentation. 2022-11-23 16:25:37 -06:00
Pentarctagon
b1587223a1 Add some more unit test documentation.
Also split some larger tests into multiple smaller tests.
2022-11-13 16:35:06 -06:00
Steve Cotton
b18b0e0f55 Add unit tests for [break] and [return] during [fire_event]
Fixes #7084.
2022-11-05 06:21:30 +01:00
Pentarctagon
16b900c273 Add documentation to more WML unit tests. 2022-11-02 15:16:23 -05:00
Pentarctagon
e37e576f12 Add documentation to more WML unit tests. 2022-10-25 11:29:48 -05:00
Steve Cotton
b74216d6c8 Unit tests for changing abilites with filters in [event]name=attack
The existing backstab tests' common code is moved to a utility file
for reuse in other tests, because it can be used to check whether a
weapon special was active during the damage calculations.

Git's diff can show a lot of lines being deleted, but that's just
because it's showing a file being copied, and then half of each copy
being removed.
2022-10-21 20:26:12 +02:00
Pentarctagon
8bc084bc0b Add tests for pre_attack event. 2022-08-10 09:07:30 -05:00
Celtic Minstrel
8a72206f02 Unit tests for the new filter options 2022-07-18 21:56:42 -04:00
Celtic Minstrel
245cd57d24 Unit tests for each way of assigning an action to an event handler 2022-07-18 21:56:42 -04:00
Celtic Minstrel
666571caa2
Fix load_string() ignoring the passed chunk name (#6794)
Complete with a unit test!
The test results in PASS_BY_VICTORY if it fails,
which is a bit weird, but it does work.
2022-06-24 01:49:28 -04:00
Celtic Minstrel
be8783154e
Add event unit tests for dynamic filters and names (#6785) 2022-06-21 22:25:01 -04:00
Steve Cotton
0f6a94f2a7 Unit tests for [drains], [poison] and [slow], with apply_to=opponent
Slightly different to PR #6582, which was the 1.16 version of this. The five
lines that were labelled `preserving known bug` are changed to test that it's
been fixed.

Here `apply_to=opponent` means that the weapon special gives the opponent the
ability, the unit that should get poisoned or slowed is the unit that has the
weapon special.

There's a known bug in 1.16, that `apply_to=opponent` check the wrong unit to
see it it's `unpoisonable`, `undrainable` etc. It also checks the wrong unit to
see if it's already poisoned or slowed, so a battle between two units that both
have reverse-poison results in at most one being poisoned.

Most of the credit for this is Newfrenchy's, as he's already written a fix
and a WML based test. This commit uses a Lua test instead to test more
combinations of statuses.

This adds a `COMMON_KEEP_A_B_UNIT_TEST` macro, which is a counterpart to the
`GENERIC_UNIT_TEST` macro that starts the leaders next to each other, ready
to attack. The `A_B` is because I'm planning a multiple-side variant too.

There's no test for [petrify], as simulate_combat doesn't provide a stat for it.

This tests only 3 of the 6 abilities whose behavior changed in 650f70405f.
My thoughts on testing the others are:
* [firststrike]'s test is in 650f70405f.
* [drains], [poison] and [slow] are tested here.
* [petrify] ends combat, it's also not exposed in simulate_combat's stats.
* [plague] triggers after combat ends.
2022-04-19 15:27:49 +02:00
newfrenchy83
650f70405f
fix [firststrike] special with apply_to=opponent crashes Wesnoth 1.17.x (#6574)
As reported on the forum in https://forums.wesnoth.org/viewtopic.php?p=672374#p672374
If a unit with "last strike" ([firststrike] special with apply_to=opponent, on any of its attacks)
was targeted by other unit for attack, wesnoth crashed.

Fix similar problems for other weapon specials like poisons, when two users of specials with
apply_to=opponent fought, one fighter only could be poisoned or slowed.

* Add a unit test for poison
* Add a unit test for firststrike and laststrike
2022-04-08 02:30:14 +02:00
Steve Cotton
071ba9d7d6 Add a unit test for [move_unit]location_id with an occupied hex
(cherry picked from commit ba1767f8b9)
2022-03-31 09:33:13 +02:00
Steve Cotton
2888f0417d Add unit tests for Lua API wesnoth.simulate_combat
(cherry picked from commit d96968b2ec)
2022-03-23 07:43:10 +01:00
Wedge009
f983a998a2 Replace deprecated share_maps and share_view with share_vision.
Closes #6496.

share_maps=yes -> share_vision=shroud
share_view=yes -> share_vision=all
2022-02-15 22:08:03 +11:00
Steve Cotton
556c66e4d0 Refactor the backstab unit test
Based on Pentarctagon's documentation addition, and also improving
the encapsulation of the test to take a boolean value for whether
the ability should be active instead of the expected damage total.
2022-02-02 20:46:37 +01:00
Steve Cotton
eacf26a2a8 Fix [store_unit]'s stored coordinates for recalls
Units on the recall list might have x,y coordinates that are on the map, which
therefore need to be replaced with "recall,recall" within [store_unit]. The
existing code created a temporary variable, changed the coordinates, and then
returned the unchanged original instead of the temporary.

Add a new test that `[put_to_recall_list]` followed by `[modify_unit]`
doesn't move the unit back to the map.

(cherry picked from commit 096d8aba14)
2022-01-12 06:57:35 +01:00
newfrenchy83
17e0c244ab add wmlindent in test and comment
i'm not sure to have implemented wmlindent correctly, i hope don't done error.
2021-12-09 18:04:24 +01:00
newfrenchy83
3e70b335da fix 'add' and 'sub' not added in leadership shema validation 2021-12-09 18:04:24 +01:00
Luther
bff219d41f
Expand the reduce function to both fold and reduce (#6337) 2021-12-04 17:46:12 -05:00
Steve Cotton
69ee817955
Remove the fast path of [modify_unit] (#6223)
Always use the "slow path", because it stores and unstores the unit, triggering
the desired side effects of unstoring a unit.

Fixes issue #5133, and tests that with the new unit test.

Fixes bug #4978, that changing the facing wasn't updating the display.

This corresponds to 1.16's commit 13c5d8a96e,
that commit merely disabled the fast path to be a minimal change.
2021-11-05 21:39:38 +01:00