vehicle_gui.c
author tron
Sat, 11 Dec 2004 11:00:54 +0000
changeset 594 1b51f81b4a77
parent 588 03521b270f62
child 842 efc3546bc313
permissions -rw-r--r--
(svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
Also add the number sorter to sort by vehicle number if the cargo capacity is equal.
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
     1
#include "stdafx.h"
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
     2
#include "ttd.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 505
diff changeset
     3
#include "table/strings.h"
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
     4
#include "vehicle.h"
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
     5
#include "window.h"
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
     6
505
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
     7
VehicleSortListingTypeFunctions * const _vehicle_sorter[] = {
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
     8
	&VehicleUnsortedSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
     9
	&VehicleNumberSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    10
	&VehicleNameSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    11
	&VehicleAgeSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    12
	&VehicleProfitThisYearSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    13
	&VehicleProfitLastYearSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    14
	&VehicleCargoSorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    15
	&VehicleReliabilitySorter,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    16
	&VehicleMaxSpeedSorter
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    17
};
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    18
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    19
const StringID _vehicle_sort_listing[] = {
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    20
	STR_SORT_BY_UNSORTED,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    21
	STR_SORT_BY_NUMBER,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    22
	STR_SORT_BY_DROPDOWN_NAME,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    23
	STR_SORT_BY_AGE,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    24
	STR_SORT_BY_PROFIT_THIS_YEAR,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    25
	STR_SORT_BY_PROFIT_LAST_YEAR,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    26
	STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    27
	STR_SORT_BY_RELIABILITY,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    28
	STR_SORT_BY_MAX_SPEED,
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    29
	INVALID_STRING_ID
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    30
};
1d5e770d2ce4 (svn r813) Push two tables from vehicle_gui.h into vehicle_gui.c - they were in the binary 48 (!) times.
tron
parents: 243
diff changeset
    31
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    32
void RebuildVehicleLists(void)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    33
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    34
	Window *w;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    35
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    36
	for (w = _windows; w != _last_window; ++w)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    37
		switch (w->window_class) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    38
			case WC_TRAINS_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    39
			case WC_ROADVEH_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    40
			case WC_SHIPS_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    41
			case WC_AIRCRAFT_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    42
				WP(w, vehiclelist_d).flags |= VL_REBUILD;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    43
				SetWindowDirty(w);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    44
				break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    45
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    46
			default:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    47
				break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    48
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    49
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    50
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    51
void ResortVehicleLists(void)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    52
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    53
	Window *w;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    54
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    55
	for (w = _windows; w != _last_window; ++w)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    56
		switch (w->window_class) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    57
			case WC_TRAINS_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    58
			case WC_ROADVEH_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    59
			case WC_SHIPS_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    60
			case WC_AIRCRAFT_LIST:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    61
				WP(w, vehiclelist_d).flags |= VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    62
				SetWindowDirty(w);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    63
				break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    64
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    65
			default:
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    66
				break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    67
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    68
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    69
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    70
void BuildVehicleList(vehiclelist_d *vl, int type, int owner, int station)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    71
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    72
	SortStruct sort_list[NUM_NORMAL_VEHICLES];
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    73
	int subtype = (type != VEH_Aircraft) ? 0 : 2;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    74
	int n = 0;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    75
	int i;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    76
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    77
	if (!(vl->flags & VL_REBUILD)) return;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    78
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    79
	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    80
		owner, station);	
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    81
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    82
	if (station != -1) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    83
		const Vehicle *v;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    84
		FOR_ALL_VEHICLES(v) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    85
			if (v->type == type && v->subtype <= subtype) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    86
				const Order *ord;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    87
				for (ord = v->schedule_ptr; ord->type != OT_NOTHING; ++ord)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    88
					if (ord->type == OT_GOTO_STATION && ord->station == station) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    89
						sort_list[n].index = v - _vehicles;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    90
						sort_list[n].owner = v->owner;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    91
						++n;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    92
						break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    93
					}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    94
			}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    95
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    96
	} else {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    97
		const Vehicle *v;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    98
		FOR_ALL_VEHICLES(v) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    99
			if (v->type == type && v->subtype <= subtype && v->owner == owner) {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   100
				sort_list[n].index = v - _vehicles;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   101
				sort_list[n].owner = v->owner;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   102
				++n;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   103
			}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   104
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   105
	}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   106
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   107
	vl->sort_list = realloc(vl->sort_list, n * sizeof(vl->sort_list[0])); /* XXX unchecked malloc */
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   108
	vl->list_length = n;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   109
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   110
	for (i = 0; i < n; ++i)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   111
		vl->sort_list[i] = sort_list[i];
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   112
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   113
	vl->flags &= ~VL_REBUILD;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   114
	vl->flags |= VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   115
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   116
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   117
void SortVehicleList(vehiclelist_d *vl)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   118
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   119
	if (!(vl->flags & VL_RESORT)) return;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   120
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   121
	_internal_sort_order = vl->flags & VL_DESC;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   122
	_internal_name_sorter_id = STR_SV_TRAIN_NAME;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   123
	_last_vehicle_idx = 0; // used for "cache" in namesorting
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   124
	qsort(vl->sort_list, vl->list_length, sizeof(vl->sort_list[0]),
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   125
		_vehicle_sorter[vl->sort_type]);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   126
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   127
	vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   128
	vl->flags &= ~VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   129
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   130
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   131
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   132
/* General Vehicle GUI based procedures that are independent of vehicle types */
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   133
void InitializeVehiclesGuiList()
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   134
{
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   135
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   136
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   137
// draw the vehicle profit button in the vehicle list window.
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   138
void DrawVehicleProfitButton(Vehicle *v, int x, int y)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   139
{
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   140
	uint32 ormod;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   141
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   142
	// draw profit-based colored icons
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   143
	if(v->age <= 365 * 2)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   144
		ormod = 0x3158000; // grey
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   145
	else if(v->profit_last_year < 0)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   146
		ormod = 0x30b8000; //red
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   147
	else if(v->profit_last_year < 10000)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   148
		ormod = 0x30a8000; // yellow
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   149
	else
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   150
		ormod = 0x30d8000; // green
579
e977d17c89b1 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 534
diff changeset
   151
	DrawSprite((SPR_BLOT) | ormod, x, y);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   152
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   153
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   154
/************ Sorter functions *****************/
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   155
int CDECL GeneralOwnerSorter(const void *a, const void *b)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   156
{
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   157
	return (*(const SortStruct*)a).owner - (*(const SortStruct*)b).owner;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   158
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   159
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   160
/* Variables you need to set before calling this function!
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   161
* 1. (byte)_internal_sort_type:					sorting criteria to sort on
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   162
* 2. (bool)_internal_sort_order:				sorting order, descending/ascending
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   163
* 3. (uint32)_internal_name_sorter_id:	default StringID of the vehicle when no name is set. eg
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   164
*    STR_SV_TRAIN_NAME for trains or STR_SV_AIRCRAFT_NAME for aircraft
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   165
*/
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   166
int CDECL VehicleUnsortedSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   167
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   168
	return DEREF_VEHICLE((*(const SortStruct*)a).index)->index - DEREF_VEHICLE((*(const SortStruct*)b).index)->index;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   169
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   170
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   171
// if the sorting criteria had the same value, sort vehicle by unitnumber
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   172
#define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}}
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   173
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   174
int CDECL VehicleNumberSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   175
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   176
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   177
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   178
	int r = va->unitnumber - vb->unitnumber;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   179
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   180
	return (_internal_sort_order & 1) ? -r : r;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   181
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   182
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   183
static char _bufcache[64];	// used together with _last_vehicle_idx to hopefully speed up stringsorting
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   184
int CDECL VehicleNameSorter(const void *a, const void *b)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   185
{
171
29854f28b90b (svn r172) -Fix: warning fixes (Tron)
darkvater
parents: 168
diff changeset
   186
	const SortStruct *cmp1 = (const SortStruct*)a;
29854f28b90b (svn r172) -Fix: warning fixes (Tron)
darkvater
parents: 168
diff changeset
   187
	const SortStruct *cmp2 = (const SortStruct*)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   188
	const Vehicle *va = DEREF_VEHICLE(cmp1->index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   189
	const Vehicle *vb = DEREF_VEHICLE(cmp2->index);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   190
	char buf1[64] = "\0";
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   191
	int r;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   192
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   193
	if (va->string_id != _internal_name_sorter_id) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   194
		SetDParam(0, va->string_id);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   195
		GetString(buf1, STR_0315);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   196
	}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   197
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   198
	if ( cmp2->index != _last_vehicle_idx) {
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   199
		_last_vehicle_idx = cmp2->index;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   200
		_bufcache[0] = '\0';
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   201
		if (vb->string_id != _internal_name_sorter_id) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   202
			SetDParam(0, vb->string_id);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   203
			GetString(_bufcache, STR_0315);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   204
		}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   205
	}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   206
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   207
	r =  strcmp(buf1, _bufcache);	// sort by name
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 171
diff changeset
   208
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   209
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   210
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   211
	return (_internal_sort_order & 1) ? -r : r;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   212
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   213
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   214
int CDECL VehicleAgeSorter(const void *a, const void *b)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   215
{
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   216
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   217
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   218
	int r = va->age - vb->age;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   219
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   220
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   221
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   222
	return (_internal_sort_order & 1) ? -r : r;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   223
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   224
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   225
int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   226
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   227
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   228
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   229
	int r = va->profit_this_year - vb->profit_this_year;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 171
diff changeset
   230
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   231
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   232
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   233
	return (_internal_sort_order & 1) ? -r : r;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   234
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   235
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   236
int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   237
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   238
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   239
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   240
	int r = va->profit_last_year - vb->profit_last_year;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   241
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   242
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   243
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   244
	return (_internal_sort_order & 1) ? -r : r;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   245
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   246
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   247
int CDECL VehicleCargoSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   248
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   249
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   250
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
594
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   251
	const Vehicle *v;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   252
	int r = 0;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   253
	int i;
594
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   254
	uint _cargo_counta[NUM_CARGO];
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   255
	uint _cargo_countb[NUM_CARGO];
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   256
	memset(_cargo_counta, 0, sizeof(_cargo_counta));
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   257
	memset(_cargo_countb, 0, sizeof(_cargo_countb));
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   258
594
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   259
	for (v = va; v != NULL; v = v->next)
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   260
		_cargo_counta[v->cargo_type] += v->cargo_cap;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   261
594
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   262
	for (v = vb; v != NULL; v = v->next)
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   263
		_cargo_countb[v->cargo_type] += v->cargo_cap;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   264
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   265
	for (i = 0; i < NUM_CARGO; i++) {
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   266
		r = _cargo_counta[i] - _cargo_countb[i];
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   267
		if (r != 0)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   268
			break;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   269
	}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   270
594
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   271
	VEHICLEUNITNUMBERSORTER(r, va, vb);
1b51f81b4a77 (svn r1016) Make the cargo sorter not consider the number of wagons of a particular cargo type but the sum of their capacity.
tron
parents: 588
diff changeset
   272
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   273
	return (_internal_sort_order & 1) ? -r : r;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
diff changeset
   274
}
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   275
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   276
int CDECL VehicleReliabilitySorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   277
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   278
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   279
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   280
	int r = va->reliability - vb->reliability;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   281
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   282
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   283
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   284
	return (_internal_sort_order & 1) ? -r : r;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   285
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   286
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   287
int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   288
{
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   289
	const Vehicle *va = DEREF_VEHICLE((*(const SortStruct*)a).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   290
	const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index);
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   291
	int r = va->max_speed - vb->max_speed;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   292
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   293
	VEHICLEUNITNUMBERSORTER(r, va, vb);
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   294
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   295
	return (_internal_sort_order & 1) ? -r : r;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 171
diff changeset
   296
}