changeset 17246:f98b40bd4ccb draft

(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
author frosch <frosch@openttd.org>
date Sat, 05 Feb 2011 20:37:00 +0000
parents e714bac51f24
children 5221777879f1
files src/engine.cpp src/engine_base.h src/strings.cpp
diffstat 3 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -145,6 +145,15 @@
 }
 
 /**
+ * Checks whether the engine spec is properly initialised.
+ * @return true if enabled
+ */
+bool Engine::IsEnabled() const
+{
+	return this->info.string_id != STR_NEWGRF_INVALID_ENGINE;
+}
+
+/**
  * Determines whether an engine can carry something.
  * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargos is available in the climate.
  * @return true if the vehicle can carry something.
@@ -935,7 +944,7 @@
 	/* check if it's available */
 	if (!HasBit(e->company_avail, company)) return false;
 
-	if (e->info.string_id == STR_NEWGRF_INVALID_ENGINE) return false;
+	if (!e->IsEnabled()) return false;
 
 	if (type == VEH_TRAIN) {
 		/* Check if the rail type is available to this company */
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -61,6 +61,7 @@
 	Engine();
 	Engine(VehicleType type, EngineID base);
 	~Engine();
+	bool IsEnabled() const;
 
 	/**
 	 * Determines the default cargo type of an engine.
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1110,7 +1110,7 @@
 
 				assert(e != NULL);
 
-				if (e->name != NULL && e->info.string_id != STR_NEWGRF_INVALID_ENGINE) {
+				if (e->name != NULL && e->IsEnabled()) {
 					buff = strecpy(buff, e->name, last);
 				} else {
 					buff = GetStringWithArgs(buff, e->info.string_id, NULL, NULL, last);