summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aircraft_gui.c39
-rw-r--r--main_gui.c2
-rw-r--r--roadveh_gui.c47
-rw-r--r--ship_gui.c40
-rw-r--r--train_gui.c39
-rw-r--r--ttd.c1
-rw-r--r--ttd.h8
-rw-r--r--vehicle_gui.c191
-rw-r--r--vehicle_gui.h49
-rw-r--r--water_cmd.c5
10 files changed, 240 insertions, 181 deletions
diff --git a/aircraft_gui.c b/aircraft_gui.c
index 0a723f895..8829b3139 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -908,11 +908,9 @@ static void MakeSortedAircraftList(byte owner)
n = _num_aircraft_sort[owner] - _num_aircraft_sort[owner-1];
}
- _internal_sort_type = _aircraft_sort_type[owner];
_internal_sort_order = _aircraft_sort_order[owner];
_internal_name_sorter_id = STR_SV_AIRCRAFT_NAME;
- // only name sorting needs a different procedure, all others are handled by the general sorter
- qsort(firstelement, n, sizeof(_aircraft_sort[0]), (_internal_sort_type == SORT_BY_NAME) ? VehicleNameSorter : GeneralVehicleSorter);
+ qsort(firstelement, n, sizeof(_aircraft_sort[0]), _vehicle_sorter[_aircraft_sort_type[owner]]);
DEBUG(misc, 1) ("Resorting Aircraft list player %d...", owner+1);
}
@@ -925,7 +923,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
const byte window_number = (byte)w->window_number;
if (_aircraft_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
- w->disabled_state |= (1 << 3);
+ w->disabled_state |= (1 << 2);
if (_aircraft_sort_dirty[window_number] || _vehicle_sort_dirty[VEHAIRCRAFT]) {
_aircraft_sort_dirty[window_number] = false;
@@ -947,11 +945,12 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
SET_DPARAM16(0, p->name_1);
SET_DPARAM32(1, p->name_2);
SET_DPARAM16(2, w->vscroll.count);
- SET_DPARAM16(3, _vehicle_sort_listing[_aircraft_sort_type[window_number]]);
DrawWindowWidgets(w);
}
+ /* draw sorting criteria string */
+ DrawString(85, 15, _vehicle_sort_listing[_aircraft_sort_type[window_number]], 0x10);
/* draw arrow pointing up/down for ascending/descending soring */
- DoDrawString(_aircraft_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 85, 15, 0x10);
+ DoDrawString(_aircraft_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 69, 15, 0x10);
/* draw the aircraft */
{
@@ -997,13 +996,13 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch(e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
+ case 2: /* Flip sorting method ascending/descending */
_aircraft_sort_order[(byte)w->window_number] ^= 1;
_aircraft_sort_dirty[(byte)w->window_number] = true;
SetWindowDirty(w);
break;
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, _aircraft_sort_type[(byte)w->window_number], 5, 0); // do it for widget 5
+ case 3: case 4:/* Select sorting criteria dropdown menu */
+ ShowDropDownMenu(w, _vehicle_sort_listing, _aircraft_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
return;
case 6: { /* Matrix to show vehicles */
int id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
@@ -1053,7 +1052,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
_aircraft_sort_type[(byte)w->window_number] = e->dropdown.index;
if (_aircraft_sort_type[(byte)w->window_number] != SORT_BY_UNSORTED) // enable 'Sort By' if a sorter criteria is chosen
- w->disabled_state &= ~(1 << 3);
+ w->disabled_state &= ~(1 << 2);
SetWindowDirty(w);
break;
@@ -1078,10 +1077,10 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
static const Widget _player_aircraft_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PUSHTXTBTN, 14, 0, 129, 170, 181, STR_A003_NEW_AIRCRAFT, STR_A020_BUILD_NEW_AIRCRAFT_REQUIRES},
@@ -1092,7 +1091,7 @@ static const Widget _player_aircraft_widgets[] = {
static const WindowDesc _player_aircraft_desc = {
-1, -1, 260, 182,
WC_AIRCRAFT_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_player_aircraft_widgets,
PlayerAircraftWndProc
};
@@ -1100,10 +1099,10 @@ static const WindowDesc _player_aircraft_desc = {
static const Widget _other_player_aircraft_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_LAST},
@@ -1112,7 +1111,7 @@ static const Widget _other_player_aircraft_widgets[] = {
static const WindowDesc _other_player_aircraft_desc = {
-1, -1, 260, 170,
WC_AIRCRAFT_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_other_player_aircraft_widgets,
PlayerAircraftWndProc
};
diff --git a/main_gui.c b/main_gui.c
index 77777725d..d387eaded 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -738,7 +738,7 @@ bool DoZoomInOutWindow(int how, Window *w)
// routine to disable/enable the zoom buttons. Didn't know where to place these otherwise
{
- Window * wt;
+ Window *wt = NULL;
switch (w->window_class) {
case WC_MAIN_WINDOW:
wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
diff --git a/roadveh_gui.c b/roadveh_gui.c
index a48b727ed..7e6e44412 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -747,11 +747,9 @@ static void MakeSortedRoadList(byte owner)
n = _num_road_sort[owner] - _num_road_sort[owner-1];
}
- _internal_sort_type = _road_sort_type[owner];
_internal_sort_order = _road_sort_order[owner];
_internal_name_sorter_id = STR_SV_ROADVEH_NAME;
- // only name sorting needs a different procedure, all others are handled by the general sorter
- qsort(firstelement, n, sizeof(_road_sort[0]), (_internal_sort_type == SORT_BY_NAME) ? VehicleNameSorter : GeneralVehicleSorter);
+ qsort(firstelement, n, sizeof(_road_sort[0]), _vehicle_sorter[_road_sort_type[owner]]);
DEBUG(misc, 1) ("Resorting Roadvehicles list player %d...", owner+1);
}
@@ -764,7 +762,7 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
const byte window_number = (byte)w->window_number;
if (_road_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
- w->disabled_state |= (1 << 3);
+ w->disabled_state |= (1 << 2);
if (_road_sort_dirty[window_number] || _vehicle_sort_dirty[VEHROAD]) {
_road_sort_dirty[window_number] = false;
@@ -786,11 +784,12 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
SET_DPARAM16(0, p->name_1);
SET_DPARAM32(1, p->name_2);
SET_DPARAM16(2, w->vscroll.count);
- SET_DPARAM16(3, _vehicle_sort_listing[_road_sort_type[window_number]]);
DrawWindowWidgets(w);
}
+ /* draw sorting criteria string */
+ DrawString(85, 15, _vehicle_sort_listing[_road_sort_type[window_number]], 0x10);
/* draw arrow pointing up/down for ascending/descending soring */
- DoDrawString(_road_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 85, 15, 0x10);
+ DoDrawString(_road_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 69, 15, 0x10);
/* draw the roadvehicles */
{
@@ -833,13 +832,13 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch(e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
+ case 2: /* Flip sorting method ascending/descending */
_road_sort_order[(byte)w->window_number] ^= 1;
_road_sort_dirty[(byte)w->window_number] = true;
SetWindowDirty(w);
break;
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, _road_sort_type[(byte)w->window_number], 5, 0); // do it for widget 5
+ case 3: case 4:/* Select sorting criteria dropdown menu */
+ ShowDropDownMenu(w, _vehicle_sort_listing, _road_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
return;
case 6: { /* Matrix to show vehicles */
int id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
@@ -889,7 +888,7 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
_road_sort_type[(byte)w->window_number] = e->dropdown.index;
if (_road_sort_type[(byte)w->window_number] != SORT_BY_UNSORTED) // enable 'Sort By' if a sorter criteria is chosen
- w->disabled_state &= ~(1 << 3);
+ w->disabled_state &= ~(1 << 2);
SetWindowDirty(w);
break;
@@ -914,21 +913,21 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
static const Widget _player_roadveh_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
-{ WWT_MATRIX, 14, 0, 248, 26, 207, 0x701, STR_901A_ROAD_VEHICLES_CLICK_ON},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
+{ WWT_MATRIX, 14, 0, 248, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PUSHTXTBTN, 14, 0, 129, 208, 219, STR_9004_NEW_VEHICLES, STR_901B_BUILD_NEW_ROAD_VEHICLES},
-{ WWT_IMGBTN, 14, 130, 259, 208, 219, 0x0, 0},
+{ WWT_PUSHTXTBTN, 14, 0, 129, 208, 219, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES},
+{ WWT_PANEL, 14, 130, 259, 208, 219, 0x0, 0},
{ WWT_LAST},
};
static const WindowDesc _player_roadveh_desc = {
-1, -1, 260, 220,
WC_ROADVEH_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_player_roadveh_widgets,
PlayerRoadVehWndProc
};
@@ -936,11 +935,11 @@ static const WindowDesc _player_roadveh_desc = {
static const Widget _other_player_roadveh_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9001_ROAD_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
-{ WWT_MATRIX, 14, 0, 248, 26, 207, 0x701, STR_901A_ROAD_VEHICLES_CLICK_ON},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
+{ WWT_MATRIX, 14, 0, 248, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_LAST},
};
@@ -948,7 +947,7 @@ static const Widget _other_player_roadveh_widgets[] = {
static const WindowDesc _other_player_roadveh_desc = {
-1, -1, 260, 208,
WC_ROADVEH_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_other_player_roadveh_widgets,
PlayerRoadVehWndProc
};
diff --git a/ship_gui.c b/ship_gui.c
index 12f927b2b..a43db3295 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -911,11 +911,9 @@ static void MakeSortedShiptList(byte owner)
n = _num_ship_sort[owner] - _num_ship_sort[owner-1];
}
- _internal_sort_type = _ship_sort_type[owner];
_internal_sort_order = _ship_sort_order[owner];
_internal_name_sorter_id = STR_SV_SHIP_NAME;
- // only name sorting needs a different procedure, all others are handled by the general sorter
- qsort(firstelement, n, sizeof(_ship_sort[0]), (_internal_sort_type == SORT_BY_NAME) ? VehicleNameSorter : GeneralVehicleSorter);
+ qsort(firstelement, n, sizeof(_ship_sort[0]), _vehicle_sorter[_ship_sort_type[owner]]);
DEBUG(misc, 1) ("Resorting Ships list player %d...", owner+1);
}
@@ -928,7 +926,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
const byte window_number = (byte)w->window_number;
if (_ship_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
- w->disabled_state |= (1 << 3);
+ w->disabled_state |= (1 << 2);
if (_ship_sort_dirty[window_number] || _vehicle_sort_dirty[VEHSHIP]) {
_ship_sort_dirty[window_number] = false;
@@ -950,11 +948,12 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
SET_DPARAM16(0, p->name_1);
SET_DPARAM32(1, p->name_2);
SET_DPARAM16(2, w->vscroll.count);
- SET_DPARAM16(3, _vehicle_sort_listing[_ship_sort_type[window_number]]);
DrawWindowWidgets(w);
}
+ /* draw sorting criteria string */
+ DrawString(85, 15, _vehicle_sort_listing[_ship_sort_type[window_number]], 0x10);
/* draw arrow pointing up/down for ascending/descending soring */
- DoDrawString(_ship_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 85, 15, 0x10);
+ DoDrawString(_ship_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 69, 15, 0x10);
/* draw the ship vehicles */
{
@@ -1000,13 +999,13 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch(e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
+ case 2: /* Flip sorting method ascending/descending */
_ship_sort_order[(byte)w->window_number] ^= 1;
_ship_sort_dirty[(byte)w->window_number] = true;
SetWindowDirty(w);
break;
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, _ship_sort_type[(byte)w->window_number], 5, 0); // do it for widget 5
+ case 3: case 4:/* Select sorting criteria dropdown menu */
+ ShowDropDownMenu(w, _vehicle_sort_listing, _ship_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
return;
case 6: { /* Matrix to show vehicles */
int id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
@@ -1056,7 +1055,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
_ship_sort_type[(byte)w->window_number] = e->dropdown.index;
if (_ship_sort_type[(byte)w->window_number] != SORT_BY_UNSORTED) // enable 'Sort By' if a sorter criteria is chosen
- w->disabled_state &= ~(1 << 3);
+ w->disabled_state &= ~(1 << 2);
SetWindowDirty(w);
break;
@@ -1077,13 +1076,14 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
break;
}
}
+
static const Widget _player_ships_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, 0},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PUSHTXTBTN, 14, 0, 129, 170, 181, STR_9804_NEW_SHIPS, STR_9824_BUILD_NEW_SHIPS_REQUIRES},
@@ -1094,7 +1094,7 @@ static const Widget _player_ships_widgets[] = {
static const WindowDesc _player_ships_desc = {
-1, -1, 260, 182,
WC_SHIPS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_player_ships_widgets,
PlayerShipsWndProc
};
@@ -1102,10 +1102,10 @@ static const WindowDesc _player_ships_desc = {
static const Widget _other_player_ships_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_9805_SHIPS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 15, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 16, 96, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 97, 248, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 249, 259, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 237, 14, 25, 0x0, 0},
+{ WWT_CLOSEBOX, 14, 238, 248, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 249, 259, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 248, 26, 169, 0x401, STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
{ WWT_SCROLLBAR, 14, 249, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_LAST},
@@ -1114,7 +1114,7 @@ static const Widget _other_player_ships_widgets[] = {
static const WindowDesc _other_player_ships_desc = {
-1, -1, 260, 170,
WC_SHIPS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_other_player_ships_widgets,
PlayerShipsWndProc
};
diff --git a/train_gui.c b/train_gui.c
index 551b0e8e7..9e09d0a00 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -1180,11 +1180,9 @@ static void MakeSortedTrainList(byte owner)
n = _num_train_sort[owner] - _num_train_sort[owner-1];
}
- _internal_sort_type = _train_sort_type[owner];
_internal_sort_order = _train_sort_order[owner];
_internal_name_sorter_id = STR_SV_TRAIN_NAME;
- // only name sorting needs a different procedure, all others are handled by the general sorter
- qsort(firstelement, n, sizeof(_train_sort[0]), (_internal_sort_type == SORT_BY_NAME) ? VehicleNameSorter : GeneralVehicleSorter);
+ qsort(firstelement, n, sizeof(_train_sort[0]), _vehicle_sorter[_train_sort_type[owner]]);
DEBUG(misc, 1) ("Resorting Trains list player %d...", owner+1);
}
@@ -1197,7 +1195,7 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
const byte window_number = (byte)w->window_number;
if (_train_sort_type[window_number] == SORT_BY_UNSORTED) // disable 'Sort By' tooltip on Unsorted sorting criteria
- w->disabled_state |= (1 << 3);
+ w->disabled_state |= (1 << 2);
if (_train_sort_dirty[window_number] || _vehicle_sort_dirty[VEHTRAIN]) {
_train_sort_dirty[window_number] = false;
@@ -1219,11 +1217,12 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
SET_DPARAM16(0, p->name_1);
SET_DPARAM32(1, p->name_2);
SET_DPARAM16(2, w->vscroll.count);
- SET_DPARAM16(3, _vehicle_sort_listing[_train_sort_type[window_number]]);
DrawWindowWidgets(w);
}
+ /* draw sorting criteria string */
+ DrawString(85, 15, _vehicle_sort_listing[_train_sort_type[window_number]], 0x10);
/* draw arrow pointing up/down for ascending/descending soring */
- DoDrawString(_train_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 150, 15, 0x10);
+ DoDrawString(_train_sort_order[window_number] & 1 ? "\xAA" : "\xA0", 69, 15, 0x10);
/* draw the trains */
{
@@ -1266,13 +1265,13 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
switch(e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
+ case 2: /* Flip sorting method ascending/descending */
_train_sort_order[(byte)w->window_number] ^= 1;
_train_sort_dirty[(byte)w->window_number] = true;
SetWindowDirty(w);
break;
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, _train_sort_type[(byte)w->window_number], 5, 0); // do it for widget 5
+ case 3: case 4:/* Select sorting criteria dropdown menu */
+ ShowDropDownMenu(w, _vehicle_sort_listing, _train_sort_type[(byte)w->window_number], 4, 0); // do it for widget 4
return;
case 6: { /* Matrix to show vehicles */
int id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
@@ -1322,7 +1321,7 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
_train_sort_type[(byte)w->window_number] = e->dropdown.index;
if (_train_sort_type[(byte)w->window_number] != SORT_BY_UNSORTED) // enable 'Sort By' if a sorter criteria is chosen
- w->disabled_state &= ~(1 << 3);
+ w->disabled_state &= ~(1 << 2);
SetWindowDirty(w);
break;
@@ -1347,10 +1346,10 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
static const Widget _player_trains_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 80, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 81, 161, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 162, 313, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 314, 324, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 232, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 233, 243, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 244, 324, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 313, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
{ WWT_SCROLLBAR, 14, 314, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PUSHTXTBTN, 14, 0, 161, 208, 219, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES},
@@ -1361,7 +1360,7 @@ static const Widget _player_trains_widgets[] = {
static const WindowDesc _player_trains_desc = {
-1, -1, 325, 220,
WC_TRAINS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_player_trains_widgets,
PlayerTrainsWndProc
};
@@ -1369,10 +1368,10 @@ static const WindowDesc _player_trains_desc = {
static const Widget _other_player_trains_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, 14, 0, 80, 14, 25, 0x0, 0},
-{ WWT_PUSHTXTBTN, 14, 81, 161, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
-{ WWT_TEXTBTN, 14, 162, 313, 14, 25, STR_02E7, 0},
-{ WWT_CLOSEBOX, 14, 314, 324, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PUSHTXTBTN, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_TIP},
+{ WWT_PANEL, 14, 81, 232, 14, 25, 0x0, STR_SORT_TIP},
+{ WWT_CLOSEBOX, 14, 233, 243, 14, 25, STR_0225, STR_SORT_TIP},
+{ WWT_PANEL, 14, 244, 324, 14, 25, 0x0, 0},
{ WWT_MATRIX, 14, 0, 313, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
{ WWT_SCROLLBAR, 14, 314, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_LAST},
@@ -1381,7 +1380,7 @@ static const Widget _other_player_trains_widgets[] = {
static const WindowDesc _other_player_trains_desc = {
-1, -1, 325, 208,
WC_TRAINS_LIST,0,
- WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_other_player_trains_widgets,
PlayerTrainsWndProc
};
diff --git a/ttd.c b/ttd.c
index ec0c4f910..dfca2556a 100644
--- a/ttd.c
+++ b/ttd.c
@@ -581,6 +581,7 @@ int ttd_main(int argc, char* argv[])
LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
MusicLoop();
+ _savegame_sort_order = 1; // default sorting of savegames is by date, newest first
// Default difficulty level
_opt_mod_ptr = &_new_opt;
diff --git a/ttd.h b/ttd.h
index ab4ffa391..6426eb506 100644
--- a/ttd.h
+++ b/ttd.h
@@ -524,10 +524,10 @@ enum Sprites {
};
enum MAP_OWNERS {
- OWNER_TOWN = 0xf, // a town owns the tile
- OWNER_NONE = 0x10,// nobody owns the tile
- OWNER_WATER = 0x11,// "water" owns the tile
- OWNER_SPECTATOR = 0xff, // spectator in MP or in scenario editor
+ OWNER_TOWN = 0xf, // a town owns the tile
+ OWNER_NONE = 0x10, // nobody owns the tile
+ OWNER_WATER = 0x11, // "water" owns the tile
+ OWNER_SPECTATOR = 0xff, // spectator in MP or in scenario editor
};
VARDEF bool _savegame_sort_dirty;
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 751e3d230..3edd898ef 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -45,103 +45,150 @@ void DrawVehicleProfitButton(Vehicle *v, int x, int y)
/************ Sorter functions *****************/
int CDECL GeneralOwnerSorter(const void *a, const void *b)
{
- return (*(SortStruct*)a).owner - (*(SortStruct*)b).owner;
+ return (*(const SortStruct*)a).owner - (*(const SortStruct*)b).owner;
}
-static char _bufcache[64]; // used together with _last_vehicle_idx to hopefully speed up stringsorting
-
/* Variables you need to set before calling this function!
-* 1. (uint32)_internal_name_sorter_id: default StringID of the vehicle when no name is set. eg
-* STR_SV_TRAIN_NAME for trains or STR_SV_AIRCRAFT_NAME for aircraft
+* 1. (byte)_internal_sort_type: sorting criteria to sort on
* 2. (bool)_internal_sort_order: sorting order, descending/ascending
+* 3. (uint32)_internal_name_sorter_id: default StringID of the vehicle when no name is set. eg
+* STR_SV_TRAIN_NAME for trains or STR_SV_AIRCRAFT_NAME for aircraft
*/
+int CDECL VehicleUnsortedSorter(const void *a, const void *b)
+{
+ return DEREF_VEHICLE((*(const SortStruct*)a).index)->index - DEREF_VEHICLE((*(const SortStruct*)b).index)->index;
+}
+
+int CDECL VehicleNumberSorter(const void *a, const void *b)
+{
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->unitnumber - vb->unitnumber;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
+static char _bufcache[64]; // used together with _last_vehicle_idx to hopefully speed up stringsorting
int CDECL VehicleNameSorter(const void *a, const void *b)
{
- SortStruct *cmp1 = (SortStruct*)a;
- SortStruct *cmp2 = (SortStruct*)b;
- Vehicle *v;
+ const SortStruct *cmp1 = (SortStruct*)a;
+ const SortStruct *cmp2 = (SortStruct*)b;
+ const Vehicle *va = DEREF_VEHICLE(cmp1->index);
+ const Vehicle *vb = DEREF_VEHICLE(cmp2->index);
char buf1[64] = "\0";
int r;
- v = DEREF_VEHICLE(cmp1->index);
- if (v->string_id != _internal_name_sorter_id) {
- SET_DPARAM16(0, v->string_id);
+ if (va->string_id != _internal_name_sorter_id) {
+ SET_DPARAM16(0, va->string_id);
GetString(buf1, STR_0315);
}
if ( cmp2->index != _last_vehicle_idx) {
_last_vehicle_idx = cmp2->index;
- v = DEREF_VEHICLE(cmp2->index);
_bufcache[0] = '\0';
- if (v->string_id != _internal_name_sorter_id) {
- SET_DPARAM16(0, v->string_id);
+ if (vb->string_id != _internal_name_sorter_id) {
+ SET_DPARAM16(0, vb->string_id);
GetString(_bufcache, STR_0315);
}
}
r = strcmp(buf1, _bufcache); // sort by name
- if (_internal_sort_order & 1) r = -r;
- return r;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
}
-/* Variables you need to set before calling this function!
-* 1. (byte)_internal_sort_type: the criteria by which to sort these vehicles (number, age, etc)
-* 2. (bool)_internal_sort_order: sorting order, descending/ascending
-*/
-int CDECL GeneralVehicleSorter(const void *a, const void *b)
+int CDECL VehicleAgeSorter(const void *a, const void *b)
{
- SortStruct *cmp1 = (SortStruct*)a;
- SortStruct *cmp2 = (SortStruct*)b;
- Vehicle *va = DEREF_VEHICLE(cmp1->index);
- Vehicle *vb = DEREF_VEHICLE(cmp2->index);
- int r;
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->age - vb->age;
- switch (_internal_sort_type) {
- case SORT_BY_UNSORTED: /* Sort unsorted */
- return va->index - vb->index;
- case SORT_BY_NUMBER: /* Sort by Number */
- r = va->unitnumber - vb->unitnumber;
- break;
- /* case SORT_BY_NAME: Sort by Name (VehicleNameSorter)*/
- case SORT_BY_AGE: /* Sort by Age */
- r = va->age - vb->age;
- break;
- case SORT_BY_PROFIT_THIS_YEAR: /* Sort by Profit this year */
- r = va->profit_this_year - vb->profit_this_year;
- break;
- case SORT_BY_PROFIT_LAST_YEAR: /* Sort by Profit last year */
- r = va->profit_last_year - vb->profit_last_year;
- break;
- case SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE: { /* Sort by Total capacity per cargotype */
- // FIXME - someone write a normal cargo sorter that also works by cargo_cap,
- // FIXME - since I seem to be unable to do so :S
- Vehicle *ua = va;
- Vehicle *ub = vb;
- int i;
- byte _cargo_counta[NUM_CARGO];
- byte _cargo_countb[NUM_CARGO];
- do {
- _cargo_counta[ua->cargo_type]++;
- } while ( (ua = ua->next) != NULL);
- do {
- _cargo_countb[ub->cargo_type]++;
- } while ( (ub = ub->next) != NULL);
-
- for (i = 0; i < NUM_CARGO; i++) {
- r = _cargo_counta[i] - _cargo_countb[i];
- if (r != 0)
- break;
- }
- } break;
- case SORT_BY_RELIABILITY: /* Sort by Reliability */
- r = va->reliability - vb->reliability;
- break;
- case SORT_BY_MAX_SPEED: /* Sort by Max speed */
- r = va->max_speed - vb->max_speed;
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
+int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
+{
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->profit_this_year - vb->profit_this_year;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
+int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
+{
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->profit_last_year - vb->profit_last_year;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
+int CDECL VehicleCargoSorter(const void *a, const void *b)
+{
+ // FIXME - someone write a normal cargo sorter that also works by cargo_cap,
+ // FIXME - since I seem to be unable to do so :S
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = 0;
+ int i;
+ byte _cargo_counta[NUM_CARGO];
+ byte _cargo_countb[NUM_CARGO];
+ memset(_cargo_counta, 0, sizeof(_cargo_counta));
+ memset(_cargo_countb, 0, sizeof(_cargo_countb));
+
+ do {
+ _cargo_counta[va->cargo_type]++;
+ } while ( (va = va->next) != NULL);
+
+ do {
+ _cargo_countb[vb->cargo_type]++;
+ } while ( (vb = vb->next) != NULL);
+
+ for (i = 0; i < NUM_CARGO; i++) {
+ r = _cargo_counta[i] - _cargo_countb[i];
+ if (r != 0)
break;
- default: NOT_REACHED();
}
-
- if (_internal_sort_order & 1) r = -r;
- return r;
+
+ return (_internal_sort_order & 1) ? -r : r;
+}
+
+int CDECL VehicleReliabilitySorter(const void *a, const void *b)
+{
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->reliability - vb->reliability;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
}
+
+int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
+{
+ const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
+ const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
+ int r = va->max_speed - vb->max_speed;
+
+ if (r == 0) // if the sorting criteria had the same value, sort by unitnumber
+ r = va->unitnumber - vb->unitnumber;
+
+ return (_internal_sort_order & 1) ? -r : r;
+} \ No newline at end of file
diff --git a/vehicle_gui.h b/vehicle_gui.h
index b6da5085f..0ca135500 100644
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -5,33 +5,46 @@ void DrawVehicleProfitButton(Vehicle *v, int x, int y);
void InitializeVehiclesGuiList();
/* sorter stuff */
-int CDECL GeneralOwnerSorter (const void *a, const void *b);
-int CDECL VehicleNameSorter (const void *a, const void *b);
-int CDECL GeneralVehicleSorter(const void *a, const void *b);
-VARDEF uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
-VARDEF uint32 _last_vehicle_idx; // cached index to hopefully speed up name-sorting
-VARDEF bool _internal_sort_order; // descending/ascending
-VARDEF byte _internal_sort_type; // Miscalleneous sorting criteria
-
typedef struct SortStruct { // store owner through sorting process
uint32 index;
byte owner;
} SortStruct;
+int CDECL GeneralOwnerSorter(const void *a, const void *b);
+void VehicleSorter(SortStruct *firstelement, uint32 n, uint16 size);
+VARDEF uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
+VARDEF uint32 _last_vehicle_idx; // cached index to hopefully speed up name-sorting
+VARDEF bool _internal_sort_order; // descending/ascending
+
#define PERIODIC_RESORT_DAYS 10
+#define DEF_SORTER(yyyy) int CDECL yyyy(const void *a, const void *b)
+
+DEF_SORTER(VehicleUnsortedSorter);
+DEF_SORTER(VehicleNumberSorter);
+DEF_SORTER(VehicleNameSorter);
+DEF_SORTER(VehicleAgeSorter);
+DEF_SORTER(VehicleProfitThisYearSorter);
+DEF_SORTER(VehicleProfitLastYearSorter);
+DEF_SORTER(VehicleCargoSorter);
+DEF_SORTER(VehicleReliabilitySorter);
+DEF_SORTER(VehicleMaxSpeedSorter);
-enum VehicleSortListingTypes {
- SORT_BY_UNSORTED = 0,
- SORT_BY_NUMBER = 1,
- SORT_BY_NAME = 2,
- SORT_BY_AGE = 3,
- SORT_BY_PROFIT_THIS_YEAR = 4,
- SORT_BY_PROFIT_LAST_YEAR = 5,
- SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE = 6,
- SORT_BY_RELIABILITY = 7,
- SORT_BY_MAX_SPEED = 8
+typedef DEF_SORTER(VehicleSortListingTypeFunctions);
+
+static VehicleSortListingTypeFunctions * const _vehicle_sorter[] = {
+ &VehicleUnsortedSorter,
+ &VehicleNumberSorter,
+ &VehicleNameSorter,
+ &VehicleAgeSorter,
+ &VehicleProfitThisYearSorter,
+ &VehicleProfitLastYearSorter,
+ &VehicleCargoSorter,
+ &VehicleReliabilitySorter,
+ &VehicleMaxSpeedSorter
};
+#define SORT_BY_UNSORTED 0
+
static const uint16 _vehicle_sort_listing[] = {
STR_SORT_BY_UNSORTED,
STR_SORT_BY_NUMBER,
diff --git a/water_cmd.c b/water_cmd.c
index 789ceb446..d96be9840 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -521,8 +521,8 @@ static void TileLoopWaterHelper(uint tile, const int16 *offs)
static void FloodVehicle(Vehicle *v)
{
Vehicle *u;
- uint16 pass;
if (!(v->vehstatus & VS_CRASHED)) {
+ uint16 pass = 0;
if (v->type == VEH_Road) { // flood bus/truck
pass = 1; // driver
@@ -550,7 +550,8 @@ static void FloodVehicle(Vehicle *v)
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
_vehicle_sort_dirty[VEHTRAIN] = true;
InvalidateWindow(WC_TRAINS_LIST, v->owner);
- }
+ } else
+ return;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);