src/build_vehicle_gui.cpp
author glx
Mon, 26 May 2008 17:40:33 +0000
branchnoai
changeset 10718 7e9d9e40e16f
parent 10715 6bdf79ffb022
child 10776 07203fc29812
permissions -rw-r--r--
(svn r13268) [NoAI] -Fix: kill AIs on game abortion
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     1
/* $Id$ */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     2
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10355
diff changeset
     3
/** @file build_vehicle_gui.cpp GUI for building vehicles. */
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
     4
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     5
#include "stdafx.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     6
#include "openttd.h"
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
     7
#include "train.h"
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
     8
#include "roadveh.h"
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
     9
#include "ship.h"
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    10
#include "aircraft.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    11
#include "debug.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    12
#include "gui.h"
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    13
#include "articulated_vehicles.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    14
#include "textbuf_gui.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    15
#include "command_func.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    16
#include "player_func.h"
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    17
#include "airport.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    18
#include "vehicle_gui.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    19
#include "newgrf_engine.h"
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6413
diff changeset
    20
#include "cargotype.h"
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
    21
#include "group.h"
9625
3301b1b3889c (svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents: 9624
diff changeset
    22
#include "road_map.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    23
#include "strings_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    24
#include "window_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    25
#include "date_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    26
#include "vehicle_func.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    27
#include "settings_type.h"
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    28
#include "gfx_func.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    29
#include "widgets/dropdown_func.h"
10513
33cb70ff2f5d (svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents: 10455
diff changeset
    30
#include "string_func.h"
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
    31
#include "window_gui.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    32
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    33
#include "table/sprites.h"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    34
#include "table/strings.h"
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    35
5273
5fde4b8c94c4 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    36
enum BuildVehicleWidgets {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    37
	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    38
	BUILD_VEHICLE_WIDGET_CAPTION,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    39
	BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    40
	BUILD_VEHICLE_WIDGET_SORT_DROPDOWN,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    41
	BUILD_VEHICLE_WIDGET_LIST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    42
	BUILD_VEHICLE_WIDGET_SCROLLBAR,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    43
	BUILD_VEHICLE_WIDGET_PANEL,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    44
	BUILD_VEHICLE_WIDGET_BUILD,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    45
	BUILD_VEHICLE_WIDGET_RENAME,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    46
	BUILD_VEHICLE_WIDGET_RESIZE,
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
    47
	BUILD_VEHICLE_WIDGET_END
5273
5fde4b8c94c4 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    48
};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    49
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    50
static const Widget _build_vehicle_widgets[] = {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    51
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
    52
	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    53
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    54
	{   WWT_DROPDOWN,  RESIZE_RIGHT,    14,    81,   239,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    55
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,    39, 0x101,                   STR_NULL },
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    56
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,    39, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    57
	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,    40,   161, 0x0,                     STR_NULL },
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    58
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    59
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   162,   173, 0x0,                     STR_NULL },
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    60
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   162,   173, 0x0,                     STR_NULL },
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
    61
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   162,   173, 0x0,                     STR_RESIZE_BUTTON },
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    62
	{   WIDGETS_END},
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    63
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    64
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    65
static bool _internal_sort_order; // descending/ascending
6035
7c56c182a490 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 6034
diff changeset
    66
static byte _last_sort_criteria[]    = {0, 0, 0, 0};
7c56c182a490 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 6034
diff changeset
    67
