Search in sources :

Example 1 with PlayerList

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());
}
Also used : PlayerList(games.strategy.engine.data.PlayerList) Test(org.junit.jupiter.api.Test)

Example 2 with PlayerList

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);
            }
        }
    }
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) INode(games.strategy.net.INode) JList(javax.swing.JList) Set(java.util.Set) PlayerList(games.strategy.engine.data.PlayerList) HashMap(java.util.HashMap) Icon(javax.swing.Icon) Component(java.awt.Component) Collectors(java.util.stream.Collectors) SwingConstants(javax.swing.SwingConstants) PlayerManager(games.strategy.engine.data.PlayerManager) HashSet(java.util.HashSet) List(java.util.List) UiContext(games.strategy.triplea.ui.UiContext) IGame(games.strategy.engine.framework.IGame) ImageIcon(javax.swing.ImageIcon) Joiner(com.google.common.base.Joiner) ImageIcon(javax.swing.ImageIcon) INode(games.strategy.net.INode) PlayerManager(games.strategy.engine.data.PlayerManager) PlayerList(games.strategy.engine.data.PlayerList) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) HashSet(java.util.HashSet)

Example 3 with PlayerList

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 "";
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) PlayerList(games.strategy.engine.data.PlayerList)

Example 4 with PlayerList

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);
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) DefaultPlayerBridge(games.strategy.engine.gamePlayer.DefaultPlayerBridge) PlayerID(games.strategy.engine.data.PlayerID) RemoteName(games.strategy.engine.message.RemoteName) PlayerList(games.strategy.engine.data.PlayerList) IPlayerBridge(games.strategy.engine.gamePlayer.IPlayerBridge)

Example 5 with PlayerList

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);
    }
}
Also used : TriggerAttachment(games.strategy.triplea.attachments.TriggerAttachment) AbstractTriggerAttachment(games.strategy.triplea.attachments.AbstractTriggerAttachment) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) PlayerList(games.strategy.engine.data.PlayerList) PlayerAttachment(games.strategy.triplea.attachments.PlayerAttachment) ICondition(games.strategy.triplea.attachments.ICondition) HashSet(java.util.HashSet)

Aggregations

PlayerList (games.strategy.engine.data.PlayerList)7 PlayerID (games.strategy.engine.data.PlayerID)5 GameData (games.strategy.engine.data.GameData)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 Joiner (com.google.common.base.Joiner)1 GameParseException (games.strategy.engine.data.GameParseException)1 PlayerManager (games.strategy.engine.data.PlayerManager)1 RelationshipTracker (games.strategy.engine.data.RelationshipTracker)1 IGame (games.strategy.engine.framework.IGame)1 DefaultPlayerBridge (games.strategy.engine.gamePlayer.DefaultPlayerBridge)1 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)1 IPlayerBridge (games.strategy.engine.gamePlayer.IPlayerBridge)1 RemoteName (games.strategy.engine.message.RemoteName)1 INode (games.strategy.net.INode)1 AbstractTriggerAttachment (games.strategy.triplea.attachments.AbstractTriggerAttachment)1 ICondition (games.strategy.triplea.attachments.ICondition)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 TriggerAttachment (games.strategy.triplea.attachments.TriggerAttachment)1 UiContext (games.strategy.triplea.ui.UiContext)1