34#include "table/strings.h"
53 case TimetableMode::Days:
57 case TimetableMode::Seconds:
61 case TimetableMode::Ticks:
77 case TimetableMode::Days:
79 case TimetableMode::Seconds:
81 case TimetableMode::Ticks:
97 case TimetableMode::Days:
99 case TimetableMode::Seconds:
101 case TimetableMode::Ticks:
117 if (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT))
return false;
140 assert(!table.empty());
142 assert(start < v->GetNumOrders());
159 if (!order->
IsType(OT_IMPLICIT)) {
160 if (travelling || i != start) {
163 table[i].arrival = sum;
168 table[i].departure = sum;
175 assert(order ==
nullptr);
178 }
while (i != start);
185 table[i].arrival = sum;
269 size.height = 8 *
resize.height + padding.height;
301 if (this->sel_index == -1)
break;
304 this->sel_index = -1;
318 if (this->sel_index == -1)
break;
323 if (from == to)
break;
333 if (from != selected_order) {
335 selected_order -= (
int)(from <= selected_order);
337 selected_order += (
int)(to <= selected_order);
343 this->sel_index = -1;
352 this->sel_index = 2 * selected_order - (
int)
travel;
354 if (this->sel_index == -1) this->sel_index = this->vehicle->
GetNumOrders() * 2 - 1;
364 int selected = this->sel_index;
370 if (selected != -1) {
372 if (selected % 2 != 0) {
373 disable = order !=
nullptr && (order->
IsType(OT_CONDITIONAL) || order->
IsType(OT_IMPLICIT));
424 int selected = this->sel_index;
432 while (order !=
nullptr) {
449 TextColour colour = (i == selected) ? TC_WHITE : TC_BLACK;
450 if (order->
IsType(OT_CONDITIONAL)) {
452 }
else if (order->
IsType(OT_IMPLICIT)) {
454 colour = ((i == selected) ? TC_SILVER : TC_GREY) |
TC_NO_SHADE;
501 int selected = this->sel_index;
518 if (this->show_expected && i / 2 ==
earlyID) {
625 static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(
const Vehicle *v, uint selected,
bool speed)
645 int selected = GetOrderFromTimetableWndPt(
pt.y, v);
648 this->sel_index = (selected ==
INVALID_ORDER || selected == this->sel_index) ? -1 : selected;
664 int selected = this->sel_index;
672 if (order !=
nullptr) {
682 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
689 int selected = this->sel_index;
696 if (order !=
nullptr) {
703 this->change_timetable_all =
_ctrl_pressed && (order !=
nullptr);
709 auto [
order_id,
mtf] = PackTimetableArgs(v, this->sel_index,
false);
719 auto [
order_id,
mtf] = PackTimetableArgs(v, this->sel_index,
true);
742 ShowVehicleListWindow(v);
751 if (!str.has_value())
return;
754 uint64_t val = str->empty() ? 0 : std::strtoul(str->c_str(),
nullptr, 10);
761 if (this->change_timetable_all) {
772 if (this->change_timetable_all) {
815static constexpr NWidgetPart _nested_timetable_widgets[] = {
825 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_VT_TIMETABLE_PANEL),
SetMinimalSize(388, 82),
SetResize(1, 10),
SetToolTip(STR_TIMETABLE_TOOLTIP),
SetScrollbar(
WID_VT_SCROLLBAR),
EndContainer(),
827 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(),
862 WDP_AUTO,
"view_vehicle_timetable", 400, 130,
865 _nested_timetable_widgets
876 AllocateWindowDescFront<TimetableWindow>(_timetable_desc, v->
index);
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.
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, void *callback_data)
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(StringID 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, int 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 OrderID INVALID_ORDER
Invalid order (sentinel)
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.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
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.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to 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.
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.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
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.
Order * GetFirstOrder() const
Get the first order of the order chain.
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?
Order * next
Pointer to next order. If nullptr, end of list.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
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.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
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.
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 NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
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.
@ QSF_ACCEPT_UNCHANGED
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.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
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: