OpenTTD Source: src/train_gui.cpp Source File

OpenTTD Source 14.0-beta3

train_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "window_gui.h"
12 #include "command_func.h"
13 #include "train.h"
14 #include "strings_func.h"
15 #include "vehicle_func.h"
16 #include "zoom_func.h"
17 #include "train_cmd.h"
18
19 #include "table/strings.h"
20
21 #include "safeguards.h"
22
29 void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
30 {
31 if (result.Failed()) return;
32
33 /* find a locomotive in the depot. */
34 const Vehicle *found = nullptr;
35 for (const Train *t : Train::Iterate()) {
36 if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) {
37 if (found != nullptr) return; // must be exactly one.
38 found = t;
39 }
40 }
41
42 /* if we found a loco, */
43 if (found != nullptr) {
44 found = found->Last();
45 /* put the new wagon at the end of the loco. */
46 Command<CMD_MOVE_RAIL_VEHICLE>::Post(found->tile, new_veh_id, found->index, false);
47 InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
48 }
49 }
50
60 static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
61 {
62 bool rtl = _current_text_dir == TD_RTL;
63
64 assert(selection != INVALID_VEHICLE);
65 int dragged_width = 0;
66 for (Train *t = Train::Get(selection); t != nullptr; t = chain ? t->Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : nullptr)) {
67 dragged_width += t->GetDisplayImageWidth(nullptr);
68 }
69
70 int drag_hlight_left = rtl ? std::max(px - dragged_width + 1, 0) : px;
71 int drag_hlight_right = rtl ? px : std::min(px + dragged_width, max_width) - 1;
72 int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
73
74 if (drag_hlight_width > 0) {
75 int height = ScaleSpriteTrad(12);
76 int top = y - height / 2;
77 Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
78 /* Sprite-scaling is used here as the area is from sprite size */
79 GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), _colour_gradient[COLOUR_GREY][7]);
80 }
81
82 return drag_hlight_width;
83 }
84
93 void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
94 {
95 bool rtl = _current_text_dir == TD_RTL;
96 Direction dir = rtl ? DIR_E : DIR_W;
97
98 DrawPixelInfo tmp_dpi;
99 /* Position of highlight box */
100 int highlight_l = 0;
101 int highlight_r = 0;
102 int max_width = r.Width();
103
104 if (!FillDrawPixelInfo(&tmp_dpi, r)) return;
105
106 {
107 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
108
109 int px = rtl ? max_width + skip : -skip;
110 int y = r.Height() / 2;
111 bool sel_articulated = false;
112 bool dragging = (drag_dest != INVALID_VEHICLE);
113 bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
114 for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
115 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
116 /* Highlight the drag-and-drop destination inside the train. */
117 int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
118 px += rtl ? -drag_hlight_width : drag_hlight_width;
119 }
120
121 Point offset;
122 int width = Train::From(v)->GetDisplayImageWidth(&offset);
123
124 if (rtl ? px + width > 0 : px - width < max_width) {
125 PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
126 VehicleSpriteSeq seq;
127 v->GetImage(dir, image_type, &seq);
128 seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0);
129 }
130
131 if (!v->IsArticulatedPart()) sel_articulated = false;
132
133 if (v->index == selection) {
134 /* Set the highlight position */
135 highlight_l = rtl ? px - width : px;
136 highlight_r = rtl ? px - 1 : px + width - 1;
137 sel_articulated = true;
138 } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
139 if (rtl) {
140 highlight_l -= width;
141 } else {
142 highlight_r += width;
143 }
144 }
145
146 px += rtl ? -width : width;
147 }
148
149 if (dragging && drag_at_end_of_train) {
150 /* Highlight the drag-and-drop destination at the end of the train. */
151 HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
152 }
153 }
154
155 if (highlight_l != highlight_r) {
156 /* Draw the highlight. Now done after drawing all the engines, as
157 * the next engine after the highlight could overlap it. */
158 int height = ScaleSpriteTrad(12);
159 Rect hr = {highlight_l, 0, highlight_r, height - 1};
160 DrawFrameRect(hr.Translate(r.left, CenterBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FR_BORDERONLY);
161 }
162 }
163
165 struct CargoSummaryItem {
166 CargoID cargo;
167 StringID subtype;
168 uint capacity;
169 uint amount;
170 StationID source;
171
173 inline bool operator != (const CargoSummaryItem &other) const
174 {
175 return this->cargo != other.cargo || this->subtype != other.subtype;
176 }
177
179 inline bool operator == (const CargoSummaryItem &other) const
180 {
181 return !(this->cargo != other.cargo);
182 }
183 };
184
185 static const uint TRAIN_DETAILS_MIN_INDENT = 32;
186 static const uint TRAIN_DETAILS_MAX_INDENT = 72;
187
189 typedef std::vector<CargoSummaryItem> CargoSummary;
191 static CargoSummary _cargo_summary;
192
201 static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
202 {
203 StringID str;
204 if (item->amount > 0) {
205 SetDParam(0, item->cargo);
206 SetDParam(1, item->amount);
207 SetDParam(2, item->source);
208 SetDParam(3, _settings_game.vehicle.freight_trains);
209 str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
210 } else {
211 str = !IsValidCargoID(item->cargo) ? STR_QUANTITY_N_A : STR_VEHICLE_DETAILS_CARGO_EMPTY;
212 }
213
214 DrawString(left, right, y, str, TC_LIGHT_BLUE);
215 }
216
225 static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
226 {
227 if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
228 SetDParam(0, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails));
229 SetDParam(1, v->value);
230 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
231 } else {
232 SetDParam(0, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails));
233 SetDParam(1, v->build_year);
234 SetDParam(2, v->value);
235 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
236 }
237 }
238
247 static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
248 {
249 StringID str;
250 if (IsValidCargoID(item->cargo)) {
251 SetDParam(0, item->cargo);
252 SetDParam(1, item->capacity);
253 SetDParam(4, item->subtype);
254 SetDParam(5, _settings_game.vehicle.freight_trains);
255 str = FreightWagonMult(item->cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY;
256 } else {
257 /* Draw subtype only */
258 SetDParam(0, item->subtype);
259 str = STR_VEHICLE_INFO_NO_CAPACITY;
260 }
261 DrawString(left, right, y, str);
262 }
263
269 static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
270 {
271 summary.clear();
272 do {
273 if (!v->GetEngine()->CanCarryCargo()) continue;
274
275 CargoSummaryItem new_item;
276 new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
277 new_item.subtype = GetCargoSubtypeText(v);
278 if (!IsValidCargoID(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
279
280 auto item = std::find(std::begin(summary), std::end(summary), new_item);
281 if (item == std::end(summary)) {
282 item = summary.emplace(std::end(summary));
283 item->cargo = new_item.cargo;
284 item->subtype = new_item.subtype;
285 item->capacity = 0;
286 item->amount = 0;
287 item->source = INVALID_STATION;
288 }
289
290 item->capacity += v->cargo_cap;
291 item->amount += v->cargo.StoredCount();
292 if (item->source == INVALID_STATION) item->source = v->cargo.GetFirstStation();
293 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
294 }
295
301 static uint GetLengthOfArticulatedVehicle(const Train *v)
302 {
303 uint length = 0;
304
305 do {
306 length += v->GetDisplayImageWidth();
307 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
308
309 return length;
310 }
311
318 int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
319 {
320 int num = 0;
321
322 if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
323 CargoArray max_cargo{};
324 for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
325 max_cargo[v->cargo_type] += v->cargo_cap;
326 }
327
328 num = max_cargo.GetCount();
329 num++; // needs one more because first line is description string
330 } else {
331 for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
332 GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
333 num += std::max(1u, (unsigned)_cargo_summary.size());
334
335 uint length = GetLengthOfArticulatedVehicle(v);
336 if (length > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT)) num++;
337 }
338 }
339
340 return num;
341 }
342
352 void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
353 {
354 bool rtl = _current_text_dir == TD_RTL;
355 int line_height = r.Height();
356 int sprite_y_offset = line_height / 2;
357 int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
358
359 /* draw the first 3 details tabs */
360 if (det_tab != TDW_TAB_TOTALS) {
361 Direction dir = rtl ? DIR_E : DIR_W;
362 int x = rtl ? r.right : r.left;
363 for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
364 GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
365
366 /* Draw sprites */
367 uint dx = 0;
368 int px = x;
369 const Train *u = v;
370 do {
371 Point offset;
372 int width = u->GetDisplayImageWidth(&offset);
373 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
374 int pitch = 0;
375 const Engine *e = Engine::Get(v->engine_type);
376 if (e->GetGRF() != nullptr) {
377 pitch = ScaleSpriteTrad(e->GetGRF()->traininfo_vehicle_pitch);
378 }
379 PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
380 VehicleSpriteSeq seq;
381 u->GetImage(dir, EIT_IN_DETAILS, &seq);
382 seq.Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->vehstatus & VS_CRASHED) != 0);
383 }
384 px += rtl ? -width : width;
385 dx += width;
386 u = u->Next();
387 } while (u != nullptr && u->IsArticulatedPart());
388
389 bool separate_sprite_row = (dx > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT));
390 if (separate_sprite_row) {
391 vscroll_pos--;
392 dx = 0;
393 }
394
395 int sprite_width = std::max<int>(dx, ScaleSpriteTrad(TRAIN_DETAILS_MIN_INDENT)) + WidgetDimensions::scaled.hsep_normal;
396 Rect dr = r.Indent(sprite_width, rtl);
397 uint num_lines = std::max(1u, (unsigned)_cargo_summary.size());
398 for (uint i = 0; i < num_lines; i++) {
399 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
400 int py = r.top - line_height * vscroll_pos + text_y_offset;
401 if (i > 0 || separate_sprite_row) {
402 if (vscroll_pos != 0) GfxFillRect(r.left, py - WidgetDimensions::scaled.matrix.top - 1, r.right, py - WidgetDimensions::scaled.matrix.top, _colour_gradient[COLOUR_GREY][5]);
403 }
404 switch (det_tab) {
405 case TDW_TAB_CARGO:
406 if (i < _cargo_summary.size()) {
407 TrainDetailsCargoTab(&_cargo_summary[i], dr.left, dr.right, py);
408 } else {
409 DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
410 }
411 break;
412
413 case TDW_TAB_INFO:
414 if (i == 0) TrainDetailsInfoTab(v, dr.left, dr.right, py);
415 break;
416
417 case TDW_TAB_CAPACITY:
418 if (i < _cargo_summary.size()) {
419 TrainDetailsCapacityTab(&_cargo_summary[i], dr.left, dr.right, py);
420 } else {
421 SetDParam(0, STR_EMPTY);
422 DrawString(dr.left, dr.right, py, STR_VEHICLE_INFO_NO_CAPACITY);
423 }
424 break;
425
426 default: NOT_REACHED();
427 }
428 }
429 vscroll_pos--;
430 }
431 }
432 } else {
433 int y = r.top;
434 CargoArray act_cargo{};
435 CargoArray max_cargo{};
436 Money feeder_share = 0;
437
438 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
439 act_cargo[u->cargo_type] += u->cargo.StoredCount();
440 max_cargo[u->cargo_type] += u->cargo_cap;
441 feeder_share += u->cargo.GetFeederShare();
442 }
443
444 /* draw total cargo tab */
445 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
446 y += line_height;
447
448 /* Indent the total cargo capacity details */
449 Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
450 for (const CargoSpec *cs : _sorted_cargo_specs) {
451 CargoID cid = cs->Index();
452 if (max_cargo[cid] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
453 SetDParam(0, cid); // {CARGO} #1
454 SetDParam(1, act_cargo[cid]); // {CARGO} #2
455 SetDParam(2, cid); // {SHORTCARGO} #1
456 SetDParam(3, max_cargo[cid]); // {SHORTCARGO} #2
457 SetDParam(4, _settings_game.vehicle.freight_trains);
458 DrawString(ir.left, ir.right, y + text_y_offset, FreightWagonMult(cid) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
459 y += line_height;
460 }
461 }
462 SetDParam(0, feeder_share);
463 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
464 }
465 }
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition: train_cmd.cpp:460
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition: vehicle_base.h:1160
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:434
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
TDW_TAB_CAPACITY
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
Definition: vehicle_gui.h:28
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:271
train.h
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:338
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:168
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1116
CargoArray::GetCount
uint GetCount() const
Get the amount of cargos that have an amount.
Definition: cargo_type.h:125
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition: gfx_type.h:144
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:110
zoom_func.h
CcBuildWagon
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
Definition: train_gui.cpp:29
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition: vehicle_type.h:88
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:153
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
TDW_TAB_INFO
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
Definition: vehicle_gui.h:27
Engine
Definition: engine_base.h:37
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
TrainDetailsCapacityTab
static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details capacity tab for the given vehicle at the given position.
Definition: train_gui.cpp:247
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition: vehicle.cpp:131
VehicleCargoList::GetFirstStation
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
Definition: cargopacket.h:405
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
TRAIN_DETAILS_MIN_INDENT
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
Definition: train_gui.cpp:185
train_cmd.h
GetCargoSummaryOfArticulatedVehicle
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
Collects the cargo transported.
Definition: train_gui.cpp:269
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:940
CargoSummaryItem::capacity
uint capacity
Amount that can be carried.
Definition: train_gui.cpp:168
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:167
GRFFile::traininfo_vehicle_pitch
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition: newgrf.h:145
window_gui.h
CargoSummary
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
Definition: train_gui.cpp:189
CargoSummaryItem::source
StationID source
One of the source stations.
Definition: train_gui.cpp:170
VehicleSettings::freight_trains
uint8_t freight_trains
value to multiply the weight of cargo by
Definition: settings_type.h:529
CommandCost
Common return value for all commands.
Definition: command_type.h:23
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
PackEngineNameDParam
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
Definition: engine_type.h:199
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:54
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:318
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:40
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:131
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:340
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:287
SpecializedVehicle< Train, Type >::Get
static Train * Get(size_t index)
Gets vehicle with given index.
Definition: vehicle_base.h:1182
_cargo_summary
static CargoSummary _cargo_summary
Reused container of cargo details.
Definition: train_gui.cpp:191
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:747
safeguards.h
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
TRAIN_DETAILS_MAX_INDENT
static const uint TRAIN_DETAILS_MAX_INDENT
Maximum indent level in the train details window; wider than this and we start on a new line.
Definition: train_gui.cpp:186
VehicleID
uint32_t VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
TrainDetailsInfoTab
static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
Draw the details info tab for the given vehicle at the given position.
Definition: train_gui.cpp:225
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:308
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
stdafx.h
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1571
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition: vehicle_gui.cpp:1325
HighlightDragPosition
static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
Highlight the position where a rail vehicle is dragged over by drawing a light gray background.
Definition: train_gui.cpp:60
vehicle_func.h
CargoSummaryItem
Helper struct for the cargo details information.
Definition: train_gui.cpp:165
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1602
strings_func.h
DrawTrainDetails
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
Definition: train_gui.cpp:352
CargoSummaryItem::cargo
CargoID cargo
The cargo that is carried.
Definition: train_gui.cpp:166
TrainDetailsCargoTab
static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
Draw the details cargo tab for the given vehicle at the given position.
Definition: train_gui.cpp:201
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:168
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:49
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition: vehicle.cpp:2123
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3217
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
VehicleDetails
@ VehicleDetails
Name is shown in the vehicle details GUI.
Definition: engine_type.h:192
CargoSummaryItem::operator!=
bool operator!=(const CargoSummaryItem &other) const
Used by CargoSummary::Find() and similar functions.
Definition: train_gui.cpp:173
TrainDetailsWindowTabs
TrainDetailsWindowTabs
The tabs in the train details window.
Definition: vehicle_gui.h:25
SpecializedVehicle< Train, Type >::Iterate
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1270
Train::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
Definition: train_cmd.cpp:494
Vehicle::Last
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition: vehicle_base.h:646
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
CommandHelper
Definition: command_func.h:93
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
CargoSummaryItem::amount
uint amount
Amount that is carried.
Definition: train_gui.cpp:169
OverflowSafeInt< int64_t >
CargoSummaryItem::operator==
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
Definition: train_gui.cpp:179
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:103
TDW_TAB_TOTALS
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
Definition: vehicle_gui.h:29
GetLengthOfArticulatedVehicle
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
Definition: train_gui.cpp:301
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Commands
Commands
List of commands.
Definition: command_type.h:187
CargoSummaryItem::subtype
StringID subtype
STR_EMPTY if none.
Definition: train_gui.cpp:167
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
GetTrainDetailsWndVScroll
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Definition: train_gui.cpp:318
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
TDW_TAB_CARGO
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Definition: vehicle_gui.h:26
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
DrawTrainImage
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
Definition: train_gui.cpp:93
FreightWagonMult
byte FreightWagonMult(CargoID cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Definition: train_cmd.cpp:70