Search in sources :

Example 1 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class ChangeResourceChange method perform.

@Override
protected void perform(final GameData data) {
    final Resource resource = data.getResourceList().getResource(m_resource);
    final ResourceCollection resources = data.getPlayerList().getPlayerId(m_player).getResources();
    if (m_quantity > 0) {
        resources.addResource(resource, m_quantity);
    } else if (m_quantity < 0) {
        resources.removeResource(resource, -m_quantity);
    }
}
Also used : Resource(games.strategy.engine.data.Resource) ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 2 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class BattleDelegate method doKamikazeSuicideAttacks.

/**
 * KamikazeSuicideAttacks are attacks that are made during an Opponent's turn, using Resources that you own that have
 * been designated.
 * The resources are designated in PlayerAttachment, and hold information like the attack power of the resource.
 * KamikazeSuicideAttacks are done in any territory that is a kamikazeZone, and the attacks are done by the original
 * owner of that
 * territory.
 * The user has the option not to do any attacks, and they make target any number of units with any number of resource
 * tokens.
 * The units are then attacked individually by each resource token (meaning that casualties do not get selected
 * because the attacks are
 * targeted).
 * The enemies of current player should decide all their attacks before the attacks are rolled.
 */
private void doKamikazeSuicideAttacks() {
    final GameData data = getData();
    if (!Properties.getUseKamikazeSuicideAttacks(data)) {
        return;
    }
    // the current player is not the one who is doing these attacks, it is the all the enemies of this player who will
    // do attacks
    final Collection<PlayerID> enemies = CollectionUtils.getMatches(data.getPlayerList().getPlayers(), Matches.isAtWar(player, data));
    if (enemies.isEmpty()) {
        return;
    }
    final Predicate<Unit> canBeAttackedDefault = Matches.unitIsOwnedBy(player).and(Matches.unitIsSea()).and(Matches.unitIsNotTransportButCouldBeCombatTransport()).and(Matches.unitIsNotSub());
    final boolean onlyWhereThereAreBattlesOrAmphibious = Properties.getKamikazeSuicideAttacksOnlyWhereBattlesAre(data);
    final Collection<Territory> pendingBattles = battleTracker.getPendingBattleSites(false);
    // create a list of all kamikaze zones, listed by enemy
    final Map<PlayerID, Collection<Territory>> kamikazeZonesByEnemy = new HashMap<>();
    for (final Territory t : data.getMap().getTerritories()) {
        final TerritoryAttachment ta = TerritoryAttachment.get(t);
        if (ta == null || !ta.getKamikazeZone()) {
            continue;
        }
        final PlayerID owner = !Properties.getKamikazeSuicideAttacksDoneByCurrentTerritoryOwner(data) ? ta.getOriginalOwner() : t.getOwner();
        if (owner == null) {
            continue;
        }
        if (enemies.contains(owner)) {
            if (t.getUnits().getUnits().stream().noneMatch(Matches.unitIsOwnedBy(player))) {
                continue;
            }
            if (onlyWhereThereAreBattlesOrAmphibious) {
                // if no battle or amphibious from here, ignore it
                if (!pendingBattles.contains(t)) {
                    if (!Matches.territoryIsWater().test(t)) {
                        continue;
                    }
                    boolean amphib = false;
                    final Collection<Territory> landNeighbors = data.getMap().getNeighbors(t, Matches.territoryIsLand());
                    for (final Territory neighbor : landNeighbors) {
                        final IBattle battle = battleTracker.getPendingBattle(neighbor, false, BattleType.NORMAL);
                        if (battle == null) {
                            final Map<Territory, Collection<Unit>> whereFrom = battleTracker.getFinishedBattlesUnitAttackFromMap().get(neighbor);
                            if (whereFrom != null && whereFrom.containsKey(t)) {
                                amphib = true;
                                break;
                            }
                            continue;
                        }
                        if (battle.isAmphibious() && ((battle instanceof MustFightBattle && ((MustFightBattle) battle).getAmphibiousAttackTerritories().contains(t)) || (battle instanceof NonFightingBattle && ((NonFightingBattle) battle).getAmphibiousAttackTerritories().contains(t)))) {
                            amphib = true;
                            break;
                        }
                    }
                    if (!amphib) {
                        continue;
                    }
                }
            }
            final Collection<Territory> currentTerrs = kamikazeZonesByEnemy.getOrDefault(owner, new ArrayList<>());
            currentTerrs.add(t);
            kamikazeZonesByEnemy.put(owner, currentTerrs);
        }
    }
    if (kamikazeZonesByEnemy.isEmpty()) {
        return;
    }
    for (final Entry<PlayerID, Collection<Territory>> entry : kamikazeZonesByEnemy.entrySet()) {
        final PlayerID currentEnemy = entry.getKey();
        final PlayerAttachment pa = PlayerAttachment.get(currentEnemy);
        if (pa == null) {
            continue;
        }
        Predicate<Unit> canBeAttacked = canBeAttackedDefault;
        final Set<UnitType> suicideAttackTargets = pa.getSuicideAttackTargets();
        if (suicideAttackTargets != null) {
            canBeAttacked = Matches.unitIsOwnedBy(player).and(Matches.unitIsOfTypes(suicideAttackTargets));
        }
        // See if the player has any attack tokens
        final IntegerMap<Resource> resourcesAndAttackValues = pa.getSuicideAttackResources();
        if (resourcesAndAttackValues.size() <= 0) {
            continue;
        }
        final IntegerMap<Resource> playerResourceCollection = currentEnemy.getResources().getResourcesCopy();
        final IntegerMap<Resource> attackTokens = new IntegerMap<>();
        for (final Resource possible : resourcesAndAttackValues.keySet()) {
            final int amount = playerResourceCollection.getInt(possible);
            if (amount > 0) {
                attackTokens.put(possible, amount);
            }
        }
        if (attackTokens.size() <= 0) {
            continue;
        }
        // now let the enemy decide if they will do attacks
        final Collection<Territory> kamikazeZones = entry.getValue();
        final HashMap<Territory, Collection<Unit>> possibleUnitsToAttack = new HashMap<>();
        for (final Territory t : kamikazeZones) {
            final List<Unit> validTargets = t.getUnits().getMatches(canBeAttacked);
            if (!validTargets.isEmpty()) {
                possibleUnitsToAttack.put(t, validTargets);
            }
        }
        final Map<Territory, HashMap<Unit, IntegerMap<Resource>>> attacks = getRemotePlayer(currentEnemy).selectKamikazeSuicideAttacks(possibleUnitsToAttack);
        if (attacks == null || attacks.isEmpty()) {
            continue;
        }
        // now validate that we have the resources and those units are valid targets
        for (final Entry<Territory, HashMap<Unit, IntegerMap<Resource>>> territoryEntry : attacks.entrySet()) {
            final Territory t = territoryEntry.getKey();
            final Collection<Unit> possibleUnits = possibleUnitsToAttack.get(t);
            if (possibleUnits == null || !possibleUnits.containsAll(territoryEntry.getValue().keySet())) {
                throw new IllegalStateException("Player has chosen illegal units during Kamikaze Suicide Attacks");
            }
            for (final IntegerMap<Resource> resourceMap : territoryEntry.getValue().values()) {
                attackTokens.subtract(resourceMap);
            }
        }
        if (!attackTokens.isPositive()) {
            throw new IllegalStateException("Player has chosen illegal resource during Kamikaze Suicide Attacks");
        }
        for (final Entry<Territory, HashMap<Unit, IntegerMap<Resource>>> territoryEntry : attacks.entrySet()) {
            final Territory location = territoryEntry.getKey();
            for (final Entry<Unit, IntegerMap<Resource>> unitEntry : territoryEntry.getValue().entrySet()) {
                final Unit unitUnderFire = unitEntry.getKey();
                final IntegerMap<Resource> numberOfAttacks = unitEntry.getValue();
                if (numberOfAttacks != null && numberOfAttacks.size() > 0 && numberOfAttacks.totalValues() > 0) {
                    fireKamikazeSuicideAttacks(unitUnderFire, numberOfAttacks, resourcesAndAttackValues, currentEnemy, location);
                }
            }
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) HashMap(java.util.HashMap) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) PlayerAttachment(games.strategy.triplea.attachments.PlayerAttachment) UnitType(games.strategy.engine.data.UnitType) IntegerMap(games.strategy.util.IntegerMap) Territory(games.strategy.engine.data.Territory) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) Resource(games.strategy.engine.data.Resource) Collection(java.util.Collection) ResourceCollection(games.strategy.engine.data.ResourceCollection)

