Skip to content

Commit

Permalink
Merge pull request #2077 from Windchild292/dev_Windchild_MRMSOptions
Browse files Browse the repository at this point in the history
Standardizing MRMS Options
  • Loading branch information
Windchild292 authored Oct 3, 2020
2 parents 4194dc0 + 4cbfe03 commit 26f6d5d
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 355 deletions.
162 changes: 14 additions & 148 deletions MekHQ/src/mekhq/campaign/CampaignOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import mekhq.campaign.againstTheBot.enums.AtBLanceRole;
import mekhq.campaign.personnel.enums.Phenotype;
import mekhq.campaign.personnel.enums.PrisonerCaptureStyle;
import mekhq.service.MassRepairOption;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand All @@ -38,7 +39,6 @@
import mekhq.MekHqXmlUtil;
import mekhq.Utilities;
import mekhq.campaign.market.PersonnelMarket;
import mekhq.campaign.parts.Part;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.SkillType;
import mekhq.campaign.personnel.enums.PrisonerStatus;
Expand Down Expand Up @@ -2935,6 +2935,7 @@ public void setUnitMarketReportRefresh(boolean refresh) {
unitMarketReportRefresh = refresh;
}

//region Mass Repair/ Mass Salvage
public boolean massRepairUseExtraTime() {
return massRepairUseExtraTime;
}
Expand Down Expand Up @@ -3022,6 +3023,7 @@ public void addMassRepairOption(MassRepairOption mro) {

massRepairOptions.sort(Comparator.comparingInt(MassRepairOption::getType));
}
//endregion Mass Repair/ Mass Salvage

public void setAllowOpforAeros(boolean allowOpforAeros) {
this.allowOpforAeros = allowOpforAeros;
Expand Down Expand Up @@ -3316,24 +3318,11 @@ public void writeToXml(PrintWriter pw1, int indent) {
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 1, "massRepairUseAssignedTechsFirst", massRepairUseAssignedTechsFirst);
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 1, "massRepairReplacePod", massRepairReplacePod);

pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "<massRepairOptions>");

for (int i = 0; i < massRepairOptions.size(); i++) {
MassRepairOption mro = massRepairOptions.get(i);

pw1.println(MekHqXmlUtil.indentStr(indent + 2) + "<massRepairOption" + i + ">");

MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "type", mro.getType());
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "active", mro.isActive() ? 1 : 0);
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "skillMin", mro.getSkillMin());
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "skillMax", mro.getSkillMax());
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "btnMin", mro.getBthMin());
MekHqXmlUtil.writeSimpleXmlTag(pw1, indent + 3, "btnMax", mro.getBthMax());

pw1.println(MekHqXmlUtil.indentStr(indent + 2) + "</massRepairOption" + i + ">");
MekHqXmlUtil.writeSimpleXMLOpenIndentedLine(pw1, indent + 1, "massRepairOptions");
for (MassRepairOption massRepairOption : massRepairOptions) {
massRepairOption.writeToXML(pw1, indent + 2);
}

pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "</massRepairOptions>");
MekHqXmlUtil.writeSimpleXMLCloseIndentedLine(pw1, indent + 1, "massRepairOptions");

