src/build_vehicle_gui.cpp
author celestar
Wed, 13 Jun 2007 12:05:56 +0000
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
permissions -rw-r--r--
(svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
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
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
     3
/** @file build_vehicle_gui.cpp */
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 "functions.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    13
#include "table/sprites.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    14
#include "table/strings.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    15
#include "window.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    16
#include "gui.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    17
#include "vehicle.h"
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    18
#include "articulated_vehicles.h"
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    19
#include "gfx.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    20
#include "station.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    21
#include "command.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    22
#include "engine.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    23
#include "player.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    24
#include "depot.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    25
#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
    26
#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
    27
#include "newgrf_engine.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    28
#include "date.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    29
#include "strings.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
    30
#include "cargotype.h"
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    31
#include "group.h"
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    32
#include "road_map.h"
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    33
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    34
5273
5fde4b8c94c4 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    35
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
    36
	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
    37
	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
    38
	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
    39
	BUILD_VEHICLE_WIDGET_SORT_TEXT,
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,
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
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 },
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
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},
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    54
	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    55
	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    56
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,   121, 0x0,                     STR_NULL },
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    57
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    58
	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,   122,   243, 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
    59
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    60
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   244,   255, 0x0,                     STR_NULL },
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    61
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   244,   255, 0x0,                     STR_NULL },
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
    62
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   244,   255, 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
    63
	{   WIDGETS_END},
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
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    66
/* Setup widget strings to fit the different types of vehicles */
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
    67
