-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ground roles, cover, some more things in movement
- Loading branch information
Showing
20 changed files
with
1,109 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
megamek/src/megamek/common/autoresolve/acar/action/MoveToCoverAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
package megamek.common.autoresolve.acar.action; | ||
|
||
import megamek.common.Coords; | ||
import megamek.common.autoresolve.acar.SimulationContext; | ||
import megamek.common.autoresolve.acar.SimulationManager; | ||
import megamek.common.autoresolve.acar.handler.MoveActionHandler; | ||
import megamek.common.autoresolve.acar.handler.MoveToCoverActionHandler; | ||
|
||
public class MoveToCoverAction implements Action { | ||
|
||
private final int formationId; | ||
private final int targetFormationId; | ||
private final Coords destination; | ||
|
||
public MoveToCoverAction(int formationId, int targetFormationId, Coords destination) { | ||
this.formationId = formationId; | ||
this.targetFormationId = targetFormationId; | ||
this.destination = destination; | ||
} | ||
|
||
@Override | ||
public int getEntityId() { | ||
return formationId; | ||
} | ||
|
||
public int getTargetFormationId() { | ||
return targetFormationId; | ||
} | ||
|
||
@Override | ||
public MoveToCoverActionHandler getHandler(SimulationManager gameManager) { | ||
return new MoveToCoverActionHandler(this, gameManager); | ||
} | ||
|
||
@Override | ||
public boolean isDataValid(SimulationContext context) { | ||
return context.getFormation(formationId).isPresent(); | ||
} | ||
|
||
public Coords getDestination() { | ||
return destination; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[MoveAction]: ID: " + formationId; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
megamek/src/megamek/common/autoresolve/acar/board/Board1D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
*/ | ||
|
||
package megamek.common.autoresolve.acar.board; | ||
|
||
import megamek.common.Board; | ||
|
||
public class Board1D { | ||
|
||
private enum Type { | ||
GROUND, | ||
ATMOSPHERE, | ||
SPACE | ||
} | ||
|
||
private enum TerrainType { | ||
URBAN, | ||
LIGHT_WOOD, | ||
HEAVY_WOODS, | ||
JUNGLE, | ||
SHALLOW_WATER, | ||
DEEP_WATER, | ||
MARSH, | ||
SWAMP, | ||
LAVA, | ||
THIN_ICE, | ||
THICK_ICE, | ||
DESERT, | ||
SNOW, | ||
ROUGH, | ||
} | ||
|
||
private final int size; | ||
|
||
public Board1D(Board board) { | ||
var c1 = board.getHeight() * board.getHeight(); | ||
var c2 = board.getWidth() * board.getWidth(); | ||
this.size = (int) Math.sqrt(c1 + c2); | ||
} | ||
|
||
public int getSize() { | ||
return size; | ||
} | ||
|
||
public int getNorthMostPosition() { | ||
return size-1; | ||
} | ||
|
||
public int getSouthMostPosition() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
megamek/src/megamek/common/autoresolve/acar/handler/MoveToCoverActionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
package megamek.common.autoresolve.acar.handler; | ||
|
||
import megamek.common.BoardLocation; | ||
import megamek.common.autoresolve.acar.SimulationManager; | ||
import megamek.common.autoresolve.acar.action.MoveAction; | ||
import megamek.common.autoresolve.acar.action.MoveToCoverAction; | ||
import megamek.common.autoresolve.acar.report.MovementReport; | ||
|
||
public class MoveToCoverActionHandler extends AbstractActionHandler { | ||
|
||
private final MovementReport reporter; | ||
|
||
public MoveToCoverActionHandler(MoveToCoverAction action, SimulationManager gameManager) { | ||
super(action, gameManager); | ||
this.reporter = new MovementReport(gameManager.getGame(), this::addReport); | ||
} | ||
|
||
@Override | ||
public boolean cares() { | ||
return game().getPhase().isMovement(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
MoveToCoverAction moveAction = (MoveToCoverAction) getAction(); | ||
|
||
var formationOpt = game().getFormation(moveAction.getEntityId()); | ||
var movingFormation = formationOpt.orElseThrow(); | ||
var x = movingFormation.getPosition().coords().getX(); | ||
var moveX = moveAction.getDestination().getX(); | ||
|
||
var targetFormationOpt = game().getFormation(moveAction.getTargetFormationId()); | ||
var boardLocation = game().clamp(new BoardLocation(moveAction.getDestination(), 0)); | ||
|
||
if (targetFormationOpt.isPresent()) { | ||
var targetX = targetFormationOpt.get().getPosition().coords().getX(); | ||
var moveDir = x < moveX ? 1 : -1; | ||
var targetDir = x < targetX ? 1 : -1; | ||
var relativeDir = moveDir * targetDir; | ||
|
||
reporter.reportMovement(movingFormation, targetFormationOpt.get(), relativeDir); | ||
} else { | ||
if (movingFormation.isWithdrawing()) { | ||
reporter.reportRetreatMovement(movingFormation); | ||
} else { | ||
reporter.reportMovement(movingFormation); | ||
} | ||
} | ||
movingFormation.getMemory().put("cover", true); | ||
simulationManager().setFormationAt(movingFormation, boardLocation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.