use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class AirBattle method queryRetreat.
private void queryRetreat(final boolean defender, final IDelegateBridge bridge, final Collection<Territory> availableTerritories) {
if (availableTerritories.isEmpty()) {
return;
}
final Collection<Unit> units = defender ? new ArrayList<>(m_defendingUnits) : new ArrayList<>(m_attackingUnits);
if (units.isEmpty()) {
return;
}
final PlayerID retreatingPlayer = defender ? m_defender : m_attacker;
final String text = retreatingPlayer.getName() + " retreat?";
final String step = defender ? DEFENDERS_WITHDRAW : ATTACKERS_WITHDRAW;
getDisplay(bridge).gotoBattleStep(m_battleID, step);
final Territory retreatTo = getRemote(retreatingPlayer, bridge).retreatQuery(m_battleID, false, m_battleSite, availableTerritories, text);
if (retreatTo != null && !availableTerritories.contains(retreatTo)) {
System.err.println("Invalid retreat selection :" + retreatTo + " not in " + MyFormatter.defaultNamedToTextList(availableTerritories));
Thread.dumpStack();
return;
}
if (retreatTo != null) {
if (!m_headless) {
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_RETREAT_AIR, m_attacker);
}
retreat(units, defender, bridge);
final String messageShort = retreatingPlayer.getName() + " retreats";
final String messageLong = retreatingPlayer.getName() + " retreats all units to " + retreatTo.getName();
getDisplay(bridge).notifyRetreat(messageShort, messageLong, step, retreatingPlayer);
}
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class AirMovementValidator method canFindLand.
private static boolean canFindLand(final GameData data, final Unit unit, final Territory current, final int movementLeft) {
if (movementLeft <= 0) {
return false;
}
final boolean areNeutralsPassableByAir = areNeutralsPassableByAir(data);
final PlayerID player = unit.getOwner();
final List<Territory> possibleSpots = CollectionUtils.getMatches(data.getMap().getNeighbors(current, movementLeft), Matches.airCanLandOnThisAlliedNonConqueredLandTerritory(player, data));
// have a lot of movement capacity.
for (final Territory landingSpot : possibleSpots) {
if (canAirReachThisSpot(data, player, unit, current, movementLeft, landingSpot, areNeutralsPassableByAir)) {
return true;
}
}
return false;
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class TerritoryAttachment method setOriginalOwner.
private void setOriginalOwner(final String player) throws GameParseException {
if (player == null) {
m_originalOwner = null;
}
final PlayerID tempPlayer = getData().getPlayerList().getPlayerId(player);
if (tempPlayer == null) {
throw new GameParseException("No player named: " + player + thisErrorMsg());
}
m_originalOwner = tempPlayer;
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class TriggerAttachment method triggerRelationshipChange.
public static void triggerRelationshipChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
final GameData data = bridge.getData();
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, relationshipChangeMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final String relationshipChange : t.getRelationshipChange()) {
final String[] s = relationshipChange.split(":");
final PlayerID player1 = data.getPlayerList().getPlayerId(s[0]);
final PlayerID player2 = data.getPlayerList().getPlayerId(s[1]);
final RelationshipType currentRelation = data.getRelationshipTracker().getRelationshipType(player1, player2);
if (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_NEUTRAL) && Matches.relationshipTypeIsNeutral().test(currentRelation)) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_ALLIED) && Matches.relationshipTypeIsAllied().test(currentRelation)) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_WAR) && Matches.relationshipTypeIsAtWar().test(currentRelation)) || currentRelation.equals(data.getRelationshipTypeList().getRelationshipType(s[2]))) {
final RelationshipType triggerNewRelation = data.getRelationshipTypeList().getRelationshipType(s[3]);
change.add(ChangeFactory.relationshipChange(player1, player2, currentRelation, triggerNewRelation));
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Changing Relationship for " + player1.getName() + " and " + player2.getName() + " from " + currentRelation.getName() + " to " + triggerNewRelation.getName());
AbstractMoveDelegate.getBattleTracker(data).addRelationshipChangesThisTurn(player1, player2, currentRelation, triggerNewRelation);
/*
* creation of new battles is handled at the beginning of the battle delegate, in
* "setupUnitsInSameTerritoryBattles", not here.
* if (Matches.relationshipTypeIsAtWar().test(triggerNewRelation))
* triggerMustFightBattle(player1, player2, aBridge);
*/
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class TriggerAttachment method triggerProductionChange.
public static void triggerProductionChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, prodMatch());
if (testWhen) {
trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
}
if (testUses) {
trigs = CollectionUtils.getMatches(trigs, availableUses);
}
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment t : trigs) {
if (testChance && !t.testChance(bridge)) {
continue;
}
if (useUses) {
t.use(bridge);
}
for (final PlayerID player : t.getPlayers()) {
change.add(ChangeFactory.changeProductionFrontier(player, t.getFrontier()));
bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " has their production frontier changed to: " + t.getFrontier().getName());
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
Aggregations