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

Prevent Early Clan Units in Non-Clan Campaigns #5094

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions MekHQ/src/mekhq/campaign/market/unitMarket/AbstractUnitMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
*/
package mekhq.campaign.market.unitMarket;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.client.ratgenerator.MissionRole;
import megamek.common.Compute;
Expand All @@ -40,6 +31,15 @@
import mekhq.campaign.market.enums.UnitMarketType;
import mekhq.campaign.universe.Faction;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;

public abstract class AbstractUnitMarket {
private static final MMLogger logger = MMLogger.create(AbstractUnitMarket.class);
Expand Down Expand Up @@ -78,7 +78,7 @@ public void setOffers(final List<UnitMarketOffer> offers) {
* This is the primary method for processing the Unit Market. It is executed as
* part of
* {@link Campaign#newDay()}
*
*
* @param campaign the campaign to process the Unit Market new day using
*/
public abstract void processNewDay(final Campaign campaign);
Expand All @@ -88,14 +88,14 @@ public void setOffers(final List<UnitMarketOffer> offers) {
* This is the primary Unit Market generation method, which is how the market
* specified
* generates unit offers
*
*
* @param campaign the campaign to generate the unit offers for
*/
public abstract void generateUnitOffers(final Campaign campaign);

/**
* This adds a number of unit offers
*
*
* @param campaign the campaign to add the offers based on
* @param number the number of units to generate
* @param market the unit market type the unit is part of
Expand Down Expand Up @@ -191,8 +191,20 @@ public abstract void addOffers(final Campaign campaign, final int number, UnitMa
public String addSingleUnit(final Campaign campaign, final UnitMarketType market,
final int unitType, final MekSummary mekSummary,
final int percent) {
final LocalDate BATTLE_OF_TUKAYYID = LocalDate.of(3052, 5, 21);

Faction campaignFaction = campaign.getFaction();
LocalDate currentDate = campaign.getLocalDate();

if (!campaignFaction.isClan()) {
if (mekSummary.isClan() && currentDate.isBefore(BATTLE_OF_TUKAYYID)) {
return null;
}
}

getOffers().add(new UnitMarketOffer(market, unitType, mekSummary, percent,
generateTransitDuration(campaign)));

return mekSummary.getName();
}

Expand Down Expand Up @@ -229,7 +241,7 @@ protected void writeRefreshReport(final Campaign campaign) {
* This is the primary Unit Market removal method, which is how the market
* specified
* removes unit offers
*
*
* @param campaign the campaign to use in determining the offers to remove
*/
protected abstract void removeUnitOffers(final Campaign campaign);
Expand All @@ -239,7 +251,7 @@ protected void writeRefreshReport(final Campaign campaign) {
// region File I/O
/**
* This writes the Unit Market to XML
*
*
* @param pw the PrintWriter to write to
* @param indent the base indent level to write at
*/
Expand All @@ -253,7 +265,7 @@ public void writeToXML(final PrintWriter pw, int indent) {
* This is meant to be overridden so that a market can have additional elements
* added to it,
* albeit with this called by super.writeBodyToXML(pw, indent) first.
*
*
* @param pw the PrintWriter to write to
* @param indent the base indent level to write at
*/
Expand All @@ -267,7 +279,7 @@ protected void writeBodyToXML(final PrintWriter pw, int indent) {
* This method fills the market based on the supplied XML node. The market is
* initialized as
* empty before this is called.
*
*
* @param wn the node to fill the market from
* @param campaign the campaign the market is being parsed as part of
* @param version the version of the market being parsed
Expand All @@ -291,7 +303,7 @@ public void fillFromXML(final Node wn, final Campaign campaign, final Version ve
* This is meant to be overridden so that a market can have additional elements
* added to it,
* albeit with this called by super.parseXMLNode(wn) first.
*
*
* @param wn the node to parse from XML
* @param campaign the campaign the market is being parsed as part of
* @param version the version of the market being parsed
Expand Down