* this turn are marked as "burning" for next turn. What turn the fire startd on is no
* longer determined by level but is rather a characteristic of the hex.
* Level now denotes standard and inferno fires.
*/
private void resolveFire() {
IBoard board = game.getBoard();
int width = board.getWidth();
int height = board.getHeight();
int windDirection = game.getPlanetaryConditions().getWindDirection();
int windStrength = game.getPlanetaryConditions().getWindStrength();
Report r;
// Get the position map of all entities in the game.
Hashtable<Coords, Vector<Entity>> positionMap = game.getPositionMap();
// process smoke FIRST, before any fires spread or
// smoke is produced.
resolveSmoke();
// Cycle through all buildings, checking for fire.
// ASSUMPTION: buildings don't lose 2 CF on the turn a fire starts.
// ASSUMPTION: multi-hex buildings lose 2 CF in each burning hex
Enumeration<Building> buildings = game.getBoard().getBuildings();
while (buildings.hasMoreElements()) {
Building bldg = buildings.nextElement();
Enumeration<Coords> bldgCoords = bldg.getCoords();
while (bldgCoords.hasMoreElements()) {
Coords coords = bldgCoords.nextElement();
if (bldg.isBurning(coords)) {
int cf = Math.max(bldg.getCurrentCF(coords) - 2, 0);
bldg.setCurrentCF(cf, coords);
// Does the building burn down?
if (cf == 0) {
r = new Report(5120, Report.PUBLIC);
r.add(bldg.getName());
vPhaseReport.addElement(r);
}
// If it doesn't collapse under its load, mark it for update.
else if (!server.checkForCollapse(bldg, positionMap, coords, false)) {
bldg.setPhaseCF(cf, coords);
}
}
}
}
debugTime("resolve fire 1", true);
// Cycle through all hexes, checking for fire and the spread of fire
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);
if(currentHex.containsTerrain(Terrains.FIRE)) {
//If the woods has been cleared, or the building
// has collapsed put non-inferno fires out.
if ((currentHex.terrainLevel(Terrains.FIRE) == 1) && !currentHex.isIgnitable()) {
server.removeFire(currentCoords, "lack of fuel");
continue;
}
//only check spread for fires that didn't start this turn
if(currentHex.getFireTurn() > 0) {
//optional rule, woods burn down
if ((currentHex.containsTerrain(Terrains.WOODS) || currentHex
.containsTerrain(Terrains.JUNGLE))
&& game.getOptions().booleanOption("woods_burn_down")) {
burnDownWoods(currentCoords);
}
//report and check for fire spread
r = new Report(5125, Report.PUBLIC);
if (currentHex.terrainLevel(Terrains.FIRE) == 2) {
r.messageId = 5130;
}
r.add(currentCoords.getBoardNum());
vPhaseReport.addElement(r);
spreadFire(currentXCoord, currentYCoord, windDirection, windStrength);
}
}
}
}
//Cycle through all hexes again, reporting new fires, spreading smoke, and incrementing the fire turn.
//Can't do this in first loop because new fires may be spread
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);
if(currentHex.containsTerrain(Terrains.FIRE)) {
//was the fire started this turn?
if(currentHex.getFireTurn() == 0) {
//report fire started this round
r = new Report(5135, Report.PUBLIC);
r.add(currentCoords.getBoardNum());
vPhaseReport.addElement(r);
// If the hex contains a building, set it on fire.
Building bldg = game.getBoard().getBuildingAt(
currentCoords);
if (bldg != null) {
bldg.setBurning(true, currentCoords);
}
}
//check for any explosions
server.checkExplodeIndustrialZone(currentCoords, vPhaseReport);
//Add smoke (unless we are in a tornado)
boolean bInferno = currentHex.terrainLevel(Terrains.FIRE) == 2;
if (game.getPlanetaryConditions().getWindStrength() < PlanetaryConditions.WI_TORNADO_F13) {
ArrayList<Coords> smokeList = new ArrayList<Coords>();
smokeList.add(new Coords(Coords.xInDir(currentXCoord, currentYCoord, windDirection), Coords.yInDir(currentXCoord, currentYCoord, windDirection)));
smokeList.add(new Coords(Coords.xInDir(currentXCoord, currentYCoord, (windDirection+1)%6), Coords.yInDir(currentXCoord, currentYCoord, (windDirection+1)%6)));
smokeList.add(new Coords(Coords.xInDir(currentXCoord, currentYCoord, (windDirection+5)%6), Coords.yInDir(currentXCoord, currentYCoord, (windDirection+5)%6)));
server.addSmoke(smokeList, windDirection, bInferno);
board.initializeAround(currentXCoord, currentYCoord);
}
//increment the fire turn counter
currentHex.incrementFireTurn();
server.sendChangedHex(currentCoords);
}