Skip to content

Commit

Permalink
Merge pull request #5732 from IllianiCBT/routedPayouts
Browse files Browse the repository at this point in the history
Fixed Routed Contracts Resulting in Truncated Payouts
  • Loading branch information
HammerGS authored Jan 15, 2025
2 parents b0c3ecb + abe72c0 commit dde6a63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 8 additions & 3 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -7781,10 +7781,15 @@ public void completeMission(@Nullable Mission mission, MissionStatus status) {
// check for money in escrow
// According to FMM(r) pg 179, both failure and breach lead to no
// further payment even though this seems foolish
if ((contract.getStatus().isSuccess())
&& (contract.getMonthsLeft(getLocalDate()) > 0)) {
if (contract.getStatus().isSuccess()) {
remainingMoney = contract.getMonthlyPayOut()
.multipliedBy(contract.getMonthsLeft(getLocalDate()));
.multipliedBy(contract.getMonthsLeft(getLocalDate()));

if (contract instanceof AtBContract) {
Money routedPayout = ((AtBContract) contract).getRoutedPayout();

remainingMoney = routedPayout == null ? remainingMoney : routedPayout;
}
}

// If overage repayment is enabled, we first need to check if the salvage
Expand Down
18 changes: 16 additions & 2 deletions MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import megamek.common.Entity;
import megamek.common.TargetRoll;
import megamek.common.UnitType;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
import megamek.common.enums.SkillLevel;
import megamek.common.icons.Camouflage;
Expand Down Expand Up @@ -162,6 +163,7 @@ public class AtBContract extends Contract {
protected int contractScoreArbitraryModifier;

protected int moraleMod = 0;
private Money routedPayout = null;

/* lasts for a month, then removed at next events roll */
protected boolean priorLogisticsFailure;
Expand Down Expand Up @@ -619,8 +621,10 @@ public void checkMorale(Campaign campaign, LocalDate today) {
if (contractType.isGarrisonType() && !contractType.isRiotDuty()) {
routEnd = today.plusMonths(max(1, d6() - 3)).minusDays(1);
} else {
campaign.addReport("With the enemy routed, any remaining objectives have been successfully completed." +
" The contract will conclude tomorrow.");
campaign.addReport("With the enemy routed, any remaining objectives have been" +
" successfully completed. The contract will conclude tomorrow.");
int remainingMonths = getMonthsLeft(campaign.getLocalDate().plusDays(1));
routedPayout = getMonthlyPayOut().multipliedBy(remainingMonths);
setEndDate(today.plusDays(1));
}
}
Expand Down Expand Up @@ -1134,6 +1138,9 @@ protected int writeToXMLBegin(final PrintWriter pw, int indent) {
if (routEnd != null) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "routEnd", routEnd);
}
if (routedPayout != null) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "routedPayout", routedPayout);
}
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "partsAvailabilityLevel", getPartsAvailabilityLevel());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "extensionLength", extensionLength);
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "sharesPct", sharesPct);
Expand Down Expand Up @@ -1210,6 +1217,9 @@ public void loadFieldsFromXmlNode(Node wn) throws ParseException {
setMoraleLevel(AtBMoraleLevel.parseFromString(wn2.getTextContent().trim()));
} else if (wn2.getNodeName().equalsIgnoreCase("routEnd")) {
routEnd = MHQXMLUtility.parseDate(wn2.getTextContent().trim());
} else if (wn2.getNodeName().equalsIgnoreCase("routedPayout")) {
double value = Double.parseDouble(wn2.getTextContent().trim());
routedPayout = Money.of(value);
} else if (wn2.getNodeName().equalsIgnoreCase("partsAvailabilityLevel")) {
partsAvailabilityLevel = Integer.parseInt(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("extensionLength")) {
Expand Down Expand Up @@ -2158,4 +2168,8 @@ public int getTransportRoll() {
public void setTransportRoll(int roll) {
transportRoll = roll;
}

public @Nullable Money getRoutedPayout() {
return routedPayout;
}
}

0 comments on commit dde6a63

Please sign in to comment.