# How should I structure my turn based engine to allow flexibility for players/AI and observation?

I've just started making a Turn Based Strategy engine in GameMaker's GML language... And I was cruising along nicely until it came time to handle the turn cycle, and determining who is controlling what player, and also how to handle the camera and what is displayed on screen.

Here's an outline of the main switch happening in my main game loop at the moment:

switch (GameState)
{
case BEGIN_TURN:
// Start of turn operations/routines
break;
case MID_TURN:
switch (PControlledBy[Turn])
{
case HUMAN:
switch (MidTurnState)
{
case MT_SELECT:
// No units selected, 'idle' UI state
break;
case MT_MOVE:
// Unit selected and attempting to move
break;
case MT_ATTACK:
break;
}
break;
case COMPUTER:
// AI ROUTINES GO HERE
break;
case OBSERVER:
// OBSERVER ROUTINES GO HERE
break;
}
break;

case END_TURN:
// End of turn routines/operations, and move Turn to next player
break;
}


Now, I can see a couple of problems with this set-up already... But I don't have any idea how to go about making it 'right'. Turn is a global variable that stores which player's turn it is, and the BEGIN_TURN and END_TURN states make perfect sense to me... But the MID_TURN state is baffling me because of the things I want to happen here:

• If there are players controlled by humans, I want the AI to do it's thing on its turn here, but I want to be able to have the camera follow the AI as it makes moves in the human player's vision.
• If there are no human controlled player's, I'd like to be able to watch two or more AI's battle it out on the map with god-like 'observer' vision.

So basically I'm wondering if there are any resources for how to structure a Turn Based Strategy engine? I've found lots of writing about pathfinding and AI, and those are all great... But when it comes to handling the turn structure and the game states I am having trouble finding any resources at all. How should the states be divided to allow flexibility between the players and the controllers (HUMAN, COMPUTER, OBSERVER)?

Also, maybe if I'm on the right track I just need some reassurance before I lay down another few hundred lines of code...

• Have you looked at How to design and implement turn-based system? and How to implement turn-based game engine?? – Joshua Drake Apr 30 '12 at 15:24
• Yep, I looked at those. One didn't really go anywhere. The other one was a solution using events, but didn't really address the issues I brought up here. – Reefpirate May 1 '12 at 3:58
• you said "Now, I can see a couple of problems with this set-up already".. so what is the problem you are facing? Are you unable to set the camera view? cannot run animations? or what? – Jake May 28 '12 at 15:01
• Is the issue camera manipulation or implementing the turn controllers? – user64742 Jun 8 '17 at 20:40