That’s the existing code from src/npc.cpp. I’m just showing you how the game actually decides to kill you.
If you’re up to a little coding and compiling, you could just replace that entire block with
set_attitude( NPCATT_KILL );
and then all NPCs would be hostile.