Skip to content

Commit 4b9286e

Browse files
authored
Merge pull request #6621 from IllianiBird/filterOutClanTech
Fix #6618: Implemented Pre-Tukayyid Clan Tech Restrictions to Force Generation
2 parents 17555d0 + 2344547 commit 4b9286e

File tree

5 files changed

+338
-249
lines changed

5 files changed

+338
-249
lines changed

MekHQ/src/mekhq/MHQConstants.java

+4
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,8 @@ public final class MHQConstants extends SuiteConstants {
340340
// endregion Backgrounds
341341

342342
// endregion File Paths
343+
344+
// startregion Important Dates
345+
public static final LocalDate BATTLE_OF_TUKAYYID = LocalDate.of(3052, 5, 21);
346+
// endregion Important Dates
343347
}

MekHQ/src/mekhq/campaign/market/unitMarket/AbstractUnitMarket.java

+88-79
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
*/
2828
package mekhq.campaign.market.unitMarket;
2929

30+
import static mekhq.MHQConstants.BATTLE_OF_TUKAYYID;
31+
32+
import java.io.PrintWriter;
33+
import java.time.LocalDate;
34+
import java.util.ArrayList;
35+
import java.util.Collection;
36+
import java.util.List;
37+
import java.util.ResourceBundle;
38+
3039
import megamek.Version;
3140
import megamek.client.ratgenerator.MissionRole;
3241
import megamek.common.Compute;
@@ -43,13 +52,6 @@
4352
import org.w3c.dom.Node;
4453
import org.w3c.dom.NodeList;
4554

46-
import java.io.PrintWriter;
47-
import java.time.LocalDate;
48-
import java.util.ArrayList;
49-
import java.util.Collection;
50-
import java.util.List;
51-
import java.util.ResourceBundle;
52-
5355
public abstract class AbstractUnitMarket {
5456
private static final MMLogger logger = MMLogger.create(AbstractUnitMarket.class);
5557

@@ -58,7 +60,7 @@ public abstract class AbstractUnitMarket {
5860
private List<UnitMarketOffer> offers;
5961

6062
protected final transient ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.Market",
61-
MekHQ.getMHQOptions().getLocale());
63+
MekHQ.getMHQOptions().getLocale());
6264
// endregion Variable Declarations
6365

6466
// region Constructors
@@ -83,20 +85,18 @@ public void setOffers(final List<UnitMarketOffer> offers) {
8385
// endregion Getters/Setters
8486

8587
// region Process New Day
88+
8689
/**
87-
* This is the primary method for processing the Unit Market. It is executed as
88-
* part of
89-
* {@link Campaign#newDay()}
90+
* This is the primary method for processing the Unit Market. It is executed as part of {@link Campaign#newDay()}
9091
*
9192
* @param campaign the campaign to process the Unit Market new day using
9293
*/
9394
public abstract void processNewDay(Campaign campaign);
9495

9596
// region Generate Offers
97+
9698
/**
97-
* This is the primary Unit Market generation method, which is how the market
98-
* specified
99-
* generates unit offers
99+
* This is the primary Unit Market generation method, which is how the market specified generates unit offers
100100
*
101101
* @param campaign the campaign to generate the unit offers for
102102
*/
@@ -109,32 +109,34 @@ public void setOffers(final List<UnitMarketOffer> offers) {
109109
* @param number the number of units to generate
110110
* @param market the unit market type the unit is part of
111111
* @param unitType the unit type to generate
112-
* @param faction the faction to add the offers for, or null. If null, that
113-
* must be handled within
114-
* this method before any generated offers may be added to
115-
* the market.
112+
* @param faction the faction to add the offers for, or null. If null, that must be handled within this method
113+
* before any generated offers may be added to the market.
116114
* @param quality the quality of the unit to generate
117115
* @param priceTarget the target number used to determine the percent
118116
*/
119117
public abstract void addOffers(Campaign campaign, int number, UnitMarketType market, int unitType,
120-
@Nullable Faction faction, int quality, int priceTarget);
118+
@Nullable Faction faction, int quality, int priceTarget);
121119

122120
/**
123121
* @param campaign the campaign to use to generate the unit
124122
* @param market the market type the unit is being offered in
125123
* @param unitType the unit type to generate the unit with
126124
* @param faction the faction to generate the unit from
127125
* @param quality the quality to generate the unit at
128-
* @param percent the percentage of the original unit cost the unit will be
129-
* offered at
130-
* @return the name of the unit that has been added to the market, or null if
131-
* none were added
126+
* @param percent the percentage of the original unit cost the unit will be offered at
127+
*
128+
* @return the name of the unit that has been added to the market, or null if none were added
132129
*/
133-
public @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market,
134-
final int unitType, final Faction faction,
135-
final int quality, final int percent) {
136-
return addSingleUnit(campaign, market, unitType, faction, quality, new ArrayList<>(),
137-
new ArrayList<>(), percent);
130+
public @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market, final int unitType,
131+
final Faction faction, final int quality, final int percent) {
132+
return addSingleUnit(campaign,
133+
market,
134+
unitType,
135+
faction,
136+
quality,
137+
new ArrayList<>(),
138+
new ArrayList<>(),
139+
percent);
138140
}
139141

