- Revamped PartyGameConfig so that it can report which type of party game

it is (seated or free-for-all) or if it's not a party game after all
  (which the old interface supported and we may need in the future).
- Cleaned up the setting of table occupants to make the extension in yohoho
  cleaner.
- tables are now party-game aware and will do the right thing with
  the occupants list.
- simplified Table.equals() and added a corresponding hashCode(), because
  two objects that are equals() must give the same hashCode.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3804 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-01-13 01:52:36 +00:00
parent bf45bb876e
commit 7f98cac7a8
5 changed files with 86 additions and 41 deletions
+53 -19
View File
@@ -29,8 +29,11 @@ import com.threerings.util.Name;
import com.threerings.presents.dobj.DSet; import com.threerings.presents.dobj.DSet;
import com.threerings.crowd.data.BodyObject;
import com.threerings.parlor.data.ParlorCodes; import com.threerings.parlor.data.ParlorCodes;
import com.threerings.parlor.game.data.GameConfig; import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.PartyGameConfig;
/** /**
* This class represents a table that is being used to matchmake a game by * This class represents a table that is being used to matchmake a game by
@@ -151,8 +154,8 @@ public class Table
*/ */
public Name[] getPlayers () public Name[] getPlayers ()
{ {
if (occupants == null) { if (isPartyGame()) {
return null; return occupants;
} }
// create and populate the players array // create and populate the players array
@@ -195,19 +198,40 @@ public class Table
return newTeams; return newTeams;
} }
/**
* Return true if the game is a party game.
*/
public boolean isPartyGame ()
{
return (PartyGameConfig.NOT_PARTY_GAME != getPartyGameType());
}
/**
* Get the type of party game being played at this table, or
* PartyGameConfig.NOT_PARTY_GAME.
*/
public byte getPartyGameType ()
{
if (config instanceof PartyGameConfig) {
return ((PartyGameConfig) config).getPartyGameType();
} else {
return PartyGameConfig.NOT_PARTY_GAME;
}
}
/** /**
* Requests to seat the specified user at the specified position in * Requests to seat the specified user at the specified position in
* this table. * this table.
* *
* @param position the position in which to seat the user. * @param position the position in which to seat the user.
* @param username the username of the user to be set. * @param occupant the occupant to set.
* @param bodyOid the body object id of the user to be set.
* *
* @return null if the user was successfully seated, a string error * @return null if the user was successfully seated, a string error
* code explaining the failure if the user was not able to be seated * code explaining the failure if the user was not able to be seated
* at that position. * at that position.
*/ */
public String setOccupant (int position, Name username, int bodyOid) public String setOccupant (int position, BodyObject occupant)
{ {
// make sure the requested position is a valid one // make sure the requested position is a valid one
if (position >= tconfig.desiredPlayerCount || position < 0) { if (position >= tconfig.desiredPlayerCount || position < 0) {
@@ -220,11 +244,21 @@ public class Table
} }
// otherwise all is well, stick 'em in // otherwise all is well, stick 'em in
occupants[position] = username; setOccupantPos(position, occupant);
bodyOids[position] = bodyOid;
return null; return null;
} }
/**
* This method is used for party games, it does no bounds checking
* or verification of the player's ability to join, if you are unsure
* you should call 'setOccupant'.
*/
public void setOccupantPos (int position, BodyObject occupant)
{
occupants[position] = occupant.getVisibleName();
bodyOids[position] = occupant.getOid();
}
/** /**
* Requests that the specified user be removed from their seat at this * Requests that the specified user be removed from their seat at this
* table. * table.
@@ -264,10 +298,10 @@ public class Table
} }
/** /**
* Internal method used for clearing an occupant once we've located * Called to clear an occupant at the specified position.
* the right position. * Only call this method if you know what you're doing.
*/ */
protected void clearOccupantPos (int position) public void clearOccupantPos (int position)
{ {
occupants[position] = null; occupants[position] = null;
bodyOids[position] = 0; bodyOids[position] = 0;
@@ -325,17 +359,17 @@ public class Table
return tableId; return tableId;
} }
/** // documentation inherited
* Returns true if this table is equal to the supplied object (which
* must be a table with the same table id).
*/
public boolean equals (Object other) public boolean equals (Object other)
{ {
if (other != null && other instanceof Table) { return (other instanceof Table) &&
return ((Table)other).tableId.equals(tableId); tableId.equals(((Table) other).tableId);
} else { }
return false;
} // documentation inherited
public int hashCode ()
{
return tableId.intValue();
} }
/** /**
@@ -309,8 +309,9 @@ public abstract class GameController extends PlaceController
*/ */
protected boolean isPartyGame () protected boolean isPartyGame ()
{ {
return ((_config instanceof PartyGameConfig) && return (_config instanceof PartyGameConfig) &&
((PartyGameConfig)_config).isPartyGame()); (((PartyGameConfig)_config).getPartyGameType() !=
PartyGameConfig.NOT_PARTY_GAME);
} }
/** A reference to the active parlor context. */ /** A reference to the active parlor context. */
@@ -23,17 +23,28 @@ package com.threerings.parlor.game.data;
/** /**
* Provides additional information for party games. * Provides additional information for party games.
* A party game is a game in which the players are not set prior to starting,
* but players can come and go at will during the normal progression of
* the game.
*/ */
public interface PartyGameConfig public interface PartyGameConfig
{ {
/** /** Party game constant indicating that this game, while it does
* Returns true if this party game is being played in party game mode, * implement PartyGameConfig, is not currently being played in party
* false if it is not. * mode. */
*/ public static final byte NOT_PARTY_GAME = 0;
public boolean isPartyGame ();
/** Party game constant indicating that we're in a party game in which
* players must sit at an available seat to play, otherwise they're
* an observer. */
public static final byte SEATED_PARTY_GAME = 1;
/** Party game constant indicating that everyone in the game place is
* a "player", meaning that they do not need to claim a seat to play. */
public static final byte FREE_FOR_ALL_PARTY_GAME = 2;
/** /**
* Configures this game config as a party game or not. * Get the type of party game being played.
*/ */
public void setPartyGame (boolean isPartyGame); public byte getPartyGameType ();
} }
@@ -106,6 +106,16 @@ public class GameManager extends PlaceManager
return _gameconfig; return _gameconfig;
} }
/**
* Used to determine if this game is a party game.
*/
public boolean isPartyGame ()
{
return (_gameconfig instanceof PartyGameConfig) &&
(((PartyGameConfig)_gameconfig).getPartyGameType() !=
PartyGameConfig.NOT_PARTY_GAME);
}
/** /**
* Adds the given player to the game at the first available player * Adds the given player to the game at the first available player
* index. This should only be called before the game is started, and * index. This should only be called before the game is started, and
@@ -1200,15 +1210,6 @@ public class GameManager extends PlaceManager
protected GameAI _ai; protected GameAI _ai;
} }
/**
* Used to determine if this game is a party game.
*/
protected boolean isPartyGame ()
{
return ((_gameconfig instanceof PartyGameConfig) &&
((PartyGameConfig)_gameconfig).isPartyGame());
}
/** A reference to our game config. */ /** A reference to our game config. */
protected GameConfig _gameconfig; protected GameConfig _gameconfig;
@@ -113,8 +113,7 @@ public class TableManager
// stick the creator into the first non-AI position // stick the creator into the first non-AI position
int cpos = (config.ais == null) ? 0 : config.ais.length; int cpos = (config.ais == null) ? 0 : config.ais.length;
String error = String error = table.setOccupant(cpos, creator);
table.setOccupant(cpos, creator.getVisibleName(), creator.getOid());
if (error != null) { if (error != null) {
Log.warning("Unable to add creator to position zero of " + Log.warning("Unable to add creator to position zero of " +
"table!? [table=" + table + ", creator=" + creator + "table!? [table=" + table + ", creator=" + creator +
@@ -170,8 +169,7 @@ public class TableManager
} }
// request that the user be added to the table at that position // request that the user be added to the table at that position
String error = table.setOccupant( String error = table.setOccupant(position, joiner);
position, joiner.getVisibleName(), joiner.getOid());
// if that failed, report the error // if that failed, report the error
if (error != null) { if (error != null) {
throw new InvocationException(error); throw new InvocationException(error);