summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-05-14 16:07:05 +0000
committerrubidium <rubidium@openttd.org>2007-05-14 16:07:05 +0000
commitc7d57379fbdda52590cddb83240934da6b5e8b21 (patch)
tree689c15a9e4c69b6092adb8178a4209a3fc4ed27b
parentd7b4fb80d0e14ca3f8d56cda920e7f0d4e81419d (diff)
downloadopenttd-c7d57379fbdda52590cddb83240934da6b5e8b21.tar.xz
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
-rw-r--r--src/economy.cpp23
-rw-r--r--src/economy.h1
-rw-r--r--src/vehicle.cpp19
-rw-r--r--src/vehicle.h2
4 files changed, 27 insertions, 18 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index bb90cb488..91679412c 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1482,8 +1482,13 @@ void VehiclePayment(Vehicle *front_v)
* Loads/unload the vehicle if possible.
* @param v the vehicle to be (un)loaded
*/
-void LoadUnloadVehicle(Vehicle *v)
+static void LoadUnloadVehicle(Vehicle *v)
{
+ assert(v->current_order.type == OT_LOADING);
+
+ /* We have not waited enough time till the next round of loading/unloading */
+ if (--v->load_unload_time_rem != 0) return;
+
int unloading_time = 0;
Vehicle *u = v;
int result = 0;
@@ -1496,8 +1501,6 @@ void LoadUnloadVehicle(Vehicle *v)
uint32 cargo_full = 0;
int total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step
- assert(v->current_order.type == OT_LOADING);
-
v->cur_speed = 0;
StationID last_visited = v->last_station_visited;
@@ -1706,6 +1709,20 @@ void LoadUnloadVehicle(Vehicle *v)
}
}
+/**
+ * Load/unload the vehicles in this station according to the order
+ * they entered.
+ * @param st the station to do the loading/unloading for
+ */
+void LoadUnloadStation(Station *st)
+{
+ std::list<Vehicle *>::iterator iter;
+ for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
+ Vehicle *v = *iter;
+ if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v);
+ }
+}
+
void PlayersMonthlyLoop()
{
PlayersGenStatistics();
diff --git a/src/economy.h b/src/economy.h
index a61bab709..504dae3e1 100644
--- a/src/economy.h
+++ b/src/economy.h
@@ -69,5 +69,6 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount);
void VehiclePayment(Vehicle *front_v);
+void LoadUnloadStation(Station *st);
#endif /* ECONOMY_H */
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 9048d3bd0..0b7916d29 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -659,8 +659,6 @@ static VehicleTickProc* _vehicle_tick_procs[] = {
void CallVehicleTicks()
{
- Vehicle *v;
-
#ifdef ENABLE_NETWORK
/* hotfix for desync problem:
* for MP games invalidate the YAPF cache every tick to keep it exactly the same on the server and all clients */
@@ -671,6 +669,10 @@ void CallVehicleTicks()
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick
+ Station *st;
+ FOR_ALL_STATIONS(st) LoadUnloadStation(st);
+
+ Vehicle *v;
FOR_ALL_VEHICLES(v) {
_vehicle_tick_procs[v->type](v);
@@ -2933,17 +2935,8 @@ void Vehicle::HandleLoading(bool mode)
{
switch (this->current_order.type) {
case OT_LOADING: {
- /* Not the first call for this tick */
- if (mode) return;
-
- /* We have not waited enough time till the next round of loading/unloading */
- if (--this->load_unload_time_rem) return;
-
- /* Load/unload the vehicle; when it actually did something
- * we do not leave the station. */
- LoadUnloadVehicle(this);
-
- if (!HASBIT(this->vehicle_flags, VF_LOADING_FINISHED)) return;
+ /* Not the first call for this tick, or still loading */
+ if (mode || !HASBIT(this->vehicle_flags, VF_LOADING_FINISHED)) return;
this->PlayLeaveStationSound();
diff --git a/src/vehicle.h b/src/vehicle.h
index 2eab1d0cf..ccd918521 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -521,8 +521,6 @@ void ShowAircraftViewWindow(const Vehicle* v);
UnitID GetFreeUnitNumber(byte type);
-void LoadUnloadVehicle(Vehicle *v);
-
void TrainConsistChanged(Vehicle *v);
void TrainPowerChanged(Vehicle *v);
int32 GetTrainRunningCost(const Vehicle *v);