summaryrefslogtreecommitdiff
path: root/src/economy.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-01-31 22:33:24 +0000
committermaedhros <maedhros@openttd.org>2007-01-31 22:33:24 +0000
commit913558797ba0fdfa4862ba825f8224fd71d5b552 (patch)
treeb3824aeb166a5bf6f38d69ce8bec3354349343e6 /src/economy.cpp
parentfc9e84b04e06dbe587e34585913f1fb00fb8ee5e (diff)
downloadopenttd-913558797ba0fdfa4862ba825f8224fd71d5b552.tar.xz
(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.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r--src/economy.cpp18
1 files changed, 11 insertions, 7 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;