Skip to content

Commit

Permalink
feat: fire fight arguments added
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Nov 16, 2024
1 parent a4c6b6a commit 50d7c13
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 5 deletions.
10 changes: 9 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4710,4 +4710,12 @@ Gamemaster.cmd.orbitalbombardment.help=Calls an orbital bombardment on the board
Gamemaster.cmd.orbitalbombardment.dmg=Total damage at target hex.
Gamemaster.cmd.orbitalbombardment.radius=Radius of the bombardment.
Gamemaster.cmd.orbitalbombardment.error.outofbounds=Specified hex is not on the board.
Gamemaster.cmd.orbitalbombardment.success=Orbital bombardment incoming!
Gamemaster.cmd.orbitalbombardment.success=Orbital bombardment incoming!
# Firefight
Gamemaster.cmd.firefight.longName=Firefight
Gamemaster.cmd.firefight.reason=Fire extinguished
Gamemaster.cmd.firefight.help=Extinguishes a fire on the board.
# No Fire
Gamemaster.cmd.nofire.longName=No Fires
Gamemaster.cmd.nofire.help=Extinguishes all fires on the board.

10 changes: 6 additions & 4 deletions megamek/src/megamek/client/ui/swing/MapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,16 @@ private JMenu createGamemasterMenu() {
private JMenu createGMSpecialCommandsMenu() {
JMenu menu = new JMenu(Messages.getString("Gamemaster.SpecialCommands"));
List.of(
new KillCommand(null, null),
new OrbitalBombardmentCommand(null, null),
new ChangeOwnershipCommand(null, null),
new ChangeWeatherCommand(null, null),
new DisasterCommand(null, null),
new KillCommand(null, null),
new FirefightCommand(null, null),
new FirestarterCommand(null, null),
new FirestormCommand(null, null),
new RemoveSmokeCommand(null, null),
new ChangeWeatherCommand(null, null)
new NoFiresCommand(null, null),
new OrbitalBombardmentCommand(null, null),
new RemoveSmokeCommand(null, null)
).forEach(cmd -> {
JMenuItem item = new JMenuItem(cmd.getLongName());
item.addActionListener(evt -> new GamemasterCommandPanel(gui.getFrame(), gui, cmd).setVisible(true));
Expand Down
77 changes: 77 additions & 0 deletions megamek/src/megamek/server/commands/FirefightCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* MegaMek - Copyright (c) 2024 - 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.server.commands;

import megamek.client.ui.Messages;
import megamek.common.Coords;
import megamek.common.Hex;
import megamek.server.Server;
import megamek.server.commands.arguments.Argument;
import megamek.server.commands.arguments.IntegerArgument;
import megamek.server.totalwarfare.TWGameManager;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* The Server Command "/firefight" that will put one hex on fire.
*
* @author Luana Coppio
*/
public class FirefightCommand extends GamemasterServerCommand {

private static final String FIRESTARTER = "firefight";
private static final String X = "x";
private static final String Y = "y";
private static final String TYPE = "type";

public FirefightCommand(Server server, TWGameManager gameManager) {
super(server,
gameManager,
FIRESTARTER,
Messages.getString("Gamemaster.cmd.firefight.help"),
Messages.getString("Gamemaster.cmd.firefight.longName"));
}

@Override
public List<Argument<?>> defineArguments() {
return List.of(
new IntegerArgument(X, Messages.getString("Gamemaster.cmd.x")),
new IntegerArgument(Y, Messages.getString("Gamemaster.cmd.y"))
);
}

/**
* Run this command with the arguments supplied
*
* @see ServerCommand#run(int, String[])
*/
@Override
protected void runAsGM(int connId, Map<String, Argument<?>> args) {
int xArg = (int) args.get(X).getValue() - 1;
int yArg = (int) args.get(Y).getValue() - 1;
firefight(new Coords(xArg, yArg));
}

private void firefight(Coords coords) {
try {
Hex hex = gameManager.getGame().getBoard().getHex(coords);
Objects.requireNonNull(hex, "Hex not found.");
gameManager.removeFire(coords, Messages.getString("Gamemaster.cmd.firefight.reason"));
} catch (Exception e) {
throw new IllegalArgumentException("Failed to ignite hex: " + e.getMessage());
}
}
}
87 changes: 87 additions & 0 deletions megamek/src/megamek/server/commands/NoFiresCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* MegaMek - Copyright (c) 2024 - 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.server.commands;

import megamek.client.ui.Messages;
import megamek.common.Coords;
import megamek.common.Hex;
import megamek.server.Server;
import megamek.server.commands.arguments.Argument;
import megamek.server.commands.arguments.IntegerArgument;
import megamek.server.totalwarfare.TWGameManager;

import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
* The Server Command "/nofires" removes all fires on the board.
*
* @author Luana Coppio
*/
public class NoFiresCommand extends GamemasterServerCommand {

private final String reason;

public NoFiresCommand(Server server, TWGameManager gameManager) {
super(server,
gameManager,
"nofires",
Messages.getString("Gamemaster.cmd.nofire.help"),
Messages.getString("Gamemaster.cmd.nofire.longName"));
this.reason = Messages.getString("Gamemaster.cmd.firefight.reason");
}

@Override
public List<Argument<?>> defineArguments() {
return List.of();
}

/**
* Run this command with the arguments supplied
*
* @see ServerCommand#run(int, String[])
*/
@Override
protected void runAsGM(int connId, Map<String, Argument<?>> args) {
try {
getAllCoords().forEach(this::firefight);
} catch (Exception e) {
logger.error(Messages.getString("Gamemaster.cmd.fire.failed"), e);
server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.fire.failed"));
}
}

private HashSet<Coords> getAllCoords() {
var boardHeight = gameManager.getGame().getBoard().getHeight();
var boardWidth = gameManager.getGame().getBoard().getWidth();
var coordsSet = new HashSet<Coords>();
for (int x = 0; x < boardWidth; x++) {
for (int y = 0; y < boardHeight; y++) {
coordsSet.add(new Coords(x, y));
}
}
return coordsSet;
}

private void firefight(Coords coords) {
Hex hex = gameManager.getGame().getBoard().getHex(coords);
if (null == hex) {
// Just ignore null hexes...
// they should not happen, but I don't want to crash the command
return;
}
gameManager.removeFire(coords, reason);
}
}
2 changes: 2 additions & 0 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public List<ServerCommand> getCommandList(Server server) {
commands.add(new ChangeOwnershipCommand(server, this));
commands.add(new DisasterCommand(server, this));
commands.add(new FirestarterCommand(server, this));
commands.add(new NoFiresCommand(server, this));
commands.add(new FirefightCommand(server, this));
commands.add(new FirestormCommand(server, this));
commands.add(new RemoveSmokeCommand(server, this));
commands.add(new ChangeWeatherCommand(server, this));
Expand Down

0 comments on commit 50d7c13

Please sign in to comment.