Skip to content

Commit

Permalink
Merge pull request #2617 from Windchild292/dev_Windchild_ContractComm…
Browse files Browse the repository at this point in the history
…andRightsEnum

Contract Command Rights Enum
  • Loading branch information
Windchild292 authored May 25, 2021
2 parents fe40891 + 618705a commit 07e78ba
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 285 deletions.
14 changes: 14 additions & 0 deletions MekHQ/resources/mekhq/resources/Mission.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
## General Mission Resources

## Enums
# ContractCommandRights Enum
ContractCommandRights.INTEGRATED.text=Integrated
ContractCommandRights.INTEGRATED.toolTipText=<html>The force's command positions are largely filled by officers provided by the employer. <br>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. <br>This is normally used when hiring mercenaries to bolster the employer's forces before a large assault or raid. <br>This is the standard for government forces and is widely avoided by all other forces.</html>
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=<html>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. <br>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. <br>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.</html>
ContractCommandRights.HOUSE.stratConText=Complete required scenarios to fulfill contract conditions.
ContractCommandRights.LIAISON.text=Liaison
ContractCommandRights.LIAISON.toolTipText=<html>The force has an employer-provided liaison that both represents the employer and accompanies the force during the contract. <br>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.</html>
ContractCommandRights.LIAISON.stratConText=Complete required scenarios and strategic objectives to fulfill contract conditions.
ContractCommandRights.INDEPENDENT.text=Independent
ContractCommandRights.INDEPENDENT.toolTipText=<html>The force has full battlefield autonomy, with no interference from their employer. However, the employer will provide limited if any support to the force. <br>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. <br>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. <br>This is the standard for pirate contracts.</html>
ContractCommandRights.INDEPENDENT.stratConText=Complete strategic objectives to fulfill contract conditions.

# MissionStatus Enum
MissionStatus.ACTIVE.text=Active
MissionStatus.ACTIVE.toolTipText=This mission/contract is active, with scenarios still occurring.
Expand Down
23 changes: 14 additions & 9 deletions MekHQ/src/mekhq/campaign/market/ContractMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 19 additions & 13 deletions MekHQ/src/mekhq/campaign/mission/AtBScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
50 changes: 15 additions & 35 deletions MekHQ/src/mekhq/campaign/mission/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")) {
Expand Down
117 changes: 117 additions & 0 deletions MekHQ/src/mekhq/campaign/mission/enums/ContractCommandRights.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
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", "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, final String stratConText) {
this.name = resources.getString(name);
this.toolTipText = resources.getString(toolTipText);
this.stratConText = resources.getString(stratConText);
}
//endregion Constructors

//region Getters
public String getToolTipText() {
return toolTipText;
}

public String getStratConText() {
return stratConText;
}
//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;
}
}
Loading

0 comments on commit 07e78ba

Please sign in to comment.