Added getPlayerSlots() which returns the maximum number of players allowed
in the game and which doesn't choke if called before we have a game object. Modified code to use it where appropriate. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1824 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.49 2002/10/24 07:01:08 shaper Exp $
|
// $Id: GameManager.java,v 1.50 2002/10/24 18:51:41 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
@@ -62,8 +62,7 @@ public class GameManager extends PlaceManager
|
|||||||
{
|
{
|
||||||
// determine the first available player index
|
// determine the first available player index
|
||||||
int pidx = -1;
|
int pidx = -1;
|
||||||
int size = _gameobj.players.length;
|
for (int ii = 0; ii < getPlayerSlots(); ii++) {
|
||||||
for (int ii = 0; ii < size; ii++) {
|
|
||||||
if (!_gameobj.isOccupiedPlayer(ii)) {
|
if (!_gameobj.isOccupiedPlayer(ii)) {
|
||||||
pidx = ii;
|
pidx = ii;
|
||||||
break;
|
break;
|
||||||
@@ -95,7 +94,7 @@ public class GameManager extends PlaceManager
|
|||||||
public boolean addPlayerAt (String player, int pidx)
|
public boolean addPlayerAt (String player, int pidx)
|
||||||
{
|
{
|
||||||
// make sure the specified player index is valid
|
// make sure the specified player index is valid
|
||||||
if (pidx < 0 || pidx >= _gameobj.players.length) {
|
if (pidx < 0 || pidx >= getPlayerSlots()) {
|
||||||
Log.warning("Attempt to add player at an invalid index " +
|
Log.warning("Attempt to add player at an invalid index " +
|
||||||
"[game=" + _gameobj.which() + ", player=" + player +
|
"[game=" + _gameobj.which() + ", player=" + player +
|
||||||
", pidx=" + pidx + "].");
|
", pidx=" + pidx + "].");
|
||||||
@@ -227,7 +226,7 @@ public class GameManager extends PlaceManager
|
|||||||
{
|
{
|
||||||
if (_AIs == null) {
|
if (_AIs == null) {
|
||||||
// create and initialize the AI skill level array
|
// create and initialize the AI skill level array
|
||||||
_AIs = new byte[_gameobj.players.length];
|
_AIs = new byte[getPlayerCount()];
|
||||||
Arrays.fill(_AIs, (byte)-1);
|
Arrays.fill(_AIs, (byte)-1);
|
||||||
// set up a delegate op for AI ticking
|
// set up a delegate op for AI ticking
|
||||||
_tickAIOp = new TickAIDelegateOp();
|
_tickAIOp = new TickAIDelegateOp();
|
||||||
@@ -277,6 +276,14 @@ public class GameManager extends PlaceManager
|
|||||||
return _playerCount;
|
return _playerCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of players allowed in this game.
|
||||||
|
*/
|
||||||
|
public int getPlayerSlots ()
|
||||||
|
{
|
||||||
|
return _gameconfig.players.length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the player at the specified player index is an AI.
|
* Returns whether the player at the specified player index is an AI.
|
||||||
*/
|
*/
|
||||||
@@ -346,8 +353,7 @@ public class GameManager extends PlaceManager
|
|||||||
_playerCount = _gameobj.getPlayerCount();
|
_playerCount = _gameobj.getPlayerCount();
|
||||||
|
|
||||||
// instantiate a player oid array which we'll fill in later
|
// instantiate a player oid array which we'll fill in later
|
||||||
int size = _gameobj.players.length;
|
_playerOids = new int[getPlayerSlots()];
|
||||||
_playerOids = new int[size];
|
|
||||||
|
|
||||||
// create and fill in our game service object
|
// create and fill in our game service object
|
||||||
GameMarshaller service = (GameMarshaller)
|
GameMarshaller service = (GameMarshaller)
|
||||||
@@ -359,7 +365,7 @@ public class GameManager extends PlaceManager
|
|||||||
|
|
||||||
// let the players of this game know that we're ready to roll (if
|
// let the players of this game know that we're ready to roll (if
|
||||||
// we have a specific set of players)
|
// we have a specific set of players)
|
||||||
for (int ii = 0; ii < size; ii++) {
|
for (int ii = 0; ii < getPlayerSlots(); ii++) {
|
||||||
// skip non-existent players
|
// skip non-existent players
|
||||||
if (!_gameobj.isOccupiedPlayer(ii)) {
|
if (!_gameobj.isOccupiedPlayer(ii)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -673,8 +679,7 @@ public class GameManager extends PlaceManager
|
|||||||
*/
|
*/
|
||||||
protected boolean allPlayersReady ()
|
protected boolean allPlayersReady ()
|
||||||
{
|
{
|
||||||
int pcount = _gameobj.players.length;
|
for (int ii = 0; ii < getPlayerSlots(); ii++) {
|
||||||
for (int ii = 0; ii < pcount; ii++) {
|
|
||||||
if (_gameobj.isOccupiedPlayer(ii) &&
|
if (_gameobj.isOccupiedPlayer(ii) &&
|
||||||
(_playerOids[ii] == 0) &&
|
(_playerOids[ii] == 0) &&
|
||||||
(_AIs == null || _AIs[ii] == -1)) {
|
(_AIs == null || _AIs[ii] == -1)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user