CleverRaven/Cataclysm-DDA — pull request #10644 by Coolthulhu (2014-12-26 22:19:17+00:00)
Title: Turret priority system (don't nuke squirrels)

A priority system for friendly turrets and hacked bots.

Each creature's power is roughly approximated by its size, hostility and equipped gun. Electronic stuff is treated as armed with guns while NPCs are explicitly checked for gun in hands.
Formula for monsters is: size - 1 + 2 for electronic + 2 for hostile, -1000 for friendly (or zlave).
For hostile NPCs it's: 4 if armed with a gun, 2 otherwise.

This power rating is used in the automatic target selection function to divide the effective distance from the turret. So a hostile tank drone (power rating 7) at 35 tiles should be targeted before a hostile hulk (power rating 5) at 28 tiles. Power ratings of 0 (non-hostile dogs and smaller) and less are ignored by turrets.

Power rating is also used to limit hacked bot's mode. Tankbot has a cap equal to target's power rating on mode, chicken walker equal to power rating - 1. For example, a hostile moose (4) will get shot with a frag, while a neutral one (2) only with the flamethrower or tazer.