Skip to content

Commit

Permalink
Merge branch 'master' into toe_selectionBug
Browse files Browse the repository at this point in the history
  • Loading branch information
IllianiCBT committed Jan 15, 2025
2 parents d766831 + ae958c7 commit 7bc7bb5
Show file tree
Hide file tree
Showing 19 changed files with 459 additions and 72 deletions.
Binary file added MekHQ/data/images/misc/acar_splash_hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions MekHQ/data/scenariomodifiers/airBattleModifiers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
Need ability to allow player to specifically deploy DropShips
HotDrop.xml
</modifier-->
<modifier>
<!--modifier>
Removed by popular demand
EnemyDropShip.xml
</modifier>
</modifier-->
<modifier>
GoodIntel.xml
</modifier>
Expand Down
10 changes: 6 additions & 4 deletions MekHQ/data/scenariomodifiers/groundBattleModifiers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
<modifier>
EnemyHotDrop.xml
</modifier>
<modifier>
<!--modifier>
Removed by popular demand
EnemyDropShip.xml
</modifier>
<modifier>
</modifier-->
<!--modifier>
Removed by popular demand
GroundedEnemyDropShip.xml
</modifier>
</modifier-->
<modifier>
GoodIntel.xml
</modifier>
Expand Down
10 changes: 6 additions & 4 deletions MekHQ/data/scenariomodifiers/modifiermanifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
<modifier>
EnemyHotDrop.xml
</modifier>
<modifier>
<!--modifier>
Removed by popular demand
EnemyDropShip.xml
</modifier>
<modifier>
</modifier-->
<!--modifier>
Removed by popular demand
GroundedEnemyDropShip.xml
</modifier>
</modifier!-->
<modifier>
GoodIntel.xml
</modifier>
Expand Down
5 changes: 3 additions & 2 deletions MekHQ/resources/mekhq/resources/CampaignGUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ btnPrintRS.toolTipText=Print record sheets for all currently assigned units.
btnPrintRS.text=Print Sheets
btnGetMul.toolTipText=Get a MUL file of all assigned units that can be loaded into MegaMek
btnGetMul.text=Export MUL File
btnClearAssignedUnits.toolTipText=Clear all assigned units for this scenario
btnClearAssignedUnits.text=Clear Units
btnClearAssignedUnits.toolTipText=Clear all assigned units for this scenario. Restricted to GM Mode\
\ if it is a scenario assigned to the Area of Operations.
btnClearAssignedUnits.text=Reset Deployment
btnResolveScenario.toolTipText=Bring up a wizard that will guide you through the process of resolving this scenario either by MUL files from a MegaMek game or by manually editing for tabletop games.
btnResolveScenario.text=Resolve Manually
btnAutoResolveScenario.toolTipText=<html>Start a game of MegaMek with all the assigned units played by bots.<br>At the game's conclusion, you will be presented with a series of dialogs for resolving the scenario.</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ col_name.text=Scenario Name
col_status.text=Resolution
col_date.text=Date
col_assign.text=Units Assigned
col_sector.text=Sector
col_sector.text=Grid Reference
col_unknown.text=?
19 changes: 11 additions & 8 deletions MekHQ/src/mekhq/MekHQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import megamek.SuiteConstants;
import megamek.client.Client;
import megamek.client.bot.princess.BehaviorSettings;
import megamek.client.ui.dialogs.AutoResolveChanceDialog;
import megamek.client.ui.dialogs.AutoResolveProgressDialog;
import megamek.client.ui.dialogs.AutoResolveSimulationLogDialog;
import megamek.client.ui.preferences.PreferencesNode;
import megamek.client.ui.preferences.SuitePreferences;
Expand All @@ -37,6 +39,7 @@
import megamek.common.Board;
import megamek.common.annotations.Nullable;
import megamek.common.autoresolve.acar.SimulatedClient;
import megamek.common.autoresolve.converter.SingletonForces;
import megamek.common.autoresolve.event.AutoResolveConcludedEvent;
import megamek.common.event.*;
import megamek.common.net.marshalling.SanityInputFilter;
Expand Down Expand Up @@ -645,25 +648,25 @@ public void startAutoResolve(AtBScenario scenario, List<Unit> units) {
this.autosaveService.requestBeforeMissionAutosave(getCampaign());

if (getCampaign().getCampaignOptions().isAutoResolveVictoryChanceEnabled()) {
var proceed = megamek.client.ui.dialogs.AutoResolveChanceDialog
var proceed = AutoResolveChanceDialog
.showDialog(
getCampaigngui().getFrame(),
campaignGUI.getFrame(),
getCampaign().getCampaignOptions().getAutoResolveNumberOfScenarios(),
Runtime.getRuntime().availableProcessors(),
getCampaign().getPlayer().getTeam(),
new AtBSetupForces(getCampaign(), units, scenario),
1,
new AtBSetupForces(getCampaign(), units, scenario, new SingletonForces()),
new Board(scenario.getBaseMapX(), scenario.getBaseMapY())) == JOptionPane.YES_OPTION;
if (!proceed) {
return;
}
}

var event = megamek.client.ui.dialogs.AutoResolveProgressDialog.showDialog(
getCampaigngui().getFrame(),
new AtBSetupForces(getCampaign(), units, scenario),
var event = AutoResolveProgressDialog.showDialog(
campaignGUI.getFrame(),
new AtBSetupForces(getCampaign(), units, scenario, new SingletonForces()),
new Board(scenario.getBaseMapX(), scenario.getBaseMapY()));

var autoResolveBattleReport = new AutoResolveSimulationLogDialog(getCampaigngui().getFrame(), event.getLogFile());
var autoResolveBattleReport = new AutoResolveSimulationLogDialog(campaignGUI.getFrame(), event.getLogFile());
autoResolveBattleReport.setModal(true);
autoResolveBattleReport.setVisible(true);

Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/CampaignFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public Campaign createCampaign(InputStream is)
// ...otherwise, assume we're an XML file.

CampaignXmlParser parser = new CampaignXmlParser(is, this.app);

return parser.parse();
}

Expand All @@ -91,4 +90,5 @@ private byte[] readHeader(InputStream is) throws IOException {

return header;
}

}
77 changes: 48 additions & 29 deletions MekHQ/src/mekhq/campaign/autoresolve/AtBSetupForces.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import megamek.common.*;
import megamek.common.alphaStrike.conversion.ASConverter;
import megamek.common.autoresolve.acar.SimulationContext;
import megamek.common.autoresolve.converter.ConsolidateForces;
import megamek.common.autoresolve.converter.ForceToFormationConverter;
import megamek.common.autoresolve.converter.SetupForces;
import megamek.common.autoresolve.converter.SingleElementConsolidateForces;
import megamek.common.autoresolve.converter.*;
import megamek.common.copy.CrewRefBreak;
import megamek.common.force.Forces;
import megamek.common.options.OptionsConstants;
Expand All @@ -41,6 +38,8 @@
import java.io.InputStream;
import java.util.*;

