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

add deployment options #4922

Merged
merged 24 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a560f8c
add team and player0 deployemnt options
kuronekochomusuke Nov 24, 2023
9640b11
typo
kuronekochomusuke Nov 24, 2023
2d419e1
code cleanup
kuronekochomusuke Nov 24, 2023
c4cd96c
handle overlapping start positions and player display
kuronekochomusuke Nov 24, 2023
cf4f166
allow limiting Any deployment to a smaller square area
kuronekochomusuke Nov 24, 2023
688dc50
code cleanup
kuronekochomusuke Nov 24, 2023
11a8d30
show player deployments on map preview
kuronekochomusuke Nov 25, 2023
ec89204
if blind drop hid player deployment zones from non gm player
kuronekochomusuke Nov 25, 2023
262b730
code cleanup
kuronekochomusuke Nov 25, 2023
b3150d6
allow gm to see and edit all units on any team hidden or not in lobby
kuronekochomusuke Nov 25, 2023
1cfebff
correct issue
kuronekochomusuke Nov 25, 2023
86a483f
save and load from mul
kuronekochomusuke Nov 26, 2023
9195c91
add ruler to map preview
kuronekochomusuke Nov 26, 2023
a106899
insure ruler is always on top of the map preview
kuronekochomusuke Nov 26, 2023
ab56dc6
apply ruler coords for deployment Any corners
kuronekochomusuke Nov 26, 2023
966f32d
update button to apply any deployment changes
kuronekochomusuke Nov 26, 2023
5163750
correct issue
kuronekochomusuke Nov 27, 2023
65cf65d
update message
kuronekochomusuke Nov 27, 2023
c2fe464
use 2 buttons
kuronekochomusuke Nov 27, 2023
3c6518d
correct gm edit issue
kuronekochomusuke Nov 27, 2023
1fad826
while in lobby and there is a gm, if player disconnects transfer the …
kuronekochomusuke Nov 27, 2023
c913302
code cleanup
kuronekochomusuke Nov 28, 2023
6df8b2f
code cleanup
kuronekochomusuke Dec 4, 2023
a1efa21
text cleanup
kuronekochomusuke Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ ChatLounge.notDone=Not Done
ChatLounge.PartialRepairs=Partial Repairs
ChatLounge.Player=Player
ChatLounge.Players=Players
ChatLounge.Player0=Player0
ChatLounge.quickView=Unit Quick View
ChatLounge.OverlapDeploy.title=Must choose exclusive deployment zone
ChatLounge.OverlapDeploy.msg=When using double blind, each player needs to have an exclusive deployment zone.
Expand Down
4 changes: 4 additions & 0 deletions megamek/i18n/megamek/common/options/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ GameOptionsInfo.option.dumping_from_round.displayableName=first round for ammo d
GameOptionsInfo.option.dumping_from_round.description=Number of the round that has to be at least reached before allowing ammo dumps.
GameOptionsInfo.option.set_arty_player_homeedge.displayableName=Automatically set artillery home edge
GameOptionsInfo.option.set_arty_player_homeedge.description=If checked, all of the players' artillery units will have their home edge set to the deployment edge of the player, NW and NE are North, SW and SE are South. \nUnchecked by default.
GameOptionsInfo.option.set_default_team_1.displayableName=Default non-bot players to team 1
GameOptionsInfo.option.set_default_team_1.description=Unchecked each player is assigned new team
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is not understandable unless you already know what it does. At least it should start with "When this option is unchecked, "

GameOptionsInfo.option.set_player_deployment_to_player0.displayableName=Non-bot player entities with \"Use Owners*\" deployment set, use Player 0\'s settings, instead of current player\'s settings
GameOptionsInfo.option.set_player_deployment_to_player0.description=Unchecked use current player deployments settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

GameOptionsInfo.option.restrict_game_commands.displayableName=Restrict sensitive commands to non-Observers
GameOptionsInfo.option.restrict_game_commands.description=If checked, commands such as /reset and /kick cannot be used by Observers while others are playing. \nUnchecked by default.
GameOptionsInfo.option.disable_local_save.displayableName=Disable local saves when using double blind
Expand Down
49 changes: 49 additions & 0 deletions megamek/src/megamek/client/ui/swing/CustomMechDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class CustomMechDialog extends AbstractButtonDialog implements ActionList
private final JFormattedTextField txtDeploymentOffset = new JFormattedTextField(formatterFactory);
private final JFormattedTextField txtDeploymentWidth = new JFormattedTextField(formatterFactory);

