changeset 15242:bcd1b7d5d3f9 draft

(svn r19877) -Change: Name invalid engines, cargos and industries 'invalid', if the player removed the supplying NewGRFs.
author frosch <frosch@openttd.org>
date Fri, 21 May 2010 20:51:00 +0000
parents a78f9f09cee9
children 4b4e245ea358
files src/lang/english.txt src/newgrf.cpp src/strings.cpp
diffstat 3 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2433,6 +2433,13 @@
 STR_NEWGRF_BUGGY_ARTICULATED_CARGO                              :{WHITE}Cargo/refit information for '{1:ENGINE}' differs from purchase list after construction. This might cause autorenew/-replace to fail refitting correctly.
 STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK                    :{WHITE}'{1:STRING}' caused an endless loop in the production callback.
 
+# 'User removed essential NewGRFs'-placeholders for stuff without specs.
+STR_NEWGRF_INVALID_CARGO                                        :<invalid cargo>
+STR_NEWGRF_INVALID_CARGO_ABBREV                                 :??
+STR_NEWGRF_INVALID_CARGO_QUANTITY                               :{COMMA} of <invalid cargo>
+STR_NEWGRF_INVALID_ENGINE                                       :<invalid engine>
+STR_NEWGRF_INVALID_INDUSTRYTYPE                                 :<invalid industry>
+
 # Sign list window
 STR_SIGN_LIST_CAPTION                                           :{WHITE}Sign List - {COMMA} Sign{P "" s}
 
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6455,6 +6455,34 @@
 	}
 }
 
+/** Check for invalid engines */
+static void FinaliseEngineArray()
+{
+	Engine *e;
+
+	FOR_ALL_ENGINES(e) {
+		if (e->grffile == NULL) {
+			const EngineIDMapping &eid = _engine_mngr[e->index];
+			if (eid.grfid != INVALID_GRFID || eid.internal_id != eid.substitute_id) {
+				e->info.string_id = STR_NEWGRF_INVALID_ENGINE;
+			}
+		}
+	}
+}
+
+/** Check for invalid cargos */
+static void FinaliseCargoArray()
+{
+	for (CargoID c = 0; c < NUM_CARGO; c++) {
+		CargoSpec *cs = CargoSpec::Get(c);
+		if (!cs->IsValid()) {
+			cs->name = cs->name_single = cs->units_volume = STR_NEWGRF_INVALID_CARGO;
+			cs->quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
+			cs->abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
+		}
+	}
+}
+
 /** Add all new houses to the house array. House properties can be set at any
  * time in the GRF file, so we can only add a house spec to the house array
  * after the file has finished loading. We also need to check the dates, due to
@@ -6583,6 +6611,9 @@
 				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
 			}
 		}
+		if (!indsp->enabled) {
+			indsp->name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
+		}
 	}
 }
 
@@ -6963,9 +6994,15 @@
 	}
 	_grf_line_to_action6_sprite_override.clear();
 
+	/* Polish cargos */
+	FinaliseCargoArray();
+
 	/* Pre-calculate all refit masks after loading GRF files. */
 	CalculateRefitMasks();
 
+	/* Polish engines */
+	FinaliseEngineArray();
+
 	/* Set the block size in the depot windows based on vehicle sprite sizes */
 	InitDepotWindowBlockSizes();
 
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -998,7 +998,7 @@
 
 				assert(e != NULL);
 
-				if (e->name != NULL) {
+				if (e->name != NULL && e->info.string_id != STR_NEWGRF_INVALID_ENGINE) {
 					buff = strecpy(buff, e->name, last);
 				} else {
 					buff = GetStringWithArgs(buff, e->info.string_id, NULL, last);