I’m currently in a debacle in regards to Turn Management in my game, and was wondering if anyone had a good suggestion in regards to scripting this to be efficient and fast.
In my current project, I have a dungeon that has X mobs inside of it (usually around 40-50, but it can vary). Everything gets its own turn to perform one action. So, for example, the player makes a move, and then all 40-50 mobs make a move, and then the player can make a move again.
I originally had a master script that controls all turns, by setting AI component boolean variables, however it was far too slow.
This concept worked as follows:
Master Script determines the turn order (later to be determined by stats and other variables, however for now it had just added every mob one by one to a list).
Master Script sets next mob’s turn to true during the Master Script’s Update, or does nothing. A second boolean that determines if the mob has finished its turn is checked to do this.
Mob’s Update performs its turn. When it is finished, it sets a second boolean to false.
Master Script reads this second boolean during its Update and determines that the turn has finished, removes the mob from the list, and sets the next mob in the list’s turn to true.
Rinse and repeat.
I think the main problem was that there are too many situations waiting on the next Update. So if the current mob’s Update had ended JUST BEFORE the Master Script set its turn to true, it would have to wait until its next turn.
I’m wondering if there is a better way to handle turns. As it was set up above, it would take over a minute, usually two, to cycle through each mob and return control to the player. The mob turns almost always consisted of simple movement (Move from Space A to Space B with a position change), because most of the AI has not been configured yet, which means that the duration of the mob turns was FAR too long for such quick actions.
I was considering having it so that all mob turns for a single turn are done at once, and then not allow them to perform their next turn until the player has acted for theirs. Maybe have all Off-Screen turns be at once, however On-Screen turns take place one by one, but I’m not sure how plausible or efficient this would be.
If I do not have a turn system in effect at all, the AI will act in a swift manner, so it’s definitely how I’m managing turns that is the issue.
Any insight on how to improve this process would be greatly appreciated.