summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-05-10 23:10:23 +0000
committerpeter1138 <peter1138@openttd.org>2007-05-10 23:10:23 +0000
commitf7ccb6e31e40513e99241d8336ab36b694ef116d (patch)
treea30307b030b6015740856c49fa80fa650b404868
parent304075b3890b5fb9b060d007f10e5de66a19fdae (diff)
downloadopenttd-f7ccb6e31e40513e99241d8336ab36b694ef116d.tar.xz
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
-rw-r--r--src/engine.cpp10
-rw-r--r--src/engine.h1
-rw-r--r--src/newgrf.cpp25
-rw-r--r--src/table/engines.h8
4 files changed, 31 insertions, 13 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 04f30689a..e4d1e6e8d 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -70,6 +70,16 @@ static void CalcEngineReliability(Engine *e)
{
uint age = e->age;
+ /* Check for early retirement */
+ if (e->player_avail != 0 && !_patches.never_expire_vehicles) {
+ uint retire_early = EngInfo(e - _engines)->retire_early;
+ if (retire_early > 0 && age >= e->duration_phase_1 + e->duration_phase_2 - retire_early * 12) {
+ /* Early retirement is enabled and we're past the date... */
+ e->player_avail = 0;
+ AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
+ }
+ }
+
if (age < e->duration_phase_1) {
uint start = e->reliability_start;
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
diff --git a/src/engine.h b/src/engine.h
index 0275b1d68..641299697 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -105,6 +105,7 @@ struct EngineInfo {
byte refit_cost;
byte misc_flags;
byte callbackmask;
+ byte retire_early; ///< Number of years early to retire vehicle
};
struct Engine {
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 79a19fa97..b5eafd4d1 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -531,6 +531,10 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf);
break;
+ case 0x26: // Retire vehicle early
+ FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
+ break;
+
case 0x27: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
@@ -553,7 +557,6 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
/* @todo air drag and retire vehicle early
* Fall-through for unimplemented one byte long properties. */
case 0x20: // Air drag
- case 0x26: // Retire vehicle early
FOR_EACH_OBJECT grf_load_byte(&buf);
ret = true;
break;
@@ -650,6 +653,10 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
break;
+ case 0x1B: // Retire vehicle early
+ FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
+ break;
+
case 0x1C: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
@@ -671,7 +678,6 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
case 0x18: // Tractive effort
case 0x19: // Air drag
- case 0x1B: // Retire vehicle early
/* @todo */
FOR_EACH_OBJECT grf_load_byte(&buf);
ret = true;
@@ -758,6 +764,10 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
break;
+ case 0x16: // Retire vehicle early
+ FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
+ break;
+
case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
@@ -779,7 +789,6 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
case 0x14: // Ocean speed fraction
case 0x15: // Canal speed fraction
- case 0x16: // Retire vehicle early
/* @todo */
FOR_EACH_OBJECT grf_load_byte(&buf);
ret = true;
@@ -871,6 +880,10 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
break;
+ case 0x16: // Retire vehicle early
+ FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
+ break;
+
case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
@@ -890,12 +903,6 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
break;
- case 0x16: // Retire vehicle early
- /* @todo */
- FOR_EACH_OBJECT grf_load_byte(&buf);
- ret = true;
- break;
-
default:
ret = true;
break;
diff --git a/src/table/engines.h b/src/table/engines.h
index 94037d21e..9ce78c497 100644
--- a/src/table/engines.h
+++ b/src/table/engines.h
@@ -19,7 +19,7 @@
* @note the 0x80 in parameter b sets the "is carriage bit"
* @note the 5 between d and e is the load amount
*/
-#define MK(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, e, 0, 8, 0, 0 }
+#define MK(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, e, 0, 8, 0, 0, 0 }
/** Writes the properties of a train carriage into the EngineInfo struct.
* @param a Introduction date
@@ -30,7 +30,7 @@
* @see MK
* @note the 5 between d and e is the load amount
*/
-#define MW(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b | 0x80, 5, e, 0, 8, 0, 0 }
+#define MW(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b | 0x80, 5, e, 0, 8, 0, 0, 0 }
/** Writes the properties of a ship into the EngineInfo struct.
* @param a Introduction date
@@ -41,7 +41,7 @@
* @see MK
* @note the 10 between d and e is the load amount
*/
-#define MS(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, e, 0, 8, 0, 0 }
+#define MS(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, e, 0, 8, 0, 0, 0 }
/** Writes the properties of an aeroplane into the EngineInfo struct.
* @param a Introduction date
@@ -52,7 +52,7 @@
* @see MK
* @note the 20 between d and e is the load amount
*/
-#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, 0, 8, 0, 0 }
+#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, 0, 8, 0, 0, 0 }
// Climates
// T = Temperate