Skip to content

Commit e4020d6

Browse files
authored
Merge pull request #3282 from MegaMek/dev_Windchild_CurrentLocationXML
MekHqXmlUtil: CurrentLocation Swapover
2 parents 5a795f7 + 981ff3c commit e4020d6

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

MekHQ/src/mekhq/campaign/Campaign.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4139,7 +4139,7 @@ public void writeToXML(final PrintWriter pw) {
41394139
forces.writeToXML(pw, indent);
41404140
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "forces");
41414141
finances.writeToXml(pw, indent);
4142-
location.writeToXml(pw, indent);
4142+
location.writeToXML(pw, indent);
41434143
shoppingList.writeToXML(pw, indent);
41444144

41454145
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "kills");

MekHQ/src/mekhq/campaign/CurrentLocation.java

+17-30
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ public void setRecharged(Campaign campaign) {
183183
* forward
184184
*/
185185
public void newDay(Campaign campaign) {
186-
//recharge even if there is no jump path
187-
//because JumpShips don't go anywhere
186+
// recharge even if there is no jump path
187+
// because JumpShips don't go anywhere
188188
double hours = 24.0;
189189
double neededRechargeTime = currentSystem.getRechargeTime(campaign.getLocalDate());
190190
double usedRechargeTime = Math.min(hours, neededRechargeTime - rechargeTime);
@@ -198,10 +198,10 @@ public void newDay(Campaign campaign) {
198198
if ((null == jumpPath) || jumpPath.isEmpty()) {
199199
return;
200200
}
201-
//if we are not at the final jump point, then check to see if we are transiting
202-
//or if we can jump
201+
// if we are not at the final jump point, then check to see if we are transiting
202+
// or if we can jump
203203
if (jumpPath.size() > 1) {
204-
//first check to see if we are transiting
204+
// first check to see if we are transiting
205205
double usedTransitTime = Math.min(hours, 24.0 * (currentSystem.getTimeToJumpPoint(1.0) - transitTime));
206206
if (usedTransitTime > 0) {
207207
transitTime += usedTransitTime/24.0;
@@ -227,11 +227,11 @@ public void newDay(Campaign campaign) {
227227
jumpZenith = pickJumpPoint(campaign.getLocalDate());
228228
jumpPath.removeFirstSystem();
229229
MekHQ.triggerEvent(new LocationChangedEvent(this, true));
230-
//reduce remaining hours by usedRechargeTime or usedTransitTime, whichever is greater
230+
// reduce remaining hours by usedRechargeTime or usedTransitTime, whichever is greater
231231
hours -= Math.max(usedRechargeTime, usedTransitTime);
232232
transitTime = currentSystem.getTimeToJumpPoint(1.0);
233233
rechargeTime = 0;
234-
//if there are hours remaining, then begin recharging jump drive
234+
// if there are hours remaining, then begin recharging jump drive
235235
usedRechargeTime = Math.min(hours, neededRechargeTime - rechargeTime);
236236
if (usedRechargeTime > 0) {
237237
campaign.addReport("JumpShips spent " + (Math.round(100.0 * usedRechargeTime) / 100.0) + " hours recharging drives");
@@ -242,7 +242,7 @@ public void newDay(Campaign campaign) {
242242
}
243243
}
244244
}
245-
//if we are now at the final jump point, then lets begin in-system transit
245+
// if we are now at the final jump point, then lets begin in-system transit
246246
if (jumpPath.size() == 1) {
247247
double usedTransitTime = Math.min(hours, 24.0 * transitTime);
248248
campaign.addReport("DropShips spent " + (Math.round(100.0 * usedTransitTime) / 100.0) + " hours transiting into system");
@@ -256,29 +256,16 @@ public void newDay(Campaign campaign) {
256256
}
257257
}
258258

259-
public void writeToXml(PrintWriter pw1, int indent) {
260-
pw1.println(MHQXMLUtility.indentStr(indent) + "<location>");
261-
pw1.println(MHQXMLUtility.indentStr(indent+1)
262-
+ "<currentSystemId>"
263-
+MHQXMLUtility.escape(currentSystem.getId())
264-
+ "</currentSystemId>");
265-
pw1.println(MHQXMLUtility.indentStr(indent+1)
266-
+"<transitTime>"
267-
+transitTime
268-
+"</transitTime>");
269-
pw1.println(MHQXMLUtility.indentStr(indent+1)
270-
+"<rechargeTime>"
271-
+rechargeTime
272-
+"</rechargeTime>");
273-
pw1.println(MHQXMLUtility.indentStr(indent+1)
274-
+"<jumpZenith>"
275-
+jumpZenith
276-
+"</jumpZenith>");
277-
if (null != jumpPath) {
278-
jumpPath.writeToXML(pw1, indent+1);
259+
public void writeToXML(final PrintWriter pw, int indent) {
260+
MHQXMLUtility.writeSimpleXMLOpenTag(pw, indent++, "location");
261+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "currentSystemId", currentSystem.getId());
262+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "transitTime", transitTime);
263+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "rechargeTime", rechargeTime);
264+
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "jumpZenith", jumpZenith);
265+
if (jumpPath != null) {
266+
jumpPath.writeToXML(pw, indent);
279267
}
280-
pw1.println(MHQXMLUtility.indentStr(indent) + "</location>");
281-
268+
MHQXMLUtility.writeSimpleXMLCloseTag(pw, --indent, "location");
282269
}
283270

284271
public static CurrentLocation generateInstanceFromXML(Node wn, Campaign c) {

0 commit comments

Comments
 (0)