author | bjarni |
Sun, 02 Jan 2005 17:23:04 +0000 | |
changeset 842 | ebfd36603ab9 |
parent 594 | 81c0d7edfb17 |
child 843 | 310555bdedf8 |
permissions | -rw-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
|
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
8aa8100b0b22
(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 | 5 |
#include "window.h" |
842 | 6 |
#include "engine.h" |
7 |
#include "gui.h" |
|
8 |
#include "command.h" |
|
9 |
#include "gfx.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
|
10 |
|
505
11582dcada49
(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 |
VehicleSortListingTypeFunctions * const _vehicle_sorter[] = { |
11582dcada49
(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 |
&VehicleUnsortedSorter, |
11582dcada49
(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 |
&VehicleNumberSorter, |
11582dcada49
(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 |
&VehicleNameSorter, |
11582dcada49
(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 |
&VehicleAgeSorter, |
11582dcada49
(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 |
&VehicleProfitThisYearSorter, |
11582dcada49
(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 |
&VehicleProfitLastYearSorter, |
11582dcada49
(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 |
&VehicleCargoSorter, |
11582dcada49
(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 |
&VehicleReliabilitySorter, |
11582dcada49
(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 |
&VehicleMaxSpeedSorter |
11582dcada49
(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 |
}; |
11582dcada49
(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 |
|
11582dcada49
(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 |
const StringID _vehicle_sort_listing[] = { |
11582dcada49
(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_UNSORTED, |
11582dcada49
(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_NUMBER, |
11582dcada49
(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_DROPDOWN_NAME, |
11582dcada49
(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_AGE, |
11582dcada49
(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_PROFIT_THIS_YEAR, |
11582dcada49
(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 |
STR_SORT_BY_PROFIT_LAST_YEAR, |
11582dcada49
(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 |
STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE, |
11582dcada49
(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 |
STR_SORT_BY_RELIABILITY, |
11582dcada49
(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
|
32 |
STR_SORT_BY_MAX_SPEED, |
11582dcada49
(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
|
33 |
INVALID_STRING_ID |
11582dcada49
(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
|
34 |
}; |
11582dcada49
(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
|
35 |
|
842 | 36 |
const StringID _rail_types_list[] = { |
37 |
STR_RAIL_VEHICLES, |
|
38 |
STR_MONORAIL_VEHICLES, |
|
39 |
STR_MAGLEV_VEHICLES, |
|
40 |
INVALID_STRING_ID |
|
41 |
}; |
|
42 |
||
588 | 43 |
void RebuildVehicleLists(void) |
44 |
{ |
|
45 |
Window *w; |
|
46 |
||
47 |
for (w = _windows; w != _last_window; ++w) |
|
48 |
switch (w->window_class) { |
|
49 |
case WC_TRAINS_LIST: |
|
50 |
case WC_ROADVEH_LIST: |
|
51 |
case WC_SHIPS_LIST: |
|
52 |
case WC_AIRCRAFT_LIST: |
|
53 |
WP(w, vehiclelist_d).flags |= VL_REBUILD; |
|
54 |
SetWindowDirty(w); |
|
55 |
break; |
|
56 |
||
57 |
default: |
|
58 |
break; |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
void ResortVehicleLists(void) |
|
63 |
{ |
|
64 |
Window *w; |
|
65 |
||
66 |
for (w = _windows; w != _last_window; ++w) |
|
67 |
switch (w->window_class) { |
|
68 |
case WC_TRAINS_LIST: |
|
69 |
case WC_ROADVEH_LIST: |
|
70 |
case WC_SHIPS_LIST: |
|
71 |
case WC_AIRCRAFT_LIST: |
|
72 |
WP(w, vehiclelist_d).flags |= VL_RESORT; |
|
73 |
SetWindowDirty(w); |
|
74 |
break; |
|
75 |
||
76 |
default: |
|
77 |
break; |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
void BuildVehicleList(vehiclelist_d *vl, int type, int owner, int station) |
|
82 |
{ |
|
83 |
SortStruct sort_list[NUM_NORMAL_VEHICLES]; |
|
84 |
int subtype = (type != VEH_Aircraft) ? 0 : 2; |
|
85 |
int n = 0; |
|
86 |
int i; |
|
87 |
||
88 |
if (!(vl->flags & VL_REBUILD)) return; |
|
89 |
||
90 |
DEBUG(misc, 1) ("Building vehicle list for player %d station %d...", |
|
91 |
owner, station); |
|
92 |
||
93 |
if (station != -1) { |
|
94 |
const Vehicle *v; |
|
95 |
FOR_ALL_VEHICLES(v) { |
|
96 |
if (v->type == type && v->subtype <= subtype) { |
|
97 |
const Order *ord; |
|
98 |
for (ord = v->schedule_ptr; ord->type != OT_NOTHING; ++ord) |
|
99 |
if (ord->type == OT_GOTO_STATION && ord->station == station) { |
|
100 |
sort_list[n].index = v - _vehicles; |
|
101 |
sort_list[n].owner = v->owner; |
|
102 |
++n; |
|
103 |
break; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} else { |
|
108 |
const Vehicle *v; |
|
109 |
FOR_ALL_VEHICLES(v) { |
|
110 |
if (v->type == type && v->subtype <= subtype && v->owner == owner) { |
|
111 |
sort_list[n].index = v - _vehicles; |
|
112 |
sort_list[n].owner = v->owner; |
|
113 |
++n; |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
vl->sort_list = realloc(vl->sort_list, n * sizeof(vl->sort_list[0])); /* XXX unchecked malloc */ |
|
119 |
vl->list_length = n; |
|
120 |
||
121 |
for (i = 0; i < n; ++i) |
|
122 |
vl->sort_list[i] = sort_list[i]; |
|
123 |
||
124 |
vl->flags &= ~VL_REBUILD; |
|
125 |
vl->flags |= VL_RESORT; |
|
126 |
} |
|
127 |
||
128 |
void SortVehicleList(vehiclelist_d *vl) |
|
129 |
{ |
|
130 |
if (!(vl->flags & VL_RESORT)) return; |
|
131 |
||
132 |
_internal_sort_order = vl->flags & VL_DESC; |
|
133 |
_internal_name_sorter_id = STR_SV_TRAIN_NAME; |
|
134 |
_last_vehicle_idx = 0; // used for "cache" in namesorting |
|
135 |
qsort(vl->sort_list, vl->list_length, sizeof(vl->sort_list[0]), |
|
136 |
_vehicle_sorter[vl->sort_type]); |
|
137 |
||
138 |
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; |
|
139 |
vl->flags &= ~VL_RESORT; |
|
140 |
} |
|
141 |
||
142 |
||
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
|
143 |
/* 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
|
144 |
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
|
145 |
{ |
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 |
} |
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 |
|
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 |
// 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
|
149 |
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
|
150 |
{ |
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
|
151 |
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
|
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 |
// 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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
ormod = 0x30d8000; // green |
579
08ce4c50bd32
(svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents:
534
diff
changeset
|
162 |
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
|
163 |
} |
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
|
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
|
165 |
/************ 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
|
166 |
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
|
167 |
{ |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
168 |
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
|
169 |
} |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
170 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
171 |
/* 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
|
172 |
* 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
|
173 |
* 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
|
174 |
* 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
|
175 |
* 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
|
176 |
*/ |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
177 |
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
|
178 |
{ |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
179 |
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
|
180 |
} |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
181 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
182 |
// 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
|
183 |
#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
|
184 |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
185 |
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
|
186 |
{ |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
191 |
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
|
192 |
} |
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
|
193 |
|
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
|
194 |
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
|
195 |
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
|
196 |
{ |
171 | 197 |
const SortStruct *cmp1 = (const SortStruct*)a; |
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
204 |
if (va->string_id != _internal_name_sorter_id) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
} |
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
|
208 |
|
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
|
209 |
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
|
210 |
_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
|
211 |
_bufcache[0] = '\0'; |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
212 |
if (vb->string_id != _internal_name_sorter_id) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
213 |
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
|
214 |
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
|
215 |
} |
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
|
216 |
} |
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
|
217 |
|
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
|
218 |
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
|
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; |
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
|
223 |
} |
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
|
224 |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
225 |
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
|
226 |
{ |
168
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->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
|
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 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
|
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_this_year - vb->profit_this_year; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
171
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 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
|
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); |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
251 |
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
|
252 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
253 |
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
|
254 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
255 |
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
|
256 |
} |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
257 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
258 |
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
|
259 |
{ |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
260 |
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
|
261 |
const Vehicle *vb = DEREF_VEHICLE((*(const SortStruct*)b).index); |
594
81c0d7edfb17
(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 |
const Vehicle *v; |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
263 |
int r = 0; |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
264 |
int i; |
594
81c0d7edfb17
(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
|
265 |
uint _cargo_counta[NUM_CARGO]; |
81c0d7edfb17
(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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
|
594
81c0d7edfb17
(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
|
270 |
for (v = va; v != NULL; v = v->next) |
81c0d7edfb17
(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 |
_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
|
272 |
|
594
81c0d7edfb17
(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
|
273 |
for (v = vb; v != NULL; v = v->next) |
81c0d7edfb17
(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
|
274 |
_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
|
275 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
break; |
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
280 |
} |
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
|
281 |
|
594
81c0d7edfb17
(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
|
282 |
VEHICLEUNITNUMBERSORTER(r, va, vb); |
81c0d7edfb17
(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
|
283 |
|
168
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; |
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
|
285 |
} |
168
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 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
|
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->reliability - vb->reliability; |
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; |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
296 |
} |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
297 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
298 |
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
|
299 |
{ |
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
|
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
193
diff
changeset
|
304 |
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
|
305 |
|
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
164
diff
changeset
|
306 |
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
|
307 |
} |
842 | 308 |
|
309 |
// this define is to match engine.c, but engine.c keeps it to itself |
|
310 |
// ENGINE_AVAILABLE is used in ReplaceVehicleWndProc |
|
311 |
#define ENGINE_AVAILABLE ((e->flags & 1 && HASBIT(info->railtype_climates, _opt.landscape)) || HASBIT(e->player_avail, _local_player)) |
|
312 |
||
313 |
/* if show_outdated is selected, it do not sort psudo engines properly but it draws all engines |
|
314 |
* if used compined with show_cars set to false, it will work as intended. Replace window do it like that |
|
315 |
* this was a big hack even before show_outdated was added. Stupid newgrf :p */ |
|
316 |
static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, int *selected_id, byte railtype, |
|
317 |
uint8 lines_drawn, bool is_engine, bool show_cars, bool show_outdated) |
|
318 |
{ |
|
319 |
int i; |
|
320 |
byte colour; |
|
321 |
||
322 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
|
323 |
const Engine *e = DEREF_ENGINE(i); |
|
324 |
const RailVehicleInfo *rvi = RailVehInfo(i); |
|
325 |
const EngineInfo *info = &_engine_info[i]; |
|
326 |
||
327 |
if ( rvi->power == 0 && !(show_cars) ) // disables display of cars (works since they do not have power) |
|
328 |
continue; |
|
329 |
||
330 |
if (*sel == 0) *selected_id = i; |
|
331 |
||
332 |
||
333 |
colour = *sel == 0 ? 0xC : 0x10; |
|
334 |
if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && e->railtype == railtype)) { |
|
335 |
if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine || |
|
336 |
!HASBIT(e->player_avail, _local_player)) |
|
337 |
continue; |
|
338 |
} /*else { |
|
339 |
// TODO find a nice red colour for vehicles being replaced |
|
340 |
if ( _autoreplace_array[i] != i ) |
|
341 |
colour = *sel == 0 ? 0x44 : 0x45; |
|
342 |
} */ |
|
343 |
||
344 |
if (IS_INT_INSIDE(--*pos, -lines_drawn, 0)) { |
|
345 |
DrawString(*x + 59, *y + 2, GetCustomEngineName(i), |
|
346 |
colour); |
|
347 |
DrawTrainEngine(*x + 29, *y + 6, i, |
|
348 |
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
349 |
*y += 14; |
|
350 |
} |
|
351 |
--*sel; |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
||
356 |
static void SetupScrollStuffForReplaceWindow(Window *w) |
|
357 |
{ |
|
358 |
byte railtype; |
|
359 |
int selected_id[2] = {-1,-1}; |
|
360 |
int sel[2] = { WP(w,replaceveh_d).sel_index[0], WP(w,replaceveh_d).sel_index[1]}; |
|
361 |
int count = 0; |
|
362 |
int count2 = 0; |
|
363 |
int engine_id; |
|
364 |
||
365 |
switch (WP(w,replaceveh_d).vehicletype) { |
|
366 |
case VEH_Train: { |
|
367 |
railtype = WP(w,replaceveh_d).railtype; |
|
368 |
for (engine_id = 0; engine_id < NUM_TRAIN_ENGINES; engine_id++) { |
|
369 |
const Engine *e = DEREF_ENGINE(engine_id); |
|
370 |
const EngineInfo *info = &_engine_info[engine_id]; |
|
371 |
||
372 |
if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype) { |
|
373 |
count++; |
|
374 |
if (sel[0]==0) selected_id[0] = engine_id; |
|
375 |
sel[0]--; |
|
376 |
if (HASBIT(e->player_avail, _local_player)) { |
|
377 |
if (sel[1]==0) selected_id[1] = engine_id; |
|
378 |
count2++; |
|
379 |
sel[1]--; |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
break; |
|
384 |
} |
|
385 |
case VEH_Road: { |
|
386 |
int num = NUM_ROAD_ENGINES; |
|
387 |
Engine *e = &_engines[ROAD_ENGINES_INDEX]; |
|
388 |
byte cargo; |
|
389 |
EngineInfo *info; |
|
390 |
engine_id = ROAD_ENGINES_INDEX; |
|
391 |
||
392 |
do { |
|
393 |
info = &_engine_info[engine_id]; |
|
394 |
if (ENGINE_AVAILABLE) { |
|
395 |
if (sel[0]==0) selected_id[0] = engine_id; |
|
396 |
count++; |
|
397 |
sel[0]--; |
|
398 |
} |
|
399 |
} while (++engine_id,++e,--num); |
|
400 |
||
401 |
if ( selected_id[0] != -1 ) { // only draw right array if we have anything in the left one |
|
402 |
num = NUM_ROAD_ENGINES; |
|
403 |
engine_id = ROAD_ENGINES_INDEX; |
|
404 |
e = &_engines[ROAD_ENGINES_INDEX]; |
|
405 |
cargo = RoadVehInfo(selected_id[0])->cargo_type; |
|
406 |
||
407 |
do { |
|
408 |
if ( cargo == RoadVehInfo(engine_id)->cargo_type && HASBIT(e->player_avail, _local_player)) { |
|
409 |
count2++; |
|
410 |
if (sel[1]==0) selected_id[1] = engine_id; |
|
411 |
sel[1]--; |
|
412 |
} |
|
413 |
} while (++engine_id,++e,--num); |
|
414 |
} |
|
415 |
break; |
|
416 |
} |
|
417 |
||
418 |
case VEH_Ship: { |
|
419 |
int num = NUM_SHIP_ENGINES; |
|
420 |
Engine *e = &_engines[SHIP_ENGINES_INDEX]; |
|
421 |
byte cargo; |
|
422 |
EngineInfo *info; |
|
423 |
engine_id = SHIP_ENGINES_INDEX; |
|
424 |
byte refittable; |
|
425 |
||
426 |
do { |
|
427 |
info = &_engine_info[engine_id]; |
|
428 |
if (ENGINE_AVAILABLE) { |
|
429 |
if ( sel[0] == 0 ) selected_id[0] = engine_id; |
|
430 |
count++; |
|
431 |
sel[0]--; |
|
432 |
} |
|
433 |
} while (++engine_id,++e,--num); |
|
434 |
||
435 |
if ( selected_id[0] != -1 ) { |
|
436 |
num = NUM_SHIP_ENGINES; |
|
437 |
e = &_engines[SHIP_ENGINES_INDEX]; |
|
438 |
engine_id = SHIP_ENGINES_INDEX; |
|
439 |
cargo = ShipVehInfo(selected_id[0])->cargo_type; |
|
440 |
refittable = ShipVehInfo(selected_id[0])->refittable; |
|
441 |
||
442 |
do { |
|
443 |
if (HASBIT(e->player_avail, _local_player) |
|
444 |
&& ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) { |
|
445 |
||
446 |
if ( sel[1]==0) selected_id[1] = engine_id; |
|
447 |
sel[1]--; |
|
448 |
count2++; |
|
449 |
} |
|
450 |
} while (++engine_id,++e,--num); |
|
451 |
} |
|
452 |
break; |
|
453 |
} //end of ship |
|
454 |
||
455 |
case VEH_Aircraft:{ |
|
456 |
int num = NUM_AIRCRAFT_ENGINES; |
|
457 |
Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX]; |
|
458 |
EngineInfo *info; |
|
459 |
engine_id = AIRCRAFT_ENGINES_INDEX; |
|
460 |
byte subtype; |
|
461 |
||
462 |
do { |
|
463 |
info = &_engine_info[engine_id]; |
|
464 |
if (ENGINE_AVAILABLE) { |
|
465 |
count++; |
|
466 |
if (sel[0]==0) selected_id[0] = engine_id; |
|
467 |
sel[0]--; |
|
468 |
} |
|
469 |
} while (++engine_id,++e,--num); |
|
470 |
||
471 |
if ( selected_id[0] != -1 ) { |
|
472 |
num = NUM_AIRCRAFT_ENGINES; |
|
473 |
e = &_engines[AIRCRAFT_ENGINES_INDEX]; |
|
474 |
subtype = AircraftVehInfo(selected_id[0])->subtype; |
|
475 |
engine_id = AIRCRAFT_ENGINES_INDEX; |
|
476 |
do { |
|
477 |
if (HASBIT(e->player_avail, _local_player)) { |
|
478 |
if ( (subtype && AircraftVehInfo(engine_id)->subtype) || (!(subtype) && !AircraftVehInfo(engine_id)->subtype) ) { |
|
479 |
count2++; |
|
480 |
if (sel[1]==0) selected_id[1] = engine_id; |
|
481 |
sel[1]--; |
|
482 |
} |
|
483 |
} |
|
484 |
} while (++engine_id,++e,--num); |
|
485 |
} |
|
486 |
break; |
|
487 |
} |
|
488 |
} |
|
489 |
// sets up the number of items in each list |
|
490 |
SetVScrollCount(w, count); |
|
491 |
SetVScroll2Count(w, count2); |
|
492 |
WP(w,replaceveh_d).sel_engine[0] = selected_id[0]; |
|
493 |
WP(w,replaceveh_d).sel_engine[1] = selected_id[1]; |
|
494 |
||
495 |
WP(w,replaceveh_d).count[0] = count; |
|
496 |
WP(w,replaceveh_d).count[1] = count2; |
|
497 |
return; |
|
498 |
} |
|
499 |
||
500 |
||
501 |
static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int y2, int pos, int pos2, |
|
502 |
int sel1, int sel2, int selected_id1, int selected_id2) |
|
503 |
{ |
|
504 |
int sel[2] = {sel1, sel2}; |
|
505 |
int selected_id[2] = {selected_id1, selected_id2}; |
|
506 |
switch (WP(w,replaceveh_d).vehicletype) { |
|
507 |
case VEH_Train: { |
|
508 |
byte railtype = WP(w,replaceveh_d).railtype; |
|
509 |
DrawString(157, 89 + (14 * w->vscroll.cap), _rail_types_list[railtype], 0x10); |
|
510 |
/* draw sorting criteria string */ |
|
511 |
||
512 |
/* Ensure that custom engines which substituted wagons |
|
513 |
* are sorted correctly. |
|
514 |
* XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as |
|
515 |
* engines to get more types.. Stays here until we have our own format |
|
516 |
* then it is exit!!! */ |
|
517 |
train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true); // True engines |
|
518 |
train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false); // True engines |
|
519 |
train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false); // Feeble wagons |
|
520 |
break; |
|
521 |
} |
|
522 |
||
523 |
case VEH_Road: { |
|
524 |
int num = NUM_ROAD_ENGINES; |
|
525 |
Engine *e = &_engines[ROAD_ENGINES_INDEX]; |
|
526 |
int engine_id = ROAD_ENGINES_INDEX; |
|
527 |
byte cargo; |
|
528 |
EngineInfo *info; |
|
529 |
||
530 |
if ( selected_id[0] >= ROAD_ENGINES_INDEX && selected_id[0] <= SHIP_ENGINES_INDEX ) |
|
531 |
cargo = RoadVehInfo(selected_id[0])->cargo_type; |
|
532 |
||
533 |
do { |
|
534 |
info = &_engine_info[engine_id]; |
|
535 |
if (ENGINE_AVAILABLE) { |
|
536 |
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { |
|
537 |
DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); |
|
538 |
DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
539 |
y += 14; |
|
540 |
} |
|
541 |
||
542 |
if ( RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player) ) { |
|
543 |
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) { |
|
544 |
DrawString(x2+59, y2+2, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10); |
|
545 |
DrawRoadVehEngine(x2+29, y2+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
546 |
y2 += 14; |
|
547 |
} |
|
548 |
sel[1]--; |
|
549 |
} |
|
550 |
sel[0]--; |
|
551 |
} |
|
552 |
} while (++engine_id, ++e,--num); |
|
553 |
||
554 |
break; |
|
555 |
} |
|
556 |
||
557 |
case VEH_Ship: { |
|
558 |
int num = NUM_SHIP_ENGINES; |
|
559 |
Engine *e = &_engines[SHIP_ENGINES_INDEX]; |
|
560 |
int engine_id = SHIP_ENGINES_INDEX; |
|
561 |
byte cargo, refittable; |
|
562 |
EngineInfo *info; |
|
563 |
||
564 |
if ( selected_id[0] != -1 ) { |
|
565 |
cargo = ShipVehInfo(selected_id[0])->cargo_type; |
|
566 |
refittable = ShipVehInfo(selected_id[0])->refittable; |
|
567 |
} |
|
568 |
||
569 |
do { |
|
570 |
info = &_engine_info[engine_id]; |
|
571 |
if (ENGINE_AVAILABLE) { |
|
572 |
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { |
|
573 |
DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); |
|
574 |
DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
575 |
y += 24; |
|
576 |
} |
|
577 |
if ( selected_id[0] != -1 ) { |
|
578 |
if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) { |
|
579 |
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) { |
|
580 |
DrawString(x2+75, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10); |
|
581 |
DrawShipEngine(x2+35, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
582 |
y2 += 24; |
|
583 |
} |
|
584 |
sel[1]--; |
|
585 |
} |
|
586 |
} |
|
587 |
sel[0]--; |
|
588 |
} |
|
589 |
} while (++engine_id, ++e,--num); |
|
590 |
break; |
|
591 |
} //end of ship |
|
592 |
||
593 |
case VEH_Aircraft: { |
|
594 |
if ( selected_id[0] != -1 ) { |
|
595 |
int num = NUM_AIRCRAFT_ENGINES; |
|
596 |
Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX]; |
|
597 |
int engine_id = AIRCRAFT_ENGINES_INDEX; |
|
598 |
byte subtype = AircraftVehInfo(selected_id[0])->subtype; |
|
599 |
EngineInfo *info; |
|
600 |
||
601 |
do { |
|
602 |
info = &_engine_info[engine_id]; |
|
603 |
if (ENGINE_AVAILABLE) { |
|
604 |
if (sel[0]==0) selected_id[0] = engine_id; |
|
605 |
if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { |
|
606 |
DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10); |
|
607 |
DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
608 |
y += 24; |
|
609 |
} |
|
610 |
if ( ((subtype && AircraftVehInfo(engine_id)->subtype) || (!(subtype) && !AircraftVehInfo(engine_id)->subtype)) |
|
611 |
&& HASBIT(e->player_avail, _local_player) ) { |
|
612 |
if (sel[1]==0) selected_id[1] = engine_id; |
|
613 |
if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) { |
|
614 |
DrawString(x2+62, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10); |
|
615 |
DrawAircraftEngine(x2+29, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
616 |
y2 += 24; |
|
617 |
} |
|
618 |
sel[1]--; |
|
619 |
} |
|
620 |
sel[0]--; |
|
621 |
} |
|
622 |
} while (++engine_id, ++e,--num); |
|
623 |
} |
|
624 |
break; |
|
625 |
} // end of aircraft |
|
626 |
} |
|
627 |
||
628 |
} |
|
629 |
static void ReplaceVehicleWndProc(Window *w, WindowEvent *e) |
|
630 |
{ |
|
631 |
// these 3 variables is used if any of the lists is clicked |
|
632 |
uint16 click_scroll_pos = w->vscroll2.pos; |
|
633 |
uint16 click_scroll_cap = w->vscroll2.cap; |
|
634 |
byte click_side = 1; |
|
635 |
||
636 |
switch(e->event) { |
|
637 |
case WE_PAINT: |
|
638 |
{ |
|
639 |
int pos = w->vscroll.pos; |
|
640 |
int selected_id[2] = {-1,-1}; |
|
641 |
int x = 1; |
|
642 |
int y = 15; |
|
643 |
int pos2 = w->vscroll2.pos; |
|
644 |
int x2 = 1 + 228; |
|
645 |
int y2 = 15; |
|
646 |
int sel[2] = { WP(w,replaceveh_d).sel_index[0], WP(w,replaceveh_d).sel_index[1]}; |
|
647 |
||
648 |
SetupScrollStuffForReplaceWindow(w); |
|
649 |
||
650 |
selected_id[0] = WP(w,replaceveh_d).sel_engine[0]; |
|
651 |
selected_id[1] = WP(w,replaceveh_d).sel_engine[1]; |
|
652 |
||
653 |
// sets the selected left item to the top one if it's greater than the number of vehicles in the left side |
|
654 |
||
655 |
if ( WP(w,replaceveh_d).count[0] <= sel[0] ) { |
|
656 |
if (WP(w,replaceveh_d).count[0]) { |
|
657 |
sel[0] = 0; |
|
658 |
WP(w,replaceveh_d).sel_index[0] = 0; |
|
659 |
w->vscroll.pos = 0; |
|
660 |
// now we go back to set selected_id[1] properly |
|
661 |
SetWindowDirty(w); |
|
662 |
return; |
|
663 |
} else { //there are no vehicles in the left window |
|
664 |
selected_id[1] = -1; |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
if ( WP(w,replaceveh_d).count[1] <= sel[1] ) { |
|
669 |
if (WP(w,replaceveh_d).count[1]) { |
|
670 |
sel[1] = 0; |
|
671 |
WP(w,replaceveh_d).sel_index[1] = 0; |
|
672 |
w->vscroll2.pos = 0; |
|
673 |
// now we go back to set selected_id[1] properly |
|
674 |
SetWindowDirty(w); |
|
675 |
return; |
|
676 |
} else { //there are no vehicles in the right window |
|
677 |
selected_id[1] = -1; |
|
678 |
} |
|
679 |
} |
|
680 |
||
681 |
if ( selected_id[0] == selected_id[1] || _autoreplace_array[selected_id[0]] == selected_id[1] |
|
682 |
|| selected_id[0] == -1 || selected_id[1] == -1 ) |
|
683 |
SETBIT(w->disabled_state, 4); |
|
684 |
else |
|
685 |
CLRBIT(w->disabled_state, 4); |
|
686 |
||
687 |
if ( _autoreplace_array[selected_id[0]] == selected_id[0] || selected_id[0] == -1 ) |
|
688 |
SETBIT(w->disabled_state, 6); |
|
689 |
else |
|
690 |
CLRBIT(w->disabled_state, 6); |
|
691 |
||
692 |
// now the actual drawing of the window itself takes place |
|
693 |
DrawWindowWidgets(w); |
|
694 |
||
695 |
||
696 |
||
697 |
// sets up the string for the vehicle that is being replaced to |
|
698 |
if ( selected_id[0] != -1 ) { |
|
699 |
if ( selected_id[0] == _autoreplace_array[selected_id[0]] ) |
|
700 |
SetDParam(0, STR_NOT_REPLACING); |
|
701 |
else |
|
702 |
SetDParam(0, GetCustomEngineName(_autoreplace_array[selected_id[0]])); |
|
703 |
} else { |
|
704 |
SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED); |
|
705 |
} |
|
706 |
||
707 |
||
708 |
DrawString(145, (WP(w,replaceveh_d).line_height == 24 ? 67 : 77 ) + ( WP(w,replaceveh_d).line_height * w->vscroll.cap), STR_02BD, 0x10); |
|
709 |
||
710 |
||
711 |
/* now we draw the two arrays according to what we just counted */ |
|
712 |
DrawEngineArrayInReplaceWindow(w, x, y, x2, y2, pos, pos2, sel[0], sel[1], selected_id[0], selected_id[1]); |
|
713 |
||
714 |
WP(w,replaceveh_d).sel_engine[0] = selected_id[0]; |
|
715 |
WP(w,replaceveh_d).sel_engine[1] = selected_id[1]; |
|
716 |
/* now we draw the info about the vehicles we selected */ |
|
717 |
switch (WP(w,replaceveh_d).vehicletype) { |
|
718 |
case VEH_Train: { |
|
719 |
byte i = 0; |
|
720 |
int offset = 0; |
|
721 |
||
722 |
for ( i = 0 ; i < 2 ; i++) { |
|
723 |
if ( i ) |
|
724 |
offset = 228; |
|
725 |
if (selected_id[i] != -1) { |
|
726 |
if (!(RailVehInfo(selected_id[i])->flags & RVI_WAGON)) { |
|
727 |
/* it's an engine */ |
|
728 |
Set_DPARAM_Train_Engine_Build_Window(selected_id[i]); |
|
729 |
DrawString(2 + offset, 15 + (14 * w->vscroll.cap), STR_8817_COST_WEIGHT_T_SPEED_POWER, 0); |
|
730 |
} else { |
|
731 |
/* it's a wagon. Train cars are not replaced with the current GUI, but this code is ready for newgrf if anybody adds that*/ |
|
732 |
Set_DPARAM_Train_Car_Build_Window(w, selected_id[i]); |
|
733 |
DrawString(2 + offset, 15 + (14 * w->vscroll.cap), STR_8821_COST_WEIGHT_T_T_CAPACITY, 0); |
|
734 |
} |
|
735 |
} |
|
736 |
} |
|
737 |
break; |
|
738 |
} //end if case VEH_Train |
|
739 |
||
740 |
case VEH_Road: { |
|
741 |
if (selected_id[0] != -1) { |
|
742 |
Set_DPARAM_Road_Veh_Build_Window(selected_id[0]); |
|
743 |
DrawString(2, 15 + (14 * w->vscroll.cap), STR_9008_COST_SPEED_RUNNING_COST, 0); |
|
744 |
if (selected_id[1] != -1) { |
|
745 |
Set_DPARAM_Road_Veh_Build_Window(selected_id[1]); |
|
746 |
DrawString(2 + 228, 15 + (14 * w->vscroll.cap), STR_9008_COST_SPEED_RUNNING_COST, 0); |
|
747 |
} |
|
748 |
} |
|
749 |
break; |
|
750 |
} // end of VEH_Road |
|
751 |
||
752 |
case VEH_Ship: { |
|
753 |
if (selected_id[0] != -1) { |
|
754 |
Set_DPARAM_Ship_Build_Window(selected_id[0]); |
|
755 |
DrawString(2, 15 + (24 * w->vscroll.cap), STR_980A_COST_SPEED_CAPACITY_RUNNING, 0); |
|
756 |
if (selected_id[1] != -1) { |
|
757 |
Set_DPARAM_Ship_Build_Window(selected_id[1]); |
|
758 |
DrawString(2 + 228, 15 + (24 * w->vscroll.cap), STR_980A_COST_SPEED_CAPACITY_RUNNING, 0); |
|
759 |
} |
|
760 |
} |
|
761 |
break; |
|
762 |
} // end of VEH_Ship |
|
763 |
||
764 |
case VEH_Aircraft: { |
|
765 |
if (selected_id[0] != -1) { |
|
766 |
Set_DPARAM_Aircraft_Build_Window(selected_id[0]); |
|
767 |
DrawString(2, 15 + (24 * w->vscroll.cap), STR_A007_COST_SPEED_CAPACITY_PASSENGERS, 0); |
|
768 |
if (selected_id[1] != -1) { |
|
769 |
Set_DPARAM_Aircraft_Build_Window(selected_id[1]); |
|
770 |
DrawString(2 + 228, 15 + (24 * w->vscroll.cap), STR_A007_COST_SPEED_CAPACITY_PASSENGERS, 0); |
|
771 |
} |
|
772 |
} |
|
773 |
break; |
|
774 |
} // end of VEH_Aircraft |
|
775 |
} |
|
776 |
} // end of paint |
|
777 |
||
778 |
case WE_CLICK: { |
|
779 |
switch(e->click.widget) { |
|
780 |
/*case 0: |
|
781 |
DeleteWindowById(WC_REPLACE_VEHICLE, WP(w,replaceveh_d).vehicletype ); |
|
782 |
break;*/ |
|
783 |
||
784 |
case 14: case 15:/* Select sorting criteria dropdown menu */ |
|
785 |
// finds mask for available engines |
|
786 |
{ |
|
787 |
int engine_avail = 0; |
|
788 |
if ( !(HASBIT(_engines[NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES].player_avail, _local_player))) { |
|
789 |
engine_avail = 4; |
|
790 |
if ( !(HASBIT(_engines[NUM_NORMAL_RAIL_ENGINES].player_avail, _local_player))) |
|
791 |
engine_avail = 6; |
|
792 |
} |
|
793 |
ShowDropDownMenu(w, _rail_types_list, WP(w,replaceveh_d).railtype, 15, engine_avail, 1); |
|
794 |
return; |
|
795 |
} |
|
796 |
case 4: { |
|
797 |
_autoreplace_array[WP(w,replaceveh_d).sel_engine[0]] = WP(w,replaceveh_d).sel_engine[1]; |
|
798 |
SetWindowDirty(w); |
|
799 |
break; |
|
800 |
} |
|
801 |
||
802 |
case 6: { |
|
803 |
_autoreplace_array[WP(w,replaceveh_d).sel_engine[0]] = WP(w,replaceveh_d).sel_engine[0]; |
|
804 |
SetWindowDirty(w); |
|
805 |
break; |
|
806 |
} |
|
807 |
||
808 |
case 7: |
|
809 |
// sets up that the left one was clicked. The default values are for the right one (9) |
|
810 |
// this way, the code for 9 handles both sides |
|
811 |
click_scroll_pos = w->vscroll.pos; |
|
812 |
click_scroll_cap = w->vscroll.cap; |
|
813 |
click_side = 0; |
|
814 |
case 9: { |
|
815 |
uint i = (e->click.pt.y - 14) / WP(w,replaceveh_d).line_height; |
|
816 |
if (i < click_scroll_cap) { |
|
817 |
WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos; |
|
818 |
SetWindowDirty(w); |
|
819 |
} |
|
820 |
} break; |
|
821 |
} |
|
822 |
||
823 |
} break; |
|
824 |
||
825 |
case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */ |
|
826 |
//potiential bug: railtypes needs to be activated 0, 1, 2... If one is skipped, it messes up |
|
827 |
WP(w,replaceveh_d).railtype = e->dropdown.index; |
|
828 |
SetWindowDirty(w); |
|
829 |
break; |
|
830 |
} |
|
831 |
} |
|
832 |
} |
|
833 |
||
834 |
static const Widget _replace_rail_vehicle_widgets[] = { |
|
835 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
836 |
{ WWT_CAPTION, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
837 |
{ WWT_STICKYBOX, 14, 444, 455, 0, 13, 0x0, STR_STICKY_BUTTON}, |
|
838 |
{ WWT_PANEL, 14, 0, 227, 126, 187, 0x0, STR_NULL}, |
|
839 |
{ WWT_PUSHTXTBTN, 14, 0, 138, 200, 211, STR_REPLACE_VEHICLES_START,STR_REPLACE_HELP_START_BUTTON}, |
|
840 |
{ WWT_PANEL, 14, 139, 316, 188, 199, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, |
|
841 |
{ WWT_PUSHTXTBTN, 14, 317, 455, 200, 211, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, |
|
842 |
{ WWT_MATRIX, 14, 0, 216, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY}, |
|
843 |
{ WWT_SCROLLBAR, 14, 217, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
844 |
{ WWT_MATRIX, 14, 228, 455, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY}, |
|
845 |
{ WWT_SCROLL2BAR, 14, 445, 455, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
846 |
{ WWT_PANEL, 14, 228, 455, 126, 187, 0x0, STR_NULL}, |
|
847 |
// the rest are train specific stuff |
|
848 |
{ WWT_PANEL, 14, 0, 138, 188, 199, 0x0, STR_NULL}, |
|
849 |
{ WWT_PANEL, 3, 139, 153, 200, 211, 0x0, STR_NULL}, |
|
850 |
{ WWT_PANEL, 14, 154, 290, 200, 211, 0x0, STR_REPLACE_HELP_RAILTYPE}, |
|
851 |
{ WWT_CLOSEBOX, 14, 291, 301, 200, 210, STR_0225, STR_REPLACE_HELP_RAILTYPE}, |
|
852 |
{ WWT_PANEL, 3, 301, 316, 200, 211, 0x0, STR_NULL}, |
|
853 |
{ WWT_PANEL, 14, 317, 455, 188, 199, 0x0, STR_NULL}, |
|
854 |
||
855 |
{ WIDGETS_END}, |
|
856 |
}; |
|
857 |
||
858 |
static const Widget _replace_road_vehicle_widgets[] = { |
|
859 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
860 |
{ WWT_CAPTION, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
861 |
{ WWT_STICKYBOX, 14, 444, 455, 0, 13, 0x0, STR_STICKY_BUTTON}, |
|
862 |
{ WWT_PANEL, 14, 0, 227, 126, 187, 0x0, STR_NULL}, |
|
863 |
{ WWT_PUSHTXTBTN, 14, 0, 138, 188, 199, STR_REPLACE_VEHICLES_START,STR_REPLACE_HELP_START_BUTTON}, |
|
864 |
{ WWT_PANEL, 14, 139, 316, 188, 199, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, |
|
865 |
{ WWT_PUSHTXTBTN, 14, 317, 455, 188, 199, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, |
|
866 |
{ WWT_MATRIX, 14, 0, 216, 14, 125, 0x801, STR_REPLACE_HELP_LEFT_ARRAY}, |
|
867 |
{ WWT_SCROLLBAR, 14, 217, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
868 |
{ WWT_MATRIX, 14, 228, 455, 14, 125, 0x801, STR_REPLACE_HELP_RIGHT_ARRAY}, |
|
869 |
{ WWT_SCROLL2BAR, 14, 445, 455, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
870 |
{ WWT_PANEL, 14, 228, 455, 126, 187, 0x0, STR_NULL}, |
|
871 |
{ WIDGETS_END}, |
|
872 |
}; |
|
873 |
||
874 |
static const Widget _replace_ship_aircraft_vehicle_widgets[] = { |
|
875 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
876 |
{ WWT_CAPTION, 14, 11, 443, 0, 13, STR_REPLACE_VEHICLES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
877 |
{ WWT_STICKYBOX, 14, 444, 455, 0, 13, 0x0, STR_STICKY_BUTTON}, |
|
878 |
{ WWT_PANEL, 14, 0, 227, 110, 161, 0x0, STR_NULL}, |
|
879 |
{ WWT_PUSHTXTBTN, 14, 0, 138, 162, 173, STR_REPLACE_VEHICLES_START,STR_REPLACE_HELP_START_BUTTON}, |
|
880 |
{ WWT_PANEL, 14, 139, 316, 162, 173, 0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB}, |
|
881 |
{ WWT_PUSHTXTBTN, 14, 317, 455, 162, 173, STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON}, |
|
882 |
{ WWT_MATRIX, 14, 0, 216, 14, 109, 0x401, STR_REPLACE_HELP_LEFT_ARRAY}, |
|
883 |
{ WWT_SCROLLBAR, 14, 217, 227, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
884 |
{ WWT_MATRIX, 14, 228, 455, 14, 109, 0x401, STR_REPLACE_HELP_RIGHT_ARRAY}, |
|
885 |
{ WWT_SCROLL2BAR, 14, 445, 455, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
886 |
{ WWT_PANEL, 14, 228, 455, 110, 161, 0x0, STR_NULL}, |
|
887 |
{ WIDGETS_END}, |
|
888 |
}; |
|
889 |
||
890 |
static const WindowDesc _replace_rail_vehicle_desc = { |
|
891 |
-1, -1, 456, 212, |
|
892 |
WC_REPLACE_VEHICLE,0, |
|
893 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
|
894 |
_replace_rail_vehicle_widgets, |
|
895 |
ReplaceVehicleWndProc |
|
896 |
}; |
|
897 |
||
898 |
static const WindowDesc _replace_road_vehicle_desc = { |
|
899 |
-1, -1, 456, 200, |
|
900 |
WC_REPLACE_VEHICLE,0, |
|
901 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
|
902 |
_replace_road_vehicle_widgets, |
|
903 |
ReplaceVehicleWndProc |
|
904 |
}; |
|
905 |
||
906 |
static const WindowDesc _replace_ship_aircraft_vehicle_desc = { |
|
907 |
-1, -1, 456, 174, |
|
908 |
WC_REPLACE_VEHICLE,0, |
|
909 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, |
|
910 |
_replace_ship_aircraft_vehicle_widgets, |
|
911 |
ReplaceVehicleWndProc |
|
912 |
}; |
|
913 |
||
914 |
||
915 |
void ShowReplaceVehicleWindow(byte vehicletype) |
|
916 |
{ |
|
917 |
Window *w; |
|
918 |
||
919 |
DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype ); |
|
920 |
||
921 |
switch (vehicletype) { |
|
922 |
case VEH_Train: |
|
923 |
w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype); |
|
924 |
w->vscroll.cap = 8; |
|
925 |
WP(w,replaceveh_d).line_height = 14; |
|
926 |
break; |
|
927 |
case VEH_Road: |
|
928 |
w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype); |
|
929 |
w->vscroll.cap = 8; |
|
930 |
WP(w,replaceveh_d).line_height = 14; |
|
931 |
break; |
|
932 |
case VEH_Ship: case VEH_Aircraft: |
|
933 |
w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype); |
|
934 |
w->vscroll.cap = 4; |
|
935 |
WP(w,replaceveh_d).line_height = 24; |
|
936 |
break; |
|
937 |
} |
|
938 |
WP(w,replaceveh_d).vehicletype = vehicletype; |
|
939 |
w->vscroll2.cap = w->vscroll.cap; // these two are always the same |
|
940 |
} |