Allow AI configuration to be specified in the GameConfig and automatically
put into place before the game starts. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3400 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -52,6 +52,12 @@ public abstract class GameConfig extends PlaceConfig implements Cloneable
|
||||
/** Indicates whether or not this game is rated. */
|
||||
public boolean rated = true;
|
||||
|
||||
/** Configurations for AIs to be used in this game. Slots with real
|
||||
* players should be null and slots with AIs should contain
|
||||
* configuration for those AIs. A null array indicates no use of AIs
|
||||
* at all. */
|
||||
public GameAI[] ais;
|
||||
|
||||
/**
|
||||
* Returns the message bundle identifier for the bundle that should be
|
||||
* used to translate the translatable strings used to describe the
|
||||
|
||||
@@ -85,6 +85,14 @@ public class GameManager extends PlaceManager
|
||||
};
|
||||
_tickInterval.schedule(TICK_DELAY, true);
|
||||
}
|
||||
|
||||
// configure our AIs
|
||||
int aicount = (_gameconfig.ais == null) ? 0 : _gameconfig.ais.length;
|
||||
for (int ii = 0; ii < aicount; ii++) {
|
||||
if (_gameconfig.ais[ii] != null) {
|
||||
setAI(ii, _gameconfig.ais[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -475,6 +483,19 @@ public class GameManager extends PlaceManager
|
||||
return !isPartyGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes that need their AIs to be ticked periodically
|
||||
* should override this method and return true. Many AIs can act
|
||||
* entirely in reaction to game state changes and need no periodic
|
||||
* ticking which is why ticking is disabled by default.
|
||||
*
|
||||
* @see #tickAIs
|
||||
*/
|
||||
protected boolean needsAITick ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void didShutdown ()
|
||||
{
|
||||
@@ -688,7 +709,7 @@ public class GameManager extends PlaceManager
|
||||
}
|
||||
|
||||
// and register ourselves to receive AI ticks
|
||||
if (_AIs != null) {
|
||||
if (_AIs != null && needsAITick()) {
|
||||
AIGameTicker.registerAIGame(this);
|
||||
}
|
||||
}
|
||||
@@ -808,7 +829,7 @@ public class GameManager extends PlaceManager
|
||||
protected void gameDidEnd ()
|
||||
{
|
||||
// remove ourselves from the AI ticker, if applicable
|
||||
if (_AIs != null) {
|
||||
if (_AIs != null && needsAITick()) {
|
||||
AIGameTicker.unregisterAIGame(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user