Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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...

share|improve this question
    
    
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
2  
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
add comment

2 Answers 2

While there are human players, you can make the camera center on the moving AI unit if it's in range of vision. Else, you can have camera controllable with mouse/keyboard independent of the moving units.

share|improve this answer
add comment

You will have to decouple the "camera" from a player. Maybe GML has limitations here but I have no experience with that to speak of. There is no reason why the position and setup of the camera has to be locked to a single player. Normally a game consists of a world and sometimes several cameras to be rendered each frame for multiple players on the same screen, or "security camera" views," or render to texture views etc. The process of rendering a frame from a single camera view to a single screen space area need not be tied to a player at all.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.