Fix transport cost display and calculation semantics #8635
Merged
Conversation
…sses #8620) --- Summary - Fixed transport cost double-counting display bug in contract payment breakdown - Changed transportAmount to represent employer's reimbursement (income) instead of player's cost - Better transport terms now correctly show improved contract value - Renamed "Transportation Amount" to "Transport Reimbursement" for clarity Background Transport cost confusion has come up multiple times on Discord, and has been discussed on the official forums: - https://battletech.com/forums/index.php?topic=90305.0 - GitHub Issue: #8620 (partially addressed - see below) The Problem Players were experiencing confusing behavior when reviewing contract proposals: 1. Double-counting appearance: Transport fees appeared to be subtracted twice - once in the Income section as "Transportation Amount" (showing the full transport cost as negative), and again in the Expenses section as "Transportation Expenses" (showing the player's share as negative). The breakdown values didn't add up to the displayed totals. 2. Better terms = lower payout paradox: When negotiating better transport compensation (e.g., going from 50% to 75% employer-paid), the displayed payout would actually decrease. This was counterintuitive and made players think something was broken. 3. Semantic confusion in code: The transportAmount field stored the player's out-of-pocket cost but was being added to income in getTotalAmount(), then subtracted again in getEstimatedTotalProfit(). While these operations cancelled mathematically, the display showed inconsistent values. Example: Before vs After Scenario: Full transport cost = 1,000,000 C-bills, Employer pays 50% | Display Section | Before (Buggy) | After (Fixed) | |----------------------|----------------------------------|-------------------------------------------------------| | Income: Transport | -1,000,000 (full cost, negative) | +500,000 (reimbursement, positive) | | Expenses: Transport | -500,000 (player's share) | -1,000,000 (full cost you pay) | | Net effect on profit | Confusing, values don't add up | Clear: +500k income - 1M expense = -500k (your share) | When negotiating better terms (75% employer-paid): | Metric | Before (Buggy) | After (Fixed) | |-------------------------|---------------------------------|--------------------------------------------| | Displayed payout | Goes DOWN (confusing!) | Stays similar | | Transport Reimbursement | Not shown correctly | +750,000 (higher = better) | | Your transport cost | -500,000 shown, -250,000 actual | -1,000,000 (full), offset by reimbursement | | Net profit effect | Unclear | Clear: -250,000 (your 25% share) | Regarding Issue #8620 Issue #8620 reported that transport fees were deducted even when the player owns sufficient ships. This PR partially addresses that issue: - Fixed: The display now correctly shows what TransportCostCalculations returns. If you own ships, the calculated transport cost should be lower (or zero), and this will now display correctly. - Not addressed in this PR: During investigation, we found that ships which are "in transit" (not present at current location) still contribute to transport capacity calculations, even though they're not actually available. This is a separate issue that will be addressed in a follow-up PR. Test plan - Updated existing ContractTest cases for new calculation values - Added testGetEmployerTransportReimbursement - verifies employer reimbursement calculation - Added testGetPlayerTransportCost - verifies player's out-of-pocket cost - Added testGetTotalTransportationFees - verifies full transport cost returned - Added testTransportReimbursementWithPartialCompensation - tests 50% compensation - Added testBetterTransportTermsIncreaseReimbursement - verifies better terms = higher reimbursement - Manual testing: Verify contract proposal UI shows correct breakdown values - Manual testing: Verify owned ships reduce displayed transport costs 🤖 Generated with https://claude.com/claude-code
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a transport cost display bug where transport fees appeared to be double-counted in contract payment breakdowns, and changes the semantics of transportAmount from representing the player's cost to representing the employer's reimbursement. The change makes better transport negotiation terms correctly show as increased contract value, and renames the UI label from "Transportation Amount" to "Transport Reimbursement" for clarity.
Key changes:
- Changed
transportAmountfield to store employer's transport reimbursement instead of player's out-of-pocket cost - Updated contract payment breakdown UI to show employer reimbursement as positive income and full transport cost as expense
- Added new methods
getEmployerTransportReimbursement()andgetPlayerTransportCost()for clearer transport cost calculations
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| MekHQ/src/mekhq/campaign/mission/Contract.java | Core logic change: transportAmount now calculated as employer reimbursement; added new methods for transport cost calculations; updated documentation |
| MekHQ/src/mekhq/gui/view/ContractPaymentBreakdown.java | Updated UI display to show employer reimbursement in income section and full transport cost in expenses section |
| MekHQ/resources/mekhq/resources/ContractPaymentBreakdown.properties | Renamed label from "Transportation Amount" to "Transport Reimbursement" |
| MekHQ/unittests/mekhq/campaign/mission/ContractTest.java | Updated existing test expectations and added comprehensive tests for new transport cost calculation methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
--- Changes Made: | Issue | File | Fix | |---------------------------------------|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------| | 1. ContractAutomation breaking change | ContractAutomation.java | Changed getTransportAmount() → getTotalTransportationFees(campaign) at lines 126 and 156 | | 2. Save compatibility | Contract.java | Added version check in loadFieldsFromXmlNode() to recalculate transportAmount for saves < 0.50.12 | | 3. Misleading comment | ContractPaymentBreakdown.java | Updated comment to clarify employer reimbursement is shown separately in income section | | 4. Duplicate calculation | Contract.java | Changed getPlayerTransportCost() to call getEmployerTransportReimbursement(campaign) instead of duplicating the calculation | --- Files modified: - MekHQ/src/mekhq/campaign/market/contractMarket/ContractAutomation.java - MekHQ/src/mekhq/campaign/mission/Contract.java - MekHQ/src/mekhq/gui/view/ContractPaymentBreakdown.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Partially addresses #8620)
Summary
Background
Transport cost confusion has come up multiple times on Discord, and has been discussed on the official forums:
The Problem
Players were experiencing confusing behavior when reviewing contract proposals:
Example: Before vs After
Scenario: Full transport cost = 1,000,000 C-bills, Employer pays 50%
When negotiating better terms (75% employer-paid):
Regarding Issue #8620
Issue #8620 reported that transport fees were deducted even when the player owns sufficient ships. This PR partially addresses that issue:
Test plan
🤖 Generated with https://claude.com/claude-code