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

Implement Hiring Hall Overrides #5069

Merged
merged 10 commits into from
Oct 21, 2024
52 changes: 52 additions & 0 deletions MekHQ/data/universe/systems.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35472,6 +35472,10 @@ A few Stone Age tribes exist in the planet's deep deserts and jungles, far from
<ycood>281.417</ycood>
<spectralType source="canon">K4IV</spectralType>
<primarySlot>3</primarySlot>
<hiringHall>
<start>2694-01-01</start>
<level>QUESTIONABLE</level>
</hiringHall>
<planet>
<name>Riverhead</name>
<type>Giant Terrestrial</type>
Expand Down Expand Up @@ -40713,6 +40717,10 @@ Arboris has a history of fierce independence. In 2308, Arboris seceded from the
<ycood>226.576</ycood>
<spectralType source="canon">G3V</spectralType>
<primarySlot>4</primarySlot>
<hiringHall>
<start>3057-01-01</start>
<level>STANDARD</level>
</hiringHall>
<planet>
<name>Plowden's Stand</name>
<type>Dwarf Terrestrial</type>
Expand Down Expand Up @@ -48861,6 +48869,10 @@ Though a major exporter of heavy metals and radioactive elements, as well as sma
<ycood>-315.408</ycood>
<spectralType source="canon">G4V</spectralType>
<primarySlot>3</primarySlot>
<hiringHall>
<start>2912-01-01</start>
<level>QUESTIONABLE</level>
</hiringHall>
<planet>
<name>Frey</name>
<type>Dwarf Terrestrial</type>
Expand Down Expand Up @@ -221714,6 +221726,11 @@ Coalition Armory</desc>
<ycood>-23.569</ycood>
<spectralType source="canon">G4V</spectralType>
<primarySlot>7</primarySlot>
<hiringHall>
<start>3058-01-01</start>
<end>3081-03-15</end>
<level>MINOR</level>
</hiringHall>
<planet>
<name>Csurgói Járás</name>
<type>Terrestrial</type>
Expand Down Expand Up @@ -230631,6 +230648,10 @@ At the dawn the thirty-second century, a surgical strike from the Lyran Commonwe
<ycood>34.077</ycood>
<spectralType source="canon">F8II</spectralType>
<primarySlot>6</primarySlot>
<hiringHall>
<start>2650-01-01</start>
<level>GREAT</level>
</hiringHall>
<planet>
<name>Skouzas's Frontier</name>
<type>Terrestrial</type>
Expand Down Expand Up @@ -280553,6 +280574,10 @@ Freeport Armorworks</desc>
<ycood>-430.11</ycood>
<spectralType source="canon">G3IV</spectralType>
<primarySlot>2</primarySlot>
<hiringHall>
<start>3020-01-01</start>
<level>MINOR</level>
</hiringHall>
<planet>
<name>Mugoma</name>
<type>Giant Terrestrial</type>
Expand Down Expand Up @@ -373827,6 +373852,11 @@ Aside from the large island continent of Galapagos in the northern hemisphere of
<ycood>18.309</ycood>
<spectralType source="canon">G0III</spectralType>
<primarySlot>4</primarySlot>
<hiringHall>
<start>2811-01-01</start>
<end>3045-01-01</end>
<level>MINOR</level>
</hiringHall>
<planet>
<name>Port de Nedelec</name>
<type>Terrestrial</type>
Expand Down Expand Up @@ -480796,6 +480826,10 @@ Niops V and VI were settled primarily to expand the available resources to the N
<ycood>148.073</ycood>
<spectralType source="canon">K0V</spectralType>
<primarySlot>3</primarySlot>
<hiringHall>
<start>3052-01-01</start>
<level>MINOR</level>
</hiringHall>
<planet>
<name>Kaarst</name>
<type>Terrestrial</type>
Expand Down Expand Up @@ -482463,6 +482497,11 @@ During the Fourth Succession War, the Federated Suns leaked false reports of ung
<ycood>-2.891</ycood>
<spectralType source="canon">G2IV</spectralType>
<primarySlot>2</primarySlot>
<hiringHall>
<start>3057-01-01</start>
<end>3081-03-15</end>
<level>GREAT</level>
</hiringHall>
<planet>
<name>Bloomsburg</name>
<type>Giant Terrestrial</type>
Expand Down Expand Up @@ -498966,6 +499005,11 @@ Rim Motors</desc>
<ycood>-34.688</ycood>
<spectralType source="canon">K9V</spectralType>
<primarySlot>2</primarySlot>
<hiringHall>
<start>3031-01-01</start>
<end>3067-10-15</end>
<level>GREAT</level>
</hiringHall>
<planet>
<name>Chen</name>
<type>Dwarf Terrestrial</type>
Expand Down Expand Up @@ -601689,6 +601733,10 @@ During the Jihad, the Word of Blake forces invaded after they neutralized the de
<ycood>-7.025</ycood>
<spectralType source="canon">K1V</spectralType>
<primarySlot>7</primarySlot>
<hiringHall>
<start>2700-01-01</start>
<level>MINOR</level>
</hiringHall>
<planet>
<name>Sanopi</name>
<type>Dwarf Terrestrial</type>
Expand Down Expand Up @@ -701566,6 +701614,10 @@ Wei is home to one of the many Duchy RTC training facilities in the Confederatio
<ycood>-276.084</ycood>
<spectralType source="canon">G3V</spectralType>
<primarySlot>2</primarySlot>
<hiringHall>
<start>3000-01-01</start>
<level>GREAT</level>
</hiringHall>
<planet>
<name>High Kelling</name>
<type>Giant Terrestrial</type>
Expand Down
35 changes: 35 additions & 0 deletions MekHQ/src/mekhq/adapter/LocalDateAdapter.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package mekhq.adapter;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

import java.time.LocalDate;

public class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
@Override
public LocalDate unmarshal(String v) throws Exception {
return LocalDate.parse(v);
}

@Override
public String marshal(LocalDate v) throws Exception {
return v.toString();
}
}
83 changes: 83 additions & 0 deletions MekHQ/src/mekhq/campaign/universe/HiringHallOverride.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package mekhq.campaign.universe;

import jakarta.xml.bind.annotation.*;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import mekhq.adapter.LocalDateAdapter;
import mekhq.campaign.universe.enums.HiringHallLevel;

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 {
@XmlJavaTypeAdapter(value = LocalDateAdapter.class)
private LocalDate start = null;
@XmlJavaTypeAdapter(value = LocalDateAdapter.class)
private LocalDate end = null;
@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) {
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);
}
}
17 changes: 16 additions & 1 deletion MekHQ/src/mekhq/campaign/universe/PlanetarySystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public class PlanetarySystem {
// the location of the primary planet for this system
private int primarySlot;

@XmlElement(name = "hiringHall")
private HiringHallOverride staticHall = null;

/** Marker for "please delete this system" */
@XmlJavaTypeAdapter(value = BooleanValueAdapter.class)
public Boolean delete;
Expand Down Expand Up @@ -750,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;
Expand All @@ -762,8 +767,18 @@ public HiringHallLevel getHiringHallLevel(LocalDate date) {
return HiringHallLevel.NONE;
}
}
int score = calculateHiringHallScore(date);
return resolveHiringHallLevel(score);
}

private int calculateHiringHallScore(LocalDate date) {
int score = 0;
score += getHiringHallHpgBonus(date);
score += getHiringHallTechBonus(date);
return score;
}

private HiringHallLevel resolveHiringHallLevel(int score) {
if (score > 9) {
return HiringHallLevel.GREAT;
} else if (score > 6) {
Expand Down