Skip to content

Commit

Permalink
Merge pull request #3991 from pheonixstorm/BUG-3727-MAGMA
Browse files Browse the repository at this point in the history
Fixes #3727 Magma crust breakthrough and liquid magma damage not working as expected
  • Loading branch information
Windchild292 authored Nov 28, 2022
2 parents 266b74e + 84155d5 commit c9ca0e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions megamek/i18n/megamek/common/report-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
2395=<newline><data> (<data>) breaks through magma crust on a 6+, rolls <data>.
2396=<newline><data> (<data>) breaks through magma crust on a 4+, rolls <data>.
2400=<data> (<data>) falls into liquid magma, and is instantly destroyed!
2404=<data> (<data>) takes additional damage from beginning and ending movement in a magma hex!
2405=<data> (<data>) is damaged by the extreme heat of liquid magma!
2410=<data> (<data>) breaks through ice from below
2415=<data> collapes due to nuclear explosion ground zero.
Expand Down
23 changes: 22 additions & 1 deletion megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4917,6 +4917,7 @@ else if ((target instanceof Infantry) && (bldg != null)) {
// note that this must sequentially occur before the next 'entering liquid magma' check
// otherwise, magma crust won't have a chance to break
ServerHelper.checkAndApplyMagmaCrust(nextHex, nextElevation, entity, curPos, false, vPhaseReport, this);
ServerHelper.checkEnteringMagma(nextHex, nextElevation, entity, this);

// is the next hex a swamp?
PilotingRollData rollTarget = entity.checkBogDown(step, moveType, nextHex, curPos, nextPos,
Expand Down Expand Up @@ -5919,6 +5920,7 @@ private void processMovement(Entity entity, MovePath md, Map<EntityTargetPair,
// okay, proceed with movement calculations
Coords lastPos = entity.getPosition();
Coords curPos = entity.getPosition();
Hex firstHex = game.getBoard().getHex(curPos); // Used to check for start/end magma damage
int curFacing = entity.getFacing();
int curVTOLElevation = entity.getElevation();
int curElevation;
Expand Down Expand Up @@ -6125,6 +6127,10 @@ private void processMovement(Entity entity, MovePath md, Map<EntityTargetPair,
break;
}

// Extra damage if first and last hex are magma
if (firstStep) {
firstHex = game.getBoard().getHex(curPos);
}
// stop if the entity already killed itself
if (entity.isDestroyed() || entity.isDoomed()) {
break;
Expand Down Expand Up @@ -7289,7 +7295,20 @@ private void processMovement(Entity entity, MovePath md, Map<EntityTargetPair,

// check for breaking magma crust unless we are jumping over the hex
if (stepMoveType != EntityMovementType.MOVE_JUMP) {
ServerHelper.checkAndApplyMagmaCrust(curHex, step.getElevation(), entity, curPos, false, vPhaseReport, this);
if (!curPos.equals(lastPos)) {
ServerHelper.checkAndApplyMagmaCrust(curHex, step.getElevation(), entity, curPos, false, vPhaseReport, this);
ServerHelper.checkEnteringMagma(curHex, step.getElevation(), entity, this);
}
}

// check for last move ending in magma TODO: build report for end of move
if (!i.hasMoreElements() && curHex.terrainLevel(Terrains.MAGMA) == 2
&& firstHex.terrainLevel(Terrains.MAGMA) == 2) {
r = new Report(2404);
r.addDesc(entity);
r.subject = entity.getId();
addReport(r);
doMagmaDamage(entity, false);
}

// check if we've moved into a swamp
Expand Down Expand Up @@ -8427,6 +8446,7 @@ else if ((step.getElevation() + entity.height()) == 0) {
// Don't interact with terrain when jumping onto a building or a bridge
if (entity.getElevation() == 0) {
ServerHelper.checkAndApplyMagmaCrust(curHex, entity.getElevation(), entity, curPos, true, vPhaseReport, this);
ServerHelper.checkEnteringMagma(curHex, entity.getElevation(), entity, this);

// jumped into swamp? maybe stuck!
if (curHex.getBogDownModifier(entity.getMovementMode(),
Expand Down Expand Up @@ -12048,6 +12068,7 @@ private Vector<Report> doEntityDisplacement(Entity entity, Coords src,
}

ServerHelper.checkAndApplyMagmaCrust(destHex, entity.getElevation(), entity, dest, false, vPhaseReport, this);
ServerHelper.checkEnteringMagma(destHex, entity.getElevation(), entity, this);

Entity violation = Compute.stackingViolation(game, entity.getId(), dest);
if (violation == null) {
Expand Down
14 changes: 13 additions & 1 deletion megamek/src/megamek/server/ServerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,24 @@ public static void checkAndApplyMagmaCrust(Hex hex, int elevation, Entity entity
hex.addTerrain(new Terrain(Terrains.MAGMA, 2));
gameManager.sendChangedHex(curPos);
for (Entity en : entity.getGame().getEntitiesVector(curPos)) {
gameManager.doMagmaDamage(en, false);
if (en != entity) {
gameManager.doMagmaDamage(en, false);
}
}
}
}
}

/**
* Check for movement into magma hex and apply damage.
*/
public static void checkEnteringMagma(Hex hex, int elevation, Entity entity, GameManager gameManager) {

if ((hex.terrainLevel(Terrains.MAGMA) == 2) && (elevation == 0) && (entity.getMovementMode() != EntityMovementMode.HOVER)) {
gameManager.doMagmaDamage(entity, false);
}
}

/**
* Loops through all active entities in the game and performs mine detection
*/
Expand Down

0 comments on commit c9ca0e9

Please sign in to comment.