Near total AI rewrite.

Reworked states. Simplified state logic. Simplified state transition
logic.