Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning storm updates #5436

Merged
merged 19 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions megamek/i18n/megamek/common/report-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@
5606=player must choose <data> bombs to be destroyed.
5607=bot loses <data> bombs.
5608=<data> (<data>) Internal Bomb Bay + Cargo critical: Damage exceeds remaining bombs; all bombs destroyed.
5620=<newline>Damage from lightning storm<newline>-------------------
5621=lightning strike in hex <data>
5622= and adjacent hex <data>

#6000's -- Damage Related
6005=\ no effect.
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5269,7 +5269,7 @@ public static ToHitData processAttackerSPAs(ToHitData toHit, Entity ae, Targetab
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.RainSpec"));
}

if (conditions.getWeather().isModerateRainOrHeavyRainOrGustingRainOrDownpour()) {
if (conditions.getWeather().isModerateRainOrHeavyRainOrGustingRainOrDownpourOrLightningStorm()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.RainSpec"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public int getWeatherHitPenalty(Entity en) {
if (getWeather().isLightRainOrLightSnow()
&& en.isConventionalInfantry()) {
return 1;
} else if (getWeather().isModerateRainOrHeavyRainOrGustingRainOrModerateSnowOrSnowFlurriesOrHeavySnowOrSleet()) {
} else if (getWeather().isModerateRainOrHeavyRainOrGustingRainOrModerateSnowOrSnowFlurriesOrHeavySnowOrSleetOrLightningStorm()) {
return 1;
} else if(getWeather().isDownpour()) {
return 2;
Expand Down Expand Up @@ -402,7 +402,7 @@ && getWind().isStrongerThan(Wind.STORM)) {
public int getIgniteModifiers() {
int mod = 0;

if (getWeather().isLightRainOrModerateRain() ) {
if (getWeather().isLightRainOrModerateRainOrLightningStorm() ) {
mod += 1;
}

Expand Down Expand Up @@ -448,6 +448,7 @@ public boolean putOutFire() {
case MOD_RAIN:
case MOD_SNOW:
case SNOW_FLURRIES:
case LIGHTNING_STORM:
roll = roll + 2;
break;
case HEAVY_RAIN:
Expand Down Expand Up @@ -751,7 +752,7 @@ && getWind().isStrongerThan(Wind.LIGHT_GALE)) {
} else {
otherRange = 8;
}
} else if (getWeather().isModerateRainOrModerateSnow()) {
} else if (getWeather().isModerateRainOrModerateSnowOrLightningStorm()) {
if (isMechOrVee || isLowAltitudeAero) {
otherRange = 20;
} else if (isAero) {
Expand Down Expand Up @@ -884,6 +885,7 @@ public static Wind setWindFromWeather(Weather weather, Wind wind) {
switch (weather) {
case ICE_STORM:
case SNOW_FLURRIES:
case LIGHTNING_STORM:
return Wind.MOD_GALE;
case GUSTING_RAIN:
return Wind.STRONG_GALE;
Expand Down
25 changes: 17 additions & 8 deletions megamek/src/megamek/common/planetaryconditions/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,26 @@ public boolean isHeavyRainOrGustingRain() {
}


public boolean isLightRainOrModerateRain() {
public boolean isLightRainOrModerateRainOrLightningStorm() {
return isLightRain()
|| isModerateRain();
|| isModerateRain()
|| isLightningStorm();
}

public boolean isModerateSnowOrSnowFlurries() {
return isModerateSnow()
|| isSnowFlurries();
}

public boolean isModerateRainOrModerateSnow() {
public boolean isModerateRainOrLightningStorm() {
return isModerateRain()
|| isModerateSnow();
|| isLightningStorm();
}

public boolean isModerateRainOrModerateSnowOrLightningStorm() {
return isModerateRain()
|| isModerateSnow()
|| isLightningStorm();
}

public boolean isDownpourOrHeavySnowOrIceStorm() {
Expand Down Expand Up @@ -218,11 +225,12 @@ public boolean isModerateSnowOrHeavySnowOrSnowFlurriesOrSleet() {
|| isSleet();
}

public boolean isModerateRainOrHeavyRainOrGustingRainOrDownpour() {
public boolean isModerateRainOrHeavyRainOrGustingRainOrDownpourOrLightningStorm() {
return isModerateRain()
|| isHeavyRain()
|| isGustingRain()
|| isDownpour();
|| isDownpour()
|| isLightningStorm();
}

public boolean isGustingRainOrSnowFlurriesOrIceStormOrLightningStorm() {
Expand Down Expand Up @@ -258,14 +266,15 @@ public boolean isHeavyRainOrGustingRainOrDownpourOrLightSnowOrModerateSnowOrSnow
|| isSnowFlurries();
}

public boolean isModerateRainOrHeavyRainOrGustingRainOrModerateSnowOrSnowFlurriesOrHeavySnowOrSleet() {
public boolean isModerateRainOrHeavyRainOrGustingRainOrModerateSnowOrSnowFlurriesOrHeavySnowOrSleetOrLightningStorm() {
return isModerateRain()
|| isHeavyRain()
|| isGustingRain()
|| isModerateSnow()
|| isSnowFlurries()
|| isHeavySnow()
|| isSleet();
|| isSleet()
|| isLightningStorm();
}

public static Weather getWeather(int i) {
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/util/BoardUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ public static void addWeatherConditions(Board board, Weather weatherCond, Wind w
Hex hex = board.getHex(c);

//moderate rain - mud in clear hexes, depth 0 water, and dirt roads (not implemented yet)
if (weatherCond.isModerateRain()) {
if (weatherCond.isModerateRainOrLightningStorm()) {
if ((hex.terrainsPresent() == 0) || (hex.containsTerrain(Terrains.WATER) && (hex.depth() == 0))) {
hex.addTerrain(new Terrain(Terrains.MUD, 1));
if (hex.containsTerrain(Terrains.WATER)) {
Expand Down
80 changes: 76 additions & 4 deletions megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1997,10 +1997,7 @@
resetEntityPhase(phase);
clearReports();
resolveHeat();
PlanetaryConditions conditions = game.getPlanetaryConditions();
if (conditions.isBlowingSandActive()) {
addReport(resolveBlowingSandDamage());
}
resolveWeather();
addReport(resolveControlRolls());
addReport(checkForTraitors());
// write End Phase header
Expand Down Expand Up @@ -18720,6 +18717,16 @@
return psr;
}

private void resolveWeather() {
PlanetaryConditions conditions = game.getPlanetaryConditions();
if (conditions.isBlowingSandActive()) {
addReport(resolveBlowingSandDamage());
}
if (conditions.getWeather().isLightningStorm()) {
addReport(resolveLightningStormDamage());
}
}

/**
* Each mech sinks the amount of heat appropriate to its current heat
* capacity.
Expand Down Expand Up @@ -34701,6 +34708,71 @@
return game.getSmokeCloudList();
}

private Vector<Report> resolveLightningStormDamage() {
Vector<Report> vFullReport = new Vector<>();
vFullReport.add(new Report(5620, Report.PUBLIC));

Roll roll = Compute.rollD6(1);

if (roll.getIntValue() > 0) {
Roll rollNumber = Compute.rollD6(1);
int numberOfStrikes = Math.max(1, rollNumber.getIntValue() / 2);
Roll rollType = Compute.rollD6(1);
int damage;
switch (rollType.getIntValue()) {
case 1:
case 2:
case 3:
damage = 5;
break;
case 4:
case 5:
damage = 10;
break;
default:
damage = 15;
}

for (int i = 0; i < numberOfStrikes; i++) {
int x = Compute.randomInt(game.getBoard().getWidth());
int y = Compute.randomInt(game.getBoard().getHeight());
Coords location = new Coords(x, y);

lightningStormDamage(location, damage, false, vFullReport);
Fixed Show fixed Hide fixed

Fixed Show fixed Hide fixed
if (rollType.getIntValue() == 6) {
for (Coords locationAdjacent : location.allAdjacent()) {
if (game.getBoard().getHex(locationAdjacent) != null) {
Fixed Show fixed Hide fixed
lightningStormDamage(locationAdjacent, 5, true, vFullReport);
}
}
}
Fixed Show fixed Hide fixed
}
}

Report.addNewline(vPhaseReport);
return vFullReport;
}

private void lightningStormDamage(Coords location, int damage, boolean adjacent, Vector<Report> vFullReport) {
List<Entity> hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList());
Report r;
if (!adjacent) {
r = new Report(5621);
} else {
r = new Report(5622);
}
r.add(location.getBoardNum());
vFullReport.add(r);

for (Entity entity : hitEntities) {
ToHitData toHit = new ToHitData();
toHit.setSideTable(ToHitData.SIDE_RANDOM);
HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, toHit.getSideTable());
vFullReport.addAll(damageEntity(entity, hit, damage));
}
}

/**
* Check to see if blowing sand caused damage to airborne VTOL/WIGEs
*/
Expand Down
Loading