use of games.strategy.engine.data.PlayerList in project triplea by triplea-game.
the class ParserTest method testPlayersAdded.
@Test
public void testPlayersAdded() {
final PlayerList players = gameData.getPlayerList();
assertEquals(3, players.size());
}
use of games.strategy.engine.data.PlayerList in project triplea by triplea-game.
the class PlayerChatRenderer method setIconMap.
private void setIconMap() {
final PlayerManager playerManager = game.getPlayerManager();
PlayerList playerList;
game.getData().acquireReadLock();
try {
playerList = game.getData().getPlayerList();
} finally {
game.getData().releaseReadLock();
}
// new HashSet removes duplicates
for (final INode playerNode : new HashSet<>(playerManager.getPlayerMapping().values())) {
final Set<String> players = playerManager.getPlayedBy(playerNode);
if (players.size() > 0) {
final List<Icon> icons = players.stream().filter(player -> uiContext != null && uiContext.getFlagImageFactory() != null).map(player -> new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(playerList.getPlayerId(player)))).collect(Collectors.toList());
maxIconCounter = Math.max(maxIconCounter, icons.size());
playerMap.put(playerNode.toString(), players);
if (uiContext == null) {
iconMap.put(playerNode.toString(), null);
} else {
iconMap.put(playerNode.toString(), icons);
}
}
}
}
use of games.strategy.engine.data.PlayerList in project triplea by triplea-game.
the class EndTurnDelegate method doNationalObjectivesAndOtherEndTurnEffects.
@Override
protected String doNationalObjectivesAndOtherEndTurnEffects(final IDelegateBridge bridge) {
final GameData data = getData();
final PlayerList playerList = data.getPlayerList();
final PlayerID british = playerList.getPlayerId(Constants.PLAYER_NAME_BRITISH);
final PlayerID japanese = playerList.getPlayerId(Constants.PLAYER_NAME_JAPANESE);
// Quick check to see who still owns their own capital
final boolean britain = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(british, data).getOwner().equals(british);
final boolean japan = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(japanese, data).getOwner().equals(japanese);
if (!m_gameOver) {
if (britain && !japan) {
m_gameOver = true;
bridge.getHistoryWriter().startEvent("British win.");
}
if (!britain && japan) {
m_gameOver = true;
bridge.getHistoryWriter().startEvent("Japanese win.");
}
}
return "";
}
use of games.strategy.engine.data.PlayerList in project triplea by triplea-game.
the class AbstractGame method setupLocalPlayers.
private void setupLocalPlayers(final Set<IGamePlayer> localPlayers) {
final PlayerList playerList = gameData.getPlayerList();
for (final IGamePlayer gp : localPlayers) {
final PlayerID player = playerList.getPlayerId(gp.getName());
gamePlayers.put(player, gp);
final IPlayerBridge bridge = new DefaultPlayerBridge(this);
gp.initialize(bridge, player);
final RemoteName descriptor = ServerGame.getRemoteName(gp.getPlayerId(), gameData);
remoteMessenger.registerRemote(gp, descriptor);
}
}
use of games.strategy.engine.data.PlayerList in project triplea by triplea-game.
the class EndRoundDelegate method start.
@Override
public void start() {
super.start();
if (gameOver) {
return;
}
String victoryMessage;
final GameData data = getData();
if (isPacificTheater()) {
final PlayerID japanese = data.getPlayerList().getPlayerId(Constants.PLAYER_NAME_JAPANESE);
final PlayerAttachment pa = PlayerAttachment.get(japanese);
if (pa != null && pa.getVps() >= 22) {
victoryMessage = "Axis achieve VP victory";
bridge.getHistoryWriter().startEvent(victoryMessage);
final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance(data.getAllianceTracker().getAlliancesPlayerIsIn(japanese).iterator().next());
signalGameOver(victoryMessage, winners, bridge);
}
}
// Check for Winning conditions
if (isTotalVictory()) {
// Check for Win by Victory Cities
victoryMessage = " achieve TOTAL VICTORY with ";
checkVictoryCities(bridge, victoryMessage, " Total Victory VCs");
}
if (isHonorableSurrender()) {
victoryMessage = " achieve an HONORABLE VICTORY with ";
checkVictoryCities(bridge, victoryMessage, " Honorable Victory VCs");
}
if (isProjectionOfPower()) {
victoryMessage = " achieve victory through a PROJECTION OF POWER with ";
checkVictoryCities(bridge, victoryMessage, " Projection of Power VCs");
}
if (isEconomicVictory()) {
// Check for regular economic victory
for (final String allianceName : data.getAllianceTracker().getAlliances()) {
final int victoryAmount = getEconomicVictoryAmount(data, allianceName);
final Set<PlayerID> teamMembers = data.getAllianceTracker().getPlayersInAlliance(allianceName);
int teamProd = 0;
for (final PlayerID player : teamMembers) {
teamProd += getProduction(player);
if (teamProd >= victoryAmount) {
victoryMessage = allianceName + " achieve economic victory";
bridge.getHistoryWriter().startEvent(victoryMessage);
final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance(allianceName);
// Added this to end the game on victory conditions
signalGameOver(victoryMessage, winners, bridge);
}
}
}
}
// now check for generic trigger based victories
if (isTriggeredVictory()) {
// First set up a match for what we want to have fire as a default in this delegate. List out as a composite match
// OR.
// use 'null, null' because this is the Default firing location for any trigger that does NOT have 'when' set.
final Predicate<TriggerAttachment> endRoundDelegateTriggerMatch = AbstractTriggerAttachment.availableUses.and(AbstractTriggerAttachment.whenOrDefaultMatch(null, null)).and(TriggerAttachment.activateTriggerMatch().or(TriggerAttachment.victoryMatch()));
// get all possible triggers based on this match.
final HashSet<TriggerAttachment> toFirePossible = TriggerAttachment.collectForAllTriggersMatching(new HashSet<>(data.getPlayerList().getPlayers()), endRoundDelegateTriggerMatch);
if (!toFirePossible.isEmpty()) {
// get all conditions possibly needed by these triggers, and then test them.
final HashMap<ICondition, Boolean> testedConditions = TriggerAttachment.collectTestsForAllTriggers(toFirePossible, bridge);
// get all triggers that are satisfied based on the tested conditions.
final Set<TriggerAttachment> toFireTestedAndSatisfied = new HashSet<>(CollectionUtils.getMatches(toFirePossible, AbstractTriggerAttachment.isSatisfiedMatch(testedConditions)));
// now list out individual types to fire, once for each of the matches above.
TriggerAttachment.triggerActivateTriggerOther(testedConditions, toFireTestedAndSatisfied, bridge, null, null, true, true, true, true);
// will call
TriggerAttachment.triggerVictory(toFireTestedAndSatisfied, bridge, null, null, true, true, true, true);
// signalGameOver itself
}
}
if (isWW2V2() || isWW2V3()) {
return;
}
final PlayerList playerList = data.getPlayerList();
// now test older maps that only use these 5 players, to see if someone has won
final PlayerID russians = playerList.getPlayerId(Constants.PLAYER_NAME_RUSSIANS);
final PlayerID germans = playerList.getPlayerId(Constants.PLAYER_NAME_GERMANS);
final PlayerID british = playerList.getPlayerId(Constants.PLAYER_NAME_BRITISH);
final PlayerID japanese = playerList.getPlayerId(Constants.PLAYER_NAME_JAPANESE);
final PlayerID americans = playerList.getPlayerId(Constants.PLAYER_NAME_AMERICANS);
if (germans == null || russians == null || british == null || japanese == null || americans == null || playerList.size() > 5) {
return;
}
// Quick check to see who still owns their own capital
final boolean russia = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(russians, data).getOwner().equals(russians);
final boolean germany = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(germans, data).getOwner().equals(germans);
final boolean britain = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(british, data).getOwner().equals(british);
final boolean japan = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(japanese, data).getOwner().equals(japanese);
final boolean america = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(americans, data).getOwner().equals(americans);
int count = 0;
if (!russia) {
count++;
}
if (!britain) {
count++;
}
if (!america) {
count++;
}
victoryMessage = " achieve a military victory";
if (germany && japan && count >= 2) {
bridge.getHistoryWriter().startEvent("Axis" + victoryMessage);
final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance("Axis");
signalGameOver("Axis" + victoryMessage, winners, bridge);
}
if (russia && !germany && britain && !japan && america) {
bridge.getHistoryWriter().startEvent("Allies" + victoryMessage);
final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance("Allies");
signalGameOver("Allies" + victoryMessage, winners, bridge);
}
}
Aggregations