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

character: relocate and refactor suffer #35300

Merged
merged 11 commits into from
Nov 10, 2019

Conversation

mlangsdorf
Copy link
Contributor

@mlangsdorf mlangsdorf commented Nov 4, 2019

Summary

SUMMARY: Infrastructure "character: relocate and refactor suffer"

Purpose of change

player::suffer() is a 1200 line function that should be broken up into several functions and moved
into character::.

Describe the solution

Move suffer() into a new file and make it part of the Character:: class. Also move some related functions and variables out of player:: and into Character:: to make the new function compile.

Split out some of the code from suffer() into smaller functions. Specifically, move the mutation power code and the mutation water damage code into two separate functions, and unify the two loops into a single loop.

Testing

Passed local unit tests.
Spawned an unwilling cyborg with chemical imbalance, schizophrenia, gills, and some other stuff. Waited a bit and observed faulty bionics and schizophrenia and chemical imbalance related messages. Swam in water without drowning, then mutated myself to remove the gills and drowned.

TODO

  • Keep splitting off functions.
  • Playtest this monster.

@mlangsdorf mlangsdorf requested a review from KorGgenT November 4, 2019 01:35
@mlangsdorf mlangsdorf added [C++] Changes (can be) made in C++. Previously named `Code` Mechanics: Character / Player Character / Player mechanics Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Nov 4, 2019
@mlangsdorf mlangsdorf marked this pull request as ready for review November 5, 2019 01:11
Copy link
Member

@KorGgenT KorGgenT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all right, i read through all of the code, and it looks good overall. just a couple thoughts.

src/bionics.cpp Show resolved Hide resolved
src/suffer.cpp Outdated Show resolved Hide resolved
src/suffer.cpp Show resolved Hide resolved
src/suffer.cpp Show resolved Hide resolved
src/suffer.cpp Outdated Show resolved Hide resolved
src/suffer.cpp Outdated Show resolved Hide resolved
@mlangsdorf mlangsdorf force-pushed the refactor_suffer branch 2 times, most recently from 7aa01fa to 2b724ed Compare November 8, 2019 15:08
Migrate suffer() down from player:: into Character::, along with the
minimum but still substantial set of functions and variables that also
need to be in Character:: in order to make the code compile.
add in stubs for all the suffer subfunctions, both to establish the
future structure and to populate the header file, which will speend up
compiles while testing this.

Move a few of the simpler bits of code directly into their subfunctions,
consolidating some code in the process.
move the code to handle mutation based water damage/healing to a
separate function, and move the code to handle mutation power to a
separate function.  Unify their loops to slightly speed up the performance.
Move the code for drowning out of suffer and into
suffer_while_underwater().
split out the code for suffering while awake, including the code
for chem imbalance and schizophrenia.

Substantially re-order and rework schizophrenia, so that NPCs
with schizophrenia will suffer from some of the externally
visible effects like dropping weapons.
split out the code for suffering from asthma.  Slightly rework the
entry conditions for clarity.
Split out the code for suffering in sunlight.  Rework it slightly to
exit early if the character is not in sunlight, which also simplifies
the following if statement.

Substantially refactor the entry conditions for albinism for clarity.
Move the radiation handling code into its own function, and slightly
change the logic in order to remove a level of indenting and terminate
the function earlier.
Move the faulty bionics code into its own function.
Move the stimulant based suffering into its own function.
Move sleep deprivation into its own function.  Reverse the order of the
logic in the trinary statement to set sleep deprivation, and add a note
that the first set of messages should be replaced with some snippets.
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: Infrastructure / Style / Static Analysis Code internal infrastructure and style Mechanics: Character / Player Character / Player mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants