-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
JSON-ify sleep-affecting mutations, trying to sleep, and sleep comfort #75852
Merged
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
…into jsonify_sleep
Add fall asleep msg to Character::fall_asleep
github-actions
bot
added
<Documentation>
Design documents, internal info, guides and help.
NPC / Factions
NPCs, AI, Speech, Factions, Ownership
[JSON]
Changes (can be) made in JSON
Mods
Issues related to mods or modding
Mutations / Traits / Professions/ Hobbies
Mutations / Traits / Professions/ Hobbies
[C++]
Changes (can be) made in C++. Previously named `Code`
[Markdown]
Markdown issues and PRs
EOC: Effects On Condition
Anything concerning Effects On Condition
Mods: Xedra Evolved
Anything to do with Xedra Evolved
labels
Aug 21, 2024
github-actions
bot
added
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
new contributor
labels
Aug 21, 2024
Maleclypse
reviewed
Aug 21, 2024
github-actions
bot
added
json-styled
JSON lint passed, label assigned by github actions
astyled
astyled PR, label is assigned by github actions
labels
Aug 21, 2024
github-actions
bot
added
the
BasicBuildPassed
This PR builds correctly, label assigned by github actions
label
Aug 22, 2024
I'm going to try and test this tonight or over the weekend and then merge it :) |
Thank you for your contribution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
astyled
astyled PR, label is assigned by github actions
BasicBuildPassed
This PR builds correctly, label assigned by github actions
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
<Documentation>
Design documents, internal info, guides and help.
EOC: Effects On Condition
Anything concerning Effects On Condition
[JSON]
Changes (can be) made in JSON
json-styled
JSON lint passed, label assigned by github actions
[Markdown]
Markdown issues and PRs
Mods: Xedra Evolved
Anything to do with Xedra Evolved
Mods
Issues related to mods or modding
Mutations / Traits / Professions/ Hobbies
Mutations / Traits / Professions/ Hobbies
new contributor
NPC / Factions
NPCs, AI, Speech, Factions, Ownership
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
Infrastructure "JSON-ify sleep-affecting mutations"
Purpose of change
Several mutations change where a character can try to sleep. This is hard coded into those mutations. Accordingly, these mutations cannot be changed, nor can new sleep-affecting mutations be added, without editing code.
Describe the solution
Added an optional
comfort
field to traits, which is a list ofcomfort_data
.comfort_data
consists of:When a character tries to sleep, all of their traits are checked for comfort data. Within a trait, the first comfort data with true conditions is chosen. If multiple traits choose comfort data, the comfort data with the worst base comfort is chosen. This is so "impossible" comfort levels, such as experienced by a post-threshold spider sleeping without a web, are prioritized.
The resulting comfort is cached so the handful of functions that use comfort and related information can fetch it without having to go back through all the comfort data. This cache is invalidated if time passes or the location changes.
Originally, I used dialogue conditions to evaluate locations, but I found myself using character-focused conditions such as
u_underwater
instead of location-focused conditions likemap_terrain_has_flag
. This was a problem, as NPCs evaluate the comfort of multiple locations around them to decide where to sleep, and character-focused conditions would result in not actually evaluating those locations.Accordingly, I took a page from climbing aids' book and rolled my own conditions. They allow checking terrain, furniture, traps, fields, vehicles, character flags, and traits. With the exception of traps, all are used by at least one of the existing sleep-affecting mutations. I added traps because traps can affect comfort in the form of the bed roll, cot, and similar.
This solution has not changed the behavior of any mutations, with the following exceptions:
t_dirt
,t_grass
,t_dirtmound
,t_pit
, andt_pit_shallow
. This can be changed back if desired.Character::base_comfort_value
andCharacter::sleep_spot
and added 10 comfort in both places. This seemed unintentional.comfort_data
-less.Describe alternatives you've considered
Adding a WATERSLEEP flag. That's what I did initially, then I made the mistake of thinking that creating a more robust solution "wouldn't be that bad".
Testing
I debug mutated each sleep-affecting trait one at a time and tried sleeping in all conditions that would produce a distinct result. For example, for Aqueous Repose I tried sleeping on land, in deep water, and in swimmable terrain. When I got a result that didn't match the hardcoding, I fixed the code or json until it did. As of my most recent test, all sleep-affecting mutations behave as they used to, save for the above-mentioned exceptions.
Additional context
I somehow missed the "keep your PR small" advice until right now, so, uh, sorry. Almost all the new code is in sleep.h and sleep.cpp if that helps.
Also, I'm pretty sure there's nothing actually stopping a character from trying to fall asleep in mid-air (via the LEVITATION flag or the like). I didn't actually check, and didn't add any code to prevent that, but I thought it was pretty funny. I can fix it with another PR if desired.
There are also a bunch of hardcoded things that occur while a character is sleeping, some of which can probably be moved to enchantments. I didn't touch those either.