vehicle_gui.c
author truelight
Tue, 22 Aug 2006 15:39:22 +0000
changeset 4347 38fc1b161e89
parent 4344 7e123fec5b0b
child 4354 10f4ce894eb1
permissions -rw-r--r--
(svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
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
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1859
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 1926
diff changeset
     7
#include "player.h"
2466
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2462
diff changeset
     8
#include "station.h"
1309
4403a69da4f8 (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1299
diff changeset
     9
#include "strings.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1309
diff changeset
    10
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 505
diff changeset
    11
#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
    12
#include "vehicle.h"
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    13
#include "window.h"
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    14
#include "engine.h"
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    15
#include "gui.h"
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    16
#include "command.h"
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    17
#include "gfx.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    18
#include "variables.h"
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    19
#include "vehicle_gui.h"
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
    20
#include "viewport.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
    21
#include "train.h"
3650
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
    22
#include "newgrf_callbacks.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2951
diff changeset
    23
#include "newgrf_engine.h"
3650
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
    24
#include "newgrf_text.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4243
diff changeset
    25
#include "date.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    26
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    27
Sorting _sorting;
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    28
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    29
static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
    30
static const Vehicle* _last_vehicle; // cached vehicle to hopefully speed up name-sorting
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    31
static bool   _internal_sort_order;     // descending/ascending
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
    32
2569
fe379f11f6bf (svn r3106) -Autoreplace feature: Continue to show old vehicles in replace window after all player's vehicles of that type have been replaced. This allows the replacement to be removed. These vehicles are shown in grey instead of the player's colour.
peter1138
parents: 2556
diff changeset
    33
static uint16 _player_num_engines[TOTAL_NUM_ENGINES];
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2519
diff changeset
    34
static RailType _railtype_selected_in_replace_gui;
2288
2e27113b0611 (svn r2812) Move variables, which only vehicle_gui.c needs to know about, there
tron
parents: 2206
diff changeset
    35
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    36
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    37
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    38
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    39
static VehicleSortListingTypeFunction VehicleUnsortedSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    40
static VehicleSortListingTypeFunction VehicleNumberSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    41
static VehicleSortListingTypeFunction VehicleNameSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    42
static VehicleSortListingTypeFunction VehicleAgeSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    43
static VehicleSortListingTypeFunction VehicleProfitThisYearSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    44
static VehicleSortListingTypeFunction VehicleProfitLastYearSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    45
static VehicleSortListingTypeFunction VehicleCargoSorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    46
static VehicleSortListingTypeFunction VehicleReliabilitySorter;
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    47
static VehicleSortListingTypeFunction VehicleMaxSpeedSorter;
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    48
static VehicleSortListingTypeFunction VehicleModelSorter;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    49
static VehicleSortListingTypeFunction VehicleValueSorter;
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    50
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    51
static VehicleSortListingTypeFunction* const _vehicle_sorter[] = {
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
    52
	&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
    53
	&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
    54
	&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
    55
	&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
    56
	&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
    57
	&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
    58
	&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
    59
	&VehicleReliabilitySorter,
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    60
	&VehicleMaxSpeedSorter,
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    61
	&VehicleModelSorter,
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    62
	&VehicleValueSorter,
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
    63
};
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
    64
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
    65
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
    66
	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
    67
	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
    68
	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
    69
	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
    70
	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
    71
	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
    72
	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
    73
	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
    74
	STR_SORT_BY_MAX_SPEED,
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    75
	STR_SORT_BY_MODEL,
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
    76
	STR_SORT_BY_VALUE,
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
    77
	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
    78
};
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
    79
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
    80
static const StringID _rail_types_list[] = {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    81
	STR_RAIL_VEHICLES,
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
    82
	STR_ELRAIL_VEHICLES,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    83
	STR_MONORAIL_VEHICLES,
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    84
	STR_MAGLEV_VEHICLES,
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    85
	INVALID_STRING_ID
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    86
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
    87
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    88
void RebuildVehicleLists(void)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    89
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    90
	Window *w;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    91
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    92
	for (w = _windows; w != _last_window; ++w)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
    93
		switch (w->window_class) {
967
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    94
		case WC_TRAINS_LIST: case WC_ROADVEH_LIST:
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    95
		case WC_SHIPS_LIST:  case WC_AIRCRAFT_LIST:
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    96
			WP(w, vehiclelist_d).flags |= VL_REBUILD;
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    97
			SetWindowDirty(w);
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    98
			break;
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
    99
		default: break;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   100
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   101
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   102
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   103
void ResortVehicleLists(void)
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
	Window *w;
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
	for (w = _windows; w != _last_window; ++w)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   108
		switch (w->window_class) {
967
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   109
		case WC_TRAINS_LIST: case WC_ROADVEH_LIST:
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   110
		case WC_SHIPS_LIST:  case WC_AIRCRAFT_LIST:
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   111
			WP(w, vehiclelist_d).flags |= VL_RESORT;
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   112
			SetWindowDirty(w);
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   113
			break;
124257e8befa (svn r1460) -Fix: [1099225] Bug Fix - Vehicle Lists not updated at Acqusition (thx tamlin and mpetrov) This also fixes some bug but can't find i right now.
darkvater
parents: 945
diff changeset
   114
		default: break;
588
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
2466
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2462
diff changeset
   118
void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   119
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   120
	const Vehicle** sort_list;
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   121
	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   122
	uint n = 0;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   123
	uint i;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   124
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   125
	if (!(vl->flags & VL_REBUILD)) return;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   126
2818
b61038e1a75c (svn r3366) Make an unnecessarily global variable local
tron
parents: 2811
diff changeset
   127
	sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   128
	if (sort_list == NULL) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   129
		error("Could not allocate memory for the vehicle-sorting-list");
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   130
	}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   131
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   132
	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   133
		owner, station);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   134
2466
1aa260b43faa (svn r2992) Use PlayerID, StationID and INVALID_STATION instead of int, int and -1
tron
parents: 2462
diff changeset
   135
	if (station != INVALID_STATION) {
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   136
		const Vehicle *v;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   137
		FOR_ALL_VEHICLES(v) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   138
			if (v->type == type && (
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   139
						(type == VEH_Train && IsFrontEngine(v)) ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   140
						(type != VEH_Train && v->subtype <= subtype)
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   141
					)) {
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1017
diff changeset
   142
				const Order *order;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1017
diff changeset
   143
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1017
diff changeset
   144
				FOR_VEHICLE_ORDERS(v, order) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1017
diff changeset
   145
					if (order->type == OT_GOTO_STATION && order->station == station) {
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   146
						sort_list[n++] = v;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   147
						break;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   148
					}
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1017
diff changeset
   149
				}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   150
			}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   151
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   152
	} else {
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   153
		const Vehicle *v;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   154
		FOR_ALL_VEHICLES(v) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2639
diff changeset
   155
			if (v->type == type && v->owner == owner && (
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   156
						(type == VEH_Train && IsFrontEngine(v)) ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   157
						(type != VEH_Train && v->subtype <= subtype)
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   158
					)) {
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   159
				sort_list[n++] = v;
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   160
			}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   161
		}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   162
	}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   163
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   164
	free((void*)vl->sort_list);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   165
	vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   166
	if (n != 0 && vl->sort_list == NULL) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   167
		error("Could not allocate memory for the vehicle-sorting-list");
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2848
diff changeset
   168
	}
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   169
	vl->list_length = n;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   170
