Search in sources :

Example 1 with IAbstractPlaceDelegate

use of games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate in project triplea by triplea-game.

the class PlacePanel method getUnitsToPlace.

private Collection<Unit> getUnitsToPlace(final Territory territory, final int[] maxUnits) {
    getData().acquireReadLock();
    try {
        // not our territory
        if (!territory.isWater() && !territory.getOwner().equals(getCurrentPlayer())) {
            if (GameStepPropertiesHelper.isBid(getData())) {
                final PlayerAttachment pa = PlayerAttachment.get(territory.getOwner());
                if ((pa == null || pa.getGiveUnitControl() == null || !pa.getGiveUnitControl().contains(getCurrentPlayer())) && !territory.getUnits().anyMatch(Matches.unitIsOwnedBy(getCurrentPlayer()))) {
                    return Collections.emptyList();
                }
            } else {
                return Collections.emptyList();
            }
        }
        // get the units that can be placed on this territory.
        Collection<Unit> units = getCurrentPlayer().getUnits().getUnits();
        if (territory.isWater()) {
            if (!(canProduceFightersOnCarriers() || canProduceNewFightersOnOldCarriers() || isLhtrCarrierProductionRules() || GameStepPropertiesHelper.isBid(getData()))) {
                units = CollectionUtils.getMatches(units, Matches.unitIsSea());
            } else {
                final Predicate<Unit> unitIsSeaOrCanLandOnCarrier = Matches.unitIsSea().or(Matches.unitCanLandOnCarrier());
                units = CollectionUtils.getMatches(units, unitIsSeaOrCanLandOnCarrier);
            }
        } else {
            units = CollectionUtils.getMatches(units, Matches.unitIsNotSea());
        }
        if (units.isEmpty()) {
            return Collections.emptyList();
        }
        final IAbstractPlaceDelegate placeDel = (IAbstractPlaceDelegate) getPlayerBridge().getRemoteDelegate();
        final PlaceableUnits production = placeDel.getPlaceableUnits(units, territory);
        if (production.isError()) {
            JOptionPane.showMessageDialog(getTopLevelAncestor(), production.getErrorMessage(), "No units", JOptionPane.INFORMATION_MESSAGE);
            return Collections.emptyList();
        }
        maxUnits[0] = production.getMaxUnits();
        return production.getUnits();
    } finally {
        getData().releaseReadLock();
    }
}
Also used : PlayerAttachment(games.strategy.triplea.attachments.PlayerAttachment) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Unit(games.strategy.engine.data.Unit)

Example 2 with IAbstractPlaceDelegate

use of games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate in project triplea by triplea-game.

the class TripleAPlayer method place.

