Skip to content

Commit 7b8ba7e

Browse files
authored
Merge pull request #7189 from IllianiBird/unmothball
Fix: #7185 Fixed Mothballed Units Teleporting to Already Deployed Forces
2 parents 2a315f6 + 057e089 commit 7b8ba7e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

MekHQ/src/mekhq/campaign/unit/MothballInfo.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
import java.util.UUID;
3434

3535
import megamek.Version;
36-
import megamek.common.force.Force;
3736
import megamek.logging.MMLogger;
3837
import mekhq.campaign.Campaign;
38+
import mekhq.campaign.force.Force;
39+
import mekhq.campaign.mission.AtBContract;
3940
import mekhq.campaign.personnel.Person;
41+
import mekhq.campaign.stratcon.StratconCampaignState;
4042
import mekhq.utilities.MHQXMLUtility;
4143
import org.w3c.dom.Node;
4244
import org.w3c.dom.NodeList;
@@ -63,7 +65,7 @@ public class MothballInfo {
6365
* Parameterless constructor, used for deserialization.
6466
*/
6567
private MothballInfo() {
66-
forceId = Force.NO_FORCE;
68+
forceId = Force.FORCE_NONE;
6769
}
6870

6971
/**
@@ -168,7 +170,32 @@ public void restorePreMothballInfo(Unit unit, Campaign campaign) {
168170
unit.setNavigator(navigator);
169171
}
170172

171-
if (campaign.getForce(forceId) != null) {
173+
// Attempt to return the unit to its last force assignment.
174+
Force force = campaign.getForce(forceId);
175+
if (force != null) {
176+
// If the force is deployed to a scenario, back out. We don't want to restore the unit to the original
177+
// force as that would cause them to teleport into the scenario. This will likely cause issues, so it's
178+
// prohibited.
179+
if (force.isDeployed()) {
180+
return;
181+
}
182+
183+
// If StratCon is enabled, we need to perform an additional check to ensure the original force isn't
184+
// currently deployed to the Area of Operations.
185+
boolean isUseStratCon = campaign.getCampaignOptions().isUseStratCon();
186+
if (isUseStratCon) {
187+
for (AtBContract contract : campaign.getActiveAtBContracts()) {
188+
StratconCampaignState campaignState = contract.getStratconCampaignState();
189+
190+
if (campaignState != null) {
191+
if (campaignState.isForceDeployedHere(forceId)) {
192+
return; // If the force is deployed to the AO return without restoring force assignment.
193+
}
194+
}
195+
}
196+
}
197+
198+
// If all the checks have passed, restore the unit to its last force
172199
campaign.addUnitToForce(unit, forceId);
173200
}
174201

0 commit comments

Comments
 (0)