Search in sources :

Example 11 with IDelegate

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);
}
Also used : IDelegate(games.strategy.engine.delegate.IDelegate)

Example 12 with IDelegate

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!");
    }
}
Also used : IPersistentDelegate(games.strategy.engine.delegate.IPersistentDelegate) MessengerException(games.strategy.engine.message.MessengerException) GameOverException(games.strategy.engine.GameOverException) IDelegate(games.strategy.engine.delegate.IDelegate)

Example 13 with IDelegate

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;
}
Also used : GameStep(games.strategy.engine.data.GameStep) IDelegate(games.strategy.engine.delegate.IDelegate) GameSequence(games.strategy.engine.data.GameSequence)

Aggregations

IDelegate (games.strategy.engine.delegate.IDelegate)13 GameOverException (games.strategy.engine.GameOverException)2 GameStep (games.strategy.engine.data.GameStep)2 DefaultDelegateBridge (games.strategy.engine.delegate.DefaultDelegateBridge)2 IPersistentDelegate (games.strategy.engine.delegate.IPersistentDelegate)2 DelegateHistoryWriter (games.strategy.engine.history.DelegateHistoryWriter)2 MessengerException (games.strategy.engine.message.MessengerException)2 Element (org.w3c.dom.Element)2 GameData (games.strategy.engine.data.GameData)1 GameParseException (games.strategy.engine.data.GameParseException)1 GameSequence (games.strategy.engine.data.GameSequence)1 XmlGameElementMapper (games.strategy.engine.data.gameparser.XmlGameElementMapper)1 GameProperties (games.strategy.engine.data.properties.GameProperties)1 AutoSave (games.strategy.engine.delegate.AutoSave)1 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)1 RemoteName (games.strategy.engine.message.RemoteName)1 RemoteNotFoundException (games.strategy.engine.message.RemoteNotFoundException)1 EndRoundDelegate (games.strategy.triplea.delegate.EndRoundDelegate)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1