diff -r 889301acc299 -r 7d1ff2f621c7 src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp Sun Feb 03 20:34:26 2008 +0000 +++ b/src/vehicle_gui.cpp Mon Mar 10 15:26:39 2008 +0000 @@ -145,10 +145,17 @@ vl->l.flags |= VL_RESORT; } +/* cached values for VehicleNameSorter to spare many GetString() calls */ +static const Vehicle *_last_vehicle[2] = { NULL, NULL }; +static char _last_name[2][64] = { "", "" }; + void SortVehicleList(vehiclelist_d *vl) { if (!(vl->l.flags & VL_RESORT)) return; + /* invalidate cached values for name sorter - vehicle names could change */ + _last_vehicle[0] = _last_vehicle[1] = NULL; + _internal_sort_order = (vl->l.flags & VL_DESC) != 0; qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]), _vehicle_sorter[vl->l.sort_type]); @@ -171,9 +178,9 @@ /* draw profit-based colored icons */ if (v->age <= 365 * 2) { pal = PALETTE_TO_GREY; - } else if (v->profit_last_year < 0) { + } else if (v->GetDisplayProfitLastYear() < 0) { pal = PALETTE_TO_RED; - } else if (v->profit_last_year < 10000) { + } else if (v->GetDisplayProfitLastYear() < 10000) { pal = PALETTE_TO_YELLOW; } else { pal = PALETTE_TO_GREEN; @@ -546,26 +553,23 @@ static int CDECL VehicleNameSorter(const void *a, const void *b) { - static const Vehicle *last_vehicle[2] = { NULL, NULL }; - static char last_name[2][64] = { "", "" }; - const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; int r; - if (va != last_vehicle[0]) { - last_vehicle[0] = va; + if (va != _last_vehicle[0]) { + _last_vehicle[0] = va; SetDParam(0, va->index); - GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0])); + GetString(_last_name[0], STR_VEHICLE_NAME, lastof(_last_name[0])); } - if (vb != last_vehicle[1]) { - last_vehicle[1] = vb; - SetDParam(1, vb->index); - GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1])); + if (vb != _last_vehicle[1]) { + _last_vehicle[1] = vb; + SetDParam(0, vb->index); + GetString(_last_name[1], STR_VEHICLE_NAME, lastof(_last_name[1])); } - r = strcmp(last_name[0], last_name[1]); // sort by name + r = strcmp(_last_name[0], _last_name[1]); // sort by name VEHICLEUNITNUMBERSORTER(r, va, vb); @@ -587,7 +591,7 @@ { const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; - int r = ClampToI32(va->profit_this_year - vb->profit_this_year); + int r = ClampToI32(va->GetDisplayProfitThisYear() - vb->GetDisplayProfitThisYear()); VEHICLEUNITNUMBERSORTER(r, va, vb); @@ -598,7 +602,7 @@ { const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; - int r = ClampToI32(va->profit_last_year - vb->profit_last_year); + int r = ClampToI32(va->GetDisplayProfitLastYear() - vb->GetDisplayProfitLastYear()); VEHICLEUNITNUMBERSORTER(r, va, vb); @@ -644,22 +648,10 @@ { const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; - int max_speed_a = 0xFFFF, max_speed_b = 0xFFFF; int r; - const Vehicle *ua = va, *ub = vb; if (va->type == VEH_TRAIN && vb->type == VEH_TRAIN) { - do { - if (RailVehInfo(ua->engine_type)->max_speed != 0) - max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed); - } while ((ua = ua->Next()) != NULL); - - do { - if (RailVehInfo(ub->engine_type)->max_speed != 0) - max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed); - } while ((ub = ub->Next()) != NULL); - - r = max_speed_a - max_speed_b; + r = va->u.rail.cached_max_speed - vb->u.rail.cached_max_speed; } else { r = va->max_speed - vb->max_speed; } @@ -735,6 +727,12 @@ w->window_number = to_v->index; SetWindowDirty(w); } + + w = FindWindowById(WC_VEHICLE_TIMETABLE, from_v->index); + if (w != NULL) { + w->window_number = to_v->index; + SetWindowDirty(w); + } } } @@ -995,8 +993,8 @@ const Vehicle *v = vl->sort_list[i]; StringID str; - SetDParam(0, v->profit_this_year); - SetDParam(1, v->profit_last_year); + SetDParam(0, v->GetDisplayProfitThisYear()); + SetDParam(1, v->GetDisplayProfitLastYear()); DrawVehicleImage(v, x + 19, y + 6, INVALID_VEHICLE, w->widget[VLW_WIDGET_LIST].right - w->widget[VLW_WIDGET_LIST].left - 20, 0); DrawString(x + 19, y + w->resize.step_height - 8, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, TC_FROMSTRING); @@ -1512,8 +1510,8 @@ } /* Draw profit */ - SetDParam(0, v->profit_this_year); - SetDParam(1, v->profit_last_year); + SetDParam(0, v->GetDisplayProfitThisYear()); + SetDParam(1, v->GetDisplayProfitLastYear()); DrawString(2, 35, _vehicle_translation_table[VST_VEHICLE_PROFIT_THIS_YEAR_LAST_YEAR][v->type], TC_FROMSTRING); /* Draw breakdown & reliability */