3333import java .util .UUID ;
3434
3535import megamek .Version ;
36- import megamek .common .force .Force ;
3736import megamek .logging .MMLogger ;
3837import mekhq .campaign .Campaign ;
38+ import mekhq .campaign .force .Force ;
39+ import mekhq .campaign .mission .AtBContract ;
3940import mekhq .campaign .personnel .Person ;
41+ import mekhq .campaign .stratcon .StratconCampaignState ;
4042import mekhq .utilities .MHQXMLUtility ;
4143import org .w3c .dom .Node ;
4244import 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