summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-01-06 22:31:58 +0000
committertruelight <truelight@openttd.org>2005-01-06 22:31:58 +0000
commit63e97754fbf907cfefd277087bfbac5e0d4434e8 (patch)
tree254702245ba43d006f4823111d0c2c592fb701ca /misc.c
parenta4111363c0def2ccec66ef28b5e8169e8a2df2f0 (diff)
downloadopenttd-63e97754fbf907cfefd277087bfbac5e0d4434e8.tar.xz
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
(in prepare of dynamic arrays): - DEREF_XXX is changed into GetXXX - All direct call are directed via GetXXX - struct Industry has now an index-field - ENUM'd some stuff - Replaced home built loops with FOR_ALL_XXX - Added _stations_size, _vehicles_size, ... which gives the length of the array (which will be dynamic in the near future) - Changed lengtof(XXX) to _XXX_size (e.g. _stations_size) - Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX) - Made the sort-functions of all 4 dynamic - Made all 4 Initialize functions more of the same - Some minor tab-fixing and stuff (tnx to Tron for proof-reading my 100kb patch ;)) Note for all: please do NOT directly call _stations, _vehicles, _towns and _industries, but use the right wrapper to access them. Thank you. Ps: please also do not use 'v++', where v is of type Vehicle *.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/misc.c b/misc.c
index b0b9d0eb6..00f8e5739 100644
--- a/misc.c
+++ b/misc.c
@@ -607,6 +607,7 @@ static const uint16 _autosave_months[] = {
void IncreaseDate()
{
+ const int vehicles_per_day = (1 << (sizeof(_date_fract) * 8)) / 885;
int i,ctr,t;
YearMonthDay ymd;
@@ -621,15 +622,15 @@ void IncreaseDate()
65536 / 885 = 74; 74x12 = 888. So max 888. Any vehicles above that were not _on_new_vehicle_day_proc'd
eg. aged.
So new code updates it for max vehicles.
- (NUM_VEHICLES / maximum number of times ctr is incremented before reset ) + 1 (to get last vehicles too)
+ (_vehicles_size / maximum number of times ctr is incremented before reset ) + 1 (to get last vehicles too)
max size of _date_fract / 885 (added each tick) is number of times before ctr is reset.
Calculation might look complicated, but compiler just replaces it with 35, so that's ok
*/
ctr = _vehicle_id_ctr_day;
- for(i=0; i!=(NUM_VEHICLES / ((1<<sizeof(_date_fract)*8) / 885)) + 1 && ctr != lengthof(_vehicles); i++) {
- Vehicle *v = &_vehicles[ctr++];
- if ((t=v->type) != 0)
+ for (i = 0; i != (_vehicles_size / vehicles_per_day) + 1 && ctr != _vehicles_size; i++) {
+ Vehicle *v = GetVehicle(ctr++);
+ if ((t = v->type) != 0)
_on_new_vehicle_day_proc[t - 0x10](v);
}
_vehicle_id_ctr_day = ctr;
@@ -637,7 +638,8 @@ void IncreaseDate()
/* increase day, and check if a new day is there? */
_tick_counter++;
- if ( (_date_fract += 885) >= 885)
+ _date_fract += 885;
+ if (_date_fract >= 885)
return;
/* yeah, increse day counter and call various daily loops */