From f245049f91a51f13c194b0859e385ee3d2cf8156 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 18 Jul 2016 00:19:19 +0100 Subject: [PATCH] TBTR: Select most used rail-type by default, instead of first rail-type. --- src/tbtr_template_gui_main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tbtr_template_gui_main.cpp b/src/tbtr_template_gui_main.cpp index 3840baa103..219fb8ea84 100644 --- a/src/tbtr_template_gui_main.cpp +++ b/src/tbtr_template_gui_main.cpp @@ -212,7 +212,22 @@ public: // From BaseVehicleListWindow this->unitnumber_digits = dig; + /* 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, ALL_GROUP, 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->details_height = 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; this->line_height = step_h;