Call GameManagerDelegate.setAI() when a player is set to an AI player.
Don't expose the game manager's internal AI skill level array to external parties. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1502 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.36 2002/06/19 23:18:58 mdb Exp $
|
// $Id: GameManager.java,v 1.37 2002/06/19 23:41:25 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||||
@@ -80,19 +81,25 @@ public class GameManager extends PlaceManager
|
|||||||
* @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 skill the skill level, from 0 to 100 inclusive.
|
||||||
*/
|
*/
|
||||||
public void setAI (int pidx, byte skill)
|
public void setAI (final int pidx, final byte skill)
|
||||||
{
|
{
|
||||||
if (_AIs == null) {
|
if (_AIs == null) {
|
||||||
|
// create and initialize the AI skill level array
|
||||||
_AIs = new byte[_players.length];
|
_AIs = new byte[_players.length];
|
||||||
for (int ii=0; ii < _players.length; ii++) {
|
Arrays.fill(_AIs, (byte)-1);
|
||||||
_AIs[ii] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
_AIs[pidx] = skill;
|
_AIs[pidx] = skill;
|
||||||
|
|
||||||
|
// let the delegates know that the player's been made an AI
|
||||||
|
applyToDelegates(new DelegateOp() {
|
||||||
|
public void apply (PlaceManagerDelegate delegate) {
|
||||||
|
((GameManagerDelegate)delegate).setAI(pidx, skill);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,15 +126,6 @@ public class GameManager extends PlaceManager
|
|||||||
return _players.length;
|
return _players.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of the AI skill levels if AIs are present in this
|
|
||||||
* game.
|
|
||||||
*/
|
|
||||||
public byte[] getAIs ()
|
|
||||||
{
|
|
||||||
return _AIs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the player at the specified player index is an AI.
|
* Returns whether the player at the specified player index is an AI.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManagerDelegate.java,v 1.4 2002/04/19 21:40:38 ray Exp $
|
// $Id: GameManagerDelegate.java,v 1.5 2002/06/19 23:41:25 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
@@ -69,4 +69,12 @@ public class GameManagerDelegate extends PlaceManagerDelegate
|
|||||||
public void gameDidReset ()
|
public void gameDidReset ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the specified player has been set as an AI with the
|
||||||
|
* given skill level (ranging from 0 to 100 inclusive.)
|
||||||
|
*/
|
||||||
|
public void setAI (int pidx, byte skill)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user