Core/Phases: Some changes to how phasing works

(cherry picked from commit e4f6cb39a2652455b78ae2416627954956c8964f)
Core/Phases: some commenting, more cleanup and compile fix

(cherry picked from commit 8b536fdf9d38a3e0c94dc9c1184ea8582495064f)
Core/Phases: fix logic in SetInPhase()
- we should not remove the terrain swap if another phase still use it

(cherry picked from commit 299c693b8420d81951ef67b8481e4ad6b192473f)