changeset 4767:aad258e85ca1 draft

(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old -Fix: when retiring an engine design, invalidate the build windows and invalidate the build window data -Fix: mark build windows dirty when engine reliability changes
author bjarni <bjarni@openttd.org>
date Sat, 07 Oct 2006 15:04:22 +0000
parents 7d88c1b405e7
children a30c96da2104
files engine.c train_gui.c
diffstat 2 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/engine.c
+++ b/engine.c
@@ -110,18 +110,21 @@
 	if (age < e->duration_phase_1) {
 		uint start = e->reliability_start;
 		e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
-	} else if ((age -= e->duration_phase_1) < e->duration_phase_2) {
+	} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _patches.never_expire_vehicles) {
+		/* We are at the peak of this engines life. It will have max reliability.
+		 * This is also true if the engines never expire. They will not go bad over time */
 		e->reliability = e->reliability_max;
 	} else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
 		uint max = e->reliability_max;
 		e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
 	} else {
-		// time's up for this engine
-		// make it either available to all players (if never_expire_vehicles is enabled and if it was available earlier)
-		// or disable this engine completely
-		e->player_avail = (_patches.never_expire_vehicles && e->player_avail)? -1 : 0;
+		/* time's up for this engine.
+		 * We will now completely retire this design */
+		e->player_avail = 0;
 		e->reliability = e->reliability_final;
+		InvalidateWindowClassesData(WC_BUILD_VEHICLE); // Kick this engine out of the lists
 	}
+	InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
 }
 
 void AddTypeToEngines(void)
--- a/train_gui.c
+++ b/train_gui.c
@@ -276,6 +276,27 @@
 	if (WP(w,buildtrain_d).data_invalidated) {
 		GenerateBuildList(&WP(w,buildtrain_d).engines, &WP(w,buildtrain_d).num_engines, &WP(w,buildtrain_d).wagons, &WP(w,buildtrain_d).num_wagons, WP(w,buildtrain_d).railtype);
 		WP(w,buildtrain_d).data_invalidated = false;
+
+		/* Make sure that the selected engine is still in the list*/
+		if (WP(w,buildtrain_d).sel_engine != INVALID_ENGINE) {
+			int i;
+			bool found = false;
+			if (HASBIT(WP(w,buildtrain_d).show_engine_wagon, 0)) {
+				for (i = 0; i < WP(w,buildtrain_d).num_engines; i++) {
+					if (WP(w,buildtrain_d).sel_engine != WP(w,buildtrain_d).engines[i]) continue;
+					found = true;
+					break;
+				}
+			}
+			if (!found && HASBIT(WP(w,buildtrain_d).show_engine_wagon, 1)) {
+				for (i = 0; i < WP(w,buildtrain_d).num_wagons; i++) {
+					if (WP(w,buildtrain_d).sel_engine != WP(w,buildtrain_d).wagons[i]) continue;
+					found = true;
+					break;
+				}
+			}
+			if (!found) WP(w,buildtrain_d).sel_engine = INVALID_ENGINE;
+		}
 	}
 
 	if (HASBIT(WP(w,buildtrain_d).show_engine_wagon, 0)) scrollcount += WP(w,buildtrain_d).num_engines;
@@ -330,6 +351,7 @@
 			WP(w,buildtrain_d).wagons  = NULL;
 			WP(w,buildtrain_d).show_engine_wagon = 3;
 			WP(w,buildtrain_d).data_invalidated  = true;
+			WP(w,buildtrain_d).sel_engine        = INVALID_ENGINE;
 			break;
 
 		case WE_INVALIDATE_DATA: