I have been working on a RPG where the player is free to wander an open world but when a monster is encountered or on keyboard command the game switches to a turn based system. Note this is not like final fantasy like games, I intend for the turn based combat to take place in the same map, there is no scene transition.
I am trying to wrap my head around how to implement the turn based combat system. Right now I have a basic game loop that handles the main world map where the player can move above, pick up items, engage in dialogue with npcs, this looks like this:
while (does_not_quit){
input();
logic();
render()
}
Within logic() there is a keyboard command that switches the game to turn based mode, turn based meaning the player and npcs' movement and actions are now controlled by aciton points and these refresh once per turn. My question is, mechanically from a software design point of view, what is the best way to implement this turn based system on top of the main game loop?
Currently, what I do is, upon entering turn based mode, I start to check player movement against available action points which are read from a json file for each npc (and player). But how do I generate the effect of turns? For example, when the NPCs move I have to halt all commands from the player and I want each NPC to move separately, one after another and then when its the player's turn again, keyboard commands are restored and the player makes his moves before hitting "end turn". Naively, I have tried using a for loop to cycle through all the npcs+players in a given turn but this doesn't seem right?
I have played around with a few methods but it just doesn't feel right and I feel that there must be some classic design patterns that do this but I haven't been able to find any literature on this.
Can anyone advise?