static bool _last_sort_order[]       = {false, false, false, false};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    68
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    69
static int CDECL EngineNumberSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    70
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    71
	const EngineID va = *(const EngineID*)a;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    72
	const EngineID vb = *(const EngineID*)b;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    73
	int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    74
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    75
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    76
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    77
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    78
static int CDECL EngineIntroDateSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    79
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    80
	const int va = GetEngine(*(const EngineID*)a)->intro_date;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    81
	const int vb = GetEngine(*(const EngineID*)b)->intro_date;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    82
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    83
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    84
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    85
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    86
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    87
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    88
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    89
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    90
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    91
static int CDECL EngineNameSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    92
{
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    93
	static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    94
	static char     last_name[2][64] = { "\0", "\0" };
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    95
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    96
	const EngineID va = *(const EngineID*)a;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    97
	const EngineID vb = *(const EngineID*)b;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    98
	int r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    99
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   100
	if (va != last_engine[0]) {
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   101
		last_engine[0] = va;
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   102
		SetDParam(0, va);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   103
		GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   104
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   105
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   106
	if (vb != last_engine[1]) {
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   107
		last_engine[1] = vb;
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   108
		SetDParam(0, vb);
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   109
		GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   110
	}
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   111
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   112
	r = strcmp(last_name[0], last_name[1]); // sort by name
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   113
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   114
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   115
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   116
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   117
	}
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   118
	return _internal_sort_order ? -r : r;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   119
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   120
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   121
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   122
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   123
	const int va = GetEngine(*(const EngineID*)a)->reliability;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   124
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   125
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   126
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   127
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   128
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   129
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   130
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   131
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   132
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   133
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   134
/* Train sorting functions */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   135
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   136
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   137
	int va = RailVehInfo(*(const EngineID*)a)->base_cost;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   138
	int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   139
	int r = va - vb;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   140
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   141
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   142
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   143
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   144
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   145
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   146
	int va = RailVehInfo(*(const EngineID*)a)->max_speed;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   147
	int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   148
	int r = va - vb;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   149
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   150
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   151
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   152
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   153
static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   154
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   155
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   156
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   157
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   158
	int va = rvi_a->power;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   159
	int vb = rvi_b->power;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   160
	int r = va - vb;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   161
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   162
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   163
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   164
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   165
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   166
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   167
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   168
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   169
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   170
	Money va = rvi_a->running_cost * GetPriceByIndex(rvi_a->running_cost_class) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   171
	Money vb = rvi_b->running_cost * GetPriceByIndex(rvi_b->running_cost_class) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   172
	int r = ClampToI32(va - vb);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   173
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   174
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   175
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   176
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   177
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   178
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   179
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   180
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   181
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   182
	/* Here we are using a few tricks to get the right sort.
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   183
		* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   184
		* we will actually calculate cunning cost/power (to make it more than 1).
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   185
		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   186
		* Another thing is that both power and running costs should be doubled for multiheaded engines.
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   187
		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   188
	Money va = (rvi_a->running_cost * GetPriceByIndex(rvi_a->running_cost_class)) / max(1U, (uint)rvi_a->power);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   189
	Money vb = (rvi_b->running_cost * GetPriceByIndex(rvi_b->running_cost_class)) / max(1U, (uint)rvi_b->power);
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   190
	int r = ClampToI32(vb - va);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   191
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   192
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   193
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   194
6349
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   195
static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   196
{
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   197
	const EngineID va = *(const EngineID*)a;
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   198
	const EngineID vb = *(const EngineID*)b;
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   199
	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   200
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   201
	return _internal_sort_order ? -r : r;
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   202
}
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   203
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   204
static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   205
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   206
	int va = RailVehInfo(*(const EngineID*)a)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   207
	int vb = RailVehInfo(*(const EngineID*)b)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   208
	int r = va - vb;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   209
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   210
	if (r == 0) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   211
		/* Use EngineID to sort instead since we want consistent sorting */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   212
		return EngineNumberSorter(a, b);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   213
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   214
	return _internal_sort_order ? -r : r;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   215
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   216
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   217
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   218
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   219
	EngineID va = *(const EngineID*)a;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   220
	EngineID vb = *(const EngineID*)b;
6122
33ce525e85ff (svn r8460) -Fix (r8455): the build train window put locomotives and wagons in appeantly random order
bjarni
parents: 6119
diff changeset
   221
	int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
33ce525e85ff (svn r8460) -Fix (r8455): the build train window put locomotives and wagons in appeantly random order
bjarni
parents: 6119
diff changeset
   222
	int val_b = (RailVehInfo(vb)->railveh_type == RAILVEH_WAGON ? 1 : 0);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   223
	int r = val_a - val_b;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   224
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   225
	/* Use EngineID to sort instead since we want consistent sorting */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   226
	if (r == 0) return EngineNumberSorter(a, b);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   227
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   228
	return _internal_sort_order ? -r : r;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   229
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   230
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   231
/* Road vehicle sorting functions */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   232
static int CDECL RoadVehEngineCostSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   233
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   234
	int va = RoadVehInfo(*(const EngineID*)a)->base_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   235
	int vb = RoadVehInfo(*(const EngineID*)b)->base_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   236
	int r = va - vb;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   237
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   238
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   239
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   240
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   241
static int CDECL RoadVehEngineSpeedSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   242
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   243
	int va = RoadVehInfo(*(const EngineID*)a)->max_speed;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   244
	int vb = RoadVehInfo(*(const EngineID*)b)->max_speed;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   245
	int r = va - vb;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   246
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   247
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   248
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   249
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   250
static int CDECL RoadVehEngineRunningCostSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   251
{
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   252
	const RoadVehicleInfo *rvi_a = RoadVehInfo(*(const EngineID*)a);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   253
	const RoadVehicleInfo *rvi_b = RoadVehInfo(*(const EngineID*)b);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   254
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   255
	Money va = rvi_a->running_cost * GetPriceByIndex(rvi_a->running_cost_class);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   256
	Money vb = rvi_b->running_cost * GetPriceByIndex(rvi_b->running_cost_class);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   257
	int r = ClampToI32(va - vb);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   258
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   259
	if (r == 0) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   260
		/* Use EngineID to sort instead since we want consistent sorting */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   261
		return EngineNumberSorter(a, b);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   262
	}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   263
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   264
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   265
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   266
static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   267
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   268
	int va = RoadVehInfo(*(const EngineID*)a)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   269
	int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   270
	int r = va - vb;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   271
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   272
	if (r == 0) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   273
		/* Use EngineID to sort instead since we want consistent sorting */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   274
		return EngineNumberSorter(a, b);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   275
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   276
	return _internal_sort_order ? -r : r;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   277
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   278
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   279
/* Road vehicle sorting functions */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   280
static int CDECL ShipEngineCostSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   281
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   282
	int va = ShipVehInfo(*(const EngineID*)a)->base_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   283
	int vb = ShipVehInfo(*(const EngineID*)b)->base_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   284
	int r = va - vb;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   285
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   286
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   287
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   288
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   289
static int CDECL ShipEngineSpeedSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   290
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   291
	int va = ShipVehInfo(*(const EngineID*)a)->max_speed;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   292
	int vb = ShipVehInfo(*(const EngineID*)b)->max_speed;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   293
	int r = va - vb;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   294
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   295
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   296
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   297
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   298
static int CDECL ShipEngineRunningCostSorter(const void *a, const void *b)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   299
{
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   300
	const int va = ShipVehInfo(*(const EngineID*)a)->running_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   301
	const int vb = ShipVehInfo(*(const EngineID*)b)->running_cost;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   302
	const int r = va - vb;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   303
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   304
	if (r == 0) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   305
		/* Use EngineID to sort instead since we want consistent sorting */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   306
		return EngineNumberSorter(a, b);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   307
	}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   308
	return _internal_sort_order ? -r : r;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   309
}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   310
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   311
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   312
{
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   313
	int va = ShipVehInfo(*(const EngineID*)a)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   314
	int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   315
	int r = va - vb;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   316
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   317
	if (r == 0) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   318
		/* Use EngineID to sort instead since we want consistent sorting */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   319
		return EngineNumberSorter(a, b);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   320
	}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   321
	return _internal_sort_order ? -r : r;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   322
}
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   323
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   324
/* Aircraft sorting functions */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   325
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   326
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   327
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   328
	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   329
	const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   330
	int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   331
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   332
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   333
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   334
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   335
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   336
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   337
	const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   338
	const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   339
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   340
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   341
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   342
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   343
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   344
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   345
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   346
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   347
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   348
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   349
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   350
	const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   351
	const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   352
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   353
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   354
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   355
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   356
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   357
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   358
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   359
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   360
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   361
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   362
{
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   363
	int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   364
	int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   365
	int r = va - vb;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   366
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   367
	if (r == 0) {
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   368
		/* The planes has the same passenger capacity. Check mail capacity instead */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   369
		va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   370
		vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   371
		r = va - vb;
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   372
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   373
		if (r == 0) {
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   374
			/* Use EngineID to sort instead since we want consistent sorting */
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   375
			return EngineNumberSorter(a, b);
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   376
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   377
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   378
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   379
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   380
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   381
static EngList_SortTypeFunction * const _sorter[][10] = {{
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   382
	/* Trains */
6349
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   383
	&TrainEngineNumberSorter,
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   384
	&TrainEngineCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   385
	&TrainEngineSpeedSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   386
	&TrainEnginePowerSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   387
	&EngineIntroDateSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   388
	&EngineNameSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   389
	&TrainEngineRunningCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   390
	&TrainEnginePowerVsRunningCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   391
	&EngineReliabilitySorter,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   392
	&TrainEngineCapacitySorter,
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   393
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   394
	/* Road vehicles */
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   395
	&EngineNumberSorter,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   396
	&RoadVehEngineCostSorter,
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   397
	&RoadVehEngineSpeedSorter,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   398
	&EngineIntroDateSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   399
	&EngineNameSorter,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   400
	&RoadVehEngineRunningCostSorter,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   401
	&EngineReliabilitySorter,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   402
	&RoadVehEngineCapacitySorter,
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   403
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   404
	/* Ships */
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   405
	&EngineNumberSorter,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   406
	&ShipEngineCostSorter,
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   407
	&ShipEngineSpeedSorter,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   408
	&EngineIntroDateSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   409
	&EngineNameSorter,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   410
	&ShipEngineRunningCostSorter,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   411
	&EngineReliabilitySorter,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   412
	&ShipEngineCapacitySorter,
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   413
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   414
	/* Aircraft */
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   415
	&EngineNumberSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   416
	&AircraftEngineCostSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   417
	&AircraftEngineSpeedSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   418
	&EngineIntroDateSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   419
	&EngineNameSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   420
	&AircraftEngineRunningCostSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   421
	&EngineReliabilitySorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   422
	&AircraftEngineCargoSorter,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   423
}};
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   424
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   425
static const StringID _sort_listing[][11] = {{
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   426
	/* Trains */
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   427
	STR_ENGINE_SORT_ENGINE_ID,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   428
	STR_ENGINE_SORT_COST,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   429
	STR_SORT_BY_MAX_SPEED,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   430
	STR_ENGINE_SORT_POWER,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   431
	STR_ENGINE_SORT_INTRO_DATE,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   432
	STR_SORT_BY_DROPDOWN_NAME,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   433
	STR_ENGINE_SORT_RUNNING_COST,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   434
	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   435
	STR_SORT_BY_RELIABILITY,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   436
	STR_ENGINE_SORT_CARGO_CAPACITY,
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   437
	INVALID_STRING_ID
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   438
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   439
	/* Road vehicles */
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   440
	STR_ENGINE_SORT_ENGINE_ID,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   441
	STR_ENGINE_SORT_COST,
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   442
	STR_SORT_BY_MAX_SPEED,
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   443
	STR_ENGINE_SORT_INTRO_DATE,
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   444
	STR_SORT_BY_DROPDOWN_NAME,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   445
	STR_ENGINE_SORT_RUNNING_COST,
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   446
	STR_SORT_BY_RELIABILITY,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   447
	STR_ENGINE_SORT_CARGO_CAPACITY,
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   448
	INVALID_STRING_ID
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   449
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   450
	/* Ships */
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   451
	STR_ENGINE_SORT_ENGINE_ID,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   452
	STR_ENGINE_SORT_COST,
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   453
	STR_SORT_BY_MAX_SPEED,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   454
	STR_ENGINE_SORT_INTRO_DATE,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   455
	STR_SORT_BY_DROPDOWN_NAME,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   456
	STR_ENGINE_SORT_RUNNING_COST,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   457
	STR_SORT_BY_RELIABILITY,
9626
79f2b5a0cdd7 (svn r10118) [NoAI] -Sync with trunk r10015:r10096
glx
parents: 9625
diff changeset
   458
	STR_ENGINE_SORT_CARGO_CAPACITY,
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   459
	INVALID_STRING_ID
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   460
}, {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   461
	/* Aircraft */
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   462
	STR_ENGINE_SORT_ENGINE_ID,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   463
	STR_ENGINE_SORT_COST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   464
	STR_SORT_BY_MAX_SPEED,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   465
	STR_ENGINE_SORT_INTRO_DATE,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   466
	STR_SORT_BY_DROPDOWN_NAME,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   467
	STR_ENGINE_SORT_RUNNING_COST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   468
	STR_SORT_BY_RELIABILITY,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   469
	STR_ENGINE_SORT_CARGO_CAPACITY,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   470
	INVALID_STRING_ID
6036
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   471
}};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   472
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   473
static int DrawCargoCapacityInfo(int x, int y, EngineID engine, VehicleType type, bool refittable)
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   474
{
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   475
	uint16 *cap = GetCapacityOfArticulatedParts(engine, type);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   476
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   477
	for (uint c = 0; c < NUM_CARGO; c++) {
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   478
		if (cap[c] == 0) continue;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   479
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   480
		SetDParam(0, c);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   481
		SetDParam(1, cap[c]);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   482
		SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   483
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   484
		y += 10;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   485
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   486
		/* Only show as refittable once */
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   487
		refittable = false;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   488
	}
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   489
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   490
	return y;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   491
}
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   492
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   493
/* Draw rail wagon specific details */
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   494
static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   495
{
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   496
	/* Purchase cost */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   497
	SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   498
	DrawString(x, y, STR_PURCHASE_INFO_COST, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   499
	y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   500
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   501
	/* Wagon weight - (including cargo) */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   502
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   503
	SetDParam(0, weight);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   504
	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   505
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   506
	y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   507
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   508
	/* Wagon speed limit, displayed if above zero */
10715
6bdf79ffb022 (svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents: 10645
diff changeset
   509
	if (_settings.vehicle.wagon_speed_limits) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   510
		uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   511
		if (max_speed > 0) {
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   512
			SetDParam(0, max_speed * 10 / 16);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   513
			DrawString(x, y, STR_PURCHASE_INFO_SPEED, TC_FROMSTRING);
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   514
			y += 10;
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   515
		}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   516
	}
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   517
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   518
	/* Running cost */
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   519
	if (rvi->running_cost_class != 0xFF) {
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   520
		SetDParam(0, GetEngineProperty(engine_number, 0x0D, rvi->running_cost) * GetPriceByIndex(rvi->running_cost_class) >> 8);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   521
		DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   522
		y += 10;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   523
	}
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   524
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   525
	return y;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   526
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   527
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   528
/* Draw locomotive specific details */
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   529
static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   530
{
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6075
diff changeset
   531
	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   532
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   533
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   534
	/* Purchase Cost - Engine weight */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   535
	SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   536
	SetDParam(1, weight << multihead);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   537
	DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   538
	y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   539
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   540
	/* Max speed - Engine power */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   541
	SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16);
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   542
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power));
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   543
	DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   544
	y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   545
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   546
	/* Max tractive effort - not applicable if old acceleration or maglev */
10715
6bdf79ffb022 (svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents: 10645
diff changeset
   547
	if (_settings.vehicle.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   548
		SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   549
		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   550
		y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   551
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   552
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   553
	/* Running cost */
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   554
	if (rvi->running_cost_class != 0xFF) {
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   555
		SetDParam(0, GetEngineProperty(engine_number, 0x0D, rvi->running_cost) * GetPriceByIndex(rvi->running_cost_class) >> 8);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   556
		DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   557
		y += 10;
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   558
	}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   559
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   560
	/* Powered wagons power - Powered wagons extra weight */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   561
	if (rvi->pow_wag_power != 0) {
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   562
		SetDParam(0, rvi->pow_wag_power);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   563
		SetDParam(1, rvi->pow_wag_weight);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   564
		DrawString(x, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   565
		y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   566
	};
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   567
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   568
	return y;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   569
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   570
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   571
/* Draw road vehicle specific details */
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   572
static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   573
{
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
   574
	bool refittable = (EngInfo(engine_number)->refit_mask != 0);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   575
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   576
	/* Purchase cost - Max speed */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   577
	SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_price.roadveh_base >> 3) >> 5);
6125
492a1c0440af (svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents: 6122
diff changeset
   578
	SetDParam(1, rvi->max_speed * 10 / 32);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   579
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   580
	y += 10;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   581
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   582
	/* Running cost */
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   583
	SetDParam(0, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   584
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   585
	y += 10;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   586
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   587
	/* Cargo type + capacity */
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   588
	return DrawCargoCapacityInfo(x, y, engine_number, VEH_ROAD, refittable);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   589
}
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   590
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   591
/* Draw ship specific details */
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   592
static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   593
{
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   594
	/* Purchase cost - Max speed */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   595
	SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost) * (_price.ship_base >> 3) >> 5);
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   596
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   597
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   598
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   599
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   600
	/* Cargo type + capacity */
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   601
	SetDParam(0, svi->cargo_type);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   602
	SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   603
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   604
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   605
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   606
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   607
	/* Running cost */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   608
	SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _price.ship_running >> 8);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   609
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   610
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   611
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   612
	return y;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   613
}
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   614
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   615
/* Draw aircraft specific details */
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   616
static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   617
{
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   618
	CargoID cargo;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   619
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   620
	/* Purchase cost - Max speed */
9620
31e38d28a0af (svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents: 9601
diff changeset
   621
	SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
6519
367d6f96e23f (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6449
diff changeset
   622
	SetDParam(1, avi->max_speed * 10 / 16);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   623
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   624
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   625
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   626
	/* Cargo capacity */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   627
	cargo = FindFirstRefittableCargo(engine_number);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   628
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   629
		SetDParam(0, avi->passenger_capacity);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   630
		SetDParam(1, avi->mail_capacity);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   631
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, TC_FROMSTRING);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   632
	} else {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   633
		/* Note, if the default capacity is selected by the refit capacity
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   634
		* callback, then the capacity shown is likely to be incorrect. */
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4807
diff changeset
   635
		SetDParam(0, cargo);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6383
diff changeset
   636
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   637
		SetDParam(2, STR_9842_REFITTABLE);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   638
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   639
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   640
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   641
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   642
	/* Running cost */
9601
b499fdd106d5 (svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents: 9566
diff changeset
   643
	SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _price.aircraft_running >> 8);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   644
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   645
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   646
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   647
	return y;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   648
}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   649
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   650
/**
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   651
 * Draw the purchase info details of a vehicle at a given location.
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   652
 * @param x,y location where to draw the info
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   653
 * @param w how wide are the text allowed to be (size of widget/window to Draw in)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   654
 * @param engine_number the engine of which to draw the info of
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
   655
 * @return y after drawing all the text
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   656
 */
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
   657
int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   658
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   659
	const Engine *e = GetEngine(engine_number);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   660
	YearMonthDay ymd;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   661
	ConvertDateToYMD(e->intro_date, &ymd);
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   662
	bool refitable = false;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   663
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   664
	switch (e->type) {
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   665
		default: NOT_REACHED();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   666
		case VEH_TRAIN: {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   667
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   668
			uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   669
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   670
			refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0);
6070
e5a6d7b94c63 (svn r8381) -Fix (r8377): [build vehicle window] cleaned up the train refitable detection. It had two variables doing the same thing, but not always set to the same (oops)
bjarni
parents: 6068
diff changeset
   671
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6075
diff changeset
   672
			if (rvi->railveh_type == RAILVEH_WAGON) {
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   673
				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   674
			} else {
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   675
				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   676
			}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   677
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   678
			/* Cargo type + capacity, or N/A */
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   679
			int new_y = DrawCargoCapacityInfo(x, y, engine_number, VEH_TRAIN, refitable);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   680
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   681
			if (new_y == y) {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   682
				SetDParam(0, CT_INVALID);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   683
				SetDParam(2, STR_EMPTY);
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   684
				DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   685
				y += 10;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   686
			} else {
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   687
				y = new_y;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   688
			}
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   689
			break;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   690
		}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   691
		case VEH_ROAD:
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   692
			y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   693
			refitable = true;
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   694
			break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   695
		case VEH_SHIP: {
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   696
			const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   697
			y = DrawShipPurchaseInfo(x, y, engine_number, svi);
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   698
			refitable = svi->refittable;
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   699
		} break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   700
		case VEH_AIRCRAFT:
6068
286d4dfa1d39 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 6067
diff changeset
   701
			y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number));
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   702
			refitable = true;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   703
			break;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   704
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   705
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   706
	/* Draw details, that applies to all types except rail wagons */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   707
	if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   708
		/* Design date - Life length */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   709
		SetDParam(0, ymd.year);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   710
		SetDParam(1, e->lifelength);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   711
		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   712
		y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   713
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   714
		/* Reliability */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   715
		SetDParam(0, e->reliability * 100 >> 16);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   716
		DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, TC_FROMSTRING);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   717
		y += 10;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   718
	}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   719
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   720
	/* Additional text from NewGRF */
