From 6fb350f9ceb39a77631cec92877e68a3782623d3 Mon Sep 17 00:00:00 2001 From: algebro Date: Fri, 18 Oct 2024 09:57:11 -0400 Subject: [PATCH 01/10] add static hiring hall data --- MekHQ/data/universe/systems.xml | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/MekHQ/data/universe/systems.xml b/MekHQ/data/universe/systems.xml index df7a6b4621..457722a701 100644 --- a/MekHQ/data/universe/systems.xml +++ b/MekHQ/data/universe/systems.xml @@ -35472,6 +35472,10 @@ A few Stone Age tribes exist in the planet's deep deserts and jungles, far from 281.417 K4IV 3 + + 2694-01-01 + QUESTIONABLE + Riverhead Giant Terrestrial @@ -40713,6 +40717,10 @@ Arboris has a history of fierce independence. In 2308, Arboris seceded from the 226.576 G3V 4 + + 3057-01-01 + STANDARD + Plowden's Stand Dwarf Terrestrial @@ -48861,6 +48869,10 @@ Though a major exporter of heavy metals and radioactive elements, as well as sma -315.408 G4V 3 + + 2912-01-01 + QUESTIONABLE + Frey Dwarf Terrestrial @@ -221714,6 +221726,11 @@ Coalition Armory -23.569 G4V 7 + + 3058-01-01 + 3081-03-15 + MINOR + Csurgói Járás Terrestrial @@ -230631,6 +230648,10 @@ At the dawn the thirty-second century, a surgical strike from the Lyran Commonwe 34.077 F8II 6 + + 2650-01-01 + GREAT + Skouzas's Frontier Terrestrial @@ -280553,6 +280574,10 @@ Freeport Armorworks -430.11 G3IV 2 + + 3020-01-01 + MINOR + Mugoma Giant Terrestrial @@ -373827,6 +373852,11 @@ Aside from the large island continent of Galapagos in the northern hemisphere of 18.309 G0III 4 + + 2811-01-01 + 3045-01-01 + MINOR + Port de Nedelec Terrestrial @@ -480796,6 +480826,10 @@ Niops V and VI were settled primarily to expand the available resources to the N 148.073 K0V 3 + + 3052-01-01 + MINOR + Kaarst Terrestrial @@ -482463,6 +482497,11 @@ During the Fourth Succession War, the Federated Suns leaked false reports of ung -2.891 G2IV 2 + + 3057-01-01 + 3081-03-15 + GREAT + Bloomsburg Giant Terrestrial @@ -498966,6 +499005,11 @@ Rim Motors -34.688 K9V 2 + + 3031-01-01 + 3067-10-15 + GREAT + Chen Dwarf Terrestrial @@ -601689,6 +601733,10 @@ During the Jihad, the Word of Blake forces invaded after they neutralized the de -7.025 K1V 7 + + 2700-01-01 + MINOR + Sanopi Dwarf Terrestrial @@ -701566,6 +701614,10 @@ Wei is home to one of the many Duchy RTC training facilities in the Confederatio -276.084 G3V 2 + + 3000-01-01 + GREAT + High Kelling Giant Terrestrial From aace0e03f0f11b1b717163f6e7ac3b3c161da464 Mon Sep 17 00:00:00 2001 From: algebro Date: Fri, 18 Oct 2024 11:15:39 -0400 Subject: [PATCH 02/10] add hiring hall override class --- .../campaign/universe/HiringHallOverride.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java diff --git a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java new file mode 100644 index 0000000000..dc44ed777d --- /dev/null +++ b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 - The MegaMek Team. 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 . + */ +package mekhq.campaign.universe; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import mekhq.adapter.LocalDateAdapter; +import mekhq.campaign.universe.enums.HiringHallLevel; + +import java.time.LocalDate; + +@XmlRootElement(name = "hiringHall") +@XmlAccessorType(value = XmlAccessType.FIELD) +public class HiringHallOverride { + @XmlJavaTypeAdapter(value = LocalDateAdapter.class) + private LocalDate start; + @XmlJavaTypeAdapter(value = LocalDateAdapter.class) + private LocalDate end; + @XmlElement(name = "level", required = false) + private HiringHallLevel level; + + + public LocalDate getStart() { + return start; + } + + public void setStart(LocalDate start) { + this.start = start; + } + + public LocalDate getEnd() { + return end; + } + + public void setEnd(LocalDate end) { + this.end = end; + } + + public HiringHallLevel getLevel() { + return level; + } + + public void setLevel(HiringHallLevel level) { + this.level = level; + } + + public boolean isActive(LocalDate date) { + return date.isAfter(start) && date.isBefore(end); + } +} From 582a85c5a58244e6563f1bca4f79e60caf64c4e6 Mon Sep 17 00:00:00 2001 From: algebro Date: Fri, 18 Oct 2024 11:15:53 -0400 Subject: [PATCH 03/10] add local date adapter --- MekHQ/src/mekhq/adapter/LocalDateAdapter.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 MekHQ/src/mekhq/adapter/LocalDateAdapter.java diff --git a/MekHQ/src/mekhq/adapter/LocalDateAdapter.java b/MekHQ/src/mekhq/adapter/LocalDateAdapter.java new file mode 100644 index 0000000000..323332cc24 --- /dev/null +++ b/MekHQ/src/mekhq/adapter/LocalDateAdapter.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 - The MegaMek Team. 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 . + */ +package mekhq.adapter; + +import jakarta.xml.bind.annotation.adapters.XmlAdapter; + +import java.time.LocalDate; + +public class LocalDateAdapter extends XmlAdapter { + @Override + public LocalDate unmarshal(String v) throws Exception { + return LocalDate.parse(v); + } + + @Override + public String marshal(LocalDate v) throws Exception { + return v.toString(); + } +} From 69bd29b541edf03b87a4965e36a376d77cf2d9e1 Mon Sep 17 00:00:00 2001 From: algebro Date: Fri, 18 Oct 2024 11:16:16 -0400 Subject: [PATCH 04/10] WIP: add static hiring hall overrides to PlanetarySystem --- MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java index 042017ed94..db83243601 100644 --- a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java +++ b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java @@ -133,6 +133,9 @@ public class PlanetarySystem { // the location of the primary planet for this system private int primarySlot; + @XmlElement(name = "hiringHall", required = false) + private HiringHallOverride staticHall = null; + /** Marker for "please delete this system" */ @XmlJavaTypeAdapter(value = BooleanValueAdapter.class) public Boolean delete; From e361722feef9919895334bdf78f7e3bca6ebdf7b Mon Sep 17 00:00:00 2001 From: algebro Date: Sat, 19 Oct 2024 13:47:07 -0400 Subject: [PATCH 05/10] extract some logic out of getHiringHallLevel() --- .../mekhq/campaign/universe/PlanetarySystem.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java index db83243601..768594bcad 100644 --- a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java +++ b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java @@ -133,7 +133,7 @@ public class PlanetarySystem { // the location of the primary planet for this system private int primarySlot; - @XmlElement(name = "hiringHall", required = false) + @XmlElement(name = "hiringHall") private HiringHallOverride staticHall = null; /** Marker for "please delete this system" */ @@ -753,10 +753,12 @@ public boolean isHiringHall(LocalDate date) { * @return The hiring hall level on the given date */ public HiringHallLevel getHiringHallLevel(LocalDate date) { + if (staticHall != null && staticHall.isActive(date)) { + return staticHall.getLevel(); + } if (getPopulation(date) == 0) { return HiringHallLevel.NONE; } - int score = 0; for (Faction faction : getFactionSet(date)) { if (faction.isPirate() || faction.isChaos()) { return HiringHallLevel.QUESTIONABLE; @@ -765,8 +767,18 @@ public HiringHallLevel getHiringHallLevel(LocalDate date) { return HiringHallLevel.NONE; } } + int score = calculateHiringHallScore(date); + return resolveHiringHallScore(score); + } + + private int calculateHiringHallScore(LocalDate date) { + int score = 0; score += getHiringHallHpgBonus(date); score += getHiringHallTechBonus(date); + return score; + } + + private HiringHallLevel resolveHiringHallScore(int score) { if (score > 9) { return HiringHallLevel.GREAT; } else if (score > 6) { From 962c1698cdfbbb784d0f9a3b0f57872182bb4707 Mon Sep 17 00:00:00 2001 From: algebro Date: Sat, 19 Oct 2024 13:48:30 -0400 Subject: [PATCH 06/10] remove redundant qualifier --- MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java index dc44ed777d..a026f5fa26 100644 --- a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java +++ b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java @@ -35,7 +35,7 @@ public class HiringHallOverride { private LocalDate start; @XmlJavaTypeAdapter(value = LocalDateAdapter.class) private LocalDate end; - @XmlElement(name = "level", required = false) + @XmlElement(name = "level") private HiringHallLevel level; From ef496b1b275380974733337b67fab3f858e73696 Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 21 Oct 2024 10:44:36 -0400 Subject: [PATCH 07/10] add missing / --- MekHQ/data/universe/systems.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MekHQ/data/universe/systems.xml b/MekHQ/data/universe/systems.xml index 457722a701..51eec658d6 100644 --- a/MekHQ/data/universe/systems.xml +++ b/MekHQ/data/universe/systems.xml @@ -499007,7 +499007,7 @@ Rim Motors 2 3031-01-01 - 3067-10-15 + 3067-10-15 GREAT From e874757fe2dd2e2e49ab008b66c63e23d9925f6b Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 21 Oct 2024 10:54:21 -0400 Subject: [PATCH 08/10] fix handling of null dates in isActive() --- .../campaign/universe/HiringHallOverride.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java index a026f5fa26..3953615473 100644 --- a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java +++ b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java @@ -18,10 +18,7 @@ */ package mekhq.campaign.universe; -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import mekhq.adapter.LocalDateAdapter; import mekhq.campaign.universe.enums.HiringHallLevel; @@ -32,28 +29,11 @@ @XmlAccessorType(value = XmlAccessType.FIELD) public class HiringHallOverride { @XmlJavaTypeAdapter(value = LocalDateAdapter.class) - private LocalDate start; + private LocalDate start = null; @XmlJavaTypeAdapter(value = LocalDateAdapter.class) - private LocalDate end; - @XmlElement(name = "level") - private HiringHallLevel level; - - - public LocalDate getStart() { - return start; - } - - public void setStart(LocalDate start) { - this.start = start; - } - - public LocalDate getEnd() { - return end; - } - - public void setEnd(LocalDate end) { - this.end = end; - } + private LocalDate end = null; + @XmlElement + private HiringHallLevel level = HiringHallLevel.NONE; public HiringHallLevel getLevel() { return level; @@ -64,6 +44,15 @@ public void setLevel(HiringHallLevel level) { } public boolean isActive(LocalDate date) { + // Hall has no start date, so it's always inactive + if (start == null) { + return false; + } + // Hall has a start date and no end date, so it's always active + if (end == null) { + return true; + } + // Hall has a start date and end date, so it's only active between those dates return date.isAfter(start) && date.isBefore(end); } } From 44e2aa4212d8ed53f4f3ed55db184d84b37fb1c3 Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 21 Oct 2024 10:59:16 -0400 Subject: [PATCH 09/10] add docstrings --- .../campaign/universe/HiringHallOverride.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java index 3953615473..8c9dcef3b6 100644 --- a/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java +++ b/MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java @@ -25,6 +25,14 @@ import java.time.LocalDate; +/** + * Class representing an "override" for the dynamic hiring hall system. Normally, hiring halls are + * generated dynamically based on planetary system factors like tech level and HPG quality, but some + * canonical systems should have hiring halls of certain qualities despite what the dynamic formula + * says. + * Overrides are stored as child elements of planetary systems in systems.xml, with a start date, + * optional end date, and quality. + */ @XmlRootElement(name = "hiringHall") @XmlAccessorType(value = XmlAccessType.FIELD) public class HiringHallOverride { @@ -35,14 +43,31 @@ public class HiringHallOverride { @XmlElement private HiringHallLevel level = HiringHallLevel.NONE; + /** + * Gets the level of the hiring hall for this override + * + * @return The hiring hall level as an enum + */ public HiringHallLevel getLevel() { return level; } + /** + * Sets the hiring hall level for this override + * + * @param level The level of hiring hall + */ public void setLevel(HiringHallLevel level) { this.level = level; } + /** + * Checks whether the hiring hall is active on a certain date. Returns true if no end date is + * specified in the override. + * + * @param date The date to check whether the hiring hall is active + * @return boolean representing whether the hiring hall is active + */ public boolean isActive(LocalDate date) { // Hall has no start date, so it's always inactive if (start == null) { From e4c6f66a863965efd7886c73ead2fc8c63370d2c Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 21 Oct 2024 12:44:53 -0400 Subject: [PATCH 10/10] rename method to be less confusing --- MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java index 768594bcad..0e9a36c338 100644 --- a/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java +++ b/MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java @@ -768,7 +768,7 @@ public HiringHallLevel getHiringHallLevel(LocalDate date) { } } int score = calculateHiringHallScore(date); - return resolveHiringHallScore(score); + return resolveHiringHallLevel(score); } private int calculateHiringHallScore(LocalDate date) { @@ -778,7 +778,7 @@ private int calculateHiringHallScore(LocalDate date) { return score; } - private HiringHallLevel resolveHiringHallScore(int score) { + private HiringHallLevel resolveHiringHallLevel(int score) { if (score > 9) { return HiringHallLevel.GREAT; } else if (score > 6) {