Example 3 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class UnitAttachment method setCreatesResourcesList.

private void setCreatesResourcesList(final String value) throws GameParseException {
    final String[] s = value.split(":");
    if (s.length <= 0 || s.length > 2) {
        throw new GameParseException("createsResourcesList cannot be empty or have more than two fields" + thisErrorMsg());
    }
    final String resourceToProduce = s[1];
    // validate that this resource exists in the xml
    final Resource r = getData().getResourceList().getResource(resourceToProduce);
    if (r == null) {
        throw new GameParseException("createsResourcesList: No resource called:" + resourceToProduce + thisErrorMsg());
    }
    final int n = getInt(s[0]);
    m_createsResourcesList.put(r, n);
}
Also used : Resource(games.strategy.engine.data.Resource) GameParseException(games.strategy.engine.data.GameParseException)

Example 4 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class UnitAttachment method toStringShortAndOnlyImportantDifferences.

/**
 * Displays all unit options in a short description form that's user friendly rather than as XML.
 * Shows all except for: m_constructionType, m_constructionsPerTerrPerTypePerTurn, m_maxConstructionsPerTypePerTerr,
 * m_canBeGivenByTerritoryTo, m_destroyedWhenCapturedBy, m_canBeCapturedOnEnteringBy.
 */
public String toStringShortAndOnlyImportantDifferences(final PlayerID player, final boolean useHtml, final boolean includeAttachedToName) {
    final StringBuilder stats = new StringBuilder();
    final UnitType unitType = (UnitType) this.getAttachedTo();
    if (includeAttachedToName && unitType != null) {
        stats.append(unitType.getName()).append(":  ");
    }
    if (getIsAir()) {
        stats.append("Air unit, ");
    } else if (getIsSea()) {
        stats.append("Sea unit, ");
    } else {
        stats.append("Land unit, ");
    }
    final int attackRolls = getAttackRolls(player);
    final int defenseRolls = getDefenseRolls(player);
    if (getAttack(player) > 0) {
        stats.append(attackRolls > 1 ? (attackRolls + "x ") : "").append(getAttack(player)).append(" Attack, ");
    }
    if (getDefense(player) > 0) {
        stats.append(defenseRolls > 1 ? (defenseRolls + "x ") : "").append(getDefense(player)).append(" Defense, ");
    }
    if (getMovement(player) > 0) {
        stats.append(getMovement(player)).append(" Movement, ");
    }
    if (getHitPoints() > 1) {
        stats.append(getHitPoints()).append(" Hitpoints, ");
    }
    if (getCanProduceUnits() && getCanProduceXUnits() < 0) {
        stats.append("can Produce Units Up To Territory Value, ");
    } else if (getCanProduceUnits() && getCanProduceXUnits() > 0) {
        stats.append("can Produce ").append(getCanProduceXUnits()).append(" Units, ");
    }
    if (getCreatesUnitsList() != null && getCreatesUnitsList().size() > 0) {
        if (getCreatesUnitsList().size() > 4) {
            stats.append("Produces ").append(getCreatesUnitsList().totalValues()).append(" Units Each Turn, ");
        } else {
            stats.append("Produces ");
            for (final Entry<UnitType, Integer> entry : getCreatesUnitsList().entrySet()) {
                stats.append(entry.getValue()).append("x").append(entry.getKey().getName()).append(" ");
            }
            stats.append("Each Turn, ");
        }
    }
    if (getCreatesResourcesList() != null && getCreatesResourcesList().size() > 0) {
        if (getCreatesResourcesList().size() > 4) {
            stats.append("Produces ").append(getCreatesResourcesList().totalValues()).append(" Resources Each Turn, ");
        } else {
            stats.append("Produces ");
            for (final Entry<Resource, Integer> entry : getCreatesResourcesList().entrySet()) {
                stats.append(entry.getValue()).append("x").append(entry.getKey().getName()).append(" ");
            }
            stats.append("Each Turn, ");
        }
    }
    if (getFuelCost() != null && getFuelCost().size() > 0) {
        if (getFuelCost().size() > 4) {
            stats.append("Uses ").append(m_fuelCost.totalValues()).append(" Resources Each movement point, ");
        } else {
            stats.append("Uses ");
            for (final Entry<Resource, Integer> entry : getFuelCost().entrySet()) {
                stats.append(entry.getValue()).append("x").append(entry.getKey().getName()).append(" ");
            }
            stats.append("Each movement point, ");
        }
    }
    if (getFuelFlatCost() != null && getFuelFlatCost().size() > 0) {
        if (getFuelFlatCost().size() > 4) {
            stats.append("Uses ").append(m_fuelFlatCost.totalValues()).append(" Resources Each turn if moved, ");
        } else {
            stats.append("Uses ");
            for (final Entry<Resource, Integer> entry : getFuelFlatCost().entrySet()) {
                stats.append(entry.getValue()).append("x").append(entry.getKey().getName()).append(" ");
            }
            stats.append("Each turn if moved, ");
        }
    }
    if ((getIsAaForCombatOnly() || getIsAaForBombingThisUnitOnly() || getIsAaForFlyOverOnly()) && (getAttackAa(player) > 0 || getOffensiveAttackAa(player) > 0)) {
        if (getOffensiveAttackAa(player) > 0) {
            stats.append(getOffensiveAttackAa(player)).append("/").append(getOffensiveAttackAaMaxDieSides() != -1 ? getOffensiveAttackAaMaxDieSides() : getData().getDiceSides()).append(" att ");
        }
        if (getAttackAa(player) > 0) {
            stats.append(getAttackAa(player)).append("/").append(getAttackAaMaxDieSides() != -1 ? getAttackAaMaxDieSides() : getData().getDiceSides()).append(" def ");
        }
        if (getIsAaForCombatOnly() && getIsAaForBombingThisUnitOnly() && getIsAaForFlyOverOnly()) {
            stats.append(getTypeAa()).append(", ");
        } else if (getIsAaForCombatOnly() && getIsAaForFlyOverOnly() && !Properties.getAaTerritoryRestricted(getData())) {
            stats.append(getTypeAa()).append(" for Combat & Move Through, ");
        } else if (getIsAaForBombingThisUnitOnly() && getIsAaForFlyOverOnly() && !Properties.getAaTerritoryRestricted(getData())) {
            stats.append(getTypeAa()).append(" for Raids & Move Through, ");
        } else if (getIsAaForCombatOnly()) {
            stats.append(getTypeAa()).append(" for Combat, ");
        } else if (getIsAaForBombingThisUnitOnly()) {
            stats.append(getTypeAa()).append(" for Raids, ");
        } else if (getIsAaForFlyOverOnly()) {
            stats.append(getTypeAa()).append(" for Move Through, ");
        }
        if (getMaxAaAttacks() > -1) {
            stats.append(getMaxAaAttacks()).append(" ").append(getTypeAa()).append(" Attacks, ");
        }
    }
    if (getIsRocket() && playerHasRockets(player)) {
        stats.append("can Rocket Attack, ");
        final int bombingBonus = getBombingBonus();
        if ((getBombingMaxDieSides() != -1 || bombingBonus != 0) && Properties.getUseBombingMaxDiceSidesAndBonus(getData())) {
            stats.append(bombingBonus != 0 ? bombingBonus + 1 : 1).append("-").append(getBombingMaxDieSides() != -1 ? getBombingMaxDieSides() + bombingBonus : getData().getDiceSides() + bombingBonus).append(" Rocket Damage, ");
        } else {
            stats.append("1-").append(getData().getDiceSides()).append(" Rocket Damage, ");
        }
    }
    // line break
    if (useHtml) {
        stats.append("<br /> &nbsp;&nbsp;&nbsp;&nbsp; ");
    }
    if (getIsInfrastructure()) {
        stats.append("can be Captured, ");
    }
    if (getIsConstruction()) {
        stats.append("can be Placed Without Factory, ");
    }
    if ((getCanBeDamaged()) && Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(getData())) {
        stats.append("can be Damaged By Raids, ");
        if (getMaxOperationalDamage() > -1) {
            stats.append(getMaxOperationalDamage()).append(" Max Operational Damage, ");
        }
        if ((getCanProduceUnits()) && getCanProduceXUnits() < 0) {
            stats.append("Total Damage up to ").append(getMaxDamage() > -1 ? getMaxDamage() : 2).append("x Territory Value, ");
        } else if (getMaxDamage() > -1) {
            stats.append(getMaxDamage()).append(" Max Total Damage, ");
        }
        if (getCanDieFromReachingMaxDamage()) {
            stats.append("will Die If Max Damage Reached, ");
        }
    } else if (getCanBeDamaged()) {
        stats.append("can be Attacked By Raids, ");
    }
    if (getIsAirBase() && Properties.getScrambleRulesInEffect(getData())) {
        stats.append("can Allow Scrambling, ");
    }
    if (getCanScramble() && Properties.getScrambleRulesInEffect(getData())) {
        stats.append("can Scramble ").append(getMaxScrambleDistance() > 0 ? getMaxScrambleDistance() : 1).append(" Distance, ");
    }
    if (getArtillery()) {
        stats.append("can Give Attack Bonus To Other Units, ");
    } else {
        final List<UnitSupportAttachment> supports = CollectionUtils.getMatches(UnitSupportAttachment.get(unitType), Matches.unitSupportAttachmentCanBeUsedByPlayer(player));
        if (supports.size() > 0) {
            if (supports.size() > 2) {
                stats.append("can Modify Power Of Other Units, ");
            } else {
                for (final UnitSupportAttachment support : supports) {
                    if (support.getUnitType() == null || support.getUnitType().isEmpty()) {
                        continue;
                    }
                    stats.append("gives ").append(support.getBonus()).append(support.getStrength() && support.getRoll() ? " Power&Rolls" : (support.getStrength() ? " Power" : " Rolls")).append(" to ").append(support.getNumber()).append(support.getAllied() && support.getEnemy() ? " Allied&Enemy " : (support.getAllied() ? " Allied " : " Enemy ")).append(support.getUnitType().size() > 4 ? "Units" : MyFormatter.defaultNamedToTextList(support.getUnitType(), "/", false)).append(" when ").append(support.getOffence() && support.getDefence() ? "Att/Def" : (support.getOffence() ? "Attacking" : "Defending")).append(", ");
                }
            }
        }
    }
    if (getArtillerySupportable()) {
        stats.append("can Receive Attack Bonus From Other Units, ");
    }
    if (getIsMarine() != 0) {
        stats.append(getIsMarine()).append(" Amphibious Attack Modifier, ");
    }
    if (getCanBlitz(player)) {
        stats.append("can Blitz, ");
    }
    if (!getReceivesAbilityWhenWith().isEmpty()) {
        if (getReceivesAbilityWhenWith().size() <= 2) {
            for (final String ability : getReceivesAbilityWhenWith()) {
                stats.append("receives ").append(ability.split(":")[0]).append(" when paired with ").append(ability.split(":")[1]).append(", ");
            }
        } else {
            stats.append("receives Abilities When Paired with Other Units, ");
        }
    }
    if (getIsStrategicBomber()) {
        stats.append("can Perform Raids, ");
        final int bombingBonus = getBombingBonus();
        if ((getBombingMaxDieSides() != -1 || bombingBonus != 0) && Properties.getUseBombingMaxDiceSidesAndBonus(getData())) {
            stats.append(bombingBonus != 0 ? bombingBonus + 1 : 1).append("-").append(getBombingMaxDieSides() != -1 ? getBombingMaxDieSides() + bombingBonus : getData().getDiceSides() + bombingBonus).append(" Raid Damage, ");
        } else {
            stats.append("1-").append(getData().getDiceSides()).append(" Raid Damage, ");
        }
    }
    final int airAttack = getAirAttack(player);
    final int airDefense = getAirDefense(player);
    if (airAttack > 0 && (getIsStrategicBomber() || getCanEscort() || getCanAirBattle())) {
        stats.append(attackRolls > 1 ? (attackRolls + "x ") : "").append(airAttack).append(" Air Attack, ");
    }
    if (airDefense > 0 && (getCanIntercept() || getCanAirBattle())) {
        stats.append(defenseRolls > 1 ? (defenseRolls + "x ") : "").append(airAttack).append(" Air Defense, ");
    }
    if (getIsSub()) {
        stats.append("is Stealth, ");
    }
    if (getIsDestroyer()) {
        stats.append("is Anti-Stealth, ");
    }
    if (getCanBombard(player) && getBombard() > 0) {
        stats.append(getBombard()).append(" Bombard, ");
    }
    if (getBlockade() > 0) {
        stats.append(getBlockade()).append(" Blockade Loss, ");
    }
    if (getIsSuicide()) {
        stats.append("Suicide/Munition Unit, ");
    }
    if (getIsSuicideOnHit()) {
        stats.append("SuicideOnHit Unit, ");
    }
    if (getIsAir() && (getIsKamikaze() || Properties.getKamikazeAirplanes(getData()))) {
        stats.append("can use All Movement To Attack Target, ");
    }
    if ((getIsInfantry() || getIsLandTransportable()) && playerHasMechInf(player)) {
        stats.append("can be Transported By Land, ");
    }
    if (getIsLandTransport() && playerHasMechInf(player)) {
        stats.append("is a Land Transport, ");
    }
    if (getIsAirTransportable() && playerHasParatroopers(player)) {
        stats.append("can be Transported By Air, ");
    }
    if (getIsAirTransport() && playerHasParatroopers(player)) {
        stats.append("is an Air Transport, ");
    }
    if (getIsCombatTransport() && getTransportCapacity() > 0) {
        stats.append("is a Combat Transport, ");
    } else if (getTransportCapacity() > 0 && getIsSea()) {
        stats.append("is a Sea Transport, ");
    }
    if (getTransportCost() > -1) {
        stats.append(getTransportCost()).append(" Transporting Cost, ");
    }
    if (getTransportCapacity() > 0 && getIsSea()) {
        stats.append(getTransportCapacity()).append(" Transporting Capacity, ");
    } else if (getTransportCapacity() > 0 && getIsAir() && playerHasParatroopers(player)) {
        stats.append(getTransportCapacity()).append(" Transporting Capacity, ");
    } else if (getTransportCapacity() > 0 && playerHasMechInf(player) && !getIsSea() && !getIsAir()) {
        stats.append(getTransportCapacity()).append(" Transporting Capacity, ");
    }
    if (getCarrierCost() > -1) {
        stats.append(getCarrierCost()).append(" Carrier Cost, ");
    }
    if (getCarrierCapacity() > 0) {
        stats.append(getCarrierCapacity()).append(" Carrier Capacity, ");
    }
    if (!getWhenCombatDamaged().isEmpty()) {
        stats.append("when hit this unit loses certain abilities, ");
    }
    // line break
    if (useHtml) {
        stats.append("<br /> &nbsp;&nbsp;&nbsp;&nbsp; ");
    }
    if (getMaxBuiltPerPlayer() > -1) {
        stats.append(getMaxBuiltPerPlayer()).append(" Max Built Allowed, ");
    }
    if (getRepairsUnits() != null && !getRepairsUnits().isEmpty() && Properties.getTwoHitPointUnitsRequireRepairFacilities(getData()) && (Properties.getBattleshipsRepairAtBeginningOfRound(getData()) || Properties.getBattleshipsRepairAtEndOfRound(getData()))) {
        if (getRepairsUnits().size() <= 4) {
            stats.append("can Repair: ").append(MyFormatter.integerDefaultNamedMapToString(getRepairsUnits(), " ", "=", false)).append(", ");
        } else {
            stats.append("can Repair Some Units, ");
        }
    }
    if (getGivesMovement() != null && getGivesMovement().totalValues() > 0 && Properties.getUnitsMayGiveBonusMovement(getData())) {
        if (getGivesMovement().size() <= 4) {
            stats.append("can Modify Unit Movement: ").append(MyFormatter.integerDefaultNamedMapToString(getGivesMovement(), " ", "=", false)).append(", ");
        } else {
            stats.append("can Modify Unit Movement, ");
        }
    }
    if (getConsumesUnits() != null && getConsumesUnits().totalValues() == 1) {
        stats.append("unit is an Upgrade Of ").append(getConsumesUnits().keySet().iterator().next().getName()).append(", ");
    } else if (getConsumesUnits() != null && getConsumesUnits().totalValues() > 0) {
        if (getConsumesUnits().size() <= 4) {
            stats.append("unit Consumes On Placement: ").append(MyFormatter.integerDefaultNamedMapToString(getConsumesUnits(), " ", "x", true)).append(", ");
        } else {
            stats.append("unit Consumes Other Units On Placement, ");
        }
    }
    if (getRequiresUnits() != null && getRequiresUnits().size() > 0 && Properties.getUnitPlacementRestrictions(getData())) {
        final List<String> totalUnitsListed = new ArrayList<>();
        for (final String[] list : getRequiresUnits()) {
            totalUnitsListed.addAll(Arrays.asList(list));
        }
        if (totalUnitsListed.size() > 4) {
            stats.append("unit Requires Other Units Present To Be Placed, ");
        } else {
            stats.append("unit can only be Placed Where There Is: ");
            stats.append(joinRequiredUnits(getRequiresUnits()));
            stats.append(", ");
        }
    }
    if (getRequiresUnitsToMove() != null && !getRequiresUnitsToMove().isEmpty()) {
        final List<String> totalUnitsListed = new ArrayList<>();
        for (final String[] list : getRequiresUnitsToMove()) {
            totalUnitsListed.addAll(Arrays.asList(list));
        }
        if (totalUnitsListed.size() > 4) {
            stats.append("unit Requires Other Units Present To Be Moved, ");
        } else {
            stats.append("unit can only be Moved Where There Is: ");
            stats.append(joinRequiredUnits(getRequiresUnitsToMove()));
            stats.append(", ");
        }
    }
    if (getUnitPlacementRestrictions() != null && Properties.getUnitPlacementRestrictions(getData())) {
        stats.append("has Placement Restrictions, ");
    }
    if (getCanOnlyBePlacedInTerritoryValuedAtX() > 0 && Properties.getUnitPlacementRestrictions(getData())) {
        stats.append("must be Placed In Territory Valued >=").append(getCanOnlyBePlacedInTerritoryValuedAtX()).append(", ");
    }
    if (getCanNotMoveDuringCombatMove()) {
        stats.append("cannot Combat Move, ");
    }
    if (getMovementLimit() != null) {
        if (getMovementLimit().getFirst() == Integer.MAX_VALUE && (getIsAaForBombingThisUnitOnly() || getIsAaForCombatOnly()) && !(Properties.getWW2V2(getData()) || Properties.getWW2V3(getData()) || Properties.getMultipleAaPerTerritory(getData()))) {
            stats.append("max of 1 ").append(getMovementLimit().getSecond()).append(" moving per territory, ");
        } else if (getMovementLimit().getFirst() < 10000) {
            stats.append("max of ").append(getMovementLimit().getFirst()).append(" ").append(getMovementLimit().getSecond()).append(" moving per territory, ");
        }
    }
    if (getAttackingLimit() != null) {
        if (getAttackingLimit().getFirst() == Integer.MAX_VALUE && (getIsAaForBombingThisUnitOnly() || getIsAaForCombatOnly()) && !(Properties.getWW2V2(getData()) || Properties.getWW2V3(getData()) || Properties.getMultipleAaPerTerritory(getData()))) {
            stats.append("max of 1 ").append(getAttackingLimit().getSecond()).append(" attacking per territory, ");
        } else if (getAttackingLimit().getFirst() < 10000) {
            stats.append("max of ").append(getAttackingLimit().getFirst()).append(" ").append(getAttackingLimit().getSecond()).append(" attacking per territory, ");
        }
    }
    if (getPlacementLimit() != null) {
        if (getPlacementLimit().getFirst() == Integer.MAX_VALUE && (getIsAaForBombingThisUnitOnly() || getIsAaForCombatOnly()) && !(Properties.getWW2V2(getData()) || Properties.getWW2V3(getData()) || Properties.getMultipleAaPerTerritory(getData()))) {
            stats.append("max of 1 ").append(getPlacementLimit().getSecond()).append(" placed per territory, ");
        } else if (getPlacementLimit().getFirst() < 10000) {
            stats.append("max of ").append(getPlacementLimit().getFirst()).append(" ").append(getPlacementLimit().getSecond()).append(" placed per territory, ");
        }
    }
    if (stats.indexOf(", ") > -1) {
        stats.delete(stats.lastIndexOf(", "), stats.length() - 1);
    }
    return stats.toString();
}
Also used : Resource(games.strategy.engine.data.Resource) ArrayList(java.util.ArrayList) UnitType(games.strategy.engine.data.UnitType)

