diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index 5a569a3c4c2..4d614305054 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -209,8 +209,8 @@ public class Campaign implements Serializable, ITechManager { private Map ancestors = new LinkedHashMap<>(); private TreeMap parts = new TreeMap<>(); private TreeMap forceIds = new TreeMap<>(); - private TreeMap missions = new TreeMap<>(); - private TreeMap scenarios = new TreeMap<>(); + private TreeMap missions = new TreeMap<>(); + private TreeMap scenarios = new TreeMap<>(); private Map> kills = new HashMap<>(); private Map duplicateNameHash = new HashMap<>(); @@ -222,8 +222,6 @@ public class Campaign implements Serializable, ITechManager { private int lastPartId; private int lastForceId; - private int lastMissionId; - private int lastScenarioId; // indicates whether or not the campaign should be gzipped, if possible. private boolean preferGzippedOutput; @@ -982,7 +980,7 @@ public ArrayList getSortedMissions() { * @param id the int id of the team * @return a SupportTeam object */ - public Mission getMission(int id) { + public Mission getMission(UUID id) { return missions.get(id); } @@ -3721,7 +3719,7 @@ public void removeAllTechJobsFor(Person tech) { } } - public void removeScenario(int id) { + public void removeScenario(UUID id) { Scenario scenario = getScenario(id); scenario.clearAllForcesAndPersonnel(this); Mission mission = getMission(scenario.getMissionId()); @@ -3732,7 +3730,7 @@ public void removeScenario(int id) { MekHQ.triggerEvent(new ScenarioChangedEvent(scenario)); } - public void removeMission(int id) { + public void removeMission(UUID id) { Mission mission = getMission(id); // Loop through scenarios here! We need to remove them as well. diff --git a/MekHQ/src/mekhq/campaign/force/Lance.java b/MekHQ/src/mekhq/campaign/force/Lance.java index 939261477c7..268a53b36b1 100644 --- a/MekHQ/src/mekhq/campaign/force/Lance.java +++ b/MekHQ/src/mekhq/campaign/force/Lance.java @@ -87,7 +87,7 @@ public class Lance implements Serializable, MekHqXmlSerializable { public static final int NO_MISSION = -1; private int forceId; - private int missionId; + private UUID missionId; private int role; private UUID commanderId; @@ -106,7 +106,7 @@ public Lance() {} public Lance(int fid, Campaign c) { forceId = fid; role = ROLE_UNASSIGNED; - missionId = -1; + missionId = null; for (Mission m : c.getSortedMissions()) { if (!m.isActive()) { break; @@ -126,7 +126,7 @@ public int getForceId() { return forceId; } - public int getMissionId() { + public UUID getMissionId() { return missionId; } diff --git a/MekHQ/src/mekhq/campaign/mission/AtBContract.java b/MekHQ/src/mekhq/campaign/mission/AtBContract.java index 296589bced7..a2226e0a6a2 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBContract.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBContract.java @@ -171,11 +171,11 @@ public class AtBContract extends Contract implements Serializable { protected int nextWeekBattleTypeMod; protected AtBContract() { - this(null); + this(UUID.randomUUID(), null); } - public AtBContract(String name) { - super(name, "Independent"); + public AtBContract(UUID id, String name) { + super(id, name, "Independent"); employerCode = "IND"; enemyCode = "IND"; diff --git a/MekHQ/src/mekhq/campaign/mission/Contract.java b/MekHQ/src/mekhq/campaign/mission/Contract.java index 5d9eb635f8d..444f1e62dc7 100644 --- a/MekHQ/src/mekhq/campaign/mission/Contract.java +++ b/MekHQ/src/mekhq/campaign/mission/Contract.java @@ -27,6 +27,7 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.UUID; import mekhq.campaign.finances.Money; import org.apache.commons.text.CharacterPredicate; @@ -94,7 +95,7 @@ public class Contract extends Mission implements Serializable, MekHqXmlSerializa // runs through initial calculations, as the same jump path is referenced multiple times // and calculating it each time is expensive. No need to preserve it in save date. private JumpPath cachedJumpPath; - + // need to keep track of total value salvaged for salvage rights private Money salvagedByUnit = Money.zero(); private Money salvagedByEmployer = Money.zero(); @@ -110,11 +111,12 @@ public class Contract extends Mission implements Serializable, MekHqXmlSerializa private Money feeAmount = Money.zero(); public Contract() { - this(null, null); + this(UUID.randomUUID(), null, null); } - public Contract(String name, String employer) { - super(name); + public Contract(UUID id, String name, String employer) { + super(id, name); + this.employer = employer; this.nMonths = 12; @@ -397,13 +399,13 @@ public void setSystemId(String n) { super.setSystemId(n); cachedJumpPath = null; } - + /** * Gets the currently calculated jump path for this contract, * only recalculating if it's not valid any longer or hasn't been calculated yet. */ public JumpPath getJumpPath(Campaign c) { - // if we don't have a cached jump path, or if the jump path's starting/ending point + // if we don't have a cached jump path, or if the jump path's starting/ending point // no longer match the campaign's current location or contract's destination if((cachedJumpPath == null) || (cachedJumpPath.size() == 0) || @@ -411,14 +413,14 @@ public JumpPath getJumpPath(Campaign c) { !cachedJumpPath.getLastSystem().getId().equals(getSystem().getId())) { cachedJumpPath = c.calculateJumpPath(c.getCurrentSystem(), getSystem()); } - + return cachedJumpPath; } - + public void setJumpPath(JumpPath path) { cachedJumpPath = path; } - + public Money getMonthlyPayOut() { if (getLength() <= 0) { return Money.zero(); diff --git a/MekHQ/src/mekhq/campaign/mission/Mission.java b/MekHQ/src/mekhq/campaign/mission/Mission.java index 273268397c3..68f5deb17d5 100644 --- a/MekHQ/src/mekhq/campaign/mission/Mission.java +++ b/MekHQ/src/mekhq/campaign/mission/Mission.java @@ -1,20 +1,20 @@ /* * Mission.java - * + * * Copyright (c) 2011 Jay Lawson . All rights reserved. - * + * * This file is part of MekHQ. - * + * * MekHQ is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * MekHQ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with MekHQ. If not, see . */ @@ -24,6 +24,7 @@ import java.io.Serializable; import java.text.ParseException; import java.util.ArrayList; +import java.util.UUID; import org.joda.time.DateTime; import org.w3c.dom.NamedNodeMap; @@ -41,15 +42,15 @@ /** * Missions are primarily holder objects for a set of scenarios. - * + * * The really cool stuff will happen when we subclass this into Contract - * + * * @author Jay Lawson */ public class Mission implements Serializable, MekHqXmlSerializable { /** - * + * */ private static final long serialVersionUID = -5692134027829715149L; @@ -59,20 +60,22 @@ public class Mission implements Serializable, MekHqXmlSerializable { public static final int S_BREACH = 3; public static final int S_NUM = 4; + private UUID id; private String name; protected String systemId; private int status; private String desc; private String type; private ArrayList scenarios; - private int id = -1; + private int legacyId = -1; private String legacyPlanetName; public Mission() { - this(null); + this(UUID.randomUUID(), null); } - public Mission(String n) { + public Mission(UUID id, String n) { + this.id = id; this.name = n; this.systemId = "Unknown System"; this.desc = ""; @@ -124,9 +127,9 @@ public void setSystemId(String n) { public PlanetarySystem getSystem() { return Systems.getInstance().getSystemById(systemId); } - + /** - * Convenience property to return the name of the current planet. + * Convenience property to return the name of the current planet. * Sometimes, the "current planet" doesn't match up with an existing planet in our planet database, * in which case we return whatever was stored. * @return @@ -135,10 +138,10 @@ public String getSystemName(DateTime when) { if(getSystem() == null) { return legacyPlanetName; } - + return getSystem().getName(when); } - + public void setLegacyPlanetName(String name) { legacyPlanetName = name; } @@ -170,7 +173,7 @@ public ArrayList getScenarios() { /** * Don't use this method directly as it will not add an id to the added * scenario. Use Campaign#AddScenario instead - * + * * @param s */ public void addScenario(Scenario s) { @@ -178,31 +181,28 @@ public void addScenario(Scenario s) { scenarios.add(s); } - public int getId() { + public UUID getId() { return id; } - public void setId(int i) { - this.id = i; + public void setId(UUID id) { + this.id = id; + } + + public int getLegacyId() { + return legacyId; + } + + public void setLegacyId(int i) { + this.legacyId = i; } public boolean isActive() { return status == S_ACTIVE; } - public void removeScenario(int id) { - int idx = 0; - boolean found = false; - for (Scenario s : getScenarios()) { - if (s.getId() == id) { - found = true; - break; - } - idx++; - } - if (found) { - scenarios.remove(idx); - } + public void removeScenario(UUID id) { + scenarios.removeIf(s -> s.getId().equals(id)); } public void clearScenarios() { @@ -228,8 +228,8 @@ protected void writeToXmlBegin(PrintWriter pw1, int indent) { pw1.println(MekHqXmlUtil.indentStr(indent) + ""); pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "" + MekHqXmlUtil.escape(name) + ""); pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "" + MekHqXmlUtil.escape(type) + ""); - - if(systemId != null) { + + if(systemId != null) { pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "" + MekHqXmlUtil.escape(systemId) + ""); } else { pw1.println(MekHqXmlUtil.indentStr(indent + 1) + "" + MekHqXmlUtil.escape(legacyPlanetName) + ""); @@ -278,7 +278,7 @@ public static Mission generateInstanceFromXML(Node wn, Campaign c, Version versi retVal.systemId = wn2.getTextContent(); } else if (wn2.getNodeName().equalsIgnoreCase("planetName")) { PlanetarySystem system = c.getSystemByName(wn2.getTextContent()); - + if(system != null) { retVal.systemId = c.getSystemByName(wn2.getTextContent()).getId(); } else { @@ -287,7 +287,11 @@ public static Mission generateInstanceFromXML(Node wn, Campaign c, Version versi } else if (wn2.getNodeName().equalsIgnoreCase("status")) { retVal.status = Integer.parseInt(wn2.getTextContent()); } else if (wn2.getNodeName().equalsIgnoreCase("id")) { - retVal.id = Integer.parseInt(wn2.getTextContent()); + try { + retVal.id = UUID.fromString(wn2.getTextContent()); + } catch (IllegalArgumentException ex) { + retVal.legacyId = Integer.parseInt(wn2.getTextContent()); + } } else if (wn2.getNodeName().equalsIgnoreCase("desc")) { retVal.setDesc(wn2.getTextContent()); } else if (wn2.getNodeName().equalsIgnoreCase("type")) { diff --git a/MekHQ/src/mekhq/campaign/mission/Scenario.java b/MekHQ/src/mekhq/campaign/mission/Scenario.java index d075bba3922..eaab124a58a 100644 --- a/MekHQ/src/mekhq/campaign/mission/Scenario.java +++ b/MekHQ/src/mekhq/campaign/mission/Scenario.java @@ -67,6 +67,7 @@ public class Scenario implements Serializable { public static final int S_DEFAULT_ID = -1; + private UUID id; private String name; private String desc; private String report; @@ -74,8 +75,9 @@ public class Scenario implements Serializable { private Date date; private ArrayList subForceIds; private ArrayList unitIds; - private int id = S_DEFAULT_ID; - private int missionId; + private UUID missionId; + private int legacyId = S_DEFAULT_ID; + private int legacyMissionId; private ForceStub stub; //allow multiple loot objects for meeting different mission objectives @@ -87,10 +89,11 @@ public class Scenario implements Serializable { private Map> playerTransportLinkages; public Scenario() { - this(null); + this(UUID.randomUUID(), null); } - public Scenario(String n) { + public Scenario(UUID id, String n) { + this.id = id; this.name = n; this.desc = ""; this.report = ""; @@ -191,20 +194,36 @@ public void addPlayerTransportRelationship(UUID transportId, UUID cargoId) { playerTransportLinkages.get(transportId).add(cargoId); } - public int getId() { + public UUID getId() { return id; } - public void setId(int i) { - this.id = i; + public void setId(UUID id) { + this.id = id; } - public int getMissionId() { + public int getLegacyId() { + return legacyId; + } + + public void setLegacyId(int i) { + this.legacyId = i; + } + + public UUID getMissionId() { return missionId; } - public void setMissionId(int i) { - this.missionId = i; + public void setMissionId(UUID id) { + missionId = id; + } + + public int getLegacyMissionId() { + return legacyMissionId; + } + + public void setLegacyMissionId(int i) { + this.legacyMissionId = i; } public List getForceIDs() { @@ -432,7 +451,11 @@ public static Scenario generateInstanceFromXML(Node wn, Campaign c, Version vers } else if (wn2.getNodeName().equalsIgnoreCase("status")) { retVal.status = Integer.parseInt(wn2.getTextContent()); } else if (wn2.getNodeName().equalsIgnoreCase("id")) { - retVal.id = Integer.parseInt(wn2.getTextContent()); + try { + retVal.id = UUID.fromString(wn2.getTextContent()); + } catch (IllegalArgumentException ex) { + retVal.legacyId = Integer.parseInt(wn2.getTextContent()); + } } else if (wn2.getNodeName().equalsIgnoreCase("desc")) { retVal.setDesc(wn2.getTextContent()); } else if (wn2.getNodeName().equalsIgnoreCase("report")) {