2818
b61038e1a75c (svn r3366) Make an unnecessarily global variable local
tron
parents: 2811
diff changeset
   171
	for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   172
	free((void*)sort_list);
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   173
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   174
	vl->flags &= ~VL_REBUILD;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   175
	vl->flags |= VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   176
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   177
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   178
void SortVehicleList(vehiclelist_d *vl)
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   179
{
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   180
	if (!(vl->flags & VL_RESORT)) return;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   181
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   182
	_internal_sort_order = vl->flags & VL_DESC;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   183
	_internal_name_sorter_id = STR_SV_TRAIN_NAME;
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   184
	_last_vehicle = NULL; // used for "cache" in namesorting
4280
90e7b2ea8627 (svn r5910) Fix some more warnings on MSVC by using (void*) casts. Followup of r5907.
Darkvater
parents: 4277
diff changeset
   185
	qsort((void*)vl->sort_list, vl->list_length, sizeof(vl->sort_list[0]),
588
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   186
		_vehicle_sorter[vl->sort_type]);
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   187
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   188
	vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   189
	vl->flags &= ~VL_RESORT;
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   190
}
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   191
03521b270f62 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 579
diff changeset
   192
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
   193
/* General Vehicle GUI based procedures that are independent of vehicle types */
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1067
diff changeset
   194
