diff --git a/src/pilot.c b/src/pilot.c index b8b638e..7ab76ab 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -55,6 +55,7 @@ static void pilot_update(Pilot* pilot, const double dt); static void pilot_hyperspace(Pilot* pilot); void pilot_render(Pilot* pilot); static void pilot_calcStats(Pilot* pilot); +static void pilot_calcCargo(Pilot* pilot); void pilot_free(Pilot* p); static Fleet* fleet_parse(const xmlNodePtr parent); static void pilot_dead(Pilot* p); @@ -617,6 +618,9 @@ static void pilot_calcStats(Pilot* pilot) { pilot->shield_regen = pilot->ship->shield_regen; pilot->energy_regen = pilot->ship->energy_regen; + // Cargo has to be reset. + pilot_calcCargo(pilot); + // Now add outfit changes. for(i = 0; i < pilot->noutfits; i++) { if(outfit_isMod(pilot->outfits[i].outfit)) { @@ -685,6 +689,14 @@ int pilot_addCargo(Pilot* pilot, Commodity* cargo, int quantity) { return q; } +static void pilot_calcCargo(Pilot* pilot) { + int i; + + pilot->cargo_free = pilot->ship->cap_cargo; + for(i = 0; i < pilot->ncommodities; i++) + pilot->cargo_free -= pilot->commodities[i].quantity; +} + unsigned int pilot_addMissionCargo(Pilot* pilot, Commodity* cargo, int quantity) { int q; q = quantity; @@ -814,6 +826,12 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction, } } + // Cargo must be set before calcStats. + pilot->credits = 0; + pilot->commodities = NULL; + pilot->ncommodities = 0; + pilot->cargo_free = pilot->ship->cap_cargo; + // Set the pilot stats based on her ship and outfits. // Hack to have full armour/shield/energy/fuel. pilot->armour = pilot->armour_max = 1.; @@ -822,12 +840,6 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction, pilot->fuel = pilot->fuel_max = 1.; pilot_calcStats(pilot); - // Cargo. - pilot->credits = 0; - pilot->commodities = NULL; - pilot->ncommodities = 0; - pilot->cargo_free = pilot->ship->cap_cargo; - // Hooks. pilot->hook_type = PILOT_HOOK_NONE; pilot->hook = 0;