Skip to content

Commit

Permalink
Merge pull request #5213 from IllianiCBT/contractAutomation_largeVessels
Browse files Browse the repository at this point in the history
Enhanced Mothballing in `ContractAutomation`
  • Loading branch information
HammerGS authored Nov 23, 2024
2 parents be350eb + 865faf7 commit 13a1305
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package mekhq.campaign.market.contractMarket;

import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.annotations.Nullable;
import megamek.logging.MMLogger;
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.JumpPath;
Expand Down Expand Up @@ -50,6 +52,7 @@
*/
public class ContractAutomation {
private final static ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.ContractAutomation");
private static final MMLogger logger = MMLogger.create(ContractAutomation.class);

/**
* Main function to initiate a sequence of automated tasks when a contract is started.
Expand Down Expand Up @@ -268,13 +271,27 @@ private static List<Unit> performAutomatedMothballing(Campaign campaign) {
for (UUID unitId : force.getUnits()) {
Unit unit = campaign.getUnit(unitId);

if (unit != null) {
if (unit.isAvailable(false) && !unit.isUnderRepair()) {
mothballTargets.add(unit);
} else {
campaign.addReport(String.format(resources.getString("mothballingFailed.text"),
unit.getName()));
if (unit == null) {
logger.error(String.format("Failed to get unit for unit ID %s", unitId));
continue;
}

try {
Entity entity = unit.getEntity();

if (entity.isLargeCraft()) {
continue;
}
} catch (Exception e) {
logger.error(String.format("Failed to get entity for %s", unit.getName()));
continue;
}

if (unit.isAvailable(false) && !unit.isUnderRepair()) {
mothballTargets.add(unit);
} else {
campaign.addReport(String.format(resources.getString("mothballingFailed.text"),
unit.getName()));
}
}
}
Expand Down

0 comments on commit 13a1305

Please sign in to comment.