From c25fda412d72fc6c0b6553d95b3ca4c84fe5314f Mon Sep 17 00:00:00 2001 From: Anarchist2 <60202690+Anarchist2@users.noreply.github.com> Date: Sun, 3 Nov 2024 10:20:56 +1000 Subject: [PATCH] fix(mechanics): Fix bug where over-capacity fleets don't unload all their cargo (#10657) --- source/PlanetPanel.cpp | 7 ++++--- source/PlayerInfo.cpp | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/PlanetPanel.cpp b/source/PlanetPanel.cpp index 0727a55d9e0a..95306daced1f 100644 --- a/source/PlanetPanel.cpp +++ b/source/PlanetPanel.cpp @@ -438,6 +438,9 @@ void PlanetPanel::CheckWarningsAndTakeOff() out << " that you do not have space for."; } out << "\nAre you sure you want to continue?"; + // Pool cargo together, so that the cargo number on the trading panel + // is still accurate while the popup is active. + player.PoolCargo(); GetUI()->Push(new Dialog(this, &PlanetPanel::WarningsDialogCallback, out.str())); return; } @@ -452,9 +455,7 @@ void PlanetPanel::CheckWarningsAndTakeOff() void PlanetPanel::WarningsDialogCallback(const bool isOk) { if(isOk) - TakeOff(false); - else - player.PoolCargo(); + TakeOff(true); } diff --git a/source/PlayerInfo.cpp b/source/PlayerInfo.cpp index a4d9b5eead0e..cfacacade209 100644 --- a/source/PlayerInfo.cpp +++ b/source/PlayerInfo.cpp @@ -1877,9 +1877,15 @@ void PlayerInfo::PoolCargo() // This can only be done while landed. if(!planet) return; + + // To make sure all cargo and passengers get unloaded from each ship, + // temporarily uncap the player's cargo and bunk capacity. + cargo.SetSize(-1); + cargo.SetBunks(-1); for(const shared_ptr &ship : ships) if(ship->GetPlanet() == planet && !ship->IsParked()) ship->Cargo().TransferAll(cargo); + UpdateCargoCapacities(); } @@ -1965,8 +1971,9 @@ bool PlayerInfo::HasLogs() const -// Call this after missions update, or if leaving the outfitter, shipyard, or -// hiring panel. Updates the information on how much space is available. +// Call this after missions update, if leaving the outfitter, shipyard, or +// hiring panel, or after backing out of a take-off warning. +// Updates the information on how much space is available. void PlayerInfo::UpdateCargoCapacities() { int size = 0;