# HG changeset patch # User ludde # Date 1121604275 0 # Node ID 9bbad972eb2a0dc33fde8b776af86d692fe20367 # Parent 36f1c717773020329a2ca331972f3587102d3781 (svn r2600) Fix: [vehicles] Fix problem with vehicle loop not distributing the calls evenly over the day. diff -r 36f1c7177730 -r 9bbad972eb2a misc.c --- a/misc.c Sun Jul 17 12:29:33 2005 +0000 +++ b/misc.c Sun Jul 17 12:44:35 2005 +0000 @@ -138,7 +138,6 @@ _tick_counter = 0; _date_fract = 0; _cur_tileloop_tile = 0; - _vehicle_id_ctr_day = 0; { uint starting = ConvertIntDate(_patches.starting_date); @@ -485,40 +484,21 @@ }; /** - * Runs the day_proc of 'amount' vehicles. + * Runs the day_proc for every DAY_TICKS vehicle starting at daytick. */ -static void RunVehicleDayProc(uint amount) +static void RunVehicleDayProc(uint daytick) { - Vehicle *v; - VehicleID ctr; - uint i; - - ctr = _vehicle_id_ctr_day; + uint i, total = _vehicle_pool.total_items; - /* If the CTR is already over the size of the pool, don't even run the for-loop */ - if (ctr >= GetVehiclePoolSize()) { - _vehicle_id_ctr_day += amount; - return; - } - - for (i = 0; i < amount; i++, ctr++) { - /* Skip non-existing vehicles */ - if (ctr >= GetVehiclePoolSize()) { - _vehicle_id_ctr_day += amount; - return; - } - - v = GetVehicle(ctr); + for (i = daytick; i < total; i += DAY_TICKS) { + Vehicle *v = GetVehicle(i); if (v->type != 0) _on_new_vehicle_day_proc[v->type - 0x10](v); } - - _vehicle_id_ctr_day = ctr; } void IncreaseDate(void) { - uint32 total_vehicles = (1 << _vehicle_pool.block_size_bits) * _vehicle_pool.max_blocks; YearMonthDay ymd; if (_game_mode == GM_MENU) { @@ -526,7 +506,7 @@ return; } - RunVehicleDayProc(total_vehicles / DAY_TICKS); + RunVehicleDayProc(_date_fract); /* increase day, and check if a new day is there? */ _tick_counter++; @@ -539,13 +519,6 @@ /* yeah, increse day counter and call various daily loops */ _date++; - /* We have a hole because of rounding errors, between the last vehicle checked and the max amount - * of vehicles.. correct for that problem here */ - RunVehicleDayProc(total_vehicles - _vehicle_id_ctr_day); - - assert(_vehicle_id_ctr_day == total_vehicles); - _vehicle_id_ctr_day = 0; - TextMessageDailyLoop(); DisasterDailyLoop(); diff -r 36f1c7177730 -r 9bbad972eb2a oldloader.c --- a/oldloader.c Sun Jul 17 12:29:33 2005 +0000 +++ b/oldloader.c Sun Jul 17 12:44:35 2005 +0000 @@ -422,8 +422,6 @@ } } } - - _vehicle_id_ctr_day = 0; } /* diff -r 36f1c7177730 -r 9bbad972eb2a variables.h --- a/variables.h Sun Jul 17 12:29:33 2005 +0000 +++ b/variables.h Sun Jul 17 12:44:35 2005 +0000 @@ -62,7 +62,7 @@ // Amount of game ticks VARDEF uint16 _tick_counter; -// Used when calling OnNewDay +// This one is not used anymore. VARDEF VehicleID _vehicle_id_ctr_day; // Skip aging of cargo? diff -r 36f1c7177730 -r 9bbad972eb2a vehicle.c --- a/vehicle.c Sun Jul 17 12:29:33 2005 +0000 +++ b/vehicle.c Sun Jul 17 12:44:35 2005 +0000 @@ -2149,9 +2149,6 @@ } } } - - if (_sl.full_version < 0x0B01) - _vehicle_id_ctr_day = 0; } const ChunkHandler _veh_chunk_handlers[] = {