From a00371c8db9d3b944d901ea0468eb58fe51418a7 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Tue, 29 Apr 2008 21:31:29 +0000 Subject: (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist. --- src/articulated_vehicles.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/articulated_vehicles.cpp') diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index ef63e71b5..d6e1a97d2 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -11,6 +11,19 @@ #include "newgrf_engine.h" #include "vehicle_func.h" +static EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id) +{ + const Engine *e = NULL; + FOR_ALL_ENGINES(e) { + if (e->grffile != file) continue; + if (e->type != type) continue; + if (e->internal_id != internal_id) continue; + + return e->index; + } + + return INVALID_ENGINE; +} uint CountArticulatedParts(EngineID engine_type, bool purchase_window) { @@ -54,7 +67,7 @@ uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type) uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, i, 0, engine, NULL); if (callback == CALLBACK_FAILED || GB(callback, 0, 8) == 0xFF) break; - EngineID artic_engine = GetFirstEngineOfType(type) + GB(callback, 0, 7); + EngineID artic_engine = GetNewEngineID(GetEngineGRF(engine), type, GB(callback, 0, 7)); if (type == VEH_TRAIN) { const RailVehicleInfo *rvi = RailVehInfo(artic_engine); @@ -88,7 +101,7 @@ void AddArticulatedParts(Vehicle **vl, VehicleType type) Vehicle *previous = u; u = u->Next(); - EngineID engine_type = GetFirstEngineOfType(type) + GB(callback, 0, 7); + EngineID engine_type = GetNewEngineID(GetEngineGRF(v->engine_type), type, GB(callback, 0, 7)); bool flip_image = HasBit(callback, 7); /* get common values from first engine */ -- cgit v1.2.3-54-g00ecf