summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-02-05 20:37:00 +0000
committerfrosch <frosch@openttd.org>2011-02-05 20:37:00 +0000
commitfaa2a26ae15d6a8cf986059ed504b3371e6c3e37 (patch)
tree056b2420018a00942522602d10bab15660f9b86c /src
parent2679051c68ea218ca00f4fe1bcadbbb86d4ecb22 (diff)
downloadopenttd-faa2a26ae15d6a8cf986059ed504b3371e6c3e37.tar.xz
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp11
-rw-r--r--src/engine_base.h1
-rw-r--r--src/strings.cpp2
3 files changed, 12 insertions, 2 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 6f544edf8..2a6183d7e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -145,6 +145,15 @@ Engine::~Engine()
}
/**
+ * 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 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
/* 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 */
diff --git a/src/engine_base.h b/src/engine_base.h
index 78a647139..a8e09129a 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -61,6 +61,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
Engine();
Engine(VehicleType type, EngineID base);
~Engine();
+ bool IsEnabled() const;
/**
* Determines the default cargo type of an engine.
diff --git a/src/strings.cpp b/src/strings.cpp
index 42e0a9450..1edea200b 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1110,7 +1110,7 @@ static char *FormatString(char *buff, const char *str_arg, int64 *argv, const in
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);