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

feat: Allows GM to control any bot in the game #6223

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
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
55 changes: 32 additions & 23 deletions megamek/src/megamek/client/ui/swing/MapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.swing.*;

import megamek.client.Client;
import megamek.client.bot.princess.CardinalEdge;
import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.gmCommands.GamemasterCommandPanel;
Expand Down Expand Up @@ -415,28 +416,26 @@ private JMenu createSpecialHexDisplayMenu() {
*/
private JMenu createPleaToRoyaltyMenu() {
JMenu menu = new JMenu(Messages.getString("Bot.commands.title"));

var isGM = client.getLocalPlayer().isGameMaster();
for (var player : client.getGame().getPlayersList()) {
if (!player.isEnemyOf(client.getLocalPlayer()) && player.isBot()) {
var isEnemy = player.isEnemyOf(client.getLocalPlayer());
var playerIsBot = player.isBot();
if (playerIsBot && (!isEnemy || isGM)) {
menu.add(createBotCommands(player));
}
}
return menu;
}

private JMenu createBotCommands(Player bot) {
JMenu menu = new JMenu(bot.getName());
JMenu menu = new JMenu(bot.getName() + " (" + Player.TEAM_NAMES[bot.getTeam()] + ")");

JMenu targetHexMenu = new JMenu(Messages.getString("Bot.commands.targetHex"));
JMenu prioritizeTargetUnitMenu = new JMenu(Messages.getString("Bot.commands.priority"));
JMenu ignoreTargetMenu= new JMenu(Messages.getString("Bot.commands.ignore"));

JMenu fleeMenu = new JMenu(Messages.getString("Bot.commands.flee"));
JMenu fleeMenu = createFleeMenu(bot);
JMenu behaviorMenu = createBehaviorMenu(bot);


behaviorMenu.add(createBehaviorMenu(bot));
fleeMenu.add(createFleeMenu(bot));
targetHexMenu.add(createTargetHexMenuItem(bot));
menu.add(targetHexMenu);

Expand Down Expand Up @@ -565,23 +564,33 @@ JMenu createCautionMenu(Player bot) {
}


JMenuItem createFleeMenu(Player bot) {
JMenuItem item = new JMenuItem(Messages.getString("Bot.commands.flee.text"));
item.addActionListener(evt -> {
int confirm = JOptionPane.showConfirmDialog(
gui.getFrame(),
Messages.getString("Bot.commands.flee.confirmation", bot.getName()),
Messages.getString("Bot.commands.flee.confirm"),
JOptionPane.YES_NO_OPTION);
JMenu createFleeMenu(Player bot) {
JMenu menu = new JMenu(Messages.getString("Bot.commands.flee"));
menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.northEdge")), bot, CardinalEdge.NORTH));
menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.southEdge")), bot, CardinalEdge.SOUTH));
menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.westEdge")), bot, CardinalEdge.WEST));
menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.eastEdge")), bot, CardinalEdge.EAST));
menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.nearestEdge")), bot, CardinalEdge.NEAREST));
return menu;
}

if (confirm == JOptionPane.YES_OPTION) {
client.sendChat(String.format("%s: flee",
bot.getName()
));
}
private JMenuItem setFleeAction(JMenuItem fleeMenuItem, Player bot, CardinalEdge cardinalEdge) {
fleeMenuItem.addActionListener(evt -> {
int confirm = JOptionPane.showConfirmDialog(
gui.getFrame(),
Messages.getString("Bot.commands.flee.confirmation", bot.getName()),
Messages.getString("Bot.commands.flee.confirm"),
JOptionPane.YES_NO_OPTION);

if (confirm == JOptionPane.YES_OPTION) {
client.sendChat(String.format("%s: flee : %d",
bot.getName(),
cardinalEdge.getIndex()
));
}
);
return item;
});

return fleeMenuItem;
}

JMenuItem createIgnoreTargetUnitMenu(Player bot, Entity entity) {
Expand Down