wesnoth/data/schema/ai/_main.cfg
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

55 lines
975 B
INI

#define AI_ASPECT_FILTERS
{SIMPLE_KEY turns unsigned_range_list}
{SIMPLE_KEY time_of_day string_list}
#enddef
#define AI_ASPECT_INVALIDATE
{SIMPLE_KEY invalidate_on_* bool}
#enddef
[tag]
name="ais"
min=1
{SIMPLE_KEY default_ai_algorithm string}
[tag]
name="ai"
max=infinite
super="$ai"
{REQUIRED_KEY id string}
{SIMPLE_KEY name t_string}
{SIMPLE_KEY mp_rank unsigned}
{SIMPLE_KEY description t_string}
{DEFAULT_KEY hidden bool no}
[/tag]
[tag]
name="default_config"
min=1
{LINK_TAG "$ai/aspect"}
[/tag]
[/tag]
[tag]
name="$ai"
max=0
{SIMPLE_KEY ai_algorithm string}
[tag]
name="$component"
{SIMPLE_KEY id string}
{SIMPLE_KEY name string}
{SIMPLE_KEY engine ai_engine}
[/tag]
[tag]
name="$generic_lua_component"
{SIMPLE_KEY code string}
{DATA_TAG args 0 1 any}
[/tag]
{./engine.cfg}
{./aspect_complex.cfg}
{./aspect_simple.cfg}
{./recruitment.cfg}
{./goal.cfg}
{./stage.cfg}
{./modify.cfg}
{./micro.cfg}
[/tag]