static void SetupWindowStrings(Window *w, byte type)
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    68
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    69
	switch (type) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    70
		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
    71
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_JUST_STRING;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    72
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_8843_TRAIN_VEHICLE_SELECTION;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    73
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_881F_BUILD_VEHICLE;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    74
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    75
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_8820_RENAME;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    76
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    77
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    78
		case VEH_ROAD:
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    79
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9006_NEW_ROAD_VEHICLES;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    80
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9026_ROAD_VEHICLE_SELECTION;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    81
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9007_BUILD_VEHICLE;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    82
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    83
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9034_RENAME;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    84
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
    85
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    86
		case VEH_SHIP:
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    87
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9808_NEW_SHIPS;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    88
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9825_SHIP_SELECTION_LIST_CLICK;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    89
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9809_BUILD_SHIP;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    90
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    91
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9836_RENAME;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    92
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
    93
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
    94
		case VEH_AIRCRAFT:
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    95
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_A005_NEW_AIRCRAFT;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    96
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_A025_AIRCRAFT_SELECTION_LIST;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    97
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_A006_BUILD_AIRCRAFT;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    98
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
    99
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_A037_RENAME;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   100
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_A038_RENAME_AIRCRAFT_TYPE;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   101
			break;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   102
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   103
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   104
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   105
static bool _internal_sort_order; // descending/ascending
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   106
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
   107
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
   108
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
   109
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   110
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
   111
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   112
	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
   113
	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
   114
	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
   115
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   116
	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
   117
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   118
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   119
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
   120
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   121
	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
   122
	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
   123
	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
   124
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   125
	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
   126
		/* 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
   127
		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
   128
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   129
	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
   130
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   131
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   132
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
   133
{
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   134
	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
   135
	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
   136
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   137
	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
   138
	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
   139
	int r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   140
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   141
	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
   142
		last_engine[0] = va;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   143
		GetString(last_name[0], GetCustomEngineName(va), 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
   144
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   145
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   146
	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
   147
		last_engine[1] = vb;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   148
		GetString(last_name[1], GetCustomEngineName(vb), 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
   149
	}
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   150
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   151
	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
   152
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   153
	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
   154
		/* 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
   155
		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
   156
	}
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   157
	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
   158
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   159
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   160
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
   161
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   162
	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
   163
	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
   164
	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
   165
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   166
	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
   167
		/* 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
   168
		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
   169
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   170
	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
   171
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   172
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
/* 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
   174
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
   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
	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
   177
	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
   178
	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
   179
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   180
	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
   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
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   183
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
   184
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   185
	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
   186
	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
   187
	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
   188
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   189
	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
   190
}
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
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
   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
	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
   195
	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
   196
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
   197
	int va = rvi_a->power << (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
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
   198
	int vb = rvi_b->power << (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 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
   199
	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
   200
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   201
	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
   202
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   203
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   204
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
   205
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   206
	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
   207
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   208
	uint32 cost_class_a, cost_class_b;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   209
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   210
	switch (rvi_a->running_cost_class) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   211
		default:
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   212
		case 0: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   213
		case 1: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   214
		case 2: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   215
	}
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   216
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   217
	switch (rvi_b->running_cost_class) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   218
		default:
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   219
		case 0: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   220
		case 1: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   221
		case 2: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   222
	}
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   223
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   224
	int va = rvi_a->running_cost_base * cost_class_a * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   225
	int vb = rvi_b->running_cost_base * cost_class_b * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   226
	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
   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
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   231
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
   232
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   233
	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
   234
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   235
	uint32 cost_class_a, cost_class_b;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   236
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   237
	switch (rvi_a->running_cost_class) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   238
		default:
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   239
		case 0: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   240
		case 1: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   241
		case 2: cost_class_a = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   242
	}
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   243
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   244
	switch (rvi_b->running_cost_class) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   245
		default:
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   246
		case 0: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   247
		case 1: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   248
		case 2: cost_class_b = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   249
	}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   250
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   251
	/* 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
   252
		* 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
   253
		* 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
   254
		* 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
   255
		* 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
   256
		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   257
	int va = rvi_a->running_cost_base * cost_class_a / max((uint16)1, rvi_a->power);
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   258
	int vb = rvi_b->running_cost_base * cost_class_b / max((uint16)1, 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
   259
	int r = vb - va;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   260
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   261
	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
   262
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   263
6349
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   264
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
   265
{
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   266
	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
   267
	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
   268
	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
   269
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   270
	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
   271
}
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   272
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   273
static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   274
{
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   275
	int va = RailVehInfo(*(const EngineID*)a)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   276
	int vb = RailVehInfo(*(const EngineID*)b)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   277
	int r = va - vb;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   278
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   279
	if (r == 0) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   280
		/* Use EngineID to sort instead since we want consistent sorting */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   281
		return EngineNumberSorter(a, b);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   282
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   283
	return _internal_sort_order ? -r : r;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   284
}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   285
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   286
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
   287
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   288
	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
   289
	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
   290
	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
   291
	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
   292
	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
   293
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   294
	/* 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
   295
	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
   296
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   297
	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
   298
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   299
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   300
static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   301
{
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   302
	int va = RoadVehInfo(*(const EngineID*)a)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   303
	int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   304
	int r = va - vb;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   305
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   306
	if (r == 0) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   307
		/* Use EngineID to sort instead since we want consistent sorting */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   308
		return EngineNumberSorter(a, b);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   309
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   310
	return _internal_sort_order ? -r : r;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   311
}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   312
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   313
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   314
{
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   315
	int va = ShipVehInfo(*(const EngineID*)a)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   316
	int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   317
	int r = va - vb;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   318
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   319
	if (r == 0) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   320
		/* Use EngineID to sort instead since we want consistent sorting */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   321
		return EngineNumberSorter(a, b);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   322
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   323
	return _internal_sort_order ? -r : r;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   324
}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   325
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   326
/* 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
   327
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   328
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
   329
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   330
	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
   331
	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
   332
	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
   333
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   334
	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
   335
}
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
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
   338
{
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 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
   340
	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
   341
	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
   342
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   343
	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
   344
		/* 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
   345
		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
   346
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   347
	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
   348
}
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
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
   351
{
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 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
   353
	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
   354
	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
   355
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   356
	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
   357
		/* 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
   358
		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
   359
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   360
	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
   361
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   362
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   363
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
   364
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   365
	int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   366
	int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   367
	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
   368
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   369
	if (r == 0) {
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   370
		/* The planes has the same passenger capacity. Check mail capacity instead */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   371
		va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   372
		vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   373
		r = va - vb;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   374
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   375
		if (r == 0) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   376
			/* Use EngineID to sort instead since we want consistent sorting */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   377
			return EngineNumberSorter(a, b);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   378
		}