4930
fd91a88d6ef6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   721
	y += ShowAdditionalText(x, y, w, engine_number);
6041
c1c8b674d756 (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 6038
diff changeset
   722
	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
   723
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
   724
	return y;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   725
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   726
9732
f8eb3e208514 (svn r12211) [NoAI] -Sync: with trunk r12050:12209
glx
parents: 9724
diff changeset
   727
static void DrawVehicleEngine(VehicleType type, int x, int y, EngineID engine, SpriteID pal)
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   728
{
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   729
	switch (type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   730
		case VEH_TRAIN:    DrawTrainEngine(   x, y, engine, pal); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   731
		case VEH_ROAD:     DrawRoadVehEngine( x, y, engine, pal); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   732
		case VEH_SHIP:     DrawShipEngine(    x, y, engine, pal); break;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   733
		case VEH_AIRCRAFT: DrawAircraftEngine(x, y, engine, pal); break;
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   734
		default: NOT_REACHED();
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   735
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   736
}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   737
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   738
/** Engine drawing loop
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   739
 * @param type Type of vehicle (VEH_*)
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   740
 * @param x,y Where should the list start
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   741
 * @param eng_list What engines to draw
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   742
 * @param min where to start in the list
6053
bec24ee21ccb (svn r8364) -Codechange (r8362): added an assert to catch conditions where a request wants to draw more vehicles than the list contains
bjarni
parents: 6051
diff changeset
   743
 * @param max where in the list to end
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   744
 * @param selected_id what engine to highlight as selected, if any
10355
ee4b5f7a5bf2 (svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents: 10249
diff changeset
   745
 * @param count_location Offset to print the engine count (used by autoreplace). 0 means it's off
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   746
 */
10355
ee4b5f7a5bf2 (svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents: 10249
diff changeset
   747
void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, int count_location, GroupID selected_group)
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   748
{
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   749
	byte step_size = GetVehicleListHeight(type);
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   750
	byte x_offset = 0;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   751
	byte y_offset = 0;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   752
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 10355
diff changeset
   753
	assert(max <= eng_list.size());
6053
bec24ee21ccb (svn r8364) -Codechange (r8362): added an assert to catch conditions where a request wants to draw more vehicles than the list contains
bjarni
parents: 6051
diff changeset
   754
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   755
	switch (type) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   756
		case VEH_TRAIN:
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   757
			x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   758
			/* Fallthough */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   759
		case VEH_ROAD:
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   760
			x += 26;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   761
			x_offset = 30;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   762
			y += 2;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   763
			y_offset = 4;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   764
			break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   765
		case VEH_SHIP:
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   766
			x += 35;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   767
			x_offset = 40;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   768
			y += 7;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   769
			y_offset = 3;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   770
			break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6563
diff changeset
   771
		case VEH_AIRCRAFT:
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   772
			x += 27;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   773
			x_offset = 33;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   774
			y += 7;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   775
			y_offset = 3;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   776
			break;
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   777
		default: NOT_REACHED();
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   778
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   779
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   780
	for (; min < max; min++, y += step_size) {
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   781
		const EngineID engine = eng_list[min];
9701
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9694
diff changeset
   782
		/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
d1ac22c62f64 (svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents: 9694
diff changeset
   783
		const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   784
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9626
diff changeset
   785
		SetDParam(0, engine);
9722
ebf0ece7d8f6 (svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents: 9704
diff changeset
   786
		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
10355
ee4b5f7a5bf2 (svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents: 10249
diff changeset
   787
		DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
ee4b5f7a5bf2 (svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents: 10249
diff changeset
   788
		if (count_location != 0) {
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
   789
			SetDParam(0, num_engines);
10355
ee4b5f7a5bf2 (svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents: 10249
diff changeset
   790
			DrawStringRightAligned(count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   791
		}
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   792
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   793
}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   794
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   795
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   796
struct BuildVehicleWindow : Window {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   797
	VehicleType vehicle_type;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   798
	union {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   799
		RailTypeByte railtype;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   800
		AirportFTAClass::Flags flags;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   801
		RoadTypes roadtypes;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   802
	} filter;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   803
	bool descending_sort_order;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   804
	byte sort_criteria;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   805
	bool regenerate_list;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   806
	EngineID sel_engine;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   807
	EngineID rename_engine;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   808
	EngineList eng_list;
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   809
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   810
	BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == 0 ? (int)type : tile)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   811
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   812
		this->vehicle_type = type;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   813
		int vlh = GetVehicleListHeight(this->vehicle_type);
9566
9936b201d53f (svn r9505) [NoAI] -Sync with trunk r9468:9504
truelight
parents: 6585
diff changeset
   814
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   815
		ResizeWindow(this, 0, vlh - 14);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   816
		this->resize.step_height = vlh;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   817
		this->vscroll.cap = 1;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   818
		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = 0x101;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   819
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   820
		this->resize.width  = this->width;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   821
		this->resize.height = this->height;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   822
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   823
		this->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   824
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   825
		this->sel_engine      = INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   826
		this->regenerate_list = false;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   827
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   828
		this->sort_criteria         = _last_sort_criteria[type];
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   829
		this->descending_sort_order = _last_sort_order[type];
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   830
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   831
		switch (type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   832
			default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   833
			case VEH_TRAIN:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   834
				this->filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   835
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   836
			case VEH_ROAD:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   837
				this->filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   838
			case VEH_SHIP:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   839
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   840
			case VEH_AIRCRAFT:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   841
				this->filter.flags =
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   842
					tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   843
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   844
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   845
		this->SetupWindowStrings(type);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   846
		ResizeButtons(this, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   847
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   848
		this->GenerateBuildList(); // generate the list, since we need it in the next line
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   849
		/* Select the first engine in the list as default when opening the window */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   850
		if (this->eng_list.size() > 0) this->sel_engine = this->eng_list[0];
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   851
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   852
		this->FindWindowPlacementAndResize(desc);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   853
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   854
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   855
	/* Setup widget strings to fit the different types of vehicles */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   856
	void SetupWindowStrings(VehicleType type)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   857
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   858
		switch (type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   859
			default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   860
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   861
			case VEH_TRAIN:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   862
				this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_JUST_STRING;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   863
				this->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_8843_TRAIN_VEHICLE_SELECTION;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   864
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_881F_BUILD_VEHICLE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   865
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   866
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_8820_RENAME;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   867
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   868
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   869
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   870
			case VEH_ROAD:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   871
				this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9006_NEW_ROAD_VEHICLES;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   872
				this->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9026_ROAD_VEHICLE_SELECTION;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   873
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9007_BUILD_VEHICLE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   874
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   875
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9034_RENAME;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   876
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   877
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   878
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   879
			case VEH_SHIP:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   880
				this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9808_NEW_SHIPS;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   881
				this->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9825_SHIP_SELECTION_LIST_CLICK;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   882
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9809_BUILD_SHIP;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   883
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   884
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9836_RENAME;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   885
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   886
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   887
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   888
			case VEH_AIRCRAFT:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   889
				this->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_A005_NEW_AIRCRAFT;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   890
				this->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_A025_AIRCRAFT_SELECTION_LIST;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   891
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_A006_BUILD_AIRCRAFT;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   892
				this->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   893
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_A037_RENAME;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   894
				this->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_A038_RENAME_AIRCRAFT_TYPE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   895
				break;
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   896
		}
6051
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   897
	}
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   898
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   899
	/* Figure out what train EngineIDs to put in the list */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   900
	void GenerateBuildTrainList()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   901
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   902
		EngineID sel_id = INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   903
		int num_engines = 0;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   904
		int num_wagons  = 0;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   905
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   906
		this->filter.railtype = (this->window_number <= VEH_END) ? RAILTYPE_END : GetRailType(this->window_number);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   907
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   908
		this->eng_list.clear();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   909
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   910
		/* Make list of all available train engines and wagons.
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   911
		* Also check to see if the previously selected engine is still available,
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   912
		* and if not, reset selection to INVALID_ENGINE. This could be the case
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   913
		* when engines become obsolete and are removed */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   914
		const Engine *e;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   915
		FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   916
			EngineID eid = e->index;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   917
			const RailVehicleInfo *rvi = &e->u.rail;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   918
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   919
			if (this->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   920
			if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   921
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   922
			this->eng_list.push_back(eid);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   923
			if (rvi->railveh_type != RAILVEH_WAGON) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   924
				num_engines++;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   925
			} else {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   926
				num_wagons++;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   927
			}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   928
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   929
			if (eid == this->sel_engine) sel_id = eid;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   930
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   931
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   932
		this->sel_engine = sel_id;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   933
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   934
		/* make engines first, and then wagons, sorted by ListPositionOfEngine() */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   935
		_internal_sort_order = false;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   936
		EngList_Sort(&this->eng_list, TrainEnginesThenWagonsSorter);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   937
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   938
		/* and then sort engines */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   939
		_internal_sort_order = this->descending_sort_order;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   940
		EngList_SortPartial(&this->eng_list, _sorter[0][this->sort_criteria], 0, num_engines);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   941
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   942
		/* and finally sort wagons */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   943
		EngList_SortPartial(&this->eng_list, _sorter[0][this->sort_criteria], num_engines, num_wagons);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   944
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   945
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   946
	/* Figure out what road vehicle EngineIDs to put in the list */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   947
	void GenerateBuildRoadVehList()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   948
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   949
		EngineID sel_id = INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   950
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   951
		this->eng_list.clear();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   952
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   953
		const Engine *e;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   954
		FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   955
			EngineID eid = e->index;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   956
			if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   957
			if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   958
			this->eng_list.push_back(eid);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   959
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   960
			if (eid == this->sel_engine) sel_id = eid;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   961
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   962
		this->sel_engine = sel_id;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   963
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   964
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   965
	/* Figure out what ship EngineIDs to put in the list */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   966
	void GenerateBuildShipList()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   967
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   968
		EngineID sel_id = INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   969
		this->eng_list.clear();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   970
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   971
		const Engine *e;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   972
		FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   973
			EngineID eid = e->index;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   974
			if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   975
			this->eng_list.push_back(eid);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   976
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   977
			if (eid == this->sel_engine) sel_id = eid;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   978
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   979
		this->sel_engine = sel_id;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   980
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   981
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   982
	/* Figure out what aircraft EngineIDs to put in the list */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   983
	void GenerateBuildAircraftList()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   984
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   985
		EngineID sel_id = INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   986
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   987
		this->eng_list.clear();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   988
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   989
		/* Make list of all available planes.
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   990
		* Also check to see if the previously selected plane is still available,
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   991
		* and if not, reset selection to INVALID_ENGINE. This could be the case
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   992
		* when planes become obsolete and are removed */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   993
		const Engine *e;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   994
		FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   995
			EngineID eid = e->index;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   996
			if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   997
			/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   998
			if (this->window_number > VEH_END && !CanAircraftUseStation(eid, this->window_number)) continue;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
   999
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1000
			this->eng_list.push_back(eid);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1001
			if (eid == this->sel_engine) sel_id = eid;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1002
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1003
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1004
		this->sel_engine = sel_id;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1005
	}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1006
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1007
	/* Generate the list of vehicles */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1008
	void GenerateBuildList()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1009
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1010
		switch (this->vehicle_type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1011
			default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1012
			case VEH_TRAIN:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1013
				this->GenerateBuildTrainList();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1014
				return; // trains should not reach the last sorting
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1015
			case VEH_ROAD:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1016
				this->GenerateBuildRoadVehList();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1017
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1018
			case VEH_SHIP:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1019
				this->GenerateBuildShipList();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1020
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1021
			case VEH_AIRCRAFT:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1022
				this->GenerateBuildAircraftList();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1023
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1024
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1025
		_internal_sort_order = this->descending_sort_order;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1026
		EngList_Sort(&this->eng_list, _sorter[this->vehicle_type][this->sort_criteria]);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1027
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1028
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1029
	void OnClick(Point pt, int widget)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1030
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1031
		switch (widget) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1032
			case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1033
				this->descending_sort_order ^= true;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1034
				_last_sort_order[this->vehicle_type] = this->descending_sort_order;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1035
				this->regenerate_list = true;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1036
				this->SetDirty();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1037
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1038
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1039
			case BUILD_VEHICLE_WIDGET_LIST: {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1040
				uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.pos;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1041
				size_t num_items = this->eng_list.size();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1042
				this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1043
				this->SetDirty();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1044
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1045
			}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1046
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1047
			case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1048
				ShowDropDownMenu(this, _sort_listing[this->vehicle_type], this->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1049
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1050
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1051
			case BUILD_VEHICLE_WIDGET_BUILD: {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1052
				EngineID sel_eng = this->sel_engine;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1053
				if (sel_eng != INVALID_ENGINE) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1054
					switch (this->vehicle_type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1055
						default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1056
						case VEH_TRAIN:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1057
							DoCommandP(this->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1058
										CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1059
							break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1060
						case VEH_ROAD:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1061
							DoCommandP(this->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1062
							break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1063
						case VEH_SHIP:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1064
							DoCommandP(this->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1065
							break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1066
						case VEH_AIRCRAFT:
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1067
							DoCommandP(this->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1068
							break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1069
					}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1070
				}
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1071
				break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1072
			}
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1073
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1074
			case BUILD_VEHICLE_WIDGET_RENAME: {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1075
				EngineID sel_eng = this->sel_engine;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1076
				if (sel_eng != INVALID_ENGINE) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1077
					StringID str = STR_NULL;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1078
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1079
					this->rename_engine = sel_eng;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1080
					switch (this->vehicle_type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1081
						default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1082
						case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1083
						case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1084
						case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1085
						case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1086
					}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1087
					SetDParam(0, sel_eng);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1088
					ShowQueryString(STR_ENGINE_NAME, str, 31, 160, this, CS_ALPHANUMERAL);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1089
				}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1090
				break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1091
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1092
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1093
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1094
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1095
	virtual void OnInvalidateData(int data)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1096
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1097
		this->regenerate_list = true;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1098
	}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1099
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1100
	virtual void OnPaint()
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1101
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1102
		if (this->regenerate_list) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1103
			this->regenerate_list = false;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1104
			this->GenerateBuildList();
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1105
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1106
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1107
		uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.size());
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1108
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1109
		this->SetWidgetDisabledState(BUILD_VEHICLE_WIDGET_BUILD, this->window_number <= VEH_END);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1110
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1111
		SetVScrollCount(this, this->eng_list.size());
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1112
		SetDParam(0, this->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1113
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1114
		/* Set text of sort by dropdown */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1115
		this->widget[BUILD_VEHICLE_WIDGET_SORT_DROPDOWN].data = _sort_listing[this->vehicle_type][this->sort_criteria];
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1116
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1117
		this->DrawWidgets();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1118
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1119
		DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1120
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1121
		if (this->sel_engine != INVALID_ENGINE) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1122
			const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1123
			int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, this->sel_engine);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1124
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1125
			if (text_end > wi->bottom) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1126
				this->SetDirty();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1127
				ResizeWindowForWidget(this, BUILD_VEHICLE_WIDGET_PANEL, 0, text_end - wi->bottom);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1128
				this->SetDirty();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1129
			}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1130
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1131
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1132
		this->DrawSortButtonState(BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1133
	}
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1134
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1135
	virtual void OnDoubleClick(Point pt, int widget)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1136
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1137
		if (widget == BUILD_VEHICLE_WIDGET_LIST) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1138
			/* When double clicking, we want to buy a vehicle */
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1139
			this->OnClick(pt, BUILD_VEHICLE_WIDGET_BUILD);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1140
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1141
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1142
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1143
	virtual void OnQueryTextFinished(char *str)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1144
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1145
		if (!StrEmpty(str)) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1146
			StringID err_str = STR_NULL;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1147
			_cmd_text = str;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1148
			switch (this->vehicle_type) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1149
				default: NOT_REACHED();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1150
				case VEH_TRAIN:    err_str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1151
				case VEH_ROAD:     err_str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1152
				case VEH_SHIP:     err_str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1153
				case VEH_AIRCRAFT: err_str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1154
			}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1155
			DoCommandP(0, this->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(err_str));
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1156
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1157
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1158
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1159
	virtual void OnDropdownSelect(int widget, int index)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1160
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1161
		if (this->sort_criteria != index) {
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1162
			this->sort_criteria = index;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1163
			_last_sort_criteria[this->vehicle_type] = this->sort_criteria;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1164
			this->regenerate_list = true;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1165
		}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1166
		this->SetDirty();
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1167
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1168
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1169
	virtual void OnResize(Point new_size, Point delta)
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1170
	{
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1171
		if (delta.x != 0) ResizeButtons(this, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1172
		if (delta.y == 0) return;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1173
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1174
		this->vscroll.cap += delta.y / (int)GetVehicleListHeight(this->vehicle_type);
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1175
		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1176
	}
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1177
};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1178
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1179
static const WindowDesc _build_vehicle_desc = {
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
  1180
	WDP_AUTO, WDP_AUTO, 240, 174, 240, 256,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6125
diff changeset
  1181
	WC_BUILD_VEHICLE, WC_NONE,
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1182
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1183
	_build_vehicle_widgets,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1184
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1185
9624
b71483f2330f (svn r9915) [NoAI] -Sync with trunk -r9815:9914
glx
parents: 9620
diff changeset
  1186
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1187
{
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1188
	/* We want to be able to open both Available Train as Available Ships,
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1189
	 *  so if tile == 0 (Available XXX Window), use 'type' as unique number.
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1190
	 *  As it always is a low value, it won't collide with any real tile
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1191
	 *  number. */
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1192
	uint num = (tile == 0) ? (int)type : tile;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1193
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1194
	assert(IsPlayerBuildableVehicleType(type));
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1195
9686
d3c195c226f9 (svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents: 9629
diff changeset
  1196
	DeleteWindowById(WC_BUILD_VEHICLE, num);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1197
10645
8cbdb511a674 (svn r13189) [NoAI] -Sync: with trunk r13055:13185.
glx
parents: 10513
diff changeset
  1198
	new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1199
}