author | skidd13 |
Tue, 25 Dec 2007 13:59:21 +0000 | |
changeset 8133 | 3ab8eaf85ca0 |
parent 8131 | 160939e24ed3 |
child 8144 | 65cec0877b78 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6393
e1e4939d19b5
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6206
diff
changeset
|
3 |
/** @file roadveh_gui.cpp */ |
e1e4939d19b5
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6206
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
7 |
#include "debug.h" |
3959 | 8 |
#include "roadveh.h" |
1922
bda6f85eefaa
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1907
diff
changeset
|
9 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
374
diff
changeset
|
10 |
#include "table/strings.h" |
0 | 11 |
#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
|
12 |
#include "window_gui.h" |
0 | 13 |
#include "vehicle.h" |
14 |
#include "viewport.h" |
|
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
15 |
#include "command_func.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
16 |
#include "depot.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2113
diff
changeset
|
17 |
#include "vehicle_gui.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2958
diff
changeset
|
18 |
#include "newgrf_engine.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8107
diff
changeset
|
19 |
#include "strings_func.h" |
0 | 20 |
|
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
21 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
22 |
void DrawRoadVehDetails(const Vehicle *v, int x, int y) |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
23 |
{ |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
24 |
uint y_offset = RoadVehHasArticPart(v) ? 15 :0; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
25 |
StringID str; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
26 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
27 |
SetDParam(0, v->engine_type); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
28 |
SetDParam(1, v->build_year); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
29 |
SetDParam(2, v->value); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
30 |
DrawString(x, y + y_offset, STR_9011_BUILT_VALUE, TC_FROMSTRING); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
31 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
32 |
if (RoadVehHasArticPart(v)) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
33 |
AcceptedCargo max_cargo; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
34 |
char capacity[512]; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
35 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
36 |
memset(max_cargo, 0, sizeof(max_cargo)); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
37 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
38 |
for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
39 |
max_cargo[u->cargo_type] += u->cargo_cap; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
40 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
41 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
42 |
GetString(capacity, STR_ARTICULATED_RV_CAPACITY, lastof(capacity)); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
43 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
44 |
bool first = true; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
45 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
46 |
if (max_cargo[i] > 0) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
47 |
char buffer[128]; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
48 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
49 |
SetDParam(0, i); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
50 |
SetDParam(1, max_cargo[i]); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
51 |
GetString(buffer, STR_BARE_CARGO, lastof(buffer)); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
52 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
53 |
if (!first) strecat(capacity, ", ", lastof(capacity)); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
54 |
strecat(capacity, buffer, lastof(capacity)); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
55 |
first = false; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
56 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
57 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
58 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
59 |
SetDParamStr(0, capacity); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
60 |
DrawStringTruncated(x, y + 10 + y_offset, STR_JUST_STRING, TC_BLUE, 380 - x); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
61 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
62 |
for (const Vehicle *u = v; u != NULL; u = u->Next()) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
63 |
str = STR_8812_EMPTY; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
64 |
if (!u->cargo.Empty()) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
65 |
SetDParam(0, u->cargo_type); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
66 |
SetDParam(1, u->cargo.Count()); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
67 |
SetDParam(2, u->cargo.Source()); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
68 |
str = STR_8813_FROM; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
69 |
} |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
70 |
DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
71 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
72 |
y_offset += 11; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
73 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
74 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
75 |
y_offset -= 11; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
76 |
} else { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
77 |
SetDParam(0, v->cargo_type); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
78 |
SetDParam(1, v->cargo_cap); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
79 |
DrawString(x, y + 10 + y_offset, STR_9012_CAPACITY, TC_FROMSTRING); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
80 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
81 |
str = STR_8812_EMPTY; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
82 |
if (!v->cargo.Empty()) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
83 |
SetDParam(0, v->cargo_type); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
84 |
SetDParam(1, v->cargo.Count()); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
85 |
SetDParam(2, v->cargo.Source()); |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
86 |
str = STR_8813_FROM; |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
87 |
} |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
88 |
DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
89 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
90 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
91 |
/* Draw Transfer credits text */ |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
92 |
SetDParam(0, v->cargo.FeederShare()); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
7653
diff
changeset
|
93 |
DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); |
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
94 |
} |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
95 |
|
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
96 |
|
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
97 |
static inline int RoadVehLengthToPixels(int length) |
0 | 98 |
{ |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
99 |
return (length * 28) / 8; |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
100 |
} |
0 | 101 |
|
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
102 |
void DrawRoadVehImage(const Vehicle *v, int x, int y, int count, VehicleID selection) |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
103 |
{ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
104 |
/* Road vehicle lengths are measured in eighths of the standard length, so |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
105 |
* count is the number of standard vehicles that should be drawn. If it is |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
106 |
* 0, we draw enough vehicles for 10 standard vehicle lengths. */ |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
107 |
int max_length = (count == 0) ? 80 : count * 8; |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
108 |
|
7530
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
109 |
for (int dx = 0 ; v != NULL && dx < max_length ; dx += v->u.road.cached_veh_length, v = v->Next()) { |
bfeada535347
(svn r11049) -Codechange: unify a large part of the vehicle details window. Based on a patch by nycom.
rubidium
parents:
7492
diff
changeset
|
110 |
if (dx + v->u.road.cached_veh_length > 0 && dx <= max_length) { |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
111 |
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
7134
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7063
diff
changeset
|
112 |
DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6); |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
113 |
|
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
114 |
if (v->index == selection) { |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
115 |
DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
116 |
} |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6691
diff
changeset
|
117 |
} |
0 | 118 |
} |
119 |
} |
|
120 |
||
1977
37bbebf94434
(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
a09379beffd5
(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; |
|
7653
dd252420d9c2
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
7530
diff
changeset
|
130 |
RestoreVehicleOrders(v); |
0 | 131 |
} |
7486
bf6a94009823
(svn r10997) -Codechange: unify the vehicle view window. Patch by PhilSophus.
rubidium
parents:
7484
diff
changeset
|
132 |
ShowVehicleViewWindow(v); |
0 | 133 |
} |