void InitializeVehiclesGuiList(void)
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
{
2519
beb11a5ac48c (svn r3048) Replace 0/1/2 by RAILTYPE_RAIL/MONO/MAGLEV where appropriate
tron
parents: 2477
diff changeset
   196
	_railtype_selected_in_replace_gui = RAILTYPE_RAIL;
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
   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
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
// draw the vehicle profit button in the vehicle list window.
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2375
diff changeset
   200
void DrawVehicleProfitButton(const Vehicle *v, int x, int 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
   201
{
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
	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
   203
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
	// draw profit-based colored icons
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   205
	if (v->age <= 365 * 2) {
1688
af2bb9bcb2ed (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1465
diff changeset
   206
		ormod = PALETTE_TO_GREY;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   207
	} else if (v->profit_last_year < 0) {
1688
af2bb9bcb2ed (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1465
diff changeset
   208
		ormod = PALETTE_TO_RED;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   209
	} else if (v->profit_last_year < 10000) {
1688
af2bb9bcb2ed (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1465
diff changeset
   210
		ormod = PALETTE_TO_YELLOW;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   211
	} else {
1688
af2bb9bcb2ed (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1465
diff changeset
   212
		ormod = PALETTE_TO_GREEN;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   213
	}
1688
af2bb9bcb2ed (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1465
diff changeset
   214
	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
   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
1859
870dcb6fd65b (svn r2365) - Change: [refitting] Make refitting capacities for trains newgrf compatible. Train vehicles can now carry twice as much mail/goods as other cargo, and four times as much passengers.
hackykid
parents: 1802
diff changeset
   217
/** Draw the list of available refit options for a consist.
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   218
 * Draw the list and highlight the selected refit option (if any)
1859
870dcb6fd65b (svn r2365) - Change: [refitting] Make refitting capacities for trains newgrf compatible. Train vehicles can now carry twice as much mail/goods as other cargo, and four times as much passengers.
hackykid
parents: 1802
diff changeset
   219
 * @param *v first vehicle in consist to get the refit-options of
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   220
 * @param sel selected refit cargo-type in the window
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   221
 * @return the cargo type that is hightlighted, CT_INVALID if none
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   222
 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   223
CargoID DrawVehicleRefitWindow(const Vehicle *v, int sel)
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   224
{
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   225
	uint32 cmask = 0;
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   226
	CargoID cid, cargo = CT_INVALID;
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   227
	int y = 25;
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   228
	const Vehicle* u = v;
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   229
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   230
	/* Check if vehicle has custom refit or normal ones, and get its bitmasked value.
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   231
	 * If its a train, 'or' this with the refit masks of the wagons. Now just 'and'
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   232
	 * it with the bitmask of available cargo on the current landscape, and
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   233
	 * where the bits are set: those are available */
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   234
	do {
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3355
diff changeset
   235
		cmask |= EngInfo(u->engine_type)->refit_mask;
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   236
		u = u->next;
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   237
	} while (v->type == VEH_Train && u != NULL);
1859
870dcb6fd65b (svn r2365) - Change: [refitting] Make refitting capacities for trains newgrf compatible. Train vehicles can now carry twice as much mail/goods as other cargo, and four times as much passengers.
hackykid
parents: 1802
diff changeset
   238
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   239
	/* Check which cargo has been selected from the refit window and draw list */
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   240
	for (cid = 0; cmask != 0; cmask >>= 1, cid++) {
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   241
		if (HASBIT(cmask, 0)) {
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   242
			// vehicle is refittable to this cargo
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   243
			byte colour = 16;
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   244
			if (sel == 0) {
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   245
				cargo = _local_cargo_id_ctype[cid];
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   246
				colour = 12;
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   247
			}
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   248
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   249
			sel--;
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   250
			DrawString(6, y, _cargoc.names_s[_local_cargo_id_ctype[cid]], colour);
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   251
			y += 10;
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   252
		}
3025
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   253
	}
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   254
9e60c370415c (svn r3605) - Remove silly macro and fix indenting in DrawVehicleRefitWindow()
peter1138
parents: 2989
diff changeset
   255
	return cargo;
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   256
}
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1763
diff changeset
   257
3650
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   258
/* Display additional text from NewGRF in the purchase information window */
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   259
int ShowAdditionalText(int x, int y, int w, EngineID engine)
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   260
{
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   261
	uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   262
	if (callback == CALLBACK_FAILED) return 0;
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   263
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   264
	DrawStringTruncated(x, y, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback), 16, w);
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   265
	return 10;
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   266
}
4dd8517bdcf6 (svn r4561) - NewGRF: implement most of callback 0x23: additional text in vehicle purchase windows.
peter1138
parents: 3492
diff changeset
   267
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   268
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   269
/* 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
   270
* 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
   271
* 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
   272
* 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
   273
*    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
   274
*/
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   275
static int CDECL VehicleUnsortedSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   276
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   277
	return (*(const Vehicle**)a)->index - (*(const Vehicle**)b)->index;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   278
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   279
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   280
// 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
   281
#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
   282
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   283
static int CDECL VehicleNumberSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   284
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   285
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   286
	const Vehicle* vb = *(const Vehicle**)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   287
	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
   288
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   289
	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
   290
}
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
   291
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   292
static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   293
static int CDECL VehicleNameSorter(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
   294
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   295
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   296
	const Vehicle* vb = *(const Vehicle**)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
   297
	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
   298
	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
   299
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   300
	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
   301
		SetDParam(0, va->string_id);
1017
b09bae77a850 (svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents: 967
diff changeset
   302
		GetString(buf1, STR_JUST_STRING);
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
   303
	}
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
   304
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   305
	if (vb != _last_vehicle) {
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4267
diff changeset
   306
		_last_vehicle = vb;
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
   307
		_bufcache[0] = '\0';
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   308
		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
   309
			SetDParam(0, vb->string_id);
1017
b09bae77a850 (svn r1518) -Fix: server issue where some company names were wrong
darkvater
parents: 967
diff changeset
   310
			GetString(_bufcache, STR_JUST_STRING);
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
   311
		}
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
   312
	}
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
   313
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
   314
	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
   315
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   316
	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
   317
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   318
	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
   319
}
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
   320
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   321
static 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
   322
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   323
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   324
	const Vehicle* vb = *(const Vehicle**)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   325
	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
   326
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   327
	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
   328
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   329
	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
   330
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   331
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   332
static int CDECL VehicleProfitThisYearSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   333
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   334
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   335
	const Vehicle* vb = *(const Vehicle**)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   336
	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
   337
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   338
	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
   339
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   340
	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
   341
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   342
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   343
static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   344
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   345
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   346
	const Vehicle* vb = *(const Vehicle**)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   347
	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
   348
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   349
	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
   350
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   351
	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
   352
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   353
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   354
static int CDECL VehicleCargoSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   355
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   356
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   357
	const Vehicle* vb = *(const Vehicle**)b;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   358
	const Vehicle* v;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   359
	AcceptedCargo cargoa;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   360
	AcceptedCargo cargob;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   361
	int r = 0;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   362
	int i;
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   363
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   364
	memset(cargoa, 0, sizeof(cargoa));
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   365
	memset(cargob, 0, sizeof(cargob));
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   366
	for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   367
	for (v = vb; v != NULL; v = v->next) cargob[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
   368
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   369
	for (i = 0; i < NUM_CARGO; i++) {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   370
		r = cargoa[i] - cargob[i];
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
   371
		if (r != 0) break;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   372
	}
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
   373
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
   374
	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
   375
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   376
	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
   377
}
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   378
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   379
static int CDECL VehicleReliabilitySorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   380
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   381
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   382
	const Vehicle* vb = *(const Vehicle**)b;
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   383
	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
   384
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   385
	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
   386
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   387
	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
   388
}
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   389
2462
2f90bb70fb00 (svn r2988) static where static is due
tron
parents: 2448
diff changeset
   390
static int CDECL VehicleMaxSpeedSorter(const void *a, const void *b)
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   391
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   392
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   393
	const Vehicle* vb = *(const Vehicle**)b;
1179
ce0a75460808 (svn r1681) -Feature: New realistic acceleration.
celestar
parents: 1178
diff changeset
   394
	int max_speed_a = 0xFFFF, max_speed_b = 0xFFFF;
ce0a75460808 (svn r1681) -Feature: New realistic acceleration.
celestar
parents: 1178
diff changeset
   395
	int r;
ce0a75460808 (svn r1681) -Feature: New realistic acceleration.
celestar
parents: 1178
diff changeset
   396
	const Vehicle *ua = va, *ub = vb;
ce0a75460808 (svn r1681) -Feature: New realistic acceleration.
celestar
parents: 1178
diff changeset
   397
1191
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   398
	if (va->type == VEH_Train && vb->type == VEH_Train) {
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   399
		do {
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   400
			if (RailVehInfo(ua->engine_type)->max_speed != 0)
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   401
				max_speed_a = min(max_speed_a, RailVehInfo(ua->engine_type)->max_speed);
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   402
		} while ((ua = ua->next) != NULL);
1179
ce0a75460808 (svn r1681) -Feature: New realistic acceleration.
celestar
parents: 1178
diff changeset
   403
1191
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   404
		do {
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   405
			if (RailVehInfo(ub->engine_type)->max_speed != 0)
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   406
				max_speed_b = min(max_speed_b, RailVehInfo(ub->engine_type)->max_speed);
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   407
		} while ((ub = ub->next) != NULL);
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   408
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   409
		r = max_speed_a - max_speed_b;
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   410
	} else {
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   411
		r = va->max_speed - vb->max_speed;
dc46f04aab3a (svn r1695) -Fix: I broke maximum speed sorting for anything but trains with the new acceleration. Sorry
Celestar
parents: 1182
diff changeset
   412
	}
168
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   413
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 193
diff changeset
   414
	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
   415
79f9ed5b23e6 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents: 164
diff changeset
   416
	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
   417
}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   418
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   419
static int CDECL VehicleModelSorter(const void *a, const void *b)
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   420
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   421
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   422
	const Vehicle* vb = *(const Vehicle**)b;
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   423
	int r = va->engine_type - vb->engine_type;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   424
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   425
	VEHICLEUNITNUMBERSORTER(r, va, vb);
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   426
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   427
	return (_internal_sort_order & 1) ? -r : r;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   428
}
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   429
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   430
static int CDECL VehicleValueSorter(const void *a, const void *b)
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   431
{
4266
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   432
	const Vehicle* va = *(const Vehicle**)a;
0de669884154 (svn r5894) Remove a totally unnecessary indirection in the vehicle sorter code. Less code, less data, simply better
tron
parents: 4261
diff changeset
   433
	const Vehicle* vb = *(const Vehicle**)b;
2965
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   434
	const Vehicle *u;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   435
	int valuea = 0, valueb = 0;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   436
	int r;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   437
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   438
	for (u = va; u != NULL; u = u->next) valuea += u->value;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   439
	for (u = vb; u != NULL; u = u->next) valueb += u->value;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   440
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   441
	r = valuea - valueb;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   442
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   443
	VEHICLEUNITNUMBERSORTER(r, va, vb);
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   444
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   445
	return (_internal_sort_order & 1) ? -r : r;
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   446
}
3eb140bd49a3 (svn r3528) - Feature: Allow sorting of vehicle lists by model or value (based on meush's work)
peter1138
parents: 2962
diff changeset
   447
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   448
// this define is to match engine.c, but engine.c keeps it to itself
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   449
// ENGINE_AVAILABLE is used in ReplaceVehicleWndProc
2530
df14798edc40 (svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents: 2520
diff changeset
   450
#define ENGINE_AVAILABLE ((e->flags & 1 && HASBIT(info->climates, _opt.landscape)) || HASBIT(e->player_avail, _local_player))
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   451
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   452
/*  if show_outdated is selected, it do not sort psudo engines properly but it draws all engines
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   453
 *	if used compined with show_cars set to false, it will work as intended. Replace window do it like that
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   454
 *  this was a big hack even before show_outdated was added. Stupid newgrf :p										*/
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   455
static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, EngineID *selected_id, RailType railtype,
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   456
	uint8 lines_drawn, bool is_engine, bool show_cars, bool show_outdated, bool show_compatible)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   457
{
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2970
diff changeset
   458
	EngineID j;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   459
	byte colour;
2569
fe379f11f6bf (svn r3106) -Autoreplace feature: Continue to show old vehicles in replace window after all player's vehicles of that type have been replaced. This allows the replacement to be removed. These vehicles are shown in grey instead of the player's colour.
peter1138
parents: 2556
diff changeset
   460
	const Player *p = GetPlayer(_local_player);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   461
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2970
diff changeset
   462
	for (j = 0; j < NUM_TRAIN_ENGINES; j++) {
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2970
diff changeset
   463
		EngineID i = GetRailVehAtPosition(j);
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1923
diff changeset
   464
		const Engine *e = GetEngine(i);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   465
		const RailVehicleInfo *rvi = RailVehInfo(i);
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3355
diff changeset
   466
		const EngineInfo *info = EngInfo(i);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   467
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   468
		if (!EngineHasReplacementForPlayer(p, i) && _player_num_engines[i] == 0 && show_outdated) continue;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   469
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   470
		if ((rvi->power == 0 && !show_cars) || (rvi->power != 0 && show_cars))  // show wagons or engines (works since wagons do not have power)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   471
			continue;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   472
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2970
diff changeset
   473
		if (*sel == 0) *selected_id = j;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   474
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   475
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   476
		colour = *sel == 0 ? 0xC : 0x10;
3492
265e806ed58e (svn r4343) [Autoreplace] Fix drawing of train list for outdated engines. Fixes FS#106
peter1138
parents: 3414
diff changeset
   477
		if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && IsCompatibleRail(e->railtype, railtype))) {
3414
d728e3793041 (svn r4229) [elrail & autoreplace] Always show compatible rail vehicles in the left list, and only the selected rail type in the right list, to
peter1138
parents: 3393
diff changeset
   478
			if ((!IsCompatibleRail(e->railtype, railtype) && show_compatible)
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   479
				|| (e->railtype != railtype && !show_compatible)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   480
				|| !(rvi->flags & RVI_WAGON) != is_engine ||
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   481
				!HASBIT(e->player_avail, _local_player))
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   482
				continue;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   483
		} /*else {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   484
		// TODO find a nice red colour for vehicles being replaced
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   485
			if ( _autoreplace_array[i] != i )
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   486
				colour = *sel == 0 ? 0x44 : 0x45;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   487
		} */
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   488
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   489
		if (IS_INT_INSIDE(--*pos, -lines_drawn, 0)) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   490
			DrawString(*x + 59, *y + 2, GetCustomEngineName(i),
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   491
				colour);
2569
fe379f11f6bf (svn r3106) -Autoreplace feature: Continue to show old vehicles in replace window after all player's vehicles of that type have been replaced. This allows the replacement to be removed. These vehicles are shown in grey instead of the player's colour.
peter1138
parents: 2556
diff changeset
   492
			// show_outdated is true only for left side, which is where we show old replacements
fe379f11f6bf (svn r3106) -Autoreplace feature: Continue to show old vehicles in replace window after all player's vehicles of that type have been replaced. This allows the replacement to be removed. These vehicles are shown in grey instead of the player's colour.
peter1138
parents: 2556
diff changeset
   493
			DrawTrainEngine(*x + 29, *y + 6, i, (_player_num_engines[i] == 0 && show_outdated) ?
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   494
				PALETTE_CRASH : GetEnginePalette(i, _local_player));
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   495
			if ( show_outdated ) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   496
				SetDParam(0, _player_num_engines[i]);
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   497
				DrawStringRightAligned(213, *y+5, STR_TINY_BLACK, 0);
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   498
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   499
			*y += 14;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   500
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   501
		--*sel;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   502
	}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   503
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   504
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   505
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   506
static void SetupScrollStuffForReplaceWindow(Window *w)
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   507
{
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   508
	EngineID selected_id[2] = { INVALID_ENGINE, INVALID_ENGINE };
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   509
	const Player* p = GetPlayer(_local_player);
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   510
	uint sel[2];
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   511
	uint count = 0;
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   512
	uint count2 = 0;
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   513
	EngineID i;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   514
912
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   515
	sel[0] = WP(w,replaceveh_d).sel_index[0];
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   516
	sel[1] = WP(w,replaceveh_d).sel_index[1];
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 912
diff changeset
   517
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   518
	switch (WP(w,replaceveh_d).vehicletype) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   519
		case VEH_Train: {
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   520
			RailType railtype = _railtype_selected_in_replace_gui;
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   521
870
b60bf24869a7 (svn r1351) fixed issue in last commit where it it not update the replace train window properly when changing company colour (the lower two panels stayed the old colour until the window was reopened)
bjarni
parents: 869
diff changeset
   522
			w->widget[13].color = _player_colors[_local_player];	// sets the colour of that art thing
b60bf24869a7 (svn r1351) fixed issue in last commit where it it not update the replace train window properly when changing company colour (the lower two panels stayed the old colour until the window was reopened)
bjarni
parents: 869
diff changeset
   523
			w->widget[16].color = _player_colors[_local_player];	// sets the colour of that art thing
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   524
2971
cae3a81e8674 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2970
diff changeset
   525
			for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   526
				EngineID eid = GetRailVehAtPosition(i);
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   527
				const Engine* e = GetEngine(eid);
3393
c40975f04842 (svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents: 3355
diff changeset
   528
				const EngineInfo* info = EngInfo(eid);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   529
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   530
				// left window contains compatible engines while right window only contains engines of the selected type
4084
318905f3d768 (svn r5399) Simplify a conditional expression: (a && b) || (!a && !b) -> a == b
tron
parents: 4023
diff changeset
   531
				if (ENGINE_AVAILABLE &&
318905f3d768 (svn r5399) Simplify a conditional expression: (a && b) || (!a && !b) -> a == b
tron
parents: 4023
diff changeset
   532
						(RailVehInfo(eid)->power != 0) == (WP(w, replaceveh_d).wagon_btnstate != 0)) {
3414
d728e3793041 (svn r4229) [elrail & autoreplace] Always show compatible rail vehicles in the left list, and only the selected rail type in the right list, to
peter1138
parents: 3393
diff changeset
   533
					if (IsCompatibleRail(e->railtype, railtype) && (_player_num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid))) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   534
						if (sel[0] == count) selected_id[0] = eid;
1134
f7342e7b4718 (svn r1635) fix: forgot to set SetVScrollCount properly in autoreplace train GUI. It appears ok now
bjarni
parents: 1128
diff changeset
   535
						count++;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   536
					}
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   537
					if (e->railtype == railtype && HASBIT(e->player_avail, _local_player)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   538
						if (sel[1] == count2) selected_id[1] = eid;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   539
						count2++;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   540
					}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   541
				}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   542
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   543
			break;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   544
		}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   545
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   546
		case VEH_Road: {
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   547
			for (i = ROAD_ENGINES_INDEX; i < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; i++) {
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   548
				if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   549
					if (sel[0] == count) selected_id[0] = i;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   550
					count++;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   551
				}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   552
			}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   553
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   554
			if (selected_id[0] != INVALID_ENGINE) { // only draw right array if we have anything in the left one
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   555
				CargoID cargo = RoadVehInfo(selected_id[0])->cargo_type;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   556
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   557
				for (i = ROAD_ENGINES_INDEX; i < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; i++) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   558
					if (cargo == RoadVehInfo(i)->cargo_type &&
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   559
							HASBIT(GetEngine(i)->player_avail, _local_player)) {
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   560
						if (sel[1] == count2) selected_id[1] = i;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   561
						count2++;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   562
					}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   563
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   564
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   565
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   566
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   567
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   568
		case VEH_Ship: {
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   569
			for (i = SHIP_ENGINES_INDEX; i < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; i++) {
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   570
				if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   571
					if (sel[0] == count) selected_id[0] = i;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   572
					count++;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   573
				}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   574
			}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   575
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   576
			if (selected_id[0] != INVALID_ENGINE) {
3030
e405fe9c8623 (svn r3610) And one more (see r3608/r3609)
tron
parents: 3029
diff changeset
   577
				const ShipVehicleInfo* svi = ShipVehInfo(selected_id[0]);
e405fe9c8623 (svn r3610) And one more (see r3608/r3609)
tron
parents: 3029
diff changeset
   578
				CargoID cargo = svi->cargo_type;
e405fe9c8623 (svn r3610) And one more (see r3608/r3609)
tron
parents: 3029
diff changeset
   579
				byte refittable = svi->refittable;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   580
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   581
				for (i = SHIP_ENGINES_INDEX; i < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; i++) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   582
					if (HASBIT(GetEngine(i)->player_avail, _local_player) && (
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   583
								ShipVehInfo(i)->cargo_type == cargo ||
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   584
								ShipVehInfo(i)->refittable & refittable
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   585
							)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   586
						if (sel[1] == count2) selected_id[1] = i;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   587
						count2++;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   588
					}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   589
				}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   590
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   591
			break;
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   592
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   593
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   594
		case VEH_Aircraft: {
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   595
			for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   596
				if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   597
					if (sel[0] == count) selected_id[0] = i;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   598
					count++;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   599
				}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   600
			}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   601
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   602
			if (selected_id[0] != INVALID_ENGINE) {
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   603
				byte subtype = AircraftVehInfo(selected_id[0])->subtype;
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   604
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   605
				for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   606
					if (HASBIT(GetEngine(i)->player_avail, _local_player) &&
4023
5d84c056a2b1 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3650
diff changeset
   607
							(subtype & AIR_CTOL) == (AircraftVehInfo(i)->subtype & AIR_CTOL)) {
3029
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   608
						if (sel[1] == count2) selected_id[1] = i;
f796d046b34d (svn r3609) Some more simplification in the same function as r3608
tron
parents: 3028
diff changeset
   609
						count2++;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   610
					}
3028
82836d6e3a27 (svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
tron
parents: 3025
diff changeset
   611
				}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   612
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   613
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   614
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   615
	}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   616
	// sets up the number of items in each list
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   617
	SetVScrollCount(w, count);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   618
	SetVScroll2Count(w, count2);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   619
	WP(w,replaceveh_d).sel_engine[0] = selected_id[0];
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   620
	WP(w,replaceveh_d).sel_engine[1] = selected_id[1];
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   621
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   622
	WP(w,replaceveh_d).count[0] = count;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   623
	WP(w,replaceveh_d).count[1] = count2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   624
	return;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   625
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   626
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   627
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   628
static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int y2, int pos, int pos2,
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   629
	int sel1, int sel2, EngineID selected_id1, EngineID selected_id2)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   630
{
912
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   631
	int sel[2];
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   632
	EngineID selected_id[2];
2569
fe379f11f6bf (svn r3106) -Autoreplace feature: Continue to show old vehicles in replace window after all player's vehicles of that type have been replaced. This allows the replacement to be removed. These vehicles are shown in grey instead of the player's colour.
peter1138
parents: 2556
diff changeset
   633
	const Player *p = GetPlayer(_local_player);
912
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   634
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   635
	sel[0] = sel1;
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   636
	sel[1] = sel2;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 912
diff changeset
   637
912
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   638
	selected_id[0] = selected_id1;
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   639
	selected_id[1] = selected_id2;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 912
diff changeset
   640
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   641
	switch (WP(w,replaceveh_d).vehicletype) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   642
		case VEH_Train: {
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2519
diff changeset
   643
			RailType railtype = _railtype_selected_in_replace_gui;
1923
bce919cad8e1 (svn r2429) - Fix: Oops, forgot to increase the size of the autoreplace window to fit the extra info from powered wagons.
hackykid
parents: 1907
diff changeset
   644
			DrawString(157, 99 + (14 * w->vscroll.cap), _rail_types_list[railtype], 0x10);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   645
			/* draw sorting criteria string */
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   646
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   647
			/* Ensure that custom engines which substituted wagons
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   648
			* are sorted correctly.
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   649
			* XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   650
			* engines to get more types.. Stays here until we have our own format
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   651
			* then it is exit!!! */
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   652
			if (WP(w,replaceveh_d).wagon_btnstate) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   653
				train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, true, false, true, true); // True engines
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   654
				train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, true, false, false, false); // True engines
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   655
				train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, false, false, false); // Feeble wagons
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   656
			} else {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   657
				train_engine_drawing_loop(&x, &y, &pos, &sel[0], &selected_id[0], railtype, w->vscroll.cap, false, true, true, true);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3040
diff changeset
   658
				train_engine_drawing_loop(&x2, &y2, &pos2, &sel[1], &selected_id[1], railtype, w->vscroll.cap, false, true, false, true);
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   659
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   660
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   661
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   662
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   663
		case VEH_Road: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   664
			int num = NUM_ROAD_ENGINES;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2617
diff changeset
   665
			const Engine* e = GetEngine(ROAD_ENGINES_INDEX);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   666
			EngineID engine_id = ROAD_ENGINES_INDEX;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   667
			byte cargo;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   668
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   669
			if (selected_id[0] >= ROAD_ENGINES_INDEX && selected_id[0] < SHIP_ENGINES_INDEX) {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   670
				cargo = RoadVehInfo(selected_id[0])->cargo_type;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   671
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   672
				do {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   673
					if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   674
						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   675
							DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   676
							DrawRoadVehEngine(x+29, y+6, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   677
							SetDParam(0, _player_num_engines[engine_id]);
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   678
							DrawStringRightAligned(213, y+5, STR_TINY_BLACK, 0);
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   679
							y += 14;
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   680
						}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   681
					sel[0]--;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   682
					}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   683
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   684
					if (RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player)) {
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   685
						if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   686
							DrawString(x2+59, y2+2, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   687
							DrawRoadVehEngine(x2+29, y2+6, engine_id, GetEnginePalette(engine_id, _local_player));
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   688
							y2 += 14;
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   689
						}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   690
						sel[1]--;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   691
					}
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   692
				} while (++engine_id, ++e,--num);
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   693
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   694
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   695
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   696
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   697
		case VEH_Ship: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   698
			int num = NUM_SHIP_ENGINES;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2617
