Skip to content

Commit

Permalink
Merge pull request #5729 from IllianiCBT/toe_commanderBug
Browse files Browse the repository at this point in the history
Fixed Force Commander Handling and Improve XML Persistence.
  • Loading branch information
HammerGS authored Jan 15, 2025
2 parents a9ec2eb + f4c25f6 commit b0c3ecb
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 b0c3ecb

Please sign in to comment.