Skip to content

Commit 2344547

Browse files
committed
- Consolidated and clarified logic for filtering Clan technology based on campaign timeline.
- Replaced duplicate "isFactionClan" and "isBeforeBattleOfTukayyid" methods with streamlined versions. - Added detailed documentation and JavaDoc comments for the new helper methods `filterOutClanTech` and `isFactionClan`. - Removed redundant comments and legacy code snippets for improved readability.
1 parent 592827b commit 2344547

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

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

+43-23
Original file line numberDiff line numberDiff line change
@@ -1962,8 +1962,6 @@ public static Entity getEntity(String faction, SkillLevel skill, int quality, in
19621962
params.setYear(campaign.getGameYear());
19631963
params.setMissionRoles(rolesByType);
19641964

1965-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
1966-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
19671965
if (filterOutClanTech(campaign, isFactionClan(factionCode))) {
19681966
params.setFilter(mekSummary -> !mekSummary.isClan() &&
19691967
(unitType == GUN_EMPLACEMENT || mekSummary.getWalkMp() >= 1));
@@ -1990,10 +1988,6 @@ public static Entity getEntity(String faction, SkillLevel skill, int quality, in
19901988
return createEntityWithCrew(factionCode, skill, campaign, unitData);
19911989
}
19921990

1993-
private static boolean isBeforeBattleOfTukayyid(Campaign campaign) {
1994-
return campaign.getLocalDate().isBefore(BATTLE_OF_TUKAYYID);
1995-
}
1996-
19971991
/**
19981992
* Determines whether the weight class constraints should be bypassed based on the given mission roles.
19991993
* <p>
@@ -2055,8 +2049,6 @@ public static Entity getTankEntity(UnitGeneratorParameters params, SkillLevel sk
20552049
if (campaign.getCampaignOptions().isOpForUsesVTOLs()) {
20562050
params.getMovementModes().addAll(IUnitGenerator.MIXED_TANK_VTOL);
20572051
} else {
2058-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
2059-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
20602052
if (filterOutClanTech(campaign, isFactionClan(params.getFaction()))) {
20612053
params.setFilter(mekSummary -> !mekSummary.isClan() && !mekSummary.getUnitType().equals("VTOL"));
20622054
} else {
@@ -2083,8 +2075,50 @@ public static Entity getTankEntity(UnitGeneratorParameters params, SkillLevel sk
20832075
return createEntityWithCrew(params.getFaction(), skill, campaign, unitData);
20842076
}
20852077

2078+
/**
2079+
* Filters out Clan technology based on the campaign timeline and unit type.
2080+
*
2081+
* <p>Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan tech,
2082+
* at that time, would be closely guarded and not something we want OpFors to be generating with.</p>
2083+
*
2084+
* @param campaign The campaign object which contains timeline details.
2085+
* @param isClan A boolean indicating whether the unit is Clan technology.
2086+
*
2087+
* @return {@code true} if the unit should be filtered out (not Clan and before the Battle of Tukayyid),
2088+
* {@code false} otherwise.
2089+
*
2090+
* @author Illiani
2091+
* @since 0.50.05
2092+
*/
20862093
private static boolean filterOutClanTech(Campaign campaign, boolean isClan) {
2087-
return isBeforeBattleOfTukayyid(campaign) && !isClan;
2094+
boolean isBeforeTukayyid = campaign.getLocalDate().isBefore(BATTLE_OF_TUKAYYID);
2095+
2096+
return isBeforeTukayyid && !isClan;
2097+
}
2098+
2099+
/**
2100+
* Checks whether a given faction, identified by its name or identifier, belongs to the Clan faction group.
2101+
*
2102+
* <p>If the specified faction code cannot be parsed into a {@link Faction}, a warning is logged and {@code false}
2103+
* is returned.</p>
2104+
*
2105+
* @param params the name or identifier of the faction to check
2106+
*
2107+
* @return {@code true} if the specified faction exists and is classified as a Clan faction; {@code false} if the
2108+
* faction does not exist or is not a Clan faction
2109+
*
2110+
* @author Illiani
2111+
* @since 0.50.05
2112+
*/
2113+
private static boolean isFactionClan(String params) {
2114+
Faction faction = Factions.getInstance().getFaction(params);
2115+
2116+
if (faction == null) {
2117+
logger.warn("AtBDynamicScenarioFactory#isFactionClan) Faction {} does not exist.", params);
2118+
return false;
2119+
}
2120+
2121+
return faction.isClan();
20882122
}
20892123

20902124
/**
@@ -2404,8 +2438,6 @@ private static List<Entity> fillTransport(AtBScenario scenario, Entity transport
24042438
newParams.getMovementModes().add(EntityMovementMode.INF_LEG);
24052439
}
24062440

2407-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
2408-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
24092441
if (filterOutClanTech(campaign, isFactionClan(params.getFaction()))) {
24102442
params.setFilter(mekSummary -> !mekSummary.isClan() &&
24112443
mekSummary.getTons() <=
@@ -2448,8 +2480,6 @@ private static List<Entity> fillTransport(AtBScenario scenario, Entity transport
24482480
} else {
24492481
newParams.getMovementModes().addAll(IUnitGenerator.ALL_INFANTRY_MODES);
24502482

2451-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
2452-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
24532483
if (filterOutClanTech(campaign, isFactionClan(params.getFaction()))) {
24542484
params.setFilter(mekSummary -> !mekSummary.isClan() && mekSummary.getTons() <= bayCapacity);
24552485
} else {
@@ -2514,8 +2544,6 @@ private static List<Entity> fillTransport(AtBScenario scenario, Entity transport
25142544
// Set the parameters to filter out types that are too heavy for the provided
25152545
// bay space, or those that cannot use mechanized BA travel
25162546
if (bayCapacity != IUnitGenerator.NO_WEIGHT_LIMIT) {
2517-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
2518-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
25192547
if (filterOutClanTech(campaign, isFactionClan(params.getFaction()))) {
25202548
params.setFilter(mekSummary -> !mekSummary.isClan() && mekSummary.getTons() <= bayCapacity);
25212549
} else {
@@ -2531,8 +2559,6 @@ private static List<Entity> fillTransport(AtBScenario scenario, Entity transport
25312559
// If generating for an internal bay fails, try again as mechanized if the flag is set
25322560
if (unitData == null) {
25332561
if (newParams != null && bayCapacity != IUnitGenerator.NO_WEIGHT_LIMIT && retryAsMechanized) {
2534-
// Special handling for pre-Tukayyid, where Clan units shouldn't be appearing in non-Clan forces. Clan
2535-
// tech, at that time, would be closely guarded and not something we want OpFors to be generating with
25362562
if (filterOutClanTech(campaign, isFactionClan(params.getFaction()))) {
25372563
params.setFilter(mekSummary -> !mekSummary.isClan());
25382564
} else {
@@ -2555,12 +2581,6 @@ private static List<Entity> fillTransport(AtBScenario scenario, Entity transport
25552581
}
25562582
}
25572583

2558-
private static boolean isFactionClan(String params) {
2559-
Faction faction = Factions.getInstance().getFaction(params);
2560-
boolean isClan = faction != null && faction.isClan();
2561-
return isClan;
2562-
}
2563-
25642584
/**
25652585
* Generates and associates Battle Armor units with a designated transport.
25662586
*

0 commit comments

Comments
 (0)