19#include "table/strings.h"
29void CcBuildWagon(
Commands,
const CommandCost &result,
VehicleID new_veh_id, uint, uint16_t,
CargoArray,
TileIndex tile,
EngineID,
bool,
CargoType,
ClientID)
31 if (result.
Failed())
return;
42 if (found !=
nullptr)
return;
48 if (found !=
nullptr) {
49 found = found->
Last();
51 Command<Commands::MoveRailVehicle>::Post(found->
tile, new_veh_id, found->index,
false);
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);
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);
79 if (drag_hlight_width > 0) {
81 int top = y - height / 2;
82 Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1};
87 return drag_hlight_width;
108 int max_width = r.
Width();
117 static std::vector<CargoIconOverlay> overlays;
119 int px = rtl ? max_width + skip : -skip;
121 bool sel_articulated =
false;
122 bool dragging = (drag_dest != VehicleID::Invalid());
123 bool drag_at_end_of_train = (drag_dest == v->index);
124 for (; v !=
nullptr && (rtl ? px > 0 : px < max_width); v = v->
Next()) {
125 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
128 px += rtl ? -drag_hlight_width : drag_hlight_width;
134 if (rtl ? px + width > 0 : px - width < max_width) {
143 if (v->index == selection) {
145 highlight_l = rtl ? px - width : px;
146 highlight_r = rtl ? px - 1 : px + width - 1;
147 sel_articulated =
true;
148 }
else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
150 highlight_l -= width;
152 highlight_r += width;
157 px += rtl ? -width : width;
165 if (dragging && drag_at_end_of_train) {
171 if (highlight_l != highlight_r) {
175 Rect hr = {highlight_l, 0, highlight_r, height - 1};
191 return !(this->cargo != other.
cargo);
216 }
else if (item->
amount == 0) {
217 str =
GetString(STR_VEHICLE_DETAILS_CARGO_EMPTY);
223 DrawString(left, right, y, str, TC_LIGHT_BLUE);
283 auto item = std::ranges::find(summary, new_item);
284 if (item == std::end(summary)) {
285 item = summary.emplace(std::end(summary));
286 item->cargo = new_item.
cargo;
287 item->subtype = new_item.
subtype;
290 item->source = StationID::Invalid();
328 max_cargo[v->cargo_type] += v->cargo_cap;
334 for (
const Train *v =
Train::Get(veh_id); v !=
nullptr; v = v->GetNextVehicle()) {
358 int line_height = r.
Height();
359 int sprite_y_offset = line_height / 2;
365 int x = rtl ? r.right : r.left;
366 for (; v !=
nullptr && vscroll_pos > -vscroll_cap; v = v->
GetNextVehicle()) {
376 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
379 if (e->
GetGRF() !=
nullptr) {
387 px += rtl ? -width : width;
393 if (separate_sprite_row) {
401 for (uint i = 0; i < num_lines; i++) {
402 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
403 int py = r.top - line_height * vscroll_pos + text_y_offset;
404 if (i > 0 || separate_sprite_row) {
412 DrawString(dr.left, dr.right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
428 default: NOT_REACHED();
438 Money feeder_share = 0;
440 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
441 act_cargo[u->cargo_type] += u->cargo.StoredCount();
442 max_cargo[u->cargo_type] += u->cargo_cap;
443 feeder_share += u->cargo.GetFeederShare();
447 DrawString(r.left, r.right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
454 if (max_cargo[cargo_type] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
457 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);
459 str =
GetString(STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY, cargo_type, act_cargo[cargo_type], cargo_type, max_cargo[cargo_type]);
461 DrawString(ir.left, ir.right, y + text_y_offset, str);
465 DrawString(r.left, r.right, y + text_y_offset,
GetString(STR_VEHICLE_INFO_FEEDER_CARGO_VALUE, feeder_share));
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
bool Failed() const
Did this command fail?
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
bool CanCarryCargo() const
Determines whether an engine can carry something.
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Iterate over all vehicles on a tile.
Functions related to commands.
Commands
List of commands.
Direction
Defines the 8 directions on the map.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
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.
@ VehicleDetails
Name is shown in the vehicle details GUI.
@ RAILVEH_WAGON
simple wagon, not motorized
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
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.
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.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ FS_NORMAL
Index of the normal font in the font tables.
uint32_t PaletteID
The number of the palette.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
ClientID
'Unique' identifier to be given to clients
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Class for storing amounts of cargo.
uint GetCount() const
Get the amount of cargos that have an amount.
Specification of a cargo type.
Helper struct for the cargo details information.
StringID subtype
STR_EMPTY if none.
bool operator==(const CargoSummaryItem &other) const
Used by std::find() and similar functions.
uint amount
Amount that is carried.
uint capacity
Amount that can be carried.
StationID source
One of the source stations.
CargoType cargo
The cargo that is carried.
Data about how and where to blit pixels.
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
static Vehicle * Get(auto index)
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
T * Next() const
Get next vehicle in the chain.
static Train * From(Vehicle *v)
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
'Train' is either a loco or a wagon.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const override
Get the sprite to display the train.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
Sprite sequence for a vehicle part.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
EngineID engine_type
The type of engine used for this vehicle.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint16_t cargo_cap
total capacity
Vehicle * Last()
Get the last vehicle of this vehicle chain.
VehStates vehstatus
Status.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
CargoType cargo_type
type of cargo this vehicle is carrying
Money value
Value of the vehicle.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
TileIndex tile
Current tile index.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Base for the train class.
uint8_t FreightWagonMult(CargoType cargo)
Return the cargo weight multiplier to use for a rail vehicle.
Command definitions related to trains.
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.
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.
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.
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.
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
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.
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &summary)
Collects the cargo transported.
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.
std::vector< CargoSummaryItem > CargoSummary
Container for the cargo summary information.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
Callback for building wagons.
static CargoSummary _cargo_summary
Reused container of cargo details.
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
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.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
@ Crashed
Vehicle is crashed.
Functions related to vehicles.
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
void DrawCargoIconOverlays(std::span< const CargoIconOverlay > overlays, int y)
Draw a list of cargo icon overlays.
void AddCargoIconOverlay(std::vector< CargoIconOverlay > &overlays, int x, int width, const Vehicle *v)
Add a cargo icon to the list of overlays.
bool ShowCargoIconOverlay()
Test if cargo icon overlays should be drawn.
TrainDetailsWindowTabs
The tabs in the train details window.
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
@ VEH_TRAIN
Train vehicle type.
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...
Functions, definitions and such used only by the GUI.
@ BorderOnly
Draw border only, no background.
@ WC_TRAINS_LIST
Trains list; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.