Skip to content

Commit

Permalink
add option for GM control over done in report phases
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Aug 1, 2023
1 parent 00e4c51 commit d092619
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 2 additions & 0 deletions megamek/i18n/megamek/common/options/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ GameOptionsInfo.option.full_rotor_hits.displayableName=(Unofficial) No reduced d
GameOptionsInfo.option.full_rotor_hits.description=If checked, VTOLs will take full damage from a rotor hit instead of Total Warfare-style reduced damage. \nUnchecked by default.
GameOptionsInfo.option.suppress_unit_tooltip_in_report_log.displayableName=Hide Unit Tooltip in report log
GameOptionsInfo.option.suppress_unit_tooltip_in_report_log.description=If checked, Unit Tooltip will not show in the end phase on the report log
GameOptionsInfo.option.gm_controls_done_report_phase.displayableName=GM controls done button in the report phases
GameOptionsInfo.option.gm_controls_done_report_phase.description=If checked, other player are automatically set to done in report phases. GM has control even if they have no units.
GameOptionsInfo.option.hide_unofficial.displayableName=Don't show unofficial game options
GameOptionsInfo.option.hide_unofficial.description=If checked, unofficial game options will be deactivated and hidden
GameOptionsInfo.option.hide_legacy.displayableName=Don't show legacy game options
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ReportDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void actionPerformed(ActionEvent ev) {
}

