diff --git a/megamek/src/megamek/client/ratgenerator/AbstractUnitRecord.java b/megamek/src/megamek/client/ratgenerator/AbstractUnitRecord.java index 13f1a8444b..27f4cdff6e 100644 --- a/megamek/src/megamek/client/ratgenerator/AbstractUnitRecord.java +++ b/megamek/src/megamek/client/ratgenerator/AbstractUnitRecord.java @@ -40,32 +40,26 @@ public AbstractUnitRecord(String chassis) { } /** - * Returns availability value modified for rating differential on +/- rating, and adjusted for - * the first few years before introduction (field experiments, etc.) and immediately after - * introduction (low rate initial production). + * Adjusts availability rating for the first couple years after introduction. * - * @param initialAv AvailabilityRating for the chassis or model. - * @param formationRating force equipment rating. - * @param ratingLevels number of equipment rating levels used by the faction. - * @param year game year - * @return adjusted availability rating. + * @param ar The AvailabilityRecord for the chassis or model. + * @param rating The force equipment rating. + * @param ratingLevels The number of equipment rating levels used by the faction. + * @param year The game year + * @return The adjusted availability rating. */ - public int calcAvailability(AvailabilityRating initialAv, int formationRating, int ratingLevels, int year) { - int avRating = initialAv.adjustForRating(formationRating, ratingLevels); + public int calcAvailability(AvailabilityRating ar, int rating, int ratingLevels, int year) { + int retVal = ar.adjustForRating(rating, ratingLevels); - if (year < introYear - 2) { - return 0; - } else if (year <= introYear) { - avRating -= 2; - } else if (year <= introYear + 1) { - avRating -= 1; + if (introYear == year) { + retVal -= 2; } - - return Math.max(avRating, 0); + if (introYear == year + 1) { + retVal -= 1; + } + return Math.max(retVal, 0); } - - public String getChassis() { return chassis; } diff --git a/megamek/src/megamek/client/ratgenerator/AvailabilityRating.java b/megamek/src/megamek/client/ratgenerator/AvailabilityRating.java index 3ad1fa064d..5a7a76a26d 100644 --- a/megamek/src/megamek/client/ratgenerator/AvailabilityRating.java +++ b/megamek/src/megamek/client/ratgenerator/AvailabilityRating.java @@ -107,26 +107,13 @@ public int getAvailability() { return availability; } - /** - * Return the availability taking into account +/- modifiers and a supplied rating. For example, - * an availability of 5+ will return 5 for an A-rating, 4 for a B rating, and so on; an - * availability of 5- will return 5 for an F-rating, 4 for a D-rating, and so on. - * @param rating numerical equivalent of rating value, from 0 to numLevels - 1 - * @param numLevels how many ratings are in this system - * @return availability rating, modified for the provided rating; may return values - * less than zero - */ - public int adjustForRating (int rating, int numLevels) { - if (rating < 0 || - ratingAdjustment == 0 || - rating > numLevels - 1) { + public int adjustForRating(int rating, int numLevels) { + if (rating < 0 || ratingAdjustment == 0) { return availability; } else if (ratingAdjustment < 0) { - // '-' modifier provides a 0 modifier at the lowest rating return availability - rating; } else { - // '+' modifier provides a 0 modifier at the highest rating - return availability - ((numLevels - 1) - rating); + return availability - (numLevels - rating); } } diff --git a/megamek/src/megamek/client/ratgenerator/ChassisRecord.java b/megamek/src/megamek/client/ratgenerator/ChassisRecord.java index 06840a7abb..66fdcfa45a 100644 --- a/megamek/src/megamek/client/ratgenerator/ChassisRecord.java +++ b/megamek/src/megamek/client/ratgenerator/ChassisRecord.java @@ -13,45 +13,46 @@ */ package megamek.client.ratgenerator; -import megamek.common.EntityMovementMode; -import megamek.common.EntityWeightClass; import org.apache.logging.log4j.LogManager; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; /** * The ChassisRecord tracks all available variants and determines how much total weight * is to be distributed among the various models. - * + * * @author Neoancient */ public class ChassisRecord extends AbstractUnitRecord { protected HashSet models; - + public ChassisRecord(String chassis) { super(chassis); models = new HashSet<>(); } - + public void addModel(ModelRecord model) { models.add(model); if (introYear == 0 || model.getIntroYear() < getIntroYear()) { introYear = model.getIntroYear(); } } - + public HashSet getModels() { return models; } - - public List getSortedModels() { + + public List getSortedModels() { List sortedModels = new ArrayList<>(models); sortedModels.sort(Comparator.comparing(ModelRecord::getModel)); return sortedModels; - + } - + public int totalModelWeight(int era, String fKey) { FactionRecord fRec = RATGenerator.getInstance().getFaction(fKey); if (fRec == null) { @@ -60,21 +61,11 @@ public int totalModelWeight(int era, String fKey) { } return totalModelWeight(era, fRec); } - - /** - * Calculate the total 'bucket weight' of all models for this chassis, first converting - * availability numbers to actual weight values (typically 2 ^ (AV / 2.0) ). - * Models which are introduced close to the era year may be included, even when the model's - * introduction date is later. - * @param era Year designator for the era to check e.g. 2765, 3058, 3067 - * @param fRec RAT building data for the desired faction - * @return sum of all converted weights - */ - + public int totalModelWeight(int era, FactionRecord fRec) { int retVal = 0; RATGenerator rg = RATGenerator.getInstance(); - + for (ModelRecord mr : models) { AvailabilityRating ar = rg.findModelAvailabilityRecord(era, mr.getKey(), fRec); @@ -82,91 +73,7 @@ public int totalModelWeight(int era, FactionRecord fRec) { retVal += AvailabilityRating.calcWeight(ar.getAvailability()); } } - + return retVal; } - - - /** - * Calculate the total 'bucket weight' of models for this chassis, first converting - * availability numbers to actual weight values (typically 2 ^ (AV / 2.0) ). - * This overload allows a total weight to reflect various filter requirements, with models - * that don't meet filter requirements excluded from the total. - * - * @param era Year designator for the era to check e.g. 2765, 3058, 3067 - * @param factionEraData RAT building data for the desired faction - * @param rating Formation rating - * @param year Specific year to check - * @param weightFilter {@link EntityWeightClass} constants with valid weight classes, or - * empty set to accept all - * @param networkFilter Mask for checking various C3 systems - * @param movementFilter Model must use at least one of these movement types - * @param roleStrictness - * @param rolesExcludeFilter Model may not have any of these roles - * @param roles Roles to select for - * @return int with total value of weight of all units which meet the filter - * requirements - */ - public int totalFilteredModelWeight (int era, - FactionRecord factionEraData, - int rating, - int ratingCounts, - int year, - Collection weightFilter, - int networkFilter, - Collection movementFilter, - int roleStrictness, - Collection roles, - Collection rolesExcludeFilter) { - double totalWeight = 0; - RATGenerator generator = RATGenerator.getInstance(); - - for (ModelRecord curModel : models) { - - // Models introduced more than 2 years from the current date are ignored. Those within - // two years are considered field testing/prototypes. - if (year < curModel.getIntroYear() - 2) { - continue; - } - - // Weight class - if (!weightFilter.isEmpty() && !weightFilter.contains(curModel.getWeightClass())) { - continue; - } - - // Movement types - if (!movementFilter.isEmpty() && !movementFilter.contains(curModel.getMovementMode())) { - continue; - } - - // Invalid roles - if (!rolesExcludeFilter.isEmpty() && curModel.getRoles().stream().anyMatch(rolesExcludeFilter::contains)) { - continue; - } - - // C3 systems - if ((networkFilter & curModel.getNetworkMask()) != networkFilter) { - continue; - } - - // If the model is considered available, convert the value to a weight and add it - // to the total - AvailabilityRating modelAvRating = generator.findModelAvailabilityRecord(era, - curModel.getKey(), factionEraData); - if (modelAvRating != null) { - - Double adjustedAvRating = (double) curModel.calcAvailability(modelAvRating, - rating, ratingCounts, year); - - adjustedAvRating = MissionRole.adjustAvailabilityByRole(adjustedAvRating, roles, curModel, year, roleStrictness); - if (adjustedAvRating != null && adjustedAvRating > 0) { - totalWeight += AvailabilityRating.calcWeight(adjustedAvRating); - } - } - - } - - return (int) Math.floor(totalWeight); - } - } diff --git a/megamek/src/megamek/client/ratgenerator/ForceDescriptor.java b/megamek/src/megamek/client/ratgenerator/ForceDescriptor.java index cd022949f7..b89c431527 100644 --- a/megamek/src/megamek/client/ratgenerator/ForceDescriptor.java +++ b/megamek/src/megamek/client/ratgenerator/ForceDescriptor.java @@ -324,7 +324,7 @@ private List generateFormation (List subs, int net for (ForceDescriptor sub : subs) { paramCount.merge(new UnitTable.Parameters(sub.getFactionRec(), sub.getUnitType(), sub.getYear(), sub.ratGeneratorRating(), null, networkMask, - sub.getMovementModes(), sub.getRoles(), new ArrayList<>(), 0, sub.getFactionRec()), 1, Integer::sum); + sub.getMovementModes(), sub.getRoles(), 0, sub.getFactionRec()), 1, Integer::sum); } List params = new ArrayList<>(); diff --git a/megamek/src/megamek/client/ratgenerator/RATGenerator.java b/megamek/src/megamek/client/ratgenerator/RATGenerator.java index 45a87d7c31..6558cbd784 100644 --- a/megamek/src/megamek/client/ratgenerator/RATGenerator.java +++ b/megamek/src/megamek/client/ratgenerator/RATGenerator.java @@ -387,96 +387,38 @@ private AvailabilityRating mergeFactionAvailability(String faction, List yearLate) { - throw new IllegalArgumentException(String.format("Interpolation requires correctly ordered early (%d) and late (%d) years.", yearEarly, yearLate)); - } - - if ((inputEarly == null && inputLate == null)) { + private Double interpolate(Number av1, Number av2, int year1, int year2, int now) { + if (av1 == null && av2 == null) { return null; } - - // No point interpolating if the years or values are the same value - if (yearEarly == yearLate) { - return inputEarly == null ? 0.0 : inputEarly.doubleValue(); + if (av1 == null) { + av1 = 0.0; } - - double valueEarly = inputEarly == null ? 0.0 : inputEarly.doubleValue(); - double valueLate = inputLate == null ? 0.0 : inputLate.doubleValue(); - - if (valueEarly == valueLate) { - return valueEarly; + if (av2 == null) { + av2 = 0.0; } - - return valueEarly + - (valueLate - valueEarly) * (testYear - yearEarly) / (yearLate - yearEarly); - } - - - /** - * Convenience overload method provided for generating a table with no excluded roles - */ - public List generateTable (FactionRecord fRec, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - int roleStrictness, - FactionRecord user) { - return generateTable(fRec, unitType, year, rating, weightClasses, networkMask, - movementModes, roles, new ArrayList<>(), roleStrictness, user); + if (year1 == year2) { + return av1.doubleValue(); + } + return av1.doubleValue() + + (av2.doubleValue() - av1.doubleValue()) * (now - year1) / (year2 - year1); } - /** - * Generate a weighted random selection table of full units (chassis + model) for random - * selection, suing the provided settings. - * VTOLs may be included with ground vehicles by selecting the TANK unit type and VTOL - * movement type. - * - * @param fRec - * @param unitType - * @param year - * @param rating - * @param weightClasses - * @param networkMask - * @param movementModes - * @param roles - * @param rolesExcluded - * @param roleStrictness - * @param user - * @return - */ - public List generateTable (FactionRecord fRec, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - Collection rolesExcluded, - int roleStrictness, - FactionRecord user) { + public List generateTable(FactionRecord fRec, int unitType, int year, + String rating, Collection weightClasses, int networkMask, + Collection movementModes, + Collection roles, int roleStrictness, + FactionRecord user) { HashMap unitWeights = new HashMap<>(); HashMap salvageWeights = new HashMap<>(); @@ -518,7 +460,6 @@ public List generateTable (FactionRecord fRec, ratingLevel = factionRatings.indexOf(rating); } - // Iterate through each chassis for (String chassisKey : chassisIndex.get(early).keySet()) { ChassisRecord cRec = chassis.get(chassisKey); if (cRec == null) { @@ -531,106 +472,44 @@ public List generateTable (FactionRecord fRec, cRec.setUnitType(UnitType.AEROSPACEFIGHTER); } - // Skip if the unit type does not match if (cRec.getUnitType() != unitType && - !(unitType == UnitType.TANK && - cRec.getUnitType() == UnitType.VTOL && - movementModes.contains(EntityMovementMode.VTOL))) { + !(unitType == UnitType.TANK + && cRec.getUnitType() == UnitType.VTOL + && movementModes.contains(EntityMovementMode.VTOL))) { continue; } - // Get the availability rating of the current chassis and modify for rating and pre/ - // early production status - AvailabilityRating ar = findChassisAvailabilityRecord(early, chassisKey, fRec, year); + AvailabilityRating ar = findChassisAvailabilityRecord(early, + chassisKey, fRec, year); if (ar == null) { continue; } - double cAv = cRec.calcAvailability(ar, ratingLevel, numRatingLevels, year); - - // If the current year is somewhere between era data sets, the availability may need - // interpolation - if (early.intValue() != late.intValue()) { - Double interpolated = interpolate( - early < cRec.introYear - 2 ? 0 : cRec.calcAvailability(ar, ratingLevel, numRatingLevels, early), - cRec.calcAvailability(ar, ratingLevel, numRatingLevels, late), - early, - late, - year); - if (interpolated != null) { - cAv = interpolated; - } - } - + double cAv = cRec.calcAvailability(ar, ratingLevel, numRatingLevels, early); + cAv = interpolate(cAv, + cRec.calcAvailability(ar, ratingLevel, numRatingLevels, late), + Math.max(early, cRec.getIntroYear()), late, year); if (cAv > 0) { - - // Calculate the total random selection weight of all models, filtering out those - // which are not applicable. If the total is 0.0 (or close to it) there are no - // suitable models for this chassis. - double totalModelWeight = cRec.totalFilteredModelWeight(early, - cRec.isOmni() ? user : fRec, - ratingLevel, - numRatingLevels, - year, - weightClasses, - networkMask, - movementModes, - roleStrictness, - roles, - rolesExcluded); - - if (totalModelWeight <= 0.01) { - continue; - } - - // Get the random selection weight for each specific model + double totalModelWeight = cRec.totalModelWeight(early, + cRec.isOmni() ? user : fRec); for (ModelRecord mRec : cRec.getModels()) { - - // Skip models that are at least two years from official introduction, and those - // that do not match the required weight classes - if (year < (mRec.getIntroYear() - 2) || - (!weightClasses.isEmpty() && !weightClasses.contains(mRec.getWeightClass()))) { + if (mRec.getIntroYear() > year + || (!weightClasses.isEmpty() + && !weightClasses.contains(mRec.getWeightClass())) + || (networkMask & mRec.getNetworkMask()) != networkMask) { continue; } - // Skip models that do not use one of the requested movement types if (!movementModes.isEmpty() && !movementModes.contains(mRec.getMovementMode())) { continue; } - - // Skip any models that have roles which are being excluded - if (rolesExcluded != null && mRec.getRoles().stream().anyMatch(rolesExcluded::contains)) { - continue; - } - - // Skip any models that do not have the requested C3 system - if ((networkMask & mRec.getNetworkMask()) != networkMask) { - continue; - } - - // Get the availability rating data for this model ar = findModelAvailabilityRecord(early, mRec.getKey(), fRec); if ((ar == null) || (ar.getAvailability() == 0)) { continue; } - - // Get the availability value of the model, including modifiers for rating - // (+/- indicator) and pre/early production - double mAv = mRec.calcAvailability(ar, ratingLevel, numRatingLevels, year); - - // If the current year is between era data sets, the availability may need - // interpolation - if (early.intValue() != late.intValue()) { - Double interpolated = interpolate( - early < mRec.getIntroYear() - 2 ? 0 : mRec.calcAvailability(ar, ratingLevel, numRatingLevels, early), - mRec.calcAvailability(ar, ratingLevel, numRatingLevels, late), - early, - late, - year); - if (interpolated != null) { - mAv = interpolated; - } - } - + double mAv = mRec.calcAvailability(ar, ratingLevel, numRatingLevels, early); + mAv = interpolate(mAv, + mRec.calcAvailability(ar, ratingLevel, numRatingLevels, late), + Math.max(early, mRec.getIntroYear()), late, year); Double adjMAv = MissionRole.adjustAvailabilityByRole(mAv, roles, mRec, year, roleStrictness); if (adjMAv != null) { double mWt = AvailabilityRating.calcWeight(adjMAv) / totalModelWeight diff --git a/megamek/src/megamek/client/ratgenerator/UnitTable.java b/megamek/src/megamek/client/ratgenerator/UnitTable.java index 2b85075b13..7696d5dd45 100644 --- a/megamek/src/megamek/client/ratgenerator/UnitTable.java +++ b/megamek/src/megamek/client/ratgenerator/UnitTable.java @@ -57,91 +57,41 @@ protected boolean removeEldestEntry(Map.Entry entry) { /** * Checks the cache for a previously generated table meeting the criteria. If none is * found, generates it and adds it to the cache. - * This method is provided as a convenience for when there are no excluded roles. * - * @param faction The faction the table filters for - * @param unitType {@link megamek.common.UnitType} constant with the type of unit - * @param year the game year - * @param rating the unit's equipment rating; if null, the table is not adjusted for unit rating. - * @param weightClasses a collection of {@link megamek.common.EntityWeightClass} constants to include in the table; - * if null or empty all weight classes are included - * @param networkMask One of the {@link MOdelRecord} NETWORK constants, for filtering various C3 systems - * @param movementModes the movement modes covered by the table, null/empty for all modes - * @param roles {@link MissionRole} types the units should qualify for, null/empty for no role - * filtering - * @param roleStrictness how strongly to apply roles, zero for none/minimal with higher being more - * restrictive; typically no higher than 5 - * @param deployingFaction when using the salvage/isorla mechanism, any omni unit will select - * the configuration based on the faction actually deploying - * @return table containing units which fit all parameters and their relative weights + * @param faction - The faction for which to generate a table + * @param unitType - a UnitType constant + * @param year - the game year + * @param rating - the unit's equipment rating; if null, the table is not adjusted for unit rating. + * @param weightClasses - a collection of EntityWeightClass constants to include in the table; + * if null or empty all weight classes are included + * @param networkMask - a ModelRecord.NETWORK_* constant + * @param movementModes - the movement modes allowed to appear in the table; if null or empty, no filtering + * is applied. + * @param roles - the roles for which to adjust the availability + * @param roleStrictness - how rigidly to apply the role adjustments; normal range is <= 4 + * @param deployingFaction - when using the salvage/isorla mechanism, any omni unit will select + * the configuration based on the faction actually deploying + * @return - a table containing the available units and their relative weights */ - public static UnitTable findTable (FactionRecord faction, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - int roleStrictness, - FactionRecord deployingFaction) { + public static UnitTable findTable(FactionRecord faction, int unitType, int year, + String rating, Collection weightClasses, int networkMask, + Collection movementModes, + Collection roles, int roleStrictness, FactionRecord deployingFaction) { Objects.requireNonNull(faction); Parameters params = new Parameters(faction, unitType, year, rating, weightClasses, networkMask, - movementModes, roles, new ArrayList<>(), roleStrictness, deployingFaction); + movementModes, roles, roleStrictness, deployingFaction); return findTable(params); } /** - * Overloaded method, with additional argument for excluded roles - * @param faction The faction the table filters for - * @param unitType {@link megamek.common.UnitType} constant with the type of unit - * @param year the game year - * @param rating the unit's equipment rating; if null, the table is not adjusted for unit rating. - * @param weightClasses collection of {@link megamek.common.EntityWeightClass} constants to include in the table; - * if null or empty all weight classes are included - * @param networkMask One of the {@link ModelRecord} NETWORK constants, for filtering various C3 systems - * @param movementModes the movement modes covered by the table, null/empty for all modes - * @param roles {@link MissionRole} types the units should qualify for, null/empty for no role - * filtering - * @param rolesExcluded {@link MissionRole} types the units should not contain, null empty to - * allow all roles - * @param roleStrictness how strongly to apply roles, zero for none/minimal with higher being more - * restrictive; typically no higher than 5 - * @param deployingFaction when using the salvage/isorla mechanism, any omni unit will select - * the configuration based on the faction actually deploying - * @return table containing units which fit all parameters and their relative weights - */ - public static UnitTable findTable (FactionRecord faction, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - Collection rolesExcluded, - int roleStrictness, - FactionRecord deployingFaction) { - Objects.requireNonNull(faction); - Parameters params = new Parameters(faction, unitType, year, rating, weightClasses, networkMask, - movementModes, roles, rolesExcluded, roleStrictness, deployingFaction); - return findTable(params); - } - - /** - * Provided as a convenience to call findTable while using the faction parameter as the - * deploying faction + * deployingFaction not specified, uses main faction. + * */ - public static UnitTable findTable (FactionRecord faction, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - int roleStrictness) { + public static UnitTable findTable(FactionRecord faction, int unitType, int year, + String rating, Collection weightClasses, int networkMask, + Collection movementModes, + Collection roles, int roleStrictness) { return findTable(faction, unitType, year, rating, weightClasses, networkMask, movementModes, roles, roleStrictness, faction); } @@ -153,7 +103,7 @@ public static UnitTable findTable (FactionRecord faction, * @param params - the parameters to use in generating the table. * @return a generated table matching the parameters */ - public static synchronized UnitTable findTable (Parameters params) { + public static synchronized UnitTable findTable(Parameters params) { Objects.requireNonNull(params); UnitTable retVal = cache.get(params); if (retVal == null) { @@ -177,31 +127,22 @@ public static synchronized UnitTable findTable (Parameters params) { int salvagePct; /** - * Initializes table based on restrictions provided by a Parameters object + * Initializes table based on values provided by key * - * @param key a {@link Parameters} structure providing the parameters for generating the table + * @param key - a structure providing the parameters for generating the table */ - protected UnitTable (Parameters key) { + protected UnitTable(Parameters key) { this.key = key; /* * Generate the RAT, then go through it to build the NavigableMaps that * will be used for random selection. */ if (key.getFaction() != null ) { - - // Simple check if the faction is active now if (key.getFaction().isActiveInYear(key.getYear())) { - List table = RATGenerator.getInstance().generateTable(key.getFaction(), - key.getUnitType(), - key.getYear(), - key.getRating(), - key.getWeightClasses(), - key.getNetworkMask(), - key.getMovementModes(), - key.getRoles(), - key.getRoleStrictness(), - key.getDeployingFaction()); + key.getUnitType(), key.getYear(), key.getRating(), key.getWeightClasses(), + key.getNetworkMask(), key.getMovementModes(), + key.getRoles(), key.getRoleStrictness(), key.getDeployingFaction()); Collections.sort(table); table.forEach(te -> { @@ -490,21 +431,13 @@ public static final class Parameters implements Cloneable { private int networkMask; private Collection movementModes; private Collection roles; - private Collection rolesExcluded; private int roleStrictness; private FactionRecord deployingFaction; - public Parameters (FactionRecord faction, - int unitType, - int year, - String rating, - Collection weightClasses, - int networkMask, - Collection movementModes, - Collection roles, - Collection rolesExcluded, - int roleStrictness, - FactionRecord deployingFaction) { + public Parameters(FactionRecord faction, int unitType, int year, + String rating, Collection weightClasses, int networkMask, + Collection movementModes, + Collection roles, int roleStrictness, FactionRecord deployingFaction) { this.faction = faction; this.unitType = unitType; this.year = year; @@ -512,16 +445,10 @@ public Parameters (FactionRecord faction, this.weightClasses = weightClasses == null? new ArrayList<>() : new ArrayList<>(weightClasses); this.networkMask = networkMask; - - this.movementModes = ((movementModes == null) || movementModes.isEmpty()) ? - EnumSet.noneOf(EntityMovementMode.class) : EnumSet.copyOf(movementModes); - - this.roles = ((roles == null) || roles.isEmpty()) ? - EnumSet.noneOf(MissionRole.class) : EnumSet.copyOf(roles); - - this.rolesExcluded = ((rolesExcluded == null) || rolesExcluded.isEmpty()) ? - EnumSet.noneOf((MissionRole.class)) : EnumSet.copyOf(rolesExcluded); - + this.movementModes = ((movementModes == null) || movementModes.isEmpty()) + ? EnumSet.noneOf(EntityMovementMode.class) : EnumSet.copyOf(movementModes); + this.roles = ((roles == null) || roles.isEmpty()) + ? EnumSet.noneOf(MissionRole.class) : EnumSet.copyOf(roles); this.roleStrictness = roleStrictness; this.deployingFaction = (deployingFaction == null) ? faction : deployingFaction; } @@ -543,7 +470,6 @@ public int hashCode() { + ((rating == null) ? 0 : rating.hashCode()); result = prime * result + roleStrictness; result = prime * result + ((roles == null) ? 0 : roles.hashCode()); - result = prime * result + ((rolesExcluded == null) ? 0 : rolesExcluded.hashCode()); result = prime * result + unitType; result = prime * result + ((weightClasses == null) ? 0 : weightClasses.hashCode()); @@ -604,13 +530,6 @@ public boolean equals(Object obj) { } else if (!roles.equals(other.roles)) { return false; } - if (rolesExcluded == null) { - if (other.rolesExcluded != null) { - return false; - } - } else if (!rolesExcluded.equals(other.rolesExcluded)) { - return false; - } if (unitType != other.unitType) { return false; } @@ -691,14 +610,6 @@ public void setRoles(Collection roles) { this.roles = roles; } - public Collection getRolesExcluded() { - return rolesExcluded; - } - - public void setRolesExcluded(Collection rolesExcluded) { - this.rolesExcluded = rolesExcluded; - } - public int getRoleStrictness() { return roleStrictness; } @@ -718,7 +629,7 @@ public void setDeployingFaction(FactionRecord deployingFaction) { public Parameters copy() { return new Parameters(faction, unitType, year, rating, weightClasses, networkMask, movementModes, - roles, rolesExcluded, roleStrictness, deployingFaction); + roles, roleStrictness, deployingFaction); } } diff --git a/megamek/src/megamek/client/ui/swing/ForceGenerationOptionsPanel.java b/megamek/src/megamek/client/ui/swing/ForceGenerationOptionsPanel.java index 4001ab8f4a..7d923cf311 100644 --- a/megamek/src/megamek/client/ui/swing/ForceGenerationOptionsPanel.java +++ b/megamek/src/megamek/client/ui/swing/ForceGenerationOptionsPanel.java @@ -1202,7 +1202,6 @@ private void showAnalysis() { .boxed().collect(Collectors.toList()), ModelRecord.NETWORK_NONE, EnumSet.noneOf(EntityMovementMode.class), ft.getMissionRoles(), - new ArrayList<>(), 2, getFaction()); params.add(p); int numUnits = getNumUnits(); diff --git a/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java b/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java index dacdbbd972..004d183a99 100644 --- a/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java +++ b/megamek/src/megamek/client/ui/swing/RandomArmyDialog.java @@ -770,9 +770,7 @@ public void actionPerformed(ActionEvent ev) { m_pFormationOptions.getRating(), null, ModelRecord.NETWORK_NONE, EnumSet.noneOf(EntityMovementMode.class), - EnumSet.noneOf(MissionRole.class), - new ArrayList<>(), - 0, fRec)); + EnumSet.noneOf(MissionRole.class), 0, fRec)); List numUnits = new ArrayList<>(); numUnits.add(m_pFormationOptions.getNumUnits()); @@ -783,9 +781,7 @@ public void actionPerformed(ActionEvent ev) { m_pFormationOptions.getYear(), m_pFormationOptions.getRating(), null, ModelRecord.NETWORK_NONE, EnumSet.noneOf(EntityMovementMode.class), - EnumSet.noneOf(MissionRole.class), - new ArrayList<>(), - 0, fRec)); + EnumSet.noneOf(MissionRole.class), 0, fRec)); numUnits.add(m_pFormationOptions.getIntegerOption("numOtherUnits")); } else if (m_pFormationOptions.getBooleanOption("mechBA")) { // Make sure at least a number units equals to the number of BA points/squads are omni @@ -811,8 +807,7 @@ public void actionPerformed(ActionEvent ev) { m_pFormationOptions.getYear(), m_pFormationOptions.getRating(), null, ModelRecord.NETWORK_NONE, EnumSet.noneOf(EntityMovementMode.class), - EnumSet.of(MissionRole.MECHANIZED_BA), - new ArrayList<>(),0, fRec); + EnumSet.of(MissionRole.MECHANIZED_BA), 0, fRec); List ba = ft.generateFormation(p, m_pFormationOptions.getIntegerOption("numOtherUnits"), ModelRecord.NETWORK_NONE, true);