Search in sources :

Example 81 with GameData

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

Example 82 with GameData

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) CompositeChange(games.strategy.engine.data.CompositeChange) Change(games.strategy.engine.data.Change) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) MoveValidationResult(games.strategy.triplea.delegate.dataObjects.MoveValidationResult) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 83 with GameData

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

Example 84 with GameData

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;
}
Also used : GameData(games.strategy.engine.data.GameData) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 85 with GameData

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++;
        }
    }
}
Also used : BidPlaceDelegate(games.strategy.triplea.delegate.BidPlaceDelegate) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) GameStep(games.strategy.engine.data.GameStep) File(java.io.File) Writer(java.io.Writer)

Aggregations

GameData (games.strategy.engine.data.GameData)204 Unit (games.strategy.engine.data.Unit)100 PlayerID (games.strategy.engine.data.PlayerID)92 Territory (games.strategy.engine.data.Territory)92 ArrayList (java.util.ArrayList)83 TripleAUnit (games.strategy.triplea.TripleAUnit)64 HashSet (java.util.HashSet)50 CompositeChange (games.strategy.engine.data.CompositeChange)40 List (java.util.List)36 HashMap (java.util.HashMap)32 Set (java.util.Set)32 Route (games.strategy.engine.data.Route)31 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)30 Collection (java.util.Collection)29 UnitType (games.strategy.engine.data.UnitType)26 Change (games.strategy.engine.data.Change)24 Test (org.junit.jupiter.api.Test)23 Resource (games.strategy.engine.data.Resource)22 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)22 Map (java.util.Map)21