diff options
-rw-r--r-- | src/economy.cpp | 18 | ||||
-rw-r--r-- | src/openttd.cpp | 17 | ||||
-rw-r--r-- | src/saveload.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 1 | ||||
-rw-r--r-- | src/vehicle.h | 3 |
5 files changed, 32 insertions, 9 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index b422b8a53..99fbdb09b 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1376,25 +1376,26 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived) st->time_since_unload = 0; unloading_time += v->cargo_count; /* TTDBUG: bug in original TTD */ - if (just_arrived && !HASBIT(v->load_status, LS_CARGO_PAID_FOR)) { - profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_source_xy, v->cargo_days); - SETBIT(v->load_status, LS_CARGO_PAID_FOR); + if (just_arrived && v->cargo_paid_for < v->cargo_count) { + profit += DeliverGoods(v->cargo_count - v->cargo_paid_for, v->cargo_type, v->cargo_source, last_visited, v->cargo_source_xy, v->cargo_days); + v->cargo_paid_for = v->cargo_count; } result |= 1; v->cargo_count -= amount_unloaded; + v->cargo_paid_for -= min(amount_unloaded, v->cargo_paid_for); if (_patches.gradual_loading) continue; } else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { /* unload goods and let it wait at the station */ st->time_since_unload = 0; - if (just_arrived && (u->current_order.flags & OF_TRANSFER) && !HASBIT(v->load_status, LS_CARGO_PAID_FOR)) { + if (just_arrived && (u->current_order.flags & OF_TRANSFER) && v->cargo_paid_for < v->cargo_count) { v_profit = GetTransportedGoodsIncome( - v->cargo_count, + v->cargo_count - v->cargo_paid_for, DistanceManhattan(v->cargo_source_xy, GetStation(last_visited)->xy), v->cargo_days, v->cargo_type) * 3 / 2; v_profit_total += v_profit; - SETBIT(v->load_status, LS_CARGO_PAID_FOR); + v->cargo_paid_for = v->cargo_count; } unloading_time += v->cargo_count; @@ -1422,6 +1423,7 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived) } result |= 2; v->cargo_count -= amount_unloaded; + v->cargo_paid_for -= min(amount_unloaded, v->cargo_paid_for); if (_patches.gradual_loading) continue; } @@ -1431,7 +1433,9 @@ int LoadUnloadVehicle(Vehicle *v, bool just_arrived) /* The vehicle must have been unloaded because it is either empty, or * the UNLOADING bit is already clear in v->load_status. */ CLRBIT(v->load_status, LS_CARGO_UNLOADING); - CLRBIT(v->load_status, LS_CARGO_PAID_FOR); + + /* We cannot have paid for more cargo than there is on board. */ + assert(v->cargo_paid_for <= v->cargo_count); /* don't pick up goods that we unloaded */ if (u->current_order.flags & OF_UNLOAD) continue; diff --git a/src/openttd.cpp b/src/openttd.cpp index 9377483e1..1d71d042b 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1748,6 +1748,23 @@ bool AfterLoadGame(void) } } + if (CheckSavegameVersion(45)) { + Vehicle *v; + /* Originally just the fact that some cargo had been paid for was + * stored to stop people cheating and cashing in several times. This + * wasn't enough though as it was cleared when the vehicle started + * loading again, even if it didn't actually load anything, so now the + * amount of cargo that has been paid for is stored. */ + FOR_ALL_VEHICLES(v) { + if (HASBIT(v->load_status, 2)) { + v->cargo_paid_for = v->cargo_count; + CLRBIT(v->load_status, 2); + } else { + v->cargo_paid_for = 0; + } + } + } + return true; } diff --git a/src/saveload.cpp b/src/saveload.cpp index 7b3b199f8..d694d5487 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -30,7 +30,7 @@ #include "variables.h" #include <setjmp.h> -extern const uint16 SAVEGAME_VERSION = 44; +extern const uint16 SAVEGAME_VERSION = 45; uint16 _sl_version; /// the major savegame version identifier byte _sl_minor_version; /// the minor savegame version, DO NOT USE! diff --git a/src/vehicle.cpp b/src/vehicle.cpp index cdaea63aa..8ee5d62b2 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3029,6 +3029,7 @@ extern const SaveLoad _common_veh_desc[] = { SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION), SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), + SLE_CONDVAR(Vehicle, cargo_paid_for, SLE_UINT16, 45, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, load_status, SLE_UINT8, 40, SL_MAX_VERSION), SLE_VAR(Vehicle, profit_this_year, SLE_INT32), diff --git a/src/vehicle.h b/src/vehicle.h index 8719ba91d..a23133188 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -31,7 +31,7 @@ enum VehStatus { enum LoadStatus { LS_LOADING_FINISHED, LS_CARGO_UNLOADING, - LS_CARGO_PAID_FOR, + /* LS_CARGO_PAID_FOR was here until savegame version 45. */ }; /* Effect vehicle types */ @@ -238,6 +238,7 @@ struct Vehicle { bool leave_depot_instantly; // NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace uint16 load_unload_time_rem; + uint16 cargo_paid_for; // How much of the cargo currently on board has been paid for. byte load_status; int32 profit_this_year; |