Skip to content

Commit

Permalink
Issue 3650: Better handling loading in MM lobby when transport has sh…
Browse files Browse the repository at this point in the history
…ip and tactical transpored units
  • Loading branch information
psikomonkie committed Jan 12, 2025
1 parent 1bb051f commit 279cb5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public void run() {
loadTransports(botClient, scenario, bf);
}

boolean alreadyResetTransport = false;

// All player and bot units have been added to the lobby
// Prompt the player to autoload units into transport ships
if (!potentialTransports.get(SHIP_TRANSPORT.getTransportAssignmentType()).isEmpty()) {
Expand Down Expand Up @@ -474,6 +476,7 @@ public void run() {
// And now load the units. Unit crews load as passengers here.
Utilities.loadPlayerTransports(transportShip.getEntity().getId(), toLoad,
client, loadDropShips, loadSmallCraft, loadFighters, loadGround);
alreadyResetTransport = true;
}
}
}
Expand Down Expand Up @@ -516,7 +519,8 @@ public void run() {
client.sendUpdateEntity(transport.getEntity());
// And now load the units.
Utilities.loadPlayerTransports(transport.getEntity().getId(), toLoad,
client, loadTactical);
client, loadTactical, alreadyResetTransport);
alreadyResetTransport = true;
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion MekHQ/src/mekhq/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,14 @@ public static void loadPlayerTransports(int trnId, Set<Integer> toLoad, Client c
* @param toLoad - Map of entity ids and transport assignments for the units we want to load
* @param client - the player's Client instance
* @param loadTactical - Should "tactical"-ly transported units be loaded?
* @param isAlreadyReset - transports loaded via "Ship" will have been reset once, don't do it again here
* @see mekhq.campaign.enums.CampaignTransportType#TACTICAL_TRANSPORT
* @see ITransportAssignment
*/
public static void loadPlayerTransports(int trnId, Map<Integer, ? extends ITransportAssignment> toLoad, Client client,
boolean loadTactical) {
boolean loadTactical, boolean isAlreadyReset) {
Set<Entity> alreadyTransportedEntities = new HashSet<>();

if (!loadTactical) {
// Nothing to do. Get outta here!
return;
Expand All @@ -1302,7 +1305,14 @@ public static void loadPlayerTransports(int trnId, Map<Integer, ? extends ITrans
// Reset transporter status, as currentSpace might still retain updates from
// when the Unit
// was assigned to the Transport on the TO&E tab
if (isAlreadyReset) {
alreadyTransportedEntities.addAll(transport.getLoadedUnits());
}

transport.resetTransporter();
for (Entity alreadyTransportedEntity : alreadyTransportedEntities) {
transport.load(alreadyTransportedEntity, alreadyTransportedEntity.getTargetBay());
}
for (int id : toLoad.keySet()) {
Entity cargo = client.getEntity(id);
if (cargo == null) {
Expand All @@ -1327,6 +1337,9 @@ public static void loadPlayerTransports(int trnId, Map<Integer, ? extends ITrans

// Reset transporter status again so that sendLoadEntity can process correctly
transport.resetTransporter();
for (Entity alreadyTransportedEntity : alreadyTransportedEntities) {
transport.load(alreadyTransportedEntity, alreadyTransportedEntity.getTargetBay());
}
for (int id : toLoad.keySet()) {
Entity cargo = client.getEntity(id);
if (!transport.canLoad(cargo, false)) {
Expand Down

0 comments on commit 279cb5a

Please sign in to comment.