Original Post
Hey folks, just sharing some design and offering opportunity for questions, comments, suggestions, criticisms... Backround The game (codename and hereafter MOE) is a turn based strategy game akin to Master of Magic, Civilization, Imperialism and their kin. MOE has no set towns. Units exist in tiles, and can work in projects which are not necessarily tied to a town or factory. They may also move, fight, die, and what normal things you might expect. Units have Action Points (AP). AP is gained each turn, and the amount is variable based on the health of the unit, its food intake, its race, and perhaps other factors. Making an action (such as working on a project, moving along the map, or slaying enemies) takes AP. AP may drop below 0, but may not rise above a max AP which is variable amongst units. No orders may be given by units with AP <= 0. Units are the only game objects which can do commands. Problem The problem comes with the multiplayer requirements of the design. Turn based strategy games are a bit slow. Really slow when you have to wait for every other guy to issue their orders before you can actually play. It would be better if players could issue their orders concurrently, and they then all would be resolved at end of turn. The problem is how to do that. Solution Enqueue-ing commands is fairly straight forward. Player issues command, command goes in player's queue. Player hits ready/end-turn, player's queue goes to server. Taking the various players' queues and deciding what order to process the commands is a little less straightforward. Here is the design that I'm aiming for: Once all players are ready, and their queues of commands are received, turn processing begins. - Take all units and save their AP at the beginning of the turn into the command structure. - Run through the command queues, pulling the first order for every unit. - Take those commands and calculate a double: ( (2 * current AP - AP cost of command) / 2) / AP at beginning of turn - Place those commands into a Sorted container, descending on the float. - Process all commands where the double equals the double of the first command in the container. - For each unit's command processed, pull the next command for that unit from the queues, inserting it as needed into the sorted container. - Repeat until queues and container are empty. What this should do is normalize the commands to be a percentage of the turn time. An example:
Unit 1, some guard. AP 8 max AP 10 Unit 3, evil zombie, AP 3 max AP 3
Commands:
Move into tile (0,0) [cost:2] Move into tile (0,0) [cost:2]
Fortify [cost:2]
So, processing, the first guard command is (8 + 8-2)/2/8 or 7/8. The first zombie command is (3 + 3-2)/2/3 or 2/3. 7/8 > 2/3 so the guard goes first and moves into the tile. Process guard command #2: (6 + 6-2)/2/8 [remember, 2 ap spent moving already] or 5/8. 2/3 > 5/8 so the zombie goes next and moves into the tile, causing combat before the guard is fortified. And that's the idea. The guard can do more, and if both start at the same time the more 'rested' unit should gain the initiative. But the zombie shouldn't have to wait until the guard makes moves until he's only got 3 AP left until starting his only action.