OpenTTD Source: src/train_gui.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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, CargoType, ClientID)
30{
31 if (result.Failed()) return;
32
33 /* find a locomotive in the depot. */
34 const Vehicle *found = nullptr;
35 /* The non-deterministic order returned from VehiclesOnTile() does not
36 * matter here as there must only be one locomotive for anything to happen. */
37 for (const Vehicle *v : VehiclesOnTile(tile)) {
38 if (v->type != VEH_TRAIN) continue;
39
40 const Train *t = Train::From(v);
41 if (t->IsFrontEngine() && t->IsStoppedInDepot()) {
42 if (found != nullptr) return; // must be exactly one.
43 found = t;
44 }
45 }
46
47 /* if we found a loco, */
48 if (found != nullptr) {
49 found = found->Last();
50 /* put the new wagon at the end of the loco. */
51 Command<CMD_MOVE_RAIL_VEHICLE>::Post(found->tile, new_veh_id, found->index, false);
52 InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
53 }
54}
55
65 static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain)
66{
67 bool rtl = _current_text_dir == TD_RTL;
68
69 assert(selection != VehicleID::Invalid());
70 int dragged_width = 0;
71 for (Train *t = Train::Get(selection); t != nullptr; t = chain ? t->Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : nullptr)) {
72 dragged_width += t->GetDisplayImageWidth(nullptr);
73 }
74
75 int drag_hlight_left = rtl ? std::max(px - dragged_width + 1, 0) : px;
76 int drag_hlight_right = rtl ? px : std::min(px + dragged_width, max_width) - 1;
77 int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0);
78
79 if (drag_hlight_width > 0) {
80 int height = ScaleSpriteTrad(12);
81 int top = y - height / 2;
82 Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
83 /* Sprite-scaling is used here as the area is from sprite size */
84 GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
85 }
86
87 return drag_hlight_width;
88}
89
98 void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
99{
100 bool rtl = _current_text_dir == TD_RTL;
101 Direction dir = rtl ? DIR_E : DIR_W;
102
103 DrawPixelInfo tmp_dpi;
104 /* Position of highlight box */
105 int highlight_l = 0;
106 int highlight_r = 0;
107 int max_width = r.Width();
108
109 if (!FillDrawPixelInfo(&tmp_dpi, r)) return;
110
111 {
112 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
113
114 bool do_overlays = ShowCargoIconOverlay();
115 /* List of overlays, only used if cargo icon overlays are enabled. */
116 static std::vector<CargoIconOverlay> overlays;
117
118 int px = rtl ? max_width + skip : -skip;
119 int y = r.Height() / 2;
120 bool sel_articulated = false;
121 bool dragging = (drag_dest != VehicleID::Invalid());
122 bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train.
123 for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) {
124 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
125 /* Highlight the drag-and-drop destination inside the train. */
126 int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
127 px += rtl ? -drag_hlight_width : drag_hlight_width;
128 }
129
130 Point offset;
131 int width = Train::From(v)->GetDisplayImageWidth(&offset);
132
133 if (rtl ? px + width > 0 : px - width < max_width) {
134 PaletteID pal = v->vehstatus.Test(VehState::Crashed) ? PALETTE_CRASH : GetVehiclePalette(v);
135 VehicleSpriteSeq seq;
136 v->GetImage(dir, image_type, &seq);
137 seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, v->vehstatus.Test(VehState::Crashed));
138 }
139
140 if (!v->IsArticulatedPart()) sel_articulated = false;
141
142 if (v->index == selection) {
143 /* Set the highlight position */
144 highlight_l = rtl ? px - width : px;
145 highlight_r = rtl ? px - 1 : px + width - 1;
146 sel_articulated = true;
147 } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
148 if (rtl) {
149 highlight_l -= width;
150 } else {
151 highlight_r += width;
152 }
153 }
154
155 if (do_overlays) AddCargoIconOverlay(overlays, px, width, v);
156 px += rtl ? -width : width;
157 }
158
159 if (do_overlays) {
160 DrawCargoIconOverlays(overlays, y);
161 overlays.clear();
162 }
163
164 if (dragging && drag_at_end_of_train) {
165 /* Highlight the drag-and-drop destination at the end of the train. */
166 HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain);
167 }
168 }
169
170 if (highlight_l != highlight_r) {
171 /* Draw the highlight. Now done after drawing all the engines, as
172 * the next engine after the highlight could overlap it. */
173 int height = ScaleSpriteTrad(12);
174 Rect hr = {highlight_l, 0, highlight_r, height - 1};
175 DrawFrameRect(hr.Translate(r.left, CentreBounds(r.top, r.bottom, height)).Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly);
176 }
177}
178
180 struct CargoSummaryItem {
181 CargoType cargo;
182 StringID subtype;
183 uint capacity;
184 uint amount;
185 StationID source;
186
188 inline bool operator == (const CargoSummaryItem &other) const
189 {
190 return !(this->cargo != other.cargo);
191 }
192};
193
194 static const uint TRAIN_DETAILS_MIN_INDENT = 32;
195 static const uint TRAIN_DETAILS_MAX_INDENT = 72;
196
198 typedef std::vector<CargoSummaryItem> CargoSummary;
200 static CargoSummary _cargo_summary;
201
210 static void TrainDetailsCargoTab(const CargoSummaryItem *item, int left, int right, int y)
211{
212 std::string str;
213 if (!IsValidCargoType(item->cargo)) {
214 str = GetString(STR_QUANTITY_N_A);
215 } else if (item->amount == 0) {
216 str = GetString(STR_VEHICLE_DETAILS_CARGO_EMPTY);
217 } else if (FreightWagonMult(item->cargo) > 1) {
218 str = GetString(STR_VEHICLE_DETAILS_CARGO_FROM_MULT, item->cargo, item->amount, item->source, _settings_game.vehicle.freight_trains);
219 } else {
220 str = GetString(STR_VEHICLE_DETAILS_CARGO_FROM, item->cargo, item->amount, item->source);
221 }
222 DrawString(left, right, y, str, TC_LIGHT_BLUE);
223}
224
233 static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
234{
235 std::string str;
236 if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
237 str = GetString(STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->value);
238 } else {
239 str = GetString(STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE, PackEngineNameDParam(v->engine_type, EngineNameContext::VehicleDetails), v->build_year, v->value);
240 }
241 DrawString(left, right, y, str);
242}
243
252 static void TrainDetailsCapacityTab(const CargoSummaryItem *item, int left, int right, int y)
253{
254 std::string str;
255 if (!IsValidCargoType(item->cargo)) {
256 /* Draw subtype only */
257 str = GetString(STR_VEHICLE_INFO_NO_CAPACITY, item->subtype);
258 } else if (FreightWagonMult(item->cargo) > 1) {
259 str = GetString(STR_VEHICLE_INFO_CAPACITY_MULT, item->cargo, item->capacity, item->subtype, _settings_game.vehicle.freight_trains);
260 } else {
261 str = GetString(STR_VEHICLE_INFO_CAPACITY, item->cargo, item->capacity, item->subtype);
262 }
263 DrawString(left, right, y, str);
264}
265
271 static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
272{
273 summary.clear();
274 do {
275 if (!v->GetEngine()->CanCarryCargo()) continue;
276
277 CargoSummaryItem new_item;
278 new_item.cargo = v->cargo_cap > 0 ? v->cargo_type : INVALID_CARGO;
279 new_item.subtype = GetCargoSubtypeText(v);
280 if (!IsValidCargoType(new_item.cargo) && new_item.subtype == STR_EMPTY) continue;
281
282 auto item = std::ranges::find(summary, new_item);
283 if (item == std::end(summary)) {
284 item = summary.emplace(std::end(summary));
285 item->cargo = new_item.cargo;
286 item->subtype = new_item.subtype;
287 item->capacity = 0;
288 item->amount = 0;
289 item->source = StationID::Invalid();
290 }
291
292 item->capacity += v->cargo_cap;
293 item->amount += v->cargo.StoredCount();
294 if (item->source == StationID::Invalid()) item->source = v->cargo.GetFirstStation();
295 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
296}
297
303 static uint GetLengthOfArticulatedVehicle(const Train *v)
304{
305 uint length = 0;
306
307 do {
308 length += v->GetDisplayImageWidth();
309 } while ((v = v->Next()) != nullptr && v->IsArticulatedPart());
310
311 return length;
312}
313
320 int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
321{
322 int num = 0;
323
324 if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
325 CargoArray max_cargo{};
326 for (const Vehicle *v = Vehicle::Get(veh_id); v != nullptr; v = v->Next()) {
327 max_cargo[v->cargo_type] += v->cargo_cap;
328 }
329
330 num = max_cargo.GetCount();
331 num++; // needs one more because first line is description string
332 } else {
333 for (const Train *v = Train::Get(veh_id); v != nullptr; v = v->GetNextVehicle()) {
334 GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
335 num += std::max(1u, (unsigned)_cargo_summary.size());
336
337 uint length = GetLengthOfArticulatedVehicle(v);
338 if (length > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT)) num++;
339 }
340 }
341
342 return num;
343}
344
354 void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
355{
356 bool rtl = _current_text_dir == TD_RTL;
357 int line_height = r.Height();
358 int sprite_y_offset = line_height / 2;
359 int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
360
361 /* draw the first 3 details tabs */
362 if (det_tab != TDW_TAB_TOTALS) {
363 Direction dir = rtl ? DIR_E : DIR_W;
364 int x = rtl ? r.right : r.left;
365 for (; v != nullptr && vscroll_pos > -vscroll_cap; v = v->GetNextVehicle()) {
366 GetCargoSummaryOfArticulatedVehicle(v, _cargo_summary);
367
368 /* Draw sprites */
369 uint dx = 0;
370 int px = x;
371 const Train *u = v;
372 do {
373 Point offset;
374 int width = u->GetDisplayImageWidth(&offset);
375 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
376 int pitch = 0;
377 const Engine *e = Engine::Get(v->engine_type);
378 if (e->GetGRF() != nullptr) {
379 pitch = ScaleSpriteTrad(e->GetGRF()->traininfo_vehicle_pitch);
380 }
381 PaletteID pal = v->vehstatus.Test(VehState::Crashed) ? PALETTE_CRASH : GetVehiclePalette(u);
382 VehicleSpriteSeq seq;
383 u->GetImage(dir, EIT_IN_DETAILS, &seq);
384 seq.Draw(px + (rtl ? -offset.x : offset.x), r.top - line_height * vscroll_pos + sprite_y_offset + pitch, pal, v->vehstatus.Test(VehState::Crashed));
385 }
386 px += rtl ? -width : width;
387 dx += width;
388 u = u->Next();
389 } while (u != nullptr && u->IsArticulatedPart());
390
391 bool separate_sprite_row = (dx > (uint)ScaleSpriteTrad(TRAIN_DETAILS_MAX_INDENT));
392 if (separate_sprite_row) {
393 vscroll_pos--;
394 dx = 0;
395 }
396
397 int sprite_width = std::max<int>(dx, ScaleSpriteTrad(TRAIN_DETAILS_MIN_INDENT)) + WidgetDimensions::scaled.hsep_normal;
398 Rect dr = r.Indent(sprite_width, rtl);
399 uint num_lines = std::max(1u, (unsigned)_cargo_summary.size());
400 for (uint i = 0; i < num_lines; i++) {
401 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
402 int py = r.top - line_height * vscroll_pos + text_y_offset;
403 if (i > 0 || separate_sprite_row) {
404 if (vscroll_pos != 0) GfxFillRect(r.WithY(py - WidgetDimensions::scaled.matrix.top - 1, py - WidgetDimensions::scaled.matrix.top), GetColourGradient(COLOUR_GREY, SHADE_LIGHT));
405 }
406 switch (det_tab) {
407 case TDW_TAB_CARGO:
408 if (i < _cargo_summary.size()) {
409 TrainDetailsCargoTab(&_cargo_summary[i], dr.left, dr.right, py);
410 } else {
411 DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
412 }
413 break;
414
415 case TDW_TAB_INFO:
416 if (i == 0) TrainDetailsInfoTab(v, dr.left, dr.right, py);
417 break;
418
419 case TDW_TAB_CAPACITY:
420 if (i < _cargo_summary.size()) {
421 TrainDetailsCapacityTab(&_cargo_summary[i], dr.left, dr.right, py);
422 } else {
423 DrawString(dr.left, dr.right, py, GetString(STR_VEHICLE_INFO_NO_CAPACITY, STR_EMPTY));
424 }
425 break;
426
427 default: NOT_REACHED();
428 }
429 }
430 vscroll_pos--;
431 }
432 }
433 } else {
434 int y = r.top;
435 CargoArray act_cargo{};
436 CargoArray max_cargo{};
437 Money feeder_share = 0;
438
439 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
440 act_cargo[u->cargo_type] += u->cargo.StoredCount();
441 max_cargo[u->cargo_type] += u->cargo_cap;
442 feeder_share += u->cargo.GetFeederShare();
443 }
444
445 /* draw total cargo tab */
446 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
447 y += line_height;
448
449 /* Indent the total cargo capacity details */
450 Rect ir = r.Indent(WidgetDimensions::scaled.hsep_indent, rtl);
451 for (const CargoSpec *cs : _sorted_cargo_specs) {
452 CargoType cargo_type = cs->Index();
453 if (max_cargo[cargo_type] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
454 std::string str;
455 if (FreightWagonMult(cargo_type) > 1) {
456 str = GetString(STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT, cargo_type, act_cargo[cargo_type], cargo_type, max_cargo[cargo_type], _settings_game.vehicle.freight_trains);
457 } else {
458 str = GetString(STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY, cargo_type, act_cargo[cargo_type], cargo_type, max_cargo[cargo_type]);
459 }
460 DrawString(ir.left, ir.right, y + text_y_offset, str);
461 y += line_height;
462 }
463 }
464 DrawString(r.left, r.right, y + text_y_offset, GetString(STR_VEHICLE_INFO_FEEDER_CARGO_VALUE, feeder_share));
465 }
466}
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition cargotype.cpp:190
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:177
Engine
Definition engine_base.h:38
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition engine_base.h:166
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition engine.cpp:167
OverflowSafeInt< int64_t >
VehicleCargoList::GetFirstStation
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
Definition cargopacket.h:396
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition cargopacket.h:425
VehiclesOnTile
Iterate over all vehicles on a tile.
Definition vehicle_func.h:53
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:61
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
command_func.h
Functions related to commands.
Commands
Commands
List of commands.
Definition command_type.h:196
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
DIR_W
@ DIR_W
West.
Definition direction_type.h:32
DIR_E
@ DIR_E
East.
Definition direction_type.h:28
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:239
EngineNameContext::VehicleDetails
@ VehicleDetails
Name is shown in the vehicle details GUI.
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:34
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
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:665
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
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:1565
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
ClientID
ClientID
'Unique' identifier to be given to clients
Definition network_type.h:43
GetColourGradient
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition sprites.h:1619
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition backup_type.hpp:150
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
CargoArray::GetCount
uint GetCount() const
Get the amount of cargos that have an amount.
Definition cargo_type.h:126
CargoSpec
Specification of a cargo type.
Definition cargotype.h:74
CargoSummaryItem
Helper struct for the cargo details information.
Definition train_gui.cpp:180
CargoSummaryItem::subtype
StringID subtype
STR_EMPTY if none.
Definition train_gui.cpp:182
CargoSummaryItem::operator==
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
Definition train_gui.cpp:188
CargoSummaryItem::amount
uint amount
Amount that is carried.
Definition train_gui.cpp:184
CargoSummaryItem::capacity
uint capacity
Amount that can be carried.
Definition train_gui.cpp:183
CargoSummaryItem::source
StationID source
One of the source stations.
Definition train_gui.cpp:185
CargoSummaryItem::cargo
CargoType cargo
The cargo that is carried.
Definition train_gui.cpp:181
CommandHelper
Definition command_func.h:83
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
CursorVars::vehchain
bool vehchain
vehicle chain is dragged
Definition gfx_type.h:150
DrawPixelInfo
Data about how and where to blit pixels.
Definition gfx_type.h:157
GRFFile::traininfo_vehicle_pitch
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition newgrf.h:154
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF >
Pool::PoolItem<&_vehicle_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::Width
int Width() const
Get width of Rect.
Definition geometry_type.hpp:111
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
Rect::Height
int Height() const
Get height of Rect.
Definition geometry_type.hpp:117
Rect::WithY
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
Definition geometry_type.hpp:280
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition geometry_type.hpp:179
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition vehicle_base.h:1049
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1134
SpecializedVehicle::GetNextVehicle
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
Definition vehicle_base.h:1093
SpecializedVehicle::Get
static T * Get(auto index)
Gets vehicle with given index.
Definition vehicle_base.h:1115
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Train
'Train' is either a loco or a wagon.
Definition train.h:91
Train::GetImage
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
Definition train_cmd.cpp:491
Train::GetDisplayImageWidth
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Definition train_cmd.cpp:457
VehicleSettings::freight_trains
uint8_t freight_trains
value to multiply the weight of cargo by
Definition settings_type.h:531
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition vehicle_base.h:102
VehicleSpriteSeq::Draw
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
Definition vehicle.cpp:142
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition vehicle_base.h:278
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition vehicle.cpp:718
Vehicle::IsStoppedInDepot
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition vehicle_base.h:515
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition vehicle_base.h:296
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition vehicle_base.h:299
Vehicle::Last
Vehicle * Last()
Get the last vehicle of this vehicle chain.
Definition vehicle_base.h:606
Vehicle::vehstatus
VehStates vehstatus
Status.
Definition vehicle_base.h:309
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition vehicle_base.h:922
Vehicle::cargo_type
CargoType cargo_type
type of cargo this vehicle is carrying
Definition vehicle_base.h:297
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition vehicle_base.h:587
Vehicle::value
Money value
Value of the vehicle.
Definition vehicle_base.h:236
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition vehicle_base.h:913
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition vehicle_base.h:252
train.h
Base for the train class.
FreightWagonMult
uint8_t FreightWagonMult(CargoType cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Definition train_cmd.cpp:68
train_cmd.h
Command definitions related to trains.
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:98
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:65
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:233
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:252
GetLengthOfArticulatedVehicle
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
Definition train_gui.cpp:303
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:354
GetCargoSummaryOfArticulatedVehicle
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
Collects the cargo transported.
Definition train_gui.cpp:271
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:195
CargoSummary
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
Definition train_gui.cpp:198
GetTrainDetailsWndVScroll
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
Definition train_gui.cpp:320
CcBuildWagon
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
Callback for building wagons.
Definition train_gui.cpp:29
_cargo_summary
static CargoSummary _cargo_summary
Reused container of cargo details.
Definition train_gui.cpp:200
TRAIN_DETAILS_MIN_INDENT
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
Definition train_gui.cpp:194
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:210
GetVehiclePalette
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
Definition vehicle.cpp:2133
VehState::Crashed
@ Crashed
Vehicle is crashed.
vehicle_func.h
Functions related to vehicles.
GetCargoSubtypeText
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
Definition vehicle_gui.cpp:1387
DrawCargoIconOverlays
void DrawCargoIconOverlays(std::span< const CargoIconOverlay > overlays, int y)
Draw a list of cargo icon overlays.
Definition vehicle_gui.cpp:401
AddCargoIconOverlay
void AddCargoIconOverlay(std::vector< CargoIconOverlay > &overlays, int x, int width, const Vehicle *v)
Add a cargo icon to the list of overlays.
Definition vehicle_gui.cpp:349
ShowCargoIconOverlay
bool ShowCargoIconOverlay()
Test if cargo icon overlays should be drawn.
Definition vehicle_gui.cpp:337
TrainDetailsWindowTabs
TrainDetailsWindowTabs
The tabs in the train details window.
Definition vehicle_gui.h:25
TDW_TAB_CAPACITY
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
Definition vehicle_gui.h:28
TDW_TAB_TOTALS
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
Definition vehicle_gui.h:29
TDW_TAB_INFO
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
Definition vehicle_gui.h:27
TDW_TAB_CARGO
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
Definition vehicle_gui.h:26
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:74
EIT_IN_DETAILS
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
Definition vehicle_type.h:77
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:289
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:3311
window_gui.h
Functions, definitions and such used only by the GUI.
FrameFlag::BorderOnly
@ BorderOnly
Draw border only, no background.
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition window_type.h:313
zoom_func.h
Functions related to zooming.
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107