Mercurial > hg > openttd
changeset 4322:635e7432d98e draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 20 Aug 2006 12:39:17 +0000 |
parents | 1ac76a0acb36 |
children | 26b70a40ebcd |
files | ai/default/default.c date.h engine.c newgrf.c newgrf_engine.c newgrf_spritegroup.c table/engines.h |
diffstat | 7 files changed, 30 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ai/default/default.c +++ b/ai/default/default.c @@ -1457,7 +1457,7 @@ { uint16 r = (uint16)Random(); - if (r >= 0x2AAA || _date < 0x3912) { + if (r >= 0x2AAA || _date < 0x3912 + DAYS_TILL_ORIGINAL_BASE_YEAR) { AiWantPassengerAircraftRoute(p); } else { AiWantOilRigAircraftRoute(p);
--- a/date.h +++ b/date.h @@ -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
--- a/engine.c +++ b/engine.c @@ -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 @@ 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();
--- a/newgrf.c +++ b/newgrf.c @@ -1007,7 +1007,7 @@ 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 @@ /* 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 */
--- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -553,7 +553,7 @@ 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 */ }
--- a/newgrf_spritegroup.c +++ b/newgrf_spritegroup.c @@ -76,7 +76,7 @@ /* 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;
--- 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