27
27
*/
28
28
package mekhq .campaign .market .unitMarket ;
29
29
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
+
30
39
import megamek .Version ;
31
40
import megamek .client .ratgenerator .MissionRole ;
32
41
import megamek .common .Compute ;
43
52
import org .w3c .dom .Node ;
44
53
import org .w3c .dom .NodeList ;
45
54
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
-
53
55
public abstract class AbstractUnitMarket {
54
56
private static final MMLogger logger = MMLogger .create (AbstractUnitMarket .class );
55
57
@@ -58,7 +60,7 @@ public abstract class AbstractUnitMarket {
58
60
private List <UnitMarketOffer > offers ;
59
61
60
62
protected final transient ResourceBundle resources = ResourceBundle .getBundle ("mekhq.resources.Market" ,
61
- MekHQ .getMHQOptions ().getLocale ());
63
+ MekHQ .getMHQOptions ().getLocale ());
62
64
// endregion Variable Declarations
63
65
64
66
// region Constructors
@@ -83,20 +85,18 @@ public void setOffers(final List<UnitMarketOffer> offers) {
83
85
// endregion Getters/Setters
84
86
85
87
// region Process New Day
88
+
86
89
/**
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()}
90
91
*
91
92
* @param campaign the campaign to process the Unit Market new day using
92
93
*/
93
94
public abstract void processNewDay (Campaign campaign );
94
95
95
96
// region Generate Offers
97
+
96
98
/**
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
100
100
*
101
101
* @param campaign the campaign to generate the unit offers for
102
102
*/
@@ -109,32 +109,34 @@ public void setOffers(final List<UnitMarketOffer> offers) {
109
109
* @param number the number of units to generate
110
110
* @param market the unit market type the unit is part of
111
111
* @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.
116
114
* @param quality the quality of the unit to generate
117
115
* @param priceTarget the target number used to determine the percent
118
116
*/
119
117
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 );
121
119
122
120
/**
123
121
* @param campaign the campaign to use to generate the unit
124
122
* @param market the market type the unit is being offered in
125
123
* @param unitType the unit type to generate the unit with
126
124
* @param faction the faction to generate the unit from
127
125
* @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
132
129
*/
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 );
138
140
}
139
141
140
142
/**
@@ -145,19 +147,22 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
145
147
* @param quality the quality to generate the unit at
146
148
* @param movementModes the movement modes to generate for
147
149
* @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
152
153
*/
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 );
161
166
}
162
167
163
168
/**
@@ -169,22 +174,30 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
169
174
* @param quality the quality to generate the unit at
170
175
* @param movementModes the movement modes to generate for
171
176
* @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
176
180
*/
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 ()));
188
201
return (mekSummary == null ) ? null : addSingleUnit (campaign , market , unitType , mekSummary , percent );
189
202
}
190
203
@@ -193,14 +206,12 @@ public abstract void addOffers(Campaign campaign, int number, UnitMarketType mar
193
206
* @param market the market type the unit is being offered in
194
207
* @param unitType the unit type of the generated unit
195
208
* @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
+ *
198
211
* @return the name of the unit that has been added to the market
199
212
*/
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 ) {
204
215
205
216
Faction campaignFaction = campaign .getFaction ();
206
217
LocalDate currentDate = campaign .getLocalDate ();
@@ -211,8 +222,7 @@ public String addSingleUnit(final Campaign campaign, final UnitMarketType market
211
222
}
212
223
}
213
224
214
- getOffers ().add (new UnitMarketOffer (market , unitType , mekSummary , percent ,
215
- generateTransitDuration (campaign )));
225
+ getOffers ().add (new UnitMarketOffer (market , unitType , mekSummary , percent , generateTransitDuration (campaign )));
216
226
217
227
return mekSummary .getName ();
218
228
}
@@ -221,18 +231,20 @@ public String addSingleUnit(final Campaign campaign, final UnitMarketType market
221
231
* @param campaign the campaign to generate the unit weight based on
222
232
* @param unitType the unit type to determine the format of weight to generate
223
233
* @param faction the faction to generate the weight for
234
+ *
224
235
* @return the generated weight
225
236
*/
226
- protected abstract int generateWeight (Campaign campaign , int unitType ,
227
- Faction faction );
237
+ protected abstract int generateWeight (Campaign campaign , int unitType , Faction faction );
228
238
229
239
/**
230
240
* @param campaign the campaign to use to generate the transit duration
241
+ *
231
242
* @return the generated transit duration
232
243
*/
233
244
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 );
236
248
}
237
249
238
250
/**
@@ -246,10 +258,9 @@ protected void writeRefreshReport(final Campaign campaign) {
246
258
// endregion Generate Offers
247
259
248
260
// region Offer Removal
261
+
249
262
/**
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
253
264
*
254
265
* @param campaign the campaign to use in determining the offers to remove
255
266
*/
@@ -258,6 +269,7 @@ protected void writeRefreshReport(final Campaign campaign) {
258
269
// endregion Process New Day
259
270
260
271
// region File I/O
272
+
261
273
/**
262
274
* This writes the Unit Market to XML
263
275
*
@@ -271,9 +283,8 @@ public void writeToXML(final PrintWriter pw, int indent) {
271
283
}
272
284
273
285
/**
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.
277
288
*
278
289
* @param pw the PrintWriter to write to
279
290
* @param indent the base indent level to write at
@@ -285,9 +296,8 @@ protected void writeBodyToXML(final PrintWriter pw, int indent) {
285
296
}
286
297
287
298
/**
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.
291
301
*
292
302
* @param wn the node to fill the market from
293
303
* @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
309
319
}
310
320
311
321
/**
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.
315
324
*
316
325
* @param wn the node to parse from XML
317
326
* @param campaign the campaign the market is being parsed as part of
0 commit comments