Commit Graph

51 Commits

Author SHA1 Message Date
Binrui Dong 9e9d726e3f Fix struct name collision 2021-01-28 23:04:35 -05:00
haveric c380afc798 Fix spelling issues (#45878)
* JSON description spelling fixes
* Markdown + txt spelling fixes
* Fix FLAMMABLE_ASH flag for butchering rack
* Fix result spelling of southwest
* Fix cephalopod achievement id spelling
* unsually is probably unusually
* Fix spelling in dynamic line
* Simple comment/text spelling fixes
* Fix variable/enum spellings
* Fix function spelling issues
2020-12-08 16:46:14 -08:00
John Bytheway b0ce494cdc Filter out non-empty invalid field values
event_field_transformation functions shouldn't need to be written
defensively against invalid inputs.  So, pre-check the arguments and
don't call the function if an argument is invalid and non-empty.

We're already relying on them supporting empty arguments, so we can't
filter those out.  Maybe in the future those empty arguments should be
replaced by null instead.
2020-10-12 08:20:34 -04:00
John Bytheway ace80ed46e Deactivate achievements_tracker for past games
When building achievements_trackers for past_games_info, these
achievements_trackers were setting up their full-featured infrastructure
of watchers.  This serves no purpose, because no new events will occur
for these past games, and we only really want these
achievements_trackers for their info about already-completed
achievements.

Add a new options to achievements_tracker to disable these watchers and
use it in this case.
2020-10-12 07:35:06 -04:00
ZhilkinSerg c8ac2d2ef0 Removed non-utilized variables 2020-08-23 02:56:39 +03:00
Kevin Granade 3888b13fac Clear global stats tracker in tests (#43042)
* Clear global stats tracker in tests

* Clear stats tracker in memorial test too
2020-08-20 10:22:48 +03:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
Kevin Granade 346d4c19fa Make several more members private in game (#42255)
* Make scent_map private in game

* Make timed events private in game.

* Make achievements tracker private in game

* Make memoial tracker private in game

* Make scenario variable private in game
2020-07-20 10:20:58 +03:00
nexusmrsep 6e29528124 Re-colorize achievements UI (#42228) 2020-07-19 11:22:52 +03:00
Kevin Granade 2ef8971308 Make game::stats() private 2020-07-18 04:39:19 +00:00
Kevin Granade 1ea5556a41 Global reference migration part 32 (#42215) 2020-07-17 12:59:41 +03:00
Kevin Granade f95326e8ad Global reference migration part 30 (#42208) 2020-07-17 12:58:14 +03:00
John Bytheway c92d8ae73e Allow event_statistics to extract first & last
Similar to unique_value, add first_value and last_value.

Add some stats & achievements using them.

Add some unit tests.
2020-06-04 22:11:04 -04:00
John Bytheway 1bfb4a5ef6 Factor out some common test code 2020-06-04 21:51:59 -04:00
John Bytheway 7603fd1b54 Expand event counts to summaries
Previously we kept only counts of events (partitioned by field values).
Convert that int to a new class event_summary, which also contains
time_points for the oldest and newest events in each partition.
2020-06-04 21:51:59 -04:00
John Bytheway c58ba3eedd Allow overriding achievement descriptions 2020-06-03 21:27:27 -04:00
John Bytheway b4c4df56a6 Add more to game_start event
We want the game_start event to record everything relevant about the
starting character (the sorts of things people expect to see in a
memorial log).

This adds some of those things:
* Name
* Grammatical gender
* Profession
* Game version
2020-06-01 09:38:30 -04:00
anothersimulacrum 0aa6ad1090 Use move mode data, not mode checks, delete enum
Centralizing this data in move modes makes maintenance and changes
easier.

Also, it cleans up the code (see avatar::set_movement_mode).

Move mode switching restrictions could use some more nuance, instead of
just being restricted to running.

The `movement_mode_is` function may seem redundant with the `is_x`
functions, but it returns true only if the move mode is the exact
provided move mode, where the `is_running` function returns true based
on type - this means a theoretical new sprinting mode satisfies
is_running, but fails `movement_mode_is( move_mode_running )`.

The move_mode_color function in panels was odd - it returned light_gray
if the mode was walking, but in the only place it was used, it wasn't
called if the move mode was walking, and white was used instead.

The vehicle follow distance was previously just 400 times the move speed
multiplier of the move mode. Let's future proof it and make it like
that, so that we don't get caught by it in the future adding a new move
mode.
2020-05-30 15:08:31 -07:00
ZhilkinSerg d254033062 Merge pull request #40940 from jbytheway/achievement_events
Send events for achievements and conducts
2020-05-30 11:26:51 +03:00
John Bytheway cf04c0b3e9 Tests for new achievement events 2020-05-28 22:19:09 -04:00
John Bytheway 3efd7ed228 Create achievement_id alias
This has spread far enough to warrant a type alias now.
2020-05-28 21:51:19 -04:00
John Bytheway 5a1e1fd8d1 Allow requirements to be hidden
Sometimes requirements are redundant or spoilers.  Allow them to be
hidden in such cases.
2020-05-28 06:42:40 -04:00
John Bytheway ae2e0ddb69 Change display of failed achievements / conducts
Now they display in red, and show a timestamp at which they were failed.
2020-05-26 16:49:08 -04:00
John Bytheway 85903ca6e6 Add tests for conducts 2020-05-26 16:49:08 -04:00
John Bytheway de44bd0a0e Add support for conducts
Conducts (inspired by the NetHack concept of the same name) are
additional restrictions that can apply to a game.  They tend to be
things which start true, but the player can violate at some point.

Examples are not killing, or being vegetarian.

The implementation of conducts is based on achievements, because they
are essentially the same, except that where achievements begin false,
and can become true at some point, conducts begin true and can become
false.
2020-05-26 16:49:08 -04:00
John Bytheway 76dd46e6bd num_avatar_kills -> num_avatar_monster_kills
Rename this stat to clarify that it doesn't count NPC kills.
2020-05-26 16:49:08 -04:00
John Bytheway a71d8f0bbf Remove walk 1000 miles test
This test is rather slow, and doesn't test anything that isn't fairly
well-tested by other tests.  Delete it to save time.
2020-05-08 13:22:06 -04:00
John Bytheway 1791e711a3 Using the debug menu disables achievements
We don't want people to accidentally get achievements when they are
merely doing dev work or debugging issues.

Make it so that most debug menu functions disable achievements.  Also,
add a new debug menu option to re-enable them (for cases where people
were just working around bugs, or when people want to debug achievements
themselves).

When achievements are disabled, the tracker still tracks them but
doesn't print any log messages when they are attained.

Longer-term, this will matter more.  Once there is global tracking of
achievements across games the achievements attained while they were
disabled won't count towards that.
2020-05-07 10:44:05 -04:00
John Bytheway 8ecd8e2707 Test for achievement hiding 2020-05-02 21:50:57 -04:00
John Bytheway e118ece0f4 Revamp achievement requirement tracking
Fixes #39879.

We now stop tracking requirement values when the achievement is
completed or fails.  Moreover, fixes a bug where a completed achievement
could be un-completed by further changes to the underlying statistics.
2020-04-27 07:41:45 -04:00
John Bytheway df3d82f4f3 Various minor scores UI improvements (#39891)
* Add Page Up / Down support to scrolling_text_view

And add keybindings for it in the scores_ui.

* Make scores_ui window taller

Rather than the "standard" terminal height (which is quite small), make
it the full window height minus two.

* Rename scores UI keybinding

Make it clear that this keybinding is about more than just scores.

* Support plurals for statistic descriptions
2020-04-25 16:42:17 +03:00
Kevin Granade 4c1071b8e6 Merge pull request #39841 from jbytheway/survival_achievement
Add a survival achievement
2020-04-24 06:45:16 +00:00
Jason Jones 19093d23d2 Add min/max event statistics and z-level achievements 2020-04-24 06:36:47 +00:00
John Bytheway 01bf58aa62 Add a "survive one day" achievement 2020-04-23 21:22:56 -04:00
Jason Jones c7b760a969 Normalize score and stat names 2020-04-22 20:34:04 -08:00
Jason Jones 1689b1e4e8 Add new movement based achievements and statistics 2020-04-22 20:34:04 -08:00
John Bytheway 9dfdf4fc62 Override time format option
To ensure consistent output from achievement tests.
2020-04-19 22:33:34 -04:00
John Bytheway 98303c2fec Fix off-by-one error in time printing
Was printing e.g. "day 0" when it was "day 1".
2020-04-19 22:33:34 -04:00
John Bytheway dfbae57185 Add achievement time constraints
Allow for achievements to specify a minimum or maximum time bound within
which they must be completed.

Test this with a new "kill within the first minute" achievement.

With this change, achievements can now become "failed", meaning that it
is impossible to ever achieve them in this game.  Failed achievements
get sorted to the bottom of the list, and get a new colour scheme.

As a side-effect, other requirements can also get a "<=" constraint,
which also means they can become impossible to satisfy, and can lead to
achievements being failed.  To support this we need to track which
statistics are monotonic, so we know when such failures are
irreversible.
2020-04-19 22:33:34 -04:00
John Bytheway 3db92839b5 Make score descriptions optional
It makes more sense to name the statistics, since both scores and
achievements are based on them, and we would only end up writing the
same information twice.

So, if a score has no description, derive one from its statistic.
2020-04-19 22:33:34 -04:00
John Bytheway 06514d01a8 Add achievements tab to score window (#39540)
* Support PREV_TAB, NEXT_TAB in scores window

* Add achievements tab to scores window

Want the player to be able to see the achievements they are working
towards.

* Add achievements text unit test
2020-04-14 12:01:01 +03:00
John Bytheway e189957ff2 Run IWYU 20200408 (#39364)
* Helper script to run IWYU

* Run IWYU

* Update deprecated headers

* Run IWYU again

* Re-suppress cxxabi.h

This pragma got accidentally removed because it was deemed to be a
comment attached to a #include.

* Remove extra SDL header includes

* Fix ime.cpp headers

Some tweaks to help IWYU not break this file by messing with
platform-specific stuff not relevant on Linux.

* Update game.h

* Move new point.h includes inside #ifdef

* Re-add platform_win.h to mapsharing.cpp

* Apply suggestions from code review

Co-authored-by: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
2020-04-10 12:16:19 +03:00
John Bytheway 1bc90aa029 Initial implementation of achievements
A minimal achievements implementation.  This is built on top of the
stats_tracker and achievement requirements are defined in terms of
event_statistic values managed there.

As a proof of concept, added a single json-defined achievement when the
player kills their first zombie.

Currently the only UI manifestation of achievements is a message in the
log.  In the long term I plan to add a new tab to the scores window.

Also, achievements are currently local to each save.  In the future we
also want to have a permanent record of what achievements have been
obtained in each player's historical games.
2020-04-08 11:30:12 -04:00
John Bytheway 2ff6b3b218 Enhanced event_transformation support
Two new features for event_transformations: the ability to drop fields,
and the ability to add new fields using new event_field_transformation
functions.

The only such function currently implemented is extracting species from
monster types.
2020-04-04 15:08:27 -04:00
John Bytheway aadb154588 Remove obsolete stats_tracker methods
These functions were useful originally, but now were only used in the
tests.  Remove them, and refactor the tests.
2020-04-04 15:08:27 -04:00
John Bytheway 23644eaa20 Allow stats to be tracked and updated in O(1) time
Prior to this change, each time the value of an event_statistic is
required, it must be recomputed entirely from scratch.

With this change, the stats_tracker can maintain objects which monitor
the transformations and stats involved, and automatically trigger
updates when relevant events occur.

The ultimate goal is to permit achievements to be triggered more
efficiently.
2020-04-04 15:08:27 -04:00
John Bytheway cb5769d40b StringMaker for cata_variant 2019-12-15 15:34:10 -05:00
John Bytheway 2072dc522c Update the stats tests
Want a test for the new "total" stat feature.  Rearrange the other tests
into SECTIONs at the same time.
2019-09-13 07:28:59 -04:00
John Bytheway bcb56663d1 Scores defined in json
Change event_tracker into event_multiset, because we want it to be a
more generic object used for more than just tracking events.  It now
represents any collection of events of the same type.

Introduce three new json-defined objects:

- event_transformation, which converts one multiset of events to
  another.  For example, it can filter all kill events to just kill
  events attributed to the avatar.

- event_statistic, which converts a multiset of events into a single
  value.  The simplest case, for example, is counting the number of
  events.

- score, which uses an event_statistic to produce a score, which can be
  saved as a permanent record of a game.  Currently scores' only purpose
  is to be written to the memorial log.
2019-09-13 07:28:59 -04:00