4800
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
	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
   381
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   382
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   383
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
   384
	/* Trains */
6349
c22327023623 (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 6206
diff changeset
   385
	&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
   386
	&TrainEngineCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   387
	&TrainEngineSpeedSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   388
	&TrainEnginePowerSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   389
	&EngineIntroDateSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   390
	&EngineNameSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   391
	&TrainEngineRunningCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   392
	&TrainEnginePowerVsRunningCostSorter,
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   393
	&EngineReliabilitySorter,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   394
	&TrainEngineCapacitySorter,
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   395
}, {
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
   396
	/* 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
   397
	&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
   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,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   400
	&EngineReliabilitySorter,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   401
	&RoadVehEngineCapacitySorter,
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   402
}, {
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
   403
	/* 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
   404
	&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
   405
	&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
   406
	&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
   407
	&EngineReliabilitySorter,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   408
	&ShipEngineCapacitySorter,
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   409
}, {
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
   410
	/* 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
   411
	&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
   412
	&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
   413
	&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
   414
	&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
   415
	&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
   416
	&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
   417
	&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
   418
	&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
   419
}};
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   420
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   421
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
   422
	/* 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
   423
	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
   424
	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
   425
	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
   426
	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
   427
	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
   428
	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
   429
	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
   430
	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
   431
	STR_SORT_BY_RELIABILITY,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   432
	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
   433
	INVALID_STRING_ID
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   434
}, {
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
   435
	/* 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
   436
	STR_ENGINE_SORT_ENGINE_ID,
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   437
	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
   438
	STR_SORT_BY_DROPDOWN_NAME,
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   439
	STR_SORT_BY_RELIABILITY,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   440
	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
   441
	INVALID_STRING_ID
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   442
}, {
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
   443
	/* 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
   444
	STR_ENGINE_SORT_ENGINE_ID,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   445
	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
   446
	STR_SORT_BY_DROPDOWN_NAME,
2775343bd5d5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 6035
diff changeset
   447
	STR_SORT_BY_RELIABILITY,
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   448
	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
   449
	INVALID_STRING_ID
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   450
}, {
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
   451
	/* Aircraft */
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   452
	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
   453
	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
   454
	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
   455
	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
   456
	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
   457
	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
   458
	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
   459
	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
   460
	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
   461
}};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   462
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   463
/* 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
   464
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
   465
{
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   466
	/* Purchase cost */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   467
	SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _eco->GetPrice(CEconomy::BUILD_RAILWAGON)) >> 8);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   468
	DrawString(x, y, STR_PURCHASE_INFO_COST, 0);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   469
	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
   470
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   471
	/* Wagon weight - (including cargo) */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   472
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   473
	SetDParam(0, weight);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   474
	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + 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
   475
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   476
	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
   477
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   478
	/* Wagon speed limit, displayed if above zero */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   479
	if (_patches.wagon_speed_limits) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   480
		uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   481
		if (max_speed > 0) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   482
			SetDParam(0, max_speed * 10 / 16);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   483
			DrawString(x, y, STR_PURCHASE_INFO_SPEED, 0);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   484
			y += 10;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   485
		}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   486
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   487
	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
   488
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   489
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   490
/* Draw locomotive specific details */
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   491
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
   492
{
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
   493
	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   494
	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
   495
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 - Engine weight */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   497
	SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_eco->GetPrice(CEconomy::BUILD_RAILVEHICLE) >> 3) >> 5);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   498
	SetDParam(1, weight << multihead);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   499
	DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, 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
   500
	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
   501
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   502
	/* Max speed - Engine power */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   503
	SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   504
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power) << multihead);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   505
	DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, 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
   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
	/* Max tractive effort - not applicable if old acceleration or maglev */
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   509
	if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   510
		SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   511
		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   512
		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
   513
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   514
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   515
	uint32 cost_class;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   516
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   517
	switch (rvi->running_cost_class) {
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   518
		default:
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   519
		case 0: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   520
		case 1: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL1); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   521
		case 2: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL2); break;
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   522
	}
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   523
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   524
	/* Running cost */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   525
	SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * cost_class >> 8) << multihead);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   526
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 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
   527
	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
   528
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   529
	/* 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
   530
	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
   531
		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
   532
		SetDParam(1, rvi->pow_wag_weight);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   533
		DrawString(x, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 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
   534
		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
   535
	};
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   536
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   537
	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
   538
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   539
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   540
/* 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
   541
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
   542
{
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   543
	bool refittable = (_engine_info[engine_number].refit_mask != 0);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   544
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   545
	/* Purchase cost - Max speed */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   546
	SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_eco->GetPrice(CEconomy::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
   547
	SetDParam(1, rvi->max_speed * 10 / 32);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   548
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   549
	y += 10;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   550
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   551
	/* Running cost */
9903
dc85aaa556ae (svn r9534) [gamebalance] -Codechange: Made the prices a member of the Economy and removed all global variables concerning prices (INCOMPLETE).
celestar
parents: 9895
diff changeset
   552
	SetDParam(0, rvi->running_cost * _eco->GetPrice(CEconomy::ROADVEH_RUNNING) >> 8);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   553
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   554
	y += 10;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   555
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   556
	/* Cargo type + capacity */
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   557
	SetDParam(0, rvi->cargo_type);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   558
	SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity));
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   559
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   560
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   561
	y += 10;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   562
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   563
	return y;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   564
}
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   565
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   566
/* 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
   567
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
   568
{
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   569
	/* Purchase cost - Max speed */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   570
	SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost)
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   571
			* (_eco->GetPrice(CEconomy::SHIP_BASE) >> 3) >> 5);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   572
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   573
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   574
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   575
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   576
	/* 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
   577
	SetDParam(0, svi->cargo_type);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   578
	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
   579
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   580
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   581
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   582
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   583
	/* Running cost */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   584
	SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _eco->GetPrice(CEconomy::SHIP_RUNNING) >> 8);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   585
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   586
	y += 10;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   587
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   588
	return y;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   589
}
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   590
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   591
/* 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
   592
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
   593
{
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   594
	CargoID cargo;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   595
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   596
	/* Purchase cost - Max speed */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   597
	SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_eco->GetPrice(CEconomy::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
   598
	SetDParam(1, avi->max_speed * 10 / 16);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   599
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   600
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   601
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   602
	/* Cargo capacity */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   603
	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
   604
	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
   605
		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
   606
		SetDParam(1, avi->mail_capacity);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   607
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   608
	} else {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   609
		/* 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
   610
		* 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
   611
		SetDParam(0, cargo);
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6383
diff changeset
   612
		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
   613
		SetDParam(2, STR_9842_REFITTABLE);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   614
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   615
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   616
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   617
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   618
	/* Running cost */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   619
	SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _eco->GetPrice(CEconomy::AIRCRAFT_RUNNING) >> 8);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   620
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   621
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   622
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   623
	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
   624
}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   625
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   626
/**
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   627
 * 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
   628
 * @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
   629
 * @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
   630
 * @param engine_number the engine of which to draw the info of
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   631
 * @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
   632
 */
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   633
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
   634
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   635
	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
   636
	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
   637
	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
   638
	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
   639
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   640
	switch (e->type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   641
		default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   642
		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
   643
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   644
			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
   645
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   646
			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
   647
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
   648
			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
   649
				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
   650
			} else {
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   651
				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
   652
			}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   653
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   654
			/* Cargo type + capacity, or N/A */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   655
			if (rvi->capacity == 0) {
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   656
				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
   657
				SetDParam(2, STR_EMPTY);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   658
			} else {
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
   659
				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
6066
917bc7592745 (svn r8377) -Fix (r8331): [build vehicle window] train cargo capacity now only add "(refitable)" if the engine in question is refitable
bjarni
parents: 6053
diff changeset
   660
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   661
				SetDParam(0, rvi->cargo_type);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   662
				SetDParam(1, (capacity * (CountArticulatedParts(engine_number) + 1)) << multihead);
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
   663
				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   664
			}
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
   665
			DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 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
   666
			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
   667
		}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   668
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   669
		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
   670
			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
   671
			refitable = true;
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   672
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   673
		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
   674
			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
   675
			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
   676
			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
   677
		} break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   678
		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
   679
			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
   680
			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
   681
			break;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   682
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   683
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   684
	/* Draw details, that applies to all types except rail wagons */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   685
	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
   686
		/* 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
   687
		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
   688
		SetDParam(1, e->lifelength);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   689
		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   690
		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
   691
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   692
		/* Reliability */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   693
		SetDParam(0, e->reliability * 100 >> 16);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   694
		DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   695
		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
   696
	}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   697
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   698
	/* 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
   699
	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
   700
	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   701
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   702
	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
   703
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   704
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   705
/* Figure out what train EngineIDs to put in the list */
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   706
static void GenerateBuildTrainList(Window *w)
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   707
{
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   708
	EngineID eid, sel_id;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   709
	int num_engines = 0;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   710
	int num_wagons  = 0;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   711
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   712
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   713
	bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   714
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   715
	EngList_RemoveAll(&bv->eng_list);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   716
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   717
	/* Make list of all available train engines and wagons.
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   718
	 * Also check to see if the previously selected engine is still available,
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   719
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   720
	 * when engines become obsolete and are removed */
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   721
	for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   722
		const RailVehicleInfo *rvi = RailVehInfo(eid);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   723
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6073
diff changeset
   724
		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   725
		if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   726
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   727
		EngList_Add(&bv->eng_list, eid);
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
   728
		if (rvi->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
   729
			num_engines++;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   730
		} else {
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   731
			num_wagons++;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   732
		}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   733
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   734
		if (eid == bv->sel_engine) sel_id = eid;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   735
	}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   736
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   737
	bv->sel_engine = sel_id;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   738
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   739
	/* make engines first, and then wagons, sorted by ListPositionOfEngine() */
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   740
	_internal_sort_order = false;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   741
	EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   742
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   743
	/* and then sort engines */
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   744
	_internal_sort_order = bv->descending_sort_order;
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
   745
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], 0, num_engines);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   746
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   747
	/* and finally sort wagons */
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
   748
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], num_engines, num_wagons);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   749
}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   750
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   751
/* Figure out what road vehicle EngineIDs to put in the list */
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   752
static void GenerateBuildRoadVehList(Window *w)
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   753
{
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   754
	EngineID eid, sel_id;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   755
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   756
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   757
	EngList_RemoveAll(&bv->eng_list);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   758
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   759
	sel_id = INVALID_ENGINE;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   760
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   761
	for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   762
		if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   763
		if (!HASBIT(bv->filter.roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   764
		EngList_Add(&bv->eng_list, eid);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   765
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   766
		if (eid == bv->sel_engine) sel_id = eid;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   767
	}
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   768
	bv->sel_engine = sel_id;
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   769
}
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   770
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   771
/* Figure out what ship EngineIDs to put in the list */
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   772
static void GenerateBuildShipList(Window *w)
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   773
{
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   774
	EngineID eid, sel_id;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   775
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   776
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   777
	EngList_RemoveAll(&bv->eng_list);
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   778
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   779
	sel_id = INVALID_ENGINE;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   780
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   781
	for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   782
		if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   783
		EngList_Add(&bv->eng_list, eid);
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   784
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   785
		if (eid == bv->sel_engine) sel_id = eid;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   786
	}
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   787
	bv->sel_engine = sel_id;
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   788
}
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   789
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   790
/* Figure out what aircraft EngineIDs to put in the list */
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   791
static void GenerateBuildAircraftList(Window *w)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   792
{
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   793
	EngineID eid, sel_id;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   794
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   795
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   796
	EngList_RemoveAll(&bv->eng_list);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   797
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   798
	/* Make list of all available planes.
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   799
	 * Also check to see if the previously selected plane is still available,
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   800
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   801
	 * when planes become obsolete and are removed */
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   802
	sel_id = INVALID_ENGINE;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   803
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   804
		if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   805
		if (w->window_number != 0 && !IsAircraftBuildableAtStation(eid, w->window_number)) continue;
6370
c0266faf1722 (svn r8771) -Fix r8343: build aircraft windows will no longer show aircraft that can't use the airport in question
bjarni
parents: 6358
diff changeset
   806
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   807
		EngList_Add(&bv->eng_list, eid);
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   808
		if (eid == bv->sel_engine) sel_id = eid;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   809
	}
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   810
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   811
	bv->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
   812
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   813
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   814
/* Generate the list of vehicles */
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   815
static void GenerateBuildList(Window *w)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   816
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   817
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   818
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   819
	switch (bv->vehicle_type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   820
		default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   821
		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
   822
			GenerateBuildTrainList(w);
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
   823
			return; // trains should not reach the last sorting
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   824
		case VEH_ROAD:
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   825
			GenerateBuildRoadVehList(w);
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   826
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   827
		case VEH_SHIP:
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   828
			GenerateBuildShipList(w);
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   829
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   830
		case VEH_AIRCRAFT:
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   831
			GenerateBuildAircraftList(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   832
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   833
	}
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
   834
	_internal_sort_order = bv->descending_sort_order;
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
   835
	EngList_Sort(&bv->eng_list, _sorter[bv->vehicle_type][bv->sort_criteria]);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   836
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   837
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
   838
static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal)
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   839
{
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   840
	switch (type) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   841
		case VEH_TRAIN:    DrawTrainEngine(   x, y, engine, pal); break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   842
		case VEH_ROAD:     DrawRoadVehEngine( x, y, engine, pal); break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   843
		case VEH_SHIP:     DrawShipEngine(    x, y, engine, pal); break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   844
		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
   845
		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
   846
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   847
}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   848
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   849
/** 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
   850
 * @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
   851
 * @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
   852
 * @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
   853
 * @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
   854
 * @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
   855
 * @param selected_id what engine to highlight as selected, if any
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   856
 * @param show_count Display the number of vehicles (used by autoreplace)
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
   857
 */
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   858
void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, 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
   859
{
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   860
	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
   861
	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
   862
	byte y_offset = 0;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   863
	Player *p = GetPlayer(_local_player);
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
   864
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
   865
	assert(max <= EngList_Count(&eng_list));
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
   866
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
   867
	switch (type) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   868
		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
   869
			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
   870
			/* Fallthough */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   871
		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
   872
			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
   873
			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
   874
			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
   875
			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
   876
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   877
		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
   878
			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
   879
			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
   880
			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
   881
			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
   882
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   883
		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
   884
			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
   885
			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
   886
			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
   887
			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
   888
			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
   889
		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
   890
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   891
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   892
	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
   893
		const EngineID engine = eng_list[min];
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   894
		const uint num_engines = IsDefaultGroupID(selected_group) ? p->num_engines[engine] : GetGroup(selected_group)->num_engines[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
   895
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   896
		DrawString(x + x_offset, y, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   897
		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   898
		if (show_count) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   899
			SetDParam(0, num_engines);
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   900
			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, 0);
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6144
diff changeset
   901
		}
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
   902
	}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   903
}
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   904
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   905
static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   906
{
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   907
	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   908
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   909
	SetWindowDirty(w);
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   910
	wi->bottom += expand_by;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   911
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   912
	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   913
		wi = &w->widget[i];
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   914
		wi->top += expand_by;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   915
		wi->bottom += expand_by;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   916
	}
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   917
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   918
	w->height += expand_by;
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   919
	SetWindowDirty(w);
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   920
}
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   921
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   922
static void DrawBuildVehicleWindow(Window *w)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   923
{
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   924
	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
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
   925
	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   926
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   927
	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   928
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   929
	SetVScrollCount(w, EngList_Count(&bv->eng_list));
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   930
	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   931
	DrawWindowWidgets(w);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   932
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   933
	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false, DEFAULT_GROUP);
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   934
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
   935
	if (bv->sel_engine != INVALID_ENGINE) {
3fdc90c44643 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 6041
diff changeset
   936
		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   937
		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   938
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
   939
		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
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
   940
	}
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   941
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
   942
	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
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
   943
	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   944
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   945
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   946
static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   947
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   948
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   949
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   950
	switch (e->we.click.widget) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   951
		case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   952
			bv->descending_sort_order ^= true;
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
   953
			_last_sort_order[bv->vehicle_type] = bv->descending_sort_order;
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
   954
			bv->regenerate_list = true;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   955
			SetWindowDirty(w);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   956
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   957
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   958
		case BUILD_VEHICLE_WIDGET_LIST: {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   959
			uint i = (e->we.click.pt.y - 26) / GetVehicleListHeight(bv->vehicle_type) + w->vscroll.pos;
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   960
			uint num_items = EngList_Count(&bv->eng_list);
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   961
			bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   962
			SetWindowDirty(w);
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   963
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   964
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   965
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   966
		case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
   967
			ShowDropDownMenu(w, _sort_listing[bv->vehicle_type], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
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
   968
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   969
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   970
		case BUILD_VEHICLE_WIDGET_BUILD: {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   971
			EngineID sel_eng = bv->sel_engine;
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   972
			if (sel_eng != INVALID_ENGINE) {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   973
				switch (bv->vehicle_type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   974
					default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   975
					case VEH_TRAIN:
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
   976
						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   977
								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   978
						break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   979
					case VEH_ROAD:
6037
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   980
						DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
7409c8f581e1 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 6036
diff changeset
   981
						break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   982
					case VEH_SHIP:
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   983
						DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
   984
						break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
   985
					case VEH_AIRCRAFT:
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   986
						DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   987
						break;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   988
				}
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   989
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   990
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   991
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   992
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   993
		case BUILD_VEHICLE_WIDGET_RENAME: {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   994
			EngineID sel_eng = bv->sel_engine;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   995
			if (sel_eng != INVALID_ENGINE) {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   996
				StringID str = STR_NULL;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   997
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   998
				bv->rename_engine = sel_eng;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
   999
				switch (bv->vehicle_type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1000
					default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1001
					case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1002
					case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1003
					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1004
					case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      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
  1005
				}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1006
				ShowQueryString(GetCustomEngineName(sel_eng), str, 31, 160, w, CS_ALPHANUMERAL);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1007
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1008
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1009
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1010
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1011
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1012
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1013
static void NewVehicleWndProc(Window *w, WindowEvent *e)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1014
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1015
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1016
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1017
	switch (e->event) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1018
		case WE_INVALIDATE_DATA:
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1019
			bv->regenerate_list = true;
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1020
			SetWindowDirty(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1021
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1022
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1023
		case WE_DESTROY:
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1024
			EngList_Destroy(&bv->eng_list);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1025
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1026
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1027
		case WE_PAINT:
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1028
			if (bv->regenerate_list) {
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1029
				bv->regenerate_list = false;
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1030
				GenerateBuildList(w);
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1031
			}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1032
			DrawBuildVehicleWindow(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1033
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1034
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1035
		case WE_CLICK:
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1036
			BuildVehicleClickEvent(w, e);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1037
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1038
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1039
		case WE_ON_EDIT_TEXT: {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1040
			if (e->we.edittext.str[0] != '\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
  1041
				StringID str = 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
  1042
				_cmd_text = e->we.edittext.str;
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1043
				switch (bv->vehicle_type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1044
					default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1045
					case VEH_TRAIN:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1046
					case VEH_ROAD:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1047
					case VEH_SHIP:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1048
					case VEH_AIRCRAFT: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; 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
  1049
				}
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1050
				DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(str));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1051
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1052
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1053
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1054
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1055
		case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1056
			if (bv->sort_criteria != e->we.dropdown.index) {
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1057
				bv->sort_criteria = e->we.dropdown.index;
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
  1058
				_last_sort_criteria[bv->vehicle_type] = bv->sort_criteria;
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1059
				bv->regenerate_list = true;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1060
			}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1061
			SetWindowDirty(w);
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1062
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1063
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1064
		case WE_RESIZE:
6075
33cdb35f9af5 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 6074
diff changeset
  1065
			if (e->we.sizing.diff.x != 0) ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1066
			if (e->we.sizing.diff.y == 0) break;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1067
6352
e2074b537a6d (svn r8749) -Regression r8331: fixed signed/unsigned issue that could create too many lines in build vehicle windows and crash the game
bjarni
parents: 6350
diff changeset
  1068
			w->vscroll.cap += e->we.sizing.diff.y / (int)GetVehicleListHeight(bv->vehicle_type);
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1069
			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1070
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1071
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1072
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1073
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1074
static const WindowDesc _build_vehicle_desc = {
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
  1075
	WDP_AUTO, WDP_AUTO, 240, 256,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6125
diff changeset
  1076
	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
  1077
	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
  1078
	_build_vehicle_widgets,
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1079
	NewVehicleWndProc
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1080
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1081
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1082
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
  1083
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1084
	buildvehicle_d *bv;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1085
	Window *w;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1086
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1087
	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
  1088
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1089
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1090
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1091
	w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
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
	if (w == NULL) return;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1094
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
  1095
	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1096
	w->resize.step_height = GetVehicleListHeight(type);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1097
	w->vscroll.cap = w->resize.step_height == 24 ? 4 : 8;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1098
	w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1099
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1100
	bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1101
	EngList_Create(&bv->eng_list);
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1102
	bv->sel_engine      = INVALID_ENGINE;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1103
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1104
	bv->vehicle_type    = type;
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1105
	bv->regenerate_list = false;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1106
6206
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
  1107
	bv->sort_criteria         = _last_sort_criteria[type];
67358999d80d (svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents: 6195
diff changeset
  1108
	bv->descending_sort_order = _last_sort_order[type];
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
  1109
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1110
	switch (type) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1111
		default: NOT_REACHED();
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1112
		case VEH_TRAIN:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9907
diff changeset
  1113
			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1114
			ResizeWindow(w, 0, 16);
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1115
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1116
		case VEH_ROAD:
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1117
			WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
9907
3b068c3a1c74 (svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
celestar
parents: 9903
diff changeset
  1118
			ResizeWindow(w, 0, 16);
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1119
		case VEH_SHIP:
6034
89a7d10fa75b (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 6033
diff changeset
  1120
			break;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6519
diff changeset
  1121
		case VEH_AIRCRAFT:
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6349
diff changeset
  1122
			bv->filter.flags =
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6352
diff changeset
  1123
				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1124
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1125
	}
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1126
	SetupWindowStrings(w, type);
6075
33cdb35f9af5 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 6074
diff changeset
  1127
	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1128
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1129
	w->resize.width  = w->width;
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1130
	w->resize.height = w->height;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1131
6032
cc75c53d40e9 (svn r8333) -Codechange: when invalidating a build window list, set a flag instead of rebuilding the list and then rebuild it the next time it's redrawn
bjarni
parents: 6031
diff changeset
  1132
	GenerateBuildList(w); // generate the list, since we need it in the next line
6030
70686dbed756 (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5919
diff changeset
  1133
	/* Select the first engine in the list as default when opening the window */
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
  1134
	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1135
}