aircraft_gui.c
author bjarni
Tue, 10 Oct 2006 08:34:14 +0000
changeset 4794 23b5ee70e87e
parent 4792 a6fa5fc79715
child 4800 5afc1bfc7a85
permissions -rw-r--r--
(svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1820
diff changeset
     4
#include "openttd.h"
3963
6cab57074a9a (svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar()
tron
parents: 3948
diff changeset
     5
#include "aircraft.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1294
diff changeset
     6
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     7
#include "functions.h"
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3157
diff changeset
     8
#include "station_map.h"
1922
bda6f85eefaa (svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents: 1907
diff changeset
     9
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 382
diff changeset
    10
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 588
diff changeset
    11
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1055
diff changeset
    12
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "player.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    22
#include "depot.h"
4153
4dabb03d629c (svn r5519) Fix: Only list helicopters in the new build window of helidepots and helistations.Suggested by peter1138 & Tron.
richk
parents: 4077
diff changeset
    23
#include "airport.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2113
diff changeset
    24
#include "vehicle_gui.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    25
#include "newgrf_engine.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4243
diff changeset
    26
#include "date.h"
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    27
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    29
typedef enum BuildAircraftWidgets {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    30
	BUILD_AIRCRAFT_WIDGET_CLOSEBOX = 0,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    31
	BUILD_AIRCRAFT_WIDGET_CAPTION,
4794
23b5ee70e87e (svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
bjarni
parents: 4792
diff changeset
    32
	BUILD_AIRCRAFT_WIDGET_SORT_ASSENDING_DESCENDING,
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    33
	BUILD_AIRCRAFT_WIDGET_SORT_TEXT,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    34
	BUILD_AIRCRAFT_WIDGET_SORT_DROPDOWN,
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    35
	BUILD_AIRCRAFT_WIDGET_LIST,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    36
	BUILD_AIRCRAFT_WIDGET_SCROLLBAR,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    37
	BUILD_AIRCRAFT_WIDGET_PANEL,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    38
	BUILD_AIRCRAFT_WIDGET_PLANES,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    39
	BUILD_AIRCRAFT_WIDGET_JETS,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    40
	BUILD_AIRCRAFT_WIDGET_HELICOPTERS,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    41
	BUILD_AIRCRAFT_WIDGET_BUILD,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    42
	BUILD_AIRCRAFT_WIDGET_RENAME,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    43
	BUILD_AIRCRAFT_WIDGET_RESIZE,
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    44
} BuildAircraftWidget;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    45
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    46
static const Widget _new_aircraft_widgets[] = {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    47
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    48
	{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   239,     0,    13, STR_A005_NEW_AIRCRAFT,   STR_018C_WINDOW_TITLE_DRAG_THIS },
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    49
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    50
	{      WWT_PANEL,   RESIZE_NONE,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    51
	{    WWT_TEXTBTN,   RESIZE_NONE,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    52
	{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   227,    26,   121, 0x401,                   STR_A025_AIRCRAFT_SELECTION_LIST },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    53
	{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    54
	{     WWT_IMGBTN,     RESIZE_TB,    14,     0,   239,   122,   193, 0x0,                     STR_NULL },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    55
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    56
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,    79,   194,   205, STR_BLACK_PLANES,        STR_BUILD_PLANES_TIP },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    57
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,    80,   159,   194,   205, STR_BLACK_JETS,          STR_BUILD_JETS_TIP },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    58
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   160,   239,   194,   205, STR_BLACK_HELICOPTERS,   STR_BUILD_HELICOPTERS_TIP },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    59
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    60
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   206,   217, STR_A006_BUILD_AIRCRAFT, STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    61
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   115,   227,   206,   217, STR_A037_RENAME,         STR_A038_RENAME_AIRCRAFT_TYPE },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    62
	{  WWT_RESIZEBOX,     RESIZE_TB,    14,   228,   239,   206,   217, 0x0,                     STR_RESIZE_BUTTON },
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    63
	{   WIDGETS_END},
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    64
};
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
    65
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    66
static bool _internal_sort_order; // descending/ascending
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    67
static byte _last_sort_criteria = 0;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    68
static bool _last_sort_order = false;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    69
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    70
typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    71
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    72
static int CDECL AircraftEngineNumberSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    73
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    74
	const EngineID va = *(const EngineID*)a;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    75
	const EngineID vb = *(const EngineID*)b;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    76
	int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    77
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    78
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    79
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    80
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    81
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    82
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    83
	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    84
	const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    85
	int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    86
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    87
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    88
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    89
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    90
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    91
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    92
	const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    93
	const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    94
	const int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    95
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    96
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    97
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    98
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
    99
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   100
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   101
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   102
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   103
static int CDECL AircraftEngineIntroDateSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   104
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   105
	const int va = GetEngine(*(const EngineID*)a)->intro_date;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   106
	const int vb = GetEngine(*(const EngineID*)b)->intro_date;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   107
	const int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   108
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   109
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   110
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   111
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   112
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   113
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   114
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   115
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   116
static EngineID _last_engine; // cached vehicle to hopefully speed up name-sorting
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   117
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   118
static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   119
static int CDECL AircraftEngineNameSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   120
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   121
	const EngineID va = *(const EngineID*)a;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   122
	const EngineID vb = *(const EngineID*)b;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   123
	char buf1[64] = "\0";
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   124
	int r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   125
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   126
	SetDParam(0, GetCustomEngineName(va));
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   127
	GetString(buf1, STR_JUST_STRING);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   128
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   129
	if (vb != _last_engine) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   130
		_last_engine = vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   131
		_bufcache[0] = '\0';
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   132
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   133
		SetDParam(0, GetCustomEngineName(vb));
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   134
		GetString(_bufcache, STR_JUST_STRING);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   135
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   136
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   137
	r =  strcmp(buf1, _bufcache); // sort by name
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   138
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   139
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   140
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   141
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   142
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   143
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   144
	return (_internal_sort_order & 1) ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   145
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   146
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   147
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   148
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   149
	const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   150
	const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   151
	const int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   152
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   153
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   154
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   155
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   156
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   157
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   158
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   159
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   160
static int CDECL AircraftEngineReliabilitySorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   161
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   162
	const int va = GetEngine(*(const EngineID*)a)->reliability;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   163
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   164
	const int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   165
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   166
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   167
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   168
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   169
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   170
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   171
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   172
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   173
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   174
{
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   175
	const int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   176
	const int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   177
	const int r = va - vb;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   178
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   179
	if (r == 0) {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   180
		/* Use EngineID to sort instead since we want consistent sorting */
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   181
		return AircraftEngineNumberSorter(a, b);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   182
	}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   183
	return _internal_sort_order ? -r : r;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   184
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   185
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   186
static VehicleSortListingTypeFunction* const _engine_sorter[] = {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   187
	&AircraftEngineNumberSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   188
	&AircraftEngineCostSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   189
	&AircraftEngineSpeedSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   190
	&AircraftEngineIntroDateSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   191
	&AircraftEngineNameSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   192
	&AircraftEngineRunningCostSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   193
	&AircraftEngineReliabilitySorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   194
	&AircraftEngineCargoSorter,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   195
};
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   196
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   197
static const StringID _engine_sort_listing[] = {
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   198
	STR_ENGINE_SORT_ENGINE_ID,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   199
	STR_ENGINE_SORT_COST,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   200
	STR_SORT_BY_MAX_SPEED,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   201
	STR_ENGINE_SORT_INTRO_DATE,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   202
	STR_SORT_BY_DROPDOWN_NAME,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   203
	STR_ENGINE_SORT_RUNNING_COST,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   204
	STR_SORT_BY_RELIABILITY,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   205
	STR_ENGINE_SORT_CARGO_CAPACITY,
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   206
	INVALID_STRING_ID
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   207
};
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   208
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   209
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   210
/**
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   211
 * Draw the purchase info details of an aircraft at a given location.
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   212
 * @param x,y location where to draw the info
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   213
 * @param engine_number the engine of which to draw the info of
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   214
 */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   215
void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   216
{
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   217
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine_number);
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   218
	const Engine *e = GetEngine(engine_number);
3987
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   219
	CargoID cargo;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   220
	YearMonthDay ymd;
4288
393de75451b1 (svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents: 4286
diff changeset
   221
	ConvertDateToYMD(e->intro_date, &ymd);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   222
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   223
	/* Purchase cost - Max speed */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   224
	SetDParam(0, avi->base_cost * (_price.aircraft_base>>3)>>5);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3338
diff changeset
   225
	SetDParam(1, avi->max_speed * 128 / 10);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   226
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   227
	y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   228
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   229
	/* Cargo capacity */
3987
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   230
	cargo = FindFirstRefittableCargo(engine_number);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   231
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   232
		SetDParam(0, avi->passenger_capacity);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   233
		SetDParam(1, avi->mail_capacity);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   234
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   235
	} else {
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   236
		/* Note, if the default capacity is selected by the refit capacity
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   237
		 * callback, then the capacity shown is likely to be incorrect. */
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   238
		SetDParam(0, _cargoc.names_long[cargo]);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   239
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, engine_number));
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   240
		SetDParam(2, STR_9842_REFITTABLE);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   241
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
22972f38e240 (svn r5186) - NewGRF: show default aircraft cargo type and the purchase list (mart3p)
peter1138
parents: 3963
diff changeset
   242
	}
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   243
	y += 10;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   244
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   245
	/* Running cost */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   246
	SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   247
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   248
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   249
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   250
	/* Design date - Life length */
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4288
diff changeset
   251
	SetDParam(0, ymd.year);
1907
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   252
	SetDParam(1, e->lifelength);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   253
	DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   254
	y += 10;
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   255
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   256
	/* Reliability */
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   257
	SetDParam(0, e->reliability * 100 >> 16);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   258
	DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
61bafb476865 (svn r2413) - Codechange: Rewrite the displaying of purchase details a bit, make it easyer to add lines later.
hackykid
parents: 1906
diff changeset
   259
	y += 10;
4243
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
   260
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
   261
	/* Additional text from NewGRF */
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
   262
	// XXX 227 will become a calculated width...
b0361faa4dfd (svn r5820) - NewGRF: Add support for extra vehicle text in the purchase list for road vehicles, aircraft and ships.
peter1138
parents: 4171
diff changeset
   263
	y += ShowAdditionalText(x, y, 227, engine_number);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   264
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 767
diff changeset
   265
4442
9f8bb348d58f (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4434
diff changeset
   266
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
{
3049
d6109b5fd55d (svn r3631) - 2cc: Remove use of some temporary variables and perform minor optimization in the form of the ternary operator.
peter1138
parents: 3040
diff changeset
   268
	PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3049
diff changeset
   269
	DrawSprite(GetAircraftImage(v, DIR_W) | pal, x + 25, y + 10);
4056
7899dc230a12 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4012
diff changeset
   270
	if (v->subtype == 0) {
7899dc230a12 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4012
diff changeset
   271
		SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
7899dc230a12 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4012
diff changeset
   272
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
7899dc230a12 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4012
diff changeset
   273
		DrawSprite(rotor_sprite, x + 25, y + 5);
7899dc230a12 (svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
peter1138
parents: 4012
diff changeset
   274
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	if (v->index == selection) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   276
		DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   280
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2561
diff changeset
   282
	if (success) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   283
		const Vehicle *v = GetVehicle(_new_vehicle_id);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
		if (v->tile == _backup_orders_tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
			_backup_orders_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
			RestoreVehicleOrders(v, _backup_orders_data);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		ShowAircraftViewWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
3887
ece644bbf459 (svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents: 3884
diff changeset
   293
void CcCloneAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   294
{
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3887
diff changeset
   295
	if (success) ShowAircraftViewWindow(GetVehicle(_new_vehicle_id));
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   296
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   298
static inline void ExtendEngineListSize(const EngineID **engine_list, uint16 *engine_list_length, uint16 step_size)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
{
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   300
	*engine_list_length = min(*engine_list_length + step_size, NUM_TRAIN_ENGINES);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   301
	*engine_list = realloc((void*)*engine_list, (*engine_list_length) * sizeof((*engine_list)[0]));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   302
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   304
static void GenerateBuildList(EngineID **planes, uint16 *num_planes, EngineID **jets, uint16 *num_jets, EngineID **helicopters, uint16 *num_helicopters)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   305
{
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   306
	uint16 plane_length      = *num_planes;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   307
	uint16 jet_length        = *num_jets;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   308
	uint16 helicopter_length = *num_helicopters;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   309
	EngineID eid;
4161
60e38778d90b (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4153
diff changeset
   310
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   311
	(*num_planes)      = 0;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   312
	(*num_jets)        = 0;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   313
	(*num_helicopters) = 0;
4161
60e38778d90b (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4153
diff changeset
   314
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   315
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
4161
60e38778d90b (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4153
diff changeset
   316
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   317
		if (IsEngineBuildable(eid, VEH_Aircraft)) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   318
			const AircraftVehicleInfo *avi = AircraftVehInfo(eid);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   319
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   320
			switch (avi->subtype) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   321
				case AIR_CTOL: // Propeller planes
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   322
					if (*num_planes == plane_length) ExtendEngineListSize((const EngineID**)planes, &plane_length, 5);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   323
					(*planes)[(*num_planes)++] = eid;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   324
					break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   325
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   326
				case (AIR_CTOL | AIR_FAST): // Jet planes
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   327
					if (*num_jets == jet_length) ExtendEngineListSize((const EngineID**)jets, &jet_length, 5);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   328
					(*jets)[(*num_jets)++] = eid;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   329
					break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   330
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   331
				case 0: // Helicopters
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   332
					if (*num_helicopters == helicopter_length) ExtendEngineListSize((const EngineID**)helicopters, &plane_length, 5);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   333
					(*helicopters)[(*num_helicopters)++] = eid;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   334
					break;
4161
60e38778d90b (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4153
diff changeset
   335
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   338
	}
4161
60e38778d90b (svn r5594) Be more strict what's allowed to be built in a hangar: if the airport can't handle planes/helicopters don't present and disallow building planes/helicopters - the latter case wasn't covered yet.
tron
parents: 4153
diff changeset
   339
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   340
	/* Reduce array sizes if they are too big */
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   341
	if (*num_planes      != plane_length)      *planes      = realloc((void*)*planes,      (*num_planes)      * sizeof((*planes)[0]));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   342
	if (*num_jets        != jet_length)        *jets        = realloc((void*)*jets,        (*num_jets)        * sizeof((*jets)[0]));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   343
	if (*num_helicopters != helicopter_length) *helicopters = realloc((void*)*helicopters, (*num_helicopters) * sizeof((*helicopters)[0]));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   344
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   346
static inline EngineID *GetEngineArray(Window *w)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   347
{
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   348
	switch (WP(w,buildvehicle_d).show_engine_button) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   349
		case 1: return WP(w, buildvehicle_d).list_a;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   350
		case 2: return WP(w, buildvehicle_d).list_b;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   351
		case 3: return WP(w, buildvehicle_d).list_c;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   352
		default: NOT_REACHED();
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   353
	}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   354
	return NULL;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   355
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   357
static inline uint16 GetEngineArrayLength(Window *w)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   358
{
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   359
	switch (WP(w,buildvehicle_d).show_engine_button) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   360
		case 1: return WP(w, buildvehicle_d).list_a_length;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   361
		case 2: return WP(w, buildvehicle_d).list_b_length;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   362
		case 3: return WP(w, buildvehicle_d).list_c_length;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   363
		default: NOT_REACHED();
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   364
	}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   365
	return 0;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   366
}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   367
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   368
static void SortAircraftBuildList(Window *w)
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   369
{
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   370
	_internal_sort_order = WP(w,buildvehicle_d).decenting_sort_order;
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   371
	qsort((void*)GetEngineArray(w), GetEngineArrayLength(w), sizeof(GetEngineArray(w)[0]),
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   372
		  _engine_sorter[WP(w,buildvehicle_d).sort_criteria]);
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   373
}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   374
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   375
static void DrawBuildAircraftWindow(Window *w)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   376
{
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   377
	SetWindowWidgetLoweredState(w, BUILD_AIRCRAFT_WIDGET_PLANES,      WP(w,buildvehicle_d).show_engine_button == 1);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   378
	SetWindowWidgetLoweredState(w, BUILD_AIRCRAFT_WIDGET_JETS,        WP(w,buildvehicle_d).show_engine_button == 2);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   379
	SetWindowWidgetLoweredState(w, BUILD_AIRCRAFT_WIDGET_HELICOPTERS, WP(w,buildvehicle_d).show_engine_button == 3);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   380
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   381
	SetWindowWidgetDisabledState(w, BUILD_AIRCRAFT_WIDGET_BUILD, w->window_number == 0);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   382
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   383
	if (WP(w, buildvehicle_d).data_invalidated) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   384
		GenerateBuildList(&WP(w, buildvehicle_d).list_a, &WP(w, buildvehicle_d).list_a_length,
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   385
						  &WP(w, buildvehicle_d).list_b, &WP(w, buildvehicle_d).list_b_length,
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   386
						  &WP(w, buildvehicle_d).list_c, &WP(w, buildvehicle_d).list_c_length);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   387
		WP(w, buildvehicle_d).data_invalidated = false;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   388
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   389
		if (WP(w,buildvehicle_d).sel_engine != INVALID_ENGINE) {
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   390
			int i;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   391
			bool found = false;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   392
			if (HASBIT(WP(w,buildvehicle_d).show_engine_button, 0)) {
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   393
				for (i = 0; i < GetEngineArrayLength(w); i++) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   394
					if (WP(w,buildvehicle_d).sel_engine != GetEngineArray(w)[i]) continue;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   395
					found = true;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   396
					break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   397
				}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   398
			}
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   399
			if (!found) WP(w,buildvehicle_d).sel_engine = INVALID_ENGINE;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   400
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   401
	}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   402
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   403
	SetVScrollCount(w, GetEngineArrayLength(w));
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   404
	DrawWindowWidgets(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   405
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   406
	if (WP(w,buildvehicle_d).sel_engine == INVALID_ENGINE && GetEngineArrayLength(w) != 0) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   407
		WP(w,buildvehicle_d).sel_engine = GetEngineArray(w)[0];
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   408
	}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   409
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   410
	{
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   411
		int x = 2;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   412
		int y = 27;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   413
		EngineID selected_id = WP(w,buildvehicle_d).sel_engine;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   414
		EngineID eid = w->vscroll.pos;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   415
		EngineID *list = GetEngineArray(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   416
		uint16 list_length = GetEngineArrayLength(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   417
		uint16 max = min(w->vscroll.pos + w->vscroll.cap, list_length);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   418
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   419
		for(; eid < max; eid++) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   420
			const EngineID engine = list[eid];
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   421
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   422
			DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   423
			DrawAircraftEngine(x + 29, y + 10, engine, GetEnginePalette(engine, _local_player));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   424
			y += 24;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   425
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   426
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   427
		if (selected_id != INVALID_ENGINE) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   428
			DrawAircraftPurchaseInfo(x, w->widget[BUILD_AIRCRAFT_WIDGET_PANEL].top + 1, selected_id);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   429
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   430
	}
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   431
	DrawString(85, 15, _engine_sort_listing[WP(w,buildvehicle_d).sort_criteria], 0x10);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   432
	DoDrawString(WP(w,buildvehicle_d).decenting_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   433
}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   434
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   435
static void BuildAircraftClickEvent(Window *w, WindowEvent *e)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   436
{
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   437
	byte click_state = 0;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   438
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   439
	switch (e->we.click.widget) {
4794
23b5ee70e87e (svn r6716) -Code cleanup: [aircraft/train build windows] fixed a spelling mistake in the widget names (the game itself is unaffected by this)
bjarni
parents: 4792
diff changeset
   440
		case BUILD_AIRCRAFT_WIDGET_SORT_ASSENDING_DESCENDING:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   441
			WP(w,buildvehicle_d).decenting_sort_order = !WP(w,buildvehicle_d).decenting_sort_order;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   442
			_last_sort_order = WP(w,buildvehicle_d).decenting_sort_order;
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   443
			SortAircraftBuildList(w);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   444
			SetWindowDirty(w);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   445
			break;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   446
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   447
		case BUILD_AIRCRAFT_WIDGET_LIST: {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   448
			uint i = (e->we.click.pt.y - 26) / 24;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   449
			if (i < w->vscroll.cap) {
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   450
				i += w->vscroll.pos;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   451
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   452
				if (i < GetEngineArrayLength(w)) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   453
					WP(w,buildvehicle_d).sel_engine = GetEngineArray(w)[i];
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   454
					SetWindowDirty(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   455
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   459
		case BUILD_AIRCRAFT_WIDGET_SORT_TEXT: case BUILD_AIRCRAFT_WIDGET_SORT_DROPDOWN:/* Select sorting criteria dropdown menu */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   460
			ShowDropDownMenu(w, _engine_sort_listing, WP(w,buildvehicle_d).sort_criteria, BUILD_AIRCRAFT_WIDGET_SORT_DROPDOWN, 0, 0);
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   461
			return;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   462
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   463
		case BUILD_AIRCRAFT_WIDGET_HELICOPTERS: click_state++;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   464
		case BUILD_AIRCRAFT_WIDGET_JETS:        click_state++;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   465
		case BUILD_AIRCRAFT_WIDGET_PLANES:      click_state++;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   466
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   467
			if (WP(w,buildvehicle_d).show_engine_button == click_state) break; // We clicked the pressed button
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   468
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   469
			WP(w,buildvehicle_d).sel_engine = INVALID_ENGINE;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   470
			WP(w,buildvehicle_d).show_engine_button = click_state;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   471
			w->vscroll.pos = 0;
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   472
			SortAircraftBuildList(w);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   473
			SetWindowDirty(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   474
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   475
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   476
		case BUILD_AIRCRAFT_WIDGET_BUILD: {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   477
			EngineID sel_eng = WP(w,buildvehicle_d).sel_engine;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   478
			if (sel_eng != INVALID_ENGINE)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
				DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   482
		case BUILD_AIRCRAFT_WIDGET_RENAME: {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   483
			EngineID sel_eng = WP(w,buildvehicle_d).sel_engine;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2477
diff changeset
   484
			if (sel_eng != INVALID_ENGINE) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   485
				WP(w,buildvehicle_d).rename_engine = sel_eng;
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 924
diff changeset
   486
				ShowQueryString(GetCustomEngineName(sel_eng),
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   487
								STR_A039_RENAME_AIRCRAFT_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL);
968
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 924
diff changeset
   488
			}
84a870c7a585 (svn r1463) -Fix: [1099451] Game crashes after the click on Rename (see also Bug 10992). There was no check for non-selected engine
darkvater
parents: 924
diff changeset
   489
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   493
static void BuildAircraftWindowCreate(Window *w)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   494
{
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   495
	TileIndex tile = w->window_number;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   496
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   497
	WP(w, buildvehicle_d).list_a_length = 0;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   498
	WP(w, buildvehicle_d).list_b_length = 0;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   499
	WP(w, buildvehicle_d).list_c_length = 0;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   500
	WP(w, buildvehicle_d).list_a        = NULL;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   501
	WP(w, buildvehicle_d).list_b        = NULL;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   502
	WP(w, buildvehicle_d).list_c        = NULL;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   503
	WP(w, buildvehicle_d).data_invalidated     = false;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   504
	WP(w, buildvehicle_d).sel_engine           = INVALID_ENGINE;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   505
	WP(w, buildvehicle_d).sort_criteria        = _last_sort_criteria;
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   506
	WP(w, buildvehicle_d).decenting_sort_order = _last_sort_order;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   507
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   508
	GenerateBuildList(&WP(w, buildvehicle_d).list_a, &WP(w, buildvehicle_d).list_a_length,
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   509
					  &WP(w, buildvehicle_d).list_b, &WP(w, buildvehicle_d).list_b_length,
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   510
					  &WP(w, buildvehicle_d).list_c, &WP(w, buildvehicle_d).list_c_length);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   511
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   512
	/* Disable the aircraft subtype buttons for the types, that can't be build at the current airport */
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   513
	if (tile == 0) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   514
		WP(w, buildvehicle_d).show_engine_button = 1;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   515
	} else {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   516
		byte acc_planes = GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   517
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   518
		WP(w, buildvehicle_d).show_engine_button = 0;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   519
		if (acc_planes == HELICOPTERS_ONLY || acc_planes == ALL) {
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   520
			WP(w, buildvehicle_d).show_engine_button = 3;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   521
		} else {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   522
			DisableWindowWidget(w, BUILD_AIRCRAFT_WIDGET_HELICOPTERS);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   523
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   524
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   525
		if (acc_planes == AIRCRAFT_ONLY || acc_planes == ALL) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   526
			/* Set the start clicked button to jets if the list isn't empty. If not, then show propeller planes */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   527
			WP(w, buildvehicle_d).show_engine_button = WP(w, buildvehicle_d).list_b_length == 0 ? 1 : 2;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   528
		} else {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   529
			DisableWindowWidget(w, BUILD_AIRCRAFT_WIDGET_JETS);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   530
			DisableWindowWidget(w, BUILD_AIRCRAFT_WIDGET_PLANES);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   531
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   532
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   533
		if (WP(w, buildvehicle_d).show_engine_button == 0) {
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   534
			/* No plane type are buildable here */
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   535
			NOT_REACHED();
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   536
			WP(w, buildvehicle_d).show_engine_button = 1;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   537
		}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   538
	}
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   539
	SortAircraftBuildList(w);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   540
}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   541
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   542
static void NewAircraftWndProc(Window *w, WindowEvent *e)
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   543
{
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   544
	switch (e->event) {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   545
		case WE_CREATE:
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   546
			BuildAircraftWindowCreate(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   547
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   548
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   549
		case WE_INVALIDATE_DATA:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   550
			WP(w,buildvehicle_d).data_invalidated = true;
4792
a6fa5fc79715 (svn r6714) -Codechange: replaced a direct manipulation of windows with InvalidateWindowData() in rail_cmd.c
bjarni
parents: 4790
diff changeset
   551
			SetWindowDirty(w);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   552
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   553
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   554
		case WE_DESTROY:
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   555
			free((void*)WP(w, buildvehicle_d).list_a);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   556
			free((void*)WP(w, buildvehicle_d).list_b);
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   557
			free((void*)WP(w, buildvehicle_d).list_c);
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   558
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   559
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   560
		case WE_PAINT:
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   561
			DrawBuildAircraftWindow(w);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   562
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   563
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   564
		case WE_CLICK:
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   565
			BuildAircraftClickEvent(w, e);
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   566
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   567
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   568
		case WE_ON_EDIT_TEXT: {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   569
			if (e->we.edittext.str[0] != '\0') {
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   570
				_cmd_text = e->we.edittext.str;
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   571
				DoCommandP(0, WP(w, buildvehicle_d).rename_engine, 0, NULL,
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   572
						   CMD_RENAME_ENGINE | CMD_MSG(STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE));
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   573
			}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   574
		} break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   575
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   576
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
4790
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   577
			if (WP(w,buildvehicle_d).sort_criteria != e->we.dropdown.index) {
69e0d03632c9 (svn r6712) -Code cleanup: renamed buildtrain_d to buildvehicle_d as it's used for all vehicle types
bjarni
parents: 4787
diff changeset
   578
				WP(w,buildvehicle_d).sort_criteria = e->we.dropdown.index;
4787
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   579
				_last_sort_criteria = e->we.dropdown.index;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   580
				SortAircraftBuildList(w);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   581
			}
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   582
			SetWindowDirty(w);
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   583
			break;
5eaa3e93cf24 (svn r6708) -Feature: [build aircraft window] added sort options to the list
bjarni
parents: 4786
diff changeset
   584
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   585
		case WE_RESIZE:
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   586
			w->vscroll.cap += e->we.sizing.diff.y / 24;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   587
			w->widget[BUILD_AIRCRAFT_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   588
			break;
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   589
	}
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   590
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
static const WindowDesc _new_aircraft_desc = {
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   593
	-1, -1, 240, 218,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	WC_BUILD_VEHICLE,0,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   595
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	_new_aircraft_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
	NewAircraftWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
4442
9f8bb348d58f (svn r6215) -Codechange: [vehicle list windows] unified Player(vehicle)WndProc into PlayerVehWndProc
bjarni
parents: 4434
diff changeset
   600
void ShowBuildAircraftWindow(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   606
	w = AllocateWindowDescFront(&_new_aircraft_desc, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	w->vscroll.cap = 4;
4786
78938c5e606a (svn r6707) -Feature: [build aircraft window] added buttons to view propeller planes, jet planes or helicopters
bjarni
parents: 4734
diff changeset
   608
	w->widget[BUILD_AIRCRAFT_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   609
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 842
diff changeset
   610
	w->resize.step_height = 24;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
	if (tile != 0) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   613
		w->caption_color = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
		w->caption_color = _local_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
{
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   621
	switch (e->event) {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   622
	case WE_PAINT: {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   623
		const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   625
		SetWindowWidgetDisabledState(w, 2, v->owner != _local_player);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   626
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   627
		/* Disable service-scroller when interval is set to disabled */
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   628
		SetWindowWidgetDisabledState(w, 5, !_patches.servint_aircraft);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   629
		SetWindowWidgetDisabledState(w, 6, !_patches.servint_aircraft);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   630
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   631
		SetDParam(0, v->string_id);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   632
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
		/* Draw running cost */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
			int year = v->age / 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   639
			SetDParam(1, year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
2252
6df2bfd7a077 (svn r2772) Simplify the age notice in the vehicle details window
tron
parents: 2244
diff changeset
   641
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   642
			SetDParam(2, v->max_age / 366);
538
24fdb517fbe5 (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   643
			SetDParam(3, _price.aircraft_running * AircraftVehInfo(v->engine_type)->running_cost >> 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
			DrawString(2, 15, STR_A00D_AGE_RUNNING_COST_YR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
		/* Draw max speed */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
		{
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3338
diff changeset
   649
			SetDParam(0, v->max_speed * 128 / 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
			DrawString(2, 25, STR_A00E_MAX_SPEED, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
		/* Draw profit */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   655
			SetDParam(0, v->profit_this_year);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   656
			SetDParam(1, v->profit_last_year);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
			DrawString(2, 35, STR_A00F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		/* Draw breakdown & reliability */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   662
			SetDParam(0, v->reliability * 100 >> 16);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   663
			SetDParam(1, v->breakdowns_since_last_service);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
			DrawString(2, 45, STR_A010_RELIABILITY_BREAKDOWNS, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
		/* Draw service interval text */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
		{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   669
			SetDParam(0, v->service_interval);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   670
			SetDParam(1, v->date_of_last_service);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   671
			DrawString(13, 103, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
		DrawAircraftImage(v, 3, 57, INVALID_VEHICLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
		{
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   677
			const Vehicle *u;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
			int y = 57;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
				if (v->subtype <= 2) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   682
					SetDParam(0, GetCustomEngineName(v->engine_type));
4329
0e6e689f66e7 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4299
diff changeset
   683
					SetDParam(1, v->build_year);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   684
					SetDParam(2, v->value);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
					DrawString(60, y, STR_A011_BUILT_VALUE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
					y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   688
					SetDParam(0, _cargoc.names_long[v->cargo_type]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   689
					SetDParam(1, v->cargo_cap);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
					u = v->next;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2049
diff changeset
   691
					SetDParam(2, _cargoc.names_long[u->cargo_type]);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   692
					SetDParam(3, u->cargo_cap);
2260
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2252
diff changeset
   693
					DrawString(60, y, (u->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
					y += 14;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
				if (v->cargo_count != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
					/* Cargo names (fix pluralness) */
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   700
					SetDParam(0, v->cargo_type);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   701
					SetDParam(1, v->cargo_count);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   702
					SetDParam(2, v->cargo_source);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
					DrawString(60, y, STR_8813_FROM, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
					y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
			} while ( (v=v->next) != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
		}
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   709
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   711
	case WE_CLICK: {
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   712
		int mod;
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   713
		const Vehicle *v;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   714
		switch (e->we.click.widget) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
		case 2: /* rename */
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   716
			v = GetVehicle(w->window_number);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   717
			SetDParam(0, v->unitnumber);
4299
91f5d2bedcff (svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents: 4293
diff changeset
   718
			ShowQueryString(v->string_id, STR_A030_NAME_AIRCRAFT, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
		case 5: /* increase int */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   721
			mod = _ctrl_pressed? 5 : 10;
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   722
			goto do_change_service_int;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
		case 6: /* decrease int */
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   724
			mod = _ctrl_pressed?- 5 : -10;
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   725
do_change_service_int:
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   726
			v = GetVehicle(w->window_number);
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   727
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   728
			mod = GetServiceIntervalClamped(mod + v->service_interval);
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   729
			if (mod == v->service_interval) return;
156
8fef5e5752d6 (svn r157) -Feature: [1009708] Percent-based service intervals. Send a vehicle to depot after it has lost X% of its reliability (mivlad)
darkvater
parents: 10
diff changeset
   730
2819
f25fb6ee397f (svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents: 2806
diff changeset
   731
			DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
		}
1790
47963a0cfca3 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1485
diff changeset
   734
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   736
	case WE_ON_EDIT_TEXT:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   737
		if (e->we.edittext.str[0] != '\0') {
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   738
			_cmd_text = e->we.edittext.str;
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
   739
			DoCommandP(0, w->window_number, 0, NULL,
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
   740
				CMD_NAME_VEHICLE | CMD_MSG(STR_A031_CAN_T_NAME_AIRCRAFT));
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
   741
		}
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2517
diff changeset
   742
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
static const Widget _aircraft_details_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   748
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   749
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   349,     0,    13, STR_A00C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   750
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   350,   389,     0,    13, STR_01AA_NAME,    STR_A032_NAME_AIRCRAFT },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   751
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   389,    14,    55, 0x0,              STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   752
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   389,    56,   101, 0x0,              STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   753
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   102,   107, STR_0188,         STR_884D_INCREASE_SERVICING_INTERVAL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   754
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    10,   108,   113, STR_0189,         STR_884E_DECREASE_SERVICING_INTERVAL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   755
{     WWT_IMGBTN,   RESIZE_NONE,    14,    11,   389,   102,   113, 0x0,              STR_NULL },
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 174
diff changeset
   756
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
static const WindowDesc _aircraft_details_desc = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   760
	-1, -1, 390, 114,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   761
	WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	_aircraft_details_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	AircraftDetailsWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   768
static void ShowAircraftDetailsWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	VehicleID veh = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	_alloc_wnd_parent_num = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
	w = AllocateWindowDesc(&_aircraft_details_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	w->window_number = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
//	w->vscroll.cap = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
//	w->traindetails_d.tab = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
static const Widget _aircraft_view_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   786
{   WWT_CLOSEBOX,  RESIZE_NONE,  14,   0,  10,   0,  13, STR_00C5,           STR_018B_CLOSE_WINDOW },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   787
{    WWT_CAPTION, RESIZE_RIGHT,  14,  11, 237,   0,  13, STR_A00A,           STR_018C_WINDOW_TITLE_DRAG_THIS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   788
{  WWT_STICKYBOX,    RESIZE_LR,  14, 238, 249,   0,  13, 0x0,                STR_STICKY_BUTTON },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   789
{     WWT_IMGBTN,    RESIZE_RB,  14,   0, 231,  14, 103, 0x0,                STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   790
{          WWT_6,    RESIZE_RB,  14,   2, 229,  16, 101, 0x0,                STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   791
{ WWT_PUSHIMGBTN,   RESIZE_RTB,  14,   0, 237, 104, 115, 0x0,                STR_A027_CURRENT_AIRCRAFT_ACTION },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   792
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  14,  31, 0x2AB,              STR_A029_CENTER_MAIN_VIEW_ON_AIRCRAFT },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   793
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  32,  49, 0x2AF,              STR_A02A_SEND_AIRCRAFT_TO_HANGAR },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   794
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  50,  67, 0x2B4,              STR_A03B_REFIT_AIRCRAFT_TO_CARRY },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   795
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  68,  85, 0x2B2,              STR_A028_SHOW_AIRCRAFT_S_ORDERS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   796
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  86, 103, 0x2B3,              STR_A02B_SHOW_AIRCRAFT_DETAILS },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   797
{ WWT_PUSHIMGBTN,    RESIZE_LR,  14, 232, 249,  32,  49, SPR_CLONE_AIRCRAFT, STR_CLONE_AIRCRAFT_INFO },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   798
{      WWT_PANEL,   RESIZE_LRB,  14, 232, 249, 104, 103, 0x0,                STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   799
{  WWT_RESIZEBOX,  RESIZE_LRTB,  14, 238, 249, 104, 115, 0x0,                STR_NULL },
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   800
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   803
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
static void AircraftViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   806
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	case WE_PAINT: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   808
		const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   811
		SetWindowWidgetDisabledState(w, 7, v->owner != _local_player);
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
   812
		SetWindowWidgetDisabledState(w, 8, !IsAircraftInHangarStopped(v) || v->owner != _local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
		/* draw widgets & caption */
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   816
		SetDParam(0, v->string_id);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   817
		SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
		if (v->vehstatus & VS_CRASHED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
			str = STR_8863_CRASHED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		} else if (v->vehstatus & VS_STOPPED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			str = STR_8861_STOPPED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
		} else {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
   825
			switch (v->current_order.type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
			case OT_GOTO_STATION: {
4527
fa30d19685c2 (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   827
				SetDParam(0, v->current_order.dest);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3338
diff changeset
   828
				SetDParam(1, v->cur_speed * 128 / 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
				str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
			case OT_GOTO_DEPOT: {
4389
18d6ccfb5335 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4345
diff changeset
   833
				/* Aircrafts always go to a station, even if you say depot */
4527
fa30d19685c2 (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4524
diff changeset
   834
				SetDParam(0, v->current_order.dest);
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3338
diff changeset
   835
				SetDParam(1, v->cur_speed * 128 / 10);
4633
cf6c2f173030 (svn r6497) -Fix r6165: Vehicles heading for depots when their orders contained "service in depot" displayed the stopping in depot string
bjarni
parents: 4547
diff changeset
   836
				if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
4412
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   837
					str = STR_HEADING_FOR_HANGAR + _patches.vehicle_speed;
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   838
				} else {
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   839
					str = STR_HEADING_FOR_HANGAR_SERVICE + _patches.vehicle_speed;
cae52239a576 (svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents: 4408
diff changeset
   840
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
			case OT_LOADING:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
				str = STR_882F_LOADING_UNLOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
				if (v->num_orders == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
					str = STR_NO_ORDERS + _patches.vehicle_speed;
3477
4a686a43af8a (svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents: 3338
diff changeset
   850
					SetDParam(0, v->cur_speed * 128 / 10);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   851
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
					str = STR_EMPTY;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   853
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
2103
a2b3106d33d5 (svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents: 2084
diff changeset
   858
		/* draw the flag plus orders */
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2498
diff changeset
   859
		DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
2113
be2f07df0dfa (svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents: 2103
diff changeset
   860
		DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
		DrawWindowViewport(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	case WE_CLICK: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   865
		const Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   867
		switch (e->we.click.widget) {
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   868
		case 5: /* start stop */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   871
		case 6: /* center main view */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			ScrollMainWindowTo(v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   874
		case 7: /* goto hangar */
4506
e6a56518135c (svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents: 4456
diff changeset
   875
			DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_A012_CAN_T_SEND_AIRCRAFT_TO));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   877
		case 8: /* refit */
4712
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4709
diff changeset
   878
			ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   880
		case 9: /* show orders */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
			ShowOrdersWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			break;
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 727
diff changeset
   883
		case 10: /* show details */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
			ShowAircraftDetailsWindow(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
			break;
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   886
		case 11:
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   887
			/* clone vehicle */
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   888
			DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   889
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1323
diff changeset
   893
	case WE_RESIZE:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   894
		w->viewport->width          += e->we.sizing.diff.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   895
		w->viewport->height         += e->we.sizing.diff.y;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   896
		w->viewport->virtual_width  += e->we.sizing.diff.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4633
diff changeset
   897
		w->viewport->virtual_height += e->we.sizing.diff.y;
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1323
diff changeset
   898
		break;
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1323
diff changeset
   899
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	case WE_DESTROY:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
		break;
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
   905
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   906
	case WE_MOUSELOOP: {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   907
		const Vehicle *v = GetVehicle(w->window_number);
4702
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   908
		bool plane_stopped = IsAircraftInHangarStopped(v);
2244
417a472e7cb5 (svn r2764) -Feature: Clone vehicles
bjarni
parents: 2186
diff changeset
   909
4702
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   910
		/* Widget 7 (send to hangar) must be hidden if the plane is already stopped in hangar.
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   911
		 * Widget 11 (clone) should then be shown, since cloning is allowed only while in hangar and stopped.
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   912
		 * This sytem allows to have two buttons, on top of each other*/
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   913
		if (plane_stopped != IsWindowWidgetHidden(w, 7) || plane_stopped == IsWindowWidgetHidden(w, 11)) {
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   914
			SetWindowWidgetHiddenState(w,  7, plane_stopped);  // send to hangar
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4668
diff changeset
   915
			SetWindowWidgetHiddenState(w, 11, !plane_stopped); // clone
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   916
			SetWindowDirty(w);
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   917
		}
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   918
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
static const WindowDesc _aircraft_view_desc = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	-1,-1, 250, 116,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
	WC_VEHICLE_VIEW ,0,
1485
34545d21c656 (svn r1989) -Feature: Resizable vehicle view windows; this is based on a patch by tmesisbob
tron
parents: 1323
diff changeset
   926
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	_aircraft_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	AircraftViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   932
void ShowAircraftViewWindow(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4162
diff changeset
   934
	Window *w = AllocateWindowDescFront(&_aircraft_view_desc, v->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
2561
233dafd7cf6c (svn r3098) static, const, uint -> TileIndex, indentation, bracing, unused return values, ... mostly related to the clone vehicle GUI
tron
parents: 2549
diff changeset
   936
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
		w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
		AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
}