src/engine_gui.cpp
author translators
Wed, 17 Dec 2008 18:01:19 +0000
changeset 10433 45f92593bd6e
parent 10000 57463dc267a0
permissions -rw-r--r--
(svn r14686) -Update: WebTranslator2 update to 2008-12-17 18:01:03
arabic_egypt - 200 fixed, 28 changed by Azoo4oozi (228)
czech - 3 changed by Hadez (3)
indonesian - 1 fixed, 4 changed by fanioz (5)
korean - 1 changed by leejaeuk5 (1)
latvian - 299 fixed, 3 changed by marismols (302)
lithuanian - 79 fixed by Zogg (79)
serbian - 25 fixed by Jenraux (25)
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
9111
48ce04029fe4 (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: 9070
diff changeset
     3
/** @file engine_gui.cpp GUI to show engine related information. */
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5931
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (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"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     8
#include "window_gui.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8131
diff changeset
     9
#include "gfx_func.h"
8786
1823ff88a054 (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: 8763
diff changeset
    10
#include "engine_func.h"
9070
dd0121143eba (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: 8786
diff changeset
    11
#include "engine_base.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    12
#include "command_func.h"
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    13
#include "economy_func.h"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8626
diff changeset
    14
#include "news_func.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    15
#include "variables.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: 2840
diff changeset
    16
#include "newgrf_engine.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    17
#include "strings_func.h"
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
    18
#include "engine_gui.h"
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
    19
#include "articulated_vehicles.h"
10000
57463dc267a0 (svn r14157) -Codechange: Add and use string properties for rail types instead of relying on consecutive string IDs.
peter1138
parents: 9923
diff changeset
    20
#include "rail.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    22
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    23
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
9199
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9143
diff changeset
    25
StringID GetEngineCategoryName(EngineID engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
{
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    27
	switch (GetEngine(engine)->type) {
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    28
		default: NOT_REACHED();
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
    29
		case VEH_ROAD:              return STR_8103_ROAD_VEHICLE;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
    30
		case VEH_AIRCRAFT:          return STR_8104_AIRCRAFT;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
    31
		case VEH_SHIP:              return STR_8105_SHIP;
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
    32
		case VEH_TRAIN:
10000
57463dc267a0 (svn r14157) -Codechange: Add and use string properties for rail types instead of relying on consecutive string IDs.
peter1138
parents: 9923
diff changeset
    33
			return GetRailTypeInfo(RailVehInfo(engine)->railtype)->strings.new_loco;
460
7506c66ce4c3 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 193
diff changeset
    34
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
static const Widget _engine_preview_widgets[] = {
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9720
diff changeset
    38
{   WWT_CLOSEBOX,  RESIZE_NONE,  COLOUR_LIGHT_BLUE,    0,   10,    0,   13, STR_00C5,                                  STR_018B_CLOSE_WINDOW},
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9720
diff changeset
    39
{    WWT_CAPTION,  RESIZE_NONE,  COLOUR_LIGHT_BLUE,   11,  299,    0,   13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9720
diff changeset
    40
{      WWT_PANEL,  RESIZE_NONE,  COLOUR_LIGHT_BLUE,    0,  299,   14,  191, 0x0,                                       STR_NULL},
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9720
diff changeset
    41
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_LIGHT_BLUE,   85,  144,  172,  183, STR_00C9_NO,                               STR_NULL},
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9720
diff changeset
    42
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_LIGHT_BLUE,  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
    43
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    46
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    47
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
    48
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6209
diff changeset
    49
struct DrawEngineInfo {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	DrawEngineProc *engine_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	DrawEngineInfoProc *info_proc;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6209
diff changeset
    52
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    54
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    55
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    56
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    57
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
    58
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
static const DrawEngineInfo _draw_engine_list[4] = {
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    60
	{ DrawTrainEngine,    DrawTrainEngineInfo    },
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    61
	{ DrawRoadVehEngine,  DrawRoadVehEngineInfo  },
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    62
	{ DrawShipEngine,     DrawShipEngineInfo     },
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    63
	{ DrawAircraftEngine, DrawAircraftEngineInfo },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    66
struct EnginePreviewWindow : Window {
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    67
	EnginePreviewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    68
	{
9333
2da01b3b71d8 (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 9317
diff changeset
    69
		this->FindWindowPlacementAndResize(desc);
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    70
	}
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    71
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    72
	virtual void OnPaint()
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    73
	{
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    74
		this->DrawWidgets();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    76
		EngineID engine = this->window_number;
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    77
		SetDParam(0, GetEngineCategoryName(engine));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
		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
    79
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7002
diff changeset
    80
		SetDParam(0, engine);
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    81
		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
    82
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    83
		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
    84
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    85
		int width = this->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
		dei->engine_proc(width >> 1, 100, engine, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
		dei->info_proc(engine, width >> 1, 130, width - 52);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    88
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    90
	virtual void OnClick(Point pt, int widget)
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    91
	{
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    92
		switch (widget) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    93
			case 4:
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    94
				DoCommandP(0, this->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
5125
d1331d6dbdcb (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 4938
diff changeset
    95
				/* Fallthrough */
d1331d6dbdcb (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 4938
diff changeset
    96
			case 3:
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
    97
				delete this;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    98
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	}
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
   101
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
static const WindowDesc _engine_preview_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   104
	WDP_CENTER, WDP_CENTER, 300, 192, 300, 192,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5868
diff changeset
   105
	WC_ENGINE_PREVIEW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	_engine_preview_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   111
void ShowEnginePreviewWindow(EngineID engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
{
9302
ed4a509cf8fd (svn r13170) -Codechange: make classes of the EnginePreview and BuyCompany windows.
rubidium
parents: 9273
diff changeset
   113
	AllocateWindowDescFront<EnginePreviewWindow>(&_engine_preview_desc, engine);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   116
static uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type)
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   117
{
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   118
	uint total = 0;
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   119
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   120
	uint16 *cap = GetCapacityOfArticulatedParts(engine, type);
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   121
	for (uint c = 0; c < NUM_CARGO; c++) {
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   122
		total += cap[c];
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   123
	}
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   124
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   125
	return total;
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   126
}
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   127
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   128
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   129
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   130
	const RailVehicleInfo *rvi = RailVehInfo(engine);
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7341
diff changeset
   131
	int multihead = (rvi->railveh_type == RAILVEH_MULTIHEAD) ? 1 : 0;
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   132
9923
3056bf623139 (svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138
parents: 9744
diff changeset
   133
	SetDParam(0, (_price.build_railvehicle >> 3) * GetEngineProperty(engine, 0x17, rvi->cost_factor) >> 5);
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   134
	SetDParam(2, GetEngineProperty(engine, 0x09, rvi->max_speed) * 10 / 16);
9720
2a0354eea879 (svn r13844) -Fix (r13074, r13591): Power, running cost and capacity of multiheaded engines were (too often) doubled in newspaper resp. offer window.
frosch
parents: 9607
diff changeset
   135
	SetDParam(3, GetEngineProperty(engine, 0x0B, rvi->power));
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   136
	SetDParam(1, GetEngineProperty(engine, 0x16, rvi->weight) << multihead);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   137
9720
2a0354eea879 (svn r13844) -Fix (r13074, r13591): Power, running cost and capacity of multiheaded engines were (too often) doubled in newspaper resp. offer window.
frosch
parents: 9607
diff changeset
   138
	SetDParam(4, GetEngineProperty(engine, 0x0D, rvi->running_cost) * GetPriceByIndex(rvi->running_cost_class) >> 8);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   139
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   140
	uint capacity = GetTotalCapacityOfArticulatedParts(engine, VEH_TRAIN);
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   141
	if (capacity != 0) {
4896
f86350aaaaa5 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   142
		SetDParam(5, rvi->cargo_type);
9720
2a0354eea879 (svn r13844) -Fix (r13074, r13591): Power, running cost and capacity of multiheaded engines were (too often) doubled in newspaper resp. offer window.
frosch
parents: 9607
diff changeset
   143
		SetDParam(6, capacity);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   144
	} else {
4898
e3962fe14ef8 (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
   145
		SetDParam(5, CT_INVALID);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   146
	}
3401
3eb83140e401 (svn r4211) - Removed measuring units from the names of two strings.
peter1138
parents: 3355
diff changeset
   147
	DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   148
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   149
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   150
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   151
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   152
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
9923
3056bf623139 (svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138
parents: 9744
diff changeset
   153
	SetDParam(0, (_price.aircraft_base >> 3) * GetEngineProperty(engine, 0x0B, avi->cost_factor) >> 5);
6321
de8ff26662e4 (svn r9275) -Fix(r8973, FS#686): Faulty display of aircraft maximum velocity in the news item for new vehicles
celestar
parents: 6259
diff changeset
   154
	SetDParam(1, avi->max_speed * 10 / 16);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   155
	SetDParam(2, avi->passenger_capacity);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   156
	SetDParam(3, avi->mail_capacity);
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   157
	SetDParam(4, GetEngineProperty(engine, 0x0E, avi->running_cost) * _price.aircraft_running >> 8);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   158
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   159
	DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   160
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   161
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   162
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   163
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   164
	const RoadVehicleInfo *rvi = RoadVehInfo(engine);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   165
9923
3056bf623139 (svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138
parents: 9744
diff changeset
   166
	SetDParam(0, (_price.roadveh_base >> 3) * GetEngineProperty(engine, 0x11, rvi->cost_factor) >> 5);
5931
7bf22bf056e2 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 5893
diff changeset
   167
	SetDParam(1, rvi->max_speed * 10 / 32);
8626
9781464622be (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: 8622
diff changeset
   168
	SetDParam(2, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) >> 8);
4896
f86350aaaaa5 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   169
	SetDParam(3, rvi->cargo_type);
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   170
	SetDParam(4, GetTotalCapacityOfArticulatedParts(engine, VEH_ROAD));
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   171
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   172
	DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   173
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   174
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
   175
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   176
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   177
	const ShipVehicleInfo *svi = ShipVehInfo(engine);
9923
3056bf623139 (svn r14078) -Codechange: Rename *VehicleInfo::base_cost to cost_factor, indicating what it actually is.
peter1138
parents: 9744
diff changeset
   178
	SetDParam(0, GetEngineProperty(engine, 0x0A, svi->cost_factor) * (_price.ship_base >> 3) >> 5);
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   179
	SetDParam(1, GetEngineProperty(engine, 0x0B, svi->max_speed) * 10 / 32);
4896
f86350aaaaa5 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4634
diff changeset
   180
	SetDParam(2, svi->cargo_type);
9567
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   181
	SetDParam(3, GetEngineProperty(engine, 0x0D, svi->capacity));
071b2187a176 (svn r13591) -Codechange: Support CB36 in the vehicle offer window.
peter1138
parents: 9404
diff changeset
   182
	SetDParam(4, GetEngineProperty(engine, 0x0F, svi->running_cost) * _price.ship_running >> 8);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   183
	DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   184
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   185
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8626
diff changeset
   186
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   187
{
9199
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9143
diff changeset
   188
	EngineID engine = ni->data_a;
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   189
	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
   190
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   191
	SetDParam(0, GetEngineCategoryName(engine));
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   192
	DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   193
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	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
   195
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7002
diff changeset
   196
	SetDParam(0, engine);
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   197
	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
   198
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   199
	dei->engine_proc(w->width >> 1, 88, engine, 0);
9607
5a5728fb702a (svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents: 9567
diff changeset
   200
	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOR);
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   201
	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
   202
}
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   203
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   204
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   205
/** Sort all items using qsort() and given 'CompareItems' function
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   206
 * @param el list to be sorted
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   207
 * @param compare function for evaluation of the quicksort
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   208
 */
9403
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   209
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   210
{
9403
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   211
	uint size = el->Length();
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   212
	/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   213
	 * generally, do not sort if there are less than 2 items */
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   214
	if (size < 2) return;
9403
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   215
	qsort(el->Begin(), size, sizeof(*el->Begin()), compare); // MorphOS doesn't know vector::at(int) ...
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   216
}
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   217
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   218
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   219
 * @param el list to be sorted
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   220
 * @param compare function for evaluation of the quicksort
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   221
 * @param begin start of sorting
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   222
 * @param num_items count of items to be sorted
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   223
 */
9403
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   224
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   225
{
9404
965b215dcb09 (svn r13315) -Fix (r13314): Assert if no engines or wagons available
peter1138
parents: 9403
diff changeset
   226
	if (num_items < 2) return;
9403
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   227
	assert(begin < el->Length());
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   228
	assert(begin + num_items <= el->Length());
8cfca59c11f1 (svn r13314) -Codechange: Switch EngineList from std::vector to GUIList
peter1138
parents: 9380
diff changeset
   229
	qsort(el->Get(begin), num_items, sizeof(*el->Begin()), compare);
9380
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   230
}
62dabf4a5b7e (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
peter1138
parents: 9333
diff changeset
   231