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

Killing hostile NPCs won't give "Killed innocent" morale debuff anymore #78371

Merged
merged 1 commit into from
Dec 14, 2024

Conversation

Night-Pryanik
Copy link
Contributor

Summary

Bugfixes "Killing hostile NPCs won't give "Killed innocent" morale debuff anymore"

Purpose of change

At the moment, to NOT get the morale debuff for killing NPCs, said NPC has to be guaranteed_hostile. This condition is true if at least one of the following conditions is true:

  1. said NPC is_enemy, which means that he must have NPC attitude of killing us (NPCATT_KILL) or fleeing from us (NPCATT_FLEE or NPCATT_FLEE_TEMP).
  2. said NPC must have a faction, and this faction must dislike us a lot.

There are situations where hostile NPC isn't aware of us yet and thus is ignoring us and thus his NPC attitude is NPCATT_NULL. This means that first condition from the list above will be false.
As @mlangsdorf said in #30124 (comment), there might be some bugs or errors in faction assignment or evaluation, and this might be the reason why second condition from the list above also becomes false.
If both conditions are false, killing hostile NPC will give us a morale debuff.

Describe the solution

Added a check for hostile creature attitude, i.e. Creature::Attitude::HOSTILE. Hostile NPCs which haven't seen us yet (and thus not angry at us and not trying to kill us yet) have this attitude, and thus won't be considered as innocent, even if faction check fail for some reason.

In any case, if these changes won't fix the issue, this additional check for creature attitude won't hurt.

Describe alternatives you've considered

None.

Testing

I conducted A LOT of testing using several methods from #30124 and #71341, i.e. killing bandits spawned through Old Guard representative's mission, bandits in road block, bandits in bandits_garage and some others. I wasn't able to reproduce the original issue. If anyone has a save which can reliably reproduce the issue, please give it to me, I'll try to test it myself.

Additional context

None.

@Night-Pryanik Night-Pryanik added NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) Mechanics: Character / Player Character / Player mechanics labels Dec 6, 2024
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Dec 6, 2024
@Maleclypse Maleclypse merged commit abe2d84 into CleverRaven:master Dec 14, 2024
22 of 28 checks passed
@Night-Pryanik Night-Pryanik deleted the innocent-bandits branch December 14, 2024 13:36
@RenechCDDA
Copy link
Member

@Night-Pryanik I hate to mention this now but I only saw this in the feed after it was merged. There's a test case for this, player_morale_murdered_innocent.

https://github.com/CleverRaven/Cataclysm-DDA/blob/master/tests/morale_test.cpp#L175

If the test case didn't catch an existing error, it would be nice (not necessary, but nice!) if the test case could be made more comprehensive.

Again I'm not saying you have to do this, I just wanted to make you aware of the test.

@Night-Pryanik
Copy link
Contributor Author

Ok, thanks, I'll check this out.

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 <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions Mechanics: Character / Player Character / Player mechanics NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Killed Innocent" morale debuff from ambushing hostile bandit
3 participants