src/engine_gui.cpp
author skidd13
Sun, 02 Dec 2007 21:43:16 +0000
changeset 8004 1c54bc6f4bdf
parent 7824 5a63d41b59ea
child 8106 e6790dd9e750
permissions -rw-r--r--
(svn r11563) -Codechange: Align the preprocessor code in stdafx.h with tabs
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
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5931
diff changeset
     3
/** @file engine_gui.cpp */
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"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 460
diff changeset
     7
#include "table/strings.h"
7266
b16e67e992b4 (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7059
diff changeset
     8
#include "strings.h"
2218
2132596a35c0 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
     9
#include "table/sprites.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    10
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "news.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    18
#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
    19
#include "newgrf_engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
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
    22
static StringID GetEngineCategoryName(EngineID engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
{
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    24
	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
    25
		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
    26
		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
    27
		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
    28
		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
    29
		case VEH_TRAIN:
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    30
			switch (RailVehInfo(engine)->railtype) {
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    31
				default: NOT_REACHED();
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    32
				case RAILTYPE_RAIL:     return STR_8102_RAILROAD_LOCOMOTIVE;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    33
				case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    34
				case RAILTYPE_MONO:     return STR_8106_MONORAIL_LOCOMOTIVE;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    35
				case RAILTYPE_MAGLEV:   return STR_8107_MAGLEV_LOCOMOTIVE;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    36
			}
460
7506c66ce4c3 (svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents: 193
diff changeset
    37
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
}
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
static const Widget _engine_preview_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: 3477
diff changeset
    41
{   WWT_CLOSEBOX,   RESIZE_NONE,     5,     0,    10,     0,    13, STR_00C5,                                  STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
    42
{    WWT_CAPTION,   RESIZE_NONE,     5,    11,   299,     0,    13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4898
diff changeset
    43
{      WWT_PANEL,   RESIZE_NONE,     5,     0,   299,    14,   191, 0x0,                                       STR_NULL},
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: 3477
diff changeset
    44
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     5,    85,   144,   172,   183, STR_00C9_NO,                               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: 3477
diff changeset
    45
{ 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
    46
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    49
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
    50
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
    51
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6209
diff changeset
    52
struct DrawEngineInfo {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	DrawEngineProc *engine_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	DrawEngineInfoProc *info_proc;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6209
diff changeset
    55
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
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
    57
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
    58
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
    59
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
    60
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
    61
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
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
    63
	{ 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
    64
	{ 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
    65
	{ 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
    66
	{ DrawAircraftEngine, DrawAircraftEngineInfo },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
};
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
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    71
	switch (e->event) {
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
    72
	case WE_PAINT: {
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2436
diff changeset
    73
		EngineID engine = w->window_number;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    74
		const DrawEngineInfo* dei;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    75
		int width;
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
    76
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    79
		SetDParam(0, GetEngineCategoryName(engine));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
		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
    81
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7002
diff changeset
    82
		SetDParam(0, engine);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
    83
		DrawStringCentered(w->width >> 1, 80, STR_ENGINE_NAME, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
    85
		dei = &_draw_engine_list[GetEngine(engine)->type];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
		width = w->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
		dei->engine_proc(width >> 1, 100, engine, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
		dei->info_proc(engine, width >> 1, 130, width - 52);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
		break;
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
    91
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4344
diff changeset
    94
		switch (e->we.click.widget) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    95
			case 4:
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    96
				DoCommandP(0, w->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
    97
				/* Fallthrough */
d1331d6dbdcb (svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
Darkvater
parents: 4938
diff changeset
    98
			case 3:
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
    99
				DeleteWindow(w);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2549
diff changeset
   100
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
		break;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
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
   107
	WDP_CENTER, WDP_CENTER, 300, 192, 300, 192,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5868
diff changeset
   108
	WC_ENGINE_PREVIEW, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	_engine_preview_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	EnginePreviewWndProc
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
225b2916fe2a (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
{
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5125
diff changeset
   117
	AllocateWindowDescFront(&_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
225b2916fe2a (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
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   121
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   122
	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
   123
	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
   124
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   125
	SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
5931
7bf22bf056e2 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 5893
diff changeset
   126
	SetDParam(2, rvi->max_speed * 10 / 16);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   127
	SetDParam(3, rvi->power << multihead);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   128
	SetDParam(1, rvi->weight << multihead);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   129
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   130
	SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8 << multihead);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   131
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   132
	if (rvi->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
   133
		SetDParam(5, rvi->cargo_type);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   134
		SetDParam(6, rvi->capacity << multihead);
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2519
diff changeset
   135
	} 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
   136
		SetDParam(5, CT_INVALID);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   137
	}
3401
3eb83140e401 (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
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   139
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   140
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
   141
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
   142
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   143
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   144
	SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 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
   145
	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
   146
	SetDParam(2, avi->passenger_capacity);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   147
	SetDParam(3, avi->mail_capacity);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   148
	SetDParam(4, 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
   149
23c42534e2a9 (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);
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
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
   153
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
   154
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   155
	const RoadVehicleInfo *rvi = RoadVehInfo(engine);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   156
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   157
	SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5);
5931
7bf22bf056e2 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 5893
diff changeset
   158
	SetDParam(1, rvi->max_speed * 10 / 32);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   159
	SetDParam(2, rvi->running_cost * _price.roadveh_running >> 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
   160
	SetDParam(3, rvi->cargo_type);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   161
	SetDParam(4, rvi->capacity);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   162
23c42534e2a9 (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);
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   164
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   165
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
   166
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
   167
{
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   168
	const ShipVehicleInfo *svi = ShipVehInfo(engine);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   169
	SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5);
5931
7bf22bf056e2 (svn r8569) -Fix (r8464): revert properly
peter1138
parents: 5893
diff changeset
   170
	SetDParam(1, 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
   171
	SetDParam(2, svi->cargo_type);
1998
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   172
	SetDParam(3, svi->capacity);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   173
	SetDParam(4, 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
   174
	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
   175
}
23c42534e2a9 (svn r2504) Move Draw*EngineInfo to engine_gui.c to reduce dependencies
tron
parents: 1926
diff changeset
   176
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   177
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   178
StringID GetNewsStringNewVehicleAvail(const NewsItem *ni)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
{
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   180
	EngineID engine = ni->string_id;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   181
	SetDParam(0, GetEngineCategoryName(engine));
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7002
diff changeset
   182
	SetDParam(1, 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
   183
	return STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   184
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   186
void DrawNewsNewVehicleAvail(Window *w)
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   187
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	DrawNewsBorder(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   190
	EngineID engine = WP(w, news_d).ni->string_id;
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   191
	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
   192
6209
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   193
	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
   194
	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
   195
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	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
   197
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7002
diff changeset
   198
	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
   199
	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
   200
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->engine_proc(w->width >> 1, 88, engine, 0);
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   202
	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
3a1a90cd67f3 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6208
diff changeset
   203
	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
   204
}