Mercurial > hg > openttd
changeset 6616:ce5601a32593 draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 14 May 2007 16:07:05 +0000 |
parents | 506e689af746 |
children | bfd51a1acb47 |
files | src/economy.cpp src/economy.h src/vehicle.cpp src/vehicle.h |
diffstat | 4 files changed, 27 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -1482,8 +1482,13 @@ * 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 @@ 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 @@ } } +/** + * 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();
--- a/src/economy.h +++ b/src/economy.h @@ -69,5 +69,6 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount); void VehiclePayment(Vehicle *front_v); +void LoadUnloadStation(Station *st); #endif /* ECONOMY_H */
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -659,8 +659,6 @@ 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 @@ _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 @@ { 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();