Search in sources :

Example 31 with TerritoryAttachment

use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.

the class TripleAFrame method getArrowKeyListener.

private KeyListener getArrowKeyListener() {
    return new KeyListener() {

        @Override
        public void keyPressed(final KeyEvent e) {
            isCtrlPressed = e.isControlDown();
            // scroll map according to wasd/arrowkeys
            final int diffPixel = computeScrollSpeed();
            final int x = mapPanel.getXOffset();
            final int y = mapPanel.getYOffset();
            final int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_RIGHT) {
                getMapPanel().setTopLeft(x + diffPixel, y);
            } else if (keyCode == KeyEvent.VK_LEFT) {
                getMapPanel().setTopLeft(x - diffPixel, y);
            } else if (keyCode == KeyEvent.VK_DOWN) {
                getMapPanel().setTopLeft(x, y + diffPixel);
            } else if (keyCode == KeyEvent.VK_UP) {
                getMapPanel().setTopLeft(x, y - diffPixel);
            }
            // I for info
            if (keyCode == KeyEvent.VK_I || keyCode == KeyEvent.VK_V) {
                String unitInfo = "";
                if (unitsBeingMousedOver != null && !unitsBeingMousedOver.isEmpty()) {
                    final Unit unit = unitsBeingMousedOver.get(0);
                    final UnitAttachment ua = UnitAttachment.get(unit.getType());
                    if (ua != null) {
                        unitInfo = "<b>Unit:</b><br>" + unit.getType().getName() + ": " + ua.toStringShortAndOnlyImportantDifferences(unit.getOwner(), true, false);
                    }
                }
                String terrInfo = "";
                if (territoryLastEntered != null) {
                    final TerritoryAttachment ta = TerritoryAttachment.get(territoryLastEntered);
                    if (ta != null) {
                        terrInfo = "<b>Territory:</b><br>" + ta.toStringForInfo(true, true) + "<br>";
                    } else {
                        terrInfo = "<b>Territory:</b><br>" + territoryLastEntered.getName() + "<br>Water Territory";
                    }
                }
                String tipText = unitInfo;
                if (unitInfo.length() > 0 && terrInfo.length() > 0) {
                    tipText = tipText + "<br><br><br><br><br>";
                }
                tipText = tipText + terrInfo;
                if (tipText.length() > 0) {
                    final Point currentPoint = MouseInfo.getPointerInfo().getLocation();
                    final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                    final JToolTip info = new JToolTip();
                    info.setTipText("<html>" + tipText + "</html>");
                    final Popup popup = popupFactory.getPopup(mapPanel, info, currentPoint.x, currentPoint.y);
                    popup.show();
                    new Thread(() -> {
                        Interruptibles.sleep(5000);
                        popup.hide();
                    }, "popup waiter").start();
                }
            }
        }

        @Override
        public void keyTyped(final KeyEvent e) {
        }

        @Override
        public void keyReleased(final KeyEvent e) {
            isCtrlPressed = e.isControlDown();
        }
    };
}
Also used : KeyEvent(java.awt.event.KeyEvent) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) PopupFactory(javax.swing.PopupFactory) JToolTip(javax.swing.JToolTip) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) Popup(javax.swing.Popup) KeyListener(java.awt.event.KeyListener) Point(java.awt.Point) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Point(java.awt.Point)

Example 32 with TerritoryAttachment

use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.

the class HistoryLog method printTerritorySummary.