140142
/**
@@ -145,19 +147,22 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
145147
* @param quality the quality to generate the unit at
146148
* @param movementModes the movement modes to generate for
147149
* @param missionRoles the mission roles to generate for
148-
* @param percent the percentage of the original unit cost the unit will
149-
* be offered at
150-
* @return the name of the unit that has been added to the market, or null if
151-
* none were added
150+
* @param percent the percentage of the original unit cost the unit will be offered at
151+
*
152+
* @return the name of the unit that has been added to the market, or null if none were added
152153
*/
153-
public @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market,
154-
final int unitType, final Faction faction,
155-
final int quality,
156-
final Collection<EntityMovementMode> movementModes,
157-
final Collection<MissionRole> missionRoles,
158-
final int percent) {
159-
return addSingleUnit(campaign, market, unitType, faction,
160-
generateWeight(campaign, unitType, faction), quality, movementModes, missionRoles, percent);
154+
public @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market, final int unitType,
155+
final Faction faction, final int quality, final Collection<EntityMovementMode> movementModes,
156+
final Collection<MissionRole> missionRoles, final int percent) {
157+
return addSingleUnit(campaign,
158+
market,
159+
unitType,
160+
faction,
161+
generateWeight(campaign, unitType, faction),
162+
quality,
163+
movementModes,
164+
missionRoles,
165+
percent);
161166
}
162167

