Repeat rebased

Use repeats properly (rebased the repeats branch)

Layout is now done dynamically. More than 3 phases are not yet supported (mainly because of some issues while testing with the Ancient Empires mod, but I'll look into that).