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: Infrastructure "Track kills through event_bus in new dedicated kill_tracker class"
Purpose of change
To reduce the code bloat in
game
, to decrease coupling, and to demonstrate the utility of the newevent_bus
class.Describe the solution
Note that this change builds on top of #33344 and #32891; a lot of the changes you see here are part of those PRs.Now those are merged, rebased on master.Create a new class
kill_tracker
which counts the player's kills. This functionality used to be directly ingame
. Move all the relevant functions fromgame
tokill_tracker
to work with that data.Also, add an
event_bus
togame
, and make thekill_tracker
a subscriber of it.Communicate information about kills via the
event_bus
, rather than having dedicated member functions ofgame
for that purpose.Add suitable (de)serialization code to save this data and migrate the old format.
Describe alternatives you've considered
When a
Character
is killed, I chose to put the name directly in theevent
. I could have only provided thecharacter_id
, and had thekill_tracker
fetch the name itself, but I thought I would mimic the previous interface for now. I was also slightly concerned that theCharacter
might not be loadable any more if they are dead; didn't look into that.Additional context
This seemed like the simplest functionality that made sense to be built on top of the
event_bus
to provide a real-world test of its functionality before moving on to more ambitious projects.Next I would like to make a subscriber that performs all the memorial logging, rather than having that logging code scattered around the codebase.