diff changeset
   699
			const Engine* e = GetEngine(SHIP_ENGINES_INDEX);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   700
			EngineID engine_id = SHIP_ENGINES_INDEX;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   701
			byte cargo, refittable;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   702
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   703
			if (selected_id[0] != INVALID_ENGINE) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   704
				cargo = ShipVehInfo(selected_id[0])->cargo_type;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   705
				refittable = ShipVehInfo(selected_id[0])->refittable;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   706
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   707
				do {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   708
					if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   709
						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   710
							DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   711
							DrawShipEngine(x+35, y+10, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   712
							SetDParam(0, _player_num_engines[engine_id]);
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   713
							DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   714
							y += 24;
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   715
						}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   716
						sel[0]--;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   717
					}
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   718
					if (selected_id[0] != INVALID_ENGINE) {
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   719
						if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   720
							if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   721
								DrawString(x2+75, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   722
								DrawShipEngine(x2+35, y2+10, engine_id, GetEnginePalette(engine_id, _local_player));
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   723
								y2 += 24;
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   724
							}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   725
							sel[1]--;
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   726
						}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   727
					}
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   728
				} while (++engine_id, ++e,--num);
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   729
			}
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
   730
			break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   731
		}   //end of ship
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   732
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   733
		case VEH_Aircraft: {
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   734
			if (selected_id[0] != INVALID_ENGINE) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   735
				int num = NUM_AIRCRAFT_ENGINES;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2617
diff changeset
   736
				const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2466
diff changeset
   737
				EngineID engine_id = AIRCRAFT_ENGINES_INDEX;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   738
				byte subtype = AircraftVehInfo(selected_id[0])->subtype;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   739
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   740
				do {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   741
					if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   742
						if (sel[0] == 0) selected_id[0] = engine_id;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   743
						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   744
							DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   745
							DrawAircraftEngine(x+29, y+10, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   746
							SetDParam(0, _player_num_engines[engine_id]);
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   747
							DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   748
							y += 24;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   749
						}
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   750
						sel[0]--;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   751
					}
4023
5d84c056a2b1 (svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
tron
parents: 3650
diff changeset
   752
					if ((subtype & AIR_CTOL) == (AircraftVehInfo(engine_id)->subtype & AIR_CTOL) &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   753
							HASBIT(e->player_avail, _local_player)) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   754
						if (sel[1] == 0) selected_id[1] = engine_id;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   755
						if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   756
							DrawString(x2+62, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
3040
7043c0de7c6d (svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents: 3030
diff changeset
   757
							DrawAircraftEngine(x2+29, y2+10, engine_id, GetEnginePalette(engine_id, _local_player));
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   758
							y2 += 24;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   759
						}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   760
						sel[1]--;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   761
					}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   762
				} while (++engine_id, ++e,--num);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   763
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   764
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   765
		}   // end of aircraft
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   766
	}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   767
}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   768
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   769
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   770
static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   771
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   772
	static const StringID _vehicle_type_names[] = {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   773
		STR_019F_TRAIN,
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   774
		STR_019C_ROAD_VEHICLE,
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   775
		STR_019E_SHIP,
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   776
		STR_019D_AIRCRAFT
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   777
	};
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   778
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   779
	switch (e->event) {
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   780
		case WE_PAINT: {
2805
29e2b43a1e20 (svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents: 2753
diff changeset
   781
				const Player *p = GetPlayer(_local_player);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   782
				int pos = w->vscroll.pos;
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   783
				EngineID selected_id[2] = { INVALID_ENGINE, INVALID_ENGINE };
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   784
				int x = 1;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   785
				int y = 15;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   786
				int pos2 = w->vscroll2.pos;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   787
				int x2 = 1 + 228;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   788
				int y2 = 15;
912
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   789
				int sel[2];
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   790
				sel[0] = WP(w,replaceveh_d).sel_index[0];
a5fb6ad68d80 (svn r1399) -Fix: Fixes for compiling with Watcom C/C++ (ie, OS/2 port). (orudge)
truelight
parents: 907
diff changeset
   791
				sel[1] = WP(w,replaceveh_d).sel_index[1];
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   792
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   793
				{
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   794
					uint i;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   795
					const Vehicle *vehicle;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   796
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   797
					for (i = 0; i < lengthof(_player_num_engines); i++) {
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   798
						_player_num_engines[i] = 0;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   799
					}
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   800
					FOR_ALL_VEHICLES(vehicle) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   801
						if (vehicle->owner == _local_player) {
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   802
							if (vehicle->type == VEH_Aircraft && vehicle->subtype > 2) continue;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   803
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   804
							// do not count the vehicles, that contains only 0 in all var
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   805
							if (vehicle->engine_type == 0 && vehicle->spritenum == 0) continue;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   806
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1923
diff changeset
   807
							if (vehicle->type != GetEngine(vehicle->engine_type)->type) continue;
1128
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   808
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   809
							_player_num_engines[vehicle->engine_type]++;
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   810
						}
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   811
					}
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   812
				}
ca7f860db7ac (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1093
diff changeset
   813
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   814
				SetupScrollStuffForReplaceWindow(w);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   815
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   816
				selected_id[0] = WP(w,replaceveh_d).sel_engine[0];
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   817
				selected_id[1] = WP(w,replaceveh_d).sel_engine[1];
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   818
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   819
			// sets the selected left item to the top one if it's greater than the number of vehicles in the left side
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   820
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   821
				if (WP(w,replaceveh_d).count[0] <= sel[0]) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   822
					if (WP(w,replaceveh_d).count[0]) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   823
						sel[0] = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   824
						WP(w,replaceveh_d).sel_index[0] = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   825
						w->vscroll.pos = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   826
						// now we go back to set selected_id[1] properly
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   827
						SetWindowDirty(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   828
						return;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   829
					} else { //there are no vehicles in the left window
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   830
						selected_id[1] = INVALID_ENGINE;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   831
					}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   832
				}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   833
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   834
				if (WP(w,replaceveh_d).count[1] <= sel[1]) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   835
					if (WP(w,replaceveh_d).count[1]) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   836
						sel[1] = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   837
						WP(w,replaceveh_d).sel_index[1] = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   838
						w->vscroll2.pos = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   839
						// now we go back to set selected_id[1] properly
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   840
						SetWindowDirty(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   841
						return;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   842
					} else { //there are no vehicles in the right window
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   843
						selected_id[1] = INVALID_ENGINE;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   844
					}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   845
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   846
2556
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   847
				// Disable the "Start Replacing" button if:
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   848
				//    Either list is empty
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   849
				// or Both lists have the same vehicle selected
2747
7a233d41e9c4 (svn r3292) - Autoreplace: Disallow replacing to an engine type that already has a replacement set up; this stops loops being set up.
peter1138
parents: 2746
diff changeset
   850
				// or The selected replacement engine has a replacement (to prevent loops)
2556
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   851
				// or The right list (new replacement) has the existing replacement vehicle selected
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   852
				if (selected_id[0] == INVALID_ENGINE ||
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   853
						selected_id[1] == INVALID_ENGINE ||
2556
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   854
						selected_id[0] == selected_id[1] ||
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   855
						EngineReplacementForPlayer(p, selected_id[1]) != INVALID_ENGINE ||
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   856
						EngineReplacementForPlayer(p, selected_id[0]) == selected_id[1]) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   857
					SETBIT(w->disabled_state, 4);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   858
				} else {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   859
					CLRBIT(w->disabled_state, 4);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   860
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   861
2556
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   862
				// Disable the "Stop Replacing" button if:
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   863
				//    The left list (existing vehicle) is empty
c7fab9ee6335 (svn r3089) Fix possible issue with out-of-bounds array access in replace vehicle gui, and add brief commenting.
peter1138
parents: 2553
diff changeset
   864
				// or The selected vehicle has no replacement set up
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   865
				if (selected_id[0] == INVALID_ENGINE ||
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   866
						!EngineHasReplacementForPlayer(p, selected_id[0])) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   867
					SETBIT(w->disabled_state, 6);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   868
				} else {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   869
					CLRBIT(w->disabled_state, 6);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   870
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   871
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   872
				// now the actual drawing of the window itself takes place
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   873
				SetDParam(0, _vehicle_type_names[WP(w, replaceveh_d).vehicletype - VEH_Train]);
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   874
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   875
				if (WP(w, replaceveh_d).vehicletype == VEH_Train) {
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   876
					// set on/off for renew_keep_length
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   877
					SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   878
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   879
					// set wagon/engine button
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   880
					SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS);
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   881
				}
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
   882
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   883
				DrawWindowWidgets(w);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   884
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   885
				// sets up the string for the vehicle that is being replaced to
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   886
				if (selected_id[0] != INVALID_ENGINE) {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   887
					if (!EngineHasReplacementForPlayer(p, selected_id[0])) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   888
						SetDParam(0, STR_NOT_REPLACING);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   889
					} else {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2818
diff changeset
   890
						SetDParam(0, GetCustomEngineName(EngineReplacementForPlayer(p, selected_id[0])));
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   891
					}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   892
				} else {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   893
					SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   894
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   895
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4084
diff changeset
   896
				DrawString(145, 87 + w->resize.step_height * w->vscroll.cap, STR_02BD, 0x10);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   897
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   898
				/*	now we draw the two arrays according to what we just counted */
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   899
				DrawEngineArrayInReplaceWindow(w, x, y, x2, y2, pos, pos2, sel[0], sel[1], selected_id[0], selected_id[1]);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   900
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   901
				WP(w,replaceveh_d).sel_engine[0] = selected_id[0];
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   902
				WP(w,replaceveh_d).sel_engine[1] = selected_id[1];
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   903
				/* now we draw the info about the vehicles we selected */
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   904
				switch (WP(w,replaceveh_d).vehicletype) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   905
					case VEH_Train: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   906
						byte i = 0;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   907
						int offset = 0;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   908
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   909
						for (i = 0 ; i < 2 ; i++) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   910
							if (i > 0) offset = 228;
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   911
							if (selected_id[i] != INVALID_ENGINE) {
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
   912
								if (WP(w, replaceveh_d).wagon_btnstate) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   913
									/* it's an engine */
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   914
									DrawTrainEnginePurchaseInfo(2 + offset, 15 + (14 * w->vscroll.cap), selected_id[i]);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   915
								} else {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   916
									/* it's a wagon. Train cars are not replaced with the current GUI, but this code is ready for newgrf if anybody adds that*/
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   917
									DrawTrainWagonPurchaseInfo(2 + offset, 15 + (14 * w->vscroll.cap), selected_id[i]);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   918
								}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   919
							}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   920
						}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   921
						break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   922
					}   //end if case  VEH_Train
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   923
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   924
					case VEH_Road: {
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   925
						if (selected_id[0] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   926
							DrawRoadVehPurchaseInfo(2, 15 + (14 * w->vscroll.cap), selected_id[0]);
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   927
							if (selected_id[1] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   928
								DrawRoadVehPurchaseInfo(2 + 228, 15 + (14 * w->vscroll.cap), selected_id[1]);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   929
							}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   930
						}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   931
						break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   932
					}   // end of VEH_Road
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   933
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   934
					case VEH_Ship: {
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   935
						if (selected_id[0] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   936
							DrawShipPurchaseInfo(2, 15 + (24 * w->vscroll.cap), selected_id[0]);
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   937
							if (selected_id[1] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   938
								DrawShipPurchaseInfo(2 + 228, 15 + (24 * w->vscroll.cap), selected_id[1]);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   939
							}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   940
						}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   941
						break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   942
					}   // end of VEH_Ship
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   943
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   944
					case VEH_Aircraft: {
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   945
						if (selected_id[0] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   946
							DrawAircraftPurchaseInfo(2, 15 + (24 * w->vscroll.cap), selected_id[0]);
2746
47c6e734556e (svn r3291) - Codechange, Autoreplace: Replace int with EngineID and -1 with INVALID_ENGINE, as appropriate.
peter1138
parents: 2725
diff changeset
   947
							if (selected_id[1] != INVALID_ENGINE) {
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1891
diff changeset
   948
								DrawAircraftPurchaseInfo(2 + 228, 15 + (24 * w->vscroll.cap), selected_id[1]);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   949
							}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   950
						}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   951
						break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   952
					}   // end of VEH_Aircraft
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   953
				}
