From d098aef4946f599041312835a0796a12d2086482 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 29 Apr 2024 17:41:55 -0400 Subject: [PATCH 01/18] update effects for lightning storm --- .../common/actions/WeaponAttackAction.java | 2 +- .../PlanetaryConditions.java | 8 +++--- .../common/planetaryconditions/Weather.java | 25 +++++++++++++------ .../megamek/common/util/BoardUtilities.java | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 55ab4e4ba9..4b31551ad4 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -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")); } } diff --git a/megamek/src/megamek/common/planetaryconditions/PlanetaryConditions.java b/megamek/src/megamek/common/planetaryconditions/PlanetaryConditions.java index 32bb38322d..6695dd8edf 100644 --- a/megamek/src/megamek/common/planetaryconditions/PlanetaryConditions.java +++ b/megamek/src/megamek/common/planetaryconditions/PlanetaryConditions.java @@ -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; @@ -402,7 +402,7 @@ && getWind().isStrongerThan(Wind.STORM)) { public int getIgniteModifiers() { int mod = 0; - if (getWeather().isLightRainOrModerateRain() ) { + if (getWeather().isLightRainOrModerateRainOrLightningStorm() ) { mod += 1; } @@ -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: @@ -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) { @@ -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; diff --git a/megamek/src/megamek/common/planetaryconditions/Weather.java b/megamek/src/megamek/common/planetaryconditions/Weather.java index 29fc1f3464..3bf98461ff 100644 --- a/megamek/src/megamek/common/planetaryconditions/Weather.java +++ b/megamek/src/megamek/common/planetaryconditions/Weather.java @@ -141,9 +141,10 @@ public boolean isHeavyRainOrGustingRain() { } - public boolean isLightRainOrModerateRain() { + public boolean isLightRainOrModerateRainOrLightningStorm() { return isLightRain() - || isModerateRain(); + || isModerateRain() + || isLightningStorm(); } public boolean isModerateSnowOrSnowFlurries() { @@ -151,9 +152,15 @@ public boolean isModerateSnowOrSnowFlurries() { || isSnowFlurries(); } - public boolean isModerateRainOrModerateSnow() { + public boolean isModerateRainOrLightningStorm() { return isModerateRain() - || isModerateSnow(); + || isLightningStorm(); + } + + public boolean isModerateRainOrModerateSnowOrLightningStorm() { + return isModerateRain() + || isModerateSnow() + || isLightningStorm(); } public boolean isDownpourOrHeavySnowOrIceStorm() { @@ -218,11 +225,12 @@ public boolean isModerateSnowOrHeavySnowOrSnowFlurriesOrSleet() { || isSleet(); } - public boolean isModerateRainOrHeavyRainOrGustingRainOrDownpour() { + public boolean isModerateRainOrHeavyRainOrGustingRainOrDownpourOrLightningStorm() { return isModerateRain() || isHeavyRain() || isGustingRain() - || isDownpour(); + || isDownpour() + || isLightningStorm(); } public boolean isGustingRainOrSnowFlurriesOrIceStormOrLightningStorm() { @@ -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) { diff --git a/megamek/src/megamek/common/util/BoardUtilities.java b/megamek/src/megamek/common/util/BoardUtilities.java index 3e476e499c..97fa7032f9 100644 --- a/megamek/src/megamek/common/util/BoardUtilities.java +++ b/megamek/src/megamek/common/util/BoardUtilities.java @@ -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)) { From 84e47f7fd0b213f544be3818f1bdb62b5150fcbf Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 29 Apr 2024 19:53:18 -0400 Subject: [PATCH 02/18] resolve lightning storm damage --- .../megamek/common/report-messages.properties | 3 +- megamek/src/megamek/server/GameManager.java | 83 ++++++++++++++++++- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index 6a9c54306b..20c9625dc9 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -748,7 +748,8 @@ 5606=player must choose bombs to be destroyed. 5607=bot loses bombs. 5608= () Internal Bomb Bay + Cargo critical: Damage exceeds remaining bombs; all bombs destroyed. - +5620=Damage from lightning storm------------------- +5621=lightning strike in hex #6000's -- Damage Related 6005=\ no effect. 6006=\ damage threshold not exceeded, diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 4927c3cb74..1edc8fc2c1 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -1997,10 +1997,7 @@ public boolean accept(Entity entity) { resetEntityPhase(phase); clearReports(); resolveHeat(); - PlanetaryConditions conditions = game.getPlanetaryConditions(); - if (conditions.isBlowingSandActive()) { - addReport(resolveBlowingSandDamage()); - } + resolveWeather(); addReport(resolveControlRolls()); addReport(checkForTraitors()); // write End Phase header @@ -18720,6 +18717,16 @@ private PilotingRollData getKickPushPSR(Entity psrEntity, Entity attacker, 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. @@ -34701,6 +34708,74 @@ public List getSmokeCloudList() { return game.getSmokeCloudList(); } + private Vector resolveLightningStormDamage() { + Vector 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; + boolean adjacent; + switch (rollType.getIntValue()) { + case 1: + case 2: + case 3: + damage = 5; + adjacent = false; + break; + case 4: + case 5: + damage = 10; + adjacent = false; + break; + default: + damage = 15; + adjacent = true; + } + + 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); + + if (adjacent) { + for (Coords locationAdjacent : location.allAdjacent()) { + if (game.getBoard().getHex(locationAdjacent) != null) { + lightningStormDamage(locationAdjacent, 5, adjacent, vFullReport); + } + } + } + } + } + + Report.addNewline(vPhaseReport); + return vFullReport; + } + + private void lightningStormDamage(Coords location, int damage, boolean adjacent, Vector vFullReport) { + List hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList()); + + String adj = adjacent ? "adjacent " : ""; + + Report r = new Report(5621); + r.add(adj); + 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 */ From cc6ec55ab9c3b8e81873a38fe54e75749a80ba67 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 29 Apr 2024 19:58:32 -0400 Subject: [PATCH 03/18] fix test condition --- megamek/i18n/megamek/common/report-messages.properties | 1 + megamek/src/megamek/server/GameManager.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index 20c9625dc9..a88d4fa764 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -750,6 +750,7 @@ 5608= () Internal Bomb Bay + Cargo critical: Damage exceeds remaining bombs; all bombs destroyed. 5620=Damage from lightning storm------------------- 5621=lightning strike in hex + #6000's -- Damage Related 6005=\ no effect. 6006=\ damage threshold not exceeded, diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 1edc8fc2c1..e85207eff9 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34714,7 +34714,7 @@ private Vector resolveLightningStormDamage() { Roll roll = Compute.rollD6(1); - if (roll.getIntValue() > 0) { + if (roll.getIntValue() > 4) { Roll rollNumber = Compute.rollD6(1); int numberOfStrikes = Math.max(1, rollNumber.getIntValue() / 2); Roll rollType = Compute.rollD6(1); From 3c4636ad6c4ae718ceb5a62e42c645b4108151ba Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 29 Apr 2024 20:39:39 -0400 Subject: [PATCH 04/18] code cleanup --- megamek/src/megamek/server/GameManager.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index e85207eff9..1fdb041251 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34719,22 +34719,18 @@ private Vector resolveLightningStormDamage() { int numberOfStrikes = Math.max(1, rollNumber.getIntValue() / 2); Roll rollType = Compute.rollD6(1); int damage; - boolean adjacent; switch (rollType.getIntValue()) { case 1: case 2: case 3: damage = 5; - adjacent = false; break; case 4: case 5: damage = 10; - adjacent = false; break; default: damage = 15; - adjacent = true; } for (int i = 0; i < numberOfStrikes; i++) { @@ -34742,12 +34738,12 @@ private Vector resolveLightningStormDamage() { int y = Compute.randomInt(game.getBoard().getHeight()); Coords location = new Coords(x, y); - lightningStormDamage(location, damage, false, vFullReport); + lightningStormDamage(location, damage, "", vFullReport); - if (adjacent) { + if (rollType.getIntValue() == 6) { for (Coords locationAdjacent : location.allAdjacent()) { if (game.getBoard().getHex(locationAdjacent) != null) { - lightningStormDamage(locationAdjacent, 5, adjacent, vFullReport); + lightningStormDamage(locationAdjacent, 5, "adjacent ", vFullReport); } } } @@ -34758,13 +34754,11 @@ private Vector resolveLightningStormDamage() { return vFullReport; } - private void lightningStormDamage(Coords location, int damage, boolean adjacent, Vector vFullReport) { + private void lightningStormDamage(Coords location, int damage, String adjacent, Vector vFullReport) { List hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList()); - String adj = adjacent ? "adjacent " : ""; - Report r = new Report(5621); - r.add(adj); + r.add(adjacent); r.add(location.getBoardNum()); vFullReport.add(r); From 9f30c4d59564508cdefab2c9b499d8b70f644a95 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 29 Apr 2024 21:01:29 -0400 Subject: [PATCH 05/18] fix report text --- .../megamek/common/report-messages.properties | 3 ++- megamek/src/megamek/server/GameManager.java | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index a88d4fa764..1b72369871 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -749,7 +749,8 @@ 5607=bot loses bombs. 5608= () Internal Bomb Bay + Cargo critical: Damage exceeds remaining bombs; all bombs destroyed. 5620=Damage from lightning storm------------------- -5621=lightning strike in hex +5621=lightning strike in hex +5622= and adjacent hex #6000's -- Damage Related 6005=\ no effect. diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 1fdb041251..4fc0aaf8d0 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34714,7 +34714,7 @@ private Vector resolveLightningStormDamage() { Roll roll = Compute.rollD6(1); - if (roll.getIntValue() > 4) { + if (roll.getIntValue() > 0) { Roll rollNumber = Compute.rollD6(1); int numberOfStrikes = Math.max(1, rollNumber.getIntValue() / 2); Roll rollType = Compute.rollD6(1); @@ -34738,12 +34738,12 @@ private Vector resolveLightningStormDamage() { int y = Compute.randomInt(game.getBoard().getHeight()); Coords location = new Coords(x, y); - lightningStormDamage(location, damage, "", vFullReport); + lightningStormDamage(location, damage, false, vFullReport); if (rollType.getIntValue() == 6) { for (Coords locationAdjacent : location.allAdjacent()) { if (game.getBoard().getHex(locationAdjacent) != null) { - lightningStormDamage(locationAdjacent, 5, "adjacent ", vFullReport); + lightningStormDamage(locationAdjacent, 5, true, vFullReport); } } } @@ -34754,11 +34754,14 @@ private Vector resolveLightningStormDamage() { return vFullReport; } - private void lightningStormDamage(Coords location, int damage, String adjacent, Vector vFullReport) { + private void lightningStormDamage(Coords location, int damage, boolean adjacent, Vector vFullReport) { List hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList()); - - Report r = new Report(5621); - r.add(adjacent); + Report r; + if (!adjacent) { + r = new Report(5621); + } else { + r = new Report(5622); + } r.add(location.getBoardNum()); vFullReport.add(r); From fde0bb48f607b3a1ccfd72df39f1192d72c71013 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Tue, 30 Apr 2024 18:08:59 -0400 Subject: [PATCH 06/18] roll type for each strike --- megamek/src/megamek/server/GameManager.java | 37 ++++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 4fc0aaf8d0..1cc6985192 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34708,32 +34708,37 @@ public List getSmokeCloudList() { return game.getSmokeCloudList(); } + /** + * Check to see if Lightning Storm caused damage + * TO:AR 6th ed. p. 57 + * */ private Vector resolveLightningStormDamage() { Vector vFullReport = new Vector<>(); vFullReport.add(new Report(5620, Report.PUBLIC)); Roll roll = Compute.rollD6(1); - if (roll.getIntValue() > 0) { + if (roll.getIntValue() > 4) { 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++) { + 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; + } + int x = Compute.randomInt(game.getBoard().getWidth()); int y = Compute.randomInt(game.getBoard().getHeight()); Coords location = new Coords(x, y); From 3deff779268c14f730287fceb58c665bb40586ea Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 1 May 2024 18:06:30 -0400 Subject: [PATCH 07/18] add clear terrain and building damage --- megamek/src/megamek/common/Building.java | 16 ++++++ megamek/src/megamek/common/Entity.java | 26 ++++++++++ megamek/src/megamek/server/GameManager.java | 54 ++++++++++++++------- 3 files changed, 78 insertions(+), 18 deletions(-) diff --git a/megamek/src/megamek/common/Building.java b/megamek/src/megamek/common/Building.java index a09bcfe840..5af2fbfb67 100644 --- a/megamek/src/megamek/common/Building.java +++ b/megamek/src/megamek/common/Building.java @@ -750,6 +750,22 @@ public int getAbsorbtion(Coords pos) { return (int) Math.ceil(getPhaseCF(pos) / 10.0); } + /** + * calculates damage absorbed and scaled by building at coords + * @param damage + * @param coords + * @return + */ + public int getAbosrbedDamage(int damage, Coords coords) { + int bldgAbsorbs = getAbsorbtion(coords); + if (bldgAbsorbs > 0) { + damage -= bldgAbsorbs; + } + // some buildings scale remaining damage that is not absorbed + // TODO : this isn't quite right for castles brian + return (int) Math.floor(getDamageToScale() * damage); + } + /** * Returns the percentage of damage done to the building for attacks against * infantry in the building from other units within the building. TW pg175. diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 6817760e25..70f147084a 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -1936,6 +1936,32 @@ public Coords getPosition() { return position; } + /** + * Returns hex for given location + * @return + */ + public Hex getHex(Coords coords) { + return game.getBoard().getHex(coords); + } + + /** + * Returns hex for current position + * @return + */ + public Hex getHex() { + return getHex(getPosition()); + } + + /** + * checks if entity is inside building in current hex + * @return + */ + public boolean isInsideBuilding() { + return (getHex().containsTerrain(Terrains.BUILDING) + && getElevation() < getHex().terrainLevel(Terrains.BLDG_ELEV)) + && !isAirborne(); + } + /** * Returns a set of the coords this Entity occupies * diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 1cc6985192..f9b4db4cc1 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34714,11 +34714,11 @@ public List getSmokeCloudList() { * */ private Vector resolveLightningStormDamage() { Vector vFullReport = new Vector<>(); - vFullReport.add(new Report(5620, Report.PUBLIC)); - Roll roll = Compute.rollD6(1); - if (roll.getIntValue() > 4) { + if (roll.getIntValue() > 0) { + vFullReport.add(new Report(5620, Report.PUBLIC)); + Roll rollNumber = Compute.rollD6(1); int numberOfStrikes = Math.max(1, rollNumber.getIntValue() / 2); @@ -34743,12 +34743,21 @@ private Vector resolveLightningStormDamage() { int y = Compute.randomInt(game.getBoard().getHeight()); Coords location = new Coords(x, y); - lightningStormDamage(location, damage, false, vFullReport); + Report r; + r = new Report(5621); + r.add(location.getBoardNum()); + vFullReport.add(r); + + lightningStormDamage(location, damage, vFullReport); if (rollType.getIntValue() == 6) { for (Coords locationAdjacent : location.allAdjacent()) { if (game.getBoard().getHex(locationAdjacent) != null) { - lightningStormDamage(locationAdjacent, 5, true, vFullReport); + r = new Report(5622); + r.add(locationAdjacent.getBoardNum()); + vFullReport.add(r); + + lightningStormDamage(locationAdjacent, 5, vFullReport); } } } @@ -34759,22 +34768,31 @@ private Vector resolveLightningStormDamage() { return vFullReport; } - private void lightningStormDamage(Coords location, int damage, boolean adjacent, Vector vFullReport) { - List 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); + private void lightningStormDamage(Coords location, int damage, Vector vFullReport) { + Vector newReports = tryClearHex(location, damage, Entity.NONE); + vFullReport.addAll(newReports); + + Building bldg = game.getBoard().getBuildingAt(location); + if (bldg != null) { + Vector buildingReport = damageBuilding(bldg, damage, location); + vFullReport.addAll(buildingReport); } - r.add(location.getBoardNum()); - vFullReport.add(r); + + List hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList()); 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)); + int entityDamage = damage; + if ((bldg != null) + && (entity.isInsideBuilding())) { + entityDamage = bldg.getAbosrbedDamage(entityDamage, location); + } + if (entityDamage > 0) { + ToHitData toHit = new ToHitData(); + toHit.setSideTable(ToHitData.SIDE_RANDOM); + HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, toHit.getSideTable()); + Vector entityReport = damageEntity(entity, hit, entityDamage); + vFullReport.addAll(entityReport); + } } } From f594d7d530d4d429bc6d01bdc2414909d5901384 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 1 May 2024 20:01:46 -0400 Subject: [PATCH 08/18] filter gun emplacements --- megamek/src/megamek/server/GameManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index f9b4db4cc1..6d77e38794 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34778,7 +34778,10 @@ private void lightningStormDamage(Coords location, int damage, Vector vF vFullReport.addAll(buildingReport); } - List hitEntities = game.getEntitiesVector().stream().filter(e -> e.getPosition().equals(location)).collect(Collectors.toList()); + List hitEntities = game.getEntitiesVector().stream() + .filter(e -> e.getPosition().equals(location) + && !(e instanceof GunEmplacement)) + .collect(Collectors.toList()); for (Entity entity : hitEntities) { int entityDamage = damage; From d2f7b8bd10dce1220cdf63b56c1b7befbbf72226 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 2 May 2024 17:50:53 -0400 Subject: [PATCH 09/18] use Compute.isInBuilding --- megamek/src/megamek/common/Entity.java | 26 --------------------- megamek/src/megamek/server/GameManager.java | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 70f147084a..6817760e25 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -1936,32 +1936,6 @@ public Coords getPosition() { return position; } - /** - * Returns hex for given location - * @return - */ - public Hex getHex(Coords coords) { - return game.getBoard().getHex(coords); - } - - /** - * Returns hex for current position - * @return - */ - public Hex getHex() { - return getHex(getPosition()); - } - - /** - * checks if entity is inside building in current hex - * @return - */ - public boolean isInsideBuilding() { - return (getHex().containsTerrain(Terrains.BUILDING) - && getElevation() < getHex().terrainLevel(Terrains.BLDG_ELEV)) - && !isAirborne(); - } - /** * Returns a set of the coords this Entity occupies * diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 6d77e38794..d8f8bd42a8 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34786,7 +34786,7 @@ private void lightningStormDamage(Coords location, int damage, Vector vF for (Entity entity : hitEntities) { int entityDamage = damage; if ((bldg != null) - && (entity.isInsideBuilding())) { + && (Compute.isInBuilding(game, entity))) { entityDamage = bldg.getAbosrbedDamage(entityDamage, location); } if (entityDamage > 0) { From c1d4ddc57f6c6ca26dc730ae55d708fb5c05b1c1 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 2 May 2024 18:57:29 -0400 Subject: [PATCH 10/18] add option to target units --- .../common/options/messages.properties | 2 ++ .../megamek/common/options/GameOptions.java | 1 + .../common/options/OptionsConstants.java | 1 + megamek/src/megamek/server/GameManager.java | 34 ++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/megamek/i18n/megamek/common/options/messages.properties b/megamek/i18n/megamek/common/options/messages.properties index ef21cb51fd..d9a186e80f 100644 --- a/megamek/i18n/megamek/common/options/messages.properties +++ b/megamek/i18n/megamek/common/options/messages.properties @@ -149,6 +149,8 @@ GameOptionsInfo.option.hidden_units.displayableName=Hidden Units GameOptionsInfo.option.hidden_units.description=If checked, players may deploy units hidden. GameOptionsInfo.option.black_ice.displayableName=Black Ice GameOptionsInfo.option.black_ice.description=If checked, Black Ice may form on pavement if temperatures are below -30C. TO:AR p38\nDoes not affect Black Ice forming due to Ice Storms. TO:AR p58 +GameOptionsInfo.option.lightning_storm_targets_units.displayableName=Lightning Storm targets units +GameOptionsInfo.option.lightning_storm_targets_units.description=If unchecked, targets random hex on the board GameOptionsInfo.option.double_blind.displayableName=TacOps Double blind GameOptionsInfo.option.single_blind_bots.displayableName=(Unofficial) Default bots to single blind, when using TacOps Double blind GameOptionsInfo.option.double_blind.description=If checked, enemy units will only be visible if they are in line of sight of one or more of your units, or within sensor range. \nUnchecked by default. diff --git a/megamek/src/megamek/common/options/GameOptions.java b/megamek/src/megamek/common/options/GameOptions.java index ff564c32b5..b0de6cfad0 100755 --- a/megamek/src/megamek/common/options/GameOptions.java +++ b/megamek/src/megamek/common/options/GameOptions.java @@ -118,6 +118,7 @@ public synchronized void initialize() { addOption(advancedRules, OptionsConstants.ADVANCED_MINEFIELDS, false); addOption(advancedRules, OptionsConstants.ADVANCED_HIDDEN_UNITS, true); addOption(advancedRules, OptionsConstants.ADVANCED_BLACK_ICE, false); + addOption(advancedRules, OptionsConstants.ADVANCED_LIGHTNING_STORM_TARGETS_UNITS, false); addOption(advancedRules, OptionsConstants.ADVANCED_DOUBLE_BLIND, false); addOption(advancedRules, OptionsConstants.ADVANCED_TACOPS_SENSORS, false); addOption(advancedRules, OptionsConstants.ADVANCED_SUPRESS_ALL_DB_MESSAGES, false); diff --git a/megamek/src/megamek/common/options/OptionsConstants.java b/megamek/src/megamek/common/options/OptionsConstants.java index afe61059a8..5071775233 100644 --- a/megamek/src/megamek/common/options/OptionsConstants.java +++ b/megamek/src/megamek/common/options/OptionsConstants.java @@ -332,6 +332,7 @@ public class OptionsConstants { public static final String ADVANCED_MINEFIELDS = "minefields"; public static final String ADVANCED_HIDDEN_UNITS = "hidden_units"; public static final String ADVANCED_BLACK_ICE= "black_ice"; + public static final String ADVANCED_LIGHTNING_STORM_TARGETS_UNITS= "lightning_storm_targets_units"; public static final String ADVANCED_DOUBLE_BLIND = "double_blind"; public static final String ADVANCED_SINGLE_BLIND_BOTS = "single_blind_bots"; public static final String ADVANCED_TACOPS_SENSORS = "tacops_sensors"; diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index d8f8bd42a8..e35ef20839 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -34717,6 +34717,7 @@ private Vector resolveLightningStormDamage() { Roll roll = Compute.rollD6(1); if (roll.getIntValue() > 0) { + Report.addNewline(vFullReport); vFullReport.add(new Report(5620, Report.PUBLIC)); Roll rollNumber = Compute.rollD6(1); @@ -34739,19 +34740,27 @@ private Vector resolveLightningStormDamage() { damage = 15; } - int x = Compute.randomInt(game.getBoard().getWidth()); - int y = Compute.randomInt(game.getBoard().getHeight()); - Coords location = new Coords(x, y); + Coords coords; + + if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_LIGHTNING_STORM_TARGETS_UNITS)) { + List entities = game.getEntitiesVector(); + int index = Compute.randomInt(entities.size()); + coords = entities.get(index).getPosition(); + } else { + int x = Compute.randomInt(game.getBoard().getWidth()); + int y = Compute.randomInt(game.getBoard().getHeight()); + coords = new Coords(x, y); + } Report r; r = new Report(5621); - r.add(location.getBoardNum()); + r.add(coords.getBoardNum()); vFullReport.add(r); - lightningStormDamage(location, damage, vFullReport); + lightningStormDamage(coords, damage, vFullReport); if (rollType.getIntValue() == 6) { - for (Coords locationAdjacent : location.allAdjacent()) { + for (Coords locationAdjacent : coords.allAdjacent()) { if (game.getBoard().getHex(locationAdjacent) != null) { r = new Report(5622); r.add(locationAdjacent.getBoardNum()); @@ -34764,22 +34773,21 @@ private Vector resolveLightningStormDamage() { } } - Report.addNewline(vPhaseReport); return vFullReport; } - private void lightningStormDamage(Coords location, int damage, Vector vFullReport) { - Vector newReports = tryClearHex(location, damage, Entity.NONE); + private void lightningStormDamage(Coords coords, int damage, Vector vFullReport) { + Vector newReports = tryClearHex(coords, damage, Entity.NONE); vFullReport.addAll(newReports); - Building bldg = game.getBoard().getBuildingAt(location); + Building bldg = game.getBoard().getBuildingAt(coords); if (bldg != null) { - Vector buildingReport = damageBuilding(bldg, damage, location); + Vector buildingReport = damageBuilding(bldg, damage, coords); vFullReport.addAll(buildingReport); } List hitEntities = game.getEntitiesVector().stream() - .filter(e -> e.getPosition().equals(location) + .filter(e -> e.getPosition().equals(coords) && !(e instanceof GunEmplacement)) .collect(Collectors.toList()); @@ -34787,7 +34795,7 @@ private void lightningStormDamage(Coords location, int damage, Vector vF int entityDamage = damage; if ((bldg != null) && (Compute.isInBuilding(game, entity))) { - entityDamage = bldg.getAbosrbedDamage(entityDamage, location); + entityDamage = bldg.getAbosrbedDamage(entityDamage, coords); } if (entityDamage > 0) { ToHitData toHit = new ToHitData(); From f4eb9ba1a13f8f462bd25dba9834fe6e942d4f7b Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 13:20:37 -0400 Subject: [PATCH 11/18] Merge remote-tracking branch 'origin/master' into lightningStorm --- .../server/totalwarfare/TWPhasePreparationManager.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/megamek/src/megamek/server/totalwarfare/TWPhasePreparationManager.java b/megamek/src/megamek/server/totalwarfare/TWPhasePreparationManager.java index 1c57393826..1d31708f8e 100644 --- a/megamek/src/megamek/server/totalwarfare/TWPhasePreparationManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWPhasePreparationManager.java @@ -178,10 +178,7 @@ void managePhase() { gameManager.resetEntityPhase(phase); gameManager.clearReports(); gameManager.resolveHeat(); - PlanetaryConditions conditions = gameManager.getGame().getPlanetaryConditions(); - if (conditions.isBlowingSandActive()) { - gameManager.addReport(gameManager.resolveBlowingSandDamage()); - } + gameManager.resolveWeather(); gameManager.addReport(gameManager.resolveControlRolls()); gameManager.addReport(gameManager.checkForTraitors()); // write End Phase header From 7ea1a082e8a747155467405cd239461fd11c0c56 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 13:30:22 -0400 Subject: [PATCH 12/18] remove absorb logic --- megamek/src/megamek/common/Building.java | 16 ---------------- .../server/totalwarfare/TWGameManager.java | 5 +---- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/megamek/src/megamek/common/Building.java b/megamek/src/megamek/common/Building.java index 3cf4451614..79c19ea8c2 100644 --- a/megamek/src/megamek/common/Building.java +++ b/megamek/src/megamek/common/Building.java @@ -779,22 +779,6 @@ public int getAbsorbtion(Coords pos) { return (int) Math.ceil(getPhaseCF(pos) / 10.0); } - /** - * calculates damage absorbed and scaled by building at coords - * @param damage - * @param coords - * @return - */ - public int getAbosrbedDamage(int damage, Coords coords) { - int bldgAbsorbs = getAbsorbtion(coords); - if (bldgAbsorbs > 0) { - damage -= bldgAbsorbs; - } - // some buildings scale remaining damage that is not absorbed - // TODO : this isn't quite right for castles brian - return (int) Math.floor(getDamageToScale() * damage); - } - /** * Returns the percentage of damage done to the building for attacks against * infantry in the building from other units within the building. TW pg175. diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index f17f3b07c2..56cba677ba 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -31348,10 +31348,7 @@ private void lightningStormDamage(Coords coords, int damage, Vector vFul for (Entity entity : hitEntities) { int entityDamage = damage; - if ((bldg != null) - && (Compute.isInBuilding(game, entity))) { - entityDamage = bldg.getAbosrbedDamage(entityDamage, coords); - } + if (entityDamage > 0) { ToHitData toHit = new ToHitData(); toHit.setSideTable(ToHitData.SIDE_RANDOM); From 4ca83fe0633181d7b7265e147cb2e42f5b2bd352 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 14:03:52 -0400 Subject: [PATCH 13/18] update ejection modifier --- .../src/megamek/common/planetaryconditions/Weather.java | 5 +++-- megamek/src/megamek/server/totalwarfare/TWGameManager.java | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/common/planetaryconditions/Weather.java b/megamek/src/megamek/common/planetaryconditions/Weather.java index 970d982955..7036aa7084 100644 --- a/megamek/src/megamek/common/planetaryconditions/Weather.java +++ b/megamek/src/megamek/common/planetaryconditions/Weather.java @@ -165,10 +165,11 @@ public boolean isModerateRainOrModerateSnowOrLightningStorm() { || isLightningStorm(); } - public boolean isDownpourOrHeavySnowOrIceStorm() { + public boolean isDownpourOrHeavySnowOrIceStormOrLightningStorm() { return isDownpour() || isHeavySnow() - || isIceStorm(); + || isIceStorm() + || isLightningStorm(); } public boolean isSnowFlurriesOrSleetOrIceStorm() { diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 56cba677ba..a238374cc6 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -29714,6 +29714,7 @@ public static PilotingRollData getEjectModifiers(Game game, Entity entity, int c } Hex targetHex = game.getBoard().getHex(targetCoords); // Terrain modifiers should only apply if the unit is on the ground... + // TO:AR 6th ed p165 if (!entity.isSpaceborne() && !entity.isAirborne()) { if (targetHex != null) { if ((targetHex.terrainLevel(Terrains.WATER) > 0) @@ -29751,6 +29752,7 @@ public static PilotingRollData getEjectModifiers(Game game, Entity entity, int c // battle, but it shouldn't // That's a fix for another day, probably when I get around to space terrain and // 'weather' + // TO:AR 6th ed p165 if (conditions.getGravity() == 0) { rollTarget.addModifier(3, "Zero-G"); } else if (conditions.getGravity() < 0.8) { @@ -29762,6 +29764,7 @@ public static PilotingRollData getEjectModifiers(Game game, Entity entity, int c // Vacuum shouldn't apply to ASF ejection since they're designed for it, but the // rules don't specify // High and low pressures make more sense to apply to all + // TO:AR 6th ed p165 if (conditions.getAtmosphere().isVacuum()) { rollTarget.addModifier(3, "Vacuum"); } else if (conditions.getAtmosphere().isVeryHigh()) { @@ -29771,11 +29774,13 @@ public static PilotingRollData getEjectModifiers(Game game, Entity entity, int c } } - if (conditions.getWeather().isDownpourOrHeavySnowOrIceStorm() + // TO:AR 6th ed p165 + if (conditions.getWeather().isDownpourOrHeavySnowOrIceStormOrLightningStorm() || conditions.getWind().isStrongGale()) { rollTarget.addModifier(2, "Bad Weather"); } + // TO:AR 6th ed p165 if (conditions.getWind().isStrongerThan(Wind.STRONG_GALE) || (conditions.getWeather().isHeavySnow() && conditions.getWind().isStrongGale())) { rollTarget.addModifier(3, "Really Bad Weather"); From 325dd2b1e12b31d442a4674d5219b11a58cb246a Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 14:41:41 -0400 Subject: [PATCH 14/18] reduce sensor range --- megamek/src/megamek/common/Sensor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/common/Sensor.java b/megamek/src/megamek/common/Sensor.java index 69084eec96..580b6d555d 100644 --- a/megamek/src/megamek/common/Sensor.java +++ b/megamek/src/megamek/common/Sensor.java @@ -182,10 +182,12 @@ public int adjustRange(int range, Game game, LosEffects los) { if ((type != TYPE_MEK_SEISMIC) && (type != TYPE_VEE_SEISMIC)) { PlanetaryConditions conditions = game.getPlanetaryConditions(); - if (conditions.getEMI().isEMI()) { + if (conditions.isEMI()) { range -= 4; } - // TODO: add lightning + if (conditions.getWeather().isLightningStorm()) { + range -= 1; + } } if ((type == TYPE_MEK_RADAR) || (type == TYPE_VEE_RADAR) From f619424667bc371b6be71dd8e560db6a6e566b84 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 14:57:27 -0400 Subject: [PATCH 15/18] add source --- megamek/src/megamek/common/Sensor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/src/megamek/common/Sensor.java b/megamek/src/megamek/common/Sensor.java index 580b6d555d..69ed8d8e1b 100644 --- a/megamek/src/megamek/common/Sensor.java +++ b/megamek/src/megamek/common/Sensor.java @@ -180,6 +180,7 @@ public int adjustRange(int range, Game game, LosEffects los) { return 0; } + //TO:AR 6th ed. p 190 if ((type != TYPE_MEK_SEISMIC) && (type != TYPE_VEE_SEISMIC)) { PlanetaryConditions conditions = game.getPlanetaryConditions(); if (conditions.isEMI()) { From d16e3803176f1f5b77779d5e85f8723f929b7c8f Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 26 Oct 2024 15:56:37 -0400 Subject: [PATCH 16/18] code cleanup --- .../megamek/server/totalwarfare/TWGameManager.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index a238374cc6..62fec0eac2 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -31352,15 +31352,11 @@ private void lightningStormDamage(Coords coords, int damage, Vector vFul .collect(Collectors.toList()); for (Entity entity : hitEntities) { - int entityDamage = damage; - - if (entityDamage > 0) { - ToHitData toHit = new ToHitData(); - toHit.setSideTable(ToHitData.SIDE_RANDOM); - HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, toHit.getSideTable()); - Vector entityReport = damageEntity(entity, hit, entityDamage); - vFullReport.addAll(entityReport); - } + ToHitData toHit = new ToHitData(); + toHit.setSideTable(ToHitData.SIDE_RANDOM); + HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, toHit.getSideTable()); + Vector entityReport = damageEntity(entity, hit, damage); + vFullReport.addAll(entityReport); } } From 8aa755443f1d2253c30a96d57214c41609a65257 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 28 Oct 2024 18:43:48 -0400 Subject: [PATCH 17/18] correct issues --- .../server/totalwarfare/TWGameManager.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 62fec0eac2..cf288e070c 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -31274,9 +31274,9 @@ public List getSmokeCloudList() { * */ private Vector resolveLightningStormDamage() { Vector vFullReport = new Vector<>(); - Roll roll = Compute.rollD6(1); + Roll rollStrike = Compute.rollD6(1); - if (roll.getIntValue() > 0) { + if (rollStrike.getIntValue() > 4) { Report.addNewline(vFullReport); vFullReport.add(new Report(5620, Report.PUBLIC)); @@ -31303,7 +31303,9 @@ private Vector resolveLightningStormDamage() { Coords coords; if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_LIGHTNING_STORM_TARGETS_UNITS)) { - List entities = game.getEntitiesVector(); + List entities = game.getEntitiesVector().stream() + .filter(e -> e.getPosition() != null) + .toList(); int index = Compute.randomInt(entities.size()); coords = entities.get(index).getPosition(); } else { @@ -31321,13 +31323,11 @@ private Vector resolveLightningStormDamage() { if (rollType.getIntValue() == 6) { for (Coords locationAdjacent : coords.allAdjacent()) { - if (game.getBoard().getHex(locationAdjacent) != null) { - r = new Report(5622); - r.add(locationAdjacent.getBoardNum()); - vFullReport.add(r); + r = new Report(5622); + r.add(locationAdjacent.getBoardNum()); + vFullReport.add(r); - lightningStormDamage(locationAdjacent, 5, vFullReport); - } + lightningStormDamage(locationAdjacent, 5, vFullReport); } } } @@ -31341,15 +31341,16 @@ private void lightningStormDamage(Coords coords, int damage, Vector vFul vFullReport.addAll(newReports); Building bldg = game.getBoard().getBuildingAt(coords); + if (bldg != null) { Vector buildingReport = damageBuilding(bldg, damage, coords); vFullReport.addAll(buildingReport); } List hitEntities = game.getEntitiesVector().stream() - .filter(e -> e.getPosition().equals(coords) - && !(e instanceof GunEmplacement)) - .collect(Collectors.toList()); + .filter(e -> coords.equals(e.getPosition()) + && !(e instanceof GunEmplacement)) + .toList(); for (Entity entity : hitEntities) { ToHitData toHit = new ToHitData(); From 3bd584f8883036b5d82a11ad064af6cc4c8223d2 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 28 Oct 2024 20:21:47 -0400 Subject: [PATCH 18/18] code cleanup --- .../src/megamek/server/totalwarfare/TWGameManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index cf288e070c..bce0f09ebb 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -31319,7 +31319,7 @@ private Vector resolveLightningStormDamage() { r.add(coords.getBoardNum()); vFullReport.add(r); - lightningStormDamage(coords, damage, vFullReport); + vFullReport.addAll(lightningStormDamage(coords, damage)); if (rollType.getIntValue() == 6) { for (Coords locationAdjacent : coords.allAdjacent()) { @@ -31327,7 +31327,7 @@ private Vector resolveLightningStormDamage() { r.add(locationAdjacent.getBoardNum()); vFullReport.add(r); - lightningStormDamage(locationAdjacent, 5, vFullReport); + vFullReport.addAll(lightningStormDamage(locationAdjacent, 5)); } } } @@ -31336,7 +31336,8 @@ private Vector resolveLightningStormDamage() { return vFullReport; } - private void lightningStormDamage(Coords coords, int damage, Vector vFullReport) { + private Vector lightningStormDamage(Coords coords, int damage) { + Vector vFullReport = new Vector<>(); Vector newReports = tryClearHex(coords, damage, Entity.NONE); vFullReport.addAll(newReports); @@ -31359,6 +31360,8 @@ private void lightningStormDamage(Coords coords, int damage, Vector vFul Vector entityReport = damageEntity(entity, hit, damage); vFullReport.addAll(entityReport); } + + return vFullReport; } /**