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