1462
a81f217b9cb6 (svn r1966) - Fix: [ 1110437 ] Replace Vehicles GUI gets random clicks. Breaks people! Don't forget the breaks in switch() statements!!
Darkvater
parents: 1363
diff changeset
   954
			} break;   // end of paint
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   955
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   956
		case WE_CLICK: {
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   957
			// these 3 variables is used if any of the lists is clicked
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   958
			uint16 click_scroll_pos = w->vscroll2.pos;
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   959
			uint16 click_scroll_cap = w->vscroll2.cap;
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   960
			byte click_side = 1;
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   961
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
   962
			switch (e->click.widget) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   963
				case 12:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   964
					WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   965
					SetWindowDirty(w);
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   966
					break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   967
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   968
				case 14:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   969
				case 15: /* Railtype selection dropdown menu */
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   970
					ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
   971
					break;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   972
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   973
				case 17: /* toggle renew_keep_length */
2805
29e2b43a1e20 (svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents: 2753
diff changeset
   974
					DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   975
					break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   976
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   977
				case 4: { /* Start replacing */
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   978
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   979
					EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   980
					DoCommandP(0, 3, veh_from + (veh_to << 16), NULL, CMD_REPLACE_VEHICLE);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   981
					break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   982
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   983
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   984
				case 6: { /* Stop replacing */
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   985
					EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2288
diff changeset
   986
					DoCommandP(0, 3, veh_from + (INVALID_ENGINE << 16), NULL, CMD_REPLACE_VEHICLE);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   987
					break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   988
				}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   989
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
   990
				case 7:
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   991
					// sets up that the left one was clicked. The default values are for the right one (9)
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   992
					// this way, the code for 9 handles both sides
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   993
					click_scroll_pos = w->vscroll.pos;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   994
					click_scroll_cap = w->vscroll.cap;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   995
					click_side = 0;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   996
					/* FALL THROUGH */
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
   997
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
   998
				case 9: {
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
   999
					uint i = (e->click.pt.y - 14) / w->resize.step_height;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1000
					if (i < click_scroll_cap) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1001
						WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1002
						SetWindowDirty(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1003
					}
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1004
					break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1005
				}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1006
			}
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1007
			break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1008
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1009
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1010
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
1178
7c39a741eafb (svn r1680) Feature: Replace train GUI now remembers the railtype selected in the dropdown menu
bjarni
parents: 1177
diff changeset
  1011
			_railtype_selected_in_replace_gui = e->dropdown.index;
3414
d728e3793041 (svn r4229) [elrail & autoreplace] Always show compatible rail vehicles in the left list, and only the selected rail type in the right list, to
peter1138
parents: 3393
diff changeset
  1012
			/* Reset scrollbar positions */
d728e3793041 (svn r4229) [elrail & autoreplace] Always show compatible rail vehicles in the left list, and only the selected rail type in the right list, to
peter1138
parents: 3393
diff changeset
  1013
			w->vscroll.pos  = 0;
d728e3793041 (svn r4229) [elrail & autoreplace] Always show compatible rail vehicles in the left list, and only the selected rail type in the right list, to
peter1138
parents: 3393
diff changeset
  1014
			w->vscroll2.pos = 0;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1015
			SetWindowDirty(w);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1016
			break;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1017
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1018
		case WE_RESIZE:
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1019
			w->vscroll.cap  += e->sizing.diff.y / (int)w->resize.step_height;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1020
			w->vscroll2.cap += e->sizing.diff.y / (int)w->resize.step_height;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1021
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1022
			w->widget[7].unkA = (w->vscroll.cap  << 8) + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1023
			w->widget[9].unkA = (w->vscroll2.cap << 8) + 1;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2971
diff changeset
  1024
			break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1025
	}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1026
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1027
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1028
static const Widget _replace_rail_vehicle_widgets[] = {
1465
e595fff78af2 (svn r1969) - GUI: Replace vehicle dropdown menu now looks a bit more comform the ones used throughout the game.
Darkvater
parents: 1462
diff changeset
  1029
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,       STR_018B_CLOSE_WINDOW},
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
  1030
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1031
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,       STR_STICKY_BUTTON},
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1032
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   197, STR_NULL,       STR_NULL},
1923
bce919cad8e1 (svn r2429) - Fix: Oops, forgot to increase the size of the autoreplace window to fit the extra info from powered wagons.
hackykid
parents: 1907
diff changeset
  1033
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   210,   221, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1034
{      WWT_PANEL,     RESIZE_TB,    14,   139,   316,   198,   209, STR_NULL,       STR_REPLACE_HELP_REPLACE_INFO_TAB},
1923
bce919cad8e1 (svn r2429) - Fix: Oops, forgot to increase the size of the autoreplace window to fit the extra info from powered wagons.
hackykid
parents: 1907
diff changeset
  1035
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   210,   221, STR_REPLACE_VEHICLES_STOP,  STR_REPLACE_HELP_STOP_BUTTON},
1465
e595fff78af2 (svn r1969) - GUI: Replace vehicle dropdown menu now looks a bit more comform the ones used throughout the game.
Darkvater
parents: 1462
diff changeset
  1036
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,          STR_REPLACE_HELP_LEFT_ARRAY},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1037
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
1465
e595fff78af2 (svn r1969) - GUI: Replace vehicle dropdown menu now looks a bit more comform the ones used throughout the game.
Darkvater
parents: 1462
diff changeset
  1038
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,          STR_REPLACE_HELP_RIGHT_ARRAY},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1039
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1040
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   197, STR_NULL,       STR_NULL},
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
  1041
