Skip to content

Commit

Permalink
Merge branch '2402-fix-linemanagement-ui' of https://github.com/Ranra…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespetts committed Feb 25, 2024
2 parents 5ffd8e0 + 4e1b8ef commit 932fb20
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 50 deletions.
65 changes: 26 additions & 39 deletions gui/components/gui_vehicle_capacitybar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -25,7 +24,6 @@ void gui_convoy_loading_info_t::update_list()
}

const minivec_tpl<uint8> &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);
{
Expand Down Expand Up @@ -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<gui_label_buf_t>(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<gui_capacity_bar_t>(scr_size(102, scr_coord_val(LINESPACE*0.6+2)), catg_bar_col)->set_value(capacity, cargo_sum);
}

new_component<gui_fill_t>();
}

if (catg_index == goods_manager_t::INDEX_PAS && overcrowded_capacity > 0) {
if (skinverwaltung_t::pax_evaluation_icons) {
new_component<gui_image_t>(skinverwaltung_t::pax_evaluation_icons->get_image_id(1), 0, ALIGN_CENTER_V, true)->set_tooltip(translator::translate("overcrowded_capacity"));
if (overcrowded_capacity) {
lb->buf().printf("(%u)", overcrowded_capacity);
}
else {
new_component<gui_empty_t>();
}
new_component<gui_label_t>("overcrowded_capacity");

// 3: capacity text
gui_label_buf_t *lb = new_component<gui_label_buf_t>(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);
}
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<gui_capacity_bar_t>(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<gui_capacity_bar_t>(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<gui_capacity_bar_t>(scr_size(102, scr_coord_val(LINESPACE>>1)), SYSCOL_OVERCROWDED)->set_value(overcrowded_capacity, get_overcrowded(i));
}
}
end_table();
}

new_component<gui_fill_t>();
}
}
Expand All @@ -129,24 +114,25 @@ 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 gui_convoy_loading_info_t::get_overcrowded_capacity(uint8 g_class)
{
uint16 capacity = 0;
if (cnv.is_bound()) {
return cnv->get_overcrowded_capacity();
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();
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;
Expand All @@ -162,21 +148,22 @@ 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 gui_convoy_loading_info_t::get_overcrowded(uint8 g_class)
{
uint16 sum = 0;
if (cnv.is_bound()) {
return cnv->get_overcrowded();
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();
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;
Expand Down
4 changes: 2 additions & 2 deletions gui/components/gui_vehicle_capacitybar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ 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();
uint16 get_overcrowded_capacity(uint8 g_class);
uint16 get_overcrowded(uint8 g_class);

public:
gui_convoy_loading_info_t(linehandle_t line, convoihandle_t cnv, bool show_loading_info = true);
Expand Down
7 changes: 6 additions & 1 deletion gui/schedule_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<gui_fill_t>();
}
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);
Expand Down
28 changes: 28 additions & 0 deletions simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -2446,11 +2448,27 @@ 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;
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);
Expand All @@ -2459,6 +2477,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;
Expand Down
4 changes: 4 additions & 0 deletions simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,12 @@ 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;
// 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,
Expand Down
2 changes: 2 additions & 0 deletions simline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 30 additions & 8 deletions vehicle/vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2330,20 +2330,42 @@ 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
{
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.
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;
// 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 && !lowest_fare_class) {
lowest_fare_class = i;
}
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(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;
}
Expand Down

0 comments on commit 932fb20

Please sign in to comment.