Skip to content

Commit

Permalink
Fix 19835b5: Wrong GoodsEntryData used after vehicle refit in station
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison committed Aug 23, 2023
1 parent 84b7f2e commit c850193
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,9 @@ static void LoadUnloadVehicle(Vehicle *front)
if (v->cargo_cap == 0) continue;
artic_part++;

/* ge and ged must both be changed together, when the cargo is changed (e.g. after HandleStationRefit) */
GoodsEntry *ge = &st->goods[v->cargo_type];
GoodsEntryData &ged = ge->CreateData();
GoodsEntryData *ged = &ge->CreateData();

if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) && payment == nullptr) {
/* Once the payment has been made, never attempt to unload again */
Expand All @@ -2047,7 +2048,7 @@ static void LoadUnloadVehicle(Vehicle *front)
uint new_remaining = v->cargo.RemainingCount() + v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER);
if (v->cargo_cap < new_remaining) {
/* Return some of the reserved cargo to not overload the vehicle. */
v->cargo.Return(new_remaining - v->cargo_cap, &ged.cargo, INVALID_STATION);
v->cargo.Return(new_remaining - v->cargo_cap, &ged->cargo, INVALID_STATION);
}

/* Keep instead of delivering. This may lead to no cargo being unloaded, so ...*/
Expand All @@ -2074,7 +2075,7 @@ static void LoadUnloadVehicle(Vehicle *front)
}
}

amount_unloaded = v->cargo.Unload(amount_unloaded, &ged.cargo, payment);
amount_unloaded = v->cargo.Unload(amount_unloaded, &ged->cargo, payment);
remaining = v->cargo.UnloadCount() > 0;
if (amount_unloaded > 0) {
dirty_vehicle = true;
Expand Down Expand Up @@ -2103,6 +2104,7 @@ static void LoadUnloadVehicle(Vehicle *front)
if (front->current_order.IsRefit() && artic_part == 1) {
HandleStationRefit(v, consist_capleft, st, next_station, front->current_order.GetRefitCargo());
ge = &st->goods[v->cargo_type];
ged = &ge->CreateData();
}

/* Do not pick up goods when we have no-load set. */
Expand Down Expand Up @@ -2144,11 +2146,11 @@ static void LoadUnloadVehicle(Vehicle *front)

/* If there's goods waiting at the station, and the vehicle
* has capacity for it, load it on the vehicle. */
if ((v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0 || ged.cargo.AvailableCount() > 0) && MayLoadUnderExclusiveRights(st, v)) {
if ((v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0 || ged->cargo.AvailableCount() > 0) && MayLoadUnderExclusiveRights(st, v)) {
if (v->cargo.StoredCount() == 0) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
if (_settings_game.order.gradual_loading) cap_left = std::min(cap_left, GetLoadAmount(v));

uint loaded = ged.cargo.Load(cap_left, &v->cargo, st->xy, next_station.Get(v->cargo_type));
uint loaded = ged->cargo.Load(cap_left, &v->cargo, st->xy, next_station.Get(v->cargo_type));
if (v->cargo.ActionCount(VehicleCargoList::MTA_LOAD) > 0) {
/* Remember if there are reservations left so that we don't stop
* loading before they're loaded. */
Expand Down Expand Up @@ -2176,7 +2178,7 @@ static void LoadUnloadVehicle(Vehicle *front)
st->time_since_load = 0;
ge->last_vehicle_type = v->type;

if (ged.cargo.TotalCount() == 0) {
if (ged->cargo.TotalCount() == 0) {
TriggerStationRandomisation(st, st->xy, SRT_CARGO_TAKEN, v->cargo_type);
TriggerStationAnimation(st, st->xy, SAT_CARGO_TAKEN, v->cargo_type);
AirportAnimationTrigger(st, AAT_STATION_CARGO_TAKEN, v->cargo_type);
Expand Down

0 comments on commit c850193

Please sign in to comment.