Skip to content

Commit

Permalink
Issue 3650: More Dev Review Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
psikomonkie committed Jan 15, 2025
1 parent 749dc58 commit b602ee8
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ TOEMouseAdapter.unassign.SHIP_TRANSPORT.text=Unassign Force from Ship Transport
AtBGameThread.loadTransportDialog.TACTICAL_TRANSPORT.title=Load Units onto Transport?
AtBGameThread.loadTransportDialog.TACTICAL_TRANSPORT.text=Would you like the units assigned to {0} to deploy loaded?

AtBGameThread.loadTransportDialog.LOAD_DROPSHIP_DIALOG_TITLE.title =Load DropShips onto Transport?
AtBGameThread.loadTransportDialog.LOAD_DROPSHIP_DIALOG_TEXT.text =Would you like the DropShip(s) assigned to {0} to deploy loaded into its bays?
AtBGameThread.loadTransportDialog.LOAD_SMALL_CRAFT_DIALOG_TITLE.title =Load Small Craft onto Transport?
AtBGameThread.loadTransportDialog.LOAD_SMALL_CRAFT_DIALOG_TEXT.text =Would you like the small craft assigned to {0} to deploy loaded into its bays?
AtBGameThread.loadTransportDialog.LOAD_FTR_DIALOG_TEXT.text =Would you like the fighter(s) assigned to {0} to deploy loaded into its bays?
AtBGameThread.loadTransportDialog.LOAD_FTR_DIALOG_TITLE.title =Load Fighters onto Transport?
AtBGameThread.loadTransportDialog.LOAD_GND_DIALOG_TEXT.text =Would you like the ground unit(s) assigned to {0} to deploy loaded into its bays?
AtBGameThread.loadTransportDialog.LOAD_GND_DIALOG_TITLE.title =Load Ground Units onto Transport?

31 changes: 10 additions & 21 deletions MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ public AtBGameThread(String name, String password, Client client, MekHQ app, Lis
this.autoResolveBehaviorSettings = autoResolveBehaviorSettings;
}

// String tokens for dialog boxes used for transport loading
// FIXME : I'm not localized!
private static final String LOAD_DROPSHIP_DIALOG_TITLE = "Load DropShips onto Transport?";
private static final String LOAD_DROPSHIP_DIALOG_TEXT = "Would you like the DropShip(s) assigned to %s to deploy loaded into its bays?";
private static final String LOAD_SMALL_CRAFT_DIALOG_TITLE = "Load Small Craft onto Transport?";
private static final String LOAD_SMALL_CRAFT_DIALOG_TEXT = "Would you like the small craft assigned to %s to deploy loaded into its bays?";
private static final String LOAD_FTR_DIALOG_TEXT = "Would you like the fighter(s) assigned to %s to deploy loaded into its bays?";
private static final String LOAD_FTR_DIALOG_TITLE = "Load Fighters onto Transport?";
private static final String LOAD_GND_DIALOG_TEXT = "Would you like the ground unit(s) assigned to %s to deploy loaded into its bays?";
private static final String LOAD_GND_DIALOG_TITLE = "Load Ground Units onto Transport?";

@Override
public void run() {
client.addCloseClientListener(this);
Expand Down Expand Up @@ -400,27 +389,27 @@ public void run() {
if (transportShip.getShipTransportedUnits().stream()
.anyMatch(unit -> unit.getEntity().getUnitType() == UnitType.DROPSHIP)) {
loadDropShips = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
String.format(AtBGameThread.LOAD_DROPSHIP_DIALOG_TEXT, transportShip.getName()),
AtBGameThread.LOAD_DROPSHIP_DIALOG_TITLE, JOptionPane.YES_NO_OPTION);
MHQInternationalization.getFormattedTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_DROPSHIP_DIALOG_TEXT.text", transportShip.getName()),
MHQInternationalization.getTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_DROPSHIP_DIALOG_TITLE.title"), JOptionPane.YES_NO_OPTION);
}

if (transportShip.getShipTransportedUnits().stream()
.anyMatch(unit -> unit.getEntity().getUnitType() == UnitType.SMALL_CRAFT)) {
loadSmallCraft = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
String.format(AtBGameThread.LOAD_SMALL_CRAFT_DIALOG_TEXT, transportShip.getName()),
AtBGameThread.LOAD_SMALL_CRAFT_DIALOG_TITLE, JOptionPane.YES_NO_OPTION);
MHQInternationalization.getFormattedTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_SMALL_CRAFT_DIALOG_TEXT.text", transportShip.getName()),
MHQInternationalization.getTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_SMALL_CRAFT_DIALOG_TITLE.title"), JOptionPane.YES_NO_OPTION);
}

if (transportShip.isCarryingSmallerAero()) {
loadFighters = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
String.format(AtBGameThread.LOAD_FTR_DIALOG_TEXT, transportShip.getName()),
AtBGameThread.LOAD_FTR_DIALOG_TITLE, JOptionPane.YES_NO_OPTION);
MHQInternationalization.getFormattedTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_FTR_DIALOG_TEXT.text", transportShip.getName()),
MHQInternationalization.getTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_FTR_DIALOG_TITLE.title"), JOptionPane.YES_NO_OPTION);
}

if (transportShip.isCarryingGround()) {
loadGround = (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
String.format(AtBGameThread.LOAD_GND_DIALOG_TEXT, transportShip.getName()),
AtBGameThread.LOAD_GND_DIALOG_TITLE, JOptionPane.YES_NO_OPTION));
MHQInternationalization.getFormattedTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_GND_DIALOG_TEXT.text", transportShip.getName()),
MHQInternationalization.getTextAt("mekhq.resources.AssignForceToTransport", "AtBGameThread.loadTransportDialog.LOAD_GND_DIALOG_TITLE.title"), JOptionPane.YES_NO_OPTION));
}

