From df72a961dbf1b69b326ee44a50b7dd59b5816087 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 23 Oct 2007 01:27:05 +0000 Subject: [PATCH] - Start up EZGames so that it's nobody's turn. - If the turn ends when it's nobody's turn and the user didn't specify who goes next, pick a random player to go next. - Fixed ancient bug that caused a NPE, every time. Nobody tickled it by having a game where turns progress in a custom order. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@463 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../ezgame/server/EZGameTurnDelegate.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java index d8ca3733..010e8064 100644 --- a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java +++ b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java @@ -22,6 +22,7 @@ package com.threerings.ezgame.server; import com.samskivert.util.ListUtil; +import com.samskivert.util.RandomUtil; import com.threerings.util.Name; @@ -46,6 +47,13 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate endTurn(); } + @Override + protected void setFirstTurnHolder () + { + // make it nobody's turn + _turnIdx = -1; + } + @Override protected void setNextTurnHolder () { @@ -55,11 +63,17 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate Name nextPlayer = _nextPlayer; _nextPlayer = null; - int index = ListUtil.indexOf(_turnGame.getPlayers(), _nextPlayer); + int index = ListUtil.indexOf(_turnGame.getPlayers(), nextPlayer); if (index != -1) { _turnIdx = index; return; } + + } else if (_turnIdx == -1) { + // If it's nobody's turn, and the user does not specify a next-turn, randomize. + // We set turnIdx to the player we want - 1, so that when it gets inc'd it'll + // be right. + _turnIdx = RandomUtil.getInt(_turnGame.getPlayers().length) - 1; } // otherwise, do the default behavior