From 2556b1d15f863b186f5bd2d4f5a15995c52fcee1 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 18 Nov 2024 12:49:34 -0600 Subject: [PATCH 1/6] Ensure transportation rating only increases from zero Added checks to only increase the transportation rating if its current value is zero and the computed rating is greater than zero. This prevents unintended cumulative increases and maintains accurate ratings. --- .../TransportationRating.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java index ee1e2683c1..d761b57ef3 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java @@ -18,16 +18,16 @@ */ package mekhq.campaign.rating.CamOpsReputation; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - import megamek.common.*; import megamek.logging.MMLogger; import mekhq.campaign.Campaign; import mekhq.campaign.unit.Unit; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + public class TransportationRating { private static final MMLogger logger = MMLogger.create(TransportationRating.class); @@ -72,7 +72,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("asf", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // Meks capacity = transportationCapacities.get("mekBays"); @@ -80,7 +82,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("mek", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // Super Heavy Vehicles capacity = transportationCapacities.get("superHeavyVehicleBays"); @@ -88,7 +92,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("superHeavyVehicle", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } spareCapacity = Math.max(0, capacity - requirements); @@ -98,7 +104,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("heavyVehicle", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // as this spare capacity can also be used by light vehicles, // we need to track the remaining spare capacity @@ -111,7 +119,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("lightVehicle", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // ProtoMeks capacity = transportationCapacities.get("protoMekBays"); @@ -119,7 +129,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("protoMek", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // Battle Armor capacity = transportationCapacities.get("battleArmorBays"); @@ -127,7 +139,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("battleArmor", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // Infantry capacity = transportationCapacities.get("infantryBays"); @@ -135,7 +149,9 @@ public static List> calculateTransportationRating(Campaign rating = calculateRating(capacity, requirements); transportationValues.put("infantry", rating); - transportationRating += rating; + if (transportationRating == 0 && rating > 0) { + transportationRating += rating; + } // Support Personnel capacity = transportationCapacities.get("passengerCapacity"); From 59eb68039902cde685cd0d30938c6dee0269cdb0 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 18 Nov 2024 13:37:32 -0600 Subject: [PATCH 2/6] Improve skill value calculation in CommandRating Revised the getSkillValue method to include skill bonus in the calculation. Added an intermediate variable to accumulate the skill level and bonus before returning the final skill value. This ensures a more accurate representation of the person's skill. --- .../rating/CamOpsReputation/CommandRating.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/CommandRating.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/CommandRating.java index d9f22a4ee6..ef196440d3 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/CommandRating.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/CommandRating.java @@ -18,10 +18,6 @@ */ package mekhq.campaign.rating.CamOpsReputation; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - import megamek.logging.MMLogger; import mekhq.campaign.Campaign; import mekhq.campaign.CampaignOptions; @@ -32,6 +28,10 @@ import mekhq.campaign.personnel.randomEvents.enums.personalities.Greed; import mekhq.campaign.personnel.randomEvents.enums.personalities.Social; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + public class CommandRating { private static final MMLogger logger = MMLogger.create(CommandRating.class); @@ -82,15 +82,20 @@ protected static Map calculateCommanderRating(Campaign campaign * @param skill the skill */ private static int getSkillValue(Person person, String skill) { + int skillValue = 0; + if (person == null) { return 0; } if (person.hasSkill(skill)) { - return person.getSkill(skill).getExperienceLevel(); + skillValue += person.getSkill(skill).getLevel(); + skillValue += person.getSkill(skill).getBonus(); } else { return 0; } + + return skillValue; } /** From 31391121cc4ffade115a3427442ef8b1e6b73f2a Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 18 Nov 2024 15:16:09 -0600 Subject: [PATCH 3/6] Refactor transportation rating system Replaced direct transportation value adjustments with capacity rating calculations. Added constants for different capacity states and a helper method to determine capacity ratings, improving code readability and maintainability. --- .../TransportationRating.java | 99 ++++++++++++------- 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java index d761b57ef3..917a4fc6a2 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java @@ -29,6 +29,11 @@ import java.util.stream.Collectors; public class TransportationRating { + final static int BELOW_CAPACITY = 0; + final static int AT_CAPACITY = 1; + final static int DOUBLE_CAPACITY = 2; + final static int USE_FALLBACK = 3; + private static final MMLogger logger = MMLogger.create(TransportationRating.class); /** @@ -57,8 +62,7 @@ public static List> calculateTransportationRating(Campaign // Add the rating adjustment to the total; We do this for each following entity int rating = calculateRating(capacity, requirements); - transportationValues.put("smallCraft", rating); - transportationRating += rating; + int capacityRating = getCapacityRating(rating, USE_FALLBACK); // Calculate spare capacity if any. // Some entity types can use spare bays not used by other entities @@ -71,30 +75,21 @@ public static List> calculateTransportationRating(Campaign requirements = Math.max(0, transportationRequirements.get("asfCount") - spareCapacity); rating = calculateRating(capacity, requirements); - transportationValues.put("asf", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // Meks capacity = transportationCapacities.get("mekBays"); requirements = transportationRequirements.get("mekCount"); rating = calculateRating(capacity, requirements); - transportationValues.put("mek", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // Super Heavy Vehicles capacity = transportationCapacities.get("superHeavyVehicleBays"); requirements = transportationRequirements.get("superHeavyVehicleCount"); rating = calculateRating(capacity, requirements); - transportationValues.put("superHeavyVehicle", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); spareCapacity = Math.max(0, capacity - requirements); @@ -103,10 +98,7 @@ public static List> calculateTransportationRating(Campaign requirements = Math.max(0, transportationRequirements.get("heavyVehicleCount") - spareCapacity); rating = calculateRating(capacity, requirements); - transportationValues.put("heavyVehicle", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // as this spare capacity can also be used by light vehicles, // we need to track the remaining spare capacity @@ -118,39 +110,43 @@ public static List> calculateTransportationRating(Campaign requirements = Math.max(0, transportationRequirements.get("lightVehicleCount") - spareCapacity); rating = calculateRating(capacity, requirements); - transportationValues.put("lightVehicle", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // ProtoMeks capacity = transportationCapacities.get("protoMekBays"); requirements = transportationRequirements.get("protoMekCount"); rating = calculateRating(capacity, requirements); - transportationValues.put("protoMek", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // Battle Armor capacity = transportationCapacities.get("battleArmorBays"); requirements = transportationRequirements.get("battleArmorCount"); rating = calculateRating(capacity, requirements); - transportationValues.put("battleArmor", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; - } + capacityRating = getCapacityRating(rating, capacityRating); // Infantry capacity = transportationCapacities.get("infantryBays"); requirements = transportationRequirements.get("infantryCount"); rating = calculateRating(capacity, requirements); - transportationValues.put("infantry", rating); - if (transportationRating == 0 && rating > 0) { - transportationRating += rating; + capacityRating = getCapacityRating(rating, capacityRating); + + switch (capacityRating) { + case BELOW_CAPACITY -> { + transportationRating -= 5; + transportationCapacities.put("capacityRating", -5); + } + case AT_CAPACITY -> { + transportationRating += 5; + transportationCapacities.put("capacityRating", 5); + } + case DOUBLE_CAPACITY -> { + transportationRating += 10; + transportationCapacities.put("capacityRating", 10); + } + default -> transportationCapacities.put("capacityRating", 0); } // Support Personnel @@ -165,6 +161,8 @@ public static List> calculateTransportationRating(Campaign transportationRating -= 3; transportationValues.put("passenger", -3); logger.debug("Below Support Personnel Transport Requirements: -3"); + } else { + transportationValues.put("passenger", 0); } // JumpShip & WarShip Presence @@ -195,6 +193,33 @@ public static List> calculateTransportationRating(Campaign return List.of(transportationCapacities, transportationRequirements, transportationValues); } + /** + * Returns capacity rating based on provided rating and capacityRating parameters. + * + * @param rating the input rating + * @param capacityRating the current capacity rating + * @return the determined capacity rating + */ + private static int getCapacityRating(int rating, int capacityRating) { + return switch (capacityRating) { + case BELOW_CAPACITY -> BELOW_CAPACITY; + case AT_CAPACITY -> { + if (rating == BELOW_CAPACITY) { + yield BELOW_CAPACITY; + } else { + yield AT_CAPACITY; + } + } + case DOUBLE_CAPACITY -> switch (rating) { + case DOUBLE_CAPACITY -> DOUBLE_CAPACITY; + case BELOW_CAPACITY -> BELOW_CAPACITY; + case AT_CAPACITY -> AT_CAPACITY; + default -> capacityRating; // USE_FALLBACK + }; + default -> USE_FALLBACK; + }; + } + /** * Calculates the transportation rating adjustment based on capacity and * requirements. @@ -208,15 +233,15 @@ protected static int calculateRating(int capacity, int requirements) { int usage = capacity - requirements; if (usage < 0) { - return -5; + return BELOW_CAPACITY; } else if (usage > requirements * 2) { - return 10; + return DOUBLE_CAPACITY; } else { - return 5; + return AT_CAPACITY; } } - return 0; + return USE_FALLBACK; } /** From 4f065b3fa3d9d4825eb2b4f74ad9a63d76bd51fe Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 18 Nov 2024 15:31:33 -0600 Subject: [PATCH 4/6] Refactored TransportationRating to simplify capacity rating logic Removed nested switch-case for DOUBLE_CAPACITY and merged it into the default case. This change reduces redundancy and clarifies the fallback logic in TransportationRating. --- .../rating/CamOpsReputation/TransportationRating.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java index 917a4fc6a2..663dd065c9 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/TransportationRating.java @@ -210,13 +210,7 @@ private static int getCapacityRating(int rating, int capacityRating) { yield AT_CAPACITY; } } - case DOUBLE_CAPACITY -> switch (rating) { - case DOUBLE_CAPACITY -> DOUBLE_CAPACITY; - case BELOW_CAPACITY -> BELOW_CAPACITY; - case AT_CAPACITY -> AT_CAPACITY; - default -> capacityRating; // USE_FALLBACK - }; - default -> USE_FALLBACK; + default -> rating; // Use Fallback, or Double Capacity }; } From b7d7e36634179b93c39d57af77757f8c1699648e Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Mon, 18 Nov 2024 16:17:55 -0600 Subject: [PATCH 5/6] Refactor getReportText method for improved readability Enhanced the `getReportText` method with cleaner HTML table formatting and consolidated string operations. Removed unused and redundant private methods to streamline the code and improve maintainability. --- .../resources/CamOpsReputation.properties | 110 ++-- .../ReputationController.java | 478 +++++++++--------- 2 files changed, 296 insertions(+), 292 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/CamOpsReputation.properties b/MekHQ/resources/mekhq/resources/CamOpsReputation.properties index 68073bf8f4..6684728987 100644 --- a/MekHQ/resources/mekhq/resources/CamOpsReputation.properties +++ b/MekHQ/resources/mekhq/resources/CamOpsReputation.properties @@ -1,57 +1,63 @@ -unitReputation.text=Unit Reputation: %d

- -averageExperienceRating.text=Average Experience Rating: %s -experienceLevel.text=
     Experience Level: %s

- -commandRating.text=Command Rating: %s -leadership.text=
     Leadership: %s -tactics.text=
     Tactics: %s -strategy.text=
     Strategy: %s -negotiation.text=
     Negotiation: %s -traits.text=
     Traits: %s Not Implemented -personality.text=
     Personality: %s - -combatRecordRating.text=Combat Record Rating: %s +refresh.text=This report refreshes every Monday. +count.text=Count +modifier.text=Modifier +required.text=Required +available.text=Available + +averageExperienceRating.text=Average Experience Rating +experienceLevel.text=Experience Level + +commandRating.text=Command Rating +leadership.text=Leadership +tactics.text=Tactics +strategy.text=Strategy +negotiation.text=Negotiation +traits.text=Traits +traitsNotImplemented.text=Not Implemented +personality.text=Personality + +combatRecordRating.text=Combat Record Rating successes.text=Successes partialSuccesses.text=Partial Successes failures.text=Failures contractsBreached.text=Contracts Breached retainerDuration.text=Retainer Duration -mission.text=
     %s: %s (%s) - -transportationRating.text=Transportation Rating: %s -hasJumpShipOrWarShip.text=
     Has JumpShip or WarShip: +10 -smallCraft.text=Small Craft -fighters.text=Fighters -battleMeks.text=BattleMeks -vehicleSuperHeavy.text=Vehicles (Super Heavy) -vehicleHeavy.text=Vehicles (Heavy) -vehicleLight.text=Vehicles (Light) -protoMeks.text=ProtoMeks -battleArmor.text=Battle Armor -infantry.text=Infantry -transportString.text=
     %s: %d / %d Bays%s %s -asterisk.text=
* Lighter units will occupy spare bays
-noDropShip.text=No DropShip: -5 -dropShipString.text=
     DropShips: %d / %d Docking Collars (%s)
- -supportRating.text=
Support Rating: %d -crewRequirements.text=
     Partially Crewed Large Craft: -5
-administrationRequirements.text=
     Administration Requirements: %d / %d (%d)
-technicianRequirements.text=
     Technician Requirements: %s
-battleMeksAndProtoMeks.text=BattleMeks & ProtoMeks -vehicles.text=Vehicles -fightersAndSmallCraft.text=Fighters & Small Craft -technicianString.text=          %s: %d / %d
- -financialRating.text=Financial Rating: %s -hasLoanOrDebt.text=
     Has Loan or Debt: -10

- -crimeRating.text=
Crime Rating: %s -piracy.text=
     Piracy: %s -otherCrimes.text=
     Other: %s -dateOfLastCrime.text=
     Date of Last Crime: %s
- -otherModifiers.text=
Other Modifiers: %s -inactiveYears.text=
     Inactivity: %d -customModifier.text=
     Custom Modifier: %s + +transportationRating.text=Transportation Rating +hasJumpShipOrWarShip.text=JumpShip/WarShip Modifier +hasDropShip.text=DropShip Modifier +capacityCombatant.text=Combatant Capacity +capacityNonCombatant.text=Non-Combatant Capacity +dockingCollars.text=Docking Collars +smallCraft.text=Small Craft Bays +fighters.text=Fighter Bays +battleMeks.text=BattleMek Bays +vehicleSuperHeavy.text=Vehicle Bays (Super Heavy) +vehicleHeavy.text=Vehicle Bays (Heavy) +vehicleLight.text=Vehicle Bays (Light) +protoMeks.text=ProtoMek Bays +battleArmor.text=Battle Armor Bays +infantry.text=Infantry Bays +passengers.text=Non-Combatant Capacity +asterisk.text=Lighter units will occupy spare bays + +supportRating.text=Support Rating +crewRequirements.text=Partially Crewed Large Craft Modifier +administrationModifier.text=Administration Modifier +TechnicianModifier.text=Technician Modifier +administrationRequirements.text=Administrators +battleMeksAndProtoMeks.text=BattleMek & ProtoMek Technicians +vehicles.text=Vehicle Technicians +fightersAndSmallCraft.text=Fighters & Small Craft Technicians + +financialRating.text=Financial Rating +hasLoanOrDebt.text=Debt Modifier + +crimeRating.text=Crime Rating +piracy.text=Piracy +otherCrimes.text=Other +dateOfLastCrime.text=Date of Last Crime + +otherModifiers.text=Other Modifiers +inactiveYears.text=Inactivity Modifier +customModifier.text=Custom Modifier diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java index 40ff6f72b1..0a18cc2ba1 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java @@ -18,6 +18,7 @@ */ package mekhq.campaign.rating.CamOpsReputation; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.annotations.Nullable; import megamek.common.enums.SkillLevel; import megamek.logging.MMLogger; @@ -203,299 +204,298 @@ public int getReputationModifier() { * @return the report text as a string */ public String getReportText(Campaign campaign) { - StringBuilder description = new StringBuilder(); + int titleFontSize = UIUtil.scaleForGUI(7); + int subtitleFontSize = UIUtil.scaleForGUI(5); + String indent = "     "; - description.append("
"); - - description.append(String.format(resources.getString("unitReputation.text"), reputationRating)); + StringBuilder description = new StringBuilder(""); + // HEADER + description.append(String.format("
%s: %d
", + titleFontSize, campaign.getName(), reputationRating)); + description.append(String.format("
%s

", + resources.getString("refresh.text"))); // AVERAGE EXPERIENCE RATING - description.append(String.format(resources.getString("averageExperienceRating.text"), averageExperienceRating)); - description.append(String.format(resources.getString("experienceLevel.text"), averageSkillLevel.toString())); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("averageExperienceRating.text"), averageExperienceRating)); + + description.append(""); + description.append(String.format("", + indent, resources.getString("experienceLevel.text"), averageSkillLevel.toString())); + + description.append("
%s%s: %s

"); // COMMAND RATING - description.append(String.format(resources.getString("commandRating.text"), commanderRating)); - description.append(String.format(resources.getString("leadership.text"), commanderMap.get("leadership"))); - description.append(String.format(resources.getString("tactics.text"), commanderMap.get("tactics"))); - description.append(String.format(resources.getString("strategy.text"), commanderMap.get("strategy"))); - description.append(String.format(resources.getString("negotiation.text"), commanderMap.get("negotiation"))); - description.append(String.format(resources.getString("traits.text"), commanderMap.get("traits"))); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("commandRating.text"), commanderRating)); + + description.append(""); + description.append(String.format("", + indent, resources.getString("leadership.text"), commanderMap.get("leadership"))); + + description.append(String.format("", + indent, resources.getString("tactics.text"), commanderMap.get("tactics"))); + + description.append(String.format("", + indent, resources.getString("strategy.text"), commanderMap.get("strategy"))); + + description.append(String.format("", + indent, resources.getString("negotiation.text"), commanderMap.get("negotiation"))); + + description.append(String.format("", + indent, resources.getString("traits.text"), commanderMap.get("traits"), indent, + resources.getString("traitsNotImplemented.text"))); if (campaign.getCampaignOptions().isUseRandomPersonalities() - && (campaign.getCampaignOptions().isUseRandomPersonalityReputation())) { - description.append(String.format(resources.getString("personality.text"), commanderMap.get("personality"))) - .append("

"); - } else { - description.append("

"); + && (campaign.getCampaignOptions().isUseRandomPersonalityReputation())) { + description.append(String.format("", + indent, resources.getString("personality.text"), commanderMap.get("personality"))); } + description.append("
%s%s: %d
%s%s: %d
%s%s: %d
%s%s: %d
%s%s: %d %s%s
%s%s: %d

"); + // COMBAT RECORD RATING - description.append(String.format(resources.getString("combatRecordRating.text"), combatRecordRating)); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("combatRecordRating.text"), combatRecordRating)); + + description.append(""); + description.append(String.format("", + resources.getString("count.text"), resources.getString("modifier.text"))); + + description.append(String.format("", + indent, resources.getString("successes.text"), combatRecordMap.get("successes"), + combatRecordMap.get("successes") * 5)); + + description.append(String.format("", + indent, resources.getString("partialSuccesses.text"), combatRecordMap.get("partialSuccesses"), + combatRecordMap.get("partialSuccesses"))); - description.append(getMissionString("successes", resources.getString("successes.text"), 5)); - description.append(getMissionString("partialSuccesses", resources.getString("partialSuccesses.text"), 0)); - description.append(getMissionString("failures", resources.getString("failures.text"), -10)); - description.append(getMissionString("contractsBreached", resources.getString("contractsBreached.text"), -25)); + description.append(String.format("", + indent, resources.getString("failures.text"), combatRecordMap.get("failures"), + combatRecordMap.get("failures") * 10)); + + description.append(String.format("", + indent, resources.getString("contractsBreached.text"), combatRecordMap.get("contractsBreached"), + combatRecordMap.get("contractsBreached") * 25)); if (campaign.getRetainerStartDate() != null) { - description.append(getMissionString("retainerDuration", resources.getString("retainerDuration.text"), 5)) - .append("

"); - } else { - description.append("

"); + description.append(String.format("", + indent, resources.getString("retainerDuration.text"), combatRecordMap.get("retainerDuration"), + combatRecordMap.get("retainerDuration") * 5)); } - // TRANSPORTATION RATING - description.append(String.format(resources.getString("transportationRating.text"), transportationRating)); + description.append("
%s%s
%s%s: " + + "%d +%d
%s%s: " + + "%d +%d
%s%s: " + + "%d -%d
%s%s: " + + "%d -%d
%s%s: " + + "%d +%d

"); - if (transportationCapacities.get("hasJumpShipOrWarShip") == 1) { - description.append(resources.getString("hasJumpShipOrWarShip.text")); - } + // TRANSPORTATION RATING + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("transportationRating.text"), transportationRating)); + + description.append(""); + description.append(String.format("", + indent, resources.getString("hasJumpShipOrWarShip.text"), + transportationCapacities.get("hasJumpShipOrWarShip") == 1 ? "+10" : "+0")); + + description.append(String.format("", + indent, resources.getString("hasDropShip.text"), + transportationRequirements.get("dropShipCount") > 0 ? "+0" : "-5")); + + description.append(String.format("", + indent, resources.getString("capacityCombatant.text"), + transportationCapacities.get("capacityRating") >= 0 ? "+" : "", + transportationCapacities.get("capacityRating"))); + + description.append(String.format("", + indent, resources.getString("capacityNonCombatant.text"), + transportationValues.get("passenger") >= 0 ? "+" : "", + transportationValues.get("passenger"))); + description.append("
%s%s: %s
%s%s: %s
%s%s: %s%s
%s%s: %s%s
"); + + description.append(""); + description.append(String.format("", + resources.getString("required.text"), resources.getString("available.text"))); + + description.append(String.format("", + indent, resources.getString("dockingCollars.text"), transportationRequirements.get("dropShipCount"), + transportationCapacities.get("dockingCollars"))); + + description.append(String.format("", + indent, resources.getString("smallCraft.text"), transportationRequirements.get("smallCraftCount"), + transportationCapacities.get("smallCraftBays"))); + + description.append(String.format("", + indent, resources.getString("fighters.text"), transportationRequirements.get("asfCount"), + transportationCapacities.get("asfBays"))); - description.append(getDropShipString()); - description.append(getTransportString("smallCraftCount", "smallCraftBays", "smallCraft", - resources.getString("smallCraft.text"), true)); - description - .append(getTransportString("asfCount", "asfBays", "asf", resources.getString("fighters.text"), false)); // <50.01 compatibility handler try { - description.append(getTransportString("mekCount", "mekBays", "mek", - resources.getString("battleMeks.text"), false)); + description.append(String.format("", + indent, resources.getString("battleMeks.text"), transportationRequirements.get("mekCount"), + transportationCapacities.get("mekBays"))); } catch (Exception e) { - description.append(getTransportString("mechCount", "mechBays", "mech", - resources.getString("battleMeks.text"), false)); + description.append(String.format("", + indent, resources.getString("battleMeks.text"), transportationRequirements.get("mechCount"), + transportationCapacities.get("mechBays"))); } - description.append(getTransportString("superHeavyVehicleCount", "superHeavyVehicleBays", "superHeavyVehicle", - resources.getString("vehicleSuperHeavy.text"), true)); - description.append(getTransportString("heavyVehicleCount", "heavyVehicleBays", "heavyVehicle", - resources.getString("vehicleHeavy.text"), true)); - description.append(getTransportString("lightVehicleCount", "lightVehicleBays", "lightVehicle", - resources.getString("vehicleLight.text"), false)); + description.append(String.format("", + indent, resources.getString("vehicleSuperHeavy.text"), transportationRequirements.get("superHeavyVehicleCount"), + transportationCapacities.get("superHeavyVehicleBays"))); + + description.append(String.format("", + indent, resources.getString("vehicleHeavy.text"), transportationRequirements.get("heavyVehicleCount"), + transportationCapacities.get("heavyVehicleBays"))); + + description.append(String.format("", + indent, resources.getString("vehicleLight.text"), transportationRequirements.get("lightVehicleCount"), + transportationCapacities.get("lightVehicleBays"))); + // <50.01 compatibility handler try { - description.append(getTransportString("protoMekCount", "protoMekBays", - "protoMek", resources.getString("protoMeks.text"), false)); + description.append(String.format("", + indent, resources.getString("protoMeks.text"), transportationRequirements.get("protoMekCount"), + transportationCapacities.get("protoMekBays"))); } catch (Exception e) { - description.append(getTransportString("protoMechCount", "protoMechBays", - "protoMech", resources.getString("protoMeks.text"), false)); + description.append(String.format("", + indent, resources.getString("protoMeks.text"), transportationRequirements.get("protoMechCount"), + transportationCapacities.get("protoMechBays"))); } - description.append(getTransportString("battleArmorCount", "battleArmorBays", "battleArmor", - resources.getString("battleArmor.text"), false)); - description.append(getTransportString("infantryCount", "infantryBays", "infantry", - resources.getString("infantry.text"), false)); - description.append(resources.getString("asterisk.text")); + description.append(String.format("", + indent, resources.getString("battleArmor.text"), transportationRequirements.get("battleArmorCount"), + transportationCapacities.get("battleArmorBays"))); - // SUPPORT RATING - description.append(String.format(resources.getString("supportRating.text"), supportRating)); + description.append(String.format("", + indent, resources.getString("infantry.text"), transportationRequirements.get("infantryCount"), + transportationCapacities.get("infantryBays"))); - if (crewRequirements.get("crewRequirements") < 0) { - description.append(resources.getString("crewRequirements.text")); - } + description.append(String.format("", + indent, resources.getString("passengers.text"), transportationRequirements.get("passengerCount"), + transportationCapacities.get("passengerCapacity"))); - description.append(String.format(resources.getString("administrationRequirements.text"), - administrationRequirements.get("personnelCount"), - administrationRequirements.get("administratorCount"), - administrationRequirements.get("total"))); + description.append("
%s%s
%s%s: " + + "%d %d
%s%s:* " + + "%d %d
%s%s:* " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s:* " + + "%d %d
%s%s:* " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
"); + description.append(String.format("* %s

", resources.getString("asterisk.text"))); - description.append(String.format(resources.getString("technicianRequirements.text"), - technicianRequirements.get("rating").get(0))); + // SUPPORT RATING + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("supportRating.text"), supportRating)); + + description.append(""); + description.append(String.format("", + indent, resources.getString("crewRequirements.text"), + crewRequirements.get("crewRequirements") >= 0 ? "+0" : "-5")); + + description.append(String.format("", + indent, resources.getString("administrationModifier.text"), + administrationRequirements.get("total") >= 0 ? "+" : "", + administrationRequirements.get("total"))); + + description.append(String.format("", + indent, resources.getString("TechnicianModifier.text"), + technicianRequirements.get("rating").get(0) >= 0 ? "+" : "", + technicianRequirements.get("rating").get(0))); + description.append("
%s%s: %s
%s%s: %s%s
%s%s: %s%s
"); + + description.append(""); + description.append(String.format("", + resources.getString("required.text"), resources.getString("available.text"))); + + description.append(String.format("", + indent, resources.getString("administrationRequirements.text"), administrationRequirements.get("personnelCount"), + administrationRequirements.get("administratorCount"))); // <50.01 compatibility handler try { - description.append(getTechnicianString("mek")); + description.append(String.format("", + indent, resources.getString("battleMeksAndProtoMeks.text"), technicianRequirements.get("mek").get(0), + technicianRequirements.get("mek").get(1))); } catch (Exception e) { - description.append(getTechnicianString("mech")); + description.append(String.format("", + indent, resources.getString("battleMeksAndProtoMeks.text"), technicianRequirements.get("mech").get(0), + technicianRequirements.get("mech").get(1))); } - description.append(getTechnicianString("vehicle")); - description.append(getTechnicianString("aero")); - description.append(getTechnicianString("battleArmor")); - description.append("
"); + description.append(String.format("", + indent, resources.getString("vehicles.text"), technicianRequirements.get("vehicle").get(0), + technicianRequirements.get("vehicle").get(1))); + + description.append(String.format("", + indent, resources.getString("fightersAndSmallCraft.text"), technicianRequirements.get("aero").get(0), + technicianRequirements.get("aero").get(1))); + + description.append(String.format("", + indent, resources.getString("battleArmor.text"), technicianRequirements.get("battleArmor").get(0), + technicianRequirements.get("battleArmor").get(1))); + description.append("
%s%s
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d
%s%s: " + + "%d %d

"); // FINANCIAL RATING - description.append(String.format(resources.getString("financialRating.text"), financialRating)); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("financialRating.text"), financialRating)); - if ((financialRatingMap.get("hasLoan") + financialRatingMap.get("inDebt")) > 0) { - description.append(resources.getString("hasLoanOrDebt.text")); - } else { - description.append("
"); - } + description.append(""); + description.append(String.format("", + indent, resources.getString("hasLoanOrDebt.text"), + ((financialRatingMap.get("hasLoan") + financialRatingMap.get("inDebt")) > 0) ? "-10" : "0")); + description.append("
%s%s: %s

"); // CRIME RATING - description.append(String.format(resources.getString("crimeRating.text"), crimeRating)); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("crimeRating.text"), crimeRating)); - if (crimeRating < 0) { - int piracy = crimeRatingMap.get("piracy"); - if (piracy < 0) { - description.append(String.format(resources.getString("piracy.text"), piracy)); - } + description.append(""); + description.append(String.format("", + indent, resources.getString("piracy.text"), crimeRatingMap.get("piracy"))); - int otherCrimes = crimeRatingMap.get("other"); - if (otherCrimes < 0) { - description.append(String.format(resources.getString("otherCrimes.text"), otherCrimes)); - } + description.append(String.format("", + indent, resources.getString("otherCrimes.text"), crimeRatingMap.get("other"))); + description.append("
%s%s: %d
%s%s: %d
"); - description.append(String.format(resources.getString("dateOfLastCrime.text"), dateOfLastCrime)); - } else { - description.append("
"); + if (crimeRating < 0) { + description.append(String.format("%s%s: %s
", indent, + resources.getString("dateOfLastCrime.text"), dateOfLastCrime == null ? "" : dateOfLastCrime)); } // OTHER MODIFIERS - description.append(String.format(resources.getString("otherModifiers.text"), otherModifiers)); + description.append(String.format("%s: %d
", + subtitleFontSize, resources.getString("otherModifiers.text"), otherModifiers)); - int inactiveYears = otherModifiersMap.get("inactiveYears"); + description.append(""); + description.append(String.format("", + indent, resources.getString("inactiveYears.text"), otherModifiersMap.get("inactiveYears"), + otherModifiersMap.get("inactiveYears") * -5)); - if (inactiveYears > 0) { - description.append(String.format(resources.getString("inactiveYears.text"), -inactiveYears * 5)); - } + description.append(String.format("", + indent, resources.getString("customModifier.text"), otherModifiersMap.get("customModifier"))); + description.append("
%s%s: %d %d
%s%s: %d
"); - int customModifier = otherModifiersMap.get("customModifier"); - - if (customModifier != 0) { - String modifier = String.format("(%+d)", customModifier); - description.append(String.format(resources.getString("customModifier.text"), modifier)); - } - - description.append("
"); + description.append(""); return description.toString(); } - /** - * Appends the technician requirement information for the given type. - * If the technician requirement exceeds 0, it generates an HTML formatted - * string - * with the technician label and the current count and maximum count of - * technicians. - * - * @param type the type of technician requirement (mek, vehicle, aero, - * battleArmor) - * @return the generated technician requirement string in HTML format, - * or an empty string if either technicianRequirement value is 0. - */ - private String getTechnicianString(String type) { - List technicianRequirement = technicianRequirements.get(type); - - if ((technicianRequirement.get(0) > 0) || (technicianRequirement.get(1) > 0)) { - String label = switch (type) { - // <50.01 compatibility handler - case "mek", "mech" -> resources.getString("battleMeksAndProtoMeks.text"); - case "vehicle" -> resources.getString("vehicles.text"); - case "aero" -> resources.getString("fightersAndSmallCraft.text"); - case "battleArmor" -> resources.getString("battleArmor.text"); - default -> throw new IllegalStateException( - "Unexpected value in mekhq/campaign/rating/CamOpsReputation/ReputationController.java/getTechnicianString: " - + type); - }; - - return String.format(resources.getString("technicianString.text"), - label, - technicianRequirement.get(0), - technicianRequirement.get(1)); - } - - return ""; - } - - /** - * Generates the mission string with the given key, label, and multiplier. - * - * @param key the key for accessing the combat record count - * @param label the label to be displayed in the mission string - * @param multiplier the multiplier to apply to the count - * @return the generated mission string, formatted as - * "
- *      label: count (count * - * multiplier)
- * ", or null if the count is <= 0 - */ - private String getMissionString(String key, String label, int multiplier) { - int count = combatRecordMap.get(key); - int total = count * multiplier; - - if (count > 0) { - return String.format(resources.getString("mission.text"), - label, - count, - String.format(total > 0 ? "+%d" : "%d", total)); - } else { - return ""; - } - } - - /** - * Generates DropShip string information for the unit report - * - * @return the generated string in HTML format, formatted as - * "
- *      DropShips: unitCount / bayCapacity - * Docking Collars (modifier)
- * " - */ - private String getDropShipString() { - int unitCount = transportationRequirements.get("dropShipCount"); - int bayCapacity = transportationCapacities.get("dockingCollars"); - String modifier = "0"; - - if (unitCount == 0) { - modifier = resources.getString("noDropShip.text"); - } else if (bayCapacity >= unitCount) { - modifier = "+5"; - } - - return String.format(resources.getString("dropShipString.text"), - unitCount, - bayCapacity, - modifier); - } - - /** - * Generates a transport string with the given unitKey, bayKey, valueKey, label, - * and displayAsterisk. - * - * @param unitKey the key to access the unit count in the - * transportationRequirements map - * @param bayKey the key to access the bay capacity in the - * transportationCapacities map - * @param valueKey the key to access the rating in the - * transportationValues map - * @param label the label to be displayed in the transport string - * @param displayAsterisk whether to display an asterisk in the transport string - * @return the generated transport string in HTML format, formatted as - * "
- *      label: unitCount / bayCount Bays* - * modifier
- * ", or an empty string if unitCount and bayCount - * are both 0 - */ - private String getTransportString(String unitKey, String bayKey, String valueKey, String label, - boolean displayAsterisk) { - int unitCount = transportationRequirements.get(unitKey); - int bayCount = transportationCapacities.get(bayKey); - int rating = transportationValues.get(valueKey); - - String asterisk = displayAsterisk ? "*" : ""; - String modifier = ""; - - if (unitCount > 0 || bayCount > 0) { - if (rating > 0) { - modifier = String.format("(+%d)", rating); - } else if (rating < 0) { - modifier = String.format("(%d)", rating); - } - - return String.format(resources.getString("transportString.text"), - label, - unitCount, - bayCount, - asterisk, - modifier); - } else { - return ""; - } - } - /** * Writes the reputation ratings and values to an XML file. * @@ -587,8 +587,6 @@ public void writeReputationToXML(final PrintWriter pw, int indent) { * @param map the map to write to XML, where the keys are strings, and the * values can be any type * @param the type of the values in the map - * @return the updated value of the indent parameter after writing the map to - * XML */ private void writeMapToXML(final PrintWriter pw, final int indent, final Map map) { for (String key : map.keySet()) { From 090eec1dc5cf6760f640f11459d52d066273918a Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 22 Nov 2024 17:32:37 -0600 Subject: [PATCH 6/6] Add commander info to reputation report Updated `ReputationController` to include the flagged commander's name in the generated reputation report. Added relevant resource strings to the properties file for localization. --- .../mekhq/resources/CamOpsReputation.properties | 2 ++ .../rating/CamOpsReputation/ReputationController.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/MekHQ/resources/mekhq/resources/CamOpsReputation.properties b/MekHQ/resources/mekhq/resources/CamOpsReputation.properties index 6684728987..1551051bd5 100644 --- a/MekHQ/resources/mekhq/resources/CamOpsReputation.properties +++ b/MekHQ/resources/mekhq/resources/CamOpsReputation.properties @@ -8,6 +8,8 @@ averageExperienceRating.text=Average Experience Rating experienceLevel.text=Experience Level commandRating.text=Command Rating +commander.text=Commander +commanderNone.text=No Commander leadership.text=Leadership tactics.text=Tactics strategy.text=Strategy diff --git a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java index 0a18cc2ba1..04f7694ed2 100644 --- a/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java +++ b/MekHQ/src/mekhq/campaign/rating/CamOpsReputation/ReputationController.java @@ -24,6 +24,7 @@ import megamek.logging.MMLogger; import mekhq.MekHQ; import mekhq.campaign.Campaign; +import mekhq.campaign.personnel.Person; import mekhq.utilities.MHQXMLUtility; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -230,6 +231,16 @@ public String getReportText(Campaign campaign) { subtitleFontSize, resources.getString("commandRating.text"), commanderRating)); description.append(""); + Person commander = campaign.getFlaggedCommander(); + + String commanderName = resources.getString("commanderNone.text"); + if (commander != null) { + commanderName = commander.getFullName(); + } + + description.append(String.format("", + indent, resources.getString("commander.text"), commanderName)); + description.append(String.format("", indent, resources.getString("leadership.text"), commanderMap.get("leadership")));
%s%s: %s
%s%s: %d