⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fireprocessor.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.WOODS, 1));                //heavy woods burned down to light woods                r = new Report(5140, Report.PUBLIC);                r.add(coords.getBoardNum());                vPhaseReport.addElement(r);            }            else if(hex.terrainLevel(Terrains.WOODS) == 1) {                hex.removeTerrain(Terrains.WOODS);                hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.ROUGH, 1));                //light woods burns down, fire goes out                r = new Report(5145, Report.PUBLIC);                r.add(coords.getBoardNum());                vPhaseReport.addElement(r);            }            if(hex.terrainLevel(Terrains.JUNGLE) > 2) {                hex.removeTerrain(Terrains.JUNGLE);                hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.JUNGLE, 2));                //ultra heavy jungle burned down to heavy jungle                r = new Report(5143, Report.PUBLIC);                r.add(coords.getBoardNum());                vPhaseReport.addElement(r);            }            else if(hex.terrainLevel(Terrains.JUNGLE) == 2) {                hex.removeTerrain(Terrains.JUNGLE);                hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.JUNGLE, 1));                //heavy jungle burned down to light jungle                r = new Report(5142, Report.PUBLIC);                r.add(coords.getBoardNum());                vPhaseReport.addElement(r);            }            else if(hex.terrainLevel(Terrains.JUNGLE) == 1) {                hex.removeTerrain(Terrains.JUNGLE);                hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.ROUGH, 1));                //light jungle burns down, fire goes out                r = new Report(5146, Report.PUBLIC);                r.add(coords.getBoardNum());                vPhaseReport.addElement(r);            }            server.sendChangedHex(coords);        }    }    /**     * Spreads the fire around the specified coordinates.     */    public void spreadFire(int x, int y, int windDir) {        Coords src = new Coords(x, y);        Coords nextCoords = src.translated(windDir);        spreadFire(nextCoords, 9);        // Spread to the next hex downwind on a 12 if the first hex wasn't burning...        IHex nextHex = game.getBoard().getHex(nextCoords);        if (nextHex != null && !(nextHex.containsTerrain(Terrains.FIRE))) {            // we've already gone one step in the wind direction, now go another            spreadFire(nextCoords.translated(windDir), 12);        }        // spread fire 60 degrees clockwise....        spreadFire(src.translated((windDir + 1) % 6), 11);        // spread fire 60 degrees counterclockwise        spreadFire(src.translated((windDir + 5) % 6), 11);    }    /**     * Spreads the fire, and reports the spread, to the specified hex, if     * possible, if the hex isn't already on fire, and the fire roll is made.     */    public void spreadFire(Coords coords, int roll) {        IHex hex = game.getBoard().getHex(coords);        if (hex == null) {            // Don't attempt to spread fire off the board.            return;        }        if (!(hex.containsTerrain(Terrains.FIRE)) && server.ignite(hex, roll)) {            server.sendChangedHex(coords);            Report r = new Report(5150, Report.PUBLIC);            r.add(coords.getBoardNum());            vPhaseReport.addElement(r);        }    }    /**     * Under L3 rules, smoke drifts in the direction of the wind and     * has a chance to dissipate.  This function will keep track of     * hexes to have smoke removed and added, since there's no other     * way to tell if a certain smoke cloud has drifted that turn.     * This method creates the class SmokeDrift to store hex and size     * data for the smoke clouds.  This method calls functions     * driftAddSmoke, driftSmokeDissipate, driftSmokeReport     */    private void resolveSmoke() {        IBoard board = game.getBoard();        int width = board.getWidth();        int height = board.getHeight();        int windDir = game.getWindDirection();        int windStr = game.getWindStrength();        Vector SmokeToAdd = new Vector();        class SmokeDrift { // hold the hex and level of the smoke cloud            public Coords coords;            public int size;            public SmokeDrift(Coords c, int s) {                coords = c;                size = s;            }            public SmokeDrift(SmokeDrift sd) {                sd.coords = coords;                sd.size = size;            }        }        // Cycle through all hexes, checking for smoke, IF the wind is higher than calm! Calm means no drift!        if(windStr > 0) {            debugTime("resolve smoke 1", true);            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 existence of smoke, then add it to the vector...if the wind is not Calm!                    if (currentHex.containsTerrain(Terrains.SMOKE)){                        int smokeLevel = currentHex.terrainLevel(Terrains.SMOKE);                        Coords smokeCoords = driftAddSmoke(currentXCoord, currentYCoord, windDir, windStr);                        //                        System.out.println(currentCoords.toString() + " to " + smokeCoords.toString());                        if( board.contains(smokeCoords)) { // don't add it to the vector if it's not on board!                            SmokeToAdd.addElement(new SmokeDrift(new Coords(smokeCoords), smokeLevel));                        }                        else {                            // report that the smoke has blown off the map                            Report r = new Report(5230, Report.PUBLIC);                            r.add(currentCoords.getBoardNum());                            vPhaseReport.addElement(r);                        }                        currentHex.removeTerrain(Terrains.SMOKE);                        server.sendChangedHex(currentCoords);                    }                }  // end the loop through Y coordinates            }  // end the loop through X coordinates            debugTime("resolve smoke 1 end, resolve smoke 2 begin", true);            // Cycle through the vector and add the drifted smoke            for (int sta = 0; sta < SmokeToAdd.size(); sta++ ) {                SmokeDrift drift = (SmokeDrift)SmokeToAdd.elementAt(sta);                Coords smokeCoords = drift.coords;                int smokeSize = drift.size;                IHex smokeHex = game.getBoard().getHex(smokeCoords);                smokeHex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.SMOKE, smokeSize));                server.sendChangedHex(smokeCoords);            }            debugTime("resolve smoke 2 end, resolve smoke 3 begin", true);            // Cycle through the vector again and dissipate the smoke, then reporting it            for (int dis = 0; dis < SmokeToAdd.size(); dis++ ) {                SmokeDrift drift = (SmokeDrift)SmokeToAdd.elementAt(dis);                Coords smokeCoords = drift.coords;                int smokeSize = drift.size;                IHex smokeHex = game.getBoard().getHex(smokeCoords);                int roll = Compute.d6(2);                boolean smokeDis = driftSmokeDissipate(smokeHex, roll, smokeSize, windStr);                driftSmokeReport(smokeCoords, smokeSize, smokeDis);                server.sendChangedHex(smokeCoords);            }            debugTime("resolve smoke 3 end", false);        } // end smoke resolution    }    public Coords driftAddSmoke(int x, int y, int windDir, int windStr){        Coords src = new Coords(x, y);        Coords nextCoords = src.translated(windDir);        // if the wind is High, it blows 2 hexes! If it's Calm, there's no drift!        if (windStr == 3) {            nextCoords = nextCoords.translated(windDir);        }        return nextCoords;    }    /**     * This method does not currently support "smoke clouds" as specified     * in MaxTech (revised ed.) under "Dissipation" on page 51.  The     * added complexity was not worth it given that smoke-delivering     * weapons were not even implemented yet (and might never be).     */    public boolean driftSmokeDissipate(IHex smokeHex, int roll, int smokeSize, int windStr) {        // Dissipate in various winds        if (roll > 10 || (roll > 9 && windStr == 2) || (roll > 7 && windStr == 3)) {            smokeHex.removeTerrain(Terrains.SMOKE);            if (smokeSize == 2) {                smokeHex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.SMOKE, 1));                return true;            }			return true;        }		return false;    }    public void driftSmokeReport(Coords smokeCoords, int size, boolean dis) {        Report r;        if (size == 2 && dis == true) {            //heavy smoke drifts and dissipates to light            r = new Report(5210, Report.PUBLIC);            r.add(smokeCoords.getBoardNum());            vPhaseReport.addElement(r);        }        else if (size == 2 && dis == false) {            //heavy smoke drifts            r = new Report(5215, Report.PUBLIC);            r.add(smokeCoords.getBoardNum());            vPhaseReport.addElement(r);        }        else if (size == 1 && dis == true) {            //light smoke drifts and dissipates            r = new Report(5220, Report.PUBLIC);            r.add(smokeCoords.getBoardNum());            vPhaseReport.addElement(r);        }        else if (size == 1 && dis == false) {            //light smoke drifts            r = new Report(5225, Report.PUBLIC);            r.add(smokeCoords.getBoardNum());            vPhaseReport.addElement(r);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -