use of games.strategy.engine.history.EventChild 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.engine.history.EventChild in project triplea by triplea-game.
the class BaseEditDelegate method logEvent.
// We don't know the current context, so we need to figure
// out whether it makes more sense to log a new event or a child.
// If any child events came before us, then we'll log a child event.
// Otherwise, we'll log a new event.
void logEvent(final String message, final Object renderingObject) {
// find last event node
final GameData gameData = getData();
gameData.acquireReadLock();
boolean foundChild = false;
try {
HistoryNode curNode = gameData.getHistory().getLastNode();
while (!(curNode instanceof Step) && !(curNode instanceof Event)) {
if (curNode instanceof EventChild) {
foundChild = true;
break;
}
curNode = (HistoryNode) curNode.getPreviousNode();
}
} finally {
gameData.releaseReadLock();
}
if (foundChild) {
bridge.getHistoryWriter().addChildToEvent(message, renderingObject);
} else {
bridge.getHistoryWriter().startEvent(message, renderingObject);
}
}
Aggregations