From c7c65cf5bc32fc6c4fe42f1839745097643c5212 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 16 Dec 2008 22:02:12 +0000 Subject: (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. --- src/engine.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/engine.cpp') 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 -- cgit v1.2.3-54-g00ecf