Revamped the way AI configuration is specified to be more extensible.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3399 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-03-12 07:37:34 +00:00
parent b4e595bd3c
commit fb53600e92
5 changed files with 58 additions and 52 deletions
@@ -37,6 +37,7 @@ import com.threerings.crowd.server.PlaceManager;
import com.threerings.crowd.server.PlaceRegistry.CreationObserver; import com.threerings.crowd.server.PlaceRegistry.CreationObserver;
import com.threerings.crowd.server.PlaceRegistry; import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.parlor.game.data.GameAI;
import com.threerings.parlor.game.data.GameConfig; import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.GameObject; import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.game.server.GameManager; import com.threerings.parlor.game.server.GameManager;
@@ -135,7 +136,7 @@ public class SimulatorManager
for (int ii = 1; ii < _playerCount; ii++) { for (int ii = 1; ii < _playerCount; ii++) {
// mark all simulants as AI players // mark all simulants as AI players
_gmgr.setAI(ii, skill, (byte) 0); _gmgr.setAI(ii, new GameAI(0, skill));
} }
// resolve the simulant body objects // resolve the simulant body objects
@@ -0,0 +1,34 @@
//
// $Id$
package com.threerings.parlor.game.data;
import com.threerings.io.SimpleStreamableObject;
/**
* Represents attributes of an AI player.
*/
public class GameAI extends SimpleStreamableObject
{
/** The "personality" of the AI, which can be interpreted by
* each puzzle. */
public int personality;
/** The skill level of the AI. */
public int skill;
/** A blank constructor for serialization. */
public GameAI ()
{
}
/**
* Constructs an AI with the specified (game-interpreted) skill and
* personality.
*/
public GameAI (int personality, int skill)
{
this.personality = personality;
this.skill = skill;
}
}
@@ -1,32 +0,0 @@
//
// $Id$
package com.threerings.parlor.game.server;
/**
* Represents attributes of an AI player.
*/
public class AI
{
/** The skill level of the AI. */
public byte skill;
/** The "personality" of the AI, which can be interpreted by
* each puzzle. */
public byte personality;
/**
* Construct an AI.
*/
public AI (byte skill, byte personality)
{
this.skill = skill;
this.personality = personality;
}
// documentation inherited
public String toString ()
{
return "skill(" + skill + "), personality(" + personality + ")";
}
}
@@ -45,6 +45,7 @@ import com.threerings.crowd.server.PlaceManagerDelegate;
import com.threerings.parlor.Log; import com.threerings.parlor.Log;
import com.threerings.parlor.data.ParlorCodes; import com.threerings.parlor.data.ParlorCodes;
import com.threerings.parlor.game.data.GameAI;
import com.threerings.parlor.game.data.GameCodes; import com.threerings.parlor.game.data.GameCodes;
import com.threerings.parlor.game.data.GameConfig; import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.data.GameMarshaller; import com.threerings.parlor.game.data.GameMarshaller;
@@ -276,30 +277,30 @@ public class GameManager extends PlaceManager
} }
/** /**
* Sets the specified player as an AI with the specified skill. It is * Sets the specified player as an AI with the specified
* assumed that this will be set soon after the player names for all * configuration. It is assumed that this will be set soon after the
* AIs present in the game. (It should be done before human players * player names for all AIs present in the game. (It should be done
* start trickling into the game.) * before human players start trickling into the game.)
* *
* @param pidx the player index of the AI. * @param pidx the player index of the AI.
* @param skill the skill level, from 0 to 100 inclusive. * @param ai the AI configuration.
*/ */
public void setAI (final int pidx, final byte skill, final byte personality) public void setAI (final int pidx, final GameAI ai)
{ {
if (_AIs == null) { if (_AIs == null) {
// create and initialize the AI skill level array // create and initialize the AI configuration array
_AIs = new AI[getPlayerSlots()]; _AIs = new GameAI[getPlayerSlots()];
// set up a delegate op for AI ticking // set up a delegate op for AI ticking
_tickAIOp = new TickAIDelegateOp(); _tickAIOp = new TickAIDelegateOp();
} }
// save off the AI's skill level // save off the AI's configuration
_AIs[pidx] = new AI(skill, personality); _AIs[pidx] = ai;
// let the delegates know that the player's been made an AI // let the delegates know that the player's been made an AI
applyToDelegates(new DelegateOp() { applyToDelegates(new DelegateOp() {
public void apply (PlaceManagerDelegate delegate) { public void apply (PlaceManagerDelegate delegate) {
((GameManagerDelegate)delegate).setAI(pidx, skill, personality); ((GameManagerDelegate)delegate).setAI(pidx, ai);
} }
}); });
} }
@@ -708,7 +709,7 @@ public class GameManager extends PlaceManager
/** /**
* Called by tickAIs to tick each AI in the game. * Called by tickAIs to tick each AI in the game.
*/ */
protected void tickAI (int pidx, AI ai) protected void tickAI (int pidx, GameAI ai)
{ {
_tickAIOp.setAI(pidx, ai); _tickAIOp.setAI(pidx, ai);
applyToDelegates(_tickAIOp); applyToDelegates(_tickAIOp);
@@ -1052,14 +1053,14 @@ public class GameManager extends PlaceManager
((GameManagerDelegate) delegate).tickAI(_pidx, _ai); ((GameManagerDelegate) delegate).tickAI(_pidx, _ai);
} }
public void setAI (int pidx, AI ai) public void setAI (int pidx, GameAI ai)
{ {
_pidx = pidx; _pidx = pidx;
_ai = ai; _ai = ai;
} }
protected int _pidx; protected int _pidx;
protected AI _ai; protected GameAI _ai;
} }
/** /**
@@ -1083,9 +1084,9 @@ public class GameManager extends PlaceManager
/** The oids of our player and AI 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 /** If AIs are present, contains their configuration, or null at human
* player indexes. */ * player indexes. */
protected AI[] _AIs; protected GameAI[] _AIs;
/** If non-null, contains bundles and messages that should be sent as /** If non-null, contains bundles and messages that should be sent as
* system messages once the game has started. */ * system messages once the game has started. */
@@ -23,6 +23,8 @@ package com.threerings.parlor.game.server;
import com.threerings.crowd.server.PlaceManagerDelegate; import com.threerings.crowd.server.PlaceManagerDelegate;
import com.threerings.parlor.game.data.GameAI;
/** /**
* Extends the {@link PlaceManagerDelegate} mechanism with game manager * Extends the {@link PlaceManagerDelegate} mechanism with game manager
* specific methods. * specific methods.
@@ -59,7 +61,7 @@ public class GameManagerDelegate extends PlaceManagerDelegate
* @param pidx the player index to fake some gameplay for. * @param pidx the player index to fake some gameplay for.
* @param ai a record indicating the AI's configuration. * @param ai a record indicating the AI's configuration.
*/ */
public void tickAI (int pidx, AI ai) public void tickAI (int pidx, GameAI ai)
{ {
} }
@@ -88,9 +90,9 @@ public class GameManagerDelegate extends PlaceManagerDelegate
/** /**
* Called when the specified player has been set as an AI with the * Called when the specified player has been set as an AI with the
* given skill level (ranging from 0 to 100 inclusive.) * supplied AI configuration.
*/ */
public void setAI (int pidx, byte skill, byte personality) public void setAI (int pidx, GameAI ai)
{ {
} }
} }