Package megamek.common

Examples of megamek.common.Coords


     * @see megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector,
     *      megamek.common.Entity, boolean)
     */
    protected boolean specialResolution(Vector<Report> vPhaseReport,
            Entity entityTarget, boolean bMissed) {
        Coords coords = target.getPosition();
        AmmoType atype = (AmmoType) ammo.getType();
        //only report to player if mine delivery
        int whoReport = Report.PLAYER;
        if(atype.getMunitionType() == AmmoType.M_FLARE) {
            whoReport = Report.PUBLIC;
        }   
        if (!bMissed) {
            r = new Report(3190, whoReport);
            r.subject = subjectId;
            r.add(coords.getBoardNum());
            vPhaseReport.addElement(r);
        } else {
            // according to http://www.classicbattletech.com/forums/index.php/topic,41188.0.html
            // scatterable LRMs scatter like dive bombing
            coords = Compute.scatterDiveBombs(coords);
            if (game.getBoard().contains(coords)) {
                // misses and scatters to another hex
                r = new Report(3195, whoReport);
                r.subject = subjectId;
                r.add(coords.getBoardNum());
                vPhaseReport.addElement(r);
            } else {
                // misses and scatters off-board
                r = new Report(3200);
                r.subject = subjectId;
View Full Code Here


        // check for shifty goodness
        boolean shiftheld = (b.getModifiers() & InputEvent.SHIFT_MASK) != 0;

        // check for a deployment
        Coords moveto = b.getCoords();
        if ((ce().getPosition() != null) && (shiftheld || turnMode)) { // turn
            ce().setFacing(ce().getPosition().direction(moveto));
            ce().setSecondaryFacing(ce().getFacing());
            clientgui.bv.redrawEntity(ce());
            turnMode = false;
        } else if(ce().isBoardProhibited(client.game.getBoard().getType())) {
            //check if this type of unit can be on the given type of map
            AlertDialog dlg = new AlertDialog(clientgui.frame,
                    Messages.getString("DeploymentDisplay.alertDialog.title"), //$NON-NLS-1$
                    Messages
                            .getString(
                                    "DeploymentDisplay.wrongMapType", new Object[] { ce().getShortName(), Board.getTypeName(client.game.getBoard().getType()) })); //$NON-NLS-1$
            dlg.setVisible(true);
            return;
        } else if (!(client.game.getBoard().isLegalDeployment(moveto,
                ce().getOwner()) || assaultDropPreference)
                || ce().isHexProhibited(client.game.getBoard().getHex(moveto))) {
            JOptionPane
                    .showMessageDialog(
                            clientgui.frame,
                            Messages
                                    .getString(
                                            "DeploymentDisplay.cantDeployInto", new Object[] { ce().getShortName(), moveto.getBoardNum() }), Messages.getString("DeploymentDisplay.alertDialog.title") //$NON-NLS-1$
                            , JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
            return;
        } else if((ce() instanceof Aero) && client.game.getBoard().inAtmosphere() &&
                (ce().getElevation() <= client.game.getBoard().getHex(moveto).ceiling())) {
            //make sure aeros don't end up at a lower elevation than the current hex
            JOptionPane
            .showMessageDialog(
                    clientgui.frame,
                    Messages
                            .getString(
                                    "DeploymentDisplay.elevationTooLow", new Object[] { ce().getShortName(), moveto.getBoardNum() }), Messages.getString("DeploymentDisplay.alertDialog.title") //$NON-NLS-1$
                    , JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
            return;
        } else if (Compute.stackingViolation(client.game, ce().getId(), moveto) != null) {
            // check if deployed unit violates stacking
            return;
View Full Code Here

                && target.getTargetType() == Targetable.TYPE_MINEFIELD_CLEAR) {
            r = new Report(3255);
            r.indent(1);
            r.subject = subjectId;
            vPhaseReport.addElement(r);
            Coords coords = target.getPosition();

            Enumeration<Minefield> minefields = game.getMinefields(coords).elements();
            ArrayList<Minefield> mfRemoved = new ArrayList<Minefield>();
            while (minefields.hasMoreElements()) {
                Minefield mf = minefields.nextElement();
View Full Code Here

    @Override
    public boolean handle(IGame.Phase phase, Vector<Report> vPhaseReport) {

        if (game.getOptions().booleanOption("tacops_start_fire") && (game.getPlanetaryConditions().getAtmosphere() >= PlanetaryConditions.ATMO_TRACE)) {
            int rear = (ae.getFacing() + 3) % 6;
            Coords src = ae.getPosition();
            Coords rearCoords = src.translated(rear);
            IBoard board = game.getBoard();
            IHex currentHex = board.getHex(src);

            if (!board.contains(rearCoords)) {
                rearCoords = src;
View Full Code Here

        ArrayList<BuildingTemplate> buildingList = new ArrayList<BuildingTemplate>();
        HashSet<Coords> buildingUsed = new HashSet<Coords>();

        ArrayList<Coords> coordList = new ArrayList<Coords>();

        Coords centre = new Coords(width / 2, height / 2);
        double falloff = (double) mapSettings.getCityDensity()
                / (double) (radius * radius);

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                Coords coord = new Coords(x, y);

                if (cityPlan.contains(coord) || buildingUsed.contains(coord)
                        || !board.contains(coord)
                        || !isHexBuildable(board.getHex(coord))) {
                    continue;
                }

                int localdensity = mapSettings.getCityDensity();
                if (radius > 0) {
                    int distance = coord.distance(centre);
                    localdensity = (int) (mapSettings.getCityDensity() - (falloff
                            * distance * distance));
                }

                if (Compute.randomInt(100) > localdensity) {
                    continue; // empty lot
                }
                coordList = new ArrayList<Coords>();
                coordList.add(coord);
                buildingUsed.add(coord);
                while (Compute.randomInt(100) < localdensity) {
                    // try to make a bigger building!
                    int dir = Compute.randomInt(6);
                    Coords next = coord.translated(dir);
                    if (cityPlan.contains(next) || buildingUsed.contains(next)
                            || !board.contains(next)
                            || !isHexBuildable(board.getHex(next))) {
                        break; // oh well, cant expand here
                    }
View Full Code Here

    private void buildGridCity(int maxX, int maxY, int roads) {
        for (int y = 0; y < roads; y++) {
            int startY = Compute.randomInt(maxY / roads) + ((y * maxY) / roads);
            // int start = Compute.randomInt(2);
            Coords coords = new Coords(-1, startY);
            int roadStyle = Compute.randomInt(2) + 1;
            int dir = Compute.randomInt(2) + NE;
            buildStraightRoad(coords, dir, roadStyle);
            startY = Compute.randomInt(maxY / roads) + ((y * maxY) / roads);
            coords = new Coords(maxX, startY);
            dir = Compute.randomInt(2) + SW;
            buildStraightRoad(coords, dir, roadStyle);
        }

        for (int x = 0; x < roads; x++) {
            int startX = Compute.randomInt(maxX / roads) + (x * (maxX / roads));
            Coords coords = new Coords(startX, -1);
            int roadStyle = Compute.randomInt(2) + 1;
            buildStraightRoad(coords, S, roadStyle);
        }
    }
View Full Code Here

        directions.add(NW);
        directions.add(E);
        directions.add(W);

        roads = Math.max(roads, 4);
        cityPlan.add(new Coords(midX, midY));

        int x = 0;
        int y = 0;
        for (int dir = 0; dir < roads; dir++) {
            int baseDirection = -1;
            int roadStyle = Compute.randomInt(2) + 1;

            if (dir < 8) {
                x = midX;
                y = midY;
                baseDirection = directions.remove(Compute.randomInt(directions
                        .size()));
            } else {
                switch (Compute.randomInt(4)) {
                    case 1:
                        x = Compute.randomInt(maxX);
                        y = -1;
                        baseDirection = S;
                        break;
                    case 2:
                        x = Compute.randomInt(maxX);
                        y = maxY;
                        baseDirection = N;
                        break;
                    case 3:
                        x = -1;
                        y = Compute.randomInt(maxY);
                        baseDirection = NE + Compute.randomInt(2);
                        break;
                    default:
                        x = maxX;
                        y = Compute.randomInt(maxY);
                        baseDirection = SW + Compute.randomInt(2);
                        break;
                }
            }
            Coords coords = new Coords(x, y);

            int nextDirection = baseDirection;
            while (coords.x >= -1 && coords.x <= maxX && coords.y >= -1
                    && coords.y <= maxY) {
                int choice = Compute.randomInt(10);
View Full Code Here

    private void buildMetroCity(int maxX, int maxY) {
        int midX = maxX / 2;
        int midY = maxY / 2;

        cityPlan.add(new Coords(midX, midY));

        // have the city hub be the mid point with all the hexes around it
        // cleared out
        for (int hex = 0; hex < 6; hex++)
            cityPlan.add(new Coords(Coords.xInDir(midX, midY, hex), Coords
                    .yInDir(midX, midY, hex)));

        // first east west road
        Coords coords = new Coords(-1, midY / 2);
        buildStraightRoad(coords, E, 1);

        // second east west road
        coords = new Coords(-1, midY + (midY / 2));
        buildStraightRoad(coords, E, 1);

        // First North South Road
        coords = new Coords(midX / 2, -1);
        buildStraightRoad(coords, S, 1);

        // second North South Road
        coords = new Coords(midX + (midX / 2), -1);
        buildStraightRoad(coords, S, 1);

        for (int dir = 0; dir < 8; dir++) {
            coords = new Coords(midX, midY);
            buildStraightRoad(coords, dir, 2);

        }
    }
View Full Code Here

        }
    }

    private Coords selectNextGrid(int dir, Coords coords) {
        Coords result = coords.translated(dir);

        if (dir == E)
            result.x++;

        if (dir == W)
View Full Code Here

     */
    private Coords tryToBuildBridge(Coords start, int direction) {
        if (!board.contains(start))
            return null;
        Vector<Coords> hexes = new Vector<Coords>(7);
        Coords end = null;
        Coords next = start.translated(direction);
        while (hexes.size() < 6) {
            if (!board.contains(next)) {
                // offboard, why bother?
                break;
            }
            if (!hexNeedsBridge(board.getHex(next))) {
                end = next;
                break;
            }
            hexes.add(next);
            next = next.translated(direction);
        }
        if (end != null) {
            // got start and end, can we make a bridge?
            if (hexes.size() == 0)
                return null;
            int elev1 = board.getHex(start).getElevation();
            int elev2 = board.getHex(end).getElevation();
            int elevBridge = board.getHex(end).terrainLevel(Terrains.BRIDGE);
            if (elevBridge >= 0) {
                if (Math.abs(elev2 + elevBridge - elev1) > 2)
                    return null;
                elev1 = elev2 + elevBridge;
            } else {
                if (Math.abs(elev1 - elev2) > 4) {
                    // nobody could use the bridge, give up
                    return null;
                }
                elev1 = (elev1 + elev2) / 2;
            }
            // build the bridge
            int exits = (1 << direction) | (1 << ((direction + 3) % 6));
            int cf = mapSettings.getCityMinCF()
                    + Compute.randomInt(1 + mapSettings.getCityMaxCF()
                            - mapSettings.getCityMinCF());

            for (Enumeration<Coords> e = hexes.elements(); e.hasMoreElements();) {
                Coords c = e.nextElement();
                addBridge(board.getHex(c), exits, elev1, cf);
            }
            connectHexes(start, hexes.firstElement(), 1);
            connectHexes(end, hexes.lastElement(), 1);
        }
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.