Skip to content

Commit

Permalink
fix(mechanics): Fix bug where over-capacity fleets don't unload all t…
Browse files Browse the repository at this point in the history
…heir cargo (endless-sky#10657)
  • Loading branch information
Anarchist2 authored Nov 3, 2024
1 parent 6c025dd commit c25fda4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions source/PlanetPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -452,9 +455,7 @@ void PlanetPanel::CheckWarningsAndTakeOff()
void PlanetPanel::WarningsDialogCallback(const bool isOk)
{
if(isOk)
TakeOff(false);
else
player.PoolCargo();
TakeOff(true);
}


Expand Down
11 changes: 9 additions & 2 deletions source/PlayerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> &ship : ships)
if(ship->GetPlanet() == planet && !ship->IsParked())
ship->Cargo().TransferAll(cargo);
UpdateCargoCapacities();
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c25fda4

Please sign in to comment.