Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps towards SBF, player turns and stuff #5541

Merged
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected void receiveTurns(Packet packet) {
* Can I unload entities stranded on immobile transports?
*/
public boolean canUnloadStranded() {
return (game.getTurn() instanceof GameTurn.UnloadStrandedTurn)
return (game.getTurn() instanceof UnloadStrandedTurn)
&& game.getTurn().isValid(localPlayerNumber, game);
}

Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/bot/BotClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ private synchronized boolean calculateMyTurnWorker() {
try {
if (game.getPhase().isMovement()) {
MovePath mp;
if (game.getTurn() instanceof GameTurn.SpecificEntityTurn) {
GameTurn.SpecificEntityTurn turn = (GameTurn.SpecificEntityTurn) game.getTurn();
if (game.getTurn() instanceof SpecificEntityTurn) {
SpecificEntityTurn turn = (SpecificEntityTurn) game.getTurn();
Entity mustMove = game.getEntity(turn.getEntityNum());
mp = continueMovementFor(mustMove);
} else {
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ protected void loadListFile(Player player, boolean reinforce) {

// If we've added reinforcements, then we need to set the round deployment up again.
if (addedUnits && reinforce) {
client.getGame().setupRoundDeployment();
client.getGame().setupDeployment();
client.sendResetRoundDeployment();
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ protected void beginMyTurn() {

GameTurn turn = clientgui.getClient().getMyTurn();
// There's special processing for triggering AP Pods.
if ((turn instanceof GameTurn.TriggerAPPodTurn) && (ce() != null)) {
if ((turn instanceof TriggerAPPodTurn) && (ce() != null)) {
disableButtons();
TriggerAPPodDialog dialog = new TriggerAPPodDialog(clientgui.getFrame(), ce());
dialog.setVisible(true);
Expand All @@ -485,10 +485,10 @@ protected void beginMyTurn() {
addAttack(actions.nextElement());
}
ready();
} else if ((turn instanceof GameTurn.TriggerBPodTurn) && (null != ce())) {
} else if ((turn instanceof TriggerBPodTurn) && (null != ce())) {
disableButtons();
TriggerBPodDialog dialog = new TriggerBPodDialog(clientgui, ce(),
((GameTurn.TriggerBPodTurn) turn).getAttackType());
((TriggerBPodTurn) turn).getAttackType());
dialog.setVisible(true);
removeAllAttacks();
Enumeration<TriggerBPodAction> actions = dialog.getActions();
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import megamek.client.ui.swing.util.MegaMekController;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.common.*;
import megamek.common.GameTurn.UnloadStrandedTurn;
import megamek.common.UnloadStrandedTurn;
import megamek.common.MovePath.MoveStepType;
import megamek.common.actions.AirmechRamAttackAction;
import megamek.common.actions.ChargeAttackAction;
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/PhysicalDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ private void beginMyTurn() {
clientgui.maybeShowUnitDisplay();
GameTurn turn = clientgui.getClient().getMyTurn();
// There's special processing for countering break grapple.
if (turn instanceof GameTurn.CounterGrappleTurn) {
if (turn instanceof CounterGrappleTurn) {
disableButtons();
selectEntity(((GameTurn.CounterGrappleTurn) turn).getEntityNum());
selectEntity(((CounterGrappleTurn) turn).getEntityNum());
grapple(true);
ready();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ public String getRemainingPlayerWithTurns() {
if (r > 0) {
String m = "";
int gti = clientgui.getClient().getGame().getTurnIndex();
List<GameTurn> gtv = clientgui.getClient().getGame().getTurnVector();
List<GameTurn> gtv = clientgui.getClient().getGame().getTurnsList();
SJuliez marked this conversation as resolved.
Show resolved Hide resolved
int j = 0;
for (int i = gti + 1; i < gtv.size(); i++) {
GameTurn nt = gtv.get(i);
Player p = clientgui.getClient().getGame().getPlayer(nt.getPlayerNum());
Player p = clientgui.getClient().getGame().getPlayer(nt.playerId());
s += p.getName() + ", ";
j++;
if (j >= r) {
Expand Down
26 changes: 13 additions & 13 deletions megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void selectEntity(int en) {

// Walk through the list of entities for this player.
for (int nextId = client.getNextEntityNum(en); nextId != en;
nextId = client.getNextEntityNum(nextId)) {
nextId = client.getNextEntityNum(nextId)) {

if (null != clientgui.getClient().getGame()
.getEntity(nextId).getPosition()) {
Expand Down Expand Up @@ -392,24 +392,24 @@ private void beginMyTurn() {

GameTurn turn = clientgui.getClient().getMyTurn();
// There's special processing for triggering AP Pods.
if ((turn instanceof GameTurn.TriggerAPPodTurn) && (null != ce())) {
if ((turn instanceof TriggerAPPodTurn) && (null != ce())) {
selectEntity(clientgui.getClient().getFirstEntityNum());
disableButtons();
TriggerAPPodDialog dialog = new TriggerAPPodDialog(clientgui.getFrame(), ce());
dialog.setVisible(true);
removeAllAttacks();
removeAllAttacks();
Enumeration<TriggerAPPodAction> actions = dialog.getActions();
while (actions.hasMoreElements()) {
addAttack(actions.nextElement());
}
ready();
} else if ((turn instanceof GameTurn.TriggerBPodTurn) && (null != ce())) {
} else if ((turn instanceof TriggerBPodTurn) && (null != ce())) {
selectEntity(clientgui.getClient().getFirstEntityNum());
disableButtons();
TriggerBPodDialog dialog = new TriggerBPodDialog(clientgui, ce(),
((GameTurn.TriggerBPodTurn) turn).getAttackType());
((TriggerBPodTurn) turn).getAttackType());
dialog.setVisible(true);
removeAllAttacks();
removeAllAttacks();
Enumeration<TriggerBPodAction> actions = dialog.getActions();
while (actions.hasMoreElements()) {
addAttack(actions.nextElement());
Expand Down Expand Up @@ -536,7 +536,7 @@ private boolean checkNags() {
@Override
public void ready() {
if (checkNags()) {
return;
return;
}

// stop further input (hopefully)
Expand Down Expand Up @@ -605,9 +605,9 @@ private void fire() {
int distance = Compute.effectiveDistance(game, waa.getEntity(game), waa.getTarget(game));
if ((mounted.getType().hasFlag(WeaponType.F_ARTILLERY))
|| (mounted.isInBearingsOnlyMode()
&& distance >= RangeType.RANGE_BEARINGS_ONLY_MINIMUM)
&& distance >= RangeType.RANGE_BEARINGS_ONLY_MINIMUM)
|| (mounted.getType() instanceof CapitalMissileWeapon
&& Compute.isGroundToGround(ce(), target))) {
&& Compute.isGroundToGround(ce(), target))) {
waa = new ArtilleryAttackAction(currentEntity, target.getTargetType(),
target.getId(), weaponNum, clientgui.getClient().getGame());
// Get the launch velocity for bearings-only telemissiles
Expand Down Expand Up @@ -725,7 +725,7 @@ private void clearAttacks() {
ce().getEquipment(waa.getWeaponId()).setUsedThisRound(false);
}
}
removeAllAttacks();
removeAllAttacks();

// remove temporary attacks from game & board
removeTempAttacks();
Expand Down Expand Up @@ -1009,13 +1009,13 @@ public void hexMoused(BoardViewEvent b) {

// ignore buttons other than 1
if (!clientgui.getClient().isMyTurn()
|| ((b.getButton() != MouseEvent.BUTTON1))) {
|| ((b.getButton() != MouseEvent.BUTTON1))) {
return;
}
// control pressed means a line of sight check.
// added ALT_MASK by kenn
if (((b.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0)
|| ((b.getModifiers() & InputEvent.ALT_DOWN_MASK) != 0)) {
|| ((b.getModifiers() & InputEvent.ALT_DOWN_MASK) != 0)) {
return;
}
// check for shifty goodness
Expand Down Expand Up @@ -1220,7 +1220,7 @@ public void actionPerformed(ActionEvent ev) {
doSearchlight();
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_DISENGAGE.getCmd())
&& clientgui.doYesNoDialog(Messages.getString("MovementDisplay.EscapeDialog.title"),
Messages.getString("MovementDisplay.EscapeDialog.message"))) {
Messages.getString("MovementDisplay.EscapeDialog.message"))) {
clear();
addAttack(new DisengageAction(currentEntity));
ready();
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/minimap/Minimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private void drawDeploymentZone(Graphics g) {
if ((null != client) && (null != game) && game.getPhase().isDeployment() && (dialog != null)
&& (bv.getDeployingEntity() != null)) {
GameTurn turn = game.getTurn();
if ((turn != null) && (turn.getPlayerNum() == client.getLocalPlayer().getId())) {
if ((turn != null) && (turn.playerId() == client.getLocalPlayer().getId())) {
Entity deployingUnit = bv.getDeployingEntity();

for (int j = 0; j < board.getWidth(); j++) {
Expand Down
47 changes: 23 additions & 24 deletions megamek/src/megamek/common/AbstractGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
public abstract class AbstractGame implements IGame {

private static final int AWAITING_FIRST_TURN = -1;

/** The players present in the game mapped to their id as key */
protected final ConcurrentHashMap<Integer, Player> players = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -76,6 +78,8 @@ public abstract class AbstractGame implements IGame {
*/
protected int currentRound = -1;

protected int turnIndex = AWAITING_FIRST_TURN;

@Override
public Forces getForces() {
return forces;
Expand Down Expand Up @@ -206,29 +210,6 @@ public void setCurrentRound(int currentRound) {
this.currentRound = currentRound;
}

/**
* Returns true when the current game phase should be played, meaning it is played in the current type
* of game and there are possible actions in it in the present game state.
* The result may be different in other rounds.
*
* @return True when the current phase should be skipped entirely in this round
* @see #shouldSkipCurrentPhase()
*/
public abstract boolean isCurrentPhasePlayable();

/**
* Returns true when the current game phase should be skipped, either because it is not played at
* all in the current type of game or because the present game state dictates that there can be no
* actions in it. The result may be different in other rounds. This is the opposite of
* {@link #isCurrentPhasePlayable()}.
*
* @return True when the current phase should be skipped entirely in this round
* @see #isCurrentPhasePlayable()
*/
public boolean shouldSkipCurrentPhase() {
return !isCurrentPhasePlayable();
}

/**
* Empties the list of pending EntityActions completely.
* @see #getActionsVector()
Expand Down Expand Up @@ -268,7 +249,13 @@ public void addAction(EntityAction action) {
fireGameEvent(new GameNewActionEvent(this, action));
}

public void setupRoundDeployment() {
/**
* Clears and re-calculates the deployment table, i.e. assembles all units/objects in the game
* that are undeployed (that includes returning units or reinforcements) together with the game
* round that they are supposed to deploy on. This method can be called at any time in the game
* and will assemble deployment according to the present game state.
*/
public void setupDeployment() {
deploymentTable.clear();
for (Deployable unit : deployableInGameObjects()) {
if (!unit.isDeployed()) {
Expand Down Expand Up @@ -309,4 +296,16 @@ public boolean shouldDeployForRound(int round) {
public void clearDeploymentThisRound() {
deploymentTable.remove(currentRound);
}

/**
* Resets the turn index to {@link #AWAITING_FIRST_TURN}
*/
public void resetTurnIndex() {
turnIndex = AWAITING_FIRST_TURN;
}

@Override
public int getTurnIndex() {
return turnIndex;
}
}
43 changes: 43 additions & 0 deletions megamek/src/megamek/common/AbstractPlayerTurn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek 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 3 of the License, or
* (at your option) any later version.
*
* MegaMek 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.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.common;

/**
* This is a basic implementation of PlayerTurn to extend other turn types from. It is suitable for
* all game types.
*/
public abstract class AbstractPlayerTurn implements PlayerTurn {

private final int playerId;

/** Creates a new instance of GameTurn */
public AbstractPlayerTurn(int playerId) {
this.playerId = playerId;
}

@Override
public final int playerId() {
return playerId;
}

@Override
public String toString() {
return "[" + getClass().getSimpleName() + "] Player: " + playerId;
}
}
44 changes: 44 additions & 0 deletions megamek/src/megamek/common/CounterGrappleTurn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek 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 3 of the License, or
* (at your option) any later version.
*
* MegaMek 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.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.common;

/**
* A type of game turn that allows only one specific entity to counterattack a break grapple by
* the original attacker
*/
public class CounterGrappleTurn extends SpecificEntityTurn {
private static final long serialVersionUID = 5248356977626018582L;

public CounterGrappleTurn(int playerId, int entityId) {
super(playerId, entityId);
}

/**
* @return true if the entity matches this game turn, even if the entity has declared an
* action.
*/
@Override
public boolean isValidEntity(Entity entity, Game game, boolean useValidNonInfantryCheck) {
final boolean oldDone = entity.done;
entity.done = false;
final boolean result = super.isValidEntity(entity, game, useValidNonInfantryCheck);
entity.done = oldDone;
return result;
}
}
Loading
Loading