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/tinkering princess ai [wip] #5569

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 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
4 changes: 4 additions & 0 deletions MekHQ/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ plugins {
id 'org.ec4j.editorconfig' version '0.1.0'
}

repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
2 changes: 2 additions & 0 deletions MekHQ/resources/mekhq/resources/CampaignGUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ miMassPersonnelTraining.toolTipText=This launches the Mass Personnel Training Di
miScenarioEditor.text=Scenario Template Editor...
miCompanyGenerator.text=Company Generator...
miAutoResolveBehaviorSettings.text=Auto Resolve Behavior Settings
miAiEditor.text=AI Editor
miAiEditor.tooltip=Opens the utility AI editor

# Help Menu
menuHelp.text=Help
Expand Down
1 change: 1 addition & 0 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@ RandomOriginOptionsPanel.InvalidSpecifiedPlanet.text=You must select a valid spe
btnNewCampaign.text=New Campaign
btnLoadCampaign.text=Load Campaign
btnLoadLastCampaign.text=Load Last Save
btnAiEditor.text=AI Editor
btnLoadStoryArc.text=Story Arcs


Expand Down
4 changes: 3 additions & 1 deletion MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import megamek.client.bot.princess.BehaviorSettings;
import megamek.client.bot.princess.Princess;
import megamek.client.bot.princess.PrincessException;
import megamek.client.bot.queen.Queen;
import megamek.client.bot.queen.ai.utility.tw.TWUtilityAIRepository;
import megamek.client.generator.RandomCallsignGenerator;
import megamek.client.ui.swing.ClientGUI;
import megamek.client.ui.swing.CommanderGUI;
Expand Down Expand Up @@ -544,7 +546,7 @@
var botName = player.getName() + "@AI";

Thread.sleep(MekHQ.getMHQOptions().getStartGameBotClientDelay());
var botClient = new Princess(botName, client.getHost(), client.getPort());
var botClient = new Queen(botName, client.getHost(), client.getPort(), TWUtilityAIRepository.getInstance().reloadRepository().getProfiles().get(0));

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable ' botClient' is never read.
botClient.setBehaviorSettings(autoResolveBehaviorSettings.getCopy());
try {
botClient.connect();
Expand Down
14 changes: 14 additions & 0 deletions MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import megamek.client.ui.swing.GameOptionsDialog;
import megamek.client.ui.swing.MMToggleButton;
import megamek.client.ui.swing.UnitLoadingDialog;
import megamek.client.ui.swing.ai.editor.AiProfileEditor;
import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog;
import megamek.client.ui.swing.util.MegaMekController;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.annotations.Nullable;
Expand Down Expand Up @@ -978,6 +980,18 @@

menuManage.add(miAutoResolveBehaviorEditor);

JMenuItem miAiEditor = new JMenuItem(resourceMap.getString("miAiEditor.text"));
miAiEditor.setToolTipText(resourceMap.getString("miAiEditor.tooltip"));
miAiEditor
.addActionListener(evt -> {
SwingUtilities.invokeLater(() -> {
MegaMekController controller = new MegaMekController();

Check warning

Code scanning / CodeQL

Expression always evaluates to the same value Warning

Expression always evaluates to the same value.
controller.aiEditor = new AiProfileEditor(controller);
});
});

menuManage.add(miAiEditor);

menuBar.add(menuManage);
// endregion Manage Campaign Menu

Expand Down
2 changes: 2 additions & 0 deletions MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package mekhq.gui.dialog;

import megamek.client.bot.queen.ai.utility.tw.TWUtilityAIRepository;
import megamek.client.generator.RandomCallsignGenerator;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.swing.util.UIUtil;
Expand Down Expand Up @@ -262,6 +263,7 @@ public Campaign doInBackground() throws Exception {
// region Progress 1
setProgress(1);
Factions.setInstance(Factions.loadDefault());
TWUtilityAIRepository.getInstance().reloadRepository();
// endregion Progress 1

// region Progress 2
Expand Down
27 changes: 26 additions & 1 deletion MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package mekhq.gui.panels;

import megamek.client.ui.swing.ai.editor.AiProfileEditor;
import megamek.client.ui.swing.util.MegaMekController;
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.widget.MegaMekButton;
import megamek.client.ui.swing.widget.SkinSpecification;
Expand Down Expand Up @@ -146,13 +148,28 @@
});

MegaMekButton btnLoadLastCampaign = new MegaMekButton(resources.getString("btnLoadLastCampaign.text"),
UIComponents.MainMenuButton.getComp(), true);
UIComponents.MainMenuButton.getComp(), true);
btnLoadLastCampaign.setEnabled(lastSaveFile != null);
btnLoadLastCampaign.addActionListener(evt -> {
btnLoadLastCampaign.setEnabled(false);
startCampaign(lastSaveFile);
});

MegaMekButton btnOpenAiEditor = new MegaMekButton(resources.getString("btnAiEditor.text"),
UIComponents.MainMenuButton.getComp(), true);
Comment on lines +158 to +159

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'MegaMekButton btnOpenAiEditor' is never read.
btnOpenAiEditor.addActionListener(evt -> {
btnOpenAiEditor.setEnabled(false);

SwingUtilities.invokeLater(() -> {
try {
showAiEditor();
} finally {
btnOpenAiEditor.setEnabled(true);
}
});

});

MegaMekButton btnLoadStoryArc = new MegaMekButton(resources.getString("btnLoadStoryArc.text"),
UIComponents.MainMenuButton.getComp(), true);
btnLoadStoryArc.addActionListener(evt -> {
Expand Down Expand Up @@ -195,6 +212,7 @@
btnLoadLastCampaign.setPreferredSize(minButtonDim);
btnLoadStoryArc.setMinimumSize(minButtonDim);
btnLoadStoryArc.setPreferredSize(minButtonDim);
btnOpenAiEditor.setMinimumSize(minButtonDim);
btnQuit.setMinimumSize(minButtonDim);
btnQuit.setPreferredSize(minButtonDim);

Expand Down Expand Up @@ -234,6 +252,8 @@
c.gridy++;
add(btnLoadStoryArc, c);
c.gridy++;
add(btnOpenAiEditor, c);
c.gridy++;
add(btnQuit, c);

getFrame().setResizable(false);
Expand All @@ -258,6 +278,11 @@
startCampaign(file, null);
}

private void showAiEditor() {
MegaMekController controller = new MegaMekController();
controller.aiEditor = new AiProfileEditor(controller);

Check warning

Code scanning / CodeQL

Expression always evaluates to the same value Warning

Expression always evaluates to the same value.
}

private void startCampaign(final @Nullable File file, @Nullable StoryArcStub storyArcStub) {
new DataLoadingDialog(getFrame(), app, file, storyArcStub, false).setVisible(true);
}
Expand Down
Loading