diff --git a/bauer/vehikelbauer.cc b/bauer/vehikelbauer.cc index 23ee70541..61032d59a 100644 --- a/bauer/vehikelbauer.cc +++ b/bauer/vehikelbauer.cc @@ -15,8 +15,10 @@ #include "../dataobj/environment.h" #include "../dataobj/tabfile.h" #include "../dataobj/loadsave.h" +#include "../dataobj/translator.h" #include "../descriptor/vehicle_desc.h" +#include "../gui/depot_frame.h" #include "vehikelbauer.h" @@ -27,9 +29,8 @@ static stringhashtable_tpl name_fahrzeuge; // index 0 aur, 1...8 at normal waytype index #define GET_WAYTYPE_INDEX(wt) ((int)(wt)>8 ? 0 : (wt)) -static slist_tpl typ_fahrzeuge[9]; - - +static slist_tpl typ_fahrzeuge[depot_frame_t::sb_length][9]; +static uint8 tmp_sort_idx; class bonus_record_t { public: @@ -127,7 +128,7 @@ sint32 vehicle_builder_t::get_speedbonus( sint32 monthyear, waytype_t wt ) sint32 speed_sum = 0; sint32 num_averages = 0; // needs to do it the old way => iterate over all vehicles with this type ... - FOR(slist_tpl, const info, typ_fahrzeuge[GET_WAYTYPE_INDEX(wt)]) { + FOR(slist_tpl, const info, typ_fahrzeuge[0][GET_WAYTYPE_INDEX(wt)]) { if( info->get_power()>0 && info->is_available(monthyear) ) { speed_sum += info->get_topspeed(); num_averages ++; @@ -189,23 +190,91 @@ vehicle_t* vehicle_builder_t::build(koord3d k, player_t* player, convoi_t* cnv, bool vehicle_builder_t::register_desc(const vehicle_desc_t *desc) { // register waytype list - const int idx = GET_WAYTYPE_INDEX( desc->get_waytype() ); + const int wt_idx = GET_WAYTYPE_INDEX( desc->get_waytype() ); const vehicle_desc_t *old_desc = name_fahrzeuge.get( desc->get_name() ); + for ( int sort_idx = 0; sort_idx < depot_frame_t::sb_length; sort_idx++ ) { if( old_desc ) { - dbg->warning( "vehicle_builder_t::register_desc()", "Object %s was overlaid by addon!", desc->get_name() ); - name_fahrzeuge.remove( desc->get_name() ); - typ_fahrzeuge[idx].remove(old_desc); + dbg->warning( "vehicle_builder_t::register_desc()", "Object %s was overlaid by addon!", desc->get_name() ); + name_fahrzeuge.remove( desc->get_name() ); + typ_fahrzeuge[sort_idx][wt_idx].remove(old_desc); + } + name_fahrzeuge.put(desc->get_name(), desc); + typ_fahrzeuge[sort_idx][wt_idx].append(desc); } - name_fahrzeuge.put(desc->get_name(), desc); - typ_fahrzeuge[idx].append(desc); return true; } +// for sort vehicle in the list +static int compare_freight(const vehicle_desc_t* a, const vehicle_desc_t* b) +{ + int cmp = a->get_freight_type()->get_catg() - b->get_freight_type()->get_catg(); + if (cmp != 0) return cmp; + if (a->get_freight_type()->get_catg() == 0) cmp = a->get_freight_type()->get_index() - b->get_freight_type()->get_index(); + return cmp; +} +static int compare_capacity(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_capacity() - b->get_capacity();} +static int compare_engine(const vehicle_desc_t* a, const vehicle_desc_t* b) +{ + return (a->get_capacity() + a->get_power() == 0 ? (uint8)vehicle_desc_t::steam : a->get_engine_type()) - (b->get_capacity() + b->get_power() == 0 ? (uint8)vehicle_desc_t::steam : b->get_engine_type()); +} +static int compare_price(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_price() - b->get_price();} +static int compare_cost(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_running_cost() - b->get_running_cost();} +static int compare_cost_per_unit(const vehicle_desc_t* a, const vehicle_desc_t* b) +{ + return a->get_running_cost()*b->get_capacity() - b->get_running_cost()*a->get_capacity(); +} +static int compare_topspeed(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_topspeed() - b->get_topspeed();} +static int compare_power(const vehicle_desc_t* a, const vehicle_desc_t* b) {return (a->get_power() == 0 ? 0x7FFFFFF : a->get_power()) - (b->get_power() == 0 ? 0x7FFFFFF : b->get_power());} +static int compare_weight(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_weight() - b->get_weight();} +static int compare_intro_year_month(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_intro_year_month() - b->get_intro_year_month();} +static int compare_retire_year_month(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_retire_year_month() - b->get_retire_year_month();} -static bool compare_vehikel_desc(const vehicle_desc_t* a, const vehicle_desc_t* b) +static bool compare_vehicles(const vehicle_desc_t* a, const vehicle_desc_t* b) { + int cmp = compare_freight(a, b); + if (cmp != 0) return cmp < 0; + switch (tmp_sort_idx) { + case depot_frame_t::sb_name: + cmp = strcmp(translator::translate(a->get_name()), translator::translate(b->get_name())); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_price: + cmp = compare_price(a, b); + if (cmp != 0) return cmp < 0; + case depot_frame_t::sb_cost: + cmp = compare_cost(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_price(a, b); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_cost_per_unit: + cmp = compare_cost_per_unit(a,b); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_speed: + cmp = compare_topspeed(a, b); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_weight: + cmp = compare_weight(a, b); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_power: + cmp = compare_power(a, b); + if (cmp != 0) return cmp < 0; + break; + case depot_frame_t::sb_intro_date: + cmp = compare_intro_year_month(a, b); + if (cmp != 0) return cmp < 0; + case depot_frame_t::sb_retire_date: + cmp = compare_retire_year_month(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_intro_year_month(a, b); + if (cmp != 0) return cmp < 0; + break; + } // Sort by: // 1. cargo category // 2. cargo (if special freight) @@ -214,60 +283,43 @@ static bool compare_vehikel_desc(const vehicle_desc_t* a, const vehicle_desc_t* // 5. power // 6. intro date // 7. name - int cmp = a->get_freight_type()->get_catg() - b->get_freight_type()->get_catg(); - if (cmp == 0) { - if (a->get_freight_type()->get_catg() == 0) { - cmp = a->get_freight_type()->get_index() - b->get_freight_type()->get_index(); - } - if (cmp == 0) { - cmp = a->get_capacity() - b->get_capacity(); - if (cmp == 0) { - // to handle tender correctly - uint8 b_engine = (a->get_capacity() + a->get_power() == 0 ? (uint8)vehicle_desc_t::steam : a->get_engine_type()); - uint8 a_engine = (b->get_capacity() + b->get_power() == 0 ? (uint8)vehicle_desc_t::steam : b->get_engine_type()); - cmp = b_engine - a_engine; - if (cmp == 0) { - cmp = a->get_topspeed() - b->get_topspeed(); - if (cmp == 0) { - // put tender at the end of the list ... - int b_power = (a->get_power() == 0 ? 0x7FFFFFF : a->get_power()); - int a_power = (b->get_power() == 0 ? 0x7FFFFFF : b->get_power()); - cmp = b_power - a_power; - if (cmp == 0) { - cmp = a->get_intro_year_month() - b->get_intro_year_month(); - if (cmp == 0) { - cmp = strcmp(a->get_name(), b->get_name()); - } - } - } - } - } - } - } + cmp = compare_capacity(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_engine(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_topspeed(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_power(a, b); + if (cmp != 0) return cmp < 0; + cmp = compare_intro_year_month(a, b); + if (cmp != 0) return cmp < 0; + cmp = strcmp(translator::translate(a->get_name()), translator::translate(b->get_name())); return cmp < 0; } - bool vehicle_builder_t::successfully_loaded() { // first: check for bonus tables DBG_MESSAGE("vehicle_builder_t::sort_lists()","called"); - for( int wt_idx=0; wt_idx<9; wt_idx++ ) { - slist_tpl& typ_liste = typ_fahrzeuge[wt_idx]; - uint count = typ_liste.get_count(); - if (count == 0) { - continue; - } - const vehicle_desc_t** const tmp = new const vehicle_desc_t*[count]; - const vehicle_desc_t** const tmp_end = tmp + count; - for( const vehicle_desc_t** tmpptr = tmp; tmpptr != tmp_end; tmpptr++ ) { - *tmpptr = typ_liste.remove_first(); - } - std::sort(tmp, tmp_end, compare_vehikel_desc); - for( const vehicle_desc_t** tmpptr = tmp; tmpptr != tmp_end; tmpptr++ ) { - typ_liste.append(*tmpptr); + for ( int sort_idx = 0; sort_idx < depot_frame_t::sb_length; sort_idx++ ) { + for( int wt_idx=0; wt_idx<9; wt_idx++ ) { + tmp_sort_idx = sort_idx; + slist_tpl& typ_liste = typ_fahrzeuge[sort_idx][wt_idx]; + uint count = typ_liste.get_count(); + if (count == 0) { + continue; + } + const vehicle_desc_t** const tmp = new const vehicle_desc_t*[count]; + const vehicle_desc_t** const tmp_end = tmp + count; + for( const vehicle_desc_t** tmpptr = tmp; tmpptr != tmp_end; tmpptr++ ) { + *tmpptr = typ_liste.remove_first(); + } + std::sort(tmp, tmp_end, compare_vehicles); + for( const vehicle_desc_t** tmpptr = tmp; tmpptr != tmp_end; tmpptr++ ) { + typ_liste.append(*tmpptr); + } + delete [] tmp; } - delete [] tmp; } return true; } @@ -280,9 +332,9 @@ const vehicle_desc_t *vehicle_builder_t::get_info(const char *name) } -slist_tpl const & vehicle_builder_t::get_info(waytype_t const typ) +slist_tpl const & vehicle_builder_t::get_info(waytype_t const typ, uint8 sortkey) { - return typ_fahrzeuge[GET_WAYTYPE_INDEX(typ)]; + return typ_fahrzeuge[sortkey][GET_WAYTYPE_INDEX(typ)]; } @@ -301,7 +353,7 @@ const vehicle_desc_t *vehicle_builder_t::vehikel_search( waytype_t wt, const uin return NULL; } - FOR(slist_tpl, const test_desc, typ_fahrzeuge[GET_WAYTYPE_INDEX(wt)]) { + FOR(slist_tpl, const test_desc, typ_fahrzeuge[0][GET_WAYTYPE_INDEX(wt)]) { // no constricts allow for rail vehicles concerning following engines if(wt==track_wt && !test_desc->can_follow_any() ) { continue; @@ -408,7 +460,7 @@ const vehicle_desc_t *vehicle_builder_t::get_best_matching( waytype_t wt, const const vehicle_desc_t *desc = NULL; sint32 desc_index = -100000; - FOR(slist_tpl, const test_desc, typ_fahrzeuge[GET_WAYTYPE_INDEX(wt)]) { + FOR(slist_tpl, const test_desc, typ_fahrzeuge[0][GET_WAYTYPE_INDEX(wt)]) { if(target_power>0 && test_desc->get_power()==0) { continue; } diff --git a/bauer/vehikelbauer.h b/bauer/vehikelbauer.h index ec0af13f7..c09e68526 100644 --- a/bauer/vehikelbauer.h +++ b/bauer/vehikelbauer.h @@ -11,6 +11,7 @@ #include "../dataobj/koord3d.h" #include "../simtypes.h" +#include "../gui/depot_frame.h" #include class vehicle_t; @@ -40,7 +41,7 @@ public: static vehicle_t* build(koord3d k, player_t* player, convoi_t* cnv, const vehicle_desc_t* vb ); static const vehicle_desc_t * get_info(const char *name); - static slist_tpl const& get_info(waytype_t); + static slist_tpl const& get_info(waytype_t, uint8 sortkey = depot_frame_t::sb_name); /* extended search for vehicles for KI * @author prissi diff --git a/bauer/vehikelbauer.h.gch b/bauer/vehikelbauer.h.gch new file mode 100644 index 000000000..8394afc68 Binary files /dev/null and b/bauer/vehikelbauer.h.gch differ diff --git a/dataobj/translator.cc b/dataobj/translator.cc index 76ebfa7c3..6090f769a 100644 --- a/dataobj/translator.cc +++ b/dataobj/translator.cc @@ -596,6 +596,102 @@ const char *translator::get_month_name(uint16 month) return translate(month_names[month % lengthof(month_names)]); } +const char *translator::get_short_month_name(uint16 month) +{ + static const char *const short_month_names[] = { + "Jan.", + "Feb.", + "Mar.", + "Apr.", + "May", + "June", + "July", + "Aug.", + "Sept.", + "Oct.", + "Nov.", + "Dec." + }; + return translate(short_month_names[month % lengthof(short_month_names)]); +} + +const char *translator::get_date(uint16 year, uint16 month) +{ + char const* const month_ = get_month_name(month); + char const* const year_sym = strcmp("YEAR_SYMBOL", translate("YEAR_SYMBOL")) ? translate("YEAR_SYMBOL") : ""; + static char sdate[256]; + switch (env_t::show_month) { + case env_t::DATE_FMT_JAPANESE: + case env_t::DATE_FMT_JAPANESE_NO_SEASON: + sprintf(sdate, "%4d%s %s", year, year_sym, month_); + break; + case env_t::DATE_FMT_GERMAN: + case env_t::DATE_FMT_GERMAN_NO_SEASON: + case env_t::DATE_FMT_US: + case env_t::DATE_FMT_US_NO_SEASON: + default: + sprintf(sdate, "%s %4d%s", month_, year, year_sym); + break; + } + return sdate; +} + +const char *translator::get_date(uint16 year, uint16 month, uint16 day, char const* season) +{ + char const* const month_ = get_month_name(month); + char const* const year_sym = strcmp("YEAR_SYMBOL", translate("YEAR_SYMBOL")) ? translate("YEAR_SYMBOL") : ""; + char const* const day_sym = strcmp("DAY_SYMBOL", translate("DAY_SYMBOL")) ? translate("DAY_SYMBOL") : ""; + static char date[256]; + switch(env_t::show_month) { + case env_t::DATE_FMT_GERMAN: + sprintf(date, "%s %d. %s %d%s", season, day, month_, year, year_sym); + break; + case env_t::DATE_FMT_GERMAN_NO_SEASON: + sprintf(date, "%d. %s %d%s", day, month_, year, year_sym); + break; + case env_t::DATE_FMT_US: + sprintf(date, "%s %s %d %d%s", season, month_, day, year, year_sym); + break; + case env_t::DATE_FMT_US_NO_SEASON: + sprintf(date, "%s %d %d%s", month_, day, year, year_sym); + break; + case env_t::DATE_FMT_JAPANESE: + sprintf(date, "%s %d%s %s %d%s", season, year, year_sym, month_, day, day_sym); + break; + case env_t::DATE_FMT_JAPANESE_NO_SEASON: + sprintf(date, "%d%s %s %d%s", year, year_sym, month_, day, day_sym); + break; + case env_t::DATE_FMT_MONTH: + sprintf(date, "%s, %s %d%s", month_, season, year, year_sym); + break; + case env_t::DATE_FMT_SEASON: + sprintf(date, "%s %d%s", season, year, year_sym); + break; + } + return date; +} + +const char *translator::get_short_date(uint16 year, uint16 month) +{ + char const* const month_ = get_short_month_name(month); + char const* const year_sym = strcmp("YEAR_SYMBOL", translate("YEAR_SYMBOL")) ? translate("YEAR_SYMBOL") : ""; + static char sdate[256]; + switch (env_t::show_month) { + case env_t::DATE_FMT_JAPANESE: + case env_t::DATE_FMT_JAPANESE_NO_SEASON: + sprintf(sdate, "%4d%s %s", year, year_sym , month_); + break; + case env_t::DATE_FMT_GERMAN: + case env_t::DATE_FMT_GERMAN_NO_SEASON: + case env_t::DATE_FMT_US: + case env_t::DATE_FMT_US_NO_SEASON: + default: + sprintf(sdate, "%s %4d%s", month_, year, year_sym); + break; + } + return sdate; +} + /* get a name for a non-matching object */ const char *translator::compatibility_name(const char *str) diff --git a/dataobj/translator.h b/dataobj/translator.h index ee90f5b65..590516964 100644 --- a/dataobj/translator.h +++ b/dataobj/translator.h @@ -123,6 +123,12 @@ public: // return the name of the month static const char *get_month_name(uint16 month); + // return the short name of the month + static const char *get_short_month_name(uint16 month); + // return date in selected format + static const char *get_date(uint16 year, uint16 month); + static const char *get_date(uint16 year, uint16 month, uint16 day, char const* season); + static const char *get_short_date(uint16 year, uint16 month); }; #endif diff --git a/dataobj/translator.h.gch b/dataobj/translator.h.gch new file mode 100644 index 000000000..d23efb0f9 Binary files /dev/null and b/dataobj/translator.h.gch differ diff --git a/gui/depot_frame.cc b/gui/depot_frame.cc index 1e3b0ad87..400ba8b1a 100644 --- a/gui/depot_frame.cc +++ b/gui/depot_frame.cc @@ -72,7 +72,6 @@ static const char* engine_type_names[9] = "battery" }; -enum { sb_name, sb_capacity, sb_price, sb_cost, sb_cost_per_unit, sb_speed, sb_power, sb_weight, sb_intro_date, sb_retire_date, sb_length }; static int sort_by_action; bool depot_frame_t::show_retired_vehicles = false; @@ -220,8 +219,9 @@ DBG_DEBUG("depot_frame_t::depot_frame_t()","get_max_convoi_length()=%i",depot->g add_component(&div_tabbottom); add_component(&lb_veh_action); add_component(&lb_sort_by); - add_component(&lb_vehicle_filter); add_component(&lb_name_filter_input); + add_component(&lb_vehicle_filter); + add_component(&div_action_bottom); veh_action = va_append; bt_veh_action.set_typ(button_t::roundbox); @@ -260,11 +260,8 @@ DBG_DEBUG("depot_frame_t::depot_frame_t()","get_max_convoi_length()=%i",depot->g build_vehicle_lists(); // text will be translated by ourselves (after update data)! - lb_convois.set_text_pointer(txt_convois); - - lb_convoi_count.set_text_pointer(txt_convoi_count); - lb_convoi_number.set_text_pointer(txt_convoi_number); - + lb_convois.set_text_pointer( txt_convois ); + lb_convoi_number.set_text_pointer( txt_convoi_number ); lb_convoi_count.set_text_pointer( txt_convoi_count ); lb_convoi_speed.set_text_pointer( txt_convoi_speed ); lb_convoi_cost.set_text_pointer( txt_convoi_cost ); @@ -587,34 +584,37 @@ void depot_frame_t::layout(scr_size *size) /* * [BOTTOM] */ + + // 1st line bt_veh_action.set_pos(scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*3, INFO_VSTART)); bt_veh_action.set_size(scr_size(BUTTON_WIDTH_DEPOT, D_BUTTON_HEIGHT)); - lb_veh_action.align_to(&bt_veh_action, ALIGN_RIGHT | ALIGN_EXTERIOR_H | ALIGN_CENTER_V, scr_coord(D_H_SPACE, 0)); - vehicle_filter.set_pos(scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*3, INFO_VSTART + D_BUTTON_HEIGHT + D_V_SPACE)); + // 2nd line + vehicle_filter.set_pos(scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*2 - proportional_string_width(translator::translate("Search:")), INFO_VSTART + D_BUTTON_HEIGHT + D_V_SPACE)); vehicle_filter.set_size(scr_size(BUTTON_WIDTH_DEPOT, D_BUTTON_HEIGHT)); vehicle_filter.set_max_size(scr_size(D_BUTTON_WIDTH, LINESPACE*7)); + lb_vehicle_filter.align_to(&vehicle_filter, ALIGN_RIGHT | ALIGN_EXTERIOR_H | ALIGN_TOP, scr_coord(2,D_GET_CENTER_ALIGN_OFFSET(LINESPACE,D_BUTTON_HEIGHT))); - lb_vehicle_filter.align_to(&vehicle_filter, ALIGN_RIGHT | ALIGN_EXTERIOR_H | ALIGN_TOP, scr_coord(D_H_SPACE,D_GET_CENTER_ALIGN_OFFSET(LINESPACE,D_BUTTON_HEIGHT))); - - bt_show_all.set_pos(scr_coord(D_MARGIN_LEFT, INFO_VSTART + D_BUTTON_HEIGHT + D_V_SPACE)); - bt_show_all.align_to(&vehicle_filter, ALIGN_CENTER_V); - + name_filter_input.set_pos( scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*3, INFO_VSTART + D_BUTTON_HEIGHT + D_V_SPACE) ); name_filter_input.set_size( scr_size( BUTTON_WIDTH_DEPOT, D_EDIT_HEIGHT ) ); - name_filter_input.set_pos( vehicle_filter.get_pos()+scr_coord(0,D_V_SPACE+D_BUTTON_HEIGHT) ); lb_name_filter_input.align_to(&name_filter_input, ALIGN_RIGHT | ALIGN_EXTERIOR_H | ALIGN_TOP, scr_coord(D_H_SPACE,D_GET_CENTER_ALIGN_OFFSET(LINESPACE,D_BUTTON_HEIGHT))); bt_obsolete.set_pos(scr_coord(D_MARGIN_LEFT, INFO_VSTART + (D_BUTTON_HEIGHT + D_V_SPACE)*2)); bt_obsolete.align_to(&name_filter_input, ALIGN_CENTER_V); - int y = name_filter_input.get_pos().y + name_filter_input.get_size().h + D_V_SPACE; - - sort_by.set_pos(scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*3, y)); + //3rd line + sort_by.set_pos(scr_coord(D_MARGIN_LEFT + (BUTTON_WIDTH_DEPOT+D_H_SPACE)*3, INFO_VSTART + (D_BUTTON_HEIGHT + D_V_SPACE)*2)); sort_by.set_size(scr_size(BUTTON_WIDTH_DEPOT, D_BUTTON_HEIGHT)); sort_by.set_max_size(scr_size(D_BUTTON_WIDTH, LINESPACE * 7)); lb_sort_by.align_to(&sort_by, ALIGN_RIGHT | ALIGN_EXTERIOR_H | ALIGN_TOP, scr_coord(D_H_SPACE,D_GET_CENTER_ALIGN_OFFSET(LINESPACE,D_BUTTON_HEIGHT))); + bt_show_all.set_pos(scr_coord(D_MARGIN_LEFT, INFO_VSTART + (D_BUTTON_HEIGHT + D_V_SPACE)*2)); + bt_show_all.align_to(&sort_by, ALIGN_CENTER_V); + + div_action_bottom.set_pos(scr_coord(0, INFO_VSTART + (D_BUTTON_HEIGHT + D_V_SPACE) * 3)); + div_action_bottom.set_width(win_size.w); + const scr_coord_val margin = 4; img_bolt.set_pos(scr_coord(get_windowsize().w - skinverwaltung_t::electricity->get_image(0)->get_pic()->w - margin, margin)); @@ -710,90 +710,6 @@ void depot_frame_t::add_to_vehicle_list(const vehicle_desc_t *info) vehicle_map.set(info, img_data); } -// for sort vehicle in the list -static int compare_freight(const vehicle_desc_t* a, const vehicle_desc_t* b) -{ - int cmp = a->get_freight_type()->get_catg() - b->get_freight_type()->get_catg(); - if (cmp != 0) return cmp; - if (a->get_freight_type()->get_catg() == 0) cmp = a->get_freight_type()->get_index() - b->get_freight_type()->get_index(); - return cmp; -} -static int compare_capacity(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_capacity() - b->get_capacity();} -static int compare_engine(const vehicle_desc_t* a, const vehicle_desc_t* b) -{ - return (a->get_capacity() + a->get_power() == 0 ? (uint8)vehicle_desc_t::steam : a->get_engine_type()) - (b->get_capacity() + b->get_power() == 0 ? (uint8)vehicle_desc_t::steam : b->get_engine_type()); -} -static int compare_price(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_price() - b->get_price();} -static int compare_cost(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_running_cost() - b->get_running_cost();} -static int compare_cost_per_unit(const vehicle_desc_t* a, const vehicle_desc_t* b) -{ - return a->get_running_cost()*b->get_capacity() - b->get_running_cost()*a->get_capacity(); -} -static int compare_topspeed(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_topspeed() - b->get_topspeed();} -static int compare_power(const vehicle_desc_t* a, const vehicle_desc_t* b) {return (a->get_power() == 0 ? 0x7FFFFFF : a->get_power()) - (b->get_power() == 0 ? 0x7FFFFFF : b->get_power());} -static int compare_weight(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_weight() - b->get_weight();} -static int compare_intro_year_month(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_intro_year_month() - b->get_intro_year_month();} -static int compare_retire_year_month(const vehicle_desc_t* a, const vehicle_desc_t* b) {return a->get_retire_year_month() - b->get_retire_year_month();} - -static bool compare_vehicles(const vehicle_desc_t* a, const vehicle_desc_t* b) -{ - int cmp = compare_freight(a, b); - if (cmp != 0) return cmp < 0; - switch (sort_by_action) { - case sb_name: - cmp = strcmp(translator::translate(a->get_name()), translator::translate(b->get_name())); - if (cmp != 0) return cmp < 0; - break; - case sb_price: - cmp = compare_price(a, b); - if (cmp != 0) return cmp < 0; - case sb_cost: - cmp = compare_cost(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_price(a, b); - if (cmp != 0) return cmp < 0; - break; - case sb_cost_per_unit: - cmp = compare_cost_per_unit(a,b); - if (cmp != 0) return cmp < 0; - break; - case sb_speed: - cmp = compare_topspeed(a, b); - if (cmp != 0) return cmp < 0; - break; - case sb_weight: - cmp = compare_weight(a, b); - if (cmp != 0) return cmp < 0; - break; - case sb_power: - cmp = compare_power(a, b); - if (cmp != 0) return cmp < 0; - break; - case sb_intro_date: - cmp = compare_intro_year_month(a, b); - if (cmp != 0) return cmp < 0; - case sb_retire_date: - cmp = compare_retire_year_month(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_intro_year_month(a, b); - if (cmp != 0) return cmp < 0; - break; - } - // sort by capacity - cmp = compare_capacity(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_engine(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_topspeed(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_power(a, b); - if (cmp != 0) return cmp < 0; - cmp = compare_intro_year_month(a, b); - if (cmp != 0) return cmp < 0; - cmp = strcmp(translator::translate(a->get_name()), translator::translate(b->get_name())); - return cmp < 0; -} - // add all current vehicles void depot_frame_t::build_vehicle_lists() { @@ -822,21 +738,23 @@ void depot_frame_t::build_vehicle_lists() img_bolt.set_image( weg_electrified ? skinverwaltung_t::electricity->get_image_id(0) : IMG_EMPTY ); + sort_by_action = depot->selected_sort_by; + vector_tpl typ_list; + if(!show_all && veh_action==va_sell) { + // show only sellable vehicles FOR(slist_tpl, const v, depot->get_vehicle_list()) { vehicle_desc_t const* const d = v->get_desc(); typ_list.append(d); } } else { - slist_tpl const& tmp_list = depot->get_vehicle_type(); + slist_tpl const& tmp_list = depot->get_vehicle_type(sort_by_action); for(slist_tpl::const_iterator itr = tmp_list.begin(); itr != tmp_list.end(); ++itr) { typ_list.append(*itr); } } - sort_by_action = depot->selected_sort_by; - std::sort(typ_list.begin(), typ_list.end(), compare_vehicles); // use this to show only sellable vehicles if(!show_all && veh_action==va_sell) { @@ -1787,44 +1705,30 @@ void depot_frame_t::draw_vehicle_info_text(scr_coord pos) buf.append( "\n" ); } - if( veh_type->get_power() > 0 ) { // LOCO - buf.printf( translator::translate("Power: %4d kW\n"), veh_type->get_power() ); - } - else { - buf.append( "\n" ); - } + buf.printf( "%s %3d km/h\n", translator::translate("Max. speed:"), veh_type->get_topspeed() ); - buf.printf( "%s %4.1ft\n", translator::translate("Weight:"), veh_type->get_weight() / 1000.0 ); - buf.printf( "%s %3d km/h", translator::translate("Max. speed:"), veh_type->get_topspeed() ); + if( veh_type->get_power() > 0 ) { + if( veh_type->get_gear() != 64 ){ + buf.printf( "%s %4d kW (x%0.2f)\n", translator::translate("Power:"), veh_type->get_power(), veh_type->get_gear() / 64.0 ); + } + else { + buf.printf( translator::translate("Power: %4d kW\n"), veh_type->get_power() ); + } + } - int yyy = pos.y + D_TITLEBAR_HEIGHT + sort_by.get_pos().y + sort_by.get_size().h - - LINESPACE; - display_multiline_text_rgb( pos.x + D_MARGIN_LEFT, yyy, buf, SYSCOL_TEXT); + int yyy = pos.y + D_TITLEBAR_HEIGHT + div_action_bottom.get_pos().y + div_action_bottom.get_size().h + 2; + display_multiline_text_rgb( pos.x + D_MARGIN_LEFT, yyy, buf, SYSCOL_TEXT); // column 2 buf.clear(); - buf.printf( "%s %s %04d\n", - translator::translate("Intro. date:"), - translator::get_month_name( veh_type->get_intro_year_month() % 12 ), - veh_type->get_intro_year_month() / 12 - ); + buf.printf( "%s %4.1ft\n", translator::translate("Weight:"), veh_type->get_weight() / 1000.0 ); + buf.printf( "%s %s - ", translator::translate("Available:"), translator::get_short_date(veh_type->get_intro_year_month() / 12, veh_type->get_intro_year_month() % 12) ); if( veh_type->get_retire_year_month() != DEFAULT_RETIRE_DATE * 12 ) { - buf.printf( "%s %s %04d\n", - translator::translate("Retire. date:"), - translator::get_month_name( veh_type->get_retire_year_month() % 12 ), - veh_type->get_retire_year_month() / 12 - ); + buf.printf( "%s\n", translator::get_short_date(veh_type->get_retire_year_month() / 12, veh_type->get_retire_year_month() % 12) ); } else { - buf.append( "\n" ); - } - - if( veh_type->get_power() > 0 && veh_type->get_gear() != 64 ) { - buf.printf( "%s %0.2f : 1\n", translator::translate("Gear:"), veh_type->get_gear() / 64.0 ); - } - else { - buf.append( "\n" ); + buf.append( "*\n" ); } if( char const* const copyright = veh_type->get_copyright() ) { diff --git a/gui/depot_frame.h b/gui/depot_frame.h index 8160fafdf..ffa1c82b6 100644 --- a/gui/depot_frame.h +++ b/gui/depot_frame.h @@ -28,6 +28,8 @@ #include "components/gui_speedbar.h" #include "../simtypes.h" #include "../utils/cbuffer_t.h" +#include "../linehandle_t.h" +#include "../convoihandle_t.h" class depot_t; class vehicle_desc_t; @@ -125,6 +127,7 @@ private: gui_tab_panel_t tabs; gui_divider_t div_tabbottom; + gui_divider_t div_action_bottom; gui_label_t lb_veh_action; button_t bt_veh_action; @@ -248,6 +251,19 @@ private: void image_from_storage_list(gui_image_list_t::image_data_t *image_data); public: + enum { + sb_name, + sb_capacity, + sb_price, + sb_cost, + sb_cost_per_unit, + sb_speed, sb_power, + sb_weight, + sb_intro_date, + sb_retire_date, + sb_length + }; + // the next two are only needed for depot_t update notifications void activate_convoi( convoihandle_t cnv ); diff --git a/gui/depot_frame.h.gch b/gui/depot_frame.h.gch new file mode 100644 index 000000000..156487f24 Binary files /dev/null and b/gui/depot_frame.h.gch differ diff --git a/gui/server_frame.cc b/gui/server_frame.cc index eb047c8db..6b4cdffc1 100644 --- a/gui/server_frame.cc +++ b/gui/server_frame.cc @@ -262,22 +262,7 @@ void server_frame_t::update_info() #endif time.clear(); - char const* const month = translator::get_month_name(gi.get_current_month()); - switch (env_t::show_month) { - case env_t::DATE_FMT_GERMAN: - case env_t::DATE_FMT_MONTH: - case env_t::DATE_FMT_SEASON: - case env_t::DATE_FMT_GERMAN_NO_SEASON: - time.printf( "%s %d", month, gi.get_current_year() ); - break; - - case env_t::DATE_FMT_US: - case env_t::DATE_FMT_JAPANESE: - case env_t::DATE_FMT_JAPANESE_NO_SEASON: - case env_t::DATE_FMT_US_NO_SEASON: - time.printf( "%i/%s", gi.get_current_year(), month ); - break; - } + time.printf("%s", translator::get_date(gi.get_current_year(), gi.get_current_month())); date.set_text( time ); date.set_pos( scr_coord( get_windowsize().w - D_MARGIN_RIGHT - date.get_size().w, date.get_pos().y ) ); set_dirty(); diff --git a/simdepot.cc b/simdepot.cc index 89d3314b7..6e89a9276 100644 --- a/simdepot.cc +++ b/simdepot.cc @@ -573,9 +573,9 @@ const char * depot_t::is_deletable(const player_t *player) } -slist_tpl const& depot_t::get_vehicle_type() const +slist_tpl const& depot_t::get_vehicle_type(uint8 sortkey) const { - return vehicle_builder_t::get_info(get_waytype()); + return vehicle_builder_t::get_info(get_waytype(), sortkey); } diff --git a/simdepot.h b/simdepot.h index 7f7c0cfeb..c6771495f 100644 --- a/simdepot.h +++ b/simdepot.h @@ -172,7 +172,7 @@ public: * Access to vehicle types which can be bought in the depot. * @author Volker Meyer */ - slist_tpl const& get_vehicle_type() const; + slist_tpl const& get_vehicle_type(uint8 sortkey = SORT_BY_DEFAULT) const; /** * A convoi arrived at the depot and is added to the convoi list. diff --git a/simdepot.h.gch b/simdepot.h.gch new file mode 100644 index 000000000..7f8aec2e0 Binary files /dev/null and b/simdepot.h.gch differ diff --git a/simintr.cc b/simintr.cc index f7039a4b6..f75f9587c 100644 --- a/simintr.cc +++ b/simintr.cc @@ -181,46 +181,21 @@ char const *tick_to_string( sint32 ticks, bool show_full ) // @author hsiegeln - updated to show month // @author prissi - also show date if desired // since seasons 0 is always summer for backward compatibility - char const* const season = translator::translate(seasons[welt_modell->get_season()]); - char const* const month_ = translator::get_month_name(month % 12); - switch(env_t::show_month) { - case env_t::DATE_FMT_GERMAN_NO_SEASON: - sprintf(time, "%d. %s %d %2d:%02dh", tage, month_, year, hours, minuten); - break; - + char const* const date = translator::get_date(year, month, tage, translator::translate(seasons[welt_modell->get_season()])); + switch (env_t::show_month) { + case env_t::DATE_FMT_US: case env_t::DATE_FMT_US_NO_SEASON: { uint32 hours_ = hours % 12; if (hours_ == 0) hours_ = 12; - sprintf(time, "%s %d %d %2d:%02d%s", month_, tage, year, hours_, minuten, hours < 12 ? "am" : "pm"); + sprintf(time, "%s %2d:%02d%s", date, hours_, minuten, hours < 12 ? "am" : "pm"); break; } - - case env_t::DATE_FMT_JAPANESE_NO_SEASON: - sprintf(time, "%d/%s/%d %2d:%02dh", year, month_, tage, hours, minuten); - break; - - case env_t::DATE_FMT_GERMAN: - sprintf(time, "%s, %d. %s %d %2d:%02dh", season, tage, month_, year, hours, minuten); - break; - - case env_t::DATE_FMT_US: { - uint32 hours_ = hours % 12; - if (hours_ == 0) hours_ = 12; - sprintf(time, "%s, %s %d %d %2d:%02d%s", season, month_, tage, year, hours_, minuten, hours < 12 ? "am" : "pm"); - break; - } - - case env_t::DATE_FMT_JAPANESE: - sprintf(time, "%s, %d/%s/%d %2d:%02dh", season, year, month_, tage, hours, minuten); - break; - - case env_t::DATE_FMT_MONTH: - sprintf(time, "%s, %s %d %2d:%02dh", month_, season, year, hours, minuten); - break; - case env_t::DATE_FMT_SEASON: - sprintf(time, "%s %d", season, year); + sprintf(time, "%s", date); break; + default: + sprintf(time, "%s %2d:%02dh", date, hours, minuten); + break; } } else {