feat(port): prompt before attacking neutral/fleeing monsters except it actually works #4149
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.
Purpose of change
A simple port request that came up in the discord. Well, I say simple but the original suggested port of safe mode making you not swing at neutral creatures proved more complicated to implement, and soon I realized the follow-up PR's idea would be better to just use outright. All it needed was some fixes to remove annoyance, and turns out (see below) that divorcing it from the safemode check is good if you want the feature to even work at all.
Describe the solution
C++ changes:
avatar_action::move
that prompt if you want to move-attack a neutral creature. Some tweaks to the code to fit BN code differences, in particular just ditch the safemode stuff because I couldn't get it working right, and instead have it always prompt if the monster in question is either ignoring you or fleeing. In addition, set it so the target having the "hit by player" effect is a condition for skipping the prompt as well, to prevent the keybind being spammed once you've woken up and choosen violence that morning.Character::melee_attack
so the effect that doles out the "hit by player" effect only triggers if the player is the attacker, not if NPCs do so. Only other thing I've found this seems to affect is that NPCs set to "only attack what I attack" won't disobey that instruction just because a more gung-ho NPC struck a monster first. As seen below, NPCs with that setting will still enter combat if a monster hits you first so this should be acceptable. The old "don't give this effect to the player" check was retained just in case you find a way to hit yourself.monster::melee_attack
from 3 seconds to 10 minutes, ensuring thatHIT_AND_RUN
monsters can't potentially abuse the short duration to milk some extra keypresses out of a vengeful player chasing them down while they're fleeing.JSON changes:
hit_by_player
so that multiple hits don't massively affect how long combat has to cool off before the player can potentially forget they started a fight with a critter.Describe alternatives you've considered
Testing
Additional context
Source PR: Add prompt to attack neutral creatures when out of safemode, by @Rewryte: CleverRaven/Cataclysm-DDA#65204
Not ported: Safemode prevents attacking neutral creatures, by @qoreQyaS: CleverRaven/Cataclysm-DDA#65075
Checked DDA (build 2024-01-05-1720) and it seems they somehow managed to break the prompt in the process or else removed it, in favor of only having the safemode check. Instead it just always goes straight to swinging at neutral monsters if safe mode is off despite it being in the code, so most likely the formatting of the safe mode check I tried and failed to port is just outright broken on their end in a different way.
augh i forgot to set co-auth until after I'd already committed the option addition and couldn't amend fuck
Checklist