From ad90f66f332e2ac8de0b8735c506ef6d0cbbc259 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 19:47:52 -0500 Subject: [PATCH 01/12] allow fleeing at end of movement --- .../src/megamek/client/bot/princess/Princess.java | 4 ++-- .../src/megamek/client/ui/swing/MovementDisplay.java | 12 +++++++++--- .../client/ui/swing/TargetingPhaseDisplay.java | 6 +++--- megamek/src/megamek/common/Entity.java | 3 +-- megamek/src/megamek/common/GunEmplacement.java | 2 +- megamek/src/megamek/common/MoveStep.java | 4 ++-- .../megamek/server/totalwarfare/MovePathHandler.java | 11 +++++------ .../megamek/client/bot/princess/PrincessTest.java | 6 +++--- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/megamek/src/megamek/client/bot/princess/Princess.java b/megamek/src/megamek/client/bot/princess/Princess.java index 120a1251aaa..ecc1485a5c4 100644 --- a/megamek/src/megamek/client/bot/princess/Princess.java +++ b/megamek/src/megamek/client/bot/princess/Princess.java @@ -1047,7 +1047,7 @@ protected void calculateTargetingOffBoardTurn() { Entity entityToFire = getGame().getFirstEntity(getMyTurn()); // if we're crippled, off-board and can do so, disengage - if (entityToFire.isOffBoard() && entityToFire.canFlee() && entityToFire.isCrippled(true)) { + if (entityToFire.isOffBoard() && entityToFire.canFlee(entityToFire.getPosition()) && entityToFire.isCrippled(true)) { Vector disengageVector = new Vector<>(); disengageVector.add(new DisengageAction(entityToFire.getId())); sendAttackData(entityToFire.getId(), disengageVector); @@ -2138,7 +2138,7 @@ boolean canShootWhileFallingBack(Entity entity) { boolean mustFleeBoard(final Entity entity) { if (!isFallingBack(entity)) { return false; - } else if (!entity.canFlee()) { + } else if (!entity.canFlee(entity.getPosition())) { return false; } else if (0 < getPathRanker(entity).distanceToHomeEdge(entity.getPosition(), getHomeEdge(entity), getGame())) { diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index 47ef702b5f8..84e63661908 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -853,7 +853,9 @@ private void updateButtons() { (ce instanceof Tank) && (ce.getSwarmAttackerId() != Entity.NONE)); - setFleeEnabled(ce.canFlee()); + boolean fleeStart = ce().canFlee(ce().getPosition()); + boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); + setFleeEnabled(fleeStart || fleeEnd); if (gOpts.booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLES_CAN_EJECT) && (ce instanceof Tank)) { // Vehicle don't have ejection systems so crews abandon, and must enter a valid // hex. @@ -968,6 +970,10 @@ private void updateMove(boolean redrawMovement) { if (redrawMovement) { clientgui.getBoardView().drawMovementData(ce(), cmd); } + + boolean fleeStart = ce().canFlee(ce().getPosition()); + boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); + setFleeEnabled(fleeStart || fleeEnd); updateDonePanel(); } @@ -1966,6 +1972,7 @@ public synchronized void hexMoused(BoardViewEvent b) { // else clear movement clear(); } + return; } // if not valid, tell why @@ -4893,10 +4900,9 @@ public synchronized void actionPerformed(ActionEvent ev) { && clientgui.doYesNoDialog( Messages.getString("MovementDisplay.EscapeDialog.title"), Messages.getString("MovementDisplay.EscapeDialog.message"))) { - - clear(); addStepToMovePath(MoveStepType.FLEE); ready(); + clear(); } else if (actionCmd.equals(MoveCommand.MOVE_FLY_OFF.getCmd()) && clientgui.doYesNoDialog( Messages.getString("MovementDisplay.FlyOffDialog.title"), diff --git a/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java b/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java index 15acb87bbf8..20a9bbd2d9b 100644 --- a/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java +++ b/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java @@ -404,7 +404,7 @@ private void beginMyTurn() { if (GUIP.getAutoSelectNextUnit()) { selectEntity(clientgui.getClient().getFirstEntityNum()); } - setDisengageEnabled((ce() != null) && attacks.isEmpty() && ce().canFlee()); + setDisengageEnabled((ce() != null) && attacks.isEmpty() && ce().canFlee(ce().getPosition())); GameTurn turn = clientgui.getClient().getMyTurn(); // There's special processing for triggering AP Pods. @@ -754,7 +754,7 @@ private void clearAttacks() { // restore any other movement to default ce().setSecondaryFacing(ce().getFacing()); ce().setArmsFlipped(false); - setDisengageEnabled(ce().isOffBoard() && ce().canFlee()); + setDisengageEnabled(ce().isOffBoard() && ce().canFlee(ce().getPosition())); } /** @@ -776,7 +776,7 @@ private void removeLastFiring() { WeaponAttackAction waa = (WeaponAttackAction) o; ce().getEquipment(waa.getWeaponId()).setUsedThisRound(false); removeAttack(o); - setDisengageEnabled(attacks.isEmpty() && ce().isOffBoard() && ce().canFlee()); + setDisengageEnabled(attacks.isEmpty() && ce().isOffBoard() && ce().canFlee(ce().getPosition())); clientgui.getUnitDisplay().wPan.displayMek(ce()); clientgui.getClient().getGame().removeAction(o); clientgui.getBoardView().refreshAttacks(); diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 5a55bd9599a..9ec423ce322 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -9546,8 +9546,7 @@ public short getUnitNumber() { * Returns whether an entity can flee from its current position. Currently * returns true if the entity is on the edge of the board. */ - public boolean canFlee() { - Coords pos = getPosition(); + public boolean canFlee(Coords pos) { return ((getWalkMP() > 0) || (this instanceof Infantry)) && !isProne() && !isStuck() diff --git a/megamek/src/megamek/common/GunEmplacement.java b/megamek/src/megamek/common/GunEmplacement.java index 26b06dce8a0..e35f84948f3 100644 --- a/megamek/src/megamek/common/GunEmplacement.java +++ b/megamek/src/megamek/common/GunEmplacement.java @@ -229,7 +229,7 @@ public boolean canCharge() { } @Override - public boolean canFlee() { + public boolean canFlee(Coords pos) { return false; } diff --git a/megamek/src/megamek/common/MoveStep.java b/megamek/src/megamek/common/MoveStep.java index 8b31155680e..937837f7b15 100644 --- a/megamek/src/megamek/common/MoveStep.java +++ b/megamek/src/megamek/common/MoveStep.java @@ -2214,7 +2214,7 @@ && getClearance() < prev.getClearance()) { // landing } // check to see if it's trying to flee and can legally do so. - if ((type == MoveStepType.FLEE) && entity.canFlee()) { + if ((type == MoveStepType.FLEE) && entity.canFlee(curPos)) { movementType = EntityMovementType.MOVE_LEGAL; } @@ -3365,7 +3365,7 @@ public boolean isMovementPossible(Game game, Coords src, int srcEl, CachedEntity } // If you want to flee, and you can flee, flee. - if ((type == MoveStepType.FLEE) && entity.canFlee()) { + if ((type == MoveStepType.FLEE) && entity.canFlee(dest)) { return true; } diff --git a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java index dbcd61f3a8b..8e9d2df927b 100644 --- a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java +++ b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java @@ -123,12 +123,6 @@ class MovePathHandler extends AbstractTWRuleHandler { } void processMovement() { - // check for fleeing - if (md.contains(MovePath.MoveStepType.FLEE)) { - addReport(gameManager.processLeaveMap(md, false, -1)); - return; - } - if (md.contains(MovePath.MoveStepType.EJECT)) { if (entity.isLargeCraft() && !entity.isCarcass()) { r = new Report(2026); @@ -1200,6 +1194,11 @@ && getGame().getOptions().booleanOption(OptionsConstants.ADVAERORULES_FUEL_CONSU ((Mek) entity).setShouldDieAtEndOfTurnBecauseOfWater(false); } } + + // check for fleeing + if (md.contains(MovePath.MoveStepType.FLEE) && md.getLastStep().getPosition() == entity.getPosition()) { + addReport(gameManager.processLeaveMap(md, false, -1)); + } } /** diff --git a/megamek/unittests/megamek/client/bot/princess/PrincessTest.java b/megamek/unittests/megamek/client/bot/princess/PrincessTest.java index 903c70fc9d6..27c647b0564 100644 --- a/megamek/unittests/megamek/client/bot/princess/PrincessTest.java +++ b/megamek/unittests/megamek/client/bot/princess/PrincessTest.java @@ -406,7 +406,7 @@ void testMustFleeBoard() { // Unit is capable of fleeing. Entity mockMek = mock(BipedMek.class); - when(mockMek.canFlee()).thenReturn(true); + when(mockMek.canFlee(mockMek.getPosition())).thenReturn(true); // Unit is on home edge. BasicPathRanker mockRanker = mock(BasicPathRanker.class); @@ -448,11 +448,11 @@ void testMustFleeBoard() { assertTrue(mockPrincess.mustFleeBoard(mockMek)); // Make the unit incapable of fleeing. - when(mockMek.canFlee()).thenReturn(false); + when(mockMek.canFlee(mockMek.getPosition())).thenReturn(false); assertFalse(mockPrincess.mustFleeBoard(mockMek)); // The unit can flee, but is no longer on the board edge. - when(mockMek.canFlee()).thenReturn(true); + when(mockMek.canFlee(mockMek.getPosition())).thenReturn(true); when(mockRanker.distanceToHomeEdge(any(Coords.class), any(CardinalEdge.class), any(Game.class))).thenReturn(1); assertFalse(mockPrincess.mustFleeBoard(mockMek)); From 112c399ebfdbcaa8cad9b73201a6123c82604454 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 19:52:14 -0500 Subject: [PATCH 02/12] use canFlee() --- megamek/src/megamek/server/totalwarfare/MovePathHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java index 8e9d2df927b..cad5a1d8c93 100644 --- a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java +++ b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java @@ -1196,7 +1196,7 @@ && getGame().getOptions().booleanOption(OptionsConstants.ADVAERORULES_FUEL_CONSU } // check for fleeing - if (md.contains(MovePath.MoveStepType.FLEE) && md.getLastStep().getPosition() == entity.getPosition()) { + if (md.contains(MovePath.MoveStepType.FLEE) && entity.canFlee(entity.getPosition())) { addReport(gameManager.processLeaveMap(md, false, -1)); } } From bf1f466800af07e8c412376a14bf277fbbe486e1 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 20:26:23 -0500 Subject: [PATCH 03/12] fix test --- megamek/unittests/megamek/client/bot/princess/PrincessTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/megamek/unittests/megamek/client/bot/princess/PrincessTest.java b/megamek/unittests/megamek/client/bot/princess/PrincessTest.java index 27c647b0564..e2bca0610ba 100644 --- a/megamek/unittests/megamek/client/bot/princess/PrincessTest.java +++ b/megamek/unittests/megamek/client/bot/princess/PrincessTest.java @@ -406,7 +406,6 @@ void testMustFleeBoard() { // Unit is capable of fleeing. Entity mockMek = mock(BipedMek.class); - when(mockMek.canFlee(mockMek.getPosition())).thenReturn(true); // Unit is on home edge. BasicPathRanker mockRanker = mock(BasicPathRanker.class); @@ -420,6 +419,7 @@ void testMustFleeBoard() { when(mockPrincess.getHomeEdge(any(Entity.class))).thenReturn(CardinalEdge.NORTH); Game mockGame = mock(Game.class); when(mockPrincess.getGame()).thenReturn(mockGame); + when(mockMek.canFlee(mockMek.getPosition())).thenReturn(true); // In its current state, the entity does not need to flee the board. assertFalse(mockPrincess.mustFleeBoard(mockMek)); From ab76ef28c0c1c6a8095e2e06a189f7d0f44ef9b8 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 20:47:41 -0500 Subject: [PATCH 04/12] fix issue --- megamek/src/megamek/client/ui/swing/MovementDisplay.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index 84e63661908..66016915d68 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -853,7 +853,7 @@ private void updateButtons() { (ce instanceof Tank) && (ce.getSwarmAttackerId() != Entity.NONE)); - boolean fleeStart = ce().canFlee(ce().getPosition()); + boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); setFleeEnabled(fleeStart || fleeEnd); if (gOpts.booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLES_CAN_EJECT) && (ce instanceof Tank)) { @@ -971,7 +971,7 @@ private void updateMove(boolean redrawMovement) { clientgui.getBoardView().drawMovementData(ce(), cmd); } - boolean fleeStart = ce().canFlee(ce().getPosition()); + boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); setFleeEnabled(fleeStart || fleeEnd); updateDonePanel(); From bba0bdc560710eb46b79066b1abe467e21971234 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 20:51:58 -0500 Subject: [PATCH 05/12] fix issue --- megamek/src/megamek/client/ui/swing/MovementDisplay.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index 66016915d68..39917d6bccf 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -854,7 +854,9 @@ private void updateButtons() { && (ce.getSwarmAttackerId() != Entity.NONE)); boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); - boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); + boolean fleeEnd = (cmd.getLastStep() != null) + && (ce().canFlee(cmd.getLastStep().getPosition()) + && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) ); setFleeEnabled(fleeStart || fleeEnd); if (gOpts.booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLES_CAN_EJECT) && (ce instanceof Tank)) { // Vehicle don't have ejection systems so crews abandon, and must enter a valid @@ -972,7 +974,9 @@ private void updateMove(boolean redrawMovement) { } boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); - boolean fleeEnd = (cmd.getLastStep() != null) && (ce().canFlee(cmd.getLastStep().getPosition())); + boolean fleeEnd = (cmd.getLastStep() != null) + && (ce().canFlee(cmd.getLastStep().getPosition()) + && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) ); setFleeEnabled(fleeStart || fleeEnd); updateDonePanel(); } From 492ec639547fe0d9e897bdf4c497c1ef40e99211 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 27 Nov 2024 22:16:04 -0500 Subject: [PATCH 06/12] fix issue --- .../megamek/client/ui/swing/MovementDisplay.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index 39917d6bccf..08910dec2fc 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -853,10 +853,11 @@ private void updateButtons() { (ce instanceof Tank) && (ce.getSwarmAttackerId() != Entity.NONE)); - boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); + boolean fleeStart = (cmd.getLastStep() == null) + && ce().canFlee(ce().getPosition()); boolean fleeEnd = (cmd.getLastStep() != null) - && (ce().canFlee(cmd.getLastStep().getPosition()) - && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) ); + && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) + && clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition()); setFleeEnabled(fleeStart || fleeEnd); if (gOpts.booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLES_CAN_EJECT) && (ce instanceof Tank)) { // Vehicle don't have ejection systems so crews abandon, and must enter a valid @@ -973,10 +974,11 @@ private void updateMove(boolean redrawMovement) { clientgui.getBoardView().drawMovementData(ce(), cmd); } - boolean fleeStart = (ce().canFlee(ce().getPosition()) && (cmd.getLastStep() == null)); + boolean fleeStart = (cmd.getLastStep() == null) + && ce().canFlee(ce().getPosition()); boolean fleeEnd = (cmd.getLastStep() != null) - && (ce().canFlee(cmd.getLastStep().getPosition()) - && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) ); + && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) + && clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition()); setFleeEnabled(fleeStart || fleeEnd); updateDonePanel(); } From 11e88e9d380859f81631894596ddc28760608e43 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 28 Nov 2024 09:39:47 -0500 Subject: [PATCH 07/12] add flee failed to report log --- .../i18n/megamek/common/report-messages.properties | 1 + .../megamek/client/ui/swing/MovementDisplay.java | 14 +++++++------- .../server/totalwarfare/MovePathHandler.java | 10 ++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index b82e7e2a3aa..5359217602f 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -80,6 +80,7 @@ 2010=It carries () with it. 2015=It takes () with it. 2016=It carries with it. +2017= flee failed. 2020= ejects from a (). 2025= () is abandoned by its crew. 2026= () is given the order to abandon ship. diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index 08910dec2fc..f32db7ccbf3 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -853,12 +853,8 @@ private void updateButtons() { (ce instanceof Tank) && (ce.getSwarmAttackerId() != Entity.NONE)); - boolean fleeStart = (cmd.getLastStep() == null) - && ce().canFlee(ce().getPosition()); - boolean fleeEnd = (cmd.getLastStep() != null) - && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) - && clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition()); - setFleeEnabled(fleeStart || fleeEnd); + updateFleeButton(); + if (gOpts.booleanOption(OptionsConstants.ADVGRNDMOV_VEHICLES_CAN_EJECT) && (ce instanceof Tank)) { // Vehicle don't have ejection systems so crews abandon, and must enter a valid // hex. @@ -974,13 +970,17 @@ private void updateMove(boolean redrawMovement) { clientgui.getBoardView().drawMovementData(ce(), cmd); } + updateFleeButton(); + updateDonePanel(); + } + + private void updateFleeButton() { boolean fleeStart = (cmd.getLastStep() == null) && ce().canFlee(ce().getPosition()); boolean fleeEnd = (cmd.getLastStep() != null) && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) && clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition()); setFleeEnabled(fleeStart || fleeEnd); - updateDonePanel(); } private void updateAeroButtons() { diff --git a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java index cad5a1d8c93..bb0aaa246e8 100644 --- a/megamek/src/megamek/server/totalwarfare/MovePathHandler.java +++ b/megamek/src/megamek/server/totalwarfare/MovePathHandler.java @@ -1196,8 +1196,14 @@ && getGame().getOptions().booleanOption(OptionsConstants.ADVAERORULES_FUEL_CONSU } // check for fleeing - if (md.contains(MovePath.MoveStepType.FLEE) && entity.canFlee(entity.getPosition())) { - addReport(gameManager.processLeaveMap(md, false, -1)); + if (md.contains(MovePath.MoveStepType.FLEE)) { + if (entity.canFlee(entity.getPosition())) { + addReport(gameManager.processLeaveMap(md, false, -1)); + } else { + r = new Report(2017, Report.PUBLIC); + r.indent(); + addReport(r); + } } } From 1568e961839d1c2f82f6bbbb3407a1320769c585 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 28 Nov 2024 10:03:41 -0500 Subject: [PATCH 08/12] add flee direction to report --- .../megamek/common/report-messages.properties | 3 +- .../server/totalwarfare/TWGameManager.java | 71 ++++++++++++++----- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index 5359217602f..580b10842de 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -76,7 +76,7 @@ 1511= to maximise range. 2000=Movement Phase------------------- -2005= () flees the battlefield. +2005= () flees the battlefield in the direction . 2010=It carries () with it. 2015=It takes () with it. 2016=It carries with it. @@ -1038,6 +1038,7 @@ 7075=The following units never entered the field of battle: 7076=All fighters in squadron destroyed 7080=The following units are in retreat: +7081=fled in direction . 7085=Graveyard contains: 7090=The following utterly destroyed units are not available for salvage: 7095=Detailed unit status saved to entitystatus.txt diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 87a0301b436..0a317111853 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -1171,6 +1171,29 @@ void prepareVictoryReport() { while (retreat.hasMoreElements()) { Entity entity = retreat.nextElement(); addReport(entity.victoryReport()); + + String fleeDirection; + switch (entity.getStartingPos(false)) { + case Board.START_N: + fleeDirection = "North"; + break; + case Board.START_E: + fleeDirection = "Ease"; + break; + case Board.START_S: + fleeDirection = "South"; + break; + case Board.START_W: + fleeDirection = "West"; + break; + default: + fleeDirection = "Edge"; + } + + r = new Report(7081, Report.PUBLIC); + r.indent(); + r.add(fleeDirection); + addReport(r); } } // List destroyed units @@ -5304,7 +5327,6 @@ public Vector processLeaveMap(MovePath movePath, boolean flewOff, int re r = new Report(9370, Report.PUBLIC); } r.addDesc(entity); - addReport(r); OffBoardDirection fleeDirection; if (movePath.getFinalCoords().getY() <= 0) { fleeDirection = OffBoardDirection.NORTH; @@ -5316,8 +5338,35 @@ public Vector processLeaveMap(MovePath movePath, boolean flewOff, int re fleeDirection = OffBoardDirection.EAST; } - if (returnable > -1) { + 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); + addReport(r); + entityUpdate(entity.getId()); + + if (returnable > -1) { entity.setDeployed(false); entity.setDeployRound(1 + game.getRoundCount() + returnable); entity.setPosition(null); @@ -5330,23 +5379,7 @@ public Vector processLeaveMap(MovePath movePath, boolean flewOff, int re // fly off again instantly. ((IAero) entity).setOutControl(false); } - switch (fleeDirection) { - case WEST: - entity.setStartingPos(Board.START_W); - break; - case NORTH: - entity.setStartingPos(Board.START_N); - break; - case EAST: - entity.setStartingPos(Board.START_E); - break; - case SOUTH: - entity.setStartingPos(Board.START_S); - break; - default: - entity.setStartingPos(Board.START_EDGE); - } - entityUpdate(entity.getId()); + return vReport; } else { ServerHelper.clearBloodStalkers(game, entity.getId(), this); From f723517881d8aae9e8c1cc03b30b8f301895dbcd Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 28 Nov 2024 12:32:39 -0500 Subject: [PATCH 09/12] add check that unit has remaining movement to enable flee button --- megamek/src/megamek/client/ui/swing/MovementDisplay.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/megamek/src/megamek/client/ui/swing/MovementDisplay.java b/megamek/src/megamek/client/ui/swing/MovementDisplay.java index f32db7ccbf3..620ffdea8e4 100644 --- a/megamek/src/megamek/client/ui/swing/MovementDisplay.java +++ b/megamek/src/megamek/client/ui/swing/MovementDisplay.java @@ -977,8 +977,16 @@ private void updateMove(boolean redrawMovement) { private void updateFleeButton() { boolean fleeStart = (cmd.getLastStep() == null) && ce().canFlee(ce().getPosition()); + boolean jumpMoveRemaining = (cmd.getLastStep() != null) + && cmd.getLastStep().isJumping() + && (cmd.getMpUsed() < ce().getJumpMP()); + boolean runMoveRemaining = (cmd.getLastStep() != null) + && !cmd.getLastStep().isJumping() + && (cmd.getMpUsed() < ce().getRunMP()); + boolean moveRemaining = jumpMoveRemaining || runMoveRemaining; boolean fleeEnd = (cmd.getLastStep() != null) && (cmd.getLastStepMovementType() != EntityMovementType.MOVE_ILLEGAL) + && moveRemaining && clientgui.getClient().getGame().canFleeFrom(ce(), cmd.getLastStep().getPosition()); setFleeEnabled(fleeStart || fleeEnd); } From cd5a88eba6937d97b4ffcc6c865b4f7657f7eb97 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Thu, 28 Nov 2024 19:05:46 -0500 Subject: [PATCH 10/12] update text --- megamek/i18n/megamek/common/report-messages.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index 580b10842de..d5044809bd3 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -76,7 +76,7 @@ 1511= to maximise range. 2000=Movement Phase------------------- -2005= () flees the battlefield in the direction . +2005= () flees the battlefield to the . 2010=It carries () with it. 2015=It takes () with it. 2016=It carries with it. @@ -1038,7 +1038,7 @@ 7075=The following units never entered the field of battle: 7076=All fighters in squadron destroyed 7080=The following units are in retreat: -7081=fled in direction . +7081=fled to the . 7085=Graveyard contains: 7090=The following utterly destroyed units are not available for salvage: 7095=Detailed unit status saved to entitystatus.txt From a716ab2fd06fa45a6a85a0e078f2c144e64593ad Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Fri, 29 Nov 2024 11:38:55 -0500 Subject: [PATCH 11/12] log edge when forced from field --- .../megamek/common/report-messages.properties | 2 +- .../server/totalwarfare/TWGameManager.java | 58 +++++++++++++++---- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/megamek/i18n/megamek/common/report-messages.properties b/megamek/i18n/megamek/common/report-messages.properties index d5044809bd3..13162ca90c7 100755 --- a/megamek/i18n/megamek/common/report-messages.properties +++ b/megamek/i18n/megamek/common/report-messages.properties @@ -160,7 +160,7 @@ 2216=collides! 2217=<misses. 2220= () takes damage from the collision. -2230=*** () has been forced from the field. *** +2230=*** () has been forced from the field to the . *** 2235= () is displaced into hex . 2240= () is displaced into hex , violating stacking with (). 2245= attempts to clear a(n) mine in hex : diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 0a317111853..01d70a94f0b 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -5305,6 +5305,22 @@ Vector 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 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 doEntityDisplacement(Entity entity, Coords src, Coords dest, PilotingRollData roll) { Vector 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 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; } From f97511460211a71abed39b3f1ccde35dd6cea356 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Fri, 29 Nov 2024 12:00:07 -0500 Subject: [PATCH 12/12] 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 01d70a94f0b..408780f7c50 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. }