use of games.strategy.engine.delegate.IDelegate in project triplea by triplea-game.
the class GameDataManager method writeDelegates.
private static void writeDelegates(final GameData data, final ObjectOutputStream out) throws IOException {
for (final IDelegate delegate : data.getDelegateList()) {
out.writeObject(DELEGATE_START);
// write out the delegate info
out.writeObject(delegate.getName());
out.writeObject(delegate.getDisplayName());
out.writeObject(delegate.getClass().getName());
out.writeObject(DELEGATE_DATA_NEXT);
out.writeObject(delegate.saveState());
}
// mark end of delegate section
out.writeObject(DELEGATE_LIST_END);
}
use of games.strategy.engine.delegate.IDelegate in project triplea by triplea-game.
the class DefaultPlayerBridge method getRemotePersistentDelegate.
@Override
public IRemote getRemotePersistentDelegate(final String name) {
if (game.isGameOver()) {
throw new GameOverException("Game Over");
}
try {
game.getData().acquireReadLock();
try {
final IDelegate delegate = game.getData().getDelegateList().getDelegate(name);
if (delegate == null) {
final String errorMessage = "IDelegate in DefaultPlayerBridge.getRemote() cannot be null. Looking for delegate named: " + name;
// for some reason, client isn't getting or seeing the errors, so make sure we print it to err
System.err.println(errorMessage);
// too
throw new IllegalStateException(errorMessage);
}
if (!(delegate instanceof IPersistentDelegate)) {
return null;
}
return getRemoteThatChecksForGameOver(game.getRemoteMessenger().getRemote(ServerGame.getRemoteName(delegate)));
} finally {
game.getData().releaseReadLock();
}
} catch (final MessengerException me) {
throw new GameOverException("Game Over!");
}
}
use of games.strategy.engine.delegate.IDelegate in project triplea by triplea-game.
the class PlayerOrderComparator method compare.
/**
* sort based on first step that isn't a bid related step.
*/
@Override
public int compare(final PlayerID p1, final PlayerID p2) {
if (p1.equals(p2)) {
return 0;
}
gameData.acquireReadLock();
final GameSequence sequence;
try {
sequence = gameData.getSequence();
} finally {
gameData.releaseReadLock();
}
for (final GameStep s : sequence) {
if (s.getPlayerId() == null) {
continue;
}
gameData.acquireReadLock();
final IDelegate delegate;
try {
delegate = s.getDelegate();
} finally {
gameData.releaseReadLock();
}
if (delegate != null && delegate.getClass() != null) {
final String delegateClassName = delegate.getClass().getName();
if (delegateClassName.equals("games.strategy.triplea.delegate.InitializationDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.BidPurchaseDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.BidPlaceDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.EndRoundDelegate")) {
continue;
}
} else if (s.getName() != null && (s.getName().endsWith("Bid") || s.getName().endsWith("BidPlace"))) {
continue;
}
if (s.getPlayerId().equals(p1)) {
return -1;
} else if (s.getPlayerId().equals(p2)) {
return 1;
}
}
return 0;
}
Aggregations