Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 4061: Failure to load older Campaign save #4064

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -5744,10 +5744,12 @@ public void clearGameData(Entity entity) {
entity.setShutDown(false);
entity.setSearchlightState(false);

if (entity.hasBAP()) {
entity.setNextSensor(entity.getSensors().lastElement());
} else if (!entity.getSensors().isEmpty()) {
entity.setNextSensor(entity.getSensors().firstElement());
if (!entity.getSensors().isEmpty()) {
if (entity.hasBAP()) {
entity.setNextSensor(entity.getSensors().lastElement());
} else {
entity.setNextSensor(entity.getSensors().firstElement());
}
}

if (entity instanceof IBomber) {
Expand Down
20 changes: 17 additions & 3 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import megamek.common.options.IOptionGroup;
import megamek.common.options.OptionsConstants;
import mekhq.MekHQ;
import mekhq.campaign.universe.PlanetarySystem;
import mekhq.utilities.MHQXMLUtility;
import mekhq.Utilities;
import mekhq.campaign.Campaign;
Expand Down Expand Up @@ -1588,9 +1589,22 @@ public static Person generateInstanceFromXML(Node wn, Campaign c, Version versio
retVal.setOriginFaction(Factions.getInstance().getFaction(wn2.getTextContent().trim()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("planetId")) {
String systemId = wn2.getAttributes().getNamedItem("systemId").getTextContent().trim();
String planetId = wn2.getTextContent().trim();
retVal.originPlanet = c.getSystemById(systemId).getPlanetById(planetId);
String systemId = "", planetId = "";
try {
systemId = wn2.getAttributes().getNamedItem("systemId").getTextContent().trim();
planetId = wn2.getTextContent().trim();
PlanetarySystem ps = c.getSystemById(systemId);
Planet p = null;
if (ps == null) {
ps = c.getSystemByName(systemId);
}
if (ps != null) {
p = ps.getPlanetById(planetId);
}
retVal.originPlanet = p;
} catch (NullPointerException e) {
LogManager.getLogger().error("Error loading originPlanet for " + systemId + ", " + planetId, e);
}
} else if (wn2.getNodeName().equalsIgnoreCase("phenotype")) {
retVal.phenotype = Phenotype.parseFromString(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("bloodname")) {
Expand Down
11 changes: 11 additions & 0 deletions MekHQ/unittests/mekhq/campaign/CampaignTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package mekhq.campaign;

import megamek.common.Dropship;
import megamek.common.Entity;
import megamek.common.EquipmentType;
import megamek.common.Infantry;
import megamek.common.enums.SkillLevel;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.enums.PersonnelRole;
Expand Down Expand Up @@ -147,6 +149,15 @@ public void testGetTechs() {
assertEquals(expected, testCampaign.getTechs(true));
}

@Test
public void testCampaignResetInfantry() {
// It is possible for Infantry to have BAP equal true, but empty Sensors vector.
Campaign campaign = new Campaign();
Entity infantry = spy(new Infantry());
when(infantry.hasBAP()).thenReturn(true);
campaign.clearGameData(infantry);
}

@Test
public void testTransportShips() {
Campaign campaign = spy(new Campaign());
Expand Down
Loading