src/engine_gui.cpp
author rubidium
Thu, 19 Jun 2008 11:45:52 +0000
changeset 11023 583f32658248
parent 10765 34cd0fa4baed
child 11035 e1ee65151624
permissions -rw-r--r--
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10382
diff changeset
     3
/** @file engine_gui.cpp GUI to show engine related information. */
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6182
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1095
diff changeset
     6
#include "openttd.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gui.h"
8603
88c5ce6a5215 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8602
diff changeset
     8
#include "window_gui.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8627
diff changeset
     9
#include "gfx_func.h"
9282
2bb9703aeb39 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 9259
diff changeset
    10
#include "engine_func.h"
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9282
diff changeset
    11
#include "engine_base.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    12
#include "command_func.h"
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    13
#include "economy_func.h"
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9122
diff changeset
    14
#include "news_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    15
#include "variables.h"
2962
dbd168a4703a (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2840
diff changeset
    16
#include "newgrf_engine.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8603
diff changeset
    17
#include "strings_func.h"
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
    18
#include "engine_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8720
diff changeset
    20
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8720
diff changeset
    21
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
10521
79e3bb000aed (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 10462
diff changeset
    23
StringID GetEngineCategoryName(EngineID engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
{
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    25
	switch (GetEngine(engine)->type) {
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    26
		default: NOT_REACHED();
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
    27
		case VEH_ROAD:              return STR_8103_ROAD_VEHICLE;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
    28
		case VEH_AIRCRAFT:          return STR_8104_AIRCRAFT;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
    29
		case VEH_SHIP:              return STR_8105_SHIP;
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
    30
		case VEH_TRAIN:
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    31
			switch (RailVehInfo(engine)->railtype) {
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    32
				default: NOT_REACHED();
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    33
				case RAILTYPE_RAIL:     return STR_8102_RAILROAD_LOCOMOTIVE;
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    34
				case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    35
				case RAILTYPE_MONO:     return STR_8106_MONORAIL_LOCOMOTIVE;
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    36
				case RAILTYPE_MAGLEV:   return STR_8107_MAGLEV_LOCOMOTIVE;
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    37
			}
460
f11659d28617 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 193
diff changeset
    38
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
static const Widget _engine_preview_widgets[] = {
4344
5d0e40cd67b9 (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: 3477
diff changeset
    42
{   WWT_CLOSEBOX,   RESIZE_NONE,     5,     0,    10,     0,    13, STR_00C5,                                  STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
    43
{    WWT_CAPTION,   RESIZE_NONE,     5,    11,   299,     0,    13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4898
diff changeset
    44
{      WWT_PANEL,   RESIZE_NONE,     5,     0,   299,    14,   191, 0x0,                                       STR_NULL},
4344
5d0e40cd67b9 (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: 3477
diff changeset
    45
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     5,    85,   144,   172,   183, STR_00C9_NO,                               STR_NULL},
5d0e40cd67b9 (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: 3477
diff changeset
    46
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     5,   155,   214,   172,   183, STR_00C8_YES,                              STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 0
diff changeset
    47
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
    50
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    51
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6535
diff changeset
    53
struct DrawEngineInfo {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	DrawEngineProc *engine_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	DrawEngineInfoProc *info_proc;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6535
diff changeset
    56
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    58
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    59
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    60
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    61
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
    62
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
static const DrawEngineInfo _draw_engine_list[4] = {
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    64
	{ DrawTrainEngine,    DrawTrainEngineInfo    },
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    65
	{ DrawRoadVehEngine,  DrawRoadVehEngineInfo  },
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    66
	{ DrawShipEngine,     DrawShipEngineInfo     },
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
    67
	{ DrawAircraftEngine, DrawAircraftEngineInfo },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    70
struct EnginePreviewWindow : Window {
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    71
	EnginePreviewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    72
	{
10681
3aa3de4d448b (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 10641
diff changeset
    73
		this->FindWindowPlacementAndResize(desc);
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    74
	}
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    75
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    76
	virtual void OnPaint()
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    77
	{
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    78
		this->DrawWidgets();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    80
		EngineID engine = this->window_number;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    81
		SetDParam(0, GetEngineCategoryName(engine));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7498
diff changeset
    84
		SetDParam(0, engine);
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    85
		DrawStringCentered(this->width >> 1, 80, STR_ENGINE_NAME, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    87
		const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    89
		int width = this->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
		dei->engine_proc(width >> 1, 100, engine, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
		dei->info_proc(engine, width >> 1, 130, width - 52);
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    92
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    94
	virtual void OnClick(Point pt, int widget)
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    95
	{
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    96
		switch (widget) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    97
			case 4:
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
    98
				DoCommandP(0, this->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
5125
60b21cf18b50 (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 4938
diff changeset
    99
				/* Fallthrough */
60b21cf18b50 (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 4938
diff changeset
   100
			case 3:
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
   101
				delete this;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   102
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	}
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
   105
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
static const WindowDesc _engine_preview_desc = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7762
diff changeset
   108
	WDP_CENTER, WDP_CENTER, 300, 192, 300, 192,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6119
diff changeset
   109
	WC_ENGINE_PREVIEW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	_engine_preview_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   115
void ShowEnginePreviewWindow(EngineID engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
{
10626
557ccb284c8c (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 10595
diff changeset
   117
	AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   120
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   121
{
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   122
	const RailVehicleInfo *rvi = RailVehInfo(engine);
8259
127e5d73637d (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7837
diff changeset
   123
	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD) ? 1 : 0;
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   124
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   125
	SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
6182
e9b456deec29 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 6144
diff changeset
   126
	SetDParam(2, rvi->max_speed * 10 / 16);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   127
	SetDParam(3, rvi->power << multihead);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   128
	SetDParam(1, rvi->weight << multihead);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   129
9122
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   130
	SetDParam(4, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8 << multihead);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   131
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   132
	if (rvi->capacity != 0) {
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   133
		SetDParam(5, rvi->cargo_type);
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   134
		SetDParam(6, rvi->capacity << multihead);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   135
	} else {
4898
68560c75ec28 (svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents: 4896
diff changeset
   136
		SetDParam(5, CT_INVALID);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   137
	}
3401
ad8175f44c3b (svn r4211) - Removed measuring units from the names of two strings.
peter1138
parents: 3355
diff changeset
   138
	DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   139
}
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   140
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   141
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   142
{
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   143
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   144
	SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 5);
6647
d565fde8d0f5 (svn r9275) -Fix(r8973, FS#686): Faulty display of aircraft maximum velocity in the news item for new vehicles
celestar
parents: 6585
diff changeset
   145
	SetDParam(1, avi->max_speed * 10 / 16);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   146
	SetDParam(2, avi->passenger_capacity);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   147
	SetDParam(3, avi->mail_capacity);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   148
	SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   149
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   150
	DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   151
}
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   152
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   153
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   154
{
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   155
	const RoadVehicleInfo *rvi = RoadVehInfo(engine);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   156
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   157
	SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5);
6182
e9b456deec29 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 6144
diff changeset
   158
	SetDParam(1, rvi->max_speed * 10 / 32);
9122
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   159
	SetDParam(2, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8);
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   160
	SetDParam(3, rvi->cargo_type);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   161
	SetDParam(4, rvi->capacity);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   162
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   163
	DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   164
}
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   165
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   166
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   167
{
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   168
	const ShipVehicleInfo *svi = ShipVehInfo(engine);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   169
	SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5);
6182
e9b456deec29 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 6144
diff changeset
   170
	SetDParam(1, svi->max_speed * 10 / 32);
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   171
	SetDParam(2, svi->cargo_type);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   172
	SetDParam(3, svi->capacity);
7498
ce6588257e8d (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 7487
diff changeset
   173
	SetDParam(4, svi->running_cost * _price.ship_running >> 8);
1998
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   174
	DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   175
}
849933cfa8de (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   176
9259
088d3649dd4f (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 9122
diff changeset
   177
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   178
{
10521
79e3bb000aed (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 10462
diff changeset
   179
	EngineID engine = ni->data_a;
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   180
	const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   181
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   182
	SetDParam(0, GetEngineCategoryName(engine));
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   183
	DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   184
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7498
diff changeset
   187
	SetDParam(0, engine);
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   188
	DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   190
	dei->engine_proc(w->width >> 1, 88, engine, 0);
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   191
	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6534
diff changeset
   192
	dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
}
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   194
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   195
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   196
/** Sort all items using qsort() and given 'CompareItems' function
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   197
 * @param el list to be sorted
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   198
 * @param compare function for evaluation of the quicksort
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   199
 */
10764
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   200
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   201
{
10764
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   202
	uint size = el->Length();
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   203
	/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   204
	 * generally, do not sort if there are less than 2 items */
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   205
	if (size < 2) return;
10764
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   206
	qsort(el->Begin(), size, sizeof(*el->Begin()), compare); // MorphOS doesn't know vector::at(int) ...
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   207
}
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   208
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   209
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   210
 * @param el list to be sorted
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   211
 * @param compare function for evaluation of the quicksort
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   212
 * @param begin start of sorting
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   213
 * @param num_items count of items to be sorted
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   214
 */
10764
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   215
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   216
{
10765
34cd0fa4baed (svn r13315) -Fix (r13314): Assert if no engines or wagons available
peter1138
parents: 10764
diff changeset
   217
	if (num_items < 2) return;
10764
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   218
	assert(begin < el->Length());
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   219
	assert(begin + num_items <= el->Length());
e46596b87826 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 10737
diff changeset
   220
	qsort(el->Get(begin), num_items, sizeof(*el->Begin()), compare);
10737
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   221
}
0f704b9afd93 (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 10681
diff changeset
   222