private void printTerritorySummary(final Collection<PlayerID> players, final Collection<Territory> territories) {
    if (players == null || players.isEmpty() || territories == null || territories.isEmpty()) {
        return;
    }
    final PrintWriter logWriter = printWriter;
    // print all units in all territories, including "flags"
    logWriter.println("Territory Summary for " + MyFormatter.defaultNamedToTextList(players) + " : \n");
    for (final Territory t : territories) {
        final List<Unit> ownedUnits = t.getUnits().getMatches(Matches.unitIsOwnedByOfAnyOfThesePlayers(players));
        // see if there's a flag
        final TerritoryAttachment ta = TerritoryAttachment.get(t);
        final boolean hasFlag = ta != null && t.getOwner() != null && players.contains(t.getOwner()) && (ta.getOriginalOwner() == null || !players.contains(ta.getOriginalOwner()));
        if (hasFlag || !ownedUnits.isEmpty()) {
            logWriter.print("    " + t.getName() + " : ");
            if (hasFlag && ownedUnits.isEmpty()) {
                logWriter.println("1 flag");
            } else if (hasFlag) {
                logWriter.print("1 flag, ");
            }
            if (!ownedUnits.isEmpty()) {
                logWriter.println(MyFormatter.unitsToTextNoOwner(ownedUnits));
            }
        }
    }
    logWriter.println();
    logWriter.println();
    textArea.setText(stringWriter.toString());
}
Also used : Territory(games.strategy.engine.data.Territory) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) Unit(games.strategy.engine.data.Unit) PrintWriter(java.io.PrintWriter)

Example 33 with TerritoryAttachment

use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.

the class HistoryLog method getProduction.

// copied from StatPanel
private static int getProduction(final PlayerID player, final GameData data) {
    int production = 0;
    for (final Territory place : data.getMap().getTerritories()) {
        boolean isConvoyOrLand = false;
        final TerritoryAttachment ta = TerritoryAttachment.get(place);
        if (!place.isWater() || place.isWater() && ta != null && OriginalOwnerTracker.getOriginalOwner(place) != PlayerID.NULL_PLAYERID && OriginalOwnerTracker.getOriginalOwner(place) == player && place.getOwner().equals(player)) {
            isConvoyOrLand = true;
        }
        if (place.getOwner().equals(player) && isConvoyOrLand) {
            if (ta != null) {
                production += ta.getProduction();
            }
        }
    }
    return production;
}
Also used : Territory(games.strategy.engine.data.Territory) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment)

Example 34 with TerritoryAttachment

use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.

the class TileManager method drawTerritory.

private void drawTerritory(final Territory territory, final GameData data, final MapData mapData) {
    final Set<Tile> drawnOn = new HashSet<>();
    final Set<IDrawable> drawing = new HashSet<>();
    if (territoryOverlays.get(territory.getName()) != null) {
        drawing.add(territoryOverlays.get(territory.getName()));
    }
    if (uiContext.getShowTerritoryEffects()) {
        drawTerritoryEffects(territory, mapData, drawing);
    }
    if (uiContext.getShowUnits()) {
        drawUnits(territory, mapData, drawnOn, drawing, data);
    }
    drawing.add(new BattleDrawable(territory.getName()));
    final TerritoryAttachment ta = TerritoryAttachment.get(territory);
    if (!territory.isWater()) {
        drawing.add(new LandTerritoryDrawable(territory.getName()));
    } else {
        if (ta != null) {
            // Kamikaze Zones
            if (ta.getKamikazeZone()) {
                drawing.add(new KamikazeZoneDrawable(territory, uiContext));
            }
            // Blockades
            if (ta.getBlockadeZone()) {
                drawing.add(new BlockadeZoneDrawable(territory));
            }
            // Convoy Routes
            if (ta.getConvoyRoute()) {
                drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
            }
            // Convoy Centers
            if (ta.getProduction() > 0) {
                drawing.add(new ConvoyZoneDrawable(territory.getOwner(), territory, uiContext));
            }
        }
        drawing.add(new SeaZoneOutlineDrawable(territory.getName()));
    }
    final OptionalExtraBorderLevel optionalBorderLevel = uiContext.getDrawTerritoryBordersAgain();
    if (optionalBorderLevel != OptionalExtraBorderLevel.LOW) {
        drawing.add(new OptionalExtraTerritoryBordersDrawable(territory.getName(), optionalBorderLevel));
    }
    drawing.add(new TerritoryNameDrawable(territory.getName(), uiContext));
    if (ta != null && ta.isCapital() && mapData.drawCapitolMarkers()) {
        final PlayerID capitalOf = data.getPlayerList().getPlayerId(ta.getCapital());
        drawing.add(new CapitolMarkerDrawable(capitalOf, territory, uiContext));
    }
    if (ta != null && (ta.getVictoryCity() != 0)) {
        drawing.add(new VcDrawable(territory));
    }
    // add to the relevant tiles
    for (Tile tile : getTiles(mapData.getBoundingRect(territory.getName()))) {
        drawnOn.add(tile);
        tile.addDrawables(drawing);
    }
    territoryDrawables.put(territory.getName(), drawing);
    territoryTiles.put(territory.getName(), drawnOn);
}
Also used : BlockadeZoneDrawable(games.strategy.triplea.ui.screen.drawable.BlockadeZoneDrawable) PlayerID(games.strategy.engine.data.PlayerID) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) ConvoyZoneDrawable(games.strategy.triplea.ui.screen.drawable.ConvoyZoneDrawable) OptionalExtraBorderLevel(games.strategy.triplea.ui.screen.drawable.IDrawable.OptionalExtraBorderLevel) CapitolMarkerDrawable(games.strategy.triplea.ui.screen.drawable.CapitolMarkerDrawable) SeaZoneOutlineDrawable(games.strategy.triplea.ui.screen.drawable.SeaZoneOutlineDrawable) VcDrawable(games.strategy.triplea.ui.screen.drawable.VcDrawable) BattleDrawable(games.strategy.triplea.ui.screen.drawable.BattleDrawable) LandTerritoryDrawable(games.strategy.triplea.ui.screen.drawable.LandTerritoryDrawable) OptionalExtraTerritoryBordersDrawable(games.strategy.triplea.ui.screen.drawable.OptionalExtraTerritoryBordersDrawable) IDrawable(games.strategy.triplea.ui.screen.drawable.IDrawable) KamikazeZoneDrawable(games.strategy.triplea.ui.screen.drawable.KamikazeZoneDrawable) TerritoryNameDrawable(games.strategy.triplea.ui.screen.drawable.TerritoryNameDrawable) HashSet(java.util.HashSet)

