In games like this, almost everything is usually trying to kill the player. It makes sense from a gameplay perspective, of course. Monsters are there to be obstacles standing between you and your goal. In the Possession games, you can even make an argument that makes sense from a narrative standpoint: people and animals can tell something’s not right with something that’s possessed.
That said, it can be interesting from a gameplay point of view (as well as making the game world feel more alive) by making some creatures hostile to each other, and some creatures not immediately try to kill the player as soon as they see them.
I’ve talked a little before about the fact that creatures have different “aggression” values, that some will attack on sight, while some will hang back unless you get too close.
In Possession 2, creatures can also have a “faction” assigned to them, as well as a list of enemy factions. If they see a creature that belongs to an enemy faction, they’ll treat them like an enemy, exactly like they would if the creature was the player.
Players can use this to their advantage, though. If they possess a creature that belongs to a faction, other creatures in that faction won’t be hostile to them! Well, unless they saw the possession happen…
There are three special factions: Chaos, which means they’ll attack anyone, Passive, which means they won’t attack anyone except creatures who attack them first, and Player Ally. If a creature is a player ally, they’re treated like the player, and are hostile to everyone except other player allies (including the player themselves, of course), and members of their own faction.
Aside from the factions, there are some other things that can change the way creatures behave towards each other.
The first one is the fact that creatures can have “masters,” who they will follow around and attack the enemies of. Creatures won’t attack their master or their master’s other followers, and will attack their master’s enemies, regardless of their own faction.
Creatures also maintain something that I call in the code a “shitlist.” It’s basically a list of known individual enemies. If they notice and become hostile to someone, they go on the shitlist. But even creatures to whom they’d normally be friendly can end up on the shitlist if they accidentally hit them with a ranged attack that missed its intended target, an attack that damages an area, or if they hit them while confused/drunk/mind controlled/getting knocked backwards/whatever. Players can use this to their advantage by causing enemies’ attacks to hit each other, making them attack each other while the player sneaks past or waits until they’re weaker to pick them off.
So, this is all well and good, but it does present a problem. If creatures on the other side of the map are attacking each other, then by the time the player gets there, they’ll probably all have killed each other off, maybe leaving a few almost-dead stragglers. And while it’s kind of cool to walk into a room and see the aftermath of recent fighting, it’s not very challenging or fun if there’s nothing left for you to fight.
The first thing I do is also a bonus for performance. Creatures far enough away (currently defined as “more than twice as far as the player’s sight distance”) don’t run through their whole AI code. They just move randomly to a square they’re touching. If they do happen to take damage (say they wander into lava, or step in a trap or in front of a moving mine cart), they only take 10% of the damage, rounded up. Of course, if something happens that would instakill them (getting knocked into a pit, for example), they’ll die.
So this works well for far away creatures, but maybe a creature is physically near the player but the player would still have to travel a long distance to actually see them…they might be on the other side of a wall, but the nearest opening in the wall is halfway across the level. Or maybe they’re just in the next room, but the player’s hanging out in this room for a while, so we run into the same problem.
For creatures near the player, but that the player can’t see, they’ll only take half damage from everything. This could be exploitable (position yourself so a friendly creature can’t be seen, but their enemy can…enemy takes full damage and ally only takes half!), so it actually only kicks in if you can’t see the creature or their attacker.