diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index c59dd8661..d81a9d360 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -1,5 +1,5 @@ // -// $Id: Table.java,v 1.15 2003/03/27 23:25:59 mdb Exp $ +// $Id: Table.java,v 1.16 2003/03/27 23:45:04 mdb Exp $ package com.threerings.parlor.data; @@ -84,10 +84,11 @@ public class Table } /** - * Once a table is ready to play (see {@link #readyToStart}), the - * players array can be fetched using this method. It will return an - * array containing the usernames of all of the players in the game, - * sized properly and with each player in the appropriate position. + * Once a table is ready to play (see {@link #mayBeStarted} and {@link + * #shouldBeStarted}), the players array can be fetched using this + * method. It will return an array containing the usernames of all of + * the players in the game, sized properly and with each player in the + * appropriate position. */ public String[] getPlayers () { @@ -189,24 +190,41 @@ public class Table } /** - * Returns true if this table has occupants in all of the desired - * positions and should be started. + * Returns true if this table has a sufficient number of occupants + * that the game can be started. */ - public boolean readyToStart () + public boolean mayBeStarted () + { + // make sure at least the minimum number of players are here + int want = _tconfig.getMinimumPlayers(), have = 0; + for (int i = 0; i < occupants.length; i++) { + if (!StringUtil.blank(occupants[i])) { + if (++have == want) { + return true; + } + } + } + return false; + } + + /** + * Returns true if sufficient seats are occupied that the game should + * be automatically started. + */ + public boolean shouldBeStarted () { int need = _tconfig.getDesiredPlayers(); if (need == -1) { need = _tconfig.getMaximumPlayers(); } - - // make sure the first "need" players are filled in - for (int i = 0; i < need; i++) { + for (int i = 0; i < occupants.length; i++) { if (StringUtil.blank(occupants[i])) { - return false; + if (--need == 0) { + return true; + } } } - - return true; + return false; } /** diff --git a/src/java/com/threerings/parlor/data/TableConfig.java b/src/java/com/threerings/parlor/data/TableConfig.java index b5a71d556..4b4572811 100644 --- a/src/java/com/threerings/parlor/data/TableConfig.java +++ b/src/java/com/threerings/parlor/data/TableConfig.java @@ -1,5 +1,5 @@ // -// $Id: TableConfig.java,v 1.2 2001/10/23 20:23:29 mdb Exp $ +// $Id: TableConfig.java,v 1.3 2003/03/27 23:45:04 mdb Exp $ package com.threerings.parlor.data; @@ -21,10 +21,10 @@ public interface TableConfig public int getMaximumPlayers (); /** - * Returns the number of players desired for this game, or -1 if the - * table services should allow up to the maximum number of players to - * join the table, but also allow the game to be started by the table - * creator any time after the minimum number of players has arrived. + * Returns the number of players that when reached, will cause the + * game to automatically be started. If this value is -1 the game will + * not automatically be started until the maximum number of players is + * reached. */ public int getDesiredPlayers (); diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index d715958ec..ed0fbc464 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -1,5 +1,5 @@ // -// $Id: TableManager.java,v 1.8 2002/10/06 00:53:15 mdb Exp $ +// $Id: TableManager.java,v 1.9 2003/03/27 23:45:04 mdb Exp $ package com.threerings.parlor.server; @@ -157,8 +157,8 @@ public class TableManager throw new InvocationException(error); } - // determine whether or not it's time to start the game - if (table.readyToStart()) { + // if the table is sufficiently full, start the game automatically + if (table.shouldBeStarted()) { // create the game manager GameManager gmgr = createGameManager(table.config, table.getPlayers());