20 #include "table/strings.h" 34 if (result.
Failed())
return;
41 if (found != NULL)
return;
48 found = found->
Last();
68 int dragged_width = 0;
69 for (
Train *t =
Train::Get(selection); t != NULL; t = chain ? t->
Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : NULL)) {
70 dragged_width += t->GetDisplayImageWidth(NULL);
73 int drag_hlight_left = rtl ?
max(px - dragged_width + 1, 0) : px;
74 int drag_hlight_right = rtl ? px :
min(px + dragged_width, max_width) - 1;
75 int drag_hlight_width =
max(drag_hlight_right - drag_hlight_left + 1, 0);
77 if (drag_hlight_width > 0) {
82 return drag_hlight_width;
104 int max_width = right - left + 1;
112 int px = rtl ? max_width + skip : -skip;
113 bool sel_articulated =
false;
115 bool drag_at_end_of_train = (drag_dest == v->
index);
116 for (; v != NULL && (rtl ? px > 0 : px < max_width); v = v->
Next()) {
117 if (dragging && !drag_at_end_of_train && drag_dest == v->index) {
120 px += rtl ? -drag_hlight_width : drag_hlight_width;
126 if (rtl ? px + width > 0 : px - width < max_width) {
129 v->GetImage(dir, image_type, &seq);
130 seq.
Draw(px + (rtl ? -offset.x : offset.x), height / 2 + offset.y, pal, (v->vehstatus &
VS_CRASHED) != 0);
133 if (!v->IsArticulatedPart()) sel_articulated =
false;
135 if (v->index == selection) {
137 highlight_l = rtl ? px - width : px;
138 highlight_r = rtl ? px - 1 : px + width - 1;
139 sel_articulated =
true;
140 }
else if ((_cursor.
vehchain && highlight_r != 0) || sel_articulated) {
142 highlight_l -= width;
144 highlight_r += width;
148 px += rtl ? -width : width;
151 if (dragging && drag_at_end_of_train) {
156 if (highlight_l != highlight_r) {
176 return this->cargo != other.
cargo || this->subtype != other.
subtype;
204 str =
FreightWagonMult(item->
cargo) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
207 str = item->
cargo ==
INVALID_CARGO ? STR_LTBLUE_STRING : STR_VEHICLE_DETAILS_CARGO_EMPTY;
226 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
231 DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
251 str =
FreightWagonMult(item->
cargo) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY;
255 str = STR_VEHICLE_INFO_NO_CAPACITY;
277 if (item == summary->
End()) {
283 item->
source = INVALID_STATION;
322 act_cargo[v->cargo_type] += v->cargo.StoredCount();
323 max_cargo[v->cargo_type] += v->cargo_cap;
330 if (max_cargo[i] > 0) num++;
364 int sprite_y_offset = line_height / 2;
371 int x = rtl ? right : left;
372 for (; v != NULL && vscroll_pos > -vscroll_cap; v = v->
GetNextVehicle()) {
382 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
385 if (e->
GetGRF() != NULL) {
391 seq.
Draw(px + (rtl ? -offset.x : offset.x), y - line_height * vscroll_pos + sprite_y_offset + pitch, pal, (v->
vehstatus &
VS_CRASHED) != 0);
393 px += rtl ? -width : width;
399 if (separate_sprite_row) {
404 uint num_lines =
max(1u, _cargo_summary.
Length());
405 for (uint i = 0; i < num_lines; i++) {
407 int data_left = left + (rtl ? 0 : sprite_width);
408 int data_right = right - (rtl ? sprite_width : 0);
409 if (vscroll_pos <= 0 && vscroll_pos > -vscroll_cap) {
410 int py = y - line_height * vscroll_pos + text_y_offset;
411 if (i > 0 || separate_sprite_row) {
416 if (i < _cargo_summary.
Length()) {
419 DrawString(data_left, data_right, py, STR_QUANTITY_N_A, TC_LIGHT_BLUE);
428 if (i < _cargo_summary.
Length()) {
432 DrawString(data_left, data_right, py, STR_VEHICLE_INFO_NO_CAPACITY);
436 default: NOT_REACHED();
445 Money feeder_share = 0;
447 for (
const Vehicle *u = v; u != NULL; u = u->
Next()) {
448 act_cargo[u->cargo_type] += u->cargo.StoredCount();
449 max_cargo[u->cargo_type] += u->cargo_cap;
450 feeder_share += u->cargo.FeederShare();
454 DrawString(left, right, y + text_y_offset, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
458 if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
464 DrawString(left, right, y + text_y_offset,
FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
469 DrawString(left, right, y + text_y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
StationID Source() const
Returns source of the first cargo packet in this list.
static Train * Get(size_t index)
Gets vehicle with given index.
Functions related to OTTD's strings.
VehicleSettings vehicle
options for vehicles
uint32 PaletteID
The number of the palette.
VehicleCargoList cargo
The cargo this vehicle is carrying.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Money value
Value of the vehicle.
StringID subtype
STR_EMPTY if none.
Data about how and where to blit pixels.
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...
static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *summary)
Collects the cargo transported.
bool vehchain
vehicle chain is dragged
static Titem * Get(size_t index)
Returns Titem with given index.
bool CanCarryCargo() const
Determines whether an engine can carry something.
static uint GetLengthOfArticulatedVehicle(const Train *v)
Get the length of an articulated vehicle.
Base for the train class.
Offset at top to draw the frame rectangular area.
Helper struct for the cargo details information.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Maximal number of cargo types in a game.
Tab with cargo capacity of the vehicles.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
uint capacity
Amount that can be carried.
Functions related to vehicles.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Get the sprite to display the train.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
void Clear()
Remove all items from the list.
Tindex index
Index of this pool item.
Offset at top of a matrix cell.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
static const uint TRAIN_DETAILS_MIN_INDENT
Minimum indent level in the train details window.
Simple vector template class.
Common return value for all commands.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
static T max(const T a, const T b)
Returns the maximum of two values.
EngineImageType
Visualisation contexts of vehicles and engines.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
const T * End() const
Get the pointer behind the last valid item (const)
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Direction
Defines the 8 directions on the map.
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
StationID source
One of the source stations.
T * Append(uint to_add=1)
Append an item and return it.
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...
Vehicle drawn in vehicle details, refit window, ...
uint16 cargo_cap
total capacity
uint8 freight_trains
value to multiply the weight of cargo by
int traininfo_vehicle_pitch
Vertical offset for draing train images in depot GUI and vehicle details.
Offset at bottom of a matrix cell.
uint Length() const
Get the number of items in the list.
uint32 VehicleID
The type all our vehicle IDs have.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
T * Next() const
Get next vehicle in the chain.
simple wagon, not motorized
Definition of base types and functions in a cross-platform compatible way.
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
A number of safeguards to prevent using unsafe methods.
void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
CargoID cargo_type
type of cargo this vehicle is carrying
static CargoSummary _cargo_summary
Reused container of cargo details.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
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.
TileIndex tile
Current tile index.
const T * Find(const T &item) const
Search for the first occurrence of an item.
Offset at bottom to draw the frame rectangular area.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Sprite sequence for a vehicle part.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
static T min(const T a, const T b)
Returns the minimum of two values.
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.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
bool Failed() const
Did this command fail?
Tab with cargo carried by the vehicles.
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback for building wagons.
int GetDisplayImageWidth(Point *offset=NULL) const
Get the width of a train vehicle image in the GUI.
Draw border only, no background.
Year build_year
Year the vehicle has been built.
static int HighlightDragPosition(int px, int max_width, VehicleID selection, bool chain)
Highlight the position where a rail vehicle is dragged over by drawing a light gray background...
'Train' is either a loco or a wagon.
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...
TrainDetailsWindowTabs
The tabs in the train details window.
Class for storing amounts of cargo.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
byte FreightWagonMult(CargoID cargo)
Return the cargo weight multiplier to use for a rail vehicle.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
TextDirection _current_text_dir
Text direction of the currently selected language.
Tab with sum of total cargo transported.
Trains list; Window numbers:
Functions related to zooming.
static const byte INVALID_CARGO
Constant representing invalid cargo.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
static uint GetVehicleHeight(VehicleType type)
Get the height of a single vehicle in the GUIs.
Functions related to commands.
CargoID cargo
The cargo that is carried.
Coordinates of a point in 2D.
SmallVector< CargoSummaryItem, 2 > CargoSummary
Container for the cargo summary information.
Offset at right to draw the frame rectangular area.
EngineID engine_type
The type of engine used for this vehicle.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Text is written right-to-left by default.
Vehicle * Last()
Get the last vehicle of this vehicle chain.
bool operator!=(const CargoSummaryItem &other) const
Used by CargoSummary::Find() and similar functions.
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle 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.
move a rail vehicle (in the depot)
Offset at left to draw the frame rectangular area.
uint amount
Amount that is carried.
Tab with name and value of the vehicles.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.