Skip to content

Commit a879f11

Browse files
authored
Merge pull request #8492 from IllianiBird/passengerFix
Fix #8450: Fixed Transport Cost Calculator Incorrectly Counting WarShip, JumpShip, and DropShip Crews as Passengers; Fixed Bay Personnel Capacity of Small Craft Not Being Factored into Cost Calculator
2 parents 8f99568 + 65cb7f4 commit a879f11

File tree

3 files changed

+413
-2
lines changed

3 files changed

+413
-2
lines changed

MekHQ/src/mekhq/campaign/mission/TransportCostCalculations.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,14 +753,50 @@ void countUnitsByType() {
753753
* @since 50.10
754754
*/
755755
void calculateAdditionalBayRequirementsFromPassengers(int passengerCapacity) {
756-
int passengerCount = allPersonnel.size();
756+
int passengerCount = getPassengerCount();
757757
int additionalPassengerNeeds = max(0, passengerCount - passengerCapacity);
758758
additionalPassengerBaysRequired = (int) ceil(additionalPassengerNeeds / PASSENGERS_PER_BAY);
759759
additionalPassengerBaysCost = round(additionalPassengerBaysRequired * PASSENGERS_COST);
760760
totalCost = totalCost.plus(additionalPassengerBaysCost);
761761
totalAdditionalBaysRequired += additionalPassengerBaysRequired;
762762
}
763763

764+
/**
765+
* Calculates and returns the total number of passengers. A person is considered a passenger if:
766+
*
767+
* <ul>
768+
* <li>They are not associated with any unit.</li>
769+
* <li>Their associated unit does not have an associated entity.</li>
770+
* <li>The entity associated with their unit is not a WarShip, JumpShip, or DropShip.</li>
771+
* </ul>
772+
*
773+
* @return The total count of passengers based on the conditions specified.
774+
*/
775+
private int getPassengerCount() {
776+
int passengerCount = 0;
777+
for (Person person : allPersonnel) {
778+
Unit unit = person.getUnit();
779+
if (unit == null) {
780+
passengerCount++;
781+
continue;
782+
}
783+
784+
Entity entity = unit.getEntity();
785+
if (entity == null) {
786+
passengerCount++;
787+
continue;
788+
}
789+
790+
// We exclude Space Stations here, as CamOps pg 35 states that only crew of the below unit types are
791+
// excluded from passenger counts
792+
if (!entity.isSmallCraft() && !entity.isWarShip() && !entity.isJumpShip() && !entity.isDropShip()) {
793+
passengerCount++;
794+
}
795+
}
796+
797+
return passengerCount;
798+
}
799+
764800
/**
765801
* Executes a financial transaction for performing a jump between two planetary systems, debiting the specified
766802
* journey cost from the provided finances. Generates and includes a report of the transaction outcome.

MekHQ/src/mekhq/campaign/unit/HangarStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public int getTotalDockingCollars() {
266266

267267
public int getTotalLargeCraftPassengerCapacity() {
268268
return getHangar().getUnitsStream()
269-
.filter(u -> u.getEntity().isLargeCraft())
269+
.filter(u -> u.getEntity().isLargeCraft() || u.getEntity().isSmallCraft())
270270
.mapToInt(u -> u.getEntity().getNPassenger() + u.getEntity().getBayPersonnel())
271271
.sum();
272272
}

0 commit comments

Comments
 (0)