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

Fixes #3727 Magma crust breakthrough and liquid magma damage not working as expected #3991

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -4921,6 +4921,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 @@ -5923,6 +5924,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 @@ -6129,6 +6131,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 @@ -7293,7 +7299,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 @@ -8431,6 +8450,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 @@ -12052,6 +12072,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 @@ -445,12 +445,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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause airborne aerospace units to take magma damage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the code is a near copy of the crust check code at line 431. I also tested it.

gameManager.doMagmaDamage(entity, false);
}
}

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