Package megamek.common

Examples of megamek.common.Coords


        }
        return end;
    }

    private Coords extendRoad(Coords coords, int nextDirection, int roadStyle) {
        Coords next = selectNextGrid(nextDirection, coords);
        if (board.contains(next) && hexNeedsBridge(board.getHex(next))) {
            if (nextDirection == E || nextDirection == W) {
                nextDirection = coords.direction(next);
            }
            Coords end = tryToBuildBridge(coords, nextDirection);
            return end;
        }
        connectHexes(coords, next, roadStyle);
        connectHexes(next, coords, roadStyle);
        return next;
View Full Code Here


        connectHexes(next, coords, roadStyle);
        return next;
    }

    private Coords resumeAfterObstacle(Coords coords, int nextDirection) {
        Coords next = selectNextGrid(nextDirection, coords);
        while (board.contains(next) && !isHexBuildable(board.getHex(next))) {
            next = selectNextGrid(nextDirection, next);
        }
        return next;
    }
View Full Code Here

        }
        return next;
    }

    private void buildStraightRoad(Coords start, int direction, int roadStyle) {
        Coords coords = start;

        while (coords != null && coords.x <= board.getWidth() && coords.x >= -1
                && coords.y <= board.getHeight() && coords.y >= -1) {
            cityPlan.add(coords);
            Coords next = extendRoad(coords, direction, roadStyle);
            if (next == null) {
                coords = resumeAfterObstacle(coords, direction);
            } else
                coords = next;
        }
View Full Code Here

    /**
     * Adds an Road to the map. Goes from one border to another, and has one
     * turn in it. Map must be at least 3x3.
     */
    private void addGenericRoad() {
        Coords c = new Coords(Compute.randomInt(board.getWidth()), Compute
                .randomInt(board.getHeight()));
        int side0 = Compute.randomInt(6);
        int side1 = Compute.randomInt(5);
        if (side1 >= side0) {
            side1++;
View Full Code Here

            aaa.turnsTilHit--;
            return true;
        }
        final Vector<Integer> spottersBefore = aaa.getSpotterIds();
        final Targetable target = aaa.getTarget(game);
        final Coords targetPos = target.getPosition();
        final int playerId = aaa.getPlayerId();
        boolean isFlak = target instanceof VTOL;
        Entity bestSpotter = null;
        Entity ae = game.getEntity(aaa.getEntityId());
        if (ae == null) {
            ae = game.getOutOfGameEntity(aaa.getEntityId());
        }
        //TODO: Fix null pointer exception
        if(ae == null) {
            System.err.println("Artillery Entity is null!");
            return true;
        }
        Mounted ammo = ae.getEquipment(aaa.getAmmoId());
        final AmmoType atype = ammo == null ? null : (AmmoType) ammo.getType();
        // Are there any valid spotters?
        if ((null != spottersBefore) && !isFlak) {
            // fetch possible spotters now
            Enumeration<Entity> spottersAfter = game
                    .getSelectedEntities(new EntitySelector() {
                        public int player = playerId;

                        public Targetable targ = target;

                        public boolean accept(Entity entity) {
                            Integer id = new Integer(entity.getId());
                            if ((player == entity.getOwnerId())
                                    && spottersBefore.contains(id)
                                    && !(LosEffects.calculateLos(game, entity
                                            .getId(), targ)).isBlocked()
                                    && entity.isActive()
                                    && !entity.isINarcedWith(INarcPod.HAYWIRE)) {
                                return true;
                            }
                            return false;
                        }
                    });

            // Out of any valid spotters, pick the best.
            while (spottersAfter.hasMoreElements()) {
                Entity ent = spottersAfter.nextElement();
                if ((bestSpotter == null)
                        || (ent.crew.getGunnery() < bestSpotter.crew
                                .getGunnery())) {
                    bestSpotter = ent;
                }
            }

        } // End have-valid-spotters

        // If at least one valid spotter, then get the benefits thereof.
        if (null != bestSpotter) {
            int mod = (bestSpotter.crew.getGunnery() - 4) / 2;
            toHit.addModifier(mod, "Spotting modifier");
        }

        // Is the attacker still alive and we're not shooting FLAK?
        // then adjust the target
        Entity artyAttacker = aaa.getEntity(game);
        if ((null != artyAttacker) && !isFlak) {

            // Get the arty weapon.
            Mounted weapon = artyAttacker.getEquipment(aaa.getWeaponId());

            // If the shot hit the target hex, then all subsequent
            // fire will hit the hex automatically.
            if (roll >= toHit.getValue()) {
                artyAttacker.aTracker.setModifier(weapon,
                        TargetRoll.AUTOMATIC_SUCCESS, targetPos);

                game.getBoard().addSpecialHexDisplay(targetPos,
                        new SpecialHexDisplay(
                                SpecialHexDisplay.Type.ARTILLERY_AUTOHIT,
                                game.getRoundCount(),
                                game.getPlayer(aaa.getPlayerId()).getName(),
                                "Artilery AutoHit. Better text later.",
                                false
                        )
                 );
            }
            // If the shot missed, but was adjusted by a
            // spotter, future shots are more likely to hit.
            else if (null != bestSpotter) {
                artyAttacker.aTracker.setModifier(weapon, artyAttacker.aTracker
                        .getModifier(weapon, targetPos) - 1, targetPos);

                game.getBoard().addSpecialHexDisplay(targetPos,
                        new SpecialHexDisplay(
                            SpecialHexDisplay.Type.ARTILLERY_ADJUSTED,
                            game.getRoundCount(),
                            game.getPlayer(aaa.getPlayerId()).getName(),
                            "Artilery toHit Adjusted. Better text later.",
                            false
                        )
                );
            }

        } // End artyAttacker-alive

        // Report weapon attack and its to-hit value.
        r = new Report(3120);
        r.indent();
        r.newlines = 0;
        r.subject = subjectId;
        if (wtype != null) {
            r.add(wtype.getName());
        } else {
            r.add("Error: From Nowhwere");
        }

        r.add(target.getDisplayName(), true);
        vPhaseReport.addElement(r);
        if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
            r = new Report(3135);
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
            return false;
        } else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
            r = new Report(3140);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
        } else if (toHit.getValue() == TargetRoll.AUTOMATIC_SUCCESS) {
            r = new Report(3145);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getDesc());
            vPhaseReport.addElement(r);
        } else {
            // roll to hit
            r = new Report(3150);
            r.newlines = 0;
            r.subject = subjectId;
            r.add(toHit.getValue());
            vPhaseReport.addElement(r);
        }

        // dice have been rolled, thanks
        r = new Report(3155);
        r.newlines = 0;
        r.subject = subjectId;
        r.add(roll);
        vPhaseReport.addElement(r);

        if (!isFlak) {
            game.getBoard().addSpecialHexDisplay(
                    targetPos,
                    new SpecialHexDisplay(SpecialHexDisplay.Type.ARTILLERY_TARGET,
                            game.getRoundCount(),
                            game.getPlayer(aaa.getPlayerId()).getName(),
                            "Artilery Target. Better text later.",
                            false
                    )
            );
        }

        // do we hit?
        bMissed = roll < toHit.getValue();
        // Set Margin of Success/Failure.
        toHit.setMoS(roll-Math.max(2,toHit.getValue()));

        // Do this stuff first, because some weapon's miss report reference the
        // amount of shots fired and stuff.
        if (!handledAmmoAndReport) {
            addHeat();
        }
        Coords coords = target.getPosition();
        if (!bMissed) {
            if (!isFlak) {
                r = new Report(3190);
            } else {
                r = new Report(3191);
            }
            r.subject = subjectId;
            r.add(coords.getBoardNum());
            vPhaseReport.addElement(r);

            game.getBoard().addSpecialHexDisplay(targetPos,
                    new SpecialHexDisplay(SpecialHexDisplay.Type.ARTILLERY_HIT,
                            game.getRoundCount(),
                            "Artilery Hit. Better text later."));

        } else {
            // direct fire artillery only scatters by one d6
            // we do this here to avoid duplicating handle()
            // in the ArtilleryWeaponDirectFireHandler
            if (phase == IGame.Phase.PHASE_FIRING) {
                coords = Compute.scatterDirectArty(coords);
            } else {
                coords = Compute.scatter(coords, Math.abs(toHit.getMoS()));
            }
            if (game.getBoard().contains(coords)) {
                // misses and scatters to another hex
                if (!isFlak) {
                    r = new Report(3195);
                    game.getBoard().addSpecialHexDisplay(
                        coords,
                        new SpecialHexDisplay(
                                SpecialHexDisplay.Type.ARTILLERY_HIT,
                                game.getRoundCount(),
                                "Artilery Scatered Here. Better text later."
                        )
                    );
                } else {
                    r = new Report(3192);
                }
                r.subject = subjectId;
                r.add(coords.getBoardNum());
                vPhaseReport.addElement(r);
            } else {
                // misses and scatters off-board
                if (isFlak) {
                    r = new Report(3193);
View Full Code Here

        int drawHeight = view.height / (int) (HEX_H * scale) + 3;
        IBoard board = game.getBoard();
        // loop through the hexes
        for (int i = 0; i < drawHeight; i++) {
            for (int j = 0; j < drawWidth; j++) {
                Coords c = new Coords(j + drawX, i + drawY);
                Point p = getHexLocation(c);
                if (board.isLegalDeployment(c, m_plDeployer)) {
                    g.setColor(Color.yellow);
                    int[] xcoords = { p.x + (int) (21 * scale), p.x + (int) (62 * scale),
                            p.x + (int) (83 * scale), p.x + (int) (83 * scale),
 
View Full Code Here

        Image scaledImage;

        // loop through the hexes
        for (int i = 0; i < drawHeight; i++) {
            for (int j = 0; j < drawWidth; j++) {
                Coords c = new Coords(j + drawX, i + drawY);
                Point p = getHexLocation(c);

                if (!board.contains(c)) {
                    continue;
                }
View Full Code Here

        IBoard board = game.getBoard();
        // loop through the hexes
        for (int i = 0; i < drawHeight; i++) {
            for (int j = 0; j < drawWidth; j++) {
                Coords c = new Coords(j + drawX, i + drawY);
                Point p = getHexLocation(c);

                if (!board.contains(c)) {
                    continue;
                }
View Full Code Here

        g.clearRect(view.x, view.y, view.width, view.height);

        // draw some hexes
        for (int i = 0; i < drawHeight; i++) {
            for (int j = 0; j < drawWidth; j++) {
                drawHex(new Coords(j + drawX, i + drawY), g);
            }
        }
    }
View Full Code Here

     */
    Coords getCoordsAt(Point p) {
        final int x = (p.x ) / (int) (HEX_WC * scale);
        final int y = ((p.y ) - ((x & 1) == 1 ? (int) (HEX_H / 2 * scale) : 0))
                / (int) (HEX_H * scale);
        return new Coords(x, y);
    }
View Full Code Here

TOP

Related Classes of megamek.common.Coords

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.