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

MM portion of fix for MHQ 3803: WOB.pm/.PM mismatch and missing parent faction check #5306

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion megamek/data/forcegenerator/factions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<faction key='CIR' name='Circinus Federation' minor='false' clan='false' periphery='true'>
<years>2785-3081</years>
<ratingLevels>F,D,C,B,A</ratingLevels>
<parentFaction>Periphery.MW,WOB.pm</parentFaction>
<parentFaction>Periphery.MW,WOB.PM</parentFaction>
</faction>
<faction key='CLAN' name='Clan - General' minor='false' clan='true' periphery='false'>
<years>2807-</years>
Expand Down
45 changes: 25 additions & 20 deletions megamek/src/megamek/client/ratgenerator/UnitTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import megamek.common.EntityMovementMode;
import megamek.common.MechSummary;
import megamek.common.annotations.Nullable;
import org.apache.logging.log4j.LogManager;

/**
* Manages random assignment table generated by RATGenerator.
Expand Down Expand Up @@ -81,7 +82,7 @@ public static UnitTable findTable(FactionRecord faction, int unitType, int year,
movementModes, roles, roleStrictness, deployingFaction);
return findTable(params);
}

/**
* deployingFaction not specified, uses main faction.
*
Expand All @@ -98,7 +99,7 @@ public static UnitTable findTable(FactionRecord faction, int unitType, int year,
/**
* Checks cache for a unit table with the given parameters. If none is found, generates
* one and adds to the cache using a copy of the Parameters object as a key.
*
*
* @param params - the parameters to use in generating the table.
* @return a generated table matching the parameters
*/
Expand Down Expand Up @@ -136,25 +137,29 @@ protected UnitTable(Parameters key) {
* Generate the RAT, then go through it to build the NavigableMaps that
* will be used for random selection.
*/
if (key.getFaction().isActiveInYear(key.getYear())) {
List<TableEntry> table = RATGenerator.getInstance().generateTable(key.getFaction(),
key.getUnitType(), key.getYear(), key.getRating(), key.getWeightClasses(),
key.getNetworkMask(), key.getMovementModes(),
key.getRoles(), key.getRoleStrictness(), key.getDeployingFaction());
Collections.sort(table);

table.forEach(te -> {
if (te.isUnit()) {
unitTotal += te.weight;
unitTable.add(te);
} else {
salvageTotal += te.weight;
salvageTable.add(te);
if (key.getFaction() != null ) {
if (key.getFaction().isActiveInYear(key.getYear())) {
List<TableEntry> table = RATGenerator.getInstance().generateTable(key.getFaction(),
key.getUnitType(), key.getYear(), key.getRating(), key.getWeightClasses(),
key.getNetworkMask(), key.getMovementModes(),
key.getRoles(), key.getRoleStrictness(), key.getDeployingFaction());
Collections.sort(table);

table.forEach(te -> {
if (te.isUnit()) {
unitTotal += te.weight;
unitTable.add(te);
} else {
salvageTotal += te.weight;
salvageTable.add(te);
}
});
if (salvageTotal + unitTotal > 0) {
salvagePct = salvageTotal * 100 / (salvageTotal + unitTotal);
}
});
if (salvageTotal + unitTotal > 0) {
salvagePct = salvageTotal * 100 / (salvageTotal + unitTotal);
}
} else {
LogManager.getLogger().warn("key.getFaction() returned null; likely faction lookup error");
}
}

Expand Down Expand Up @@ -620,6 +625,6 @@ public Parameters copy() {
rating, weightClasses, networkMask, movementModes,
roles, roleStrictness, deployingFaction);
}

}
}
Loading