Implementing Turn based play on TGE 1.5.2
by David Dowdy · in Torque Game Engine · 05/25/2007 (11:01 am) · 1 replies
Hey Everyone,
Looking for a resource or explaination of how to do turn based play on TGE 1.5.2. We need the real time part of TGE for some of our game but would also like to implement a turn based system for other parts. If it sounds like i am unfamilar with torque, its cause I just started trying to understand the engine. Any help on how to do a turn based system would be muchly appreicated. Pointers on what part of the engine to modify would be appreciated too. Or can this be done in scripts entirely too? I rather do it in scripting cause C++ is not my best language. So be as detailed as you can be please. Thank you so very much!
David
Looking for a resource or explaination of how to do turn based play on TGE 1.5.2. We need the real time part of TGE for some of our game but would also like to implement a turn based system for other parts. If it sounds like i am unfamilar with torque, its cause I just started trying to understand the engine. Any help on how to do a turn based system would be muchly appreicated. Pointers on what part of the engine to modify would be appreciated too. Or can this be done in scripts entirely too? I rather do it in scripting cause C++ is not my best language. So be as detailed as you can be please. Thank you so very much!
David
Employee Michael Perry
ZombieShortbus
My immediate thought is to first create a global variable for tracking who is currently up for a turn ($activeClient). At the start of a game (networked or single player), you roll a number (getRandom(100)) to see who gets the first turn and set up an array ($clientList[0]) ordered by those numbers. Once number of players ($maxNumPlayers) is reached, you can start game play. Two other important variables to keep track of would be a global, server variable to toggle game play starting, and a client side variable which doesn't allow important player actions until it is their turn.
I guess this might be the starting pseudo code:
In server\scripts\game.cs:
$activeClient = -1; $maxPlayerCount = 5; $clientList[0]; $readyToStartGame = false; function GameConnection::onClientEnterGame(%this) { [b]//... After starting code, but before %this.playerSpawn()[/b] %this.turnOrder = -1; [b]// Create the variable and give it an invalid value[/b] %this.roll = getRandom(100); [b]// Pick a random number to determine turn order[/b] %this.turnDone = true; [b]// Create a variable for determining if client is done[/b] checkForMaxPlayers(); }From here, you would want to create the sorted array of clients based on their roll variable. I personally hate sorting algorithms, but here's a shot:
Somewhere in server\scripts\game.cs:
function checkForMaxPlayers() { // How many clients have connected? %count = ClientGroup.getCount(); // Are we all filled up? if(%count > $maxPlayerCount ) { // Go through the client list and store it in our array for sorting for (%i = 0; %i < %count; %i++) { %cl = ClientGroup.getObject(%i); $clientList[%i] = %cl; } // Sort our array sortClientList(); // Iterate through our sorted array and assign turn order for (%i = 0; %i < %count; %i++) { $clientList[%i].turnOrder = %i; } // First client in our array is up for action $clientList[0].turnDone = false; $activeClient = $clientList[0]; // All clients are ready, the game can proceed $readyToStartGame = true; } else return false; } // TODO - Fill this out, or using one of the various script array resources for sorting function sortClientList() { [b]// Perform crazy script sorting algorithm on list based on .roll variable[/b] }Once all the players are connected, ready, and sorted, you would toggle the $readyToStartGame, which is checked most likely in function startGame() in server\scripts\game.cs.
There are lots of ways to go about this code concept, in both script and engine code. This is just a starting way if you want to stick to script. We can probably discuss this further in this thread, but see how you like my starting procedure before I continue.
*EDIT*- Of course, you could just assign turn order on a first come, first serve basis. Players are assigned turn order as they connect to the game, which eliminates the need for the sorted client list variable I created.
Also, handling the start of the game and what not is also determined on whether or not you'll have a lobby system like most RTS games (StarCraft, Rise of Nations, etc), or if this an RTS at all.