35#include "table/strings.h"
55 case TimetableMode::Ticks:
return {STR_UNITS_TICKS, ticks};
68 case TimetableMode::Days:
70 case TimetableMode::Seconds:
72 case TimetableMode::Ticks:
88 case TimetableMode::Days:
90 case TimetableMode::Seconds:
92 case TimetableMode::Ticks:
108 if (order.
IsType(OT_CONDITIONAL) || order.
IsType(OT_IMPLICIT))
return false;
131 assert(!table.empty());
133 assert(start < v->GetNumOrders());
142 auto orders = v->Orders();
150 if (!orders[i].IsType(OT_IMPLICIT)) {
151 if (travelling || i != start) {
153 sum += orders[i].GetTimetabledTravel();
154 table[i].arrival = sum;
158 sum += orders[i].GetTimetabledWait();
159 table[i].departure = sum;
163 }
while (i != start);
169 sum += orders[i].GetTimetabledTravel();
170 table[i].arrival = sum;
230 size.width = std::max(
236 size.width = std::max(
246 size.height = 8 *
resize.height + padding.height;
255 int GetOrderFromTimetableWndPt(
int y, [[maybe_unused]]
const Vehicle *v)
258 if (sel == INT32_MAX)
return sel;
259 assert(
IsInsideBS(sel, 0, v->GetNumOrders() * 2));
268 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
278 if (this->sel_index == -1)
break;
281 this->sel_index = -1;
285 if (!gui_scope)
break;
291 if (gui_scope)
break;
295 if (this->sel_index == -1)
break;
300 if (from == to)
break;
306 if (selected_order == old_num_orders) selected_order = 0;
308 bool travel =
HasBit(this->sel_index, 0);
310 if (from != selected_order) {
312 selected_order -= (int)(from <= selected_order);
314 selected_order += (int)(to <= selected_order);
320 this->sel_index = -1;
329 this->sel_index = 2 * selected_order - (int)travel;
331 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
268 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override {
…}
341 int selected = this->sel_index;
347 if (selected != -1) {
349 if (selected % 2 != 0) {
350 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
355 bool disable_speed = disable || selected % 2 == 0 || v->
type ==
VEH_AIRCRAFT;
391 std::string GetTimetableTravelString(
const Order &order,
int i,
TextColour &colour)
const
393 colour = (i == this->sel_index) ? TC_WHITE : TC_BLACK;
395 if (order.
IsType(OT_CONDITIONAL)) {
396 return GetString(STR_TIMETABLE_NO_TRAVEL);
399 if (order.
IsType(OT_IMPLICIT)) {
400 colour = ((i == this->sel_index) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
401 return GetString(STR_TIMETABLE_NOT_TIMETABLEABLE);
408 :
GetString(STR_TIMETABLE_TRAVEL_FOR, str, value);
415 :
GetString(STR_TIMETABLE_TRAVEL_FOR_ESTIMATED, str, value);
420 :
GetString(STR_TIMETABLE_TRAVEL_NOT_TIMETABLED);
433 bool final_order =
false;
434 int selected = this->sel_index;
438 int middle = rtl ? tr.right - index_column_width : tr.left + index_column_width;
440 auto orders = v->Orders();
446 DrawOrderString(v, &orders[order_id], order_id, tr.top, i == selected,
true, tr.left, middle, tr.right);
447 if (order_id > v->
orders->
GetNext(order_id)) final_order =
true;
451 std::string
string = GetTimetableTravelString(orders[order_id], i, colour);
453 DrawString(rtl ? tr.left : middle, rtl ? middle : tr.right, tr.top, string, colour);
455 if (final_order)
break;
477 std::vector<TimetableArrivalDeparture> arr_dep(v->
GetNumOrders());
481 int selected = this->sel_index;
492 TextColour tc = show_late ? TC_RED : TC_INVALID;
498 if (this->show_expected && i / 2 == early_id) {
504 this_offset = offset;
512 i == selected ? TC_WHITE : TC_BLACK);
517 i == selected ? TC_WHITE : TC_BLACK);
527 i == selected ? TC_WHITE : TC_BLACK);
532 i == selected ? TC_WHITE : TC_BLACK);
545 return GetString(STR_TIMETABLE_APPROX_TIME, str, value);
558 if (total_time != 0) {
559 DrawString(tr, GetTimetableTotalTimeString(total_time));
576 DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
607 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
609 uint order_number = (selected + 1) / 2;
612 if (order_number >= v->
GetNumOrders()) order_number = 0;
614 return { order_number, mtf };
627 int selected = GetOrderFromTimetableWndPt(pt.y, v);
630 this->sel_index = (selected == INT32_MAX || selected == this->sel_index) ? -1 : selected;
642 Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, w->window_number, ctrl, GetStartTickFromDate(date));
650 int selected = this->sel_index;
658 if (order !=
nullptr) {
667 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
674 int selected = this->sel_index;
681 if (order !=
nullptr) {
687 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
693 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
false);
703 auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index,
true);
726 ShowVehicleListWindow(v);
735 if (!str.has_value())
return;
738 uint64_t val = ParseInteger<uint64_t>(*str, 10,
true).value_or(0);
745 if (this->change_timetable_all) {
756 if (this->change_timetable_all) {
799static constexpr NWidgetPart _nested_timetable_widgets[] = {
809 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_TIMETABLE_PANEL),
SetMinimalSize(388, 82),
SetResize(1, 10),
SetToolTip(STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
811 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_ARRIVAL_DEPARTURE_PANEL),
SetMinimalSize(110, 0),
SetFill(0, 1),
SetToolTip(STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
846 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
849 _nested_timetable_widgets
860 AllocateWindowDescFront<TimetableWindow>(_timetable_desc, v->
index);
@ AutofillTimetable
Whether the vehicle should fill in the timetable automatically.
@ TimetableStarted
Whether the vehicle has started running on the timetable yet.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
An interval timer will fire every interval, and will continue to fire until it is deleted.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static DateFract date_fract
Fractional part of the day.
uint64_t TickCounter
The type that the tick counter is stored in.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
int32_t Ticks
The type to store ticks in.
@ NONE
These timers can be executed in any order; the order is not relevant.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
Functions related to commands.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback &&callback)
Create the new 'set date' window.
Functions related to the graphical selection of a date.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ TC_NO_SHADE
Do not add shading to this text colour.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
GUI functions that shouldn't be here.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ MTF_TRAVEL_TIME
Set travel time.
@ MTF_WAIT_TIME
Set wait time.
@ MTF_TRAVEL_SPEED
Set max travel speed.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
@ CS_NUMERAL
Only numeric ones.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
VehicleType type
Type of vehicle.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool timetable_arrival_departure
show arrivals and departures in vehicle timetables
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
TimerGameTick::Ticks GetTimetableDurationIncomplete() const
Gets the known duration of the vehicles timetable even if the timetable is not complete.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
VehicleOrderID GetNext(VehicleOrderID cur) const
Get the order after the given one or the first one, if the given one is the last one.
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
bool IsType(OrderType type) const
Check whether this order is of the given type.
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Coordinates of a point in 2D.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Templated helper to make a type-safe 'typedef' representing a single POD value.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
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.
Order current_order
The current order (+ status, like: loading)
OrderList * orders
Pointer to the order list for this vehicle.
Owner owner
Which company owns the vehicle?
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ AcceptUnchanged
return success even when the text didn't change
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Definition of the Window system.
Base class for all vehicles.
Functions related to the vehicle's GUIs.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
@ VIWD_MODIFY_ORDERS
Other order modifications.
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
@ VEH_AIRCRAFT
Aircraft vehicle type.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers: