if ( entity.hasVibroblades() ){ int vibroHeat = 0;  vibroHeat = entity.getActiveVibrobladeHeat(Mech.LOC_RARM); vibroHeat += entity.getActiveVibrobladeHeat(Mech.LOC_LARM);  if ( vibroHeat > 0 ){ r = new Report(5017); r.subject = entity.getId(); r.add(vibroHeat); addReport(r); entity.heatBuildup += vibroHeat; } }
    private void resolveHeat() {        Report r;        //Heat phase header        addReport(new Report(5000, Report.PUBLIC));        for (Enumeration i = game.getEntities(); i.hasMoreElements();) {            Entity entity = (Entity)i.nextElement();            if ( null == entity.getPosition() ) {                continue;            }            IHex entityHex = game.getBoard().getHex(entity.getPosition());            // heat doesn't matter for non-mechs            if (!(entity instanceof Mech)) {                entity.heatBuildup = 0;                if(game.getOptions().booleanOption("vehicle_fires")                        && entity instanceof Tank) {                    resolveVehicleFire((Tank)entity, true);                }                // If the unit is hit with an Inferno, do flaming death test.                else if ( entity.infernos.isStillBurning()) {                    doFlamingDeath(entity);                }                continue;            }            else {                // Meks gain heat from inferno hits.                if ( entity.infernos.isStillBurning() ) {                    int infernoHeat = entity.infernos.getHeat();                    entity.heatBuildup += infernoHeat;                    r = new Report(5010);                    r.subject = entity.getId();                    r.add(infernoHeat);                    addReport(r);                }            }            // should we even bother?            if ( entity.isDestroyed() || entity.isDoomed() ||                 entity.crew.isDoomed() || entity.crew.isDead() ) {                continue;            }            // engine hits add a lot of heat, provided the engine is on            entity.heatBuildup += entity.getEngineCritHeat();            // If a Mek had an active Stealth suite, add 10 heat.            if ( entity instanceof Mech && entity.isStealthActive() ) {                entity.heatBuildup += 10;                r = new Report(5015);                r.subject = entity.getId();                addReport(r);            }            // If a Mek is in extreme Temperatures, add or subtract one            // heat per 10 degrees (or fraction of 10 degrees) above or            // below 50 or -30 degrees Celsius            if ( entity instanceof Mech && game.getTemperatureDifference() != 0                 && !((Mech)entity).hasLaserHeatSinks()) {                if (game.getOptions().intOption("temperature") > 50) {                    entity.heatBuildup += game.getTemperatureDifference();                    r = new Report(5020);                    r.subject = entity.getId();                    r.add(game.getTemperatureDifference());                    addReport(r);                }                else {                    entity.heatBuildup -= game.getTemperatureDifference();                    r = new Report(5025);                    r.subject = entity.getId();                    r.add(game.getTemperatureDifference());                    addReport(r);                }            }            // Add +5 Heat if the hex you're in is on fire            // and was on fire for the full round.            if (entityHex != null) {                if (entityHex.terrainLevel(Terrains.FIRE) == 2) {                    entity.heatBuildup += 5;                    r = new Report(5030);                    r.subject = entity.getId();                    addReport(r);                }                int magma = entityHex.terrainLevel(Terrains.MAGMA);                if(magma > 0) {                    entity.heatBuildup += 5 * magma;                    r = new Report(5032);                    r.subject = entity.getId();                    r.add(5 * magma);                    addReport(r);                                    }            }                        // if heatbuildup is negative due to temperature, set it to 0            // for prettier turnreports            if (entity.heatBuildup < 0) {                entity.heatBuildup = 0;            }            // add the heat we've built up so far.            entity.heat += entity.heatBuildup;            // how much heat can we sink?            int tosink = entity.getHeatCapacityWithWater();            // should we use a coolant pod?            int safeHeat = entity.hasInfernoAmmo() ? 9 : 13;            int possibleSinkage = ((Mech)entity).getNumberOfSinks();            for(Enumeration equip=entity.getEquipment();equip.hasMoreElements();) {                Mounted m = (Mounted)equip.nextElement();                if(m.getType() instanceof AmmoType) {                    AmmoType at = (AmmoType)(m.getType());                    if(at.getAmmoType() == AmmoType.T_COOLANT_POD && m.isAmmoUsable()) {                        EquipmentMode mode = m.curMode();                        if(mode.equals("dump")) {                            r = new Report(5260);                            r.subject = entity.getId();                            addReport(r);                            m.setShotsLeft(0);                            tosink += possibleSinkage;                            break;                        }                        if(mode.equals("safe") && entity.heat - tosink > safeHeat) {                            r = new Report(5265);                            r.subject = entity.getId();                            addReport(r);                            m.setShotsLeft(0);                            tosink += possibleSinkage;                            break;                        }                        if(mode.equals("efficient") && entity.heat - tosink >= possibleSinkage) {                            r = new Report(5270);                            r.subject = entity.getId();                            addReport(r);                            m.setShotsLeft(0);                            tosink += possibleSinkage;                            break;                        }                    }                }            }            tosink = Math.min( tosink, entity.heat );            entity.heat -= tosink;            r = new Report(5035);            r.subject = entity.getId();            r.addDesc(entity);            r.add(entity.heatBuildup);            r.add(tosink);            r.add(entity.heat);            addReport(r);            entity.heatBuildup = 0;            // Does the unit have inferno ammo?            if( entity.hasInfernoAmmo() ) {                // Roll for possible inferno ammo explosion.                if (entity.heat >= 10) {                    int boom = 4 + (entity.heat >= 14 ? 2 : 0) +                        (entity.heat >= 19 ? 2 : 0) +                        (entity.heat >= 23 ? 2 : 0) +                        (entity.heat >= 28 ? 2 : 0);                    int boomroll = Compute.d6(2);                    r = new Report(5040);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(boom);                    r.add(boomroll);                    if (boomroll >= boom) {                        //avoided                        r.choose(true);                        addReport(r);                    } else {                        r.choose(false);                        addReport(r);                        addReport( explodeInfernoAmmoFromHeat(entity));                    }                }            } // End avoid-inferno-explosion            int autoShutDownHeat;            boolean mtHeat;                        if (game.getOptions().booleanOption("maxtech_heat")) {                autoShutDownHeat = 50;                mtHeat = true;            } else {                autoShutDownHeat = 30;                mtHeat = false;            }            // heat effects: start up            if (entity.heat < autoShutDownHeat && entity.isShutDown()) {                if (entity.heat < 14) {                    //automatically starts up again                    entity.setShutDown(false);                    r = new Report(5045);                    r.subject = entity.getId();                    r.addDesc(entity);                    addReport(r);                } else {                    //roll for startup                    int startup = 4 + (((entity.heat - 14) / 4) * 2);                    if (mtHeat) {                        startup = entity.crew.getPiloting() + startup - 8;                    }                    int suroll = Compute.d6(2);                    r = new Report(5050);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(startup);                    r.add(suroll);                    if (suroll >= startup) {                        //start 'er back up                        entity.setShutDown(false);                        r.choose(true);                    } else {                        r.choose(false);                    }                    addReport(r);                }            }            // heat effects: shutdown!            // 2003-01-26 JAD - Don't shut down if you just restarted.            else if (entity.heat >= 14 && !entity.isShutDown()) {                if (entity.heat >= autoShutDownHeat) {                    r = new Report(5055);                    r.subject = entity.getId();                    r.addDesc(entity);                    addReport(r);                    // add a piloting roll and resolve immediately                    game.addPSR(new PilotingRollData                        ( entity.getId(), 3, "reactor shutdown" ));                    resolvePilotingRolls();                    // okay, now mark shut down                    entity.setShutDown(true);                } else if (entity.heat >= 14) {                    int shutdown = 4 + (((entity.heat - 14) / 4) * 2);                    if (mtHeat) {                        shutdown = entity.crew.getPiloting() + shutdown - 8;                    }                    int sdroll = Compute.d6(2);                    r = new Report(5060);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(shutdown);                    r.add(sdroll);                    if (sdroll >= shutdown) {                        //avoided                        r.choose(true);                        addReport(r);                    } else {                        //shutting down...                        r.choose(false);                        addReport(r);                        // add a piloting roll and resolve immediately                        game.addPSR(new PilotingRollData                            ( entity.getId(), 3, "reactor shutdown" ));                        resolvePilotingRolls();                        // okay, now mark shut down                        entity.setShutDown(true);                    }                }            }            // heat effects: ammo explosion!            if (entity.heat >= 19) {                int boom = 4 + (entity.heat >= 23 ? 2 : 0) +                    (entity.heat >= 28 ? 2 : 0);                if (mtHeat) {                    boom +=                         (entity.heat >= 35 ? 2 : 0) +                        (entity.heat >= 40 ? 2 : 0) +                        (entity.heat >= 45 ? 2 : 0);                    // Last line is a crutch; 45 heat should be no roll                    // but automatic explosion.                }                if(entity instanceof Mech && ((Mech)entity).hasLaserHeatSinks())                    boom--;                int boomroll = Compute.d6(2);                r = new Report(5065);                r.subject = entity.getId();                r.addDesc(entity);                r.add(boom);                r.add(boomroll);                if (boomroll >= boom) {                    //mech is ok                    r.choose(true);                    addReport(r);                } else {                    //boom!                    r.choose(false);                    addReport(r);                    addReport( explodeAmmoFromHeat(entity));                }            }            // heat effects: mechwarrior damage            // N.B. The pilot may already be dead.            int lifeSupportCritCount = 0;            boolean torsoMountedCockpit = ((Mech)entity).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED;            if ((entity instanceof Mech)                    && torsoMountedCockpit) {                lifeSupportCritCount = entity.getHitCriticals(CriticalSlot.TYPE_SYSTEM,                    Mech.SYSTEM_LIFE_SUPPORT,                    Mech.LOC_RT);                lifeSupportCritCount += entity.getHitCriticals(CriticalSlot.TYPE_SYSTEM,                    Mech.SYSTEM_LIFE_SUPPORT,                    Mech.LOC_LT);            } else {                lifeSupportCritCount = entity.getHitCriticals(CriticalSlot.TYPE_SYSTEM,                        Mech.SYSTEM_LIFE_SUPPORT,                        Mech.LOC_HEAD);            }            if (lifeSupportCritCount > 0                    && ((entity.heat >= 15) || (torsoMountedCockpit && (entity.heat >= 0)))                    && !entity.crew.isDead() && !entity.crew.isDoomed()                    && !entity.crew.isEjected()) {                int heatLimitDesc = 1;                int damageToCrew = 0;                if (entity.heat >= 47 && mtHeat) {                    // mechwarrior takes 5 damage                    heatLimitDesc = 47;                    damageToCrew = 5;                } else if (entity.heat >= 39 && mtHeat) {                    // mechwarrior takes 4 damage                    heatLimitDesc = 39;                    damageToCrew = 4;                } else if (entity.heat >= 32 && mtHeat) {                    // mechwarrior takes 3 damage                    heatLimitDesc = 32;                    damageToCrew = 3;                } else if (entity.heat >= 25) {                    // mechwarrior takes 2 damage                    heatLimitDesc = 25;                    damageToCrew = 2;                } else if (entity.heat >= 15) {                    // mechwarrior takes 1 damage                    heatLimitDesc = 15;                    damageToCrew = 1;                }                if (entity.heat > 0                        && (entity instanceof Mech)                        && ((Mech)entity).getCockpitType() == Mech.COCKPIT_TORSO_MOUNTED)                    damageToCrew += 1;                r = new Report(5070);                r.subject = entity.getId();                r.addDesc(entity);                r.add(heatLimitDesc);                r.add(damageToCrew);                addReport(r);                damageCrew(entity, damageToCrew);            } else if (mtHeat && entity.heat >= 32                       && !entity.crew.isDead() && !entity.crew.isDoomed() ) {                // Pilot may take damage from heat if MaxTech option is set                int heatroll = Compute.d6(2);                int avoidNumber = -1;                if (entity.heat >= 47) {                    avoidNumber = 12;                } else if (entity.heat >= 39) {                    avoidNumber = 10;                } else if (entity.heat >= 32) {                    avoidNumber = 8;                }                r = new Report(5075);                r.subject = entity.getId();                r.addDesc(entity);                r.add(avoidNumber);                r.add(heatroll);                if (heatroll >= avoidNumber) {                    //damage avoided                    r.choose(true);                } else {                    damageCrew(entity, 1);                    r.choose(false);                }                addReport(r);            }            // The pilot may have just expired.            if ( (entity.crew.isDead() || entity.crew.isDoomed() )                 && !entity.crew.isEjected() ) {                r = new Report(5080);                r.subject = entity.getId();                r.addDesc(entity);                r.newlines = 0;                addReport(r);                addReport( destroyEntity(entity, "crew death", true));            }            // With MaxTech Heat Scale, there may occur critical damage            if (mtHeat) {                if (entity.heat >= 36) {                    int damageroll = Compute.d6(2);                    int damageNumber = -1;                    if (entity.heat >= 44) {                        damageNumber = 10;                    } else if (entity.heat >= 36) {                        damageNumber = 8;                    }                    r = new Report(5085);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(damageNumber);                    r.add(damageroll);                    r.newlines = 0;                    if (damageroll >= damageNumber) {                        r.choose(true);                        addReport(r);                    } else {                        r.choose(false);                        addReport(r);                        addReport(oneCriticalEntity(entity, Compute.d6(2)));                        //add an empty report, for linebreaking                        r = new Report(1210);                        addReport(r);                    }                }            }        }        if (vPhaseReport.size() == 1) {            //I guess nothing happened...            addReport(new Report(1205, Report.PUBLIC));        }    }