Updating the turn_costs branch with current master

Hello,
This pull request rebases the turn_cost branch to current master.
Sadly, the update resulted in a lot of conflicts that made many changes necessray. Hence, the last few commits that only fix stuff that was broken after rebasing.

Unit tests run correctly with these changes and everything seems to work fine.