From e117cffed54b14affecc28fd8dc23f44c076237f Mon Sep 17 00:00:00 2001 From: sleet01 Date: Sat, 31 Aug 2024 12:56:31 -0700 Subject: [PATCH] MHQ side of fix for MHQ 4755: NPE when opfor has no faction code --- MekHQ/src/mekhq/gui/BriefingTab.java | 33 +++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/MekHQ/src/mekhq/gui/BriefingTab.java b/MekHQ/src/mekhq/gui/BriefingTab.java index 14594f55d7..2474b5346f 100644 --- a/MekHQ/src/mekhq/gui/BriefingTab.java +++ b/MekHQ/src/mekhq/gui/BriefingTab.java @@ -927,8 +927,10 @@ private void autoconfigureBotMunitions(AtBScenario scenario, List chosen) Game cGame = getCampaign().getGame(); boolean groundMap = scenario.getBoardType() == AtBScenario.T_GROUND; boolean spaceMap = scenario.getBoardType() == AtBScenario.T_SPACE; + ArrayList alliedEntities = new ArrayList<>(); ArrayList allyFactionCodes = new ArrayList<>(); + ArrayList opforFactionCodes = new ArrayList<>(); String opforFactionCode = "IS"; String allyFaction = "IS"; int opforQuality = RATING_5; @@ -938,12 +940,15 @@ private void autoconfigureBotMunitions(AtBScenario scenario, List chosen) // This had better be an AtB contract... final Mission mission = comboMission.getSelectedItem(); if (mission instanceof AtBContract atbc) { - opforFactionCode = atbc.getEnemyCode(); + opforFactionCode = (atbc.getEnemyCode().isBlank()) ? opforFactionCode : atbc.getEnemyCode(); opforQuality = atbc.getEnemyQuality(); allyFactionCodes.add(atbc.getEmployerCode()); allyFaction = atbc.getEmployerName(allowedYear); + } else { + allyFactionCodes.add(allyFaction); } Faction opforFaction = Factions.getInstance().getFaction(opforFactionCode); + opforFactionCodes.add(opforFactionCode); boolean isPirate = opforFaction.isRebelOrPirate(); // Collect player units to use as configuration fodder @@ -958,6 +963,7 @@ private void autoconfigureBotMunitions(AtBScenario scenario, List chosen) if (botForce.getName().contains(allyFaction)) { // Stuff with our employer's name should be with us. playerEntities.addAll(botForce.getFixedEntityList()); + alliedEntities.addAll(botForce.getFixedEntityList()); } else { int botTeam = botForce.getTeam(); if (!botTeamMappings.containsKey(botTeam)) { @@ -967,10 +973,11 @@ private void autoconfigureBotMunitions(AtBScenario scenario, List chosen) } } + // Configure generated units with appropriate munitions (for BV calcs) + TeamLoadoutGenerator tlg = new TeamLoadoutGenerator(cGame); + // Reconfigure each group separately so they only consider their own capabilities for (ArrayList entityList: botTeamMappings.values()) { - // Configure generated units with appropriate munitions (for BV calcs) - TeamLoadoutGenerator tlg = new TeamLoadoutGenerator(cGame); // bin fill ratio will be adjusted by the loadout generator based on piracy and quality ReconfigurationParameters rp = TeamLoadoutGenerator.generateParameters( cGame, @@ -988,6 +995,26 @@ private void autoconfigureBotMunitions(AtBScenario scenario, List chosen) MunitionTree mt = TeamLoadoutGenerator.generateMunitionTree(rp, entityList, ""); tlg.reconfigureEntities(entityList, opforFactionCode, mt, rp); } + + // Finally, reconfigure all allies (but not player entities) as one organization + ArrayList allEnemyEntities = new ArrayList<>(); + botTeamMappings.values().stream().forEach(x -> allEnemyEntities.addAll(x)); + ReconfigurationParameters rp = TeamLoadoutGenerator.generateParameters( + cGame, + cGame.getOptions(), + alliedEntities, + allyFactionCodes.get(0), + allEnemyEntities, + opforFactionCodes, + opforQuality, + (getCampaign().getFaction().isPirate()) ? TeamLoadoutGenerator.UNSET_FILL_RATIO : 1.0f + ); + rp.isPirate = getCampaign().getFaction().isPirate(); + rp.groundMap = groundMap; + rp.spaceEnvironment = spaceMap; + MunitionTree mt = TeamLoadoutGenerator.generateMunitionTree(rp, alliedEntities, ""); + tlg.reconfigureEntities(alliedEntities, allyFactionCodes.get(0), mt, rp); + } private void joinScenario() {