// train specific stuff
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
  1042
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   198,   209, STR_REPLACE_ENGINE_WAGON_SELECT,       STR_REPLACE_ENGINE_WAGON_SELECT_HELP},  // widget 12
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1043
{      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   210,   221, STR_NULL,       STR_NULL},
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1044
{      WWT_PANEL,     RESIZE_TB,    14,   154,   277,   210,   221, STR_NULL,       STR_REPLACE_HELP_RAILTYPE},
2725
775e3e14ca46 (svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents: 2697
diff changeset
  1045
{    WWT_TEXTBTN,     RESIZE_TB,    14,   278,   289,   210,   221, STR_0225,       STR_REPLACE_HELP_RAILTYPE},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1046
{      WWT_PANEL,     RESIZE_TB,    14,   290,   305,   210,   221, STR_NULL,       STR_NULL},
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2611
diff changeset
  1047
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   317,   455,   198,   209, STR_REPLACE_REMOVE_WAGON,       STR_REPLACE_REMOVE_WAGON_HELP},
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
  1048
// end of train specific stuff
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1049
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   210,   221, STR_NULL,       STR_RESIZE_BUTTON},
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1050
{   WIDGETS_END},
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1051
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1052
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1053
static const Widget _replace_road_vehicle_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1054
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
1465
e595fff78af2 (svn r1969) - GUI: Replace vehicle dropdown menu now looks a bit more comform the ones used throughout the game.
Darkvater
parents: 1462
diff changeset
  1055
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1056
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1057
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   197, STR_NULL,                    STR_NULL},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1058
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   198,   209, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1059
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   198,   209, STR_NULL,                    STR_REPLACE_HELP_REPLACE_INFO_TAB},
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1060
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   198,   209, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1061
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                       STR_REPLACE_HELP_LEFT_ARRAY},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1062
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1063
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                       STR_REPLACE_HELP_RIGHT_ARRAY},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1064
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1065
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   197, STR_NULL,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1066
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   198,   209, STR_NULL,                    STR_RESIZE_BUTTON},
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1067
{   WIDGETS_END},
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1068
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1069
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1070
static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1071
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
1465
e595fff78af2 (svn r1969) - GUI: Replace vehicle dropdown menu now looks a bit more comform the ones used throughout the game.
Darkvater
parents: 1462
diff changeset
  1072
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1073
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1074
{      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   110,   181, STR_NULL,                    STR_NULL},
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4084
diff changeset
  1075
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   182,   193, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1076
{      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   182,   193, STR_NULL,                    STR_REPLACE_HELP_REPLACE_INFO_TAB},
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4084
diff changeset
  1077
{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   182,   193, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1078
{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   109, 0x401,                       STR_REPLACE_HELP_LEFT_ARRAY},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1079
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1080
{     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   109, 0x401,                       STR_REPLACE_HELP_RIGHT_ARRAY},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1081
{ WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1082
{      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   110,   181, STR_NULL,                    STR_NULL},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4280
diff changeset
  1083
{  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   182,   193, STR_NULL,                    STR_RESIZE_BUTTON},
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1084
{   WIDGETS_END},
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1085
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1086
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1087
static const WindowDesc _replace_rail_vehicle_desc = {
1923
bce919cad8e1 (svn r2429) - Fix: Oops, forgot to increase the size of the autoreplace window to fit the extra info from powered wagons.
hackykid
parents: 1907
diff changeset
  1088
	-1, -1, 456, 222,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1089
	WC_REPLACE_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1090
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1091
	_replace_rail_vehicle_widgets,
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1092
	ReplaceVehicleWndProc
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1093
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1094
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1095
static const WindowDesc _replace_road_vehicle_desc = {
2375
8cb43bb74d0e (svn r2901) Refix 'replace window' with wrong string-etc. coordinates. Also clean up, and make window-title a bit more meaningful (specify vehicle type replaced)
Darkvater
parents: 2354
diff changeset
  1096
	-1, -1, 456, 210,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1097
	WC_REPLACE_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1098
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1099
	_replace_road_vehicle_widgets,
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1100
	ReplaceVehicleWndProc
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1101
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1102
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1103
static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4084
diff changeset
  1104
	-1, -1, 456, 194,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1105
	WC_REPLACE_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1106
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1107
	_replace_ship_aircraft_vehicle_widgets,
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1108
	ReplaceVehicleWndProc
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1109
};
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1110
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1111
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1112
void ShowReplaceVehicleWindow(byte vehicletype)
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1113
{
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1114
	Window *w;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1115
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
  1116
	DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1117
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1118
	switch (vehicletype) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1119
		case VEH_Train:
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1120
			w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1121
			w->vscroll.cap  = 8;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1122
			w->resize.step_height = 14;
2970
3b9380f10074 (svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents: 2965
diff changeset
  1123
			WP(w, replaceveh_d).wagon_btnstate = true;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1124
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1125
		case VEH_Road:
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1126
			w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1127
			w->vscroll.cap  = 8;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1128
			w->resize.step_height = 14;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1129
			break;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
  1130
		case VEH_Ship:
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2530
diff changeset
  1131
		case VEH_Aircraft:
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1132
			w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1133
			w->vscroll.cap  = 4;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 845
diff changeset
  1134
			w->resize.step_height = 24;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1135
			break;
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 843
diff changeset
  1136
		default: return;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1137
	}
869
0f8d9efae2e8 (svn r1350) Replace Vehicle GUI:
bjarni
parents: 867
diff changeset
  1138
	w->caption_color = _local_player;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1139
	WP(w,replaceveh_d).vehicletype = vehicletype;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1140
	w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 594
diff changeset
  1141
}
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1191
diff changeset
  1142
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1191
diff changeset
  1143
void InitializeGUI(void)
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1191
diff changeset
  1144
{
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1191
diff changeset
  1145
	memset(&_sorting, 0, sizeof(_sorting));
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1191
diff changeset
  1146
}
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1147
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1148
/** Assigns an already open vehicle window to a new vehicle.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1149
 * Assigns an already open vehicle window to a new vehicle. If the vehicle got
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1150
 * any sub window open (orders and so on) it will change owner too.
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1151
 * @param *from_v the current owner of the window
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1152
 * @param *to_v the new owner of the window
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1153
 */
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1154
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v)
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1155
{
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1156
	Window *w;
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1157
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1158
	w = FindWindowById(WC_VEHICLE_VIEW, from_v->index);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1159
	if (w != NULL) {
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1160
		w->window_number = to_v->index;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1161
		WP(w, vp_d).follow_vehicle = to_v->index;
2552
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1162
		SetWindowDirty(w);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1163
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1164
		w = FindWindowById(WC_VEHICLE_ORDERS, from_v->index);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1165
		if (w != NULL) {
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1166
			w->window_number = to_v->index;
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1167
			SetWindowDirty(w);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1168
		}
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1169
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1170
		w = FindWindowById(WC_VEHICLE_REFIT, from_v->index);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1171
		if (w != NULL) {
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1172
			w->window_number = to_v->index;
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1173
			SetWindowDirty(w);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1174
		}
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1175
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1176
		w = FindWindowById(WC_VEHICLE_DETAILS, from_v->index);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1177
		if (w != NULL) {
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1178
			w->window_number = to_v->index;
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1179
			SetWindowDirty(w);
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1180
		}
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1181
	}
5b586a545665 (svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents: 2549
diff changeset
  1182
}