diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 93b87b18..00b6ac5d 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -866,7 +866,18 @@ static GLfloat sBaseMass = 0.0; unsigned original_hold_size = [UNIVERSE maxCargoForShip:[self shipDataKey]]; max_cargo = [dict oo_intForKey:@"max_cargo" defaultValue:max_cargo]; if (max_cargo > original_hold_size) [self addEquipmentItem:@"EQ_CARGO_BAY"]; - max_cargo = original_hold_size + ([self hasExpandedCargoBay] ? extra_cargo : 0) - max_passengers * 5; + max_cargo = original_hold_size + ([self hasExpandedCargoBay] ? extra_cargo : 0); + if (max_cargo >= max_passengers * 5) + { + max_cargo -= max_passengers * 5; + } + else // Handle case where something went wrong. Possibly the save file was hacked to contain more passenger cabins than the available cargo space would allow - Nikos 20110731 + { + unsigned originalMaxPassengers = max_passengers; + max_passengers = (unsigned)(max_cargo / 5); // we should really make the magic number 5 a constant - something like PASSENGER_BERTH_REQUIRED_SPACE or similar + OOLogWARN(@"setCommanderDataFromDictionary.max_cargo.isNegative", @"max_cargo for player ship %@ gone negative, probably due to max_passengers (%u) being set to a value that requires more cargo space than it is available on player ship. Resetting max_passengers to %u to compensate.", [self name], originalMaxPassengers, max_passengers); + } + credits = OODeciCreditsFromObject([dict objectForKey:@"credits"]); fuel = [dict oo_unsignedIntForKey:@"fuel" defaultValue:fuel];