import static megamek.common.force.Force.NO_FORCE;

/**
* @author Luana Coppio
*/
Expand All @@ -50,11 +49,20 @@ public class AtBSetupForces extends SetupForces {
private final Campaign campaign;
private final List<Unit> units;
private final AtBScenario scenario;
private final ForceConsolidation forceConsolidationMethod;

private final OrderFactory orderFactory;

public AtBSetupForces(Campaign campaign, List<Unit> units, AtBScenario scenario, ForceConsolidation forceConsolidationMethod) {
this(campaign, units, scenario, forceConsolidationMethod, new OrderFactory(campaign, scenario));
}

public AtBSetupForces(Campaign campaign, List<Unit> units, AtBScenario scenario) {
public AtBSetupForces(Campaign campaign, List<Unit> units, AtBScenario scenario, ForceConsolidation forceConsolidationMethod, OrderFactory orderFactory) {
this.campaign = campaign;
this.units = units;
this.scenario = scenario;
this.forceConsolidationMethod = forceConsolidationMethod;
this.orderFactory = orderFactory;
}

/**
Expand All @@ -64,10 +72,18 @@ public AtBSetupForces(Campaign campaign, List<Unit> units, AtBScenario scenario)
public void createForcesOnSimulation(SimulationContext game) {
setupPlayer(game);
setupBots(game);
ConsolidateForces.consolidateForces(game, new SingleElementConsolidateForces());
forceConsolidationMethod.consolidateForces(game);
convertForcesIntoFormations(game);
}

@Override
public void addOrdersToForces(SimulationContext context) {
var orders = orderFactory.getOrders();
context.getOrders().clear();
context.getOrders().addAll(orders);
context.getOrders().resetOrders();
}

private static class FailedToConvertForceToFormationException extends RuntimeException {
public FailedToConvertForceToFormationException(Throwable cause) {
super(cause);
Expand All @@ -80,10 +96,10 @@ public FailedToConvertForceToFormationException(Throwable cause) {
* and used in the auto resolve in place of the original entities
* @param game The game object to convert the forces in
*/
private static void convertForcesIntoFormations(SimulationContext game) {
private void convertForcesIntoFormations(SimulationContext game) {
for(var force : game.getForces().getTopLevelForces()) {
try {
var formation = new ForceToFormationConverter(force, game).convert();
var formation = new EntityAsUnit(force, game).convert();
formation.setTargetFormationId(Entity.NONE);
formation.setOwnerId(force.getOwnerId());
game.addUnit(formation);
Expand Down Expand Up @@ -413,33 +429,14 @@ private PlanetaryConditions getPlanetaryConditions() {
private void sendEntities(List<Entity> entities, SimulationContext game) {
Map<Integer, Integer> forceMapping = new HashMap<>();
for (final Entity entity : new ArrayList<>(entities)) {
if (entity instanceof ProtoMek) {
int numPlayerProtos = game.getSelectedEntityCount(new EntitySelector() {
private final int ownerId = entity.getOwnerId();
@Override
public boolean accept(Entity entity) {
return (entity instanceof ProtoMek) && (ownerId == entity.getOwnerId());
}
});

entity.setUnitNumber((short) (numPlayerProtos / 5));
}

if (Entity.NONE == entity.getId()) {
entity.setId(game.getNextEntityId());
}

// Give the unit a spotlight, if it has the spotlight quirk
entity.setExternalSearchlight(entity.hasExternalSearchlight()
|| entity.hasQuirk(OptionsConstants.QUIRK_POS_SEARCHLIGHT));

lastTouchesBeforeSendingEntity(game, entity);
game.getPlayer(entity.getOwnerId()).changeInitialEntityCount(1);

// Restore forces from MULs or other external sources from the forceString, if
// any
if (!entity.getForceString().isBlank()) {
List<megamek.common.force.Force> forceList = Forces.parseForceString(entity);
int realId = megamek.common.force.Force.NO_FORCE;
int realId = NO_FORCE;
boolean topLevel = true;

for (megamek.common.force.Force force : forceList) {
Expand All @@ -463,4 +460,26 @@ public boolean accept(Entity entity) {
}
}
}

private static void lastTouchesBeforeSendingEntity(SimulationContext game, Entity entity) {
if (entity instanceof ProtoMek) {
int numPlayerProtos = game.getSelectedEntityCount(new EntitySelector() {
private final int ownerId = entity.getOwnerId();
@Override
public boolean accept(Entity entity) {
return (entity instanceof ProtoMek) && (ownerId == entity.getOwnerId());
}
});

entity.setUnitNumber((short) (numPlayerProtos / 5));
}

if (Entity.NONE == entity.getId()) {
entity.setId(game.getNextEntityId());
}

// Give the unit a spotlight, if it has the spotlight quirk
entity.setExternalSearchlight(entity.hasExternalSearchlight()
|| entity.hasQuirk(OptionsConstants.QUIRK_POS_SEARCHLIGHT));
}
}
Loading

0 comments on commit 7bc7bb5

Please sign in to comment.