I'd be suprised if your attack on a player character/unit isn't
controlled by that very same few lines of code once the attack begins.
In fact, the NPC's are capable of exhibiting smarter behavior than your
units because they can decide to attack or not on the fly based on the
opponent's size/strength. The only difference is that the NPC's don't
taunt you or terrorize you with email before attacking :)