use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class SpecialMoveDelegate method start.
@Override
public void start() {
super.start();
final GameData data = getData();
if (!allowAirborne(player, data)) {
return;
}
final boolean onlyWhereUnderAttackAlready = Properties.getAirborneAttacksOnlyInExistingBattles(data);
final BattleTracker battleTracker = AbstractMoveDelegate.getBattleTracker(data);
if (needToInitialize && onlyWhereUnderAttackAlready) {
// we do this to clear any 'finishedBattles' and also to create battles for units that didn't move
BattleDelegate.doInitialize(battleTracker, bridge);
needToInitialize = false;
}
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class SpecialMoveDelegate method move.
@Override
public String move(final Collection<Unit> units, final Route route, final Collection<Unit> transportsThatCanBeLoaded, final Map<Unit, Collection<Unit>> newDependents) {
if (!allowAirborne(player, getData())) {
return "No Airborne Movement Allowed Yet";
}
final GameData data = getData();
// there reason we use this, is because if we are in edit mode, we may have a different unit owner than the current
// player.
final PlayerID player = getUnitsOwner(units);
// here we have our own new validation method....
final MoveValidationResult result = validateMove(units, route, player, data);
final StringBuilder errorMsg = new StringBuilder(100);
final int numProblems = result.getTotalWarningCount() - (result.hasError() ? 0 : 1);
final String numErrorsMsg = numProblems > 0 ? ("; " + numProblems + " " + MyFormatter.pluralize("error", numProblems) + " not shown") : "";
if (result.hasError()) {
return errorMsg.append(result.getError()).append(numErrorsMsg).toString();
}
if (result.hasDisallowedUnits()) {
return errorMsg.append(result.getDisallowedUnitWarning(0)).append(numErrorsMsg).toString();
}
if (result.hasUnresolvedUnits()) {
return errorMsg.append(result.getUnresolvedUnitWarning(0)).append(numErrorsMsg).toString();
}
// allow user to cancel move if aa guns will fire
final AAInMoveUtil aaInMoveUtil = new AAInMoveUtil();
aaInMoveUtil.initialize(bridge);
final Collection<Territory> aaFiringTerritores = aaInMoveUtil.getTerritoriesWhereAaWillFire(route, units);
if (!aaFiringTerritores.isEmpty()) {
if (!getRemotePlayer().confirmMoveInFaceOfAa(aaFiringTerritores)) {
return null;
}
}
// do the move
final UndoableMove currentMove = new UndoableMove(units, route);
// add dependencies (any move that came before this, from this start territory, is a dependency)
for (final UndoableMove otherMove : movesToUndo) {
if (otherMove.getStart().equals(route.getStart())) {
currentMove.addDependency(otherMove);
}
}
// make the units airborne
final CompositeChange airborneChange = new CompositeChange();
for (final Unit u : units) {
airborneChange.add(ChangeFactory.unitPropertyChange(u, true, TripleAUnit.AIRBORNE));
}
currentMove.addChange(airborneChange);
// make the bases start filling up their capacity
final Collection<Unit> basesAtStart = route.getStart().getUnits().getMatches(getAirborneBaseMatch(player, data));
final Change fillLaunchCapacity = getNewAssignmentOfNumberLaunchedChange(units.size(), basesAtStart, player, data);
currentMove.addChange(fillLaunchCapacity);
// start event
final String transcriptText = MyFormatter.unitsToTextNoOwner(units) + " moved from " + route.getStart().getName() + " to " + route.getEnd().getName();
bridge.getHistoryWriter().startEvent(transcriptText, currentMove.getDescriptionObject());
// actually do our special changes
bridge.addChange(airborneChange);
bridge.addChange(fillLaunchCapacity);
tempMovePerformer = new MovePerformer();
tempMovePerformer.initialize(this);
tempMovePerformer.moveUnits(units, route, player, transportsThatCanBeLoaded, newDependents, currentMove);
tempMovePerformer = null;
return null;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class TechActivationDelegate method shareTechnology.
private void shareTechnology() {
final PlayerAttachment pa = PlayerAttachment.get(player);
if (pa == null) {
return;
}
final Collection<PlayerID> shareWith = pa.getShareTechnology();
if (shareWith == null || shareWith.isEmpty()) {
return;
}
final GameData data = getData();
final Collection<TechAdvance> currentAdvances = TechTracker.getCurrentTechAdvances(player, data);
for (final PlayerID p : shareWith) {
final Collection<TechAdvance> availableTechs = TechnologyDelegate.getAvailableTechs(p, data);
final Collection<TechAdvance> toGive = CollectionUtils.intersection(currentAdvances, availableTechs);
if (!toGive.isEmpty()) {
// Start event
bridge.getHistoryWriter().startEvent(player.getName() + " giving technology to " + p.getName() + ": " + advancesAsString(toGive));
for (final TechAdvance advance : toGive) {
TechTracker.addAdvance(p, bridge, advance);
}
}
}
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class TransportTracker method isTransportUnloadRestrictedToAnotherTerritory.
// In some versions, a transport can never unload into
// multiple territories in a given turn.
// In WW2V1 a transport can unload to multiple territories in
// non-combat phase, provided they are both adjacent to the sea zone.
static boolean isTransportUnloadRestrictedToAnotherTerritory(final Unit transport, final Territory territory) {
final Collection<Unit> unloaded = ((TripleAUnit) transport).getUnloaded();
if (unloaded.isEmpty()) {
return false;
}
// See if transport has unloaded anywhere yet
final GameData data = transport.getData();
for (final Unit u : unloaded) {
final TripleAUnit taUnit = (TripleAUnit) u;
if (isWW2V2(data) || isTransportUnloadRestricted(data)) {
// cannot unload to two different territories
if (!taUnit.getUnloadedTo().equals(territory)) {
return true;
}
} else {
// cannot unload to two different territories in combat phase
if (!GameStepPropertiesHelper.isNonCombatMove(transport.getData(), true) && !taUnit.getUnloadedTo().equals(territory)) {
return true;
}
}
}
return false;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class PlayerOrder method saveToFile.
void saveToFile(final PrintGenerationData printData) throws IOException {
final GameData gameData = printData.getData();
for (final GameStep currentStep : gameData.getSequence()) {
if (currentStep.getDelegate() != null && currentStep.getDelegate().getClass() != null) {
final String delegateClassName = currentStep.getDelegate().getClass().getName();
if (delegateClassName.equals(InitializationDelegate.class.getName()) || delegateClassName.equals(BidPurchaseDelegate.class.getName()) || delegateClassName.equals(BidPlaceDelegate.class.getName()) || delegateClassName.equals(EndRoundDelegate.class.getName())) {
continue;
}
} else if (currentStep.getName() != null && (currentStep.getName().endsWith("Bid") || currentStep.getName().endsWith("BidPlace"))) {
continue;
}
final PlayerID currentPlayerId = currentStep.getPlayerId();
if (currentPlayerId != null && !currentPlayerId.isNull()) {
playerSet.add(currentPlayerId);
}
}
printData.getOutDir().mkdir();
final File outFile = new File(printData.getOutDir(), "General Information.csv");
try (Writer turnWriter = Files.newBufferedWriter(outFile.toPath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
turnWriter.write("Turn Order\r\n");
int count = 1;
for (final PlayerID currentPlayerId : removeDups(playerSet)) {
turnWriter.write(count + ". " + currentPlayerId.getName() + "\r\n");
count++;
}
}
}
Aggregations