-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Achievements: add support for time constraints #39686
Merged
ZhilkinSerg
merged 7 commits into
CleverRaven:master
from
jbytheway:achievement_time_constraints
Apr 21, 2020
Merged
Achievements: add support for time constraints #39686
ZhilkinSerg
merged 7 commits into
CleverRaven:master
from
jbytheway:achievement_time_constraints
Apr 21, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1363e8d
to
65ee146
Compare
|
src/event_statistics.cpp
Outdated
Comment on lines
211
to
214
if( equals_statistic_ && ( *equals_statistic_ )->monotonicity() != monotonically::constant ) { | ||
return false; | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested by clang-tidy readability-simplify-boolean-expr
Suggested change
if( equals_statistic_ && ( *equals_statistic_ )->monotonicity() != monotonically::constant ) { | |
return false; | |
} | |
return true; | |
return !equals_statistic_ || ( *equals_statistic_ )->monotonicity() == monotonically::constant ); |
68d9983
to
618c47a
Compare
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.
Currently we track the time of the cataclysm, but not the time of the game starting. This is needed for achievements (and potentially other things, like missions) so add it. In legacy saves, it will default to the same time as the cataclysm.
Add new enumerator, and move into header.
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.
Was printing e.g. "day 0" when it was "day 1".
To ensure consistent output from achievement tests.
618c47a
to
9dfdf4f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[C++]
Changes (can be) made in C++. Previously named `Code`
<Enhancement / Feature>
New features, or enhancements on existing
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Features "Achievements can now have time constraints"
Purpose of change
It is common for achievements in games to require you to do something within a certain amount of time. We want to support that use case. Moreover, we would like to support achievements with a lower time bound (like "survive for a month").
Describe the solution
A new field
"time_constraint"
on achievements that allows enforcing a lower or upper bound on the time an achievement can be captured (but not both).Comes with the following associated changes:
calendar::start_of_game
to keep a record of when the game started for reference. In legacy saves this will default tostart_of_cataclysm
.scores.json
was starting to get cluttered.Describe alternatives you've considered
One limitation is that you can't directly write an achievement which fires at a particular time. Achievements are only considered when a relevant event fires. So if you want to write e.g. a "survive for a month" achievement then it still needs to have an associated event (via a statistic), and won't fire until that event happens. We could add (or link into) a timer system for additional triggers beyond events, but I think that's not really necessary.
Testing
Added some new unit tests.
Tested in game long enough to capture the below screenshots.
Additional context
(The pictures below have an off-by-one error in the day of printed times; I fixed that after taking the screenshots).
How things look initially:
![achievement-times-initial](https://user-images.githubusercontent.com/52664/79639395-929c2300-8159-11ea-82fd-051bfa8e9f4f.png)
![achievement-times-log](https://user-images.githubusercontent.com/52664/79639394-92038c80-8159-11ea-9503-126fb0674737.png)
![achievement-times-both-success](https://user-images.githubusercontent.com/52664/79639393-92038c80-8159-11ea-9da8-8f8703bb5369.png)
![achievement-times-after-waiting](https://user-images.githubusercontent.com/52664/79639392-92038c80-8159-11ea-8db4-bc2bffd30ed5.png)
![achievement-times-one-success](https://user-images.githubusercontent.com/52664/79639391-916af600-8159-11ea-94d2-e9ecc50e1f4b.png)
Getting both achievements by killing a zombie fast:
Achievements window now looks like:
If instead you wait until after a minute then:
And then, after killing a zombie: