summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-16 22:02:12 +0000
committerrubidium <rubidium@openttd.org>2008-12-16 22:02:12 +0000
commitc7c65cf5bc32fc6c4fe42f1839745097643c5212 (patch)
tree2eec1532bcceec638b2cb9b9b38dc6280ecc303a /src/engine.cpp
parentb177c5fd9e41d75a44fad47a8572fef93e29c9a0 (diff)
downloadopenttd-c7c65cf5bc32fc6c4fe42f1839745097643c5212.tar.xz
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
NOTE: it is still possible that a vehicle is marked refittable when there is nothing to refit to, e.g. when only one subcargo is available but that cannot be determined without a vehicle chain.
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 0335c8a87..f24574a94 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -559,6 +559,32 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
return true;
}
+/**
+ * Check if an engine is refittable.
+ * @param engine index of the engine to check.
+ * @return true if the engine is refittable.
+ */
+bool IsEngineRefittable(EngineID engine)
+{
+ /* check if it's an engine that is in the engine array */
+ if (!IsEngineIndex(engine)) return false;
+
+ const Engine *e = GetEngine(engine);
+
+ if (e->type == VEH_SHIP && !e->u.ship.refittable) return false;
+
+ const EngineInfo *ei = &e->info;
+ if (ei->refit_mask == 0) return false;
+
+ /* Are there suffixes?
+ * Note: This does not mean the suffixes are actually available for every consist at any time. */
+ if (HasBit(ei->callbackmask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
+
+ /* Is there any cargo except the default cargo? */
+ CargoID default_cargo = GetEngineCargoType(engine);
+ return default_cargo != CT_INVALID && ei->refit_mask != 1U << default_cargo;
+}
+
/** Get the default cargo type for a certain engine type
* @param engine The ID to get the cargo for
* @return The cargo type. CT_INVALID means no cargo capacity