(svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.

This commit is contained in:
maedhros 2007-01-31 22:33:24 +00:00
parent 43242302e0
commit d8edc2bb98
5 changed files with 32 additions and 9 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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!

View File

@ -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),

View File

@ -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;