Skip to content

Commit

Permalink
Merge pull request #2793 from Windchild292/dev_Windchild_TransactionType
Browse files Browse the repository at this point in the history
Transaction Type Enum: Expanded Personnel Transaction Types
  • Loading branch information
Windchild292 authored Aug 24, 2021
2 parents ed447da + 5452dff commit 7120d3b
Show file tree
Hide file tree
Showing 26 changed files with 634 additions and 576 deletions.
54 changes: 54 additions & 0 deletions MekHQ/resources/mekhq/resources/Finances.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,60 @@ FinancialYearDuration.DECENNIAL.toolTipText=The financial year lasts ten years
FinancialYearDuration.FOREVER.text=Forever (Not Recommended)
FinancialYearDuration.FOREVER.toolTipText=The financial year lasts forever. This option is not recommended and can cause issues in lengthy campaigns.

# TransactionType Enum
TransactionType.UNIT_PURCHASE.text=Unit Purchase(s)
TransactionType.UNIT_PURCHASE.toolTipText=A financial transaction where a unit was or multiple units were purchased.
TransactionType.EQUIPMENT_PURCHASE.text=Equipment Purchase(s)
TransactionType.EQUIPMENT_PURCHASE.toolTipText=A financial transaction where some equipment was purchased.
TransactionType.RECRUITMENT.text=Recruitment
TransactionType.RECRUITMENT.toolTipText=A financial transaction where a person was or multiple people were recruited.
TransactionType.SALARIES.text=Salaries
TransactionType.SALARIES.toolTipText=A financial transaction where the salaries of a person or multiple people were paid.
TransactionType.RETIREMENT.text=Retirement
TransactionType.RETIREMENT.toolTipText=A financial transaction where a person or multiple people retired.
TransactionType.OVERHEAD.text=Overhead
TransactionType.OVERHEAD.toolTipText=A financial transaction where force overhead is paid for.
TransactionType.MAINTENANCE.text=Maintenance
TransactionType.MAINTENANCE.toolTipText=A financial transaction where unit maintenance is paid for.
TransactionType.REPAIRS.text=Repairs
TransactionType.REPAIRS.toolTipText=A financial transaction where unit repairs are paid for.
TransactionType.TRANSPORTATION.text=Transportation
TransactionType.TRANSPORTATION.toolTipText=A financial transaction where force transportation is paid for.
TransactionType.UNIT_SALE.text=Unit Sale(s)
TransactionType.UNIT_SALE.toolTipText=A financial transaction where a unit was or multiple units were sold.
TransactionType.EQUIPMENT_SALE.text=Equipment Sale(s)
TransactionType.EQUIPMENT_SALE.toolTipText=A financial transaction where some equipment was sold.
TransactionType.CONTRACT_PAYMENT.text=Contract Payments
TransactionType.CONTRACT_PAYMENT.toolTipText=A financial transaction where the force is paid for their current contract.
TransactionType.BATTLE_LOSS_COMPENSATION.text=Battle Loss Compensation
TransactionType.BATTLE_LOSS_COMPENSATION.toolTipText=A financial transaction where battle losses are partially to completely paid back by the employer, as per the current negotiated contract.
TransactionType.SALVAGE.text=Salvage
TransactionType.SALVAGE.toolTipText=A financial transaction where salvaged units are either ransomed back to the foe or immediately sold on the market.
TransactionType.SALVAGE_EXCHANGE.text=Salvage Exchange
TransactionType.SALVAGE_EXCHANGE.toolTipText=A financial transaction where salvaged units are exchanged for funds as per the current negotiated contract.
TransactionType.RANSOM.text=Ransom
TransactionType.RANSOM.toolTipText=A financial transaction where captured personnel are ransomed.
TransactionType.LOAN_PRINCIPAL.text=Loan Principal
TransactionType.LOAN_PRINCIPAL.toolTipText=A financial transaction where a loan was signed.
TransactionType.LOAN_PAYMENT.text=Loan Payment
TransactionType.LOAN_PAYMENT.toolTipText=A financial transaction where a loan was being paid for.
TransactionType.STARTING_CAPITAL.text=Starting Capital
TransactionType.STARTING_CAPITAL.toolTipText=A financial transaction where the fund are supplied to start a force.
TransactionType.CARRYOVER.text=End-of-Year Carryover
TransactionType.CARRYOVER.toolTipText=Funds carried over from the previous financial year.
TransactionType.FINE.text=Fine
TransactionType.FINE.toolTipText=A financial transaction where the force pays or is paid a fine.
TransactionType.RENT.text=Rent
TransactionType.RENT.toolTipText=A financial transaction where the force pays or is paid rent.
TransactionType.CONSTRUCTION.text=Construction
TransactionType.CONSTRUCTION.toolTipText=A financial transaction where the force pays for building construction.
TransactionType.TAXES.text=Taxes
TransactionType.TAXES.toolTipText=A financial transaction where the force pays or is paid taxes.
TransactionType.MEDICAL_EXPENSES.text=Medical Expenses
TransactionType.MEDICAL_EXPENSES.toolTipText=A financial transaction where medical expenses are covered.
TransactionType.MISCELLANEOUS.text=Miscellaneous
TransactionType.MISCELLANEOUS.toolTipText=A miscellaneous financial transaction.