Example 35 with TerritoryAttachment

use of games.strategy.triplea.attachments.TerritoryAttachment in project triplea by triplea-game.

the class KamikazeZoneDrawable method draw.

@Override
public void draw(final Rectangle bounds, final GameData data, final Graphics2D graphics, final MapData mapData, final AffineTransform unscaled, final AffineTransform scaled) {
    // Change so only original owner gets the kamikazi zone marker
    final Territory terr = data.getMap().getTerritory(location);
    final TerritoryAttachment ta = TerritoryAttachment.get(terr);
    PlayerID owner;
    if (Properties.getKamikazeSuicideAttacksDoneByCurrentTerritoryOwner(data)) {
        owner = terr.getOwner();
        if (owner == null) {
            owner = PlayerID.NULL_PLAYERID;
        }
    } else {
        if (ta == null) {
            owner = PlayerID.NULL_PLAYERID;
        } else {
            owner = ta.getOriginalOwner();
            if (owner == null) {
                owner = PlayerID.NULL_PLAYERID;
            }
        }
    }
    final Image img = uiContext.getFlagImageFactory().getFadedFlag(owner);
    final Point point = mapData.getKamikazeMarkerLocation(data.getMap().getTerritory(location));
    graphics.drawImage(img, point.x - bounds.x, point.y - bounds.y, null);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) Point(java.awt.Point) Image(java.awt.Image)

Aggregations

TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)36 Territory (games.strategy.engine.data.Territory)29 Unit (games.strategy.engine.data.Unit)24 TripleAUnit (games.strategy.triplea.TripleAUnit)19 ArrayList (java.util.ArrayList)14 PlayerID (games.strategy.engine.data.PlayerID)13 GameData (games.strategy.engine.data.GameData)9 HashSet (java.util.HashSet)8 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)7 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)6 UnitType (games.strategy.engine.data.UnitType)5 ProBattleResult (games.strategy.triplea.ai.pro.data.ProBattleResult)5 CompositeChange (games.strategy.engine.data.CompositeChange)4 Resource (games.strategy.engine.data.Resource)4 ProOtherMoveOptions (games.strategy.triplea.ai.pro.data.ProOtherMoveOptions)4 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)4 IntegerMap (games.strategy.util.IntegerMap)4 RelationshipTracker (games.strategy.engine.data.RelationshipTracker)3 ProPlaceTerritory (games.strategy.triplea.ai.pro.data.ProPlaceTerritory)3 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)3