31 #include "table/strings.h" 67 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
90 assert(table != NULL);
92 assert(start < v->GetNumOrders());
109 if (!order->
IsType(OT_IMPLICIT)) {
110 if (travelling || i != start) {
125 assert(order == NULL);
128 }
while (i != start);
163 vehicle(
Vehicle::Get(window_number)),
166 this->CreateNestedTree();
168 this->UpdateSelectionStates();
169 this->FinishInitNested(window_number);
171 this->owner = this->vehicle->
owner;
214 int GetOrderFromTimetableWndPt(
int y,
const Vehicle *v)
222 return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel :
INVALID_ORDER;
240 if (this->sel_index == -1)
break;
242 this->DeleteChildWindows();
243 this->sel_index = -1;
247 if (!gui_scope)
break;
248 this->UpdateSelectionStates();
253 if (gui_scope)
break;
257 if (this->sel_index == -1)
break;
262 if (from == to)
break;
268 if (selected_order == old_num_orders) selected_order = 0;
270 bool travel =
HasBit(this->sel_index, 0);
272 if (from != selected_order) {
274 selected_order -= (int)(from <= selected_order);
276 selected_order += (int)(to <= selected_order);
281 this->DeleteChildWindows();
282 this->sel_index = -1;
291 this->sel_index = 2 * selected_order - (int)travel;
293 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
302 const Vehicle *v = this->vehicle;
303 int selected = this->sel_index;
309 if (selected != -1) {
311 if (selected % 2 == 1) {
312 disable = order != NULL && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
317 bool disable_speed = disable || selected % 2 != 1 || v->
type ==
VEH_AIRCRAFT;
354 const Vehicle *v = this->vehicle;
355 int selected = this->sel_index;
362 bool final_order =
false;
370 while (order != NULL) {
387 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
388 if (order->
IsType(OT_CONDITIONAL)) {
389 string = STR_TIMETABLE_NO_TRAVEL;
390 }
else if (order->
IsType(OT_IMPLICIT)) {
391 string = STR_TIMETABLE_NOT_TIMETABLEABLE;
392 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
397 STR_TIMETABLE_TRAVEL_FOR_SPEED_ESTIMATED :
398 STR_TIMETABLE_TRAVEL_FOR_ESTIMATED;
401 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED_SPEED :
402 STR_TIMETABLE_TRAVEL_NOT_TIMETABLED;
407 STR_TIMETABLE_TRAVEL_FOR_SPEED : STR_TIMETABLE_TRAVEL_FOR;
413 if (final_order)
break;
452 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
453 if (this->show_expected && i / 2 == earlyID) {
455 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY, TC_GREEN);
458 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
459 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
464 DrawString(abbr_left, abbr_right, y, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
466 DrawString(time_left, time_right, y, STR_JUST_DATE_TINY,
467 show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK);
479 if (total_time != 0) {
506 static inline uint32 PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
508 uint order_number = (selected + 1) / 2;
511 if (order_number >= v->
GetNumOrders()) order_number = 0;
513 return v->
index | (order_number << 20) | (mtf << 28);
518 const Vehicle *v = this->vehicle;
526 int selected = GetOrderFromTimetableWndPt(pt.y, v);
528 this->DeleteChildWindows();
529 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
538 int selected = this->sel_index;
552 current = STR_JUST_INT;
556 this->query_is_speed_query =
false;
562 int selected = this->sel_index;
572 current = STR_JUST_INT;
576 this->query_is_speed_query =
true;
582 uint32 p1 = PackTimetableArgs(v, this->sel_index,
false);
588 uint32 p1 = PackTimetableArgs(v, this->sel_index,
true);
606 this->show_expected = !this->show_expected;
610 ShowVehicleListWindow(v);
619 if (str == NULL)
return;
621 const Vehicle *v = this->vehicle;
623 uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query);
625 uint64 val =
StrEmpty(str) ? 0 : strtoul(str, NULL, 10);
626 if (this->query_is_speed_query) {
632 uint32 p2 =
minu(val, UINT16_MAX);
653 static const NWidgetPart _nested_timetable_widgets[] = {
663 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(),
665 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(),
700 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
703 _nested_timetable_widgets,
lengthof(_nested_timetable_widgets)
714 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.
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 NULL, end of list.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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.
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.
OwnerByte owner
Which company owns the vehicle?
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.
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 NULL 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.
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
GUI functions that shouldn't be here.
Date _date
Current date in days (day counter)
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleTypeByte type
Type of vehicle.
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.