src/build_vehicle_gui.cpp
author skidd13
Mon, 19 Nov 2007 21:02:30 +0000
changeset 7928 63e18de69e50
parent 7824 5a63d41b59ea
child 7997 df87ccd00a96
permissions -rw-r--r--
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     1
/* $Id$ */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     2
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
     3
/** @file build_vehicle_gui.cpp */
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
     4
4800
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
     7
#include "train.h"
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
     8
#include "roadveh.h"
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
     9
#include "ship.h"
4800
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
6772
8672ba1bebc9 (svn r10008) -Codechange: Move a couple of functions related to articulated vehicles to a file of their own.
maedhros
parents: 6685
diff changeset
    18
#include "articulated_vehicles.h"
4800
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
5afc1bfc7a85 (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"
6091
c8827d9ae04a (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: 6087
diff changeset
    30
#include "cargotype.h"
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
    31
#include "group.h"
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6643
diff changeset
    32
#include "road_map.h"
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    33
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    34
5273
d9f707aa36a6 (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
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
5afc1bfc7a85 (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,
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
    47
	BUILD_VEHICLE_WIDGET_END
5273
d9f707aa36a6 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    48
};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    49
5afc1bfc7a85 (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[] = {
5afc1bfc7a85 (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 },
6386
bc26d1d67aa2 (svn r9476) -Codechange: Make build windows for all vehicle types the same width.
maedhros
parents: 6385
diff changeset
    52
	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
4800
5afc1bfc7a85 (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},
6386
bc26d1d67aa2 (svn r9476) -Codechange: Make build windows for all vehicle types the same width.
maedhros
parents: 6385
diff changeset
    54
	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
bc26d1d67aa2 (svn r9476) -Codechange: Make build windows for all vehicle types the same width.
maedhros
parents: 6385
diff changeset
    55
	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
7368
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    56
	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,    39, 0x101,                   STR_NULL },
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    57
	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,    39, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    58
	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,    40,   161, 0x0,                     STR_NULL },
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    59
7368
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    60
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   162,   173, 0x0,                     STR_NULL },
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    61
	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   162,   173, 0x0,                     STR_NULL },
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
    62
	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   162,   173, 0x0,                     STR_RESIZE_BUTTON },
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    63
	{   WIDGETS_END},
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    64
};
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    65
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    66
/* Setup widget strings to fit the different types of vehicles */
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
    67
