Search in sources :

Example 1 with TripleAPlayer

use of games.strategy.triplea.TripleAPlayer in project triplea by triplea-game.

the class ServerGame method addPlayerTypesToGameData.

private void addPlayerTypesToGameData(final Collection<IGamePlayer> localPlayers, final PlayerManager allPlayers, final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    // start before making changes.
    if (getCurrentStep() == null || getCurrentStep().getPlayerId() == null || (firstRun)) {
        firstRun = false;
        return;
    }
    // we can't add a new event or add new changes if we are not in a step.
    final HistoryNode curNode = data.getHistory().getLastNode();
    if (!(curNode instanceof Step) && !(curNode instanceof Event) && !(curNode instanceof EventChild)) {
        return;
    }
    final CompositeChange change = new CompositeChange();
    final Set<String> allPlayersString = allPlayers.getPlayers();
    bridge.getHistoryWriter().startEvent("Game Loaded");
    for (final IGamePlayer player : localPlayers) {
        allPlayersString.remove(player.getName());
        final boolean isHuman = player instanceof TripleAPlayer;
        bridge.getHistoryWriter().addChildToEvent(player.getName() + ((player.getName().endsWith("s") || player.getName().endsWith("ese") || player.getName().endsWith("ish")) ? " are" : " is") + " now being played by: " + player.getType());
        final PlayerID p = data.getPlayerList().getPlayerId(player.getName());
        final String newWhoAmI = ((isHuman ? "Human" : "AI") + ":" + player.getType());
        if (!p.getWhoAmI().equals(newWhoAmI)) {
            change.add(ChangeFactory.changePlayerWhoAmIChange(p, newWhoAmI));
        }
    }
    final Iterator<String> playerIter = allPlayersString.iterator();
    while (playerIter.hasNext()) {
        final String player = playerIter.next();
        playerIter.remove();
        bridge.getHistoryWriter().addChildToEvent(player + ((player.endsWith("s") || player.endsWith("ese") || player.endsWith("ish")) ? " are" : " is") + " now being played by: Human:Client");
        final PlayerID p = data.getPlayerList().getPlayerId(player);
        final String newWhoAmI = "Human:Client";
        if (!p.getWhoAmI().equals(newWhoAmI)) {
            change.add(ChangeFactory.changePlayerWhoAmIChange(p, newWhoAmI));
        }
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
    needToInitialize = false;
    if (!allPlayersString.isEmpty()) {
        throw new IllegalStateException("Not all Player Types (ai/human/client) could be added to game data.");
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) GameStep(games.strategy.engine.data.GameStep) Step(games.strategy.engine.history.Step) EventChild(games.strategy.engine.history.EventChild) TripleAPlayer(games.strategy.triplea.TripleAPlayer) HistoryNode(games.strategy.engine.history.HistoryNode) Event(games.strategy.engine.history.Event) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 2 with TripleAPlayer

use of games.strategy.triplea.TripleAPlayer in project triplea by triplea-game.

the class TripleADisplay method reportMessageToAll.

@Override
public void reportMessageToAll(final String message, final String title, final boolean doNotIncludeHost, final boolean doNotIncludeClients, final boolean doNotIncludeObservers) {
    if (doNotIncludeHost && doNotIncludeClients && doNotIncludeObservers) {
        return;
    }
    if (doNotIncludeHost || doNotIncludeClients || doNotIncludeObservers) {
        boolean isHost = false;
        boolean isClient = false;
        boolean isObserver = true;
        for (final IGamePlayer player : ui.getLocalPlayers().getLocalPlayers()) {
            // if we have any local players, we are not an observer
            isObserver = false;
            if (player instanceof TripleAPlayer) {
                if (IGameLoader.CLIENT_PLAYER_TYPE.equals(player.getType())) {
                    isClient = true;
                } else {
                    isHost = true;
                }
            } else {
                // AIs are run by the host machine
                isHost = true;
            }
        }
        if ((doNotIncludeHost && isHost) || (doNotIncludeClients && isClient) || (doNotIncludeObservers && isObserver)) {
            return;
        }
    }
    ui.notifyMessage(message, title);
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) TripleAPlayer(games.strategy.triplea.TripleAPlayer)

Aggregations

IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)2 TripleAPlayer (games.strategy.triplea.TripleAPlayer)2 CompositeChange (games.strategy.engine.data.CompositeChange)1 GameData (games.strategy.engine.data.GameData)1 GameStep (games.strategy.engine.data.GameStep)1 PlayerID (games.strategy.engine.data.PlayerID)1 Event (games.strategy.engine.history.Event)1 EventChild (games.strategy.engine.history.EventChild)1 HistoryNode (games.strategy.engine.history.HistoryNode)1 Step (games.strategy.engine.history.Step)1