Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Nov 29, 2024
1 parent a716ab2 commit f975114
Showing 1 changed file with 32 additions and 49 deletions.
81 changes: 32 additions & 49 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5321,6 +5321,34 @@ private OffBoardDirection calculateEdge(Coords coords) {
return fleeDirection;
}

private String setRetreatEdge(Entity entity, OffBoardDirection fleeDirection) {
String result;

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

return result;
}

/**
* Process any flee movement actions, including flying off the map
*
Expand All @@ -5345,31 +5373,8 @@ public Vector<Report> processLeaveMap(MovePath movePath, boolean flewOff, int re
r.addDesc(entity);

OffBoardDirection fleeDirection = calculateEdge(movePath.getFinalCoords());
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";
}

r.add(fleeDir);
String retreatEdge = setRetreatEdge(entity, fleeDirection);
r.add(retreatEdge);
addReport(r);

entityUpdate(entity.getId());
Expand Down Expand Up @@ -8676,37 +8681,15 @@ Vector<Report> doEntityDisplacement(Entity entity, Coords src,
}

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";
}
String retreatEdge = setRetreatEdge(entity, fleeDirection);

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);
r.add(retreatEdge);
vPhaseReport.add(r);
// TODO : remove passengers and swarmers.
}
Expand Down

0 comments on commit f975114

Please sign in to comment.