From 42aaf9d64d111186f59f6bc2f1644e23d949cb7b Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 17 Jun 2005 20:25:28 +0000 Subject: [PATCH] Moved team game configuration stuff into the TableConfig, added a method in Table to return the compressed team indices, added a new TeamGameManager which can be implemented to have the final team info communicated to the game manager. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3604 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/parlor/data/Table.java | 53 ++++++++++++++++++- .../threerings/parlor/data/TableConfig.java | 15 ++++-- .../TeamGameManager.java} | 19 ++++--- 3 files changed, 72 insertions(+), 15 deletions(-) rename src/java/com/threerings/parlor/game/{data/TeamGameConfig.java => server/TeamGameManager.java} (64%) diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index a4f9c7e36..a1bc709df 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -21,7 +21,10 @@ package com.threerings.parlor.data; +import com.samskivert.util.ArrayIntSet; +import com.samskivert.util.ListUtil; import com.samskivert.util.StringUtil; + import com.threerings.util.Name; import com.threerings.presents.dobj.DSet; @@ -163,6 +166,35 @@ public class Table return players; } + /** + * For a team game, get the team member indices of the compressed + * players array returned by getPlayers(). + */ + public int[][] getTeamMemberIndices () + { + int[][] teams = tconfig.teamMemberIndices; + if (teams == null) { + return null; + } + + // compress the team indexes down + ArrayIntSet set = new ArrayIntSet(); + int[][] newTeams = new int[teams.length][]; + Name[] players = getPlayers(); + for (int ii=0; ii < teams.length; ii++) { + set.clear(); + for (int jj=0; jj < teams[ii].length; jj++) { + Name occ = occupants[teams[ii][jj]]; + if (occ != null) { + set.add(ListUtil.indexOf(players, occ)); + } + } + newTeams[ii] = set.toIntArray(); + } + + return newTeams; + } + /** * Requests to seat the specified user at the specified position in * this table. @@ -247,7 +279,26 @@ public class Table */ public boolean mayBeStarted () { - return tconfig.minimumPlayerCount <= getOccupiedCount(); + if (tconfig.teamMemberIndices == null) { + // for a normal game, just check to see if we're past the minimum + return tconfig.minimumPlayerCount <= getOccupiedCount(); + + } else { + // for a team game, make sure each team has the minimum players + int[][] teams = tconfig.teamMemberIndices; + for (int ii=0; ii < teams.length; ii++) { + int teamCount = 0; + for (int jj=0; jj < teams[ii].length; jj++) { + if (occupants[teams[ii][jj]] != null) { + teamCount++; + } + } + if (teamCount < tconfig.minimumPlayerCount) { + return false; + } + } + return true; + } } /** diff --git a/src/java/com/threerings/parlor/data/TableConfig.java b/src/java/com/threerings/parlor/data/TableConfig.java index 63e1a6d24..d6d1355a9 100644 --- a/src/java/com/threerings/parlor/data/TableConfig.java +++ b/src/java/com/threerings/parlor/data/TableConfig.java @@ -29,14 +29,21 @@ import com.threerings.io.SimpleStreamableObject; */ public class TableConfig extends SimpleStreamableObject { - /** The number of players that are desired for the table, or -1 for a - * party game. */ + /** The total number of players that are desired for the table, + * or -1 for a party game. For team games, this should be set to the + * total number of players overall, as teams may be unequal. */ public int desiredPlayerCount; - /** The minimum number of players needed for the game to start at - * the creator's discretion. */ + /** The minimum number of players needed overall (or per-team if a + * team-based game) for the game to start at the creator's discretion. */ public int minimumPlayerCount; + /** If non-null, indicates that this is a team-based game and contains + * the team assignments for each player. For example, a game with + * three players in two teams- players 0 and 2 versus player 1- would + * have { {0, 2}, {1} }; */ + public int[][] teamMemberIndices; + /** Whether the table is "private". */ public boolean privateTable; } diff --git a/src/java/com/threerings/parlor/game/data/TeamGameConfig.java b/src/java/com/threerings/parlor/game/server/TeamGameManager.java similarity index 64% rename from src/java/com/threerings/parlor/game/data/TeamGameConfig.java rename to src/java/com/threerings/parlor/game/server/TeamGameManager.java index 58f164e29..91edbe7d4 100644 --- a/src/java/com/threerings/parlor/game/data/TeamGameConfig.java +++ b/src/java/com/threerings/parlor/game/server/TeamGameManager.java @@ -2,7 +2,7 @@ // $Id$ // // Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved +// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved // http://www.threerings.net/code/narya/ // // This library is free software; you can redistribute it and/or modify it @@ -19,19 +19,18 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -package com.threerings.parlor.game.data; - -import com.threerings.parlor.data.TableConfig; +package com.threerings.parlor.game.server; /** - * Provides additional information for games with teams. + * An interface to be implemented by a game if it wants to hear about + * the team indices that were configured during matchmaking. */ -public interface TeamGameConfig +public interface TeamGameManager { /** - * Returns the members of each team. For instance, a game with three - * players in two teams--players 0 and 2 versus player 1--would return - * { {0, 2}, {1} }. + * Set the team member indices. For example, a game with + * three players in two teams- players 0 and 2 versus player 1- would + * have { {0, 2}, {1} } set. */ - public int[][] getTeamMemberIndices(); + public void setTeamMemberIndices (int[][] teams); }