- In TurnGameManagerDelegate, pulled out random-turn picking into its
own method, so that subclasses can get that behavior without assuming their their superclass implementation of setFirstTurnHolder does that. - Use that in EZ's code, and also fall back to it if there's some problem with the user-specified next-turn value and it's nobody's turn. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@464 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -69,11 +69,12 @@ public class EZGameTurnDelegate extends TurnGameManagerDelegate
|
||||
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, if it's nobody's turn randomly pick a turn holder
|
||||
if (_turnIdx == -1) {
|
||||
assignTurnRandomly();
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, do the default behavior
|
||||
|
||||
@@ -194,18 +194,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
||||
*/
|
||||
protected void setFirstTurnHolder ()
|
||||
{
|
||||
int size = _turnGame.getPlayers().length;
|
||||
if (size > 0) {
|
||||
int firstPick = _turnIdx = RandomUtil.getInt(size);
|
||||
while (!_tgmgr.isActivePlayer(_turnIdx)) {
|
||||
_turnIdx = (_turnIdx + 1) % size;
|
||||
if (_turnIdx == firstPick) {
|
||||
Log.warning("No players eligible for first turn. Choking. " +
|
||||
"[game=" + where() + "].");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
assignTurnRandomly();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,6 +226,25 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
||||
} while (!_tgmgr.isActivePlayer(_turnIdx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to randomly assign the turn.
|
||||
*/
|
||||
protected void assignTurnRandomly ()
|
||||
{
|
||||
int size = _turnGame.getPlayers().length;
|
||||
if (size > 0) {
|
||||
int firstPick = _turnIdx = RandomUtil.getInt(size);
|
||||
while (!_tgmgr.isActivePlayer(_turnIdx)) {
|
||||
_turnIdx = (_turnIdx + 1) % size;
|
||||
if (_turnIdx == firstPick) {
|
||||
Log.warning("No players eligible for randomly-assigned turn. Choking. " +
|
||||
"[game=" + where() + "].");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The game manager for which we are delegating. */
|
||||
protected TurnGameManager _tgmgr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user