author | rubidium |
Wed, 19 Dec 2007 19:44:29 +0000 | |
changeset 8602 | 9e75e594a068 |
parent 8320 | 6ffad7a5d242 |
child 8603 | 88c5ce6a5215 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6532
diff
changeset
|
3 |
/** @file roadveh_gui.cpp */ |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6532
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
7 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
8 |
#include "functions.h" |
3959 | 9 |
#include "roadveh.h" |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
10 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
374
diff
changeset
|
11 |
#include "table/strings.h" |
0 | 12 |
#include "gui.h" |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
13 |
#include "strings.h" |
0 | 14 |
#include "vehicle.h" |
15 |
#include "viewport.h" |
|
16 |
#include "command.h" |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
17 |
#include "depot.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2113
diff
changeset
|
18 |
#include "vehicle_gui.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:
2958
diff
changeset
|
19 |
#include "newgrf_engine.h" |
0 | 20 |
|
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
21 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
22 |
void DrawRoadVehDetails(const Vehicle *v, int x, int y) |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
23 |
{ |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
24 |
uint y_offset = RoadVehHasArticPart(v) ? 15 :0; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
25 |
StringID str; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
26 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
27 |
SetDParam(0, v->engine_type); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
28 |
SetDParam(1, v->build_year); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
29 |
SetDParam(2, v->value); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
30 |
DrawString(x, y + y_offset, STR_9011_BUILT_VALUE, TC_FROMSTRING); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
31 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
32 |
if (RoadVehHasArticPart(v)) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
33 |
AcceptedCargo max_cargo; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
34 |
char capacity[512]; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
35 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
36 |
memset(max_cargo, 0, sizeof(max_cargo)); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
37 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
38 |
for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
39 |
max_cargo[u->cargo_type] += u->cargo_cap; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
40 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
41 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
42 |
GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity)); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
43 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
44 |
bool first = true; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
45 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
46 |
if (max_cargo[i] > 0) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
47 |
char buffer[128]; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
48 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
49 |
SetDParam(0, i); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
50 |
SetDParam(1, max_cargo[i]); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
51 |
GetString(buffer, STR_BARE_CARGO, lastof(buffer)); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
52 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
53 |
if (!first) strecat(capacity, ", ", lastof(capacity)); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
54 |
strecat(capacity, buffer, lastof(capacity)); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
55 |
first = false; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
56 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
57 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
58 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
59 |
SetDParamStr(0, capacity); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
60 |
DrawStringTruncated(x, y + 10 + y_offset, STR_JUST_STRING, TC_BLUE, 380 - x); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
61 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
62 |
for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
63 |
str = STR_8812_EMPTY; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
64 |
if (!u->cargo.Empty()) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
65 |
SetDParam(0, u->cargo_type); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
66 |
SetDParam(1, u->cargo.Count()); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
67 |
SetDParam(2, u->cargo.Source()); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
68 |
str = STR_8813_FROM; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
69 |
} |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
70 |
DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
71 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
72 |
y_offset += 11; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
73 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
74 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
75 |
y_offset -= 11; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
76 |
} else { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
77 |
SetDParam(0, v->cargo_type); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
78 |
SetDParam(1, v->cargo_cap); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
79 |
DrawString(x, y + 10 + y_offset, STR_9012_CAPACITY, TC_FROMSTRING); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
80 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
81 |
str = STR_8812_EMPTY; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
82 |
if (!v->cargo.Empty()) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
83 |
SetDParam(0, v->cargo_type); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
84 |
SetDParam(1, v->cargo.Count()); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
85 |
SetDParam(2, v->cargo.Source()); |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
86 |
str = STR_8813_FROM; |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
87 |
} |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
88 |
DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
89 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
90 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
91 |
/* Draw Transfer credits text */ |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
92 |
SetDParam(0, v->cargo.FeederShare()); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
8149
diff
changeset
|
93 |
DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); |
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
94 |
} |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
95 |
|
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
96 |
|
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
97 |
static inline int RoadVehLengthToPixels(int length) |
0 | 98 |
{ |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
99 |
return (length * 28) / 8; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
100 |
} |
0 | 101 |
|
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
102 |
void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selection) |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
103 |
{ |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
104 |
/* Road vehicle lengths are measured in eighths of the standard length, so |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
105 |
* count is the number of standard vehicles that should be drawn. If it is |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
106 |
* 0, we draw enough vehicles for 10 standard vehicle lengths. */ |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
107 |
int max_length = (count == 0) ? 80 : count * 8; |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
108 |
|
8026
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
109 |
for (int dx = 0 ; v != NULL && dx < max_length ; dx += v->u.road.cached_veh_length, v = v->Next()) { |
269979f5319d
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7988
diff
changeset
|
110 |
if (dx + v->u.road.cached_veh_length > 0 && dx <= max_length) { |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
111 |
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
7630
2cd754d7dfa4
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7559
diff
changeset
|
112 |
DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6); |
7353
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
113 |
|
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
114 |
if (v->index == selection) { |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
115 |
DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
116 |
} |
716c6dd9322a
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
7187
diff
changeset
|
117 |
} |
0 | 118 |
} |
119 |
} |
|
120 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
121 |
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 122 |
{ |
4171 | 123 |
const Vehicle *v; |
0 | 124 |
|
125 |
if (!success) return; |
|
126 |
||
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3887
diff
changeset
|
127 |
v = GetVehicle(_new_vehicle_id); |
0 | 128 |
if (v->tile == _backup_orders_tile) { |
129 |
_backup_orders_tile = 0; |
|
8149
eb78fb69096f
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
8026
diff
changeset
|
130 |
RestoreVehicleOrders(v); |
0 | 131 |
} |
7982
539e32cc37ce
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7980
diff
changeset
|
132 |
ShowVehicleViewWindow(v); |
0 | 133 |
} |