private void resetButtons() {
butDone.setEnabled(true);
butDone.setEnabled(!clientgui.getClient().getLocalPlayer().isDone());
setReportEnabled(true);
setPlayerListEnabled(true);

Expand Down
1 change: 1 addition & 0 deletions megamek/src/megamek/common/options/GameOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public synchronized void initialize() {
addOption(base, OptionsConstants.BASE_AUTO_AMS, true);
addOption(base, OptionsConstants.BASE_TURN_TIMER, 0);
addOption(base, OptionsConstants.BASE_SUPPRESS_UNIT_TOOLTIP_IN_REPORT_LOG, false);
addOption(base, OptionsConstants.BASE_GM_CONTROLS_DONE_REPORT_PHASE, false);
addOption(base, OptionsConstants.BASE_HIDE_UNOFFICIAL, false);
addOption(base, OptionsConstants.BASE_HIDE_LEGACY, false);

Expand Down
1 change: 1 addition & 0 deletions megamek/src/megamek/common/options/OptionsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public class OptionsConstants {
public static final String BASE_RANDOM_BASEMENTS = "random_basements";
public static final String BASE_AUTO_AMS = "auto_ams";
public static final String BASE_SUPPRESS_UNIT_TOOLTIP_IN_REPORT_LOG = "suppress_unit_tooltip_in_report_log";
public static final String BASE_GM_CONTROLS_DONE_REPORT_PHASE = "gm_controls_done_report_phase";
public static final String BASE_HIDE_UNOFFICIAL = "hide_unofficial";
public static final String BASE_HIDE_LEGACY = "hide_legacy";

Expand Down
44 changes: 25 additions & 19 deletions megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public void resetGame() {

// reset all players
resetPlayersDone();
transmitAllPlayerDones();

// Write end of game to stdout so controlling scripts can rotate logs.
LogManager.getLogger().info(LocalDateTime.now() + " END OF GAME");
Expand Down Expand Up @@ -660,7 +659,8 @@ public void sendCurrentInfo(int connId) {
} else {
send(connId, createFullEntitiesPacket());
}
player.setDone(getGame().getEntitiesOwnedBy(player) <= 0);

setPlayerDone(player, getGame().getEntitiesOwnedBy(player) <= 0);
send(connId, new Packet(PacketCommand.PHASE_CHANGE, getGame().getPhase()));
}

Expand Down Expand Up @@ -811,7 +811,6 @@ public void handlePacket(int connId, Packet packet) {
case ENTITY_LOAD:
receiveEntityLoad(packet, connId);
resetPlayersDone();
transmitAllPlayerDones();
break;
case ENTITY_MODECHANGE:
receiveEntityModeChange(packet, connId);
Expand Down Expand Up @@ -863,7 +862,6 @@ public void handlePacket(int connId, Packet packet) {
case SENDING_GAME_SETTINGS:
if (receiveGameOptions(packet, connId)) {
resetPlayersDone();
transmitAllPlayerDones();
send(createGameSettingsPacket());
receiveGameOptionsAux(packet, connId);
}
Expand All @@ -880,7 +878,6 @@ public void handlePacket(int connId, Packet packet) {
mapSettings.setNullBoards(DEFAULT_BOARD);
game.setMapSettings(mapSettings);
resetPlayersDone();
transmitAllPlayerDones();
send(createMapSettingsPacket());
}
break;
Expand All @@ -896,7 +893,6 @@ public void handlePacket(int connId, Packet packet) {
mapSettings.setNullBoards(DEFAULT_BOARD);
game.setMapSettings(mapSettings);
resetPlayersDone();
transmitAllPlayerDones();
send(createMapSettingsPacket());
}
break;
Expand All @@ -906,7 +902,6 @@ public void handlePacket(int connId, Packet packet) {
sendServerChat(player + " changed planetary conditions");
game.setPlanetaryConditions(conditions);
resetPlayersDone();
transmitAllPlayerDones();
send(createPlanetaryConditionsPacket());
}
break;
Expand All @@ -919,12 +914,10 @@ public void handlePacket(int connId, Packet packet) {
case CUSTOM_INITIATIVE:
receiveCustomInit(packet, connId);
resetPlayersDone();
transmitAllPlayerDones();
break;
case SQUADRON_ADD:
receiveSquadronAdd(packet, connId);
resetPlayersDone();
transmitAllPlayerDones();
break;
case RESET_ROUND_DEPLOYMENT:
game.setupRoundDeployment();
Expand Down Expand Up @@ -1129,6 +1122,20 @@ public void decrementASEWTurns() {
}
}

private void setPlayerDone(Player player, boolean normalDone) {
if (getGame().getPhase().isReport()
&& getGame().getOptions().booleanOption(OptionsConstants.BASE_GM_CONTROLS_DONE_REPORT_PHASE)
&& getGame().getPlayersList().stream().filter(p -> p.isGameMaster()).count() > 0) {
if (player.isGameMaster()) {
player.setDone(false);
} else {
player.setDone(true);
}
} else {
player.setDone(normalDone);
}
}

/**
* Called at the beginning of certain phases to make every player not ready.
*/
Expand All @@ -1137,10 +1144,10 @@ private void resetPlayersDone() {
return;
}

for (Enumeration<Player> i = game.getPlayers(); i.hasMoreElements(); ) {
final Player player = i.nextElement();
player.setDone(false);
for (Player player : game.getPlayersList()) {
setPlayerDone(player, false);
}

transmitAllPlayerDones();
}

Expand All @@ -1149,10 +1156,10 @@ private void resetPlayersDone() {
* ready.
*/
private void resetActivePlayersDone() {
for (Enumeration<Player> i = game.getPlayers(); i.hasMoreElements(); ) {
final Player player = i.nextElement();
player.setDone(game.getEntitiesOwnedBy(player) <= 0);
for (Player player : game.getPlayersList()) {
setPlayerDone(player, getGame().getEntitiesOwnedBy(player) <= 0);
}

transmitAllPlayerDones();
}

Expand Down Expand Up @@ -1342,8 +1349,7 @@ public void forceVictory(Player victor) {
*/
private void checkReady() {
// check if all active players are done
for (Enumeration<Player> i = game.getPlayers(); i.hasMoreElements(); ) {
final Player player = i.nextElement();
for (Player player : game.getPlayersList()) {
if (!player.isGhost() && !player.isObserver() && !player.isDone()) {
return;
}
Expand Down Expand Up @@ -29935,6 +29941,7 @@ private void receiveInitiativeRerollRequest(Packet pkt, int connIndex) {
if (null != player) {
player.setDone(true);
}

checkReady();
}

Expand Down Expand Up @@ -30249,8 +30256,7 @@ private Packet createEndOfGamePacket() {
* Sends out the player ready stats for all players to all connections
*/
private void transmitAllPlayerDones() {
for (Enumeration<Player> i = getGame().getPlayers(); i.hasMoreElements(); ) {
final Player player = i.nextElement();
for (Player player : getGame().getPlayersList()) {
send(createPlayerDonePacket(player.getId()));
}
}
Expand Down

0 comments on commit d092619

Please sign in to comment.