Package megamek.common

Examples of megamek.common.PlanetaryConditions


    private void resolveWeather() {
        ITerrainFactory tf = Terrains.getTerrainFactory();
        IBoard board = game.getBoard();
        int width = board.getWidth();
        int height = board.getHeight();
        PlanetaryConditions conditions = game.getPlanetaryConditions();
        boolean lightSnow = false;
        boolean deepSnow = false;
        boolean ice = false;
       
        if(!conditions.isTerrainAffected())
            return;
       
        debugTime("resolve weather 1", true);

        //first we need to increment the conditions
        if(conditions.getWeather() == PlanetaryConditions.WE_MOD_SNOW && game.getBoard().onGround()) {
            modSnowTurn = modSnowTurn + 1;
            if(modSnowTurn == 9) {
                lightSnow = true;
            }
            if(modSnowTurn == 19) {
                deepSnow = true;
                ice = true;
            }
        }
        if(conditions.getWeather() == PlanetaryConditions.WE_HEAVY_SNOW && game.getBoard().onGround()) { 
            heavySnowTurn = heavySnowTurn + 1;
            if(heavySnowTurn == 4) {
                lightSnow = true;
            }
            if(heavySnowTurn == 14) {
                deepSnow = true;
            }
            if(heavySnowTurn == 19) {
                ice = true;
            }
        }
        if(conditions.getWeather() == PlanetaryConditions.WE_SLEET && game.getBoard().onGround()) { 
            sleetTurn = sleetTurn + 1;
            if(sleetTurn == 14) {
                ice = true;
            }
        }
        if(conditions.getWeather() == PlanetaryConditions.WE_ICE_STORM && game.getBoard().onGround()) { 
            iceTurn = iceTurn + 1;
            if(iceTurn == 14) {
                ice = true;
            }
        }
       
        if(lightSnow) {
            Report r = new Report(5505, Report.PUBLIC);
            vPhaseReport.addElement(r);
        }
        if(deepSnow) {
            Report r = new Report(5510, Report.PUBLIC);
            vPhaseReport.addElement(r);
        }
        if(ice) {
            Report r = new Report(5515, Report.PUBLIC);
            vPhaseReport.addElement(r);
        }
           
        // Cycle through all hexes, checking for the appropriate weather changes
        for (int currentXCoord = 0; currentXCoord < width; currentXCoord++ ) {
            for (int currentYCoord = 0; currentYCoord < height; currentYCoord++) {
                Coords currentCoords = new Coords(currentXCoord, currentYCoord);
                IHex currentHex = board.getHex(currentXCoord, currentYCoord);

                //check for fires and potentially put them out
                if (currentHex.containsTerrain(Terrains.FIRE)) {
                    //only standard fires get put out
                    if(currentHex.terrainLevel(Terrains.FIRE) == 1) {
                        if(conditions.putOutFire()) {
                            server.removeFire(currentCoords, "weather conditions");   
                        }
                    } else {
                        //inferno fires should become regular fires
                        currentHex.removeTerrain(Terrains.FIRE);
                        currentHex.addTerrain(tf.createTerrain(Terrains.FIRE,1));
                        server.sendChangedHex(currentCoords);
                    }
                }  
               
                if(ice && !currentHex.containsTerrain(Terrains.ICE)
                        && currentHex.containsTerrain(Terrains.WATER)) {
                    currentHex.addTerrain(tf.createTerrain(Terrains.ICE, 1));
                    server.sendChangedHex(currentCoords);
                }
               
                if(lightSnow
                        && !currentHex.containsTerrain(Terrains.SNOW)
                        && !(currentHex.containsTerrain(Terrains.WATER) && !currentHex.containsTerrain(Terrains.ICE))
                        && !currentHex.containsTerrain(Terrains.MAGMA)) {
                    currentHex.addTerrain(tf.createTerrain(Terrains.SNOW, 1));
                    server.sendChangedHex(currentCoords);
                }
               
                if(deepSnow && !(currentHex.terrainLevel(Terrains.SNOW) > 1)
                        && !(currentHex.containsTerrain(Terrains.WATER) && !currentHex.containsTerrain(Terrains.ICE))
                        && !currentHex.containsTerrain(Terrains.MAGMA)) {
                    currentHex.addTerrain(tf.createTerrain(Terrains.SNOW, 2));
                    server.sendChangedHex(currentCoords);
                }
               
                //check for the melting of any snow or ice
                if(currentHex.terrainLevel(Terrains.SNOW) > 1
                        && currentHex.containsTerrain(Terrains.FIRE) && currentHex.getFireTurn() == 3) {
                    currentHex.removeTerrain(Terrains.SNOW);
                    if(!currentHex.containsTerrain(Terrains.MUD) && !currentHex.containsTerrain(Terrains.WATER)) {
                        currentHex.addTerrain(tf.createTerrain(Terrains.MUD, 1));
                    }
                }
               
                if(currentHex.terrainLevel(Terrains.SNOW) == 1
                        && currentHex.containsTerrain(Terrains.FIRE) && currentHex.getFireTurn() == 1) {
                    currentHex.removeTerrain(Terrains.SNOW);
                    if(!currentHex.containsTerrain(Terrains.MUD) && !currentHex.containsTerrain(Terrains.WATER)) {
                        currentHex.addTerrain(tf.createTerrain(Terrains.MUD, 1));
                    }
                }
               
                if(currentHex.containsTerrain(Terrains.ICE)
                        && currentHex.containsTerrain(Terrains.FIRE) && currentHex.getFireTurn() == 2) {
                    currentHex.removeTerrain(Terrains.ICE);
                    if(!currentHex.containsTerrain(Terrains.MUD) && !currentHex.containsTerrain(Terrains.WATER)) {
                        currentHex.addTerrain(tf.createTerrain(Terrains.MUD, 1));
                    }
                }
               
                //check for rapids/torrents created by wind
                //FIXME: This doesn't seem to be doing anything
                if(conditions.getWindStrength() > PlanetaryConditions.WI_MOD_GALE
                        && currentHex.containsTerrain(Terrains.WATER) && currentHex.depth() > 0) {
                   
                    if(conditions.getWindStrength() > PlanetaryConditions.WI_STORM) {
                        if(!(currentHex.terrainLevel(Terrains.RAPIDS) > 1)) {
                            currentHex.addTerrain(tf.createTerrain(Terrains.RAPIDS, 2));
                        }
                    } else {
                        if(!currentHex.containsTerrain(Terrains.RAPIDS)) {
View Full Code Here


            }
            break;
        case Packet.COMMAND_SENDING_PLANETARY_CONDITIONS:
            // MapSettings newSettings = (MapSettings) packet.getObject(0);
            if ( game.getPhase().isBefore(Phase.PHASE_DEPLOYMENT) ){
                PlanetaryConditions conditions = (PlanetaryConditions) packet.getObject(0);
                sendServerChat("Player " + player.getName() + " changed planetary conditions");
                game.setPlanetaryConditions(conditions);
                resetPlayersDone();
                transmitAllPlayerDones();
                send(createPlanetaryConditionsPacket());
View Full Code Here

TOP

Related Classes of megamek.common.PlanetaryConditions

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.