Example 5 with Resource

use of games.strategy.engine.data.Resource in project triplea by triplea-game.

the class PoliticsDelegate method checkEnoughMoney.

/**
 * @param paa
 *        The Political Action the player should be charged for.
 * @return false if the player can't afford the action
 */
private boolean checkEnoughMoney(final PoliticalActionAttachment paa) {
    final Resource pus = getData().getResourceList().getResource(Constants.PUS);
    final int cost = paa.getCostPu();
    final int has = bridge.getPlayerId().getResources().getQuantity(pus);
    return has >= cost;
}
Also used : Resource(games.strategy.engine.data.Resource)

Aggregations

Resource (games.strategy.engine.data.Resource)71 PlayerID (games.strategy.engine.data.PlayerID)22 IntegerMap (games.strategy.util.IntegerMap)16 GameData (games.strategy.engine.data.GameData)15 Unit (games.strategy.engine.data.Unit)15 ArrayList (java.util.ArrayList)15 Territory (games.strategy.engine.data.Territory)14 UnitType (games.strategy.engine.data.UnitType)13 Change (games.strategy.engine.data.Change)11 CompositeChange (games.strategy.engine.data.CompositeChange)11 ProductionRule (games.strategy.engine.data.ProductionRule)10 TripleAUnit (games.strategy.triplea.TripleAUnit)10 NamedAttachable (games.strategy.engine.data.NamedAttachable)9 ResourceCollection (games.strategy.engine.data.ResourceCollection)8 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)7 GameParseException (games.strategy.engine.data.GameParseException)6 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Test (org.junit.jupiter.api.Test)5