pw1.println(MekHqXmlUtil.indentStr(indent + 1)
+ "<planetTechAcquisitionBonus>"
Expand Down Expand Up @@ -3389,7 +3378,7 @@ public void writeToXml(PrintWriter pw1, int indent) {
}

public static CampaignOptions generateCampaignOptionsFromXml(Node wn) {
MekHQ.getLogger().info(CampaignOptions.class, "Loading Campaign Options from XML...");
MekHQ.getLogger().info("Loading Campaign Options from XML...");

wn.normalize();
CampaignOptions retVal = new CampaignOptions();
Expand All @@ -3404,7 +3393,7 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn) {
continue;
}

MekHQ.getLogger().info(CampaignOptions.class, String.format("%s\n\t%s", wn2.getNodeName(), wn2.getTextContent()));
MekHQ.getLogger().debug(String.format("%s\n\t%s", wn2.getNodeName(), wn2.getTextContent()));

//region Repair and Maintenance Tab
if (wn2.getNodeName().equalsIgnoreCase("checkMaintenance")) {
Expand Down Expand Up @@ -3643,7 +3632,7 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn) {
} else if (values.length == 9) {
migrateMarriageSurnameWeights(retVal, values);
} else {
MekHQ.getLogger().error(CampaignOptions.class, "Unkown length of randomMarriageSurnameWeights");
MekHQ.getLogger().error("Unknown length of randomMarriageSurnameWeights");
}
} else if (wn2.getNodeName().equalsIgnoreCase("useRandomSameSexMarriages")) {
retVal.useRandomSameSexMarriages = Boolean.parseBoolean(wn2.getTextContent().trim());
Expand Down Expand Up @@ -3967,61 +3956,16 @@ public static CampaignOptions generateCampaignOptionsFromXml(Node wn) {
} else if (wn2.getNodeName().equalsIgnoreCase("massRepairReplacePod")) {
retVal.massRepairReplacePod = Boolean.parseBoolean(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("massRepairOptions")) {
NodeList mroList = wn2.getChildNodes();

for (int mroIdx = 0; mroIdx < mroList.getLength(); mroIdx++) {
Node mroNode = mroList.item(mroIdx);

if (mroNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}

for (int mroTypeIdx = 0; mroTypeIdx < MassRepairOption.VALID_REPAIR_TYPES.length; mroTypeIdx++) {
if (mroNode.getNodeName().equalsIgnoreCase("massRepairOption" + mroTypeIdx)) {

MassRepairOption mro = new MassRepairOption();
mro.setType(-1);

NodeList mroItemList = mroNode.getChildNodes();

for (int mroItemIdx = 0; mroItemIdx < mroItemList.getLength(); mroItemIdx++) {
Node mroItemNode = mroItemList.item(mroItemIdx);

if (mroItemNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
MekHQ.getLogger().info(CampaignOptions.class, String.format("massRepairOption %d.%s\n\t%s",
mroTypeIdx, mroItemNode.getNodeName(), mroItemNode.getTextContent()));

if (mroItemNode.getNodeName().equalsIgnoreCase("type")) {
mro.setType(Integer.parseInt(mroItemNode.getTextContent().trim()));
} else if (mroItemNode.getNodeName().equalsIgnoreCase("active")) {
mro.setActive(Integer.parseInt(mroItemNode.getTextContent().trim()) == 1);
} else if (mroItemNode.getNodeName().equalsIgnoreCase("skillMin")) {
mro.setSkillMin(Integer.parseInt(mroItemNode.getTextContent().trim()));
} else if (mroItemNode.getNodeName().equalsIgnoreCase("skillMax")) {
mro.setSkillMax(Integer.parseInt(mroItemNode.getTextContent().trim()));
} else if (mroItemNode.getNodeName().equalsIgnoreCase("btnMin")) {
mro.setBthMin(Integer.parseInt(mroItemNode.getTextContent().trim()));
} else if (mroItemNode.getNodeName().equalsIgnoreCase("btnMax")) {
mro.setBthMax(Integer.parseInt(mroItemNode.getTextContent().trim()));
}
}

if (mro.getType() != -1) {
retVal.addMassRepairOption(mro);
}
}
}
}
retVal.setMassRepairOptions(MassRepairOption.parseListFromXML(wn2));
}
}

MekHQ.getLogger().info(CampaignOptions.class, "Load Campaign Options Complete!");
MekHQ.getLogger().debug("Load Campaign Options Complete!");

return retVal;
}

//region Migration
/**
* This is annoyingly required for the case of anyone having changed the surname weights.
* The code is not nice, but will nicely handle the cases where anyone has made changes
Expand Down Expand Up @@ -4063,83 +4007,5 @@ private static void migrateMarriageSurnameWeights(CampaignOptions retVal, String
retVal.randomMarriageSurnameWeights[12] = weights[8];
}
}

public static class MassRepairOption {
public MassRepairOption() {

}

public MassRepairOption(int type) {
this (type, false, SkillType.EXP_ULTRA_GREEN, SkillType.EXP_ELITE, 4, 4);
}

public MassRepairOption(int type, boolean active, int skillMin, int skillMax, int bthMin, int bthMax) {
this.type = type;
this.active = active;
this.skillMin = skillMin;
this.skillMax = skillMax;
this.bthMin = bthMin;
this.bthMax = bthMax;
}

public static final int[] VALID_REPAIR_TYPES = new int[] { Part.REPAIR_PART_TYPE.ARMOR, Part.REPAIR_PART_TYPE.AMMO,
Part.REPAIR_PART_TYPE.WEAPON, Part.REPAIR_PART_TYPE.GENERAL_LOCATION, Part.REPAIR_PART_TYPE.ENGINE,
Part.REPAIR_PART_TYPE.GYRO, Part.REPAIR_PART_TYPE.ACTUATOR, Part.REPAIR_PART_TYPE.ELECTRONICS,
Part.REPAIR_PART_TYPE.POD_SPACE, Part.REPAIR_PART_TYPE.GENERAL };

private int type;
private boolean active = true;
private int skillMin;
private int skillMax;
private int bthMin;
private int bthMax;

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public int getSkillMin() {
return skillMin;
}

public void setSkillMin(int skillMin) {
this.skillMin = skillMin;
}

public int getSkillMax() {
return skillMax;
}

public void setSkillMax(int skillMax) {
this.skillMax = skillMax;
}

public int getBthMin() {
return bthMin;
}

public void setBthMin(int bthMin) {
this.bthMin = bthMin;
}

public int getBthMax() {
return bthMax;
}

public void setBthMax(int bthMax) {
this.bthMax = bthMax;
}
}
//endregion Migration
}
Loading

0 comments on commit 26f6d5d

Please sign in to comment.