Skip to content

Commit

Permalink
Fix force commander handling and improve XML persistence.
Browse files Browse the repository at this point in the history
Set forceCommanderID to null when no eligible commanders exist, ensuring valid leadership. Added overrideForceCommanderID to XML read/write methods for better persistence. Updated force commander assignment during campaign load to prevent invalid leadership issues.
  • Loading branch information
IllianiCBT committed Jan 9, 2025
1 parent 8ea7a6d commit f4c25f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MekHQ/src/mekhq/campaign/force/Force.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public void updateCommander(Campaign campaign) {
List<UUID> eligibleCommanders = getEligibleCommanders(campaign);

if (eligibleCommanders.isEmpty()) {
forceCommanderID = null;
overrideForceCommanderID = null;
return;
}
Expand Down Expand Up @@ -711,6 +712,7 @@ public void writeToXML(PrintWriter pw1, int indent) {
MHQXMLUtility.writeSimpleXMLTag(pw1, indent, "populateOriginNode", overrideFormationLevel.toString());
MHQXMLUtility.writeSimpleXMLTag(pw1, indent, "scenarioId", scenarioId);
MHQXMLUtility.writeSimpleXMLTag(pw1, indent, "techId", techId);
MHQXMLUtility.writeSimpleXMLTag(pw1, indent, "overrideForceCommanderID", overrideForceCommanderID);
MHQXMLUtility.writeSimpleXMLTag(pw1, indent, "forceCommanderID", forceCommanderID);
if (!units.isEmpty()) {
MHQXMLUtility.writeSimpleXMLOpenTag(pw1, indent++, "units");
Expand Down Expand Up @@ -766,6 +768,8 @@ public void writeToXML(PrintWriter pw1, int indent) {
force.scenarioId = Integer.parseInt(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("techId")) {
force.techId = UUID.fromString(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("overrideForceCommanderID")) {
force.overrideForceCommanderID = UUID.fromString(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("forceCommanderID")) {
force.forceCommanderID = UUID.fromString(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("units")) {
Expand Down
5 changes: 5 additions & 0 deletions MekHQ/src/mekhq/campaign/io/CampaignXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ private static void processForces(Campaign retVal, Node wn, Version version) {
}
}

// This removes the risk of having forces with invalid leadership getting locked in
for (Force force : retVal.getAllForces()) {
force.updateCommander(retVal);
}

recalculateCombatTeams(retVal);
logger.info("Load of Force Organization complete!");
}
Expand Down

0 comments on commit f4c25f6

Please sign in to comment.