Make the faction changer logic much more concise.

Remove large amounts of duplicated logic, chiefly from the faction switcher code.
*shakes fist at LUA*