summaryrefslogtreecommitdiff
path: root/src/economy.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2010-08-15 22:37:30 +0000
committermichi_cc <michi_cc@openttd.org>2010-08-15 22:37:30 +0000
commita994c1ef71adecc7bc1968d31ab0bcbcf4912d24 (patch)
tree92e0b6f9732546ee858205b7237bbade62cf9c22 /src/economy.cpp
parent236737b2f29cc9ddd129a963d6a312a5c4ffe78b (diff)
downloadopenttd-a994c1ef71adecc7bc1968d31ab0bcbcf4912d24.tar.xz
(svn r20506) -Change: Vehicles will now stop loading after a load cycle that loaded less than possible, unless it's a full load order. This should improve behaviour with gradual loading and cargo continuously trickling in.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r--src/economy.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index ad977a624..4ac69da14 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1161,6 +1161,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
bool completely_emptied = true;
bool anything_unloaded = false;
bool anything_loaded = false;
+ bool full_load_amount = false;
uint32 cargo_not_full = 0;
uint32 cargo_full = 0;
@@ -1239,8 +1240,8 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
continue;
}
- /* Do not pick up goods when we have no-load set. */
- if (u->current_order.GetLoadType() & OLFB_NO_LOAD) continue;
+ /* Do not pick up goods when we have no-load set or loading is stopped. */
+ if (u->current_order.GetLoadType() & OLFB_NO_LOAD || HasBit(u->vehicle_flags, VF_STOP_LOADING)) continue;
/* update stats */
int t;
@@ -1272,12 +1273,17 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
}
if (cap > count) cap = count;
- if (_settings_game.order.gradual_loading) cap = min(cap, load_amount);
+ if (_settings_game.order.gradual_loading) {
+ cap = min(cap, load_amount);
+ cap_left = min(cap_left, load_amount);
+ }
if (_settings_game.order.improved_load) {
/* Don't load stuff that is already 'reserved' for other vehicles */
cap = min((uint)cargo_left[v->cargo_type], cap);
+ count = cargo_left[v->cargo_type];
cargo_left[v->cargo_type] -= cap;
}
+ if (count >= (uint)cap_left) full_load_amount = true;
if (v->cargo.Empty()) TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
@@ -1330,6 +1336,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
if (!anything_unloaded) delete payment;
+ ClrBit(u->vehicle_flags, VF_STOP_LOADING);
if (anything_loaded || anything_unloaded) {
if (_settings_game.order.gradual_loading) {
/* The time it takes to load one 'slice' of cargo or passengers depends
@@ -1338,6 +1345,8 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
unloading_time = gradual_loading_wait_time[v->type];
}
+ /* We loaded less cargo than possible and it's not full load, stop loading. */
+ if (!anything_unloaded && !full_load_amount && !(v->current_order.GetLoadType() & OLFB_FULL_LOAD)) SetBit(u->vehicle_flags, VF_STOP_LOADING);
} else {
bool finished_loading = true;
if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) {