163168
/**
@@ -169,22 +174,30 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
169174
* @param quality the quality to generate the unit at
170175
* @param movementModes the movement modes to generate for
171176
* @param missionRoles the mission roles to generate for
172-
* @param percent the percentage of the original unit cost the unit will
173-
* be offered at
174-
* @return the name of the unit that has been added to the market, or null if
175-
* none were added
177+
* @param percent the percentage of the original unit cost the unit will be offered at
178+
*
179+
* @return the name of the unit that has been added to the market, or null if none were added
176180
*/
177-
protected @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market,
178-
final int unitType, final Faction faction,
179-
final int weight, final int quality,
180-
final Collection<EntityMovementMode> movementModes,
181-
final Collection<MissionRole> missionRoles,
182-
final int percent) {
183-
final MekSummary mekSummary = campaign.getUnitGenerator().generate(faction.getShortName(),
184-
unitType, weight, campaign.getGameYear(), quality, movementModes, missionRoles,
185-
ms -> (!campaign.getCampaignOptions().isLimitByYear() || (campaign.getGameYear() > ms.getYear()))
186-
&& (!ms.isClan() || campaign.getCampaignOptions().isAllowClanPurchases())
187-
&& (ms.isClan() || campaign.getCampaignOptions().isAllowISPurchases()));
181+
protected @Nullable String addSingleUnit(final Campaign campaign, final UnitMarketType market, final int unitType,
182+
final Faction faction, final int weight, final int quality,
183+
final Collection<EntityMovementMode> movementModes, final Collection<MissionRole> missionRoles,
184+
final int percent) {
185+
final MekSummary mekSummary = campaign.getUnitGenerator()
186+
.generate(faction.getShortName(),
187+
unitType,
188+
weight,
189+
campaign.getGameYear(),
190+
quality,
191+
movementModes,
192+
missionRoles,
193+
ms -> (!campaign.getCampaignOptions().isLimitByYear() ||
194+
(campaign.getGameYear() > ms.getYear())) &&
195+
(!ms.isClan() ||
196+
campaign.getCampaignOptions()
197+
.isAllowClanPurchases()) &&
198+
(ms.isClan() ||
199+
campaign.getCampaignOptions()
200+
.isAllowISPurchases()));
188201
return (mekSummary == null) ? null : addSingleUnit(campaign, market, unitType, mekSummary, percent);
189202
}
190203

@@ -193,14 +206,12 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
193206
* @param market the market type the unit is being offered in
194207
* @param unitType the unit type of the generated unit
195208
* @param mekSummary the generated mek summary
196-
* @param percent the percentage of the original unit cost the unit will be
197-
* offered at
209+
* @param percent the percentage of the original unit cost the unit will be offered at
210+
*
198211
* @return the name of the unit that has been added to the market
199212
*/
200-
public String addSingleUnit(final Campaign campaign, final UnitMarketType market,
201-
final int unitType, final MekSummary mekSummary,
202-
final int percent) {
203-
final LocalDate BATTLE_OF_TUKAYYID = LocalDate.of(3052, 5, 21);
213+
public String addSingleUnit(final Campaign campaign, final UnitMarketType market, final int unitType,
214+
final MekSummary mekSummary, final int percent) {
204215

205216
Faction campaignFaction = campaign.getFaction();
206217
LocalDate currentDate = campaign.getLocalDate();
@@ -211,8 +222,7 @@ public String addSingleUnit(final Campaign campaign, final UnitMarketType market
211222
}
212223
}
213224

214-
getOffers().add(new UnitMarketOffer(market, unitType, mekSummary, percent,
215-
generateTransitDuration(campaign)));
225+
getOffers().add(new UnitMarketOffer(market, unitType, mekSummary, percent, generateTransitDuration(campaign)));
216226

217227
return mekSummary.getName();
218228
}
@@ -221,18 +231,20 @@ public String addSingleUnit(final Campaign campaign, final UnitMarketType market
221231
* @param campaign the campaign to generate the unit weight based on
222232
* @param unitType the unit type to determine the format of weight to generate
223233
* @param faction the faction to generate the weight for
234+
*
224235
* @return the generated weight
225236
*/
226-
protected abstract int generateWeight(Campaign campaign, int unitType,
227-
Faction faction);
237+
protected abstract int generateWeight(Campaign campaign, int unitType, Faction faction);
228238

229239
/**
230240
* @param campaign the campaign to use to generate the transit duration
241+
*
231242
* @return the generated transit duration
232243
*/
233244
protected int generateTransitDuration(final Campaign campaign) {
234-
return campaign.getCampaignOptions().isInstantUnitMarketDelivery() ? 0
235-
: campaign.calculatePartTransitTime(Compute.d6(2) - 2);
245+
return campaign.getCampaignOptions().isInstantUnitMarketDelivery() ?
246+
0 :
247+
campaign.calculatePartTransitTime(Compute.d6(2) - 2);
236248
}
237249

238250
/**
@@ -246,10 +258,9 @@ protected void writeRefreshReport(final Campaign campaign) {
246258
// endregion Generate Offers
247259

248260
// region Offer Removal
261+
249262
/**
250-
* This is the primary Unit Market removal method, which is how the market
251-
* specified
252-
* removes unit offers
263+
* This is the primary Unit Market removal method, which is how the market specified removes unit offers
253264
*
254265
* @param campaign the campaign to use in determining the offers to remove
255266
*/
@@ -258,6 +269,7 @@ protected void writeRefreshReport(final Campaign campaign) {
258269
// endregion Process New Day
259270

260271
// region File I/O
272+
261273
/**
262274
* This writes the Unit Market to XML
263275
*
@@ -271,9 +283,8 @@ public void writeToXML(final PrintWriter pw, int indent) {
271283
}
272284

273285
/**
274-
* This is meant to be overridden so that a market can have additional elements
275-
* added to it,
276-
* albeit with this called by super.writeBodyToXML(pw, indent) first.
286+
* This is meant to be overridden so that a market can have additional elements added to it, albeit with this called
287+
* by super.writeBodyToXML(pw, indent) first.
277288
*
278289
* @param pw the PrintWriter to write to
279290
* @param indent the base indent level to write at
@@ -285,9 +296,8 @@ protected void writeBodyToXML(final PrintWriter pw, int indent) {
285296
}
286297

287298
/**
288-
* This method fills the market based on the supplied XML node. The market is
289-
* initialized as
290-
* empty before this is called.
299+
* This method fills the market based on the supplied XML node. The market is initialized as empty before this is
300+
* called.
291301
*
292302
* @param wn the node to fill the market from
293303
* @param campaign the campaign the market is being parsed as part of
@@ -309,9 +319,8 @@ public void fillFromXML(final Node wn, final Campaign campaign, final Version ve
309319
}
310320

311321
/**
312-
* This is meant to be overridden so that a market can have additional elements
313-
* added to it,
314-
* albeit with this called by super.parseXMLNode(wn) first.
322+
* This is meant to be overridden so that a market can have additional elements added to it, albeit with this called
323+
* by super.parseXMLNode(wn) first.
315324
*
316325
* @param wn the node to parse from XML
317326
* @param campaign the campaign the market is being parsed as part of

MekHQ/src/mekhq/campaign/mission/AtBContract.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static megamek.common.enums.SkillLevel.parseFromInteger;
4747
import static megamek.common.enums.SkillLevel.parseFromString;
4848
import static megamek.utilities.ImageUtilities.scaleImageIcon;
49+
import static mekhq.MHQConstants.BATTLE_OF_TUKAYYID;
4950
import static mekhq.campaign.force.CombatTeam.getStandardForceSize;
5051
import static mekhq.campaign.force.ForceType.STANDARD;
5152
import static mekhq.campaign.force.FormationLevel.BATTALION;
@@ -1717,8 +1718,6 @@ public AtBContract(Contract c, Campaign campaign) {
17171718
* </p>
17181719
*/
17191720
public void clanTechSalvageOverride() {
1720-
final LocalDate BATTLE_OF_TUKAYYID = LocalDate.of(3052, 5, 21);
1721-
17221721
if (getEnemy().isClan() && !getEmployerFaction().isClan()) {
17231722
if (getStartDate().isBefore(BATTLE_OF_TUKAYYID)) {
17241723
setSalvageExchange(true);

0 commit comments

Comments
 (0)