Commit graph

194 commits

Author SHA1 Message Date
Steve Cotton
551357f48b Fix an off-by-one in mapgen's x and y filters, and add unit tests
Fixes the currently suspected root cause of #5108, but requires further testing
to confirm that it fixes that issue.

Closes #6501 (the question of how to test the mapgen filter).

(cherry picked from commit 30f50bac68)
2021-09-01 15:48:32 +02:00
Celtic Minstrel
03ee904513 Update the shroud unit tests and add a few more for cases new in 1.16 2021-07-30 19:22:57 -04:00
Celtic Minstrel
3af768150e Add unit tests for the Lua shroud functions 2021-07-30 19:22:57 -04:00
Pentarctagon
8e2996661f
Prevents logging of duplicate deprecation messages and messages missing timestamps.
Fixes #5942
2021-07-24 18:51:42 -05:00
Steve Cotton
f9fc806fd2 Add a unit test for wesnoth.current.synced_state
The edge-case of calling evaluate_single within an unsynced event was
surprising, and I'm not sure it's correct. However, as we're about to
release the 1.16 branch I think it's better to include that as a test
that the API doesn't change during the stable branch.
2021-07-07 02:09:49 +02:00
Steve Cotton
17edbcb90a When starting or loading a game, warn if the next scenario is unknown
Check that the scenario's next_scenario= exists, and display a warning
if it would lead to an "Unknown Scenario" error. This also checks any
[endlevel] tags in events.

The error message includes the id of the missing scenario, but is mainly
a recommendation to check the forums and report a bug in the campaign.

