- Moved AI handling framework here from PuzzleManager.
- Set game state to CANCELLED if it wasn't yet GAME_OVER when shutting down the game. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1281 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.26 2002/04/15 18:05:30 mdb Exp $
|
// $Id: GameManager.java,v 1.27 2002/04/19 18:33:10 ray Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
@@ -66,6 +66,30 @@ public class GameManager extends PlaceManager
|
|||||||
_playerOids = new int[players.length];
|
_playerOids = new int[players.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the specified player as an AI with the specified skill.
|
||||||
|
* It is assumed that this will be set soon after the player names for all
|
||||||
|
* AIs present in the game. (It should be done before human players start
|
||||||
|
* trickling into the game.)
|
||||||
|
*
|
||||||
|
* @param pidx the player index of the AI.
|
||||||
|
* @param skill the skill level, from 0 to 100 inclusive.
|
||||||
|
*/
|
||||||
|
public void setAI (int pidx, byte skill)
|
||||||
|
{
|
||||||
|
if (_AIs == null) {
|
||||||
|
_AIs = new byte[_players.length];
|
||||||
|
for (int ii=0; ii < _players.length; ii++) {
|
||||||
|
_AIs[ii] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// and register ourselves to receive AI ticks
|
||||||
|
AIGameTicker.registerAIGame(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_AIs[pidx] = skill;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of the usernames of the players in this game.
|
* Returns an array of the usernames of the players in this game.
|
||||||
*/
|
*/
|
||||||
@@ -115,6 +139,17 @@ public class GameManager extends PlaceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public void shutdown ()
|
||||||
|
{
|
||||||
|
super.shutdown();
|
||||||
|
|
||||||
|
// also remove ourselves from the AIticker, if applicable
|
||||||
|
if (_AIs != null) {
|
||||||
|
AIGameTicker.unregisterAIGame(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
protected void bodyLeft (int bodyOid)
|
protected void bodyLeft (int bodyOid)
|
||||||
{
|
{
|
||||||
@@ -132,6 +167,11 @@ public class GameManager extends PlaceManager
|
|||||||
Log.info("Game room empty. Going away. " +
|
Log.info("Game room empty. Going away. " +
|
||||||
"[gameOid=" + _gameobj.getOid() + "].");
|
"[gameOid=" + _gameobj.getOid() + "].");
|
||||||
|
|
||||||
|
// cancel the game if it wasn't over.
|
||||||
|
if (_gameobj.state != GameObject.GAME_OVER) {
|
||||||
|
_gameobj.setState(GameObject.CANCELLED);
|
||||||
|
}
|
||||||
|
|
||||||
// shut down the place (which will destroy the game object and
|
// shut down the place (which will destroy the game object and
|
||||||
// clean up after everything)
|
// clean up after everything)
|
||||||
shutdown();
|
shutdown();
|
||||||
@@ -209,6 +249,14 @@ public class GameManager extends PlaceManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the AIGameTicker if we're registered as an AI game.
|
||||||
|
*/
|
||||||
|
protected void tickAIs ()
|
||||||
|
{
|
||||||
|
// subclasses should implement their AI gameplay here
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the game is known to be over. This will call some
|
* Called when the game is known to be over. This will call some
|
||||||
* calldown functions to determine the winner of the game and then
|
* calldown functions to determine the winner of the game and then
|
||||||
@@ -332,7 +380,8 @@ public class GameManager extends PlaceManager
|
|||||||
if (_players[i].equals(body.username)) {
|
if (_players[i].equals(body.username)) {
|
||||||
_playerOids[i] = body.getOid();
|
_playerOids[i] = body.getOid();
|
||||||
}
|
}
|
||||||
if (_playerOids[i] == 0) {
|
if ((_playerOids[i] == 0) &&
|
||||||
|
((_AIs == null) || (_AIs[i] == -1))) {
|
||||||
allSet = false;
|
allSet = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,6 +402,10 @@ public class GameManager extends PlaceManager
|
|||||||
/** The usernames of the players of this game. */
|
/** The usernames of the players of this game. */
|
||||||
protected String[] _players;
|
protected String[] _players;
|
||||||
|
|
||||||
/** The oids of our player's body objects. */
|
/** The oids of our player and AI body objects. */
|
||||||
protected int[] _playerOids;
|
protected int[] _playerOids;
|
||||||
|
|
||||||
|
/** If AIs are present, contains their skill levels, or -1 at human
|
||||||
|
* player indexes.. */
|
||||||
|
protected byte[] _AIs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user