Added support for minimumPlayerCount, allowing tables to be started
before they're full. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3597 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -66,6 +66,8 @@ public class DefaultSwingTableConfigurator extends TableConfigurator
|
||||
public DefaultSwingTableConfigurator (int minPlayers,
|
||||
int desiredPlayers, int maxPlayers, boolean allowPrivate)
|
||||
{
|
||||
_config.minimumPlayerCount = minPlayers;
|
||||
|
||||
// create a slider for players, if applicable
|
||||
if (minPlayers != maxPlayers) {
|
||||
_playerSlider = new SimpleSlider(
|
||||
|
||||
@@ -63,12 +63,11 @@ public class Table
|
||||
|
||||
/**
|
||||
* Creates a new table instance, and assigns it the next monotonically
|
||||
* increasing table id. The supplied config instance must implement
|
||||
* {@link TableConfig} or a <code>ClassCastException</code> will be
|
||||
* thrown.
|
||||
* increasing table id.
|
||||
*
|
||||
* @param lobbyOid the object id of the lobby in which this table is
|
||||
* to live.
|
||||
* @param tconfig the table configuration for this table.
|
||||
* @param config the configuration of the game being matchmade by this
|
||||
* table.
|
||||
*/
|
||||
@@ -113,6 +112,33 @@ public class Table
|
||||
return tableId.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is no one sitting at this table.
|
||||
*/
|
||||
public boolean isEmpty ()
|
||||
{
|
||||
for (int i = 0; i < bodyOids.length; i++) {
|
||||
if (bodyOids[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of players currently occupying this table.
|
||||
*/
|
||||
public int getOccupiedCount ()
|
||||
{
|
||||
int count = 0;
|
||||
for (int ii = 0; ii < occupants.length; ii++) {
|
||||
if (occupants[ii] != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once a table is ready to play (see {@link #mayBeStarted} and {@link
|
||||
* #shouldBeStarted}), the players array can be fetched using this
|
||||
@@ -126,20 +152,11 @@ public class Table
|
||||
return null;
|
||||
}
|
||||
|
||||
// count up the players
|
||||
int pcount = 0;
|
||||
for (int i = 0; i < occupants.length; i++) {
|
||||
if (occupants[i] != null) {
|
||||
pcount++;
|
||||
}
|
||||
}
|
||||
|
||||
// create and populate the players array
|
||||
Name[] players = new Name[pcount];
|
||||
pcount = 0;
|
||||
for (int i = 0; i < occupants.length; i++) {
|
||||
if (occupants[i] != null) {
|
||||
players[pcount++] = occupants[i];
|
||||
Name[] players = new Name[getOccupiedCount()];
|
||||
for (int ii = 0, dex = 0; ii < occupants.length; ii++) {
|
||||
if (occupants[ii] != null) {
|
||||
players[dex++] = occupants[ii];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,19 +247,7 @@ public class Table
|
||||
*/
|
||||
public boolean mayBeStarted ()
|
||||
{
|
||||
// TODO: this becomes more meaningful if we implement games
|
||||
// that can optionally be started with less than the desired number
|
||||
|
||||
// make sure at least the minimum number of players are here
|
||||
int want = tconfig.desiredPlayerCount, have = 0;
|
||||
for (int i = 0; i < occupants.length; i++) {
|
||||
if (occupants[i] != null) {
|
||||
if (++have == want) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return tconfig.minimumPlayerCount <= getOccupiedCount();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,26 +256,7 @@ public class Table
|
||||
*/
|
||||
public boolean shouldBeStarted ()
|
||||
{
|
||||
int need = tconfig.desiredPlayerCount;
|
||||
for (int i = 0; i < occupants.length; i++) {
|
||||
if (occupants[i] != null && --need == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is no one sitting at this table.
|
||||
*/
|
||||
public boolean isEmpty ()
|
||||
{
|
||||
for (int i = 0; i < bodyOids.length; i++) {
|
||||
if (bodyOids[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return tconfig.desiredPlayerCount <= getOccupiedCount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,10 @@ public class TableConfig extends SimpleStreamableObject
|
||||
* party game. */
|
||||
public int desiredPlayerCount;
|
||||
|
||||
/** The minimum number of players needed for the game to start at
|
||||
* the creator's discretion. */
|
||||
public int minimumPlayerCount;
|
||||
|
||||
/** Whether the table is "private". */
|
||||
public boolean privateTable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user