From 787d4f1fe5b15e823d1cd482309c36da993ebd75 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 12 Mar 2005 07:46:34 +0000 Subject: [PATCH] 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 --- .../parlor/game/data/GameConfig.java | 6 +++++ .../parlor/game/server/GameManager.java | 25 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/parlor/game/data/GameConfig.java b/src/java/com/threerings/parlor/game/data/GameConfig.java index f05c20631..017a7995f 100644 --- a/src/java/com/threerings/parlor/game/data/GameConfig.java +++ b/src/java/com/threerings/parlor/game/data/GameConfig.java @@ -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 diff --git a/src/java/com/threerings/parlor/game/server/GameManager.java b/src/java/com/threerings/parlor/game/server/GameManager.java index 1dc3abfa1..e5b26d155 100644 --- a/src/java/com/threerings/parlor/game/server/GameManager.java +++ b/src/java/com/threerings/parlor/game/server/GameManager.java @@ -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); }