// Now, send the load commands
Expand Down Expand Up @@ -479,8 +468,8 @@ public void run() {
if (scenario.getPlayerTransportLinkages().containsKey(transportId)) {
scenario.addPlayerTransportRelationship(transportId, transportedUnit.getId());
}
if (transportedUnit.getTech() != null && transportedUnit.getTacticalTransportAssignment().hasTransporterType()
&& Bay.class.isAssignableFrom(transportedUnit.getTacticalTransportAssignment().getTransporterType().getTransporterClass())) {
if (transportedUnit.getTech() != null && transportedUnit.hasTransportAssignment(TACTICAL_TRANSPORT)
&& transportedUnit.getTransportAssignment(TACTICAL_TRANSPORT).isTransportedInBay()){
cargoTechs.add(transportedUnit.getTech());
}
}
Expand Down
6 changes: 2 additions & 4 deletions MekHQ/src/mekhq/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -1328,12 +1328,10 @@ public static void loadPlayerTransports(int trnId, Map<Integer, ? extends ITrans

// Find a bay with space in it and update that space so the next unit can
// process, unless the unit isn't being loaded into a bay
if (transportAssignment.getTransportedLocation() instanceof Bay) {
Bay bay = (Bay) transportAssignment.getTransportedLocation();
if (transportAssignment.getTransportedLocation() instanceof Bay bay) {
cargo.setTargetBay(bay.getBayNumber());
} else {
if (transportAssignment.hasTransporterType()
&& Bay.class.isAssignableFrom(transportAssignment.getTransporterType().getTransporterClass())) {
if (transportAssignment.isTransportedInBay()) {
cargo.setTargetBay(selectBestBayFor(cargo, transport));
}
}
Expand Down
10 changes: 0 additions & 10 deletions MekHQ/src/mekhq/campaign/enums/CampaignTransportType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
import mekhq.campaign.unit.*;
import mekhq.campaign.unit.enums.TransporterType;

import java.util.HashSet;
import java.util.Set;

import static mekhq.campaign.unit.enums.TransporterType.*;

/**
* Enum for the different transport types used in MekHQ.
* Campaign Transports allow a unit to be
Expand Down Expand Up @@ -105,9 +100,4 @@ public enum CampaignTransportType
*/
public Class<? extends AbstractTransportedUnitsSummary> getTransportedUnitsSummaryType() { return transportedUnitsSummaryType; }
// endregion Getters


public String getName() {
return this.toString();
}
}
11 changes: 10 additions & 1 deletion MekHQ/src/mekhq/campaign/unit/ITransportAssignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package mekhq.campaign.unit;

import megamek.common.Transporter;
import megamek.common.annotations.Nullable;
import mekhq.campaign.Campaign;
import mekhq.campaign.unit.enums.TransporterType;

Expand Down Expand Up @@ -73,4 +72,14 @@ public interface ITransportAssignment {
*/
void fixReferences(Campaign campaign, Unit unit);

/**
* Bays have some extra functionality other transporters don't have, like
* having a tech crew, which will matter for boarding actions against
* dropships and other Ship Transports. This method determines if this
* transport assignment is for a Bay.
* @return true if the unit is transported in a Bay or a subclass
* @see megamek.common.Bay
*/
boolean isTransportedInBay();

}
17 changes: 15 additions & 2 deletions MekHQ/src/mekhq/campaign/unit/TransportAssignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

package mekhq.campaign.unit;

import megamek.common.Bay;
import megamek.common.Transporter;
import megamek.common.annotations.Nullable;
import megamek.logging.MMLogger;
import mekhq.campaign.Campaign;
import mekhq.campaign.enums.CampaignTransportType;
import mekhq.campaign.unit.enums.TransporterType;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

/**
* Represents an assignment on a transport. Currently only used by TACTICAL_TRANSPORT
Expand Down Expand Up @@ -183,4 +182,18 @@ public void fixReferences(Campaign campaign, Unit unit) {
}
}
}

/**
* Bays have some extra functionality other transporters don't have, like
* having a tech crew, which will matter for boarding actions against
* dropships and other Ship Transports. This method determines if this
* transport assignment is for a Bay.
*
* @return true if the unit is transported in a Bay or a subclass
* @see Bay
*/
@Override
public boolean isTransportedInBay() {
return (hasTransporterType() && Bay.class.isAssignableFrom(getTransporterType().getTransporterClass()));
}
}
8 changes: 4 additions & 4 deletions MekHQ/src/mekhq/campaign/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ public void initializeTransportSpace(CampaignTransportType campaignTransportType
Constructor<? extends AbstractTransportedUnitsSummary> constructor = campaignTransportType.getTransportedUnitsSummaryType().getConstructor(new Class[]{Unit.class});
addTransportedUnitType(constructor.newInstance(this));
} catch (NoSuchMethodException e) {
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.getName(), e.toString(), e.getCause()));
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.name(), e.toString(), e.getCause()));
} catch (InvocationTargetException e) {
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.getName(), e.toString(), e.getCause()));
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.name(), e.toString(), e.getCause()));
} catch (InstantiationException e) {
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.getName(), e.toString(), e.getCause()));
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.name(), e.toString(), e.getCause()));
} catch (IllegalAccessException e) {
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.getName(), e.toString(), e.getCause()));
logger.error(String.format("Could not find constructor to initialize transport space for %s Error: %s Cause: %s", campaignTransportType.name(), e.toString(), e.getCause()));
}
}
}
Expand Down
Loading

0 comments on commit b602ee8

Please sign in to comment.