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

93 lines
2.1 KiB
INI

#define CHAMBER_TAG_CONTENTS
max=infinite
{SIMPLE_KEY id string}
{SIMPLE_KEY x unsigned_range_list}
{SIMPLE_KEY y unsigned_range_list}
{SIMPLE_KEY size unsigned}
{SIMPLE_KEY jagged unsigned}
{DEFAULT_KEY chance unsigned 100}
{SIMPLE_KEY side unsigned}
[tag]
name="passage"
max=infinite
{SIMPLE_KEY destination string}
{SIMPLE_KEY windiness unsigned}
{SIMPLE_KEY laziness unsigned}
{SIMPLE_KEY width unsigned}
{SIMPLE_KEY jagged unsigned}
{DEFAULT_KEY chance unsigned 100}
[/tag]
[tag]
name="item_location"
max=infinite
{SIMPLE_KEY id string}
{DEFAULT_KEY place_castle bool no}
[/tag]
#enddef
[tag]
name="generator"
# General Lua map generator
{SIMPLE_KEY id string}
{SIMPLE_KEY name t_string}
{SIMPLE_KEY description t_string}
{SIMPLE_KEY error_message t_string}
{SIMPLE_KEY create_map string}
{SIMPLE_KEY create_scenario string}
{SIMPLE_KEY user_config string}
{SIMPLE_KEY config_name t_string}
# Additional contents for Lua cave map generator
[if]
glob_on_create_map=*cave_map_generator*
[or]
glob_on_create_scenario=*cave_map_generator*
[/or]
[then]
{SIMPLE_KEY map_width unsigned}
{SIMPLE_KEY map_height unsigned}
{SIMPLE_KEY village_density unsigned}
{SIMPLE_KEY transform map_transform}
{SIMPLE_KEY transform_chance unsigned}
{SIMPLE_KEY terrain_wall terrain_code}
{SIMPLE_KEY terrain_castle terrain_code}
{SIMPLE_KEY terrain_keep terrain_code}
{SIMPLE_KEY terrain_village terrain_code}
{SIMPLE_KEY terrain_clear terrain_code}
[tag]
name="chamber"
{CHAMBER_TAG_CONTENTS}
[/tag]
[/then]
[/if]
# Additional contents for Lua cave scenario generator
[if]
glob_on_create_scenario=*cave_map_generator*
[then]
[tag]
name="chamber"
{CHAMBER_TAG_CONTENTS}
[tag]
name="items"
super="scenario"
[/tag]
[/tag]
[tag]
name="settings"
super="scenario"
[/tag]
[/then]
[/if]
# Additional contents for WC scenario generator
[if]
glob_on_create_scenario=*World_Conquest*
[then]
[tag]
name="scenario"
super="scenario"
[/tag]
{SIMPLE_KEY nplayers int}
[/then]
[/if]
[/tag]