private void place() {
    final boolean bid = GameStepPropertiesHelper.isBid(getGameData());
    if (getPlayerBridge().isGameOver()) {
        return;
    }
    final PlayerID id = getPlayerId();
    final IAbstractPlaceDelegate placeDel;
    try {
        placeDel = (IAbstractPlaceDelegate) getPlayerBridge().getRemoteDelegate();
    } catch (final ClassCastException e) {
        final String errorContext = "PlayerBridge step name: " + getPlayerBridge().getStepName() + ", Remote class name: " + getPlayerBridge().getRemoteDelegate().getClass();
        // for some reason the client is not seeing or getting these errors, so print to err too
        System.err.println(errorContext);
        ClientLogger.logQuietly(errorContext, e);
        throw new IllegalStateException(errorContext, e);
    }
    while (true) {
        if (!soundPlayedAlreadyPlacement) {
            ClipPlayer.play(SoundPath.CLIP_PHASE_PLACEMENT, id);
            soundPlayedAlreadyPlacement = true;
        }
        final PlaceData placeData = ui.waitForPlace(id, bid, getPlayerBridge());
        if (placeData == null) {
            // this only happens in lhtr rules
            if (!GameStepPropertiesHelper.isRemoveAirThatCanNotLand(getGameData()) || canAirLand(false, id) || getPlayerBridge().isGameOver()) {
                return;
            }
            continue;
        }
        final String error = placeDel.placeUnits(placeData.getUnits(), placeData.getAt(), bid ? IAbstractPlaceDelegate.BidMode.BID : IAbstractPlaceDelegate.BidMode.NOT_BID);
        if (error != null) {
            ui.notifyError(error);
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) PlaceData(games.strategy.triplea.ui.PlaceData)

Example 3 with IAbstractPlaceDelegate

use of games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate in project triplea by triplea-game.

the class AbstractAi method start.

@Override
public final void start(final String name) {
    super.start(name);
    final PlayerID id = getPlayerId();
    if (name.endsWith("Bid")) {
        final IPurchaseDelegate purchaseDelegate = (IPurchaseDelegate) getPlayerBridge().getRemoteDelegate();
        final String propertyName = id.getName() + " bid";
        final int bidAmount = getGameData().getProperties().get(propertyName, 0);
        purchase(true, bidAmount, purchaseDelegate, getGameData(), id);
    } else if (name.endsWith("Purchase")) {
        final IPurchaseDelegate purchaseDelegate = (IPurchaseDelegate) getPlayerBridge().getRemoteDelegate();
        final Resource pus = getGameData().getResourceList().getResource(Constants.PUS);
        final int leftToSpend = id.getResources().getQuantity(pus);
        purchase(false, leftToSpend, purchaseDelegate, getGameData(), id);
    } else if (name.endsWith("Tech")) {
        final ITechDelegate techDelegate = (ITechDelegate) getPlayerBridge().getRemoteDelegate();
        tech(techDelegate, getGameData(), id);
    } else if (name.endsWith("Move")) {
        final IMoveDelegate moveDel = (IMoveDelegate) getPlayerBridge().getRemoteDelegate();
        if (name.endsWith("AirborneCombatMove")) {
        // do nothing
        } else {
            move(name.endsWith("NonCombatMove"), moveDel, getGameData(), id);
        }
    } else if (name.endsWith("Battle")) {
        battle((IBattleDelegate) getPlayerBridge().getRemoteDelegate(), getGameData(), id);
    } else if (name.endsWith("Politics")) {
        politicalActions();
    } else if (name.endsWith("Place")) {
        final IAbstractPlaceDelegate placeDel = (IAbstractPlaceDelegate) getPlayerBridge().getRemoteDelegate();
        place(name.contains("Bid"), placeDel, getGameData(), id);
    } else if (name.endsWith("EndTurn")) {
        endTurn((IAbstractForumPosterDelegate) getPlayerBridge().getRemoteDelegate(), getGameData(), id);
    }
}
Also used : IMoveDelegate(games.strategy.triplea.delegate.remote.IMoveDelegate) PlayerID(games.strategy.engine.data.PlayerID) ITechDelegate(games.strategy.triplea.delegate.remote.ITechDelegate) IPurchaseDelegate(games.strategy.triplea.delegate.remote.IPurchaseDelegate) IAbstractForumPosterDelegate(games.strategy.triplea.delegate.remote.IAbstractForumPosterDelegate) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Resource(games.strategy.engine.data.Resource)

Aggregations

IAbstractPlaceDelegate (games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate)3 PlayerID (games.strategy.engine.data.PlayerID)2 Resource (games.strategy.engine.data.Resource)1 Unit (games.strategy.engine.data.Unit)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 PlaceableUnits (games.strategy.triplea.delegate.dataObjects.PlaceableUnits)1 IAbstractForumPosterDelegate (games.strategy.triplea.delegate.remote.IAbstractForumPosterDelegate)1 IMoveDelegate (games.strategy.triplea.delegate.remote.IMoveDelegate)1 IPurchaseDelegate (games.strategy.triplea.delegate.remote.IPurchaseDelegate)1 ITechDelegate (games.strategy.triplea.delegate.remote.ITechDelegate)1 PlaceData (games.strategy.triplea.ui.PlaceData)1