Search in sources :

Example 36 with PlayerID

use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.

the class GameStepPropertiesHelper method getRepairPlayers.

/**
 * @return a set of player ids. if argument player is not null this set will definitely include that player, but if
 *         not the set could be
 *         empty. never null.
 */
public static Set<PlayerID> getRepairPlayers(final GameData data, final PlayerID player) {
    data.acquireReadLock();
    final Set<PlayerID> allowedIDs = new HashSet<>();
    try {
        final String allowedPlayers = data.getSequence().getStep().getProperties().getProperty(GameStep.PropertyKeys.REPAIR_PLAYERS);
        if (player != null) {
            allowedIDs.add(player);
        }
        if (allowedPlayers != null) {
            for (final String p : allowedPlayers.split(":")) {
                final PlayerID id = data.getPlayerList().getPlayerId(p);
                if (id == null) {
                    System.err.println("gamePlay sequence step: " + data.getSequence().getStep().getName() + " stepProperty: " + GameStep.PropertyKeys.REPAIR_PLAYERS + " player: " + p + " DOES NOT EXIST");
                } else {
                    allowedIDs.add(id);
                }
            }
        }
    } finally {
        data.releaseReadLock();
    }
    return allowedIDs;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) HashSet(java.util.HashSet)

Example 37 with PlayerID

use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.

the class EditDelegate method changePoliticalRelationships.

@Override
public String changePoliticalRelationships(final Collection<Triple<PlayerID, PlayerID, RelationshipType>> relationshipChanges) {
    if (relationshipChanges == null || relationshipChanges.isEmpty()) {
        return null;
    }
    String result = checkEditMode();
    if (result != null) {
        return result;
    }
    result = EditValidator.validateChangePoliticalRelationships(relationshipChanges);
    if (result != null) {
        return result;
    }
    final BattleTracker battleTracker = AbstractMoveDelegate.getBattleTracker(getData());
    for (final Triple<PlayerID, PlayerID, RelationshipType> relationshipChange : relationshipChanges) {
        final RelationshipType currentRelation = getData().getRelationshipTracker().getRelationshipType(relationshipChange.getFirst(), relationshipChange.getSecond());
        if (!currentRelation.equals(relationshipChange.getThird())) {
            logEvent("Editing Political Relationship for " + relationshipChange.getFirst().getName() + " and " + relationshipChange.getSecond().getName() + " from " + currentRelation.getName() + " to " + relationshipChange.getThird().getName(), null);
            bridge.addChange(ChangeFactory.relationshipChange(relationshipChange.getFirst(), relationshipChange.getSecond(), currentRelation, relationshipChange.getThird()));
            battleTracker.addRelationshipChangesThisTurn(relationshipChange.getFirst(), relationshipChange.getSecond(), currentRelation, relationshipChange.getThird());
        }
    }
    return null;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) RelationshipType(games.strategy.engine.data.RelationshipType)

Example 38 with PlayerID

use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.

the class EditValidator method validateChangeHitDamage.

static String validateChangeHitDamage(final GameData data, final IntegerMap<Unit> unitDamageMap, final Territory territory) {
    if (unitDamageMap == null || unitDamageMap.isEmpty()) {
        return "Damage map is empty";
    }
    final String result = validateTerritoryBasic(data, territory);
    if (result != null) {
        return result;
    }
    final Collection<Unit> units = new ArrayList<>(unitDamageMap.keySet());
    if (!territory.getUnits().getUnits().containsAll(units)) {
        return "Selected Territory does not contain all of the selected units";
    }
    final PlayerID player = units.iterator().next().getOwner();
    // all units should be same owner
    if (units.isEmpty() || !units.stream().allMatch(Matches.unitIsOwnedBy(player))) {
        return "Not all units have the same owner";
    }
    if (units.isEmpty() || !units.stream().allMatch(Matches.unitHasMoreThanOneHitPointTotal())) {
        return "Not all units have more than one total hitpoints";
    }
    for (final Unit u : units) {
        final int dmg = unitDamageMap.getInt(u);
        if (dmg < 0 || dmg >= UnitAttachment.get(u.getType()).getHitPoints()) {
            return "Damage cannot be less than zero or equal to or greater than unit hitpoints (if you want to kill the " + "unit, use remove unit)";
        }
    }
    return null;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 39 with PlayerID

use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.

the class EndRoundDelegate method checkVictoryCities.

private void checkVictoryCities(final IDelegateBridge bridge, final String victoryMessage, final String victoryType) {
    final GameData data = bridge.getData();
    final Collection<Territory> territories = data.getMap().getTerritories();
    for (final String allianceName : data.getAllianceTracker().getAlliances()) {
        final int vcAmount = getVcAmount(data, allianceName, victoryType);
        final Set<PlayerID> teamMembers = data.getAllianceTracker().getPlayersInAlliance(allianceName);
        int teamVCs = 0;
        for (final Territory t : territories) {
            if (Matches.isTerritoryOwnedBy(teamMembers).test(t)) {
                final TerritoryAttachment ta = TerritoryAttachment.get(t);
                if (ta != null) {
                    teamVCs += ta.getVictoryCity();
                }
            }
        }
        if (teamVCs >= vcAmount) {
            bridge.getHistoryWriter().startEvent(allianceName + victoryMessage + vcAmount + " Victory Cities!");
            final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance(allianceName);
            // Added this to end the game on victory conditions
            signalGameOver(allianceName + victoryMessage + vcAmount + " Victory Cities!", winners, bridge);
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment)

Example 40 with PlayerID

use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.

the class ServerGame method waitForPlayerToFinishStep.

private void waitForPlayerToFinishStep() {
    final PlayerID playerId = getCurrentStep().getPlayerId();
    // no player specified for the given step
    if (playerId == null) {
        return;
    }
    if (!getCurrentStep().getDelegate().delegateCurrentlyRequiresUserInput()) {
        return;
    }
    final IGamePlayer player = gamePlayers.get(playerId);
    if (player != null) {
        // a local player
        player.start(getCurrentStep().getName());
    } else {
        // a remote player
        final INode destination = playerManager.getNode(playerId.getName());
        final IGameStepAdvancer advancer = (IGameStepAdvancer) remoteMessenger.getRemote(ClientGame.getRemoteStepAdvancerName(destination));
        advancer.startPlayerStep(getCurrentStep().getName(), playerId);
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) PlayerID(games.strategy.engine.data.PlayerID) INode(games.strategy.net.INode)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)323 Territory (games.strategy.engine.data.Territory)163 Unit (games.strategy.engine.data.Unit)133 Test (org.junit.jupiter.api.Test)122 TripleAUnit (games.strategy.triplea.TripleAUnit)104 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)94 GameData (games.strategy.engine.data.GameData)90 ArrayList (java.util.ArrayList)79 UnitType (games.strategy.engine.data.UnitType)74 Route (games.strategy.engine.data.Route)67 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)46 HashSet (java.util.HashSet)44 Change (games.strategy.engine.data.Change)29 CompositeChange (games.strategy.engine.data.CompositeChange)29 IntegerMap (games.strategy.util.IntegerMap)29 List (java.util.List)29 HashMap (java.util.HashMap)28 Collection (java.util.Collection)27 Resource (games.strategy.engine.data.Resource)25 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)23