This version has a short, one-size-fits-all, text for the error message.
2021-06-19 22:22:19 +02:00
Steve Cotton
63bb15b94e Add a unit-test for the backstab ability 2021-06-06 08:45:36 +02:00
newfrenchy83
bf6b09007c
add 'unslowable' and 'unpetrifiable' status (#5788) 2021-05-27 13:35:49 -04:00
Steve Cotton
c560b0efab Add attribute apply_to_vision to [effect]apply_to=movement
When processing [effect]apply_to=movement, if apply_to_vision is 'yes'
(which is the default) then the vision points will change by the same amount.
Previously, it sometimes affected vision and sometimes didn't; for most cases
where it makes a difference, I expect it to be a change from unanticipated
behavior to expected behavior.

Please refer to the new unit test added in this commit for more detailed docs;
that test is also a rough draft for the Wiki update needed when this merges.

The reason it sometimes affected vision was that the special value of -1 vision
points was interpreted as "use the value of the max movement points instead".
The special value of -1 is still supported and frequently used, and refactor that
is out of scope for this commit - it's easy to check when the code path changed
in this commit is used, however it's considerably more complex to find all
routes that create a unit with vision set to -1.

I'm expecting one add-on, Rebirth In Nature, to need a large update for this;
as well as a trivial change needed to the Add Creature Pack.

There are several mods that have their own handling for vision, recalculate the
values frequently, and are expected to continue working as before, as they'll
just overwrite any changes that the engine makes.
* Proper Flying Mod / Proper Vision Mod
* LotI
* Blessed Altar Mod
* Shards Era's `CALCULATE_WEAPONS_ONLY` macro
* Castle of Evil Spirit

Rebirth In Nature is an RPG-style campaign that expects the player's unit to
have vision separated from movement along with right-click menus that change
the character's movement, this will probably need `apply_to_vision=no` in
many places. OTOH, its `item_id=mobility` uses `apply_to=movement` followed by
`apply_to=vision` to implement in 1.14 what this change will make default
behavior in 1.16.

There are a few sharpshooter units which have vision better than their
movement. If given a buff which boosts their movement, this will give
them a buff to vision too; likely a change towards expected behavior.
* Archaic Era's Royal Ranger
* Ageless Era's Royal Ranger and Dwarvish Forest Sniper
* Eastern Europe at War's Yacht and Great Yacht
* Era of More Units's Lone Wolf
* Southernerns has several sharpshooters
* WWII Era has several sharpshooters
* War of Dominions has some guard towers with very low movement

Silver Age has abilities that modify vision based on time-of-day, but unlike
the Proper Flying Mod and LotI these are done by adding and removing objects
that add or subtract one vision point, these should be unaffected by this
change. Unrelated to that, it declares values for `[unit_type]vision=` even
when the value is the same as max moves - like the sharpshooters this means
that buffs to their movement wouldn't have buffed their vision but now do.

There are few units with vision less than movement. Generally these seem to be
missile weapons that are represented as units, and they probably won't meet any
apply_to=movement statements - even if a movement power-up is available, the
player would probably choose a different unit.

The Add Creature Pack has two creatures (the Cactose Elder and Carnivore Fatal
Plant) that have reduced vision, along with AMLAs that increase those units'
movement; these AMLAs will need to use `apply_to_vision=no`. These two
creatures are used in Castle of Evil Spirit, but they won't get enough
experience to get an AMLA there.

Fixes #3356.
2021-05-13 18:02:36 +02:00
Celtic Minstrel
2a1fc43860 Add a versions userdata for a cleaner way to compare and manipulate game versions 2021-05-11 14:50:29 -04:00
Celtic Minstrel
b20e226f30 Unit test to verify that [event]delayed_variable_substitution=no works 2021-05-08 17:15:02 -04:00
Steve Cotton
df41f13e41 Rewrite the WML unit test for sighted events
The old version's [event]name=sighted had a {RETURN} statement in it,
which meant the test stopped on the first sighting. Most of the test
wasn't testing anything.
2021-05-06 01:21:59 +02:00
newfrenchy83
00452c0187
add 'ability_id_active' attribute to filter (#5739)
Add 'ability_id_active' attribute to filter

Until now, only the type of ability could be filtered with activity, and id only for unit who have ability, same if she's inactive.
2021-05-03 14:38:05 -05:00
Steve Cotton
8e315683ae Add wesnoth.colors[name].pango_color and use it in the multiplayer turns-over dialog 2021-04-28 10:44:19 +02: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
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
Celtic Minstrel
5bb0576e17 Add some event filter tests 2021-04-09 23:09:47 -04:00
Celtic Minstrel
7cbc6c9d5d Add unit tests for auto-scoped variables in events 2021-04-09 23:09:47 -04:00
Celtic Minstrel
aa8e171816 Add more unit tests for nested event handlers and a few other things 2021-04-09 23:09:47 -04:00
Steve Cotton
20eb001be3 Unit tests for [effect]apply_to=movement and [effect]apply_to=vision
These would also pass on 1.14, checking that movement does affect vision if and
only if vision hasn't been modified separately. The comments talk about an
[effect]also_apply_to_vision= attribute which hasn't been added yet, the aim of these
tests is to regression test that attribute when it is added.
2021-03-28 17:40:07 +02:00
Celtic Minstrel
9e1677612b Add some unit tests for [terrain_mask] 2021-02-27 21:24:47 -05:00
newfrenchy83
05b2ea2262
Extend special_id_active and special_type_active to account for abilities used as specials 2021-02-18 18:19:35 -06: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
Pentarctagon
093db78cc7 Add the Plan Unit Advance modification to mainline. 2021-02-13 19:16:37 -06:00
newfrenchy83
2168f629fb
Add overwrite_specials attribute to allow forcing a lower chance to hit
The reported issue being that the FORCE_CHANCE_TO_HIT macro was able to force an increase in an attack's chance to hit, but no longer able to force a decrease.
2020-12-14 14:57:59 -06:00
Steve Cotton
72863e578b Add a unit test for resistances (using the standard 6 damage types)
I'm working on a bugfix for the [resistance_defaults] tag, for which the
unit test is going to be out-of-tree until we support some method of testing
it without affecting other tests. The version here is the part of that which
can be in-tree, because it doesn't change the core unit's stats.
2020-11-29 22:30:14 +01:00
Steve Cotton
ffeb80f6ca Add a unit test for the behavior of [unit]id= recalling units
Answers a question raised in PR #4999. This also passes on 1.14.
2020-11-19 16:07:47 +01: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
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
newfrenchy83
ce4fb82173 Filter weapon in [filter student/opponent/etc] rework (pr #4678)
All weapon specials can now be used in [abilities] to effect all weapons of the unit that pass the filter given in [filter_student][filter_weapon].

Explanation: filter_student filters on the unit that is  under the effect of the ability (which is usually the unit itself, but not always if [affect_adjacent] is used).  [filter_student][filter_weapon] filters on the active weapon of that unit (the student) in a specific combat.

[filter_weapon] is now supported in all filter_opponent, filter_student, filter_attacker, filter_defender

Note that constructs like [filter_student][or][filter_weapon] are not suported, [filter_weapon] must be a direct subtag of the four just mentioned tags.
 
[filter_second_weapon] is no longer used for abilities that come from weapon specials.

implements #4629 , #4475 , #4389

Co-authored-by: gfgtdf <daniel.gfgtdf@gmail.com>
2020-01-05 00:27:55 +01:00
Steve Cotton
7359fddecb
Separate unit test statuses for WML exceptions and strict warnings (#4599)
This is part of working out whether a subset of the "fail" tests could be run
in one Wesnoth instance. To run a test that returns TEST_FAIL_BROKE_STRICT with
any other test would require a mechanism to reset lg::broke_strict()'s flag.

All tests that fail with an {ASSERT} will also set the lg::broke_strict() flag,
the tests with the new status are only those that would pass without the strict
flag.

In the SUF tests, change a test from fail-on-success to breaks-strict, rename
the formula tests and add some comments. The rename is because "fai" is
"Formula AI", an obsolete name for WFL.
2019-12-22 19:11:48 +01:00
Steve Cotton
de92d17a6d WIP: Test [move_unit] moving back to the starting hex 2019-12-14 11:31:55 -05:00
Steve Cotton
e50fd80d53
Convert some fail-on-success unit tests to pass-on-success (#4597) 2019-11-25 14:28:03 +01:00
Steve Cotton
16f93cd24c Add a unit test for wesnoth.create_side 2019-11-18 21:00:26 +01:00
Steve Cotton
06dd9a140c Add [find_path] option "nearest_by", and simple_find_path test
Adding this is issue 2 of #4177, changing the behavior when [find_path]
is given a SLF which matches multiple hexes.

The map and tests here should be easy enough for manually editing them. It
duplicates some of the functionality of the existing characterize_pathfinding
tests, however those tests need their expected values to be calculated and
can't be changed by hand.

'''nearest_by''': {DevFeature1.15|2} possible values "movement_cost"
(default), "steps", "hexes". If the [destination] SLF matches multiple hexes,
the one that would need the least movement points to reach may not be the one
that's closest as measured by '''hexes''', or closest as measured by steps,
from the starting point.

Behavior in 1.14 depended on which hex was checked first.
2019-09-11 11:17:56 +02:00
Steve Cotton
1c123fb3fa Allow '1-infinity' in ranges, and tighten the schema's validation of ranges
Fixes #4253.

The schema's validation of ranges now rejects negative numbers, because the C++
code doesn't support them (both before and after this commit):
* utils::parse_range("-7") will return {0,0}, because std::stoi("") throws invalid_argument.
* src/map/location.cpp will parse it as -7, but that will never match an on-map coordinate
2019-08-29 22:28:22 +02:00
Steve Cotton
358f564301 Add unit tests for movement and vision costs
Includes changing the terrain costs, and aliased terrains.

Can be cleanly cherry-picked to 1.14.
2019-07-22 17:18:20 +02:00
Toom
53be0fef39 Add WML unit test for unupgradable (#3336)
* Add WML unit test for unupgradable

* Follow [do_command] requirements

(cherry picked from commit 739df85e1d)
2018-10-28 02:53:08 +00:00
josteph
2f266dde90 Add test for #3663 2018-10-27 20:40:03 +00:00
josteph
2f62302dc7 Healing: Add a unit test. 2018-10-21 17:34:52 +00:00
gfgtdf
a414703946 wml test for cve-2018-1999023
this test whether we succesfully prevent the exceution and parsing of
precompiled lua chunks, which can be used to break the lua sandbox.
This test does not cover all affected functions in particular not the ai
code that loads lua chunks.

(cherry-picked from commit 6b13a63bb0)
2018-10-07 03:23:46 +00:00
Jyrki Vesterinen
1386e3945c Added unit tests about which WML tag names Lua API accepts 2018-01-17 23:23:13 +02:00
Charles Dang
8ae99bc86a Added some event unit tests by @Pentarctagon
Tests event execution order and events with variable names.
2018-01-11 13:12:28 -05:00
Gregory A Lundberg
eaccef65f8 Add WML unit tests for [for] tag 2017-06-21 21:18:24 -05:00
Celtic Minstrel
cb0fad078a WML unit tests for simple aspects 2016-03-22 07:22:22 -07:00
Celtic Minstrel
240b5f61a7 Output formula errors in unit filters to WML error stream
(And consider them to match no units)
2016-03-17 23:27:03 -04:00
Celtic Minstrel
26a2638f2c Make the formula and Lua views of a unit coincide more closely
Several keys were either missing or misnamed in the formula view.
These have been changed to match the Lua and WML names for the keys.
This affects canrecruit, moves, and max_moves, as well as status.

In addition, a large number of keys were missing entirely from the formula view.
Most of these keys have now been added and can be accessed from formulas.
A few that have little use in filters (such as image_mods or profile) are still missing.

The Lua view missed a few keys that the formula view did provide.
Although these could in principle have been obtained by using the special __cfg key,
they have now been added to the Lua view anyway.
2016-03-17 23:27:03 -04:00
Celtic Minstrel
aa2e24d1b7 Finally fix all the [for] issues. Probably.
(With unit tests to back it up!)

- Fixes [for]step=0
- Fixes [for]start,stop=0,0
- Fixes [for]start,end,step=0,1,-1
- Probably fixes several other things too
2015-10-06 13:51:28 -04:00
Celtic Minstrel
7e26e09061 Fix erroneous handling of [break]/[continue] in [elseif] 2015-09-23 00:25:31 -04:00
Celtic Minstrel
aec99429c4 Merge branch 'break-continue' into foreach 2015-09-20 00:48:39 -04:00