From 0b5698a5b0ae79bf24ef0bcc220460cbc83e16c0 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 27 Oct 2009 20:19:05 +0000 Subject: (svn r17892) -Feature [FS#1760]: automatically select the railtype with the most engines for the autoreplace window/try to avoid showing an empty autoreplace list --- src/autoreplace_gui.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 5aadee6fd..3d971350a 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -105,7 +105,7 @@ class ReplaceVehicleWindow : public Window { bool reset_sel_engine; ///< Also reset #sel_engine while updating left and/or right (#update_left and/or #update_right) and no valid engine selected. GroupID sel_group; ///< Group selected to replace. int details_height; ///< Minimal needed height of the details panels (found so far). - static RailType sel_railtype; ///< Type of rail tracks selected. + RailType sel_railtype; ///< Type of rail tracks selected. /** Figure out if an engine should be added to a list. * @param e The EngineID. @@ -198,6 +198,24 @@ class ReplaceVehicleWindow : public Window { public: ReplaceVehicleWindow(const WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window() { + if (vehicletype == VEH_TRAIN) { + /* For rail vehicles find the most used vehicle type, which is usually + * better than 'just' the first/previous vehicle type. */ + uint type_count[RAILTYPE_END]; + memset(type_count, 0, sizeof(type_count)); + + const Engine *e; + FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) { + if (e->u.rail.railveh_type == RAILVEH_WAGON) continue; + type_count[e->u.rail.railtype] += GetGroupNumEngines(_local_company, id_g, e->index); + } + + this->sel_railtype = RAILTYPE_BEGIN; + for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { + if (type_count[this->sel_railtype] < type_count[rt]) this->sel_railtype = rt; + } + } + this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool) this->engines[0].ForceRebuild(); this->engines[1].ForceRebuild(); @@ -544,8 +562,6 @@ static const WindowDesc _replace_vehicle_desc( NULL, _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets) ); -RailType ReplaceVehicleWindow::sel_railtype = RAILTYPE_RAIL; - void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype) { DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype); -- cgit v1.2.3-54-g00ecf