private JSpinner spinStartingAnyNWx;
private JSpinner spinStartingAnyNWy;
private JSpinner spinStartingAnySEx;
private JSpinner spinStartingAnySEy;

private final JLabel labDeployShutdown = new JLabel(
Messages.getString("CustomMechDialog.labDeployShutdown"), SwingConstants.RIGHT);
private final JCheckBox chDeployShutdown = new JCheckBox();
Expand Down Expand Up @@ -473,6 +478,17 @@ private void refreshDeployment() {
txtDeploymentOffset.setText(Integer.toString(entity.getStartingOffset(false)));
txtDeploymentWidth.setText(Integer.toString(entity.getStartingWidth(false)));

int bh = clientgui.getClient().getMapSettings().getBoardHeight();
int bw = clientgui.getClient().getMapSettings().getBoardWidth();
int x = entity.getStartingAnyNWx() + 1 >= bw ? bw : entity.getStartingAnyNWx() + 1;
spinStartingAnyNWx.setValue(x);
int y = entity.getStartingAnyNWy() + 1 >= bh ? bh : entity.getStartingAnyNWy() + 1;
spinStartingAnyNWy.setValue(y);
x = entity.getStartingAnySEx() + 1 >= bw ? bw : entity.getStartingAnySEx() + 1;
spinStartingAnySEy.setValue(x);
y = entity.getStartingAnySEy() + 1 >= bh ? bh : entity.getStartingAnySEy() + 1;
spinStartingAnySEy.setValue(y);

boolean enableDeploymentZoneControls = choDeploymentZone.isEnabled() && (choDeploymentZone.getSelectedIndex() > 0);
txtDeploymentOffset.setEnabled(enableDeploymentZoneControls);
txtDeploymentWidth.setEnabled(enableDeploymentZoneControls);
Expand Down Expand Up @@ -881,6 +897,13 @@ protected void okAction() {
entity.setStartingOffset(Integer.parseInt(txtDeploymentOffset.getText()));
entity.setStartingWidth(Integer.parseInt(txtDeploymentWidth.getText()));

int x = (Integer) spinStartingAnyNWx.getValue() > (Integer) spinStartingAnySEx.getValue() ? (Integer) spinStartingAnySEx.getValue() : (Integer) spinStartingAnyNWx.getValue();
int y = (Integer) spinStartingAnyNWy.getValue() > (Integer) spinStartingAnySEy.getValue() ? (Integer) spinStartingAnySEy.getValue() : (Integer) spinStartingAnyNWy.getValue();
entity.setStartingAnyNWx(x - 1);
entity.setStartingAnyNWy(y - 1);
entity.setStartingAnySEx((Integer) spinStartingAnySEx.getValue() - 1);
entity.setStartingAnySEy((Integer) spinStartingAnySEy.getValue() - 1);

// Should the entity begin the game shutdown?
if (chDeployShutdown.isSelected() && gameOptions().booleanOption(OptionsConstants.RPG_BEGIN_SHUTDOWN)) {
entity.performManualShutdown();
Expand Down Expand Up @@ -1200,6 +1223,32 @@ protected Container createCenterPane() {
panDeploy.add(labDeploymentWidth, GBC.std());
panDeploy.add(txtDeploymentWidth, GBC.eol());

int bh = clientgui.getClient().getMapSettings().getBoardHeight();
int bw = clientgui.getClient().getMapSettings().getBoardWidth();

panDeploy.add(new JLabel("Deployment Any NW corner:"), GBC.std());
int x = entity.getStartingAnyNWx() + 1 >= bw ? bw : entity.getStartingAnyNWx() + 1;
SpinnerNumberModel mStartingAnyNWx = new SpinnerNumberModel(x, 0,bw, 1);
spinStartingAnyNWx = new JSpinner(mStartingAnyNWx);
spinStartingAnyNWx.setValue(x);
panDeploy.add(spinStartingAnyNWx, GBC.std());
int y = entity.getStartingAnyNWy() + 1 >= bh ? bh : entity.getStartingAnyNWy() + 1;
SpinnerNumberModel mStartingAnyNWy = new SpinnerNumberModel(y, 0, bh, 1);
spinStartingAnyNWy = new JSpinner(mStartingAnyNWy);
spinStartingAnyNWy.setValue(y);
panDeploy.add(spinStartingAnyNWy, GBC.eol());
panDeploy.add(new JLabel("Deployment Any SE corner:"), GBC.std());
x = entity.getStartingAnySEx() + 1 >= bw ? bw : entity.getStartingAnySEx() + 1;
SpinnerNumberModel mStartingAnySEx = new SpinnerNumberModel(x, 0, bw, 1);
spinStartingAnySEx = new JSpinner(mStartingAnySEx);
spinStartingAnySEx.setValue(x);
panDeploy.add(spinStartingAnySEx, GBC.std());
y = entity.getStartingAnySEy() + 1 >= bh ? bh : entity.getStartingAnySEy() + 1;
SpinnerNumberModel mStartingAnySEy = new SpinnerNumberModel(y, -0, bh, 1);
spinStartingAnySEy = new JSpinner(mStartingAnySEy);
spinStartingAnySEy.setValue(y);
panDeploy.add(spinStartingAnySEy, GBC.eol());

numFormatter.setMinimum(0);
numFormatter.setCommitsOnValidEdit(true);

Expand Down
16 changes: 16 additions & 0 deletions megamek/src/megamek/client/ui/swing/MapDimensionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.MapSettings;

import javax.swing.*;
Expand Down Expand Up @@ -281,6 +282,21 @@ private void apply() {
mapSettings.setBoardSize(boardWidth, boardHeight);
mapSettings.setMapSize(mapWidth, mapHeight);
clientGUI.getClient().sendMapDimensions(mapSettings);

for (Entity entity : clientGUI.getClient().getGame().getEntitiesVector()) {
if (entity.getStartingAnyNWx() >= boardWidth) {
entity.setStartingAnyNWx(boardWidth - 1);
}
if (entity.getStartingAnyNWy() >= boardHeight) {
entity.setStartingAnyNWy(boardHeight - 1);
}
if (entity.getStartingAnySEx() >= boardWidth) {
entity.setStartingAnySEx(boardWidth - 1);
}
if (entity.getStartingAnySEy() >= boardHeight) {
entity.setStartingAnySEy(boardHeight - 1);
}
}
}


Expand Down
4 changes: 4 additions & 0 deletions megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,10 @@ public void configPlayer() {
player.setStartingPos(startPos);
player.setStartOffset(psd.getStartOffset());
player.setStartWidth(psd.getStartWidth());
player.setStartingAnyNWx(psd.getStartingAnyNWx());
player.setStartingAnyNWy(psd.getStartingAnyNWy());
player.setStartingAnySEx(psd.getStartingAnySEx());
player.setStartingAnySEy(psd.getStartingAnySEy());
c.sendPlayerInfo();

// If the gameoption set_arty_player_homeedge is set, adjust the player's offboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ static String formatUnitFull(Entity entity, ChatLounge lobby, boolean forceView)
}
String msg_start = Messages.getString("ChatLounge.Start");
result.append(" " + msg_start + ":" + IStartingPositions.START_LOCATION_NAMES[sp]);
if (sp == 0) {
int NWx = entity.getStartingAnyNWx() + 1;
int NWy = entity.getStartingAnyNWy() + 1;
int SEx = entity.getStartingAnySEx() + 1;
int SEy = entity.getStartingAnySEy() + 1;
if ((NWx + NWy + SEx + SEy) > 0) {
result.append("(" + NWx + ", " + NWy + ")-(" + SEx + ", " + SEy + ")");
}
}
int so = entity.getStartingOffset(true);
int sw = entity.getStartingWidth(true);
if ((so != 0) || (sw != 3)) {
Expand Down
15 changes: 13 additions & 2 deletions megamek/src/megamek/client/ui/swing/lobby/LobbyUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ static boolean isValidStartPos(Game game, Player player, int pos) {
if (!isExclusiveDeployment(game)) {
return true;
} else {
final GameOptions gOpts = game.getOptions();
List<Player> players = game.getPlayersList();

if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0) && !player.isBot() && player.getId() != 0) {
return true;
}

if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0)) {
players = players.stream().filter(p -> p.isBot() || p.getId() == 0).collect(Collectors.toList());
}

if (isTeamsShareVision(game)) {
return game.getPlayersVector().stream().filter(p -> p.isEnemyOf(player))
return players.stream().filter(p -> p.isEnemyOf(player))
.noneMatch(p -> startPosOverlap(pos, p.getStartingPos()));
} else {
return game.getPlayersVector().stream().filter(p -> !p.equals(player))
return players.stream().filter(p -> !p.equals(player))
.noneMatch(p -> startPosOverlap(pos, p.getStartingPos()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@
return currentPlayerStartPos;
}

public int getStartingAnyNWx() {
return (Integer) spinStartingAnyNWx.getValue() - 1;
}

public int getStartingAnyNWy() {
return (Integer) spinStartingAnyNWy.getValue() - 1;
}

public int getStartingAnySEx() {
return (Integer) spinStartingAnySEx.getValue() - 1;
}

public int getStartingAnySEy() {
return (Integer) spinStartingAnySEy.getValue() - 1;
}

/**
* @return the current {@link SkillGenerationOptionsPanel}
*/
Expand Down Expand Up @@ -167,6 +183,10 @@
private final DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(numFormatter);
private final JFormattedTextField txtOffset = new JFormattedTextField(formatterFactory, 0);
private final JFormattedTextField txtWidth = new JFormattedTextField(formatterFactory, 3);
private JSpinner spinStartingAnyNWx;
private JSpinner spinStartingAnyNWy;
private JSpinner spinStartingAnySEx;
private JSpinner spinStartingAnySEy;

// Bot Settings Section
private final JButton butBotSettings = new JButton(Messages.getString("PlayerSettingsDialog.botSettings"));
Expand Down Expand Up @@ -248,7 +268,17 @@
result.add(txtOffset, GBC.eol());
result.add(lblWidth, GBC.std());
result.add(txtWidth, GBC.eol());


int bh = clientgui.getClient().getMapSettings().getBoardHeight();
Fixed Show fixed Hide fixed
int bw = clientgui.getClient().getMapSettings().getBoardWidth();
Fixed Show fixed Hide fixed

result.add(new JLabel("Deployment Any NW corner:"), GBC.std());
result.add(spinStartingAnyNWx, GBC.std());
result.add(spinStartingAnyNWy, GBC.eol());
result.add(new JLabel("Deployment Any SE corner:"), GBC.std());
result.add(spinStartingAnySEx, GBC.std());
result.add(spinStartingAnySEy, GBC.eol());

return result;
}

Expand Down Expand Up @@ -309,7 +339,27 @@
fldEmail.setText(player.getEmail());
txtWidth.setText(Integer.toString(player.getStartWidth()));
txtOffset.setText(Integer.toString(player.getStartOffset()));


int bh = clientgui.getClient().getMapSettings().getBoardHeight();
int bw = clientgui.getClient().getMapSettings().getBoardWidth();

SpinnerNumberModel mStartingAnyNWx = new SpinnerNumberModel(0, 0,bw, 1);
spinStartingAnyNWx = new JSpinner(mStartingAnyNWx);
SpinnerNumberModel mStartingAnyNWy = new SpinnerNumberModel(0, 0, bh, 1);
spinStartingAnyNWy = new JSpinner(mStartingAnyNWy);
SpinnerNumberModel mStartingAnySEx = new SpinnerNumberModel(0, 0, bw, 1);
spinStartingAnySEx = new JSpinner(mStartingAnySEx);
SpinnerNumberModel mStartingAnySEy = new SpinnerNumberModel(0, -0, bh, 1);
spinStartingAnySEy = new JSpinner(mStartingAnySEy);

int x = player.getStartingAnyNWx() + 1 >= bw ? bw : player.getStartingAnyNWx() + 1;
spinStartingAnyNWx.setValue(x);
int y = player.getStartingAnyNWy() + 1 >= bh ? bh : player.getStartingAnyNWy() + 1;
spinStartingAnyNWy.setValue(y);
x = player.getStartingAnySEx() + 1 >= bw ? bw : player.getStartingAnySEx() + 1;
spinStartingAnySEx.setValue(x);
y = player.getStartingAnySEy() + 1 >= bh ? bh : player.getStartingAnySEy() + 1;
spinStartingAnySEy.setValue(y);
}

private void setupStartGrid() {
Expand Down
16 changes: 15 additions & 1 deletion megamek/src/megamek/client/ui/swing/lobby/PlayerTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.IStartingPositions;
import megamek.common.Player;
import megamek.common.options.GameOptions;
import megamek.common.options.OptionsConstants;

import javax.swing.*;
Expand Down Expand Up @@ -195,8 +196,21 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
result.append(guiScaledFontHTML());

String msg_start = Messages.getString("ChatLounge.Start");
if ((player.getStartingPos() >= 0) && (player.getStartingPos() <= IStartingPositions.START_LOCATION_NAMES.length)) {

final GameOptions gOpts = lobby.game().getOptions();
if (gOpts.booleanOption(OptionsConstants.BASE_SET_PLAYER_DEPLOYMENT_TO_PLAYER0) && !player.isBot() && player.getId() != 0) {
result.append(msg_start + ": " + Messages.getString("ChatLounge.Player0"));
} else if ((player.getStartingPos() >= 0) && (player.getStartingPos() <= IStartingPositions.START_LOCATION_NAMES.length)) {
result.append(msg_start + ": " + IStartingPositions.START_LOCATION_NAMES[player.getStartingPos()]);
if (player.getStartingPos() == 0) {
int NWx = player.getStartingAnyNWx() + 1;
int NWy = player.getStartingAnyNWy() + 1;
int SEx = player.getStartingAnySEx() + 1;
int SEy = player.getStartingAnySEy() + 1;
if ((NWx + NWy + SEx + SEy) > 0) {
result.append("(" + NWx + ", " + NWy + ")-(" + SEx + ", " + SEy + ")");
}
}
int so = player.getStartOffset();
int sw = player.getStartWidth();
if ((so != 0) || (sw != 3)) {
Expand Down
11 changes: 7 additions & 4 deletions megamek/src/megamek/common/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public static boolean isValid(String board) {
* Can the given player deploy at these coordinates?
*/
public boolean isLegalDeployment(Coords c, Player p) {
return isLegalDeployment(c, p.getStartingPos(), p.getStartWidth(), p.getStartOffset());
return isLegalDeployment(c, p.getStartingPos(), p.getStartWidth(), p.getStartOffset(), p.getStartingAnyNWx(), p.getStartingAnyNWy(), p.getStartingAnySEx(), p.getStartingAnySEy());
}

/**
Expand All @@ -857,13 +857,13 @@ public boolean isLegalDeployment(Coords c, Entity e) {
return false;
}

return isLegalDeployment(c, e.getStartingPos(), e.getStartingWidth(), e.getStartingOffset());
return isLegalDeployment(c, e.getStartingPos(), e.getStartingWidth(), e.getStartingOffset(), e.getStartingAnyNWx(), e.getStartingAnyNWy(), e.getStartingAnySEx(), e.getStartingAnySEy());
}

/**
* Can an object be deployed at these coordinates, given a starting zone, width of starting zone and offset from edge of board?
*/
public boolean isLegalDeployment(Coords c, int zoneType, int startingWidth, int startingOffset) {
public boolean isLegalDeployment(Coords c, int zoneType, int startingWidth, int startingOffset, int startingAnyNWx, int startingAnyNWy, int startingAnySEx, int startingAnySEy) {
if ((c == null) || !contains(c)) {
return false;
}
Expand All @@ -876,7 +876,10 @@ public boolean isLegalDeployment(Coords c, int zoneType, int startingWidth, int

switch (zoneType) {
case START_ANY:
return true;
return (((startingAnyNWx == -1) || (c.getX() >= startingAnyNWx))
&& ((startingAnySEx == -1) || (c.getX() <= startingAnySEx))
&& ((startingAnyNWy == -1) || (c.getY() >= startingAnyNWy))
&& ((startingAnySEy == -1) || (c.getY() <= startingAnySEy)));
case START_NW:
return ((c.getX() < (minx + nLimit)) && (c.getX() >= minx) && (c.getY() >= miny) && (c.getY() < (height / 2)))
|| ((c.getY() < (miny + nLimit)) && (c.getY() >= miny) && (c.getX() >= minx) && (c.getX() < (width / 2)));
Expand Down
Loading