(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.
--- a/ai/default/default.c Sun Aug 20 12:09:32 2006 +0000
+++ b/ai/default/default.c Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/date.h Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/engine.c Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/newgrf.c Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/newgrf_engine.c Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/newgrf_spritegroup.c Sun Aug 20 12:39:17 2006 +0000
@@ -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 Sun Aug 20 12:09:32 2006 +0000
+++ b/table/engines.h Sun Aug 20 12:39:17 2006 +0000
@@ -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