29 #include "table/strings.h" 65 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
88 assert(table !=
nullptr);
90 assert(start < v->GetNumOrders());
107 if (!order->
IsType(OT_IMPLICIT)) {
108 if (travelling || i != start) {
123 assert(order ==
nullptr);
126 }
while (i != start);
161 vehicle(
Vehicle::Get(window_number)),
164 this->CreateNestedTree();
166 this->UpdateSelectionStates();
167 this->FinishInitNested(window_number);
169 this->owner = this->vehicle->
owner;
212 int GetOrderFromTimetableWndPt(
int y,
const Vehicle *v)
220 return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel :
INVALID_ORDER;
238 if (this->sel_index == -1)
break;
240 this->DeleteChildWindows();
241 this->sel_index = -1;
245 if (!gui_scope)
break;
246 this->UpdateSelectionStates();
251 if (gui_scope)
break;
255 if (this->sel_index == -1)
break;
260 if (from == to)
break;
266 if (selected_order == old_num_orders) selected_order = 0;
268 bool travel =
HasBit(this->sel_index, 0);
270 if (from != selected_order) {
272 selected_order -= (int)(from <= selected_order);
274 selected_order += (int)(to <= selected_order);
279 this->DeleteChildWindows();
280 this->sel_index = -1;
289 this->sel_index = 2 * selected_order - (int)travel;
291 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
300 const Vehicle *v = this->vehicle;
301 int selected = this->sel_index;
307 if (selected != -1) {
309 if (selected % 2 == 1) {
310 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
315 bool disable_speed = disable || selected % 2 != 1 || v->
type ==
VEH_AIRCRAFT;
352 const Vehicle *v = this->vehicle;
353 int selected = this->sel_index;
360 bool final_order =
false;
368 while (order !=
nullptr) {
385 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
386 if (order->
IsType(OT_CONDITIONAL)) {
387 string = STR_TIMETABLE_NO_TRAVEL;
388 }
else if (order->
IsType(OT_IMPLICIT)) {
389 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
390 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
395 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
396 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
399 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
400 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
405 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
411 if (final_order)
break;
450 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
451 if (this->show_expected && i / 2 == earlyID) {
453 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, TC_GREEN);
456 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
457 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
462 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
464 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
465 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
477 if (total_time != 0) {
504 static inline uint32 PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
506 uint order_number = (selected + 1) / 2;
509 if (order_number >= v->
GetNumOrders()) order_number = 0;
511 return v->
index | (order_number << 20) | (mtf << 28);
516 const Vehicle *v = this->vehicle;
524 int selected = GetOrderFromTimetableWndPt(pt.y, v);
526 this->DeleteChildWindows();
527 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
536 int selected = this->sel_index;
544 if (order !=
nullptr) {
550 current = STR_JUST_INT;
554 this->query_is_speed_query =
false;
560 int selected = this->sel_index;
567 if (order !=
nullptr) {
570 current = STR_JUST_INT;
574 this->query_is_speed_query =
true;
580 uint32 p1 = PackTimetableArgs(v, this->sel_index,
false);
586 uint32 p1 = PackTimetableArgs(v, this->sel_index,
true);
604 this->show_expected = !this->show_expected;
608 ShowVehicleListWindow(v);
617 if (str ==
nullptr)
return;
619 const Vehicle *v = this->vehicle;
621 uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
623 uint64 val =
StrEmpty(str) ? 0 : strtoul(str,
nullptr, 10);
624 if (this->query_is_speed_query) {
630 uint32 p2 =
minu(val, UINT16_MAX);
651 static const NWidgetPart _nested_timetable_widgets[] = {
661 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_TIMETABLE_PANEL),
SetMinimalSize(388, 82),
SetResize(1, 10),
SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
663 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_ARRIVAL_DEPARTURE_PANEL),
SetMinimalSize(110, 0),
SetFill(0, 1),
SetDataTip(STR_NULL, STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
698 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
701 _nested_timetable_widgets,
lengthof(_nested_timetable_widgets)
712 AllocateWindowDescFront<TimetableWindow>(&_timetable_desc, v->
index);
Functions related to OTTD's strings.
change the timetable for a vehicle
static uint minu(const uint a, const uint b)
Returns the minimum of two unsigned integers.
static const int DAYS_IN_YEAR
days per year
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not)...
set the vehicle on time feature (timetable)
High level window description.
union Vehicle::@49 orders
The orders currently assigned to the vehicle.
static Titem * Get(size_t index)
Returns Titem with given index.
Whether the vehicle has started running on the timetable yet.
Functions related to dates.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Offset at top to draw the frame rectangular area.
Other order modifications.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
OrderList * list
Pointer to the order list for this vehicle.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint32 current_order_time
How many ticks have passed since this order started.
Tindex index
Index of this pool item.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
return success even when the text didn't change
Stuff related to the text buffer GUI.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
static T max(const T a, const T b)
Returns the maximum of two values.
Year _cur_year
Current year, starting at 0.
Functions related to the vehicle's GUIs.
Functions, definitions and such used only by the GUI.
The vehicle will stop at any station it passes except the destination.
Order * next
Pointer to next order. If nullptr, end of list.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
The vehicle will stop at any station it passes and the destination.
Autoreplace replaced the vehicle.
Vehicle orders; Window numbers:
Functions related to low-level strings.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed)
Convert the given display speed to the km/h-ish speed.
DateFract _date_fract
Fractional part of the day.
This window is used for construction; close it whenever changing company.
bool IsType(OrderType type) const
Check whether this order is of the given type.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
Removed / replaced all orders (after deleting / sharing).
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback)
Create the new 'set date' window.
Whether the vehicle should fill in the timetable automatically.
Vehicle view; Window numbers:
set the date that a timetable should start
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled...
Order * GetFirstOrder() const
Get the first order of the order chain.
Vehicle timetable; Window numbers:
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.
Owner owner
Which company owns the vehicle?
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Date timetable_start
When the vehicle is supposed to start the timetable.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not)...
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Functions related to companies.
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Functions related to the graphical selection of a date.
bool timetable_in_ticks
whether to show the timetable in ticks rather than days
uint ConvertKmhishSpeedToDisplaySpeed(uint speed)
Convert the given km/h-ish speed to the display speed.
static const OrderID INVALID_ORDER
Invalid order (sentinel)
GUISettings gui
settings related to the GUI
Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
Base class for all vehicles.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
int32 Ticks
The type to store ticks in.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Do not add shading to this text colour.
VehicleType type
Type of vehicle.
Vehicle details; Window numbers:
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Index of the small font in the font tables.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
int32 Date
The type to store our dates in.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Offset at right to draw the frame rectangular area.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
#define CMD_MSG(x)
Used to combine a StringID with the command.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination...
Text is written right-to-left by default.
WindowNumber window_number
Window number within the window class.
Window functions not directly related to making/drawing windows.
Find a place automatically.
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
GUI functions that shouldn't be here.
Date _date
Current date in days (day counter)
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date...
This file contains all sprite-related enums and defines.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Order current_order
The current order (+ status, like: loading)
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.