Further AI handling improvements.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3401 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -89,6 +89,13 @@ public class Table
|
|||||||
// make room for the maximum number of players
|
// make room for the maximum number of players
|
||||||
occupants = new Name[_tconfig.getMaximumPlayers()];
|
occupants = new Name[_tconfig.getMaximumPlayers()];
|
||||||
bodyOids = new int[occupants.length];
|
bodyOids = new int[occupants.length];
|
||||||
|
|
||||||
|
// fill in information on the AIs
|
||||||
|
int acount = (config.ais == null) ? 0 : config.ais.length;
|
||||||
|
for (int ii = 0; ii < acount; ii++) {
|
||||||
|
// TODO: handle this naming business better
|
||||||
|
occupants[ii] = new Name("AI " + (ii+1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -265,8 +272,8 @@ public class Table
|
|||||||
*/
|
*/
|
||||||
public boolean isEmpty ()
|
public boolean isEmpty ()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < occupants.length; i++) {
|
for (int i = 0; i < bodyOids.length; i++) {
|
||||||
if (occupants[i] != null) {
|
if (bodyOids[i] != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public abstract class GameConfig extends PlaceConfig implements Cloneable
|
|||||||
* players should be null and slots with AIs should contain
|
* players should be null and slots with AIs should contain
|
||||||
* configuration for those AIs. A null array indicates no use of AIs
|
* configuration for those AIs. A null array indicates no use of AIs
|
||||||
* at all. */
|
* at all. */
|
||||||
public GameAI[] ais;
|
public GameAI[] ais = new GameAI[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message bundle identifier for the bundle that should be
|
* Returns the message bundle identifier for the bundle that should be
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ public class GameManager extends PlaceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure our AIs
|
// configure our AIs
|
||||||
int aicount = (_gameconfig.ais == null) ? 0 : _gameconfig.ais.length;
|
for (int ii = 0; ii < _gameconfig.ais.length; ii++) {
|
||||||
for (int ii = 0; ii < aicount; ii++) {
|
|
||||||
if (_gameconfig.ais[ii] != null) {
|
if (_gameconfig.ais[ii] != null) {
|
||||||
setAI(ii, _gameconfig.ais[ii]);
|
setAI(ii, _gameconfig.ais[ii]);
|
||||||
}
|
}
|
||||||
@@ -446,8 +445,8 @@ 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 < getPlayerSlots(); ii++) {
|
for (int ii = 0; ii < getPlayerSlots(); ii++) {
|
||||||
// skip non-existent players
|
// skip non-existent players and AIs
|
||||||
if (!_gameobj.isOccupiedPlayer(ii)) {
|
if (!_gameobj.isOccupiedPlayer(ii) || isAI(ii)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,9 +116,10 @@ public class TableManager
|
|||||||
// create a brand spanking new table
|
// create a brand spanking new table
|
||||||
Table table = new Table(_plobj.getOid(), config);
|
Table table = new Table(_plobj.getOid(), config);
|
||||||
|
|
||||||
// stick the creator into position zero
|
// stick the creator into the first non-AI position
|
||||||
|
int cpos = (config.ais == null) ? 0 : config.ais.length;
|
||||||
String error =
|
String error =
|
||||||
table.setOccupant(0, creator.username, creator.getOid());
|
table.setOccupant(cpos, creator.username, 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 +
|
||||||
@@ -275,9 +276,9 @@ public class TableManager
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
CrowdServer.plreg.createPlace(table.config, obs);
|
CrowdServer.plreg.createPlace(table.config, obs);
|
||||||
} catch (InstantiationException ie) {
|
} catch (Throwable t) {
|
||||||
Log.warning("Failed to create manager for game " +
|
Log.warning("Failed to create manager for game " +
|
||||||
"[config=" + table.config + "]: " + ie);
|
"[config=" + table.config + "]: " + t);
|
||||||
throw new InvocationException(INTERNAL_ERROR);
|
throw new InvocationException(INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user