Skip to content

Commit

Permalink
log edge when forced from field
Browse files Browse the repository at this point in the history
kuronekochomusuke committed Nov 29, 2024
1 parent cd5a88e commit a716ab2
Showing 2 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion megamek/i18n/megamek/common/report-messages.properties
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@
2216=collides!
2217=<<span class='miss'><B>misses</B></span>.
2220=<data> (<data>) takes <data> damage from the collision.
2230=<newline><span class='info'>*** <data> (<data>) has been forced from the field. ***</span>
2230=<newline><span class='info'>*** <data> (<data>) has been forced from the field to the <data>. ***</span>
2235=<data> (<data>) is displaced into hex <data>.
2240=<data> (<data>) is displaced into hex <data>, violating stacking with <data> (<data>).
2245=<data> attempts to clear a(n) <data> mine in hex <data>:
58 changes: 48 additions & 10 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
@@ -5305,6 +5305,22 @@ Vector<Report> processCrash(Entity entity, int vel, Coords c) {
return vReport;
}

private OffBoardDirection calculateEdge(Coords coords) {
OffBoardDirection fleeDirection;

if (coords.getY() <= 0) {
fleeDirection = OffBoardDirection.NORTH;
} else if (coords.getY() >= (getGame().getBoard().getHeight() - 1)) {
fleeDirection = OffBoardDirection.SOUTH;
} else if (coords.getX() <= 0) {
fleeDirection = OffBoardDirection.WEST;
} else {
fleeDirection = OffBoardDirection.EAST;
}

return fleeDirection;
}

/**
* Process any flee movement actions, including flying off the map
*
@@ -5327,18 +5343,10 @@ public Vector<Report> processLeaveMap(MovePath movePath, boolean flewOff, int re
r = new Report(9370, Report.PUBLIC);
}
r.addDesc(entity);
OffBoardDirection fleeDirection;
if (movePath.getFinalCoords().getY() <= 0) {
fleeDirection = OffBoardDirection.NORTH;
} else if (movePath.getFinalCoords().getY() >= (getGame().getBoard().getHeight() - 1)) {
fleeDirection = OffBoardDirection.SOUTH;
} else if (movePath.getFinalCoords().getX() <= 0) {
fleeDirection = OffBoardDirection.WEST;
} else {
fleeDirection = OffBoardDirection.EAST;
}

OffBoardDirection fleeDirection = calculateEdge(movePath.getFinalCoords());
String fleeDir;

switch (fleeDirection) {
case NORTH:
entity.setStartingPos(Board.START_N);
@@ -8652,6 +8660,7 @@ Vector<Report> doEntityDisplacement(Entity entity, Coords src,
Coords dest, PilotingRollData roll) {
Vector<Report> vPhaseReport = new Vector<>();
Report r;

if (!game.getBoard().contains(dest)) {
// set position anyway, for pushes moving through, stuff like that
entity.setPosition(dest);
@@ -8665,12 +8674,39 @@ Vector<Report> doEntityDisplacement(Entity entity, Coords src,
} else if (turnsRemoved > 0) {
send(packetHelper.createTurnListPacket());
}

OffBoardDirection fleeDirection = calculateEdge(src);
String fleeDir;

switch (fleeDirection) {
case NORTH:
entity.setStartingPos(Board.START_N);
fleeDir = "North";
break;
case EAST:
entity.setStartingPos(Board.START_E);
fleeDir = "East";
break;
case SOUTH:
entity.setStartingPos(Board.START_S);
fleeDir = "South";
break;
case WEST:
entity.setStartingPos(Board.START_W);
fleeDir = "West";
break;
default:
entity.setStartingPos(Board.START_EDGE);
fleeDir = "Edge";
}

game.removeEntity(entity.getId(), IEntityRemovalConditions.REMOVE_PUSHED);
send(createRemoveEntityPacket(entity.getId(), IEntityRemovalConditions.REMOVE_PUSHED));
// entity forced from the field
r = new Report(2230);
r.subject = entity.getId();
r.addDesc(entity);
r.add(fleeDir);
vPhaseReport.add(r);
// TODO : remove passengers and swarmers.
}
@@ -8809,6 +8845,7 @@ else if ((waterDepth > 0)
doSkillCheckInPlace(entity, waterRoll);
}
}

// Update the entity's position on the client.
entityUpdate(entity.getId());

@@ -8920,6 +8957,7 @@ else if ((waterDepth > 0)
entityUpdate(violation.getId());
}
}

return vPhaseReport;
}

0 comments on commit a716ab2

Please sign in to comment.