diff options
author | rubidium <rubidium@openttd.org> | 2006-08-20 12:39:17 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2006-08-20 12:39:17 +0000 |
commit | e159ada7a2a0367c99e94ee07b1d439e7ffacc0b (patch) | |
tree | 33714b71b0f9fc1c73fccdd4b1ed25321adc99fa | |
parent | 5fb6c9e1cc073ad96d62efc423e87d79d38d435a (diff) | |
download | openttd-e159ada7a2a0367c99e94ee07b1d439e7ffacc0b.tar.xz |
(svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
-Cleanup: use DAYS_TILL_ORIGINAL_BASE_YEAR where the date variables are in the old date format and conversions are needed.
-Cleanup: replace one (forgotten) instance of uint16 with Date.
-rw-r--r-- | ai/default/default.c | 2 | ||||
-rw-r--r-- | date.h | 21 | ||||
-rw-r--r-- | engine.c | 4 | ||||
-rw-r--r-- | newgrf.c | 4 | ||||
-rw-r--r-- | newgrf_engine.c | 2 | ||||
-rw-r--r-- | newgrf_spritegroup.c | 2 | ||||
-rw-r--r-- | table/engines.h | 4 |
7 files changed, 30 insertions, 9 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index 752d2cac9..54a550599 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -1457,7 +1457,7 @@ static void AiWantAircraftRoute(Player *p) { uint16 r = (uint16)Random(); - if (r >= 0x2AAA || _date < 0x3912) { + if (r >= 0x2AAA || _date < 0x3912 + DAYS_TILL_ORIGINAL_BASE_YEAR) { AiWantPassengerAircraftRoute(p); } else { AiWantOilRigAircraftRoute(p); @@ -8,7 +8,28 @@ */ #define DAY_TICKS 74 +/* + * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are + * primarily used for loading newgrf and savegame data and returning some + * newgrf (callback) functions that were in the original (TTD) inherited + * format, where '_date == 0' meant that it was 1920-01-01. + */ + +/** The minimum starting year/base year of the original TTD */ +#define ORIGINAL_BASE_YEAR 1920 +/** The maximum year of the original TTD */ +#define ORIGINAL_MAX_YEAR 2090 + +/** + * The offset in days from the '_date == 0' till + * 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)' + */ +#define DAYS_TILL_ORIGINAL_BASE_YEAR 0 + +/* Temporary value to make transition to full past 2090 easier/more clear */ #define BASE_YEAR 1920 + +/* The absolute minimum & maximum years in OTTD */ #define MIN_YEAR 1920 #define MAX_YEAR 2090 @@ -6,7 +6,6 @@ #include "functions.h" #include "table/strings.h" #include "engine.h" -#include "table/engines.h" #include "gfx.h" #include "player.h" #include "command.h" @@ -17,6 +16,7 @@ #include "train.h" #include "newgrf_cargo.h" #include "date.h" +#include "table/engines.h" EngineInfo _engine_info[TOTAL_NUM_ENGINES]; RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; @@ -140,7 +140,7 @@ void StartupEngines(void) Engine *e; const EngineInfo *ei; /* Aging of vehicles stops, so account for that when starting late */ - const uint16 aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1)); + const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1)); SetupEngineNames(); @@ -1007,7 +1007,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int switch (prop) { case 0x08: /* Year of availability */ - FOR_EACH_OBJECT _bridge[brid + i].avail_year = BASE_YEAR + grf_load_byte(&buf); + FOR_EACH_OBJECT _bridge[brid + i].avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf); break; case 0x09: /* Minimum length */ @@ -1177,7 +1177,7 @@ static void FeatureChangeInfo(byte *buf, int len) /* Common properties for vehicles */ switch (prop) { case 0x00: /* Introduction date */ - FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf); + FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR; break; case 0x02: /* Decay speed */ diff --git a/newgrf_engine.c b/newgrf_engine.c index 90b7f1e82..8413770d5 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -553,7 +553,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x43: return _current_player; /* Owner information */ case 0x46: return 0; /* Motion counter */ case 0x48: return GetVehicleTypeInfo(object->u.vehicle.self_type); /* Vehicle Type Info */ - case 0xC4: return clamp(_cur_year, BASE_YEAR, MAX_YEAR) - BASE_YEAR; /* Build year */ + case 0xC4: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; /* Build year */ case 0xDA: return INVALID_VEHICLE; /* Next vehicle */ case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); /* Read GRF parameter */ } diff --git a/newgrf_spritegroup.c b/newgrf_spritegroup.c index f6e0e37bb..601116e7a 100644 --- a/newgrf_spritegroup.c +++ b/newgrf_spritegroup.c @@ -76,7 +76,7 @@ static inline uint32 GetVariable(const ResolverObject *object, byte variable, by /* Return common variables */ switch (variable) { case 0x00: return _date; - case 0x01: return clamp(_cur_year, BASE_YEAR, MAX_YEAR) - BASE_YEAR; + case 0x01: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; case 0x02: return _cur_month; case 0x03: return _opt.landscape; case 0x09: return _date_fract; diff --git a/table/engines.h b/table/engines.h index 9365c7f8c..f468f0029 100644 --- a/table/engines.h +++ b/table/engines.h @@ -15,7 +15,7 @@ * @param e Rail Type of the vehicle * @param f Bitmask of the climates */ -#define MK(a, b, c, d, e, f) { a, b, c, d, e, f, 0, 8, 0, 0 } +#define MK(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, b, c, d, e, f, 0, 8, 0, 0 } /** Writes the properties of a train carriage into the EngineInfo struct. * @see EngineInfo * @param a Introduction date @@ -23,7 +23,7 @@ * @param f Bitmask of the climates * @note the 0x80 in parameter b sets the "is carriage bit" */ -#define MW(a, b, c, d, e, f) { a, b | 0x80, c, d, e, f, 0, 8, 0, 0 } +#define MW(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, b | 0x80, c, d, e, f, 0, 8, 0, 0 } // Rail types // R = Conventional railway |