Skip to content
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

Initial bare-bones implementation of achievements #39351

Merged
merged 4 commits into from Apr 9, 2020

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: Features "Add support for json-defined achievements to provide more goals to strive for"

Purpose of change

Adding achievements to help inspire more varied gameplay and provide goals for those players who wish for them.

Describe the solution

Building on the event_bus and stats_tracker work, this adds a new layer achievements_tracker that waits for achievements to be completed.

Achievements are defined in terms of event_statistics managed by the stats_tracker, which are in turn derived from events taken from the event_bus.

As a proof-of-concept I've implemented a very simple first achievement: kill a zombie.

This is a bare-bones absolute minimal implementation for that achievement. It can be expanded in many directions, and I hope to do that.

In particular, the only visible impact of achievements right now is a message in the sidebar log when you get one, which I imagine most players won't even notice. My next step is to add a new tab to the scores screen to show achievements for a particular game.

At the same time, I discovered and fixed some issues with object lifetimes in stats_tracker which could cause problems when you played multiple games in a single session of CDDA.

Describe alternatives you've considered

There are many ways this could be done. I'm a little concerned that this approach leads to hard-to-follow code flow, but it does have the advantage that it's easy to write tests for, which is nice.

Testing

Added a small unit test, and verified that the achievement works in-game.

Additional context

achievement-log

@Night-Pryanik
Copy link
Contributor

message in the sidebar log when you get one, which I imagine most players won't even notice.

Light green text instead of usual green to make it more visible?
Popup instead of message in the log?

@ghost
Copy link

ghost commented Apr 8, 2020

this would go well in the codex (#36479). maybe a specific tab for achievements.
solving a quest could be considered an achievement too.
i was thinking it needed a new tab for all things like: fulfilled missions/goals/overall progress.
to keep track of game's notable events.

@jbytheway
Copy link
Contributor Author

message in the sidebar log when you get one, which I imagine most players won't even notice.

Light green text instead of usual green to make it more visible?

It is light green when it first appears, but shades to darker when the window loses focus (the same as the other messages around it).

Popup instead of message in the log?

My longer term plan is that once we have global state for achievements you'll get a popup the first time you get any achievement, but not on every game you get it. I don't want to spam players too much, so I'll leave it out until then.

@Dacendeth
Copy link
Contributor

Dacendeth commented Apr 8, 2020

It's only a matter of time before someone makes a "Stats through achievements" mod now.

@jbytheway
Copy link
Contributor Author

Looks like there are some clang-tidy errors I need to fix.

Allow watchers to unsubscribe from the stats_tracker, and ensure that
happens automatically on destruction, so that the stats_tracker doesn't
send messages to dangling pointers.

Also, ensure that the various watcher classes are non-movable because
stats_tracker requires reference stability.

Also, clear more things in stats_tracker.  When the game is cleared, the
set of initial scores is also cleared, all watchers are forcibly
unsubscribed, and the state tracking objects are also cleared.  This
prevents strangeness with scores when running multiple games in a single
session of CDDA.
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.
@jbytheway
Copy link
Contributor Author

jbytheway commented Apr 8, 2020

Fixed the clang-tidy issues. Some here, and unrelated ones on #39367.

@FuelType-Memes
Copy link
Contributor

It's only a matter of time before someone makes a "Stats through achievements" mod now.

There is a very cool system based on finding oddities and curios that is implemented in Underrail

@ZhilkinSerg ZhilkinSerg added <Enhancement / Feature> New features, or enhancements on existing [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON <Documentation> Design documents, internal info, guides and help. [Markdown] Markdown issues and PRs Code: Tests Measurement, self-control, statistics, balancing. labels Apr 8, 2020
@ZhilkinSerg
Copy link
Contributor

Popups will be nice to add later:

image

@ZhilkinSerg ZhilkinSerg merged commit 2da2dcb into CleverRaven:master Apr 9, 2020
@jbytheway jbytheway deleted the achievements branch April 9, 2020 12:06
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` Code: Tests Measurement, self-control, statistics, balancing. <Documentation> Design documents, internal info, guides and help. <Enhancement / Feature> New features, or enhancements on existing [JSON] Changes (can be) made in JSON [Markdown] Markdown issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants