From ec4dbfd5655bd73307b0d58a3289429b77fb4ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Sun, 18 Feb 2024 18:20:29 +0900 Subject: [PATCH 1/9] FIX: Monthly transportation density table is too wide in some case --- gui/schedule_list.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/schedule_list.cc b/gui/schedule_list.cc index 05cfc5905b8..bb1486d1df1 100644 --- a/gui/schedule_list.cc +++ b/gui/schedule_list.cc @@ -334,7 +334,12 @@ schedule_list_gui_t::schedule_list_gui_t(player_t *player_) : cont_transport_density.set_table_layout(3,0); cont_transport_density.set_spacing(scr_size(1,1)); cont_transport_density.set_table_frame(true,true); - cont_line_info.add_component(&cont_transport_density); + cont_line_info.add_table(2, 1); + { + cont_line_info.add_component(&cont_transport_density); + cont_line_info.new_component(); + } + cont_line_info.end_table(); scroll_line_info.set_pos(scr_coord(0, 8 + SCL_HEIGHT + D_BUTTON_HEIGHT + D_BUTTON_HEIGHT + 2)); add_component(&scroll_line_info); From 7f56a78b783f0e06bd3e0a911f229fe89d27f634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Sun, 18 Feb 2024 20:58:36 +0900 Subject: [PATCH 2/9] CHG: Count overcrowded capacity by class --- gui/components/gui_vehicle_capacitybar.cc | 19 +++++++++++++++++++ gui/components/gui_vehicle_capacitybar.h | 1 + simconvoi.cc | 10 ++++++++++ simconvoi.h | 3 +++ 4 files changed, 33 insertions(+) diff --git a/gui/components/gui_vehicle_capacitybar.cc b/gui/components/gui_vehicle_capacitybar.cc index 06e672962d9..77f6e283a7f 100644 --- a/gui/components/gui_vehicle_capacitybar.cc +++ b/gui/components/gui_vehicle_capacitybar.cc @@ -147,6 +147,25 @@ uint16 gui_convoy_loading_info_t::get_overcrowded_capacity() return capacity; } +uint16 gui_convoy_loading_info_t::get_overcrowded_capacity(uint8 g_class) +{ + uint16 capacity = 0; + if (cnv.is_bound()) { + return cnv->get_overcrowded_capacity(g_class); + } + else if (line.is_bound()) { + for (uint32 i = 0; i < line->count_convoys(); i++) { + convoihandle_t const convoy = line->get_convoy(i); + // we do not want to count the capacity of depot convois + if (!convoy->in_depot()) { + capacity += convoy->get_overcrowded_capacity(g_class); + } + } + } + return capacity; +} + + uint16 gui_convoy_loading_info_t::get_total_cargo_by_fare_class(uint8 catg_index, uint8 g_class) { uint16 sum=0; diff --git a/gui/components/gui_vehicle_capacitybar.h b/gui/components/gui_vehicle_capacitybar.h index abb434a52ec..a8aa344b265 100644 --- a/gui/components/gui_vehicle_capacitybar.h +++ b/gui/components/gui_vehicle_capacitybar.h @@ -30,6 +30,7 @@ class gui_convoy_loading_info_t : public gui_aligned_container_t uint16 get_unique_fare_capacity(uint8 catg_index, uint8 g_class); uint16 get_total_cargo_by_fare_class(uint8 catg_index, uint8 g_class); uint16 get_overcrowded_capacity(); + uint16 get_overcrowded_capacity(uint8 g_class); uint16 get_overcrowded(); public: diff --git a/simconvoi.cc b/simconvoi.cc index 8dd59fa47a5..9fa6b962bcc 100644 --- a/simconvoi.cc +++ b/simconvoi.cc @@ -2459,6 +2459,16 @@ uint16 convoi_t::get_overcrowded_capacity() const return standing_capacity; } +uint16 convoi_t::get_overcrowded_capacity(uint8 fare_class) const +{ + uint16 standing_capacity = 0; + for (uint8 i = 0; i < vehicle_count; i++) + { + standing_capacity += vehicle[i]->get_overcrowded_capacity(fare_class); + } + return standing_capacity; +} + uint8 convoi_t::get_comfort(uint8 g_class, bool check_reassigned) const { uint32 comfort = 0; diff --git a/simconvoi.h b/simconvoi.h index 1c2a6156080..c5faadb3141 100644 --- a/simconvoi.h +++ b/simconvoi.h @@ -1412,7 +1412,10 @@ class convoi_t : public sync_steppable, public overtaker_t, public lazy_convoy_t // Returns the number of standing passengers (etc.) in this convoy. uint16 get_overcrowded() const; + // Returns the total regardless of fare class uint16 get_overcrowded_capacity() const; + // Returns only the overcrowded capacity for the specified fare class + uint16 get_overcrowded_capacity(uint8 fare_class) const; // @author: jamespetts // Returns the average comfort of this convoy, From bb465be91a59f9fffb656770d051ec960fc4ffd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 17:59:02 +0900 Subject: [PATCH 3/9] CODE: Reduce vehicle search loops with early returns --- simconvoi.cc | 4 ++++ simline.cc | 2 ++ 2 files changed, 6 insertions(+) diff --git a/simconvoi.cc b/simconvoi.cc index 9fa6b962bcc..225c3a524d8 100644 --- a/simconvoi.cc +++ b/simconvoi.cc @@ -2438,6 +2438,8 @@ uint16 convoi_t::get_overcrowded() const uint16 overcrowded = 0; for(uint8 i = 0; i < vehicle_count; i ++) { + if (vehicle[i]->get_cargo_type()->get_catg_index() != goods_manager_t::INDEX_PAS) continue; + for (uint8 j = 0; j < vehicle[i]->get_desc()->get_number_of_classes(); j++) { overcrowded += vehicle[i]->get_overcrowding(j); @@ -2451,6 +2453,8 @@ uint16 convoi_t::get_overcrowded_capacity() const uint16 standing_capacity = 0; for (uint8 i = 0; i < vehicle_count; i++) { + if (vehicle[i]->get_cargo_type()->get_catg_index() != goods_manager_t::INDEX_PAS) continue; + for (uint8 j = 0; j < vehicle[i]->get_desc()->get_number_of_classes(); j++) { standing_capacity += vehicle[i]->get_overcrowded_capacity(j); diff --git a/simline.cc b/simline.cc index 38d64545c92..b279f62b3ee 100644 --- a/simline.cc +++ b/simline.cc @@ -853,6 +853,8 @@ bool simline_t::has_overcrowded() const { ITERATE(line_managed_convoys,i) { + if (!line_managed_convoys[i]->get_goods_catg_index().is_contained(goods_manager_t::INDEX_PAS)) continue; + if(line_managed_convoys[i]->get_overcrowded() > 0) { return true; From 29425fb631144bda3650704887516ac9c11fd2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 18:02:31 +0900 Subject: [PATCH 4/9] ADD: Function to get the number of pax standing in a particular fare class in the convoy --- simconvoi.cc | 14 ++++++++++++++ simconvoi.h | 1 + 2 files changed, 15 insertions(+) diff --git a/simconvoi.cc b/simconvoi.cc index 225c3a524d8..dfc46eb1aee 100644 --- a/simconvoi.cc +++ b/simconvoi.cc @@ -2448,6 +2448,20 @@ uint16 convoi_t::get_overcrowded() const return overcrowded; } +uint16 convoi_t::get_overcrowded(uint8 fare_class) const +{ + uint16 overcrowded = 0; + for (uint8 i = 0; i < vehicle_count; i++) + { + if (vehicle[i]->get_cargo_type()->get_catg_index() != goods_manager_t::INDEX_PAS) continue; + if (!vehicle[i]->get_overcrowded_capacity(fare_class)) continue; + + overcrowded += vehicle[i]->get_overcrowding(fare_class); + } + return overcrowded; +} + + uint16 convoi_t::get_overcrowded_capacity() const { uint16 standing_capacity = 0; diff --git a/simconvoi.h b/simconvoi.h index c5faadb3141..a1bd72cc3c0 100644 --- a/simconvoi.h +++ b/simconvoi.h @@ -1411,6 +1411,7 @@ class convoi_t : public sync_steppable, public overtaker_t, public lazy_convoy_t // @author: jamespetts // Returns the number of standing passengers (etc.) in this convoy. uint16 get_overcrowded() const; + uint16 get_overcrowded(uint8 fare_class) const; // Returns the total regardless of fare class uint16 get_overcrowded_capacity() const; From 7f19b1898b6496440843c63c2d48e75b86586c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 18:05:27 +0900 Subject: [PATCH 5/9] FIX: Overcrowded capacity class remains fixed even if fares change --- vehicle/vehicle.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/vehicle/vehicle.cc b/vehicle/vehicle.cc index c73dd656c4a..bda1ec61dd8 100644 --- a/vehicle/vehicle.cc +++ b/vehicle/vehicle.cc @@ -2330,18 +2330,35 @@ uint16 vehicle_t::get_overcrowded_capacity(uint8 g_class) const { return 0; } - for (uint8 i = 0; i < number_of_classes; i++) - { - if (desc->get_capacity(i) > 0) - { - return i == g_class ? desc->get_overcrowded_capacity() : 0; + // The overcrowded capacity class is the lowest fare class of this vehicle. + uint8 lowest_fare_class = 0; + for (uint8 i = 0; i < number_of_classes; i++) { + if (get_fare_capacity(i) > 0) { + lowest_fare_class = i; + break; } } - return 0; + if (g_class != lowest_fare_class) return 0; + + return desc->get_overcrowded_capacity(); } uint16 vehicle_t::get_overcrowding(uint8 g_class) const { + if (g_class >= number_of_classes) + { + return 0; + } + // The overcrowded capacity class is the lowest fare class of this vehicle. + uint8 lowest_fare_class = 0; + for (uint8 i = 0; i < number_of_classes; i++) { + if (get_fare_capacity(i) > 0) { + lowest_fare_class = i; + break; + } + } + if (g_class != lowest_fare_class) return 0; + const uint16 carried = get_total_cargo_by_class(g_class); const uint16 capacity = get_accommodation_capacity(g_class); // Do not count a vehicle as overcrowded if the higher class passengers can travel in lower class accommodation and still get a seat. From ed343a36825905f172ad12d7748189c273790cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 18:12:18 +0900 Subject: [PATCH 6/9] ADD: get_overcrowded(uint8 g_class) for loading indicator gui --- gui/components/gui_vehicle_capacitybar.cc | 16 ++++++++++++++++ gui/components/gui_vehicle_capacitybar.h | 1 + 2 files changed, 17 insertions(+) diff --git a/gui/components/gui_vehicle_capacitybar.cc b/gui/components/gui_vehicle_capacitybar.cc index 77f6e283a7f..8fd1690db55 100644 --- a/gui/components/gui_vehicle_capacitybar.cc +++ b/gui/components/gui_vehicle_capacitybar.cc @@ -196,6 +196,22 @@ uint16 gui_convoy_loading_info_t::get_overcrowded() return sum; } +uint16 gui_convoy_loading_info_t::get_overcrowded(uint8 g_class) +{ + uint16 sum = 0; + if (cnv.is_bound()) { + return cnv->get_overcrowded(g_class); + } + else if (line.is_bound()) { + for (uint32 i = 0; i < line->count_convoys(); i++) { + convoihandle_t const convoy = line->get_convoy(i); + sum += convoy->get_overcrowded(g_class); + } + } + return sum; +} + + gui_convoy_loading_info_t::gui_convoy_loading_info_t(linehandle_t line, convoihandle_t cnv, bool show_loading_info) { this->cnv = cnv; diff --git a/gui/components/gui_vehicle_capacitybar.h b/gui/components/gui_vehicle_capacitybar.h index a8aa344b265..3ad7c804341 100644 --- a/gui/components/gui_vehicle_capacitybar.h +++ b/gui/components/gui_vehicle_capacitybar.h @@ -32,6 +32,7 @@ class gui_convoy_loading_info_t : public gui_aligned_container_t uint16 get_overcrowded_capacity(); uint16 get_overcrowded_capacity(uint8 g_class); uint16 get_overcrowded(); + uint16 get_overcrowded(uint8 g_class); public: gui_convoy_loading_info_t(linehandle_t line, convoihandle_t cnv, bool show_loading_info = true); From 29d844be811400170cec87cfc2ccf2f1cde44141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 20:12:12 +0900 Subject: [PATCH 7/9] CHG/FIX: Improve the display of overcrowding capacity and amount and their association with each class. --- gui/components/gui_vehicle_capacitybar.cc | 84 +++++------------------ gui/components/gui_vehicle_capacitybar.h | 2 - 2 files changed, 18 insertions(+), 68 deletions(-) diff --git a/gui/components/gui_vehicle_capacitybar.cc b/gui/components/gui_vehicle_capacitybar.cc index 8fd1690db55..7a24943e2c1 100644 --- a/gui/components/gui_vehicle_capacitybar.cc +++ b/gui/components/gui_vehicle_capacitybar.cc @@ -16,7 +16,6 @@ void gui_convoy_loading_info_t::update_list() { remove_all(); if( cnv.is_bound() || line.is_bound() ) { - const scr_coord_val text_width = show_loading ? proportional_string_width(" 18888/18888") : proportional_string_width(" 188888"); // update factors if (cnv.is_bound()) { old_vehicle_count = cnv->get_vehicle_count(); @@ -25,7 +24,6 @@ void gui_convoy_loading_info_t::update_list() } const minivec_tpl &goods_catg_index = cnv.is_bound() ? cnv->get_goods_catg_index() : line->get_goods_catg_index(); - const uint16 overcrowded_capacity = goods_catg_index.is_contained(goods_manager_t::INDEX_PAS) ? get_overcrowded_capacity() : 0; add_table(4+show_loading,0); { @@ -66,49 +64,36 @@ void gui_convoy_loading_info_t::update_list() // 3: capacity text const uint16 cargo_sum = get_total_cargo_by_fare_class(catg_index,i); + uint16 overcrowded_capacity = 0; + if (catg_index==goods_manager_t::INDEX_PAS) { + overcrowded_capacity = get_overcrowded_capacity(i); + } gui_label_buf_t *lb = new_component(SYSCOL_TEXT, gui_label_t::right); if (show_loading) { - lb->buf().printf(" %4d/%3d", min(capacity, cargo_sum), capacity); + lb->buf().printf("%4d/%3d", cargo_sum, capacity); } else { lb->buf().append(capacity,0); } - lb->set_fixed_width(text_width); - lb->update(); - - // 4: capacity bar - if (show_loading) { - PIXVAL catg_bar_col = catg_index < goods_manager_t::INDEX_NONE ? ware->get_color() : color_idx_to_rgb(115); - new_component(scr_size(102, scr_coord_val(LINESPACE*0.6+2)), catg_bar_col)->set_value(capacity, cargo_sum); - } - - new_component(); - } - - if (catg_index == goods_manager_t::INDEX_PAS && overcrowded_capacity > 0) { - if (skinverwaltung_t::pax_evaluation_icons) { - new_component(skinverwaltung_t::pax_evaluation_icons->get_image_id(1), 0, ALIGN_CENTER_V, true)->set_tooltip(translator::translate("overcrowded_capacity")); - } - else { - new_component(); - } - new_component("overcrowded_capacity"); - - // 3: capacity text - gui_label_buf_t *lb = new_component(SYSCOL_TEXT, gui_label_t::right); - if (show_loading) { - lb->buf().printf(" %4d/%3d", get_overcrowded(), overcrowded_capacity); - } - else { - lb->buf().append(overcrowded_capacity,0); + if (overcrowded_capacity) { + lb->buf().printf("(%u)", overcrowded_capacity); } - lb->set_fixed_width(text_width); lb->update(); + lb->set_fixed_width(lb->get_min_size().w); // 4: capacity bar if (show_loading) { - new_component(scr_size(102, scr_coord_val(LINESPACE*0.6)), SYSCOL_OVERCROWDED)->set_value(overcrowded_capacity, get_overcrowded()); + add_table(1,2)->set_spacing(scr_size(0,0)); + { + PIXVAL catg_bar_col = catg_index < goods_manager_t::INDEX_NONE ? ware->get_color() : color_idx_to_rgb(115); + new_component(scr_size(102, scr_coord_val(LINESPACE*0.6+2)), catg_bar_col)->set_value(capacity, cargo_sum); + if (overcrowded_capacity) { + new_component(scr_size(102, scr_coord_val(LINESPACE>>1)), SYSCOL_OVERCROWDED)->set_value(overcrowded_capacity, get_overcrowded(i)); + } + } + end_table(); } + new_component(); } } @@ -129,24 +114,6 @@ uint16 gui_convoy_loading_info_t::get_unique_fare_capacity(uint8 catg_index, uin return 0; } -uint16 gui_convoy_loading_info_t::get_overcrowded_capacity() -{ - uint16 capacity = 0; - if (cnv.is_bound()) { - return cnv->get_overcrowded_capacity(); - } - else if (line.is_bound()) { - for (uint32 i = 0; i < line->count_convoys(); i++) { - convoihandle_t const convoy = line->get_convoy(i); - // we do not want to count the capacity of depot convois - if (!convoy->in_depot()) { - capacity += convoy->get_overcrowded_capacity(); - } - } - } - return capacity; -} - uint16 gui_convoy_loading_info_t::get_overcrowded_capacity(uint8 g_class) { uint16 capacity = 0; @@ -181,21 +148,6 @@ uint16 gui_convoy_loading_info_t::get_total_cargo_by_fare_class(uint8 catg_index return sum; } -uint16 gui_convoy_loading_info_t::get_overcrowded() -{ - uint16 sum = 0; - if (cnv.is_bound()) { - return cnv->get_overcrowded(); - } - else if (line.is_bound()) { - for (uint32 i = 0; i < line->count_convoys(); i++) { - convoihandle_t const convoy = line->get_convoy(i); - sum += convoy->get_overcrowded(); - } - } - return sum; -} - uint16 gui_convoy_loading_info_t::get_overcrowded(uint8 g_class) { uint16 sum = 0; diff --git a/gui/components/gui_vehicle_capacitybar.h b/gui/components/gui_vehicle_capacitybar.h index 3ad7c804341..65f6ecdd45e 100644 --- a/gui/components/gui_vehicle_capacitybar.h +++ b/gui/components/gui_vehicle_capacitybar.h @@ -29,9 +29,7 @@ class gui_convoy_loading_info_t : public gui_aligned_container_t uint16 get_unique_fare_capacity(uint8 catg_index, uint8 g_class); uint16 get_total_cargo_by_fare_class(uint8 catg_index, uint8 g_class); - uint16 get_overcrowded_capacity(); uint16 get_overcrowded_capacity(uint8 g_class); - uint16 get_overcrowded(); uint16 get_overcrowded(uint8 g_class); public: From 6535bc323e341db88da9cfc896668b80075e6a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 21:35:09 +0900 Subject: [PATCH 8/9] FIX: overcrowding amount of the vehicle is not retrieved correctly --- vehicle/vehicle.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vehicle/vehicle.cc b/vehicle/vehicle.cc index bda1ec61dd8..894235b025f 100644 --- a/vehicle/vehicle.cc +++ b/vehicle/vehicle.cc @@ -2351,16 +2351,21 @@ uint16 vehicle_t::get_overcrowding(uint8 g_class) const } // The overcrowded capacity class is the lowest fare class of this vehicle. uint8 lowest_fare_class = 0; + // Passengers are placed in each accommodation, so the lowest accommodation must be referenced. - fracht[a_class] + uint8 lowest_accommodation_class = 0; for (uint8 i = 0; i < number_of_classes; i++) { - if (get_fare_capacity(i) > 0) { + if (get_fare_capacity(i) > 0 && !lowest_fare_class) { lowest_fare_class = i; - break; } + if (get_accommodation_capacity(i) > 0 && !lowest_accommodation_class) { + lowest_accommodation_class = i; + } + if (lowest_fare_class && lowest_accommodation_class) break; } if (g_class != lowest_fare_class) return 0; - const uint16 carried = get_total_cargo_by_class(g_class); - const uint16 capacity = get_accommodation_capacity(g_class); // Do not count a vehicle as overcrowded if the higher class passengers can travel in lower class accommodation and still get a seat. + const uint16 carried = get_total_cargo_by_class(lowest_accommodation_class); + const uint16 capacity = get_fare_capacity(g_class); // Do not count a vehicle as overcrowded if the higher class passengers can travel in lower class accommodation and still get a seat. return carried - capacity > 0 ? carried - capacity : 0; } From 4e1b8ef01106af6d5ae0205b9a67889be1b5fa3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Mon, 19 Feb 2024 21:46:06 +0900 Subject: [PATCH 9/9] CHG: By splitting the bar, there is no longer a need to mix overcrowded color. --- gui/components/gui_vehicle_capacitybar.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/components/gui_vehicle_capacitybar.cc b/gui/components/gui_vehicle_capacitybar.cc index 7a24943e2c1..099a5027f41 100644 --- a/gui/components/gui_vehicle_capacitybar.cc +++ b/gui/components/gui_vehicle_capacitybar.cc @@ -86,7 +86,7 @@ void gui_convoy_loading_info_t::update_list() add_table(1,2)->set_spacing(scr_size(0,0)); { PIXVAL catg_bar_col = catg_index < goods_manager_t::INDEX_NONE ? ware->get_color() : color_idx_to_rgb(115); - new_component(scr_size(102, scr_coord_val(LINESPACE*0.6+2)), catg_bar_col)->set_value(capacity, cargo_sum); + new_component(scr_size(102, scr_coord_val(LINESPACE*0.6+2)), catg_bar_col)->set_value(capacity, min(cargo_sum, capacity)); if (overcrowded_capacity) { new_component(scr_size(102, scr_coord_val(LINESPACE>>1)), SYSCOL_OVERCROWDED)->set_value(overcrowded_capacity, get_overcrowded(i)); }