## Finances Files
# Peacetime Operating Costs
PeacetimeCosts.title="Monthly Peacetime Operating Costs"
Expand Down
50 changes: 26 additions & 24 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import megamek.utils.MegaMekXmlUtil;
import mekhq.*;
import mekhq.campaign.againstTheBot.AtBConfiguration;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.mission.enums.AtBLanceRole;
import mekhq.campaign.event.MissionRemovedEvent;
import mekhq.campaign.event.ScenarioRemovedEvent;
Expand Down Expand Up @@ -598,7 +599,8 @@ private void processShipSearch() {
return;
}
StringBuilder report = new StringBuilder();
if (getFinances().debit(getAtBConfig().shipSearchCostPerWeek(), Transaction.C_UNIT, "Ship search", getLocalDate())) {
if (getFinances().debit(TransactionType.UNIT_PURCHASE, getLocalDate(),
getAtBConfig().shipSearchCostPerWeek(), "Ship Search")) {
report.append(getAtBConfig().shipSearchCostPerWeek().toAmountAndSymbolString())
.append(" deducted for ship search.");
} else {
Expand Down Expand Up @@ -664,7 +666,7 @@ public void purchaseShipSearchResult() {
int transitDays = getCampaignOptions().getInstantUnitMarketDelivery() ? 0
: calculatePartTransitTime(Compute.d6(2) - 2);

getFinances().debit(cost, Transaction.C_UNIT, "Purchased " + en.getShortName(), getLocalDate());
getFinances().debit(TransactionType.UNIT_PURCHASE, getLocalDate(), cost, "Purchased " + en.getShortName());
addNewUnit(en, true, transitDays);
if (!getCampaignOptions().getInstantUnitMarketDelivery()) {
addReport("<font color='green'>Unit will be delivered in " + transitDays + " days.</font>");
Expand All @@ -682,7 +684,7 @@ public void purchaseShipSearchResult() {
*/
public boolean applyRetirement(Money totalPayout, HashMap<UUID, UUID> unitAssignments) {
if ((totalPayout.isPositive()) || (null != getRetirementDefectionTracker().getRetirees())) {
if (getFinances().debit(totalPayout, Transaction.C_SALARY, "Final Payout", getLocalDate())) {
if (getFinances().debit(TransactionType.RETIREMENT, getLocalDate(), totalPayout, "Final Payout")) {
for (UUID pid : getRetirementDefectionTracker().getRetirees()) {
if (getPerson(pid).getStatus().isActive()) {
getPerson(pid).changeStatus(this, PersonnelStatus.RETIRED);
Expand Down Expand Up @@ -1352,8 +1354,8 @@ public boolean recruitPerson(Person p, PrisonerStatus prisonerStatus, boolean gm
// Only pay if option set, they weren't GM added, and they aren't a dependent, prisoner or bondsman
if (getCampaignOptions().payForRecruitment() && !p.getPrimaryRole().isDependent()
&& !gmAdd && prisonerStatus.isFree()) {
if (!getFinances().debit(p.getSalary().multipliedBy(2), Transaction.C_SALARY,
"Recruitment of " + p.getFullName(), getLocalDate())) {
if (!getFinances().debit(TransactionType.RECRUITMENT, getLocalDate(),
p.getSalary().multipliedBy(2), "Recruitment of " + p.getFullName())) {
addReport("<font color='red'><b>Insufficient funds to recruit "
+ p.getFullName() + "</b></font>");
return false;
Expand Down Expand Up @@ -2896,7 +2898,8 @@ public String fixPart(IPartWork partWork, Person tech) {
report += "<br>Repairs cost " +
cost.toAmountAndSymbolString() +
" worth of parts.";
finances.debit(cost, Transaction.C_REPAIRS, "Repair of " + partWork.getPartName(), getLocalDate());
finances.debit(TransactionType.REPAIRS, getLocalDate(), cost,
"Repair of " + partWork.getPartName());
}
if ((roll == 12) && (target.getValue() != TargetRoll.AUTOMATIC_SUCCESS)) {
xpGained += getCampaignOptions().getSuccessXP();
Expand Down Expand Up @@ -3999,18 +4002,17 @@ public void setIconFileName(String s) {
this.iconFileName = s;
}

public void addFunds(Money quantity) {
addFunds(quantity, "Rich Uncle", Transaction.C_MISC);
public void addFunds(final Money quantity) {
addFunds(TransactionType.MISCELLANEOUS, quantity, null);
}

public void addFunds(Money quantity, String description, int category) {
if (description == null || description.isEmpty()) {
public void addFunds(final TransactionType type, final Money quantity,
@Nullable String description) {
if ((description == null) || description.isEmpty()) {
description = "Rich Uncle";
}
if (category == -1) {
category = Transaction.C_MISC;
}
finances.credit(quantity, category, description, getLocalDate());

finances.credit(type, getLocalDate(), quantity, description);
String quantityString = quantity.toAmountAndSymbolString();
addReport("Funds added : " + quantityString + " (" + description + ")");
}
Expand Down Expand Up @@ -6032,13 +6034,13 @@ public void completeMission(@Nullable Mission mission, MissionStatus status) {
}

if (remainingMoney.isPositive()) {
getFinances().credit(remainingMoney, Transaction.C_CONTRACT,
"Remaining payment for " + contract.getName(), getLocalDate());
getFinances().credit(TransactionType.CONTRACT_PAYMENT, getLocalDate(), remainingMoney,
"Remaining payment for " + contract.getName());
addReport("Your account has been credited for " + remainingMoney.toAmountAndSymbolString()
+ " for the remaining payout from contract " + contract.getName());
} else if (remainingMoney.isNegative()) {
getFinances().credit(remainingMoney, Transaction.C_CONTRACT,
"Repaying payment overages for " + contract.getName(), getLocalDate());
getFinances().credit(TransactionType.CONTRACT_PAYMENT, getLocalDate(), remainingMoney,
"Repaying payment overages for " + contract.getName());
addReport("Your account has been debited for " + remainingMoney.absolute().toAmountAndSymbolString()
+ " to replay payment overages occurred during the contract " + contract.getName());
}
Expand Down Expand Up @@ -6216,13 +6218,13 @@ public void addLoan(Loan loan) {
+ " for the principal amount.");
finances.addLoan(loan);
MekHQ.triggerEvent(new LoanNewEvent(loan));
finances.credit(loan.getPrincipal(), Transaction.C_LOAN_PRINCIPAL,
"loan principal for " + loan, getLocalDate());
finances.credit(TransactionType.LOAN_PRINCIPAL, getLocalDate(), loan.getPrincipal(),
"Loan principal for " + loan);
}

public void payOffLoan(Loan loan) {
if (finances.debit(loan.determineRemainingValue(),
Transaction.C_LOAN_PAYMENT, "loan payoff for " + loan, getLocalDate())) {
if (finances.debit(TransactionType.LOAN_PAYMENT, getLocalDate(), loan.determineRemainingValue(),
"Loan payoff for " + loan)) {
addReport("You have paid off the remaining loan balance of "
+ loan.determineRemainingValue().toAmountAndSymbolString()
+ "on " + loan);
Expand Down Expand Up @@ -6300,8 +6302,8 @@ public void doMaintenance(Unit u) {
if (u.getDaysSinceMaintenance() >= (getCampaignOptions().getMaintenanceCycleDays() * ruggedMultiplier)) {
// maybe use the money
if (campaignOptions.payForMaintain()) {
if (!(finances.debit(u.getMaintenanceCost(), Transaction.C_MAINTAIN, "Maintenance for "
+ u.getName(), getLocalDate()))) {
if (!(finances.debit(TransactionType.MAINTENANCE, getLocalDate(), u.getMaintenanceCost(),
"Maintenance for " + u.getName()))) {
addReport("<font color='red'><b>You cannot afford to pay maintenance costs for "
+ u.getHyperlinkedName() + "!</b></font>");
paidMaintenance = false;
Expand Down
26 changes: 12 additions & 14 deletions MekHQ/src/mekhq/campaign/CurrentLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@
*/
package mekhq.campaign;

import java.io.PrintWriter;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Locale;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.common.Compute;
import mekhq.MekHQ;
import mekhq.MekHqXmlUtil;
import mekhq.campaign.event.LocationChangedEvent;
import mekhq.campaign.finances.Transaction;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.universe.PlanetarySystem;
import mekhq.campaign.universe.Systems;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.PrintWriter;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Locale;

/**
* This keeps track of a location, which includes both the planet
Expand Down Expand Up @@ -208,12 +207,11 @@ public void newDay(Campaign campaign) {
if (isAtJumpPoint() && (rechargeTime >= neededRechargeTime)) {
//jump
if (campaign.getCampaignOptions().payForTransport()) {
if (!campaign.getFinances().debit(campaign.calculateCostPerJump(
true, campaign.getCampaignOptions().useEquipmentContractBase()),
Transaction.C_TRANSPORT,
if (!campaign.getFinances().debit(TransactionType.TRANSPORTATION, campaign.getLocalDate(),
campaign.calculateCostPerJump(
true, campaign.getCampaignOptions().useEquipmentContractBase()),
"Jump from " + currentSystem.getName(campaign.getLocalDate())
+ " to " + jumpPath.get(1).getName(campaign.getLocalDate()),
campaign.getLocalDate())) {
+ " to " + jumpPath.get(1).getName(campaign.getLocalDate()))) {
campaign.addReport("<font color='red'><b>You cannot afford to make the jump!</b></font>");
return;
}
Expand Down
47 changes: 21 additions & 26 deletions MekHQ/src/mekhq/campaign/Quartermaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@

package mekhq.campaign;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import megamek.common.AmmoType;
import megamek.common.Entity;
import megamek.common.annotations.Nullable;
Expand All @@ -31,18 +27,16 @@
import mekhq.campaign.event.PartArrivedEvent;
import mekhq.campaign.event.PartChangedEvent;
import mekhq.campaign.finances.Money;
import mekhq.campaign.finances.Transaction;
import mekhq.campaign.parts.AmmoStorage;
import mekhq.campaign.parts.Armor;
import mekhq.campaign.parts.InfantryAmmoStorage;
import mekhq.campaign.parts.MissingPart;
import mekhq.campaign.parts.OmniPod;
import mekhq.campaign.parts.Part;
import mekhq.campaign.parts.Refit;
import mekhq.campaign.finances.enums.TransactionType;
import mekhq.campaign.parts.*;
import mekhq.campaign.parts.equipment.AmmoBin;
import mekhq.campaign.unit.TestUnit;
import mekhq.campaign.unit.Unit;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Manages machines and materiel for a campaign.
*/
Expand Down Expand Up @@ -469,8 +463,8 @@ public boolean buyUnit(Entity en, int days) {

if (getCampaignOptions().payForUnits()) {
Money cost = new Unit(en, getCampaign()).getBuyCost();
if (getCampaign().getFinances().debit(cost, Transaction.C_UNIT,
"Purchased " + en.getShortName(), getCampaign().getLocalDate())) {
if (getCampaign().getFinances().debit(TransactionType.UNIT_PURCHASE, getCampaign().getLocalDate(),
cost, "Purchased " + en.getShortName())) {
getCampaign().addNewUnit(en, false, days);
return true;
} else {
Expand All @@ -491,8 +485,8 @@ public void sellUnit(Unit unit) {

Money sellValue = unit.getSellValue();

getCampaign().getFinances().credit(sellValue, Transaction.C_UNIT_SALE,
"Sale of " + unit.getName(), getCampaign().getLocalDate());
getCampaign().getFinances().credit(TransactionType.UNIT_SALE, getCampaign().getLocalDate(),
sellValue, "Sale of " + unit.getName());

getCampaign().removeUnit(unit.getId());
}
Expand Down Expand Up @@ -543,8 +537,8 @@ public void sellPart(Part part, int quantity) {
plural = "s";
}

getCampaign().getFinances().credit(cost, Transaction.C_EQUIP_SALE, "Sale of " + quantity
+ " " + part.getName() + plural, getCampaign().getLocalDate());
getCampaign().getFinances().credit(TransactionType.EQUIPMENT_SALE, getCampaign().getLocalDate(),
cost, "Sale of " + quantity + " " + part.getName() + plural);

getWarehouse().removePart(part, quantity);
}
Expand Down Expand Up @@ -582,8 +576,8 @@ public void sellAmmo(AmmoStorage ammo, int shots) {

Money cost = ammo.getActualValue().multipliedBy(saleProportion);

getCampaign().getFinances().credit(cost, Transaction.C_EQUIP_SALE, "Sale of " + shots
+ " " + ammo.getName(), getCampaign().getLocalDate());
getCampaign().getFinances().credit(TransactionType.EQUIPMENT_SALE, getCampaign().getLocalDate(),
cost, "Sale of " + shots + " " + ammo.getName());

getWarehouse().removeAmmo(ammo, shots);
}
Expand Down Expand Up @@ -621,8 +615,8 @@ public void sellArmor(Armor armor, int points) {

Money cost = armor.getActualValue().multipliedBy(saleProportion);

getCampaign().getFinances().credit(cost, Transaction.C_EQUIP_SALE, "Sale of " + points
+ " " + armor.getName(), getCampaign().getLocalDate());
getCampaign().getFinances().credit(TransactionType.EQUIPMENT_SALE, getCampaign().getLocalDate(),
cost, "Sale of " + points + " " + armor.getName());

getWarehouse().removeArmor(armor, points);
}
Expand Down Expand Up @@ -688,8 +682,9 @@ public void depodPart(Part part, int quantity) {
*/
public boolean buyRefurbishment(Part part) {
if (getCampaignOptions().payForParts()) {
return getCampaign().getFinances().debit(part.getStickerPrice(), Transaction.C_EQUIP,
"Purchase of " + part.getName(), getCampaign().getLocalDate());
return getCampaign().getFinances().debit(TransactionType.EQUIPMENT_PURCHASE,
getCampaign().getLocalDate(), part.getStickerPrice(),
"Purchase of " + part.getName());
} else {
return true;
}
Expand Down Expand Up @@ -717,8 +712,8 @@ public boolean buyPart(Part part, double costMultiplier, int transitDays) {

if (getCampaignOptions().payForParts()) {
Money cost = part.getStickerPrice().multipliedBy(costMultiplier);
if (getCampaign().getFinances().debit(cost,
Transaction.C_EQUIP, "Purchase of " + part.getName(), getCampaign().getLocalDate())) {
if (getCampaign().getFinances().debit(TransactionType.EQUIPMENT_PURCHASE,
getCampaign().getLocalDate(), cost, "Purchase of " + part.getName())) {
if (part instanceof Refit) {
((Refit) part).addRefitKitParts(transitDays);
} else {
Expand Down
Loading

0 comments on commit 7120d3b

Please sign in to comment.