From f97511460211a71abed39b3f1ccde35dd6cea356 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Fri, 29 Nov 2024 12:00:07 -0500 Subject: [PATCH] code cleanup --- .../server/totalwarfare/TWGameManager.java | 81 ++++++++----------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 01d70a94f0..408780f7c5 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -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 * @@ -5345,31 +5373,8 @@ public Vector 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()); @@ -8676,29 +8681,7 @@ Vector 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)); @@ -8706,7 +8689,7 @@ Vector doEntityDisplacement(Entity entity, Coords src, 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. }