From 7dc65ef7043234dc53d62488b07b09a321f2b7d4 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Mon, 17 May 2021 11:11:08 -0400 Subject: [PATCH 1/3] Creating a contract command rights enum --- .../mekhq/resources/Mission.properties | 10 ++ .../mekhq/campaign/market/ContractMarket.java | 23 +-- .../mekhq/campaign/mission/AtBScenario.java | 32 ++-- .../src/mekhq/campaign/mission/Contract.java | 50 ++---- .../mission/enums/ContractCommandRights.java | 111 ++++++++++++++ .../stratcon/StratconContractInitializer.java | 144 +++++++++--------- .../stratcon/StratconRulesManager.java | 39 ++--- .../gui/dialog/NewAtBContractDialog.java | 2 +- .../mekhq/gui/dialog/NewContractDialog.java | 76 +++++---- .../mekhq/gui/view/ContractSummaryPanel.java | 6 +- .../src/mekhq/gui/view/MissionViewPanel.java | 10 +- 11 files changed, 316 insertions(+), 187 deletions(-) create mode 100644 MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java diff --git a/MekHQ/resources/mekhq/resources/Mission.properties b/MekHQ/resources/mekhq/resources/Mission.properties index 80fec4ed65..6132a41562 100644 --- a/MekHQ/resources/mekhq/resources/Mission.properties +++ b/MekHQ/resources/mekhq/resources/Mission.properties @@ -3,6 +3,16 @@ ## General Mission Resources ## Enums +# ContractCommandRights Enum +ContractCommandRights.INTEGRATED.text=Integrated +ContractCommandRights.INTEGRATED.toolTipText=The force's command positions are largely filled by officers provided by the employer.
By doing so the employer takes on full legal responsibility for the actions of the force, provided that the force does not willfully disobey the orders of the officer in the legally questionable action or actions.
This is normally used when hiring mercenaries to bolster the employer's forces before a large assault or raid.
This is the standard for government forces and is widely avoided by all other forces. +ContractCommandRights.HOUSE.text=House +ContractCommandRights.HOUSE.toolTipText=The force is placed under the direct authority of an employer-provided military officer. This officer may dictate tactics and strategies to the force, but the force otherwise retains its command structure.
By doing so the employer takes on full legal responsibility for the actions of the force, provided that the force does not willfully disobey the orders of the officer in the legally questionable action or actions.
This may be required by the employer for closely coordinated raids, planetary assaults, and garrison duties, as this allows the government to ensure the force is properly deployed within the larger battle plan. +ContractCommandRights.LIAISON.text=Liaison +ContractCommandRights.LIAISON.toolTipText=The force has an employer-provided liaison that both represents the employer and accompanies the force during the contract.
By doing so the employer takes on limited legal responsibility for the actions of the force, as their decisions are being monitored by the liaison. +ContractCommandRights.INDEPENDENT.text=Independent +ContractCommandRights.INDEPENDENT.toolTipText=The force has full battlefield autonomy, with no interference from their employer. However, the employer will provide limited if any support to the force.
The force is still bound to answer for any questionable actions they take to their employer and/or an outside authority/arbitrator (e.g. the Mercenary Review and Bonding Commission) following the contract.
Employers may, especially for covert missions, sign contracts with independent command rights to shield them from legal responsibility from the force's actions while undertaking the contract.
This is the standard for pirate contracts. + # MissionStatus Enum MissionStatus.ACTIVE.text=Active MissionStatus.ACTIVE.toolTipText=This mission/contract is active, with scenarios still occurring. diff --git a/MekHQ/src/mekhq/campaign/market/ContractMarket.java b/MekHQ/src/mekhq/campaign/market/ContractMarket.java index d8f88707f5..dc309666e7 100644 --- a/MekHQ/src/mekhq/campaign/market/ContractMarket.java +++ b/MekHQ/src/mekhq/campaign/market/ContractMarket.java @@ -30,6 +30,7 @@ import java.util.Set; import mekhq.campaign.market.enums.ContractMarketMethod; +import mekhq.campaign.mission.enums.ContractCommandRights; import mekhq.campaign.personnel.enums.PersonnelRole; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -496,8 +497,7 @@ else if (contract.getMissionType() == AtBContract.MT_RIOTDUTY) } contract.calculateLength(campaign.getCampaignOptions().getVariableContractLength()); - contract.setCommandRights(Math.max(parent.getCommandRights() - 1, - Contract.COM_INTEGRATED)); + contract.setCommandRights(ContractCommandRights.values()[Math.max(parent.getCommandRights().ordinal() - 1, 0)]); contract.setSalvageExchange(parent.isSalvageExchange()); contract.setSalvagePct(Math.max(parent.getSalvagePct() - 10, 0)); contract.setStraightSupport(Math.max(parent.getStraightSupport() - 20, @@ -756,19 +756,24 @@ protected void setAtBContractClauses(AtBContract contract, int unitRatingMod, Ca if (campaign.getFactionCode().equals("MERC")) { rollCommandClause(contract, mods.mods[CLAUSE_COMMAND]); } else { - contract.setCommandRights(Contract.COM_INTEGRATED); + contract.setCommandRights(ContractCommandRights.INTEGRATED); } rollSalvageClause(contract, mods.mods[CLAUSE_SALVAGE]); rollSupportClause(contract, mods.mods[CLAUSE_SUPPORT]); rollTransportClause(contract, mods.mods[CLAUSE_TRANSPORT]); } - private void rollCommandClause(AtBContract contract, int mod) { - int roll = Compute.d6(2) + mod; - if (roll < 3) contract.setCommandRights(Contract.COM_INTEGRATED); - else if (roll < 8) contract.setCommandRights(Contract.COM_HOUSE); - else if (roll < 12) contract.setCommandRights(Contract.COM_LIAISON); - else contract.setCommandRights(Contract.COM_INDEP); + private void rollCommandClause(final Contract contract, final int modifier) { + final int roll = Compute.d6(2) + modifier; + if (roll < 3) { + contract.setCommandRights(ContractCommandRights.INTEGRATED); + } else if (roll < 8) { + contract.setCommandRights(ContractCommandRights.HOUSE); + } else if (roll < 12) { + contract.setCommandRights(ContractCommandRights.LIAISON); + } else { + contract.setCommandRights(ContractCommandRights.INDEPENDENT); + } } private void rollSalvageClause(AtBContract contract, int mod) { diff --git a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java index f01f041160..b57265baaf 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java @@ -682,20 +682,26 @@ private void setStandardMissionForces(Campaign campaign) { if (getContract(campaign).getMissionType() == AtBContract.MT_CADREDUTY) { numAttachedPlayer = 3; } else if (campaign.getFactionCode().equals("MERC")) { - if (getContract(campaign).getCommandRights() == Contract.COM_INTEGRATED) { - if (campaign.getCampaignOptions().getPlayerControlsAttachedUnits()) { - numAttachedPlayer = 2; - } else { - numAttachedBot = 2; - } - } else if (getContract(campaign).getCommandRights() == Contract.COM_HOUSE) { - if (campaign.getCampaignOptions().getPlayerControlsAttachedUnits()) { + switch (getContract(campaign).getCommandRights()) { + case INTEGRATED: + if (campaign.getCampaignOptions().getPlayerControlsAttachedUnits()) { + numAttachedPlayer = 2; + } else { + numAttachedBot = 2; + } + break; + case HOUSE: + if (campaign.getCampaignOptions().getPlayerControlsAttachedUnits()) { + numAttachedPlayer = 1; + } else { + numAttachedBot = 1; + } + break; + case LIAISON: numAttachedPlayer = 1; - } else { - numAttachedBot = 1; - } - } else if (getContract(campaign).getCommandRights() == Contract.COM_LIAISON) { - numAttachedPlayer = 1; + break; + default: + break; } } diff --git a/MekHQ/src/mekhq/campaign/mission/Contract.java b/MekHQ/src/mekhq/campaign/mission/Contract.java index b8c3429357..3dd247e934 100644 --- a/MekHQ/src/mekhq/campaign/mission/Contract.java +++ b/MekHQ/src/mekhq/campaign/mission/Contract.java @@ -28,6 +28,7 @@ import mekhq.campaign.finances.Accountant; import mekhq.campaign.finances.Money; +import mekhq.campaign.mission.enums.ContractCommandRights; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -46,18 +47,12 @@ public class Contract extends Mission implements Serializable, MekHqXmlSerializable { private static final long serialVersionUID = 4606932545119410453L; - public final static int OH_NONE = 0; - public final static int OH_HALF = 1; - public final static int OH_FULL = 2; - public final static int OH_NUM = 3; + public final static int OH_NONE = 0; + public final static int OH_HALF = 1; + public final static int OH_FULL = 2; + public final static int OH_NUM = 3; - public final static int COM_INTEGRATED = 0; - public final static int COM_HOUSE = 1; - public final static int COM_LIAISON = 2; - public final static int COM_INDEP = 3; - public final static int COM_NUM = 4; - - public final static int MRBC_FEE_PERCENTAGE = 5; + public final static int MRBC_FEE_PERCENTAGE = 5; private LocalDate startDate; private LocalDate endDate; @@ -66,7 +61,7 @@ public class Contract extends Mission implements Serializable, MekHqXmlSerializa private String employer; private double paymentMultiplier; - private int commandRights; + private ContractCommandRights commandRights; private int overheadComp; private int straightSupport; private int battleLossComp; @@ -107,7 +102,7 @@ public Contract(String name, String employer) { this.nMonths = 12; this.paymentMultiplier = 2.0; - this.commandRights = COM_HOUSE; + setCommandRights(ContractCommandRights.HOUSE); this.overheadComp = OH_NONE; this.straightSupport = 50; this.battleLossComp = 50; @@ -132,21 +127,6 @@ public static String getOverheadCompName(int i) { } } - public static String getCommandRightsName(int i) { - switch (i) { - case COM_INTEGRATED: - return "Integrated"; - case COM_HOUSE: - return "House"; - case COM_LIAISON: - return "Liaison"; - case COM_INDEP: - return "Independent"; - default: - return "?"; - } - } - public String getEmployer() { return employer; } @@ -221,12 +201,12 @@ public void setOverheadComp(int s) { overheadComp = s; } - public int getCommandRights() { + public ContractCommandRights getCommandRights() { return commandRights; } - public void setCommandRights(int s) { - commandRights = s; + public void setCommandRights(final ContractCommandRights commandRights) { + this.commandRights = commandRights; } public int getBattleLossComp() { @@ -559,9 +539,9 @@ public int getMonthsLeft(LocalDate date) { * Calculations to be performed once the contract has been accepted. */ public void acceptContract(Campaign campaign) { - + } - + /** * Only do this at the time the contract is set up, otherwise amounts may change after * the ink is signed, which is a no-no. @@ -684,7 +664,7 @@ protected void writeToXmlBegin(PrintWriter pw1, int indent) { MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "endDate", MekHqXmlUtil.saveFormattedDate(endDate)); MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "employer", employer); MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "paymentMultiplier", paymentMultiplier); - MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "commandRights", commandRights); + MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "commandRights", getCommandRights().name()); MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "overheadComp", overheadComp); MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "salvagePct", salvagePct); MekHqXmlUtil.writeSimpleXmlTag(pw1, indent, "salvageExchange", salvageExchange); @@ -726,7 +706,7 @@ public void loadFieldsFromXmlNode(Node wn) throws ParseException { } else if (wn2.getNodeName().equalsIgnoreCase("paymentMultiplier")) { paymentMultiplier = Double.parseDouble(wn2.getTextContent().trim()); } else if (wn2.getNodeName().equalsIgnoreCase("commandRights")) { - commandRights = Integer.parseInt(wn2.getTextContent().trim()); + setCommandRights(ContractCommandRights.parseFromString(wn2.getTextContent().trim())); } else if (wn2.getNodeName().equalsIgnoreCase("overheadComp")) { overheadComp = Integer.parseInt(wn2.getTextContent().trim()); } else if (wn2.getNodeName().equalsIgnoreCase("salvagePct")) { diff --git a/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java b/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java new file mode 100644 index 0000000000..fd8e5d8d73 --- /dev/null +++ b/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 - The MegaMek Team. All Rights Reserved. + * + * This file is part of MekHQ. + * + * MekHQ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MekHQ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MekHQ. If not, see . + */ +package mekhq.campaign.mission.enums; + +import megamek.common.util.EncodeControl; +import mekhq.MekHQ; + +import java.util.ResourceBundle; + +public enum ContractCommandRights { + //region Enum Declarations + INTEGRATED("ContractCommandRights.INTEGRATED.text", "ContractCommandRights.INTEGRATED.toolTipText"), + HOUSE("ContractCommandRights.HOUSE.text", "ContractCommandRights.HOUSE.toolTipText"), + LIAISON("ContractCommandRights.LIAISON.text", "ContractCommandRights.LIAISON.toolTipText"), + INDEPENDENT("ContractCommandRights.INDEPENDENT.text", "ContractCommandRights.INDEPENDENT.toolTipText"); + //endregion Enum Declarations + + //region Variable Declarations + private final String name; + private final String toolTipText; + + private final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.Mission", new EncodeControl()); + //endregion Variable Declarations + + //region Constructors + ContractCommandRights(final String name, final String toolTipText) { + this.name = resources.getString(name); + this.toolTipText = resources.getString(toolTipText); + } + //endregion Constructors + + //region Getters + public String getToolTipText() { + return toolTipText; + } + //endregion Getters + + //region Boolean Comparison Methods + public boolean isIntegrated() { + return this == INTEGRATED; + } + + public boolean isHouse() { + return this == HOUSE; + } + + public boolean isLiaison() { + return this == LIAISON; + } + + public boolean isIndependent() { + return this == INDEPENDENT; + } + //endregion Boolean Comparison Methods + + //region File I/O + /** + * @param text containing the ContractCommandRights + * @return the saved ContractCommandRights + */ + public static ContractCommandRights parseFromString(final String text) { + try { + return valueOf(text); + } catch (Exception ignored) { + + } + + try { + switch (Integer.parseInt(text)) { + case 0: + return INTEGRATED; + case 1: + return HOUSE; + case 2: + return LIAISON; + case 3: + return INDEPENDENT; + default: + break; + } + } catch (Exception ignored) { + + } + + MekHQ.getLogger().error("Failed to parse text " + text + " into a ContractCommandRights, returning HOUSE."); + + return HOUSE; + } + //endregion File I/O + + @Override + public String toString() { + return name; + } +} diff --git a/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java b/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java index f999b22d3e..849c3d03dc 100644 --- a/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java +++ b/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java @@ -49,55 +49,55 @@ public static void initializeCampaignState(AtBContract contract, Campaign campai StratconCampaignState campaignState = new StratconCampaignState(contract); campaignState.setBriefingText(contractDefinition.getBriefing() + "
" + generateCommandLevelText(contract)); campaignState.setStrategicObjectivesBehaveAsVPs(contractDefinition.objectivesBehaveAsVPs()); - + // dependency: this is required here in order for scenario initialization to work properly contract.setStratconCampaignState(campaignState); - + // First, initialize the proper number of tracks. Then: - // for each objective: + // for each objective: // step 1: calculate objective count // if scaled, multiply # required lances by factor, round up, otherwise just fixed # // step 2: evenly distribute objectives through tracks - // if uneven number remaining, distribute randomly + // if uneven number remaining, distribute randomly // when objective is specific scenario victory, place specially flagged scenarios // when objective is allied/hostile facility, place those facilities int numTracks = contract.getRequiredLances() / NUM_LANCES_PER_TRACK; - + for (int x = 0; x < numTracks; x++) { int scenarioOdds = contractDefinition.getScenarioOdds().get(Compute.randomInt(contractDefinition.getScenarioOdds().size())); int deploymentTime = contractDefinition.getDeploymentTimes().get(Compute.randomInt(contractDefinition.getDeploymentTimes().size())); - + StratconTrackState track = initializeTrackState(NUM_LANCES_PER_TRACK, scenarioOdds, deploymentTime); track.setDisplayableName(String.format("Track %d", x)); campaignState.addTrack(track); } - + // a campaign will have X tracks going at a time, where // X = # required lances / 3, rounded up. The last track will have fewer required lances. int oddLanceCount = contract.getRequiredLances() % NUM_LANCES_PER_TRACK; if (oddLanceCount > 0) { int scenarioOdds = contractDefinition.getScenarioOdds().get(Compute.randomInt(contractDefinition.getScenarioOdds().size())); int deploymentTime = contractDefinition.getDeploymentTimes().get(Compute.randomInt(contractDefinition.getDeploymentTimes().size())); - + StratconTrackState track = initializeTrackState(oddLanceCount, scenarioOdds, deploymentTime); track.setDisplayableName(String.format("Track %d", campaignState.getTracks().size())); campaignState.addTrack(track); } - + // now seed the tracks with objectives and facilities for (ObjectiveParameters objectiveParams : contractDefinition.getObjectiveParameters()) { int objectiveCount = objectiveParams.objectiveCount > 0 ? (int) objectiveParams.objectiveCount : (int) (-objectiveParams.objectiveCount * contract.getRequiredLances()); - + campaignState.incrementPendingStrategicObjectiveCount(objectiveCount); - - List trackObjects = trackObjectDistribution(objectiveCount, campaignState.getTracks().size()); - + + List trackObjects = trackObjectDistribution(objectiveCount, campaignState.getTracks().size()); + for (int x = 0; x < trackObjects.size(); x++) { int numObjects = trackObjects.get(x); - + switch (objectiveParams.objectiveType) { case SpecificScenarioVictory: initializeObjectiveScenarios(campaign, contract, campaignState.getTrack(x), numObjects, @@ -119,112 +119,112 @@ public static void initializeCampaignState(AtBContract contract, Campaign campai } } } - + // non-objective allied facilities int facilityCount = contractDefinition.getAlliedFacilityCount() > 0 ? (int) contractDefinition.getAlliedFacilityCount() : (int) (-contractDefinition.getAlliedFacilityCount() * contract.getRequiredLances()); - - List trackObjects = trackObjectDistribution(facilityCount, campaignState.getTracks().size()); - + + List trackObjects = trackObjectDistribution(facilityCount, campaignState.getTracks().size()); + for (int x = 0; x < trackObjects.size(); x++) { int numObjects = trackObjects.get(x); - + initializeTrackFacilities(campaignState.getTrack(x), numObjects, ForceAlignment.Allied, false); } - + // non-objective hostile facilities facilityCount = contractDefinition.getHostileFacilityCount() > 0 ? (int) contractDefinition.getHostileFacilityCount() : (int) (-contractDefinition.getHostileFacilityCount() * contract.getRequiredLances()); - - trackObjects = trackObjectDistribution(facilityCount, campaignState.getTracks().size()); - + + trackObjects = trackObjectDistribution(facilityCount, campaignState.getTracks().size()); + for (int x = 0; x < trackObjects.size(); x++) { int numObjects = trackObjects.get(x); - + initializeTrackFacilities(campaignState.getTrack(x), numObjects, ForceAlignment.Opposing, false); } - + // now we're done } - + /** * Set up initial state of a track, dimensions are based on number of assigned lances. */ public static StratconTrackState initializeTrackState(int numLances, int scenarioOdds, int deploymentTime) { - // to initialize a track, + // to initialize a track, // 1. we set the # of required lances // 2. set the track size to a total of numlances * 28 hexes, a rectangle that is wider than it is taller // the idea being to create a roughly rectangular playing field that, // if one deploys a scout lance each week to a different spot, can be more or less fully covered - + StratconTrackState retVal = new StratconTrackState(); retVal.setRequiredLanceCount(numLances); - + // set width and height int numHexes = numLances * 28; int height = (int) Math.floor(Math.sqrt(numHexes)); int width = numHexes / height; retVal.setWidth(width); retVal.setHeight(height); - + retVal.setScenarioOdds(scenarioOdds); retVal.setDeploymentTime(deploymentTime); - + // TODO: place terrain - + return retVal; } - + /** * Generates an array list representing the number of objects to place in a given number of tracks. */ private static List trackObjectDistribution(int numObjects, int numTracks) { List retVal = new ArrayList<>(); int leftOver = numObjects % numTracks; - + for (int track = 0; track < numTracks; track++) { int trackObjects = numObjects / numTracks; - + // if we are unevenly distributed, add an extra one if (leftOver > 0) { trackObjects++; leftOver--; } - + retVal.add(trackObjects); } - + // don't always front-load extra objects - Collections.shuffle(retVal); + Collections.shuffle(retVal); return retVal; } - + /** * Worker function that takes a trackstate and plops down the given number of facilities owned by the given faction * Avoids places with existing facilities and scenarios, capable of taking facility sub set and setting strategic objective flag. */ - private static void initializeTrackFacilities(StratconTrackState trackState, int numFacilities, + private static void initializeTrackFacilities(StratconTrackState trackState, int numFacilities, ForceAlignment owner, boolean strategicObjective) { - + int trackSize = trackState.getWidth() * trackState.getHeight(); - + for (int fCount = 0; fCount < numFacilities; fCount++) { // if there's no possible empty places to put down a new scenario, then move on - if ((trackState.getFacilities().size() + trackState.getScenarios().size()) >= trackSize) { + if ((trackState.getFacilities().size() + trackState.getScenarios().size()) >= trackSize) { break; } - + StratconFacility sf = owner == ForceAlignment.Allied ? StratconFacilityFactory.getRandomAlliedFacility() : StratconFacilityFactory.getRandomHostileFacility(); - + sf.setOwner(owner); sf.setStrategicObjective(strategicObjective); - + StratconCoords coords = getUnoccupiedCoords(trackState); - + trackState.addFacility(coords, sf); if (sf.getOwner() == ForceAlignment.Allied) { trackState.getRevealedCoords().add(coords); @@ -234,59 +234,59 @@ private static void initializeTrackFacilities(StratconTrackState trackState, int } } } - + /** * Worker function that takes a trackstate and plops down the given number of facilities owned by the given faction */ - private static void initializeObjectiveScenarios(Campaign campaign, AtBContract contract, StratconTrackState trackState, + private static void initializeObjectiveScenarios(Campaign campaign, AtBContract contract, StratconTrackState trackState, int numScenarios, List objectiveScenarios, List objectiveModifiers) { // pick scenario from subset // place it on the map somewhere nothing else has been placed yet // if it's a facility scenario, place the facility // run generateScenario() to apply all the necessary mods // apply objective mods (?) - + int trackSize = trackState.getWidth() * trackState.getHeight(); - + for (int sCount = 0; sCount < numScenarios; sCount++) { // if there's no possible empty places to put down a new scenario, then move on - if ((trackState.getFacilities().size() + trackState.getScenarios().size()) >= trackSize) { + if ((trackState.getFacilities().size() + trackState.getScenarios().size()) >= trackSize) { break; } - + // pick ScenarioTemplate template = StratconScenarioFactory.getSpecificScenario( objectiveScenarios.get(Compute.randomInt(objectiveScenarios.size()))); - + StratconCoords coords = getUnoccupiedCoords(trackState); - + // facility if (template.isFacilityScenario()) { StratconFacility facility = template.isHostileFacility() ? StratconFacilityFactory.getRandomHostileFacility() : StratconFacilityFactory.getRandomAlliedFacility(); trackState.addFacility(coords, facility); } - + // create scenario - don't assign a force yet StratconScenario scenario = StratconRulesManager.generateScenario(campaign, contract, trackState, Force.FORCE_NONE, coords, template); - + // clear dates, because we don't want the scenario disappearing on us scenario.setDeploymentDate(null); scenario.setActionDate(null); scenario.setReturnDate(null); scenario.setStrategicObjective(true); - + // apply objective mods if (objectiveModifiers != null) { for (String modifier : objectiveModifiers) { scenario.getBackingScenario().addScenarioModifier(AtBScenarioModifier.getScenarioModifier(modifier)); } } - + trackState.addScenario(scenario); } } - + /** * Utility function that, given a track state, picks a random set of unoccupied coordinates. */ @@ -295,7 +295,7 @@ private static StratconCoords getUnoccupiedCoords(StratconTrackState trackState) int x = Compute.randomInt(trackState.getWidth()); int y = Compute.randomInt(trackState.getHeight()); StratconCoords coords = new StratconCoords(x, y); - + // make sure we don't put the facility down on top of anything else while ((trackState.getFacility(coords) != null) || (trackState.getScenario(coords) != null)) { @@ -303,23 +303,23 @@ private static StratconCoords getUnoccupiedCoords(StratconTrackState trackState) y = Compute.randomInt(trackState.getHeight()); coords = new StratconCoords(x, y); } - + return coords; } - + /** * Generates additional instructional text based on the contract command rights */ - private static String generateCommandLevelText(AtBContract contract) { + private static String generateCommandLevelText(final AtBContract contract) { switch (contract.getCommandRights()) { - case AtBContract.COM_INTEGRATED: + case INTEGRATED: return "Lance assignments will be made by the employer. " - + "Complete required scenarios to fulfill contract conditions."; - case AtBContract.COM_HOUSE: + + "Complete required scenarios to fulfill contract conditions."; + case HOUSE: return "Complete required scenarios to fulfill contract conditions."; - case AtBContract.COM_LIAISON: + case LIAISON: return "Complete required scenarios and strategic objectives to fulfill contract conditions."; - case AtBContract.COM_INDEP: + case INDEPENDENT: return "Complete strategic objectives to fulfill contract conditions."; default: return ""; @@ -339,11 +339,11 @@ public static void restoreTransientStratconInformation(Mission m, Campaign campa for (StratconTrackState track : atbContract.getStratconCampaignState().getTracks()) { for (StratconScenario scenario : track.getScenarios().values()) { Scenario campaignScenario = campaign.getScenario(scenario.getBackingScenarioID()); - - if ((campaignScenario != null) && (campaignScenario instanceof AtBDynamicScenario)) { + + if ((campaignScenario instanceof AtBDynamicScenario)) { scenario.setBackingScenario((AtBDynamicScenario) campaignScenario); } else { - MekHQ.getLogger().warning(String.format("Unable to set backing scenario for stratcon scenario in track %s ID %d", + MekHQ.getLogger().warning(String.format("Unable to set backing scenario for stratcon scenario in track %s ID %d", track.getDisplayableName(), scenario.getBackingScenarioID())); } } diff --git a/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java b/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java index a26472a879..d3d4721f19 100644 --- a/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java +++ b/MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java @@ -91,7 +91,7 @@ public enum ReinforcementEligibilityType { public static void generateScenariosForTrack(Campaign campaign, AtBContract contract, StratconTrackState track) { // maps scenarios to force IDs List generatedScenarios = new ArrayList<>(); - boolean autoAssignLances = contract.getCommandRights() == AtBContract.COM_INTEGRATED; + final boolean autoAssignLances = contract.getCommandRights().isIntegrated(); // get this list just so we have it available List availableForceIDs = getAvailableForceIDs(campaign); @@ -158,7 +158,7 @@ public static void generateScenariosForTrack(Campaign campaign, AtBContract cont // if under liaison command, pick a random scenario from the ones generated // to set as required and attach liaison - if (contract.getCommandRights() == AtBContract.COM_LIAISON) { + if (contract.getCommandRights().isLiaison()) { StratconScenario randomScenario = Utilities.getRandomItem(generatedScenarios); randomScenario.setRequiredScenario(true); setAttachedUnitsModifier(randomScenario, contract); @@ -613,8 +613,7 @@ static StratconScenario generateScenario(Campaign campaign, AtBContract contract applyFacilityModifiers(scenario, track, coords); applyGlobalModifiers(scenario, contract.getStratconCampaignState()); - if ((contract.getCommandRights() == AtBContract.COM_HOUSE) - || (contract.getCommandRights() == AtBContract.COM_INTEGRATED)) { + if (contract.getCommandRights().isHouse() || contract.getCommandRights().isIntegrated()) { scenario.setRequiredScenario(true); } @@ -700,15 +699,17 @@ private static void setAlliedForceModifier(StratconScenario scenario, AtBContrac alliedUnitOdds = 50; } else { switch (contract.getCommandRights()) { - case AtBContract.COM_INTEGRATED: + case INTEGRATED: alliedUnitOdds = 50; break; - case AtBContract.COM_HOUSE: + case HOUSE: alliedUnitOdds = 30; break; - case AtBContract.COM_LIAISON: + case LIAISON: alliedUnitOdds = 10; break; + default: + break; } } @@ -753,23 +754,25 @@ public static void setAttachedUnitsModifier(StratconScenario scenario, AtBContra // if we're under non-independent command rights, a supervisor may come along switch (contract.getCommandRights()) { - case AtBContract.COM_INTEGRATED: + case INTEGRATED: backingScenario.addScenarioModifier(AtBScenarioModifier .getScenarioModifier(airBattle ? MekHqConstants.SCENARIO_MODIFIER_INTEGRATED_UNITS_AIR : MekHqConstants.SCENARIO_MODIFIER_INTEGRATED_UNITS_GROUND)); break; - case AtBContract.COM_HOUSE: + case HOUSE: backingScenario.addScenarioModifier( AtBScenarioModifier.getScenarioModifier(airBattle ? MekHqConstants.SCENARIO_MODIFIER_HOUSE_CO_AIR : MekHqConstants.SCENARIO_MODIFIER_HOUSE_CO_GROUND)); break; - case AtBContract.COM_LIAISON: + case LIAISON: if (scenario.isRequiredScenario()) { backingScenario.addScenarioModifier( AtBScenarioModifier.getScenarioModifier(airBattle ? MekHqConstants.SCENARIO_MODIFIER_LIAISON_AIR : MekHqConstants.SCENARIO_MODIFIER_LIAISON_GROUND)); } break; + default: + break; } } @@ -967,11 +970,11 @@ public static List getEligibleLeadershipUnits(Campaign campaign, Set forceIDs) int unitType = unit.getEntity().getUnitType(); - unitTypeBuckets.merge(unitType, 1, (oldCount, value) -> oldCount + value); + unitTypeBuckets.merge(unitType, 1, Integer::sum); if (unitTypeBuckets.get(unitType) > biggestBucketCount) { biggestBucketCount = unitTypeBuckets.get(unitType); @@ -1221,16 +1224,16 @@ public static void processScenarioCompletion(ResolveScenarioTracker rst) { } } } - + /** * Contains logic for what should happen when a facility gets captured: * modifier/type/alignment switches etc. */ private static void switchFacilityOwner(StratconFacility facility) { if ((facility.getCapturedDefinition() != null) && !facility.getCapturedDefinition().isBlank()) { - StratconFacility newOwnerData = + StratconFacility newOwnerData = StratconFacilityFactory.getFacilityByName(facility.getCapturedDefinition()); - + if (newOwnerData != null) { // for now, we only need to change a limited subset of the captured facility's data // the rest can be retained; we may revisit this assumption later @@ -1238,11 +1241,11 @@ private static void switchFacilityOwner(StratconFacility facility) { facility.setLocalModifiers(new ArrayList<>(newOwnerData.getLocalModifiers())); facility.setSharedModifiers(new ArrayList<>(newOwnerData.getSharedModifiers())); facility.setOwner(newOwnerData.getOwner()); - + return; } } - + // if we the facility didn't have any data defined for what happens when it's captured // fall back to the default of just switching the owner if (facility.getOwner() == ForceAlignment.Allied) { diff --git a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java index 8380dcd4a0..0b72ea809b 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewAtBContractDialog.java @@ -516,7 +516,7 @@ protected void btnOKActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnHireA contract.setEmployerCode(getCurrentEmployerCode(), campaign.getGameYear()); contract.setMissionType(cbMissionType.getSelectedIndex()); contract.setDesc(txtDesc.getText()); - contract.setCommandRights(choiceCommand.getSelectedIndex()); + contract.setCommandRights(choiceCommand.getSelectedItem()); contract.setEnemyCode(getCurrentEnemyCode()); contract.setAllySkill(cbAllySkill.getSelectedIndex()); diff --git a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java index 81fc0a5a69..9063113891 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java @@ -20,7 +20,7 @@ */ package mekhq.gui.dialog; -import java.awt.Dimension; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; @@ -31,12 +31,14 @@ import javax.swing.*; import javax.swing.event.ChangeListener; +import megamek.client.ui.baseComponents.MMComboBox; import megamek.common.util.EncodeControl; import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.finances.Transaction; import mekhq.campaign.mission.Contract; import mekhq.campaign.mission.Mission; +import mekhq.campaign.mission.enums.ContractCommandRights; import mekhq.campaign.personnel.Person; import mekhq.campaign.personnel.SkillType; import megamek.client.ui.preferences.JWindowPreference; @@ -49,13 +51,35 @@ /** * @author Taharqa */ -public class NewContractDialog extends javax.swing.JDialog { +public class NewContractDialog extends JDialog { private static final long serialVersionUID = -8038099101234445018L; protected JFrame frame; protected Contract contract; protected Campaign campaign; private JComboBox cboNegotiator; + protected JButton btnClose; + protected JButton btnOK; + protected JTextField txtName; + protected JTextField txtEmployer; + protected JTextField txtType; + protected MarkdownEditorPanel txtDesc; + protected JSuggestField suggestPlanet; + + protected JButton btnDate; + protected JComboBox choiceOverhead; + protected MMComboBox choiceCommand; + protected JSpinner spnLength; + protected JSpinner spnMultiplier; + protected JSpinner spnTransport; + protected JSpinner spnSalvageRights; + protected JCheckBox checkSalvageExchange; + protected JSpinner spnStraightSupport; + protected JSpinner spnBattleLossComp; + protected JSpinner spnSignBonus; + protected JSpinner spnAdvance; + protected JCheckBox checkMRBC; + private ContractPaymentBreakdown contractPaymentBreakdown; /** Creates new form NewTeamDialog */ @@ -364,12 +388,20 @@ protected void initContractPanel(ResourceBundle resourceMap, JPanel contractPane choiceOverhead.addActionListener(contractUpdateActionListener); choiceOverhead.addFocusListener(contractUpdateFocusListener); - DefaultComboBoxModel commandModel = new DefaultComboBoxModel<>(); - for (int i = 0; i < Contract.COM_NUM; i++) { - commandModel.addElement(Contract.getCommandRightsName(i)); - } - choiceCommand = new JComboBox<>(commandModel); - choiceCommand.setSelectedIndex(contract.getCommandRights()); + choiceCommand = new MMComboBox<>("choiceCommand", ContractCommandRights.values()); + choiceCommand.setSelectedItem(contract.getCommandRights()); + choiceCommand.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(final JList list, final Object value, + final int index, final boolean isSelected, + final boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof ContractCommandRights) { + list.setToolTipText(((ContractCommandRights) value).getToolTipText()); + } + return this; + } + }); choiceCommand.addActionListener(contractUpdateActionListener); spnTransport = new JSpinner(new SpinnerNumberModel(contract.getTransportComp(), 0, 100, 10)); @@ -647,10 +679,10 @@ protected void btnOKActionPerformed(ActionEvent evt) { contract.setEmployer(txtEmployer.getText()); contract.setType(txtType.getText()); contract.setDesc(txtDesc.getText()); - contract.setCommandRights(choiceCommand.getSelectedIndex()); + contract.setCommandRights(choiceCommand.getSelectedItem()); campaign.getFinances().credit(contract.getTotalAdvanceAmount(), Transaction.C_CONTRACT, "Advance monies for " + contract.getName(), campaign.getLocalDate()); - + campaign.addMission(contract); // Negotiator XP @@ -707,28 +739,6 @@ private void btnCloseActionPerformed(ActionEvent evt) { setVisible(false); } - protected javax.swing.JButton btnClose; - protected javax.swing.JButton btnOK; - protected javax.swing.JTextField txtName; - protected javax.swing.JTextField txtEmployer; - protected javax.swing.JTextField txtType; - protected MarkdownEditorPanel txtDesc; - protected JSuggestField suggestPlanet; - - protected javax.swing.JButton btnDate; - protected JComboBox choiceOverhead; - protected JComboBox choiceCommand; - protected JSpinner spnLength; - protected JSpinner spnMultiplier; - protected JSpinner spnTransport; - protected JSpinner spnSalvageRights; - protected JCheckBox checkSalvageExchange; - protected JSpinner spnStraightSupport; - protected JSpinner spnBattleLossComp; - protected JSpinner spnSignBonus; - protected JSpinner spnAdvance; - protected JCheckBox checkMRBC; - protected FocusListener contractUpdateFocusListener = new FocusListener() { @Override public void focusGained(FocusEvent e) { @@ -756,7 +766,7 @@ protected void doUpdateContract(Object source) { } else if (choiceOverhead.equals(source)) { contract.setOverheadComp(choiceOverhead.getSelectedIndex()); } else if (choiceCommand.equals(source)) { - contract.setCommandRights(choiceCommand.getSelectedIndex()); + contract.setCommandRights(choiceCommand.getSelectedItem()); } else if (checkMRBC.equals(source)) { contract.setMRBCFee(checkMRBC.isSelected()); } else if (checkSalvageExchange.equals(source)) { diff --git a/MekHQ/src/mekhq/gui/view/ContractSummaryPanel.java b/MekHQ/src/mekhq/gui/view/ContractSummaryPanel.java index d4b083333a..a13429cb07 100644 --- a/MekHQ/src/mekhq/gui/view/ContractSummaryPanel.java +++ b/MekHQ/src/mekhq/gui/view/ContractSummaryPanel.java @@ -297,7 +297,8 @@ public void mouseClicked(MouseEvent e) { gridBagConstraintsLabels.gridy = ++y; mainPanel.add(lblCommand, gridBagConstraintsLabels); - txtCommand = new JLabel(Contract.getCommandRightsName(contract.getCommandRights())); + txtCommand = new JLabel(contract.getCommandRights().toString()); + txtCommand.setToolTipText(contract.getCommandRights().getToolTipText()); txtCommand.setName("txtCommand"); // Then we determine if we just add it to the main panel, or if we combine it with a button @@ -326,7 +327,8 @@ public void mouseClicked(MouseEvent e) { campaign.getContractMarket().rerollClause((AtBContract) contract, ContractMarket.CLAUSE_COMMAND, campaign); setCommandRerollButtonText((JButton) ev.getSource()); - txtCommand.setText(Contract.getCommandRightsName(contract.getCommandRights())); + txtCommand.setText(contract.getCommandRights().toString()); + txtCommand.setToolTipText(contract.getCommandRights().getToolTipText()); if (campaign.getContractMarket().getRerollsUsed(contract, ContractMarket.CLAUSE_COMMAND) >= cmdRerolls) { btn.setEnabled(false); diff --git a/MekHQ/src/mekhq/gui/view/MissionViewPanel.java b/MekHQ/src/mekhq/gui/view/MissionViewPanel.java index 27e12624e1..8a60927e97 100644 --- a/MekHQ/src/mekhq/gui/view/MissionViewPanel.java +++ b/MekHQ/src/mekhq/gui/view/MissionViewPanel.java @@ -427,8 +427,9 @@ public void mouseClicked(MouseEvent e) { gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; pnlStats.add(lblCommand, gridBagConstraints); - txtCommand.setName("txtCommand"); // NOI18N - txtCommand.setText(Contract.getCommandRightsName(contract.getCommandRights())); + txtCommand.setName("txtCommand"); + txtCommand.setText(contract.getCommandRights().toString()); + txtCommand.setToolTipText(contract.getCommandRights().getToolTipText()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 7; @@ -817,8 +818,9 @@ public void mouseClicked(MouseEvent e) { gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; pnlStats.add(lblCommand, gridBagConstraints); - txtCommand.setName("txtCommand"); // NOI18N - txtCommand.setText(Contract.getCommandRightsName(contract.getCommandRights())); + txtCommand.setName("txtCommand"); + txtCommand.setText(contract.getCommandRights().toString()); + txtCommand.setToolTipText(contract.getCommandRights().getToolTipText()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = y++; From f7a3125c34ee959092b84d1791494b990f33134c Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Mon, 17 May 2021 11:22:35 -0400 Subject: [PATCH 2/3] Moving StratCon command text into the enum --- .../mekhq/resources/Mission.properties | 4 ++++ .../mission/enums/ContractCommandRights.java | 16 +++++++++----- .../stratcon/StratconContractInitializer.java | 21 +------------------ 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/Mission.properties b/MekHQ/resources/mekhq/resources/Mission.properties index 6132a41562..32719f187e 100644 --- a/MekHQ/resources/mekhq/resources/Mission.properties +++ b/MekHQ/resources/mekhq/resources/Mission.properties @@ -6,12 +6,16 @@ # ContractCommandRights Enum ContractCommandRights.INTEGRATED.text=Integrated ContractCommandRights.INTEGRATED.toolTipText=The force's command positions are largely filled by officers provided by the employer.
By doing so the employer takes on full legal responsibility for the actions of the force, provided that the force does not willfully disobey the orders of the officer in the legally questionable action or actions.
This is normally used when hiring mercenaries to bolster the employer's forces before a large assault or raid.
This is the standard for government forces and is widely avoided by all other forces. +ContractCommandRights.INTEGRATED.stratConText=Lance assignments will be made by the employer. Complete required scenarios to fulfill contract conditions. ContractCommandRights.HOUSE.text=House ContractCommandRights.HOUSE.toolTipText=The force is placed under the direct authority of an employer-provided military officer. This officer may dictate tactics and strategies to the force, but the force otherwise retains its command structure.
By doing so the employer takes on full legal responsibility for the actions of the force, provided that the force does not willfully disobey the orders of the officer in the legally questionable action or actions.
This may be required by the employer for closely coordinated raids, planetary assaults, and garrison duties, as this allows the government to ensure the force is properly deployed within the larger battle plan. +ContractCommandRights.HOUSE.stratConText=Complete required scenarios to fulfill contract conditions. ContractCommandRights.LIAISON.text=Liaison ContractCommandRights.LIAISON.toolTipText=The force has an employer-provided liaison that both represents the employer and accompanies the force during the contract.
By doing so the employer takes on limited legal responsibility for the actions of the force, as their decisions are being monitored by the liaison. +ContractCommandRights.LIAISON.stratConText=Complete required scenarios and strategic objectives to fulfill contract conditions. ContractCommandRights.INDEPENDENT.text=Independent ContractCommandRights.INDEPENDENT.toolTipText=The force has full battlefield autonomy, with no interference from their employer. However, the employer will provide limited if any support to the force.
The force is still bound to answer for any questionable actions they take to their employer and/or an outside authority/arbitrator (e.g. the Mercenary Review and Bonding Commission) following the contract.
Employers may, especially for covert missions, sign contracts with independent command rights to shield them from legal responsibility from the force's actions while undertaking the contract.
This is the standard for pirate contracts. +ContractCommandRights.INDEPENDENT.stratConText=Complete strategic objectives to fulfill contract conditions. # MissionStatus Enum MissionStatus.ACTIVE.text=Active diff --git a/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java b/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java index fd8e5d8d73..8f7afc117e 100644 --- a/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java +++ b/MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java @@ -25,23 +25,25 @@ public enum ContractCommandRights { //region Enum Declarations - INTEGRATED("ContractCommandRights.INTEGRATED.text", "ContractCommandRights.INTEGRATED.toolTipText"), - HOUSE("ContractCommandRights.HOUSE.text", "ContractCommandRights.HOUSE.toolTipText"), - LIAISON("ContractCommandRights.LIAISON.text", "ContractCommandRights.LIAISON.toolTipText"), - INDEPENDENT("ContractCommandRights.INDEPENDENT.text", "ContractCommandRights.INDEPENDENT.toolTipText"); + INTEGRATED("ContractCommandRights.INTEGRATED.text", "ContractCommandRights.INTEGRATED.toolTipText", "ContractCommandRights.INTEGRATED.stratConText"), + HOUSE("ContractCommandRights.HOUSE.text", "ContractCommandRights.HOUSE.toolTipText", "ContractCommandRights.HOUSE.stratConText"), + LIAISON("ContractCommandRights.LIAISON.text", "ContractCommandRights.LIAISON.toolTipText", "ContractCommandRights.LIAISON.stratConText"), + INDEPENDENT("ContractCommandRights.INDEPENDENT.text", "ContractCommandRights.INDEPENDENT.toolTipText", "ContractCommandRights.INDEPENDENT.stratConText"); //endregion Enum Declarations //region Variable Declarations private final String name; private final String toolTipText; + private final String stratConText; private final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.Mission", new EncodeControl()); //endregion Variable Declarations //region Constructors - ContractCommandRights(final String name, final String toolTipText) { + ContractCommandRights(final String name, final String toolTipText, final String stratConText) { this.name = resources.getString(name); this.toolTipText = resources.getString(toolTipText); + this.stratConText = resources.getString(stratConText); } //endregion Constructors @@ -49,6 +51,10 @@ public enum ContractCommandRights { public String getToolTipText() { return toolTipText; } + + public String getStratConText() { + return stratConText; + } //endregion Getters //region Boolean Comparison Methods diff --git a/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java b/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java index 849c3d03dc..d5353abf21 100644 --- a/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java +++ b/MekHQ/src/mekhq/campaign/stratcon/StratconContractInitializer.java @@ -47,7 +47,7 @@ public class StratconContractInitializer { */ public static void initializeCampaignState(AtBContract contract, Campaign campaign, StratconContractDefinition contractDefinition) { StratconCampaignState campaignState = new StratconCampaignState(contract); - campaignState.setBriefingText(contractDefinition.getBriefing() + "
" + generateCommandLevelText(contract)); + campaignState.setBriefingText(contractDefinition.getBriefing() + "
" + contract.getCommandRights().getStratConText()); campaignState.setStrategicObjectivesBehaveAsVPs(contractDefinition.objectivesBehaveAsVPs()); // dependency: this is required here in order for scenario initialization to work properly @@ -307,25 +307,6 @@ private static StratconCoords getUnoccupiedCoords(StratconTrackState trackState) return coords; } - /** - * Generates additional instructional text based on the contract command rights - */ - private static String generateCommandLevelText(final AtBContract contract) { - switch (contract.getCommandRights()) { - case INTEGRATED: - return "Lance assignments will be made by the employer. " - + "Complete required scenarios to fulfill contract conditions."; - case HOUSE: - return "Complete required scenarios to fulfill contract conditions."; - case LIAISON: - return "Complete required scenarios and strategic objectives to fulfill contract conditions."; - case INDEPENDENT: - return "Complete strategic objectives to fulfill contract conditions."; - default: - return ""; - } - } - /** * Given a mission (that's an AtB contract), restore track state information, * such as pointers from StratCon scenario objects to AtB scenario objects. From b0d67cee2cfad000c38021db66e3793152bbfa02 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Mon, 17 May 2021 11:26:19 -0400 Subject: [PATCH 3/3] Fixing tab spacing --- .../mekhq/gui/dialog/NewContractDialog.java | 170 +++++++++--------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java index 9063113891..013b97ebc3 100644 --- a/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/NewContractDialog.java @@ -52,7 +52,7 @@ * @author Taharqa */ public class NewContractDialog extends JDialog { - private static final long serialVersionUID = -8038099101234445018L; + private static final long serialVersionUID = -8038099101234445018L; protected JFrame frame; protected Contract contract; protected Campaign campaign; @@ -95,7 +95,7 @@ public NewContractDialog(JFrame parent, boolean modal, Campaign c) { } protected void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; + java.awt.GridBagConstraints gridBagConstraints; ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.NewContractDialog", new EncodeControl()); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -105,8 +105,8 @@ protected void initComponents() { JPanel newContractPanel = new JPanel(new java.awt.GridBagLayout()); JPanel descPanel = new JPanel(); - descPanel.setLayout(new java.awt.GridBagLayout()); - gridBagConstraints = new java.awt.GridBagConstraints(); + descPanel.setLayout(new java.awt.GridBagLayout()); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.weightx = 1.0; @@ -118,11 +118,11 @@ protected void initComponents() { newContractPanel.add(descPanel, gridBagConstraints); JPanel contractPanel = new JPanel(); - contractPanel.setLayout(new java.awt.GridBagLayout()); - contractPanel.setBorder(BorderFactory.createCompoundBorder( + contractPanel.setLayout(new java.awt.GridBagLayout()); + contractPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("contractPanel.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.weightx = 1.0; @@ -133,11 +133,11 @@ protected void initComponents() { newContractPanel.add(contractPanel, gridBagConstraints); JPanel totalsPanel = new JPanel(); - totalsPanel.setLayout(new java.awt.GridBagLayout()); - totalsPanel.setBorder(BorderFactory.createCompoundBorder( + totalsPanel.setLayout(new java.awt.GridBagLayout()); + totalsPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(resourceMap.getString("totalsPanel.title")), BorderFactory.createEmptyBorder(5, 5, 5, 5))); - gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.weightx = 1.0; @@ -189,9 +189,9 @@ private void setUserPreferences() { preferences.manage(new JWindowPreference(this)); } - protected void initDescPanel(ResourceBundle resourceMap, JPanel descPanel) { - java.awt.GridBagConstraints gridBagConstraints; - txtName = new javax.swing.JTextField(); + protected void initDescPanel(ResourceBundle resourceMap, JPanel descPanel) { + java.awt.GridBagConstraints gridBagConstraints; + txtName = new javax.swing.JTextField(); JLabel lblName = new JLabel(); txtEmployer = new javax.swing.JTextField(); JLabel lblEmployer = new JLabel(); @@ -236,15 +236,15 @@ protected void initDescPanel(ResourceBundle resourceMap, JPanel descPanel) { suggestPlanet = new JSuggestField(this, campaign.getSystemNames()); /*suggestPlanet.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - contract.setPlanetName(suggestPlanet.getText()); - //reset the start date so this can be recalculated - contract.setStartDate(campaign.getDate()); - contract.calculateContract(campaign); - btnDate.setText(dateFormatter.format(contract.getStartDate())); - refreshTotals(); - } - });*/ + public void actionPerformed(java.awt.event.ActionEvent evt) { + contract.setPlanetName(suggestPlanet.getText()); + //reset the start date so this can be recalculated + contract.setStartDate(campaign.getDate()); + contract.calculateContract(campaign); + btnDate.setText(dateFormatter.format(contract.getStartDate())); + refreshTotals(); + } + });*/ suggestPlanet.addFocusListener(contractUpdateFocusListener); suggestPlanet.addActionListener(contractUpdateActionListener); @@ -338,16 +338,16 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); descPanel.add(txtDesc, gridBagConstraints); - } + } - protected void initPaymentBreakdownPanel(JPanel totalsPanel) { + protected void initPaymentBreakdownPanel(JPanel totalsPanel) { contractPaymentBreakdown = new ContractPaymentBreakdown(totalsPanel, contract, campaign); contractPaymentBreakdown.display(0, 1); - } + } - protected void initContractPanel(ResourceBundle resourceMap, JPanel contractPanel) { - java.awt.GridBagConstraints gridBagConstraints; - JLabel lblDate = new JLabel(resourceMap.getString("lblDate.text")); + protected void initContractPanel(ResourceBundle resourceMap, JPanel contractPanel) { + java.awt.GridBagConstraints gridBagConstraints; + JLabel lblDate = new JLabel(resourceMap.getString("lblDate.text")); JLabel lblLength = new JLabel(resourceMap.getString("lblLength.text")); JLabel lblMultiplier = new JLabel(resourceMap.getString("lblMultiplier.text")); JLabel lblOverhead = new JLabel(resourceMap.getString("lblOverhead.text")); @@ -380,16 +380,16 @@ protected void initContractPanel(ResourceBundle resourceMap, JPanel contractPane spnMultiplier.addChangeListener(contractUpdateChangeListener); DefaultComboBoxModel overheadModel = new DefaultComboBoxModel<>(); - for (int i = 0; i < Contract.OH_NUM; i++) { - overheadModel.addElement(Contract.getOverheadCompName(i)); - } - choiceOverhead = new JComboBox<>(overheadModel); - choiceOverhead.setSelectedIndex(contract.getOverheadComp()); + for (int i = 0; i < Contract.OH_NUM; i++) { + overheadModel.addElement(Contract.getOverheadCompName(i)); + } + choiceOverhead = new JComboBox<>(overheadModel); + choiceOverhead.setSelectedIndex(contract.getOverheadComp()); choiceOverhead.addActionListener(contractUpdateActionListener); choiceOverhead.addFocusListener(contractUpdateFocusListener); - choiceCommand = new MMComboBox<>("choiceCommand", ContractCommandRights.values()); - choiceCommand.setSelectedItem(contract.getCommandRights()); + choiceCommand = new MMComboBox<>("choiceCommand", ContractCommandRights.values()); + choiceCommand.setSelectedItem(contract.getCommandRights()); choiceCommand.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(final JList list, final Object value, @@ -402,13 +402,13 @@ public Component getListCellRendererComponent(final JList list, final Object return this; } }); - choiceCommand.addActionListener(contractUpdateActionListener); + choiceCommand.addActionListener(contractUpdateActionListener); - spnTransport = new JSpinner(new SpinnerNumberModel(contract.getTransportComp(), 0, 100, 10)); - spnTransport.addChangeListener(contractUpdateChangeListener); + spnTransport = new JSpinner(new SpinnerNumberModel(contract.getTransportComp(), 0, 100, 10)); + spnTransport.addChangeListener(contractUpdateChangeListener); - spnSalvageRights = new JSpinner(new SpinnerNumberModel(contract.getSalvagePct(), 0, 100, 10)); - spnSalvageRights.addChangeListener(contractUpdateChangeListener); + spnSalvageRights = new JSpinner(new SpinnerNumberModel(contract.getSalvagePct(), 0, 100, 10)); + spnSalvageRights.addChangeListener(contractUpdateChangeListener); spnStraightSupport = new JSpinner(new SpinnerNumberModel(contract.getStraightSupport(), 0, 100, 10)); spnStraightSupport.addChangeListener(contractUpdateChangeListener); @@ -656,7 +656,7 @@ public Component getListCellRendererComponent(final JList list, final Object gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); contractPanel.add(spnAdvance, gridBagConstraints); - } + } protected void btnOKActionPerformed(ActionEvent evt) { if (!btnOK.equals(evt.getSource())) { @@ -664,34 +664,34 @@ protected void btnOKActionPerformed(ActionEvent evt) { } String chosenName = txtName.getText(); - for (Mission m : campaign.getMissions()) { - if (m.getName().equals(chosenName)) { - JOptionPane.showMessageDialog(frame, + for (Mission m : campaign.getMissions()) { + if (m.getName().equals(chosenName)) { + JOptionPane.showMessageDialog(frame, "There is already a mission with the name " + chosenName, - "Duplicate Mission Name", - JOptionPane.ERROR_MESSAGE); - return; - } - } - - contract.setName(txtName.getText()); - //contract.setPlanetName(suggestPlanet.getText()); - contract.setEmployer(txtEmployer.getText()); - contract.setType(txtType.getText()); - contract.setDesc(txtDesc.getText()); - contract.setCommandRights(choiceCommand.getSelectedItem()); - campaign.getFinances().credit(contract.getTotalAdvanceAmount(), Transaction.C_CONTRACT, + "Duplicate Mission Name", + JOptionPane.ERROR_MESSAGE); + return; + } + } + + contract.setName(txtName.getText()); + //contract.setPlanetName(suggestPlanet.getText()); + contract.setEmployer(txtEmployer.getText()); + contract.setType(txtType.getText()); + contract.setDesc(txtDesc.getText()); + contract.setCommandRights(choiceCommand.getSelectedItem()); + campaign.getFinances().credit(contract.getTotalAdvanceAmount(), Transaction.C_CONTRACT, "Advance monies for " + contract.getName(), campaign.getLocalDate()); - campaign.addMission(contract); + campaign.addMission(contract); - // Negotiator XP - Person negotiator = (Person) cboNegotiator.getSelectedItem(); - if ((negotiator != null) && (campaign.getCampaignOptions().getContractNegotiationXP() > 0)) { - negotiator.awardXP(campaign.getCampaignOptions().getContractNegotiationXP()); - } + // Negotiator XP + Person negotiator = (Person) cboNegotiator.getSelectedItem(); + if ((negotiator != null) && (campaign.getCampaignOptions().getContractNegotiationXP() > 0)) { + negotiator.awardXP(campaign.getCampaignOptions().getContractNegotiationXP()); + } - this.setVisible(false); + this.setVisible(false); } private void changeStartDate() { @@ -699,13 +699,13 @@ private void changeStartDate() { DateChooser dc = new DateChooser(frame, contract.getStartDate()); // user can either choose a date or cancel by closing if (dc.showDateChooser() == DateChooser.OK_OPTION) { - if (campaign.getLocalDate().isAfter(dc.getDate())) { - JOptionPane.showMessageDialog(frame, - "You cannot choose a start date before the current date.", - "Invalid date", - JOptionPane.ERROR_MESSAGE); - return; - } + if (campaign.getLocalDate().isAfter(dc.getDate())) { + JOptionPane.showMessageDialog(frame, + "You cannot choose a start date before the current date.", + "Invalid date", + JOptionPane.ERROR_MESSAGE); + return; + } contract.setStartDate(dc.getDate()); contract.calculateContract(campaign); btnDate.setText(MekHQ.getMekHQOptions().getDisplayFormattedDate(contract.getStartDate())); @@ -713,30 +713,30 @@ private void changeStartDate() { } public int getContractId() { - return contract.getId(); + return contract.getId(); } /* private void refreshTotals() { - lblBaseAmount2.setText(formatter.format(contract.getBaseAmount())); - lblOverheadAmount2.setText("+" + formatter.format(contract.getOverheadAmount())); - lblSupportAmount2.setText("+" + formatter.format(contract.getSupportAmount())); - lblTransitAmount2.setText("+" + formatter.format(contract.getTransitAmount())); - lblTransportAmount2.setText("+" + formatter.format(contract.getTransportAmount())); - lblTotalAmount2.setText(formatter.format(contract.getTotalAmount())); - lblSignBonusAmount2.setText("+" + formatter.format(contract.getSigningBonusAmount())); - lblFeeAmount2.setText("-" + formatter.format(contract.getFeeAmount())); - lblTotalAmountPlus2.setText(formatter.format(contract.getTotalAmountPlusFeesAndBonuses())); - lblAdvanceMoney2.setText(formatter.format(contract.getTotalAdvanceAmount())); - lblMonthlyAmount2.setText(formatter.format(contract.getMonthlyPayOut())); - lblProfit2.setText(formatter.format(contract.getEstimatedTotalProfit(campaign))); + lblBaseAmount2.setText(formatter.format(contract.getBaseAmount())); + lblOverheadAmount2.setText("+" + formatter.format(contract.getOverheadAmount())); + lblSupportAmount2.setText("+" + formatter.format(contract.getSupportAmount())); + lblTransitAmount2.setText("+" + formatter.format(contract.getTransitAmount())); + lblTransportAmount2.setText("+" + formatter.format(contract.getTransportAmount())); + lblTotalAmount2.setText(formatter.format(contract.getTotalAmount())); + lblSignBonusAmount2.setText("+" + formatter.format(contract.getSigningBonusAmount())); + lblFeeAmount2.setText("-" + formatter.format(contract.getFeeAmount())); + lblTotalAmountPlus2.setText(formatter.format(contract.getTotalAmountPlusFeesAndBonuses())); + lblAdvanceMoney2.setText(formatter.format(contract.getTotalAdvanceAmount())); + lblMonthlyAmount2.setText(formatter.format(contract.getMonthlyPayOut())); + lblProfit2.setText(formatter.format(contract.getEstimatedTotalProfit(campaign))); }*/ private void btnCloseActionPerformed(ActionEvent evt) { if (!btnClose.equals(evt.getSource())) { return; } - setVisible(false); + setVisible(false); } protected FocusListener contractUpdateFocusListener = new FocusListener() {