static void SetupWindowStrings(Window *w, byte type)
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    68
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    69
	switch (type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
    70
		case VEH_TRAIN:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    71
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_JUST_STRING;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    72
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_8843_TRAIN_VEHICLE_SELECTION;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    73
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_881F_BUILD_VEHICLE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    74
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    75
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_8820_RENAME;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    76
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_8845_RENAME_TRAIN_VEHICLE_TYPE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    77
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
    78
		case VEH_ROAD:
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    79
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9006_NEW_ROAD_VEHICLES;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    80
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9026_ROAD_VEHICLE_SELECTION;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    81
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9007_BUILD_VEHICLE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    82
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9027_BUILD_THE_HIGHLIGHTED_ROAD;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    83
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9034_RENAME;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    84
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9035_RENAME_ROAD_VEHICLE_TYPE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
    85
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
    86
		case VEH_SHIP:
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    87
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_9808_NEW_SHIPS;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    88
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_9825_SHIP_SELECTION_LIST_CLICK;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    89
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_9809_BUILD_SHIP;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    90
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_9826_BUILD_THE_HIGHLIGHTED_SHIP;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    91
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_9836_RENAME;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    92
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_9837_RENAME_SHIP_TYPE;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
    93
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
    94
		case VEH_AIRCRAFT:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    95
			w->widget[BUILD_VEHICLE_WIDGET_CAPTION].data    = STR_A005_NEW_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    96
			w->widget[BUILD_VEHICLE_WIDGET_LIST].tooltips   = STR_A025_AIRCRAFT_SELECTION_LIST;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    97
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].data      = STR_A006_BUILD_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    98
			w->widget[BUILD_VEHICLE_WIDGET_BUILD].tooltips  = STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
    99
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].data     = STR_A037_RENAME;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   100
			w->widget[BUILD_VEHICLE_WIDGET_RENAME].tooltips = STR_A038_RENAME_AIRCRAFT_TYPE;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   101
			break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   102
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   103
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   104
4800
5afc1bfc7a85 (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
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   106
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   107
static byte _last_sort_criteria[]    = {0, 0, 0, 0};
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
   108
static bool _last_sort_order[]       = {false, false, false, false};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   109
5afc1bfc7a85 (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)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   111
{
5afc1bfc7a85 (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;
5afc1bfc7a85 (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;
5afc1bfc7a85 (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;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   115
5afc1bfc7a85 (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;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   117
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   118
5afc1bfc7a85 (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)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   120
{
5afc1bfc7a85 (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;
5afc1bfc7a85 (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;
5afc1bfc7a85 (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;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   124
5afc1bfc7a85 (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) {
5afc1bfc7a85 (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 */
5afc1bfc7a85 (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);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   128
	}
5afc1bfc7a85 (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;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   130
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   131
5afc1bfc7a85 (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)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   133
{
4804
bfa7a5b5ad15 (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 };
bfa7a5b5ad15 (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" };
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   136
4800
5afc1bfc7a85 (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;
5afc1bfc7a85 (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;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   139
	int r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   140
4804
bfa7a5b5ad15 (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]) {
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   142
		last_engine[0] = va;
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   143
		SetDParam(0, va);
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   144
		GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   145
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   146
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   147
	if (vb != last_engine[1]) {
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   148
		last_engine[1] = vb;
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   149
		SetDParam(0, vb);
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   150
		GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   151
	}
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   152
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   153
	r = strcmp(last_name[0], last_name[1]); // sort by name
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   154
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   155
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   156
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   157
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   158
	}
4804
bfa7a5b5ad15 (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   159
	return _internal_sort_order ? -r : r;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   160
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   161
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   162
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   163
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   164
	const int va = GetEngine(*(const EngineID*)a)->reliability;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   165
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   166
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   167
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   168
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   169
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   170
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   171
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   172
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   173
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   174
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   175
/* Train sorting functions */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   176
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   177
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   178
	int va = RailVehInfo(*(const EngineID*)a)->base_cost;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   179
	int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   180
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   181
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   182
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   183
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   184
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   185
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   186
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   187
	int va = RailVehInfo(*(const EngineID*)a)->max_speed;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   188
	int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   189
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   190
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   191
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   192
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   193
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   194
static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   195
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   196
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   197
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   198
5868
94430141c189 (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: 5824
diff changeset
   199
	int va = rvi_a->power << (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
94430141c189 (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: 5824
diff changeset
   200
	int vb = rvi_b->power << (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   201
	int r = va - vb;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   202
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   203
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   204
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   205
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   206
static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   207
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   208
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   209
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   210
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6787
diff changeset
   211
	Money va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6787
diff changeset
   212
	Money vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6787
diff changeset
   213
	int r = ClampToI32(va - vb);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   214
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   215
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   216
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   217
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   218
static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   219
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   220
	const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   221
	const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   222
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   223
	/* Here we are using a few tricks to get the right sort.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   224
		* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   225
		* we will actually calculate cunning cost/power (to make it more than 1).
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   226
		* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   227
		* Another thing is that both power and running costs should be doubled for multiheaded engines.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   228
		* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7683
diff changeset
   229
	Money va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1U, (uint)rvi_a->power);
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7683
diff changeset
   230
	Money vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1U, (uint)rvi_b->power);
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6787
diff changeset
   231
	int r = ClampToI32(vb - va);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   232
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   233
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   234
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   235
6023
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   236
static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   237
{
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   238
	const EngineID va = *(const EngineID*)a;
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   239
	const EngineID vb = *(const EngineID*)b;
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   240
	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   241
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   242
	return _internal_sort_order ? -r : r;
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   243
}
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   244
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   245
static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   246
{
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   247
	int va = RailVehInfo(*(const EngineID*)a)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   248
	int vb = RailVehInfo(*(const EngineID*)b)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   249
	int r = va - vb;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   250
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   251
	if (r == 0) {
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   252
		/* Use EngineID to sort instead since we want consistent sorting */
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   253
		return EngineNumberSorter(a, b);
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   254
	}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   255
	return _internal_sort_order ? -r : r;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   256
}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   257
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   258
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   259
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   260
	EngineID va = *(const EngineID*)a;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   261
	EngineID vb = *(const EngineID*)b;
5871
a98c86408de4 (svn r8460) -Fix (r8455): the build train window put locomotives and wagons in appeantly random order
bjarni
parents: 5868
diff changeset
   262
	int val_a = (RailVehInfo(va)->railveh_type == RAILVEH_WAGON ? 1 : 0);
a98c86408de4 (svn r8460) -Fix (r8455): the build train window put locomotives and wagons in appeantly random order
bjarni
parents: 5868
diff changeset
   263
	int val_b = (RailVehInfo(vb)->railveh_type == RAILVEH_WAGON ? 1 : 0);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   264
	int r = val_a - val_b;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   265
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   266
	/* Use EngineID to sort instead since we want consistent sorting */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   267
	if (r == 0) return EngineNumberSorter(a, b);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   268
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   269
	return _internal_sort_order ? -r : r;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   270
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   271
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   272
static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   273
{
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   274
	int va = RoadVehInfo(*(const EngineID*)a)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   275
	int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   276
	int r = va - vb;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   277
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   278
	if (r == 0) {
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   279
		/* Use EngineID to sort instead since we want consistent sorting */
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   280
		return EngineNumberSorter(a, b);
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   281
	}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   282
	return _internal_sort_order ? -r : r;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   283
}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   284
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   285
static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   286
{
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   287
	int va = ShipVehInfo(*(const EngineID*)a)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   288
	int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   289
	int r = va - vb;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   290
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   291
	if (r == 0) {
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   292
		/* Use EngineID to sort instead since we want consistent sorting */
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   293
		return EngineNumberSorter(a, b);
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   294
	}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   295
	return _internal_sort_order ? -r : r;
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   296
}
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   297
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   298
/* Aircraft sorting functions */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   299
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   300
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   301
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   302
	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   303
	const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   304
	int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   305
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   306
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   307
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   308
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   309
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   310
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   311
	const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   312
	const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   313
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   314
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   315
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   316
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   317
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   318
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   319
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   320
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   321
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   322
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   323
{
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   324
	const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   325
	const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   326
	const int r = va - vb;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   327
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   328
	if (r == 0) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   329
		/* Use EngineID to sort instead since we want consistent sorting */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   330
		return EngineNumberSorter(a, b);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   331
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   332
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   333
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   334
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   335
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   336
{
6787
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   337
	int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   338
	int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   339
	int r = va - vb;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   340
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   341
	if (r == 0) {
6787
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   342
		/* The planes has the same passenger capacity. Check mail capacity instead */
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   343
		va = AircraftVehInfo(*(const EngineID*)a)->mail_capacity;
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   344
		vb = AircraftVehInfo(*(const EngineID*)b)->mail_capacity;
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   345
		r = va - vb;
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   346
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   347
		if (r == 0) {
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   348
			/* Use EngineID to sort instead since we want consistent sorting */
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   349
			return EngineNumberSorter(a, b);
47f6921e8c4c (svn r10025) -Fix: [build windows] sorting planes for capacity didn't check mail capacity. Now mail capacity is used if passenger capacity is the same
bjarni
parents: 6786
diff changeset
   350
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   351
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   352
	return _internal_sort_order ? -r : r;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   353
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   354
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   355
static EngList_SortTypeFunction * const _sorter[][10] = {{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   356
	/* Trains */
6023
0ef69a935adc (svn r8746) -Regression r8331: build train window could sort incorrectly by EngineID with certain newGRF sets
bjarni
parents: 5955
diff changeset
   357
	&TrainEngineNumberSorter,
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   358
	&TrainEngineCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   359
	&TrainEngineSpeedSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   360
	&TrainEnginePowerSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   361
	&EngineIntroDateSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   362
	&EngineNameSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   363
	&TrainEngineRunningCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   364
	&TrainEnginePowerVsRunningCostSorter,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   365
	&EngineReliabilitySorter,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   366
	&TrainEngineCapacitySorter,
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   367
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   368
	/* Road vehicles */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   369
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   370
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   371
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   372
	&EngineReliabilitySorter,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   373
	&RoadVehEngineCapacitySorter,
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   374
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   375
	/* Ships */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   376
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   377
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   378
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   379
	&EngineReliabilitySorter,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   380
	&ShipEngineCapacitySorter,
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   381
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   382
	/* Aircraft */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   383
	&EngineNumberSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   384
	&AircraftEngineCostSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   385
	&AircraftEngineSpeedSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   386
	&EngineIntroDateSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   387
	&EngineNameSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   388
	&AircraftEngineRunningCostSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   389
	&EngineReliabilitySorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   390
	&AircraftEngineCargoSorter,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   391
}};
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   392
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   393
static const StringID _sort_listing[][11] = {{
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   394
	/* Trains */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   395
	STR_ENGINE_SORT_ENGINE_ID,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   396
	STR_ENGINE_SORT_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   397
	STR_SORT_BY_MAX_SPEED,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   398
	STR_ENGINE_SORT_POWER,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   399
	STR_ENGINE_SORT_INTRO_DATE,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   400
	STR_SORT_BY_DROPDOWN_NAME,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   401
	STR_ENGINE_SORT_RUNNING_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   402
	STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   403
	STR_SORT_BY_RELIABILITY,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   404
	STR_ENGINE_SORT_CARGO_CAPACITY,
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   405
	INVALID_STRING_ID
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   406
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   407
	/* Road vehicles */
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   408
	STR_ENGINE_SORT_ENGINE_ID,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   409
	STR_ENGINE_SORT_INTRO_DATE,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   410
	STR_SORT_BY_DROPDOWN_NAME,
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   411
	STR_SORT_BY_RELIABILITY,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   412
	STR_ENGINE_SORT_CARGO_CAPACITY,
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   413
	INVALID_STRING_ID
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   414
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   415
	/* Ships */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   416
	STR_ENGINE_SORT_ENGINE_ID,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   417
	STR_ENGINE_SORT_INTRO_DATE,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   418
	STR_SORT_BY_DROPDOWN_NAME,
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   419
	STR_SORT_BY_RELIABILITY,
6786
f938f80a255f (svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
bjarni
parents: 6772
diff changeset
   420
	STR_ENGINE_SORT_CARGO_CAPACITY,
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   421
	INVALID_STRING_ID
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
   422
}, {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   423
	/* Aircraft */
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   424
	STR_ENGINE_SORT_ENGINE_ID,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   425
	STR_ENGINE_SORT_COST,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   426
	STR_SORT_BY_MAX_SPEED,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   427
	STR_ENGINE_SORT_INTRO_DATE,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   428
	STR_SORT_BY_DROPDOWN_NAME,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   429
	STR_ENGINE_SORT_RUNNING_COST,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   430
	STR_SORT_BY_RELIABILITY,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   431
	STR_ENGINE_SORT_CARGO_CAPACITY,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   432
	INVALID_STRING_ID
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   433
}};
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   434
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   435
/* Draw rail wagon specific details */
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   436
static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   437
{
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   438
	/* Purchase cost */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   439
	SetDParam(0, (GetEngineProperty(engine_number, 0x17, rvi->base_cost) * _price.build_railwagon) >> 8);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   440
	DrawString(x, y, STR_PURCHASE_INFO_COST, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   441
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   442
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   443
	/* Wagon weight - (including cargo) */
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   444
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   445
	SetDParam(0, weight);
6608
dc0b009642a4 (svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138
parents: 6595
diff changeset
   446
	SetDParam(1, (GetCargo(rvi->cargo_type)->weight * GetEngineProperty(engine_number, 0x14, rvi->capacity) >> 4) + weight);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   447
	DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   448
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   449
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   450
	/* Wagon speed limit, displayed if above zero */
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   451
	if (_patches.wagon_speed_limits) {
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   452
		uint max_speed = GetEngineProperty(engine_number, 0x09, rvi->max_speed);
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   453
		if (max_speed > 0) {
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   454
			SetDParam(0, max_speed * 10 / 16);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   455
			DrawString(x, y, STR_PURCHASE_INFO_SPEED, TC_FROMSTRING);
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   456
			y += 10;
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   457
		}
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   458
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   459
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   460
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   461
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   462
/* Draw locomotive specific details */
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5822
diff changeset
   463
static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   464
{
5868
94430141c189 (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: 5824
diff changeset
   465
	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   466
	uint weight = GetEngineProperty(engine_number, 0x16, rvi->weight);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   467
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   468
	/* Purchase Cost - Engine weight */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   469
	SetDParam(0, GetEngineProperty(engine_number, 0x17, rvi->base_cost) * (_price.build_railvehicle >> 3) >> 5);
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   470
	SetDParam(1, weight << multihead);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   471
	DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   472
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   473
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   474
	/* Max speed - Engine power */
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   475
	SetDParam(0, GetEngineProperty(engine_number, 0x09, rvi->max_speed) * 10 / 16);
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   476
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, rvi->power) << multihead);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   477
	DrawString(x, y, STR_PURCHASE_INFO_SPEED_POWER, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   478
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   479
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   480
	/* Max tractive effort - not applicable if old acceleration or maglev */
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5822
diff changeset
   481
	if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) {
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   482
		SetDParam(0, ((weight << multihead) * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   483
		DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   484
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   485
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   486
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   487
	/* Running cost */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   488
	SetDParam(0, (GetEngineProperty(engine_number, 0x0D, rvi->running_cost_base) * _price.running_rail[rvi->running_cost_class] >> 8) << multihead);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   489
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   490
	y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   491
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   492
	/* Powered wagons power - Powered wagons extra weight */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   493
	if (rvi->pow_wag_power != 0) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   494
		SetDParam(0, rvi->pow_wag_power);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   495
		SetDParam(1, rvi->pow_wag_weight);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   496
		DrawString(x, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   497
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   498
	};
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   499
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   500
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   501
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   502
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   503
/* Draw road vehicle specific details */
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   504
static int DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number, const RoadVehicleInfo *rvi)
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   505
{
7273
6cbc9e849d99 (svn r10603) -Codechange: avoid direct access to _engine_info
peter1138
parents: 7258
diff changeset
   506
	bool refittable = (EngInfo(engine_number)->refit_mask != 0);
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   507
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   508
	/* Purchase cost - Max speed */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   509
	SetDParam(0, GetEngineProperty(engine_number, 0x11, rvi->base_cost) * (_price.roadveh_base >> 3) >> 5);
5874
2db89a640b7a (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: 5871
diff changeset
   510
	SetDParam(1, rvi->max_speed * 10 / 32);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   511
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   512
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   513
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   514
	/* Running cost */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   515
	SetDParam(0, rvi->running_cost * _price.roadveh_running >> 8);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   516
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   517
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   518
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   519
	/* Cargo type + capacity */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   520
	SetDParam(0, rvi->cargo_type);
6608
dc0b009642a4 (svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138
parents: 6595
diff changeset
   521
	SetDParam(1, GetEngineProperty(engine_number, 0x0F, rvi->capacity));
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   522
	SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   523
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   524
	y += 10;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   525
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   526
	return y;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   527
}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   528
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   529
/* Draw ship specific details */
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   530
static int DrawShipPurchaseInfo(int x, int y, EngineID engine_number, const ShipVehicleInfo *svi)
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   531
{
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   532
	/* Purchase cost - Max speed */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   533
	SetDParam(0, GetEngineProperty(engine_number, 0x0A, svi->base_cost) * (_price.ship_base >> 3) >> 5);
6595
5239d6e72066 (svn r9809) -Codechange: [NewGRF] Add callback 36 properties to purchase lists and add running cost changing for ships.
peter1138
parents: 6592
diff changeset
   534
	SetDParam(1, GetEngineProperty(engine_number, 0x0B, svi->max_speed) * 10 / 32);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   535
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   536
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   537
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   538
	/* Cargo type + capacity */
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   539
	SetDParam(0, svi->cargo_type);
6608
dc0b009642a4 (svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138
parents: 6595
diff changeset
   540
	SetDParam(1, GetEngineProperty(engine_number, 0x0D, svi->capacity));
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   541
	SetDParam(2, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   542
	DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   543
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   544
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   545
	/* Running cost */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   546
	SetDParam(0, GetEngineProperty(engine_number, 0x0F, svi->running_cost) * _price.ship_running >> 8);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   547
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   548
	y += 10;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   549
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   550
	return y;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   551
}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   552
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   553
/* Draw aircraft specific details */
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   554
static int DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number, const AircraftVehicleInfo *avi)
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   555
{
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   556
	CargoID cargo;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   557
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   558
	/* Purchase cost - Max speed */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   559
	SetDParam(0, GetEngineProperty(engine_number, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5);
6193
6f20de9e4f1b (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: 6123
diff changeset
   560
	SetDParam(1, avi->max_speed * 10 / 16);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   561
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, TC_FROMSTRING);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   562
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   563
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   564
	/* Cargo capacity */
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   565
	cargo = FindFirstRefittableCargo(engine_number);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   566
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   567
		SetDParam(0, avi->passenger_capacity);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   568
		SetDParam(1, avi->mail_capacity);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   569
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, TC_FROMSTRING);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   570
	} else {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   571
		/* Note, if the default capacity is selected by the refit capacity
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   572
		* callback, then the capacity shown is likely to be incorrect. */
4896
f86350aaaaa5 (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
   573
		SetDParam(0, cargo);
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6057
diff changeset
   574
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, avi));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   575
		SetDParam(2, STR_9842_REFITTABLE);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   576
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   577
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   578
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   579
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   580
	/* Running cost */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   581
	SetDParam(0, GetEngineProperty(engine_number, 0x0E, avi->running_cost) * _price.aircraft_running >> 8);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   582
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, TC_FROMSTRING);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   583
	y += 10;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   584
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   585
	return y;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   586
}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   587
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   588
/**
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   589
 * Draw the purchase info details of a vehicle at a given location.
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   590
 * @param x,y location where to draw the info
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   591
 * @param w how wide are the text allowed to be (size of widget/window to Draw in)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   592
 * @param engine_number the engine of which to draw the info of
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   593
 * @return y after drawing all the text
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   594
 */
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   595
int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   596
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   597
	const Engine *e = GetEngine(engine_number);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   598
	YearMonthDay ymd;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   599
	ConvertDateToYMD(e->intro_date, &ymd);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   600
	bool refitable = false;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   601
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   602
	switch (e->type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
   603
		default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   604
		case VEH_TRAIN: {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   605
			const RailVehicleInfo *rvi = RailVehInfo(engine_number);
6608
dc0b009642a4 (svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138
parents: 6595
diff changeset
   606
			uint capacity = GetEngineProperty(engine_number, 0x14, rvi->capacity);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   607
6608
dc0b009642a4 (svn r9828) -Codechange: [NewGRF] Add support for changing cargo capacity with callback 36. This is set on construction for ships and roadvehicles, and whenever carriages are attached for trains.
peter1138
parents: 6595
diff changeset
   608
			refitable = (EngInfo(engine_number)->refit_mask != 0) && (capacity > 0);
5819
77fa0b7a6065 (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: 5817
diff changeset
   609
5868
94430141c189 (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: 5824
diff changeset
   610
			if (rvi->railveh_type == RAILVEH_WAGON) {
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   611
				y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   612
			} else {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5822
diff changeset
   613
				y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   614
			}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   615
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   616
			/* Cargo type + capacity, or N/A */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   617
			if (rvi->capacity == 0) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   618
				SetDParam(0, CT_INVALID);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   619
				SetDParam(2, STR_EMPTY);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   620
			} else {
5868
94430141c189 (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: 5824
diff changeset
   621
				int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
5815
1af8b7c2f257 (svn r8377) -Fix (r8331): [build vehicle window] train cargo capacity now only add "(refitable)" if the engine in question is refitable
bjarni
parents: 5802
diff changeset
   622
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   623
				SetDParam(0, rvi->cargo_type);
7595
9d645518f001 (svn r11122) -Fix [FS#1234]: crash when building a NewGRF vehicle when the articulated build vehicle callback returneed a different value for the purchase window than the normal build. Thanks for Dalestan and _minime_ for pointers to possible causes.
rubidium
parents: 7481
diff changeset
   624
				SetDParam(1, (capacity * (CountArticulatedParts(engine_number, true) + 1)) << multihead);
5819
77fa0b7a6065 (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: 5817
diff changeset
   625
				SetDParam(2, refitable ? STR_9842_REFITTABLE : STR_EMPTY);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   626
			}
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   627
			DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   628
			y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   629
		}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   630
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   631
		case VEH_ROAD:
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   632
			y = DrawRoadVehPurchaseInfo(x, y, engine_number, RoadVehInfo(engine_number));
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   633
			refitable = true;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   634
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   635
		case VEH_SHIP: {
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   636
			const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   637
			y = DrawShipPurchaseInfo(x, y, engine_number, svi);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   638
			refitable = svi->refittable;
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   639
		} break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   640
		case VEH_AIRCRAFT:
5817
0bd3e66ece83 (svn r8379) -Cleanup: [build vehicle window] removed overloading with DrawVehiclePurchaseInfo() and renamed them into type specific names
bjarni
parents: 5816
diff changeset
   641
			y = DrawAircraftPurchaseInfo(x, y, engine_number, AircraftVehInfo(engine_number));
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   642
			refitable = true;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   643
			break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   644
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   645
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   646
	/* Draw details, that applies to all types except rail wagons */
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   647
	if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   648
		/* Design date - Life length */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   649
		SetDParam(0, ymd.year);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   650
		SetDParam(1, e->lifelength);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   651
		DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   652
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   653
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   654
		/* Reliability */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   655
		SetDParam(0, e->reliability * 100 >> 16);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   656
		DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, TC_FROMSTRING);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   657
		y += 10;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   658
	}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   659
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   660
	/* Additional text from NewGRF */
4930
708801d486c6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   661
	y += ShowAdditionalText(x, y, w, engine_number);
5790
d4a732968bda (svn r8343) -Cleanup: [build vehicle windows] added a few comments and removed two switch-cases, that we can do without
bjarni
parents: 5787
diff changeset
   662
	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   663
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   664
	return y;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   665
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   666
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   667
/* Figure out what train EngineIDs to put in the list */
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   668
static void GenerateBuildTrainList(Window *w)
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   669
{
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   670
	EngineID eid, sel_id;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   671
	int num_engines = 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   672
	int num_wagons  = 0;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   673
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   674
7251
6c9c673182e9 (svn r10552) -Fix [FS#1034, r10546]: opening Available Aircrafts segfaulted
truelight
parents: 7246
diff changeset
   675
	bv->filter.railtype = (w->window_number <= VEH_END) ? RAILTYPE_END : GetRailType(w->window_number);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   676
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   677
	EngList_RemoveAll(&bv->eng_list);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   678
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   679
	/* Make list of all available train engines and wagons.
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   680
	 * Also check to see if the previously selected engine is still available,
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   681
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   682
	 * when engines become obsolete and are removed */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   683
	for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   684
		const RailVehicleInfo *rvi = RailVehInfo(eid);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   685
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5822
diff changeset
   686
		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   687
		if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   688
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   689
		EngList_Add(&bv->eng_list, eid);
5868
94430141c189 (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: 5824
diff changeset
   690
		if (rvi->railveh_type != RAILVEH_WAGON) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   691
			num_engines++;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   692
		} else {
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   693
			num_wagons++;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   694
		}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   695
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   696
		if (eid == bv->sel_engine) sel_id = eid;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   697
	}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   698
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   699
	bv->sel_engine = sel_id;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   700
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   701
	/* make engines first, and then wagons, sorted by ListPositionOfEngine() */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   702
	_internal_sort_order = false;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   703
	EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   704
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   705
	/* and then sort engines */
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   706
	_internal_sort_order = bv->descending_sort_order;
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   707
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], 0, num_engines);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   708
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   709
	/* and finally sort wagons */
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   710
	EngList_SortPartial(&bv->eng_list, _sorter[0][bv->sort_criteria], num_engines, num_wagons);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   711
}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   712
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   713
/* Figure out what road vehicle EngineIDs to put in the list */
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   714
static void GenerateBuildRoadVehList(Window *w)
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   715
{
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   716
	EngineID eid, sel_id;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   717
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   718
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   719
	EngList_RemoveAll(&bv->eng_list);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   720
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   721
	sel_id = INVALID_ENGINE;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   722
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   723
	for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   724
		if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7824
diff changeset
   725
		if (!HasBit(bv->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   726
		EngList_Add(&bv->eng_list, eid);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   727
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   728
		if (eid == bv->sel_engine) sel_id = eid;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   729
	}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   730
	bv->sel_engine = sel_id;
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   731
}
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   732
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   733
/* Figure out what ship EngineIDs to put in the list */
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   734
static void GenerateBuildShipList(Window *w)
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   735
{
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   736
	EngineID eid, sel_id;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   737
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   738
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   739
	EngList_RemoveAll(&bv->eng_list);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   740
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   741
	sel_id = INVALID_ENGINE;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   742
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   743
	for (eid = SHIP_ENGINES_INDEX; eid < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; eid++) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   744
		if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   745
		EngList_Add(&bv->eng_list, eid);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   746
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   747
		if (eid == bv->sel_engine) sel_id = eid;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   748
	}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   749
	bv->sel_engine = sel_id;
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   750
}
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   751
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   752
/* Figure out what aircraft EngineIDs to put in the list */
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   753
static void GenerateBuildAircraftList(Window *w)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   754
{
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   755
	EngineID eid, sel_id;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   756
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   757
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   758
	EngList_RemoveAll(&bv->eng_list);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   759
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   760
	/* Make list of all available planes.
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   761
	 * Also check to see if the previously selected plane is still available,
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   762
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   763
	 * when planes become obsolete and are removed */
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   764
	sel_id = INVALID_ENGINE;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   765
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   766
		if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
7251
6c9c673182e9 (svn r10552) -Fix [FS#1034, r10546]: opening Available Aircrafts segfaulted
truelight
parents: 7246
diff changeset
   767
		/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
7683
13e6fb7baa57 (svn r11214) -Fix [FS#1296]: planes can't use heliports so refuse these orders
glx
parents: 7595
diff changeset
   768
		if (w->window_number > VEH_END && !CanAircraftUseStation(eid, w->window_number)) continue;
6044
e9e318238ad6 (svn r8771) -Fix r8343: build aircraft windows will no longer show aircraft that can't use the airport in question
bjarni
parents: 6032
diff changeset
   769
6237
69427b23257f (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents: 6193
diff changeset
   770
		EngList_Add(&bv->eng_list, eid);
69427b23257f (svn r9040) -Codechange: the build window and CmdBuildAircraft() now shares the code to figure out if an aircraft is buildable in the hangar in question
bjarni
parents: 6193
diff changeset
   771
		if (eid == bv->sel_engine) sel_id = eid;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   772
	}
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   773
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   774
	bv->sel_engine = sel_id;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   775
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   776
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   777
/* Generate the list of vehicles */
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   778
static void GenerateBuildList(Window *w)
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   779
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   780
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   781
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   782
	switch (bv->vehicle_type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
   783
		default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   784
		case VEH_TRAIN:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   785
			GenerateBuildTrainList(w);
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   786
			return; // trains should not reach the last sorting
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   787
		case VEH_ROAD:
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   788
			GenerateBuildRoadVehList(w);
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   789
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   790
		case VEH_SHIP:
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   791
			GenerateBuildShipList(w);
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   792
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   793
		case VEH_AIRCRAFT:
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   794
			GenerateBuildAircraftList(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   795
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   796
	}
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   797
	_internal_sort_order = bv->descending_sort_order;
5955
fe61588d5188 (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: 5944
diff changeset
   798
	EngList_Sort(&bv->eng_list, _sorter[bv->vehicle_type][bv->sort_criteria]);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   799
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   800
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   801
static void DrawVehicleEngine(byte type, int x, int y, EngineID engine, SpriteID pal)
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   802
{
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   803
	switch (type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   804
		case VEH_TRAIN:    DrawTrainEngine(   x, y, engine, pal); break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   805
		case VEH_ROAD:     DrawRoadVehEngine( x, y, engine, pal); break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   806
		case VEH_SHIP:     DrawShipEngine(    x, y, engine, pal); break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   807
		case VEH_AIRCRAFT: DrawAircraftEngine(x, y, engine, pal); break;
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   808
		default: NOT_REACHED();
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   809
	}
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   810
}
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   811
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   812
/** Engine drawing loop
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   813
 * @param type Type of vehicle (VEH_*)
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   814
 * @param x,y Where should the list start
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   815
 * @param eng_list What engines to draw
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   816
 * @param min where to start in the list
5802
e770857f092f (svn r8364) -Codechange (r8362): added an assert to catch conditions where a request wants to draw more vehicles than the list contains
bjarni
parents: 5800
diff changeset
   817
 * @param max where in the list to end
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   818
 * @param selected_id what engine to highlight as selected, if any
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   819
 * @param show_count Display the number of vehicles (used by autoreplace)
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   820
 */
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   821
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)
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   822
{
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   823
	byte step_size = GetVehicleListHeight(type);
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   824
	byte x_offset = 0;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   825
	byte y_offset = 0;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   826
5802
e770857f092f (svn r8364) -Codechange (r8362): added an assert to catch conditions where a request wants to draw more vehicles than the list contains
bjarni
parents: 5800
diff changeset
   827
	assert(max <= EngList_Count(&eng_list));
e770857f092f (svn r8364) -Codechange (r8362): added an assert to catch conditions where a request wants to draw more vehicles than the list contains
bjarni
parents: 5800
diff changeset
   828
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   829
	switch (type) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   830
		case VEH_TRAIN:
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   831
			x++; // train and road vehicles use the same offset, except trains are one more pixel to the right
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   832
			/* Fallthough */
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   833
		case VEH_ROAD:
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   834
			x += 26;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   835
			x_offset = 30;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   836
			y += 2;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   837
			y_offset = 4;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   838
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   839
		case VEH_SHIP:
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   840
			x += 35;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   841
			x_offset = 40;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   842
			y += 7;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   843
			y_offset = 3;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   844
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   845
		case VEH_AIRCRAFT:
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   846
			x += 27;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   847
			x_offset = 33;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   848
			y += 7;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   849
			y_offset = 3;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   850
			break;
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   851
		default: NOT_REACHED();
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   852
	}
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   853
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   854
	for (; min < max; min++, y += step_size) {
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   855
		const EngineID engine = eng_list[min];
7481
7d8d1dd8da4c (svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
rubidium
parents: 7368
diff changeset
   856
		/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
7d8d1dd8da4c (svn r10992) -Fix [FS#1132]: huge amount of vehicles in the "ungrouped" group. Patch by frosch.
rubidium
parents: 7368
diff changeset
   857
		const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   858
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   859
		SetDParam(0, engine);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   860
		DrawString(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   861
		DrawVehicleEngine(type, x, y + y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   862
		if (show_count) {
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   863
			SetDParam(0, num_engines);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   864
			DrawStringRightAligned(213, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING);
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5893
diff changeset
   865
		}
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   866
	}
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   867
}
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   868
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   869
static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   870
{
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   871
	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   872
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   873
	SetWindowDirty(w);
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   874
	wi->bottom += expand_by;
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   875
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   876
	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   877
		wi = &w->widget[i];
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   878
		wi->top += expand_by;
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   879
		wi->bottom += expand_by;
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   880
	}
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   881
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   882
	w->height += expand_by;
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   883
	SetWindowDirty(w);
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   884
}
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   885
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   886
static void DrawBuildVehicleWindow(Window *w)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   887
{
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   888
	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   889
	uint max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   890
7251
6c9c673182e9 (svn r10552) -Fix [FS#1034, r10546]: opening Available Aircrafts segfaulted
truelight
parents: 7246
diff changeset
   891
	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number <= VEH_END);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   892
5201
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   893
	SetVScrollCount(w, EngList_Count(&bv->eng_list));
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   894
	SetDParam(0, bv->filter.railtype + STR_881C_NEW_RAIL_VEHICLES); // This should only affect rail vehicles
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   895
	DrawWindowWidgets(w);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   896
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6638
diff changeset
   897
	DrawEngineList(bv->vehicle_type, 2, 27, bv->eng_list, w->vscroll.pos, max, bv->sel_engine, false, DEFAULT_GROUP);
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   898
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   899
	if (bv->sel_engine != INVALID_ENGINE) {
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   900
		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
6385
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   901
		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   902
78f5307ce501 (svn r9475) -Codechange: Allow the purchase details widget to expand dynamically if there's still not enough room for the text.
maedhros
parents: 6384
diff changeset
   903
		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
5800
672266389034 (svn r8362) -Codechange: [vehicle build window] moved the engine drawing loop to a function of it's own
bjarni
parents: 5790
diff changeset
   904
	}
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   905
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   906
	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], TC_BLACK);
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   907
	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, TC_BLACK);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   908
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   909
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   910
static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   911
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   912
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   913
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   914
	switch (e->we.click.widget) {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   915
		case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
5199
9a75b853ad22 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   916
			bv->descending_sort_order ^= true;
5955
fe61588d5188 (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: 5944
diff changeset
   917
			_last_sort_order[bv->vehicle_type] = bv->descending_sort_order;
5781
404262bfa03d (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: 5780
diff changeset
   918
			bv->regenerate_list = true;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   919
			SetWindowDirty(w);
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   920
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   921
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   922
		case BUILD_VEHICLE_WIDGET_LIST: {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   923
			uint i = (e->we.click.pt.y - 26) / GetVehicleListHeight(bv->vehicle_type) + w->vscroll.pos;
5201
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   924
			uint num_items = EngList_Count(&bv->eng_list);
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   925
			bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
a4279a8884ea (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   926
			SetWindowDirty(w);
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   927
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   928
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   929
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   930
		case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN: // Select sorting criteria dropdown menu
5955
fe61588d5188 (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: 5944
diff changeset
   931
			ShowDropDownMenu(w, _sort_listing[bv->vehicle_type], bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
5785
5205f8b7fef5 (svn r8337) -Cleanup: removed some more switch-cases in build_vehicle_gui.cpp and added arrays + VehTypeToIndex() instead
bjarni
parents: 5784
diff changeset
   932
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   933
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   934
		case BUILD_VEHICLE_WIDGET_BUILD: {
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   935
			EngineID sel_eng = bv->sel_engine;
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   936
			if (sel_eng != INVALID_ENGINE) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   937
				switch (bv->vehicle_type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
   938
					default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   939
					case VEH_TRAIN:
5868
94430141c189 (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: 5824
diff changeset
   940
						DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildLoco,
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   941
								   CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   942
						break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   943
					case VEH_ROAD:
5786
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   944
						DoCommandP(w->window_number, sel_eng, 0, CcBuildRoadVeh, CMD_BUILD_ROAD_VEH | CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE));
9bbd2d7f2a30 (svn r8338) -Codechange: merged road vehicle build window into the other ones
bjarni
parents: 5785
diff changeset
   945
						break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   946
					case VEH_SHIP:
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   947
						DoCommandP(w->window_number, sel_eng, 0, CcBuildShip, CMD_BUILD_SHIP | CMD_MSG(STR_980D_CAN_T_BUILD_SHIP));
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
   948
						break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   949
					case VEH_AIRCRAFT:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   950
						DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   951
						break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   952
				}
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   953
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   954
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   955
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   956
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   957
		case BUILD_VEHICLE_WIDGET_RENAME: {
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   958
			EngineID sel_eng = bv->sel_engine;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   959
			if (sel_eng != INVALID_ENGINE) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   960
				StringID str = STR_NULL;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   961
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   962
				bv->rename_engine = sel_eng;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   963
				switch (bv->vehicle_type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
   964
					default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   965
					case VEH_TRAIN:    str = STR_886A_RENAME_TRAIN_VEHICLE_TYPE; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   966
					case VEH_ROAD:     str = STR_9036_RENAME_ROAD_VEHICLE_TYPE;  break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   967
					case VEH_SHIP:     str = STR_9838_RENAME_SHIP_TYPE;          break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
   968
					case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE;      break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   969
				}
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   970
				SetDParam(0, sel_eng);
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7009
diff changeset
   971
				ShowQueryString(STR_ENGINE_NAME, str, 31, 160, w, CS_ALPHANUMERAL);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   972
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   973
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   974
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   975
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   976
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   977
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
   978
static void NewVehicleWndProc(Window *w, WindowEvent *e)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   979
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   980
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   981
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   982
	switch (e->event) {
7368
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   983
		case WE_CREATE: {
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   984
			bv->vehicle_type = *(VehicleType*)e->we.create.data;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   985
			int vlh = GetVehicleListHeight(bv->vehicle_type);
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   986
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   987
			ResizeWindow(w, 0, vlh - 14);
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   988
			w->resize.step_height = vlh;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   989
			w->vscroll.cap = 1;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   990
			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = 0x101;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   991
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   992
			w->resize.width  = w->width;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   993
			w->resize.height = w->height;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   994
		} break;
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
   995
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   996
		case WE_INVALIDATE_DATA:
5781
404262bfa03d (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: 5780
diff changeset
   997
			bv->regenerate_list = true;
404262bfa03d (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: 5780
diff changeset
   998
			SetWindowDirty(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   999
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1000
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1001
		case WE_DESTROY:
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1002
			EngList_Destroy(&bv->eng_list);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1003
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1004
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1005
		case WE_PAINT:
5781
404262bfa03d (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: 5780
diff changeset
  1006
			if (bv->regenerate_list) {
404262bfa03d (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: 5780
diff changeset
  1007
				bv->regenerate_list = false;
404262bfa03d (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: 5780
diff changeset
  1008
				GenerateBuildList(w);
404262bfa03d (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: 5780
diff changeset
  1009
			}
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1010
			DrawBuildVehicleWindow(w);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1011
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1012
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1013
		case WE_CLICK:
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1014
			BuildVehicleClickEvent(w, e);
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1015
			break;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1016
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1017
		case WE_DOUBLE_CLICK:
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1018
			if (e->we.click.widget == BUILD_VEHICLE_WIDGET_LIST) {
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1019
				/* When double clicking, we want to buy a vehicle */
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1020
				e->we.click.widget = BUILD_VEHICLE_WIDGET_BUILD;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1021
				BuildVehicleClickEvent(w, e);
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1022
			}
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1023
			break;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7002
diff changeset
  1024
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1025
		case WE_ON_EDIT_TEXT: {
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1026
			if (e->we.edittext.str[0] != '\0') {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1027
				StringID str = STR_NULL;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1028
				_cmd_text = e->we.edittext.str;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1029
				switch (bv->vehicle_type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
  1030
					default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1031
					case VEH_TRAIN:    str = STR_886B_CAN_T_RENAME_TRAIN_VEHICLE; break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1032
					case VEH_ROAD:     str = STR_9037_CAN_T_RENAME_ROAD_VEHICLE;  break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1033
					case VEH_SHIP:     str = STR_9839_CAN_T_RENAME_SHIP_TYPE;     break;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1034
					case VEH_AIRCRAFT: str = STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE; break;
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1035
				}
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1036
				DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(str));
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1037
			}
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1038
			break;
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1039
		}
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1040
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1041
		case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1042
			if (bv->sort_criteria != e->we.dropdown.index) {
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1043
				bv->sort_criteria = e->we.dropdown.index;
5955
fe61588d5188 (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: 5944
diff changeset
  1044
				_last_sort_criteria[bv->vehicle_type] = bv->sort_criteria;
5781
404262bfa03d (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: 5780
diff changeset
  1045
				bv->regenerate_list = true;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1046
			}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1047
			SetWindowDirty(w);
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1048
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1049
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1050
		case WE_RESIZE:
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5823
diff changeset
  1051
			if (e->we.sizing.diff.x != 0) ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1052
			if (e->we.sizing.diff.y == 0) break;
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1053
6026
775982557e0e (svn r8749) -Regression r8331: fixed signed/unsigned issue that could create too many lines in build vehicle windows and crash the game
bjarni
parents: 6024
diff changeset
  1054
			w->vscroll.cap += e->we.sizing.diff.y / (int)GetVehicleListHeight(bv->vehicle_type);
5192
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1055
			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
771a8421a4cc (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
  1056
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1057
	}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1058
}
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1059
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1060
static const WindowDesc _build_vehicle_desc = {
7368
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
  1061
	WDP_AUTO, WDP_AUTO, 240, 174, 240, 256,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5874
diff changeset
  1062
	WC_BUILD_VEHICLE, WC_NONE,
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1063
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1064
	_build_vehicle_widgets,
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1065
	NewVehicleWndProc
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1066
};
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1067
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
  1068
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1069
{
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1070
	buildvehicle_d *bv;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1071
	Window *w;
7246
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1072
	/* We want to be able to open both Available Train as Available Ships,
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1073
	 *  so if tile == 0 (Available XXX Window), use 'type' as unique number.
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1074
	 *  As it always is a low value, it won't collide with any real tile
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1075
	 *  number. */
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1076
	uint num = (tile == 0) ? (int)type : tile;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1077
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1078
	assert(IsPlayerBuildableVehicleType(type));
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1079
7246
9ac33793ac75 (svn r10546) -Fix [FS#1026]: you can now have both Available Train as Available Ship window open
truelight
parents: 7059
diff changeset
  1080
	DeleteWindowById(WC_BUILD_VEHICLE, num);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1081
7368
92dd846cf2c5 (svn r10731) -Codechange: allow smaller initial "build <vehicle type>" windows.
rubidium
parents: 7341
diff changeset
  1082
	w = AllocateWindowDescFront(&_build_vehicle_desc, num, &type);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1083
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1084
	if (w == NULL) return;
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1085
5199
9a75b853ad22 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
  1086
	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1087
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1088
	bv = &WP(w, buildvehicle_d);
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1089
	EngList_Create(&bv->eng_list);
5781
404262bfa03d (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: 5780
diff changeset
  1090
	bv->sel_engine      = INVALID_ENGINE;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1091
5781
404262bfa03d (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: 5780
diff changeset
  1092
	bv->regenerate_list = false;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1093
5955
fe61588d5188 (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: 5944
diff changeset
  1094
	bv->sort_criteria         = _last_sort_criteria[type];
fe61588d5188 (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: 5944
diff changeset
  1095
	bv->descending_sort_order = _last_sort_order[type];
5784
a3b23f0fc794 (svn r8336) -Codechange: added function to translate vehicle types to 0,1,2... for use for index to arrays
bjarni
parents: 5783
diff changeset
  1096
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1097
	switch (type) {
6638
09c5d7bf69a5 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 6608
diff changeset
  1098
		default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1099
		case VEH_TRAIN:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6386
diff changeset
  1100
			WP(w, buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1101
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1102
		case VEH_ROAD:
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6643
diff changeset
  1103
			WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile);
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1104
		case VEH_SHIP:
5783
e207986ffe71 (svn r8335) -Feature: the build ship window is now also resizable horizontally and contains sorting options
bjarni
parents: 5782
diff changeset
  1105
			break;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6237
diff changeset
  1106
		case VEH_AIRCRAFT:
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6023
diff changeset
  1107
			bv->filter.flags =
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6026
diff changeset
  1108
				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
5187
12dc9dfa6af6 (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
  1109
			break;
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1110
	}
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1111
	SetupWindowStrings(w, type);
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5823
diff changeset
  1112
	ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1113
5781
404262bfa03d (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: 5780
diff changeset
  1114
	GenerateBuildList(w); // generate the list, since we need it in the next line
5779
a694ce1457bb (svn r8331) -Feature: the train and aircraft build windows are now resizable in horizontal direction as well
bjarni
parents: 5668
diff changeset
  1115
	/* Select the first engine in the list as default when opening the window */
5200
dfd31d4f2410 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
  1116
	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
4800
5afc1bfc7a85 (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
  1117
}