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.");
}
}
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);
}
Aggregations