Skip to content

Commit

Permalink
Merge pull request #5156 from IllianiCBT/stratCon_supplyDepot
Browse files Browse the repository at this point in the history
Refactor Supply Depot SP Modifiers to be Monthly
  • Loading branch information
HammerGS authored Nov 4, 2024
2 parents e0fb583 + 045596a commit c6bbbe3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion MekHQ/data/stratconfacilities/AlliedSupplyDepot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<facilityType>SupplyDepot</facilityType>
<owner>Allied</owner>
<weeklySPModifier>1</weeklySPModifier>
<userDescription>Provides 1 SP/week of allied logistical support.</userDescription>
<userDescription>Provides 1 SP/month of allied logistical support.</userDescription>
<visible>true</visible>
</StratconFacility>
43 changes: 25 additions & 18 deletions MekHQ/src/mekhq/campaign/stratcon/StratconFacility.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 - The MegaMek Team. All Rights Reserved.
* Copyright (c) 2020-2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand All @@ -18,14 +18,6 @@
*/
package mekhq.campaign.stratcon;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import javax.xml.transform.Source;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.Unmarshaller;
Expand All @@ -34,9 +26,16 @@
import mekhq.campaign.mission.ScenarioForceTemplate.ForceAlignment;
import mekhq.utilities.MHQXMLUtility;

import javax.xml.transform.Source;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
* This represents a facility in the StratCon context
*
*
* @author NickAragua
*/
@XmlRootElement(name = "StratconFacility")
Expand Down Expand Up @@ -68,7 +67,7 @@ public enum FacilityType {
private String capturedDefinition;
private boolean revealTrack;
private int scenarioOddsModifier;
private int weeklySPModifier;
private int monthlySPModifier;
private boolean preventAerospace;
// TODO: post-MVP
// private Map<String, Integer> fixedGarrisonUnitStates = new HashMap<>();
Expand Down Expand Up @@ -96,7 +95,7 @@ public StratconFacility clone() {
clone.setCapturedDefinition(capturedDefinition);
clone.revealTrack = revealTrack;
clone.scenarioOddsModifier = scenarioOddsModifier;
clone.weeklySPModifier = weeklySPModifier;
clone.monthlySPModifier = monthlySPModifier;
clone.preventAerospace = preventAerospace;
clone.userDescription = userDescription;
clone.biomes = new ArrayList<>(biomes);
Expand All @@ -115,7 +114,7 @@ public void copyRulesDataFrom(StratconFacility facility) {
setOwner(facility.getOwner());
setRevealTrack(facility.getRevealTrack());
setScenarioOddsModifier(facility.getScenarioOddsModifier());
setWeeklySPModifier(facility.getWeeklySPModifier());
setMonthlySPModifier(facility.getMonthlySPModifier());
setPreventAerospace(facility.preventAerospace());
setBiomes(new ArrayList<>(facility.getBiomes()));
setUserDescription(facility.getUserDescription());
Expand Down Expand Up @@ -254,12 +253,20 @@ public void setScenarioOddsModifier(int scenarioOddsModifier) {
this.scenarioOddsModifier = scenarioOddsModifier;
}

public int getWeeklySPModifier() {
return weeklySPModifier;
/**
* @return The facility's monthly SP (Support Points) modifier as an integer.
*/
public int getMonthlySPModifier() {
return monthlySPModifier;
}

public void setWeeklySPModifier(int weeklySPModifier) {
this.weeklySPModifier = weeklySPModifier;
/**
* Sets a new value for the monthly SP (Support Points) modifier.
*
* @param monthlySPModifier The new monthly SP modifier value.
*/
public void setMonthlySPModifier(int monthlySPModifier) {
this.monthlySPModifier = monthlySPModifier;
}

/**
Expand All @@ -273,7 +280,7 @@ public TreeMap<Integer, StratconBiome> getBiomeTempMap() {
/**
* Attempt to deserialize an instance of a StratconFacility from the passed-in
* file name
*
*
* @return Possibly an instance of a StratconFacility
*/
public static StratconFacility deserialize(String fileName) {
Expand Down
9 changes: 5 additions & 4 deletions MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@ private static void setupFacilityScenario(StratconScenario scenario, StratconFac
* Applies time-sensitive facility effects.
*/
private static void processFacilityEffects(StratconTrackState track,
StratconCampaignState campaignState, boolean isMonday) {
StratconCampaignState campaignState, boolean isStartOfMonth) {
for (StratconFacility facility : track.getFacilities().values()) {
if (isMonday) {
campaignState.addSupportPoints(facility.getWeeklySPModifier());
if (isStartOfMonth) {
campaignState.addSupportPoints(facility.getMonthlySPModifier());
}
}
}
Expand Down Expand Up @@ -1903,6 +1903,7 @@ public void handleNewDay(NewDayEvent ev) {
return;
}
boolean isMonday = ev.getCampaign().getLocalDate().getDayOfWeek() == DayOfWeek.MONDAY;
boolean isStartOfMonth = ev.getCampaign().getLocalDate().getDayOfMonth() == 1;

// run scenario generation routine for every track attached to an active
// contract
Expand All @@ -1919,7 +1920,7 @@ public void handleNewDay(NewDayEvent ev) {
// 0-deployment-length tracks
processTrackForceReturnDates(track, ev.getCampaign());

processFacilityEffects(track, campaignState, isMonday);
processFacilityEffects(track, campaignState, isStartOfMonth);

// loop through scenarios - if we haven't deployed in time,
// fail it and apply consequences
Expand Down

0 comments on commit c6bbbe3

Please sign in to comment.