Skip to content

Commit

Permalink
Merge pull request #2805 from Windchild292/dev_Windchild_274
Browse files Browse the repository at this point in the history
274: Moving Era Definitions to Data
  • Loading branch information
Windchild292 authored Aug 24, 2021
2 parents 33a0f49 + 3a471af commit ed447da
Show file tree
Hide file tree
Showing 9 changed files with 473 additions and 202 deletions.
95 changes: 95 additions & 0 deletions MekHQ/data/universe/eras.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Each Era consists of the following fields:
Code: The unique String code for the era.
Name: The display name for the era.
End: The end date for the era. This can be in the formats "yyyy-MM-dd", "yyyy-MM" (assuming first day of the month), and "yyyy" (assuming first day of the year). One era should have this value missing, which will put it as the final era. For the canon dates, these will be one year after their end date in the MUL, as that will swapover on the first day of the new era.
Flag: The internal flags for the base eras. You can have multiple flag fields (multiple lines each with a single flag) per custom era, which isn't used in base MekHQ, but allows one to customize things.
Note that internal use of this setup is minimal at best, at least as of 0.49.3.
-->
<eras>
<era>
<code>PSF</code>
<name>Pre-Spaceflight</name>
<end>1951</end>
<flag>PRE_SPACEFLIGHT</flag>
</era>
<era>
<code>ESF</code>
<name>Early Spaceflight</name>
<end>2005</end>
<flag>EARLY_SPACEFLIGHT</flag>
</era>
<era>
<code>AOW</code>
<name>Age of War</name>
<end>2571</end>
<flag>AGE_OF_WAR</flag>
</era>
<era>
<code>SL</code>
<name>Star League</name>
<end>2781</end>
<flag>STAR_LEAGUE</flag>
</era>
<era>
<code>ESW</code>
<name>Early Succession Wars</name>
<end>2901</end>
<flag>EARLY_SUCCESSION_WARS</flag>
</era>
<era>
<code>LSWL</code>
<name>Late Succession Wars - LosTech</name>
<end>3020</end>
<flag>LATE_SUCCESSION_WARS_LOSTECH</flag>
</era>
<era>
<code>LSWR</code>
<name>Late Succession Wars - Renaissance</name>
<end>3050</end>
<flag>LATE_SUCCESSION_WARS_RENAISSANCE</flag>
</era>
<era>
<code>CI</code>
<name>Clan Invasion</name>
<end>3062</end>
<flag>CLAN_INVASION</flag>
</era>
<era>
<code>CW</code>
<name>Civil War</name>
<end>3068</end>
<flag>CIVIL_WAR</flag>
</era>
<era>
<code>J</code>
<name>Jihad</name>
<end>3081</end>
<flag>JIHAD</flag>
</era>
<era>
<code>ER</code>
<name>Early Republic</name>
<end>3101</end>
<flag>EARLY_REPUBLIC</flag>
</era>
<era>
<code>LR</code>
<name>Late Republic</name>
<end>3131</end>
<flag>LATE_REPUBLIC</flag>
</era>
<era>
<code>DA</code>
<name>Dark Ages</name>
<end>3151</end>
<flag>DARK_AGES</flag>
</era>
<era>
<code>ILC</code>
<name>ilClan</name>
<flag>ILCLAN</flag>
</era>
</eras>
3 changes: 2 additions & 1 deletion MekHQ/src/mekhq/MekHqConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public final class MekHqConstants {
public static final String LAYERED_FORCE_ICON_FRAME_PATH = "Pieces/Frames/";
public static final String LAYERED_FORCE_ICON_LOGO_PATH = "Pieces/Logos/";
public static final String AWARDS_DIRECTORY_PATH = "data/universe/awards/";
public static final String RATINFO_DIR = "data/universe/ratdata";
public static final String RATINFO_DIR = "data/universe/ratdata/";
public static final String ERAS_FILE_PATH = "data/universe/eras.xml";
public static final String FACTION_HINTS_FILE = "data/universe/factionhints.xml";
public static final String RANKS_FILE_PATH = "data/universe/ranks.xml";
public static final String USER_RANKS_FILE_PATH = "userdata/data/universe/ranks.xml";
Expand Down
13 changes: 5 additions & 8 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import mekhq.campaign.personnel.ranks.RankSystem;
import mekhq.campaign.personnel.ranks.RankValidator;
import mekhq.campaign.personnel.ranks.Ranks;
import mekhq.campaign.universe.eras.Eras;
import mekhq.service.AutosaveService;
import mekhq.service.IAutosaveService;

Expand Down Expand Up @@ -148,7 +149,7 @@
import mekhq.campaign.universe.AbstractPlanetSelector;
import mekhq.campaign.universe.DefaultFactionSelector;
import mekhq.campaign.universe.DefaultPlanetSelector;
import mekhq.campaign.universe.Era;
import mekhq.campaign.universe.eras.Era;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Factions;
import mekhq.campaign.universe.IUnitGenerator;
Expand Down Expand Up @@ -381,18 +382,14 @@ public void setName(String s) {
this.name = s;
}

public String getEraName() {
return Era.getEraNameFromYear(getGameYear());
}

public int getEra() {
return Era.getEra(getGameYear());
public Era getEra() {
return Eras.getInstance().getEra(getLocalDate());
}

public String getTitle() {
return getName() + " (" + getFactionName() + ")" + " - "
+ MekHQ.getMekHQOptions().getLongDisplayFormattedDate(getLocalDate())
+ " (" + getEraName() + ")";
+ " (" + getEra() + ")";
}

public LocalDate getLocalDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import mekhq.campaign.personnel.SkillType;
import mekhq.campaign.personnel.enums.Phenotype;
import mekhq.campaign.unit.Unit;
import mekhq.campaign.universe.Era;
import mekhq.campaign.universe.enums.EraFlag;
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.Factions;
import mekhq.campaign.universe.Faction.Tag;
Expand Down Expand Up @@ -1478,10 +1478,9 @@ private static List<Integer> generateUnitTypes(int unitTypeCode, int unitCount,
// logic mostly lifted from AtBScenario.java, uses campaign config to determine tank/mech mixture
if (useVehicles) {
// some specialized logic for clan opfors
int era = Era.getEra(campaign.getGameYear());

// if we're in the late republic or dark ages, clans no longer have the luxury of mech only stars
boolean clanEquipmentScarcity = era == Era.E_LATE_REPUBLIC || era == Era.E_DARK_AGES;
boolean clanEquipmentScarcity = campaign.getEra()
.hasFlag(EraFlag.LATE_REPUBLIC, EraFlag.DARK_AGES, EraFlag.ILCLAN);

if (faction.isClan() && !clanEquipmentScarcity) {
return generateClanUnitTypes(unitCount, forceQuality, factionCode, campaign);
Expand Down
157 changes: 0 additions & 157 deletions MekHQ/src/mekhq/campaign/universe/Era.java

This file was deleted.

Loading

0 comments on commit ed447da

Please sign in to comment.