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

feat(port): prompt before attacking neutral/fleeing monsters except it actually works #4149

Conversation

chaosvolt
Copy link
Member

@chaosvolt chaosvolt commented Jan 22, 2024

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:

  1. In avatar_action.cpp, added checks in 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.
  2. In melee.cpp, changed 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.
  3. In monster.cpp, bumped the duration of "hit by player" effect doled out in monster::melee_attack from 3 seconds to 10 minutes, ensuring that HIT_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.
  4. Per request, additionally set it up so an additional condition for the prompt is a new option defined in options.cpp, allowing you to turn the feature off if you prefer to wake up and choose violence all morning, every morning.

JSON changes:

  1. Specified a max duration of 10 minutes for 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

  1. Trying to figure out how safe mode code different DDA and BN to allow it to outright deny you the ability to attack neutral mobs in safe mode, but as can be seen this seems to be a bad idea.
  2. Reminding myself to port over easier PRs.

Testing

  1. Checked affected JSON for syntax and lint errors.
  2. Compiled and load-tested.
  3. Spawned in a gracken.
  4. Hit tab next to it, confirmed prompt shows up.
  5. Moved at it, confirmed prompt still appears after hitting no.
  6. Confirmed move-attack works after hitting "yes"
  7. Checked that once I did take a swing at it, I could now slap it with impunity.
  8. Spawned in Lost and Damned sceanario, confirmed this doesn't impact displacing friendly zombies.
  9. Tested against a kreck, confirmed that Safemode treats hit and run enemies as "neutral" for the purpose of preventing melee attacks CleverRaven/Cataclysm-DDA#65222 does not seem to be a problem.
  10. Turned the new option off and spawned in another gracken, I can immediately slap it around.
  11. Checked affected C++ changes for astyle.

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.

image

augh i forgot to set co-auth until after I'd already committed the option addition and couldn't amend fuck

Checklist

@github-actions github-actions bot added src changes related to source code. JSON related to game datas in JSON format. labels Jan 22, 2024
@chaosvolt chaosvolt merged commit 02e1090 into cataclysmbnteam:main Feb 7, 2024
12 checks passed
@chaosvolt chaosvolt deleted the port-neutral-query-but-actually-do-it-right branch February 7, 2024 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON related to game datas in JSON format. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants