7
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ Have you looked at How to design and implement turn-based system? and How to implement turn-based game engine?? \$\endgroup\$ Apr 30, 2012 at 15:24
  • \$\begingroup\$ 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. \$\endgroup\$
    – Reefpirate
    May 1, 2012 at 3:58
  • 2
    \$\begingroup\$ 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? \$\endgroup\$
    – Jake
    May 28, 2012 at 15:01
  • \$\begingroup\$ Is the issue camera manipulation or implementing the turn controllers? \$\endgroup\$
    – user64742
    Jun 8, 2017 at 20:40

2 Answers 2

2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .