From b08e2e052717772000071c5d5c69c10c2bdbd48b Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Tue, 31 Jan 2023 18:25:49 -0500 Subject: [PATCH] Codechange: Use ecomomy dates for timetables --- src/date_gui.cpp | 24 ++++++++++++------------ src/date_gui.h | 4 ++-- src/timetable.h | 8 ++++---- src/timetable_cmd.cpp | 24 ++++++++++++------------ src/timetable_gui.cpp | 16 ++++++++-------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/date_gui.cpp b/src/date_gui.cpp index c81252f70f..0ad8cb2a53 100644 --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -9,7 +9,7 @@ #include "stdafx.h" #include "strings_func.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "window_func.h" #include "window_gui.h" #include "date_gui.h" @@ -25,9 +25,9 @@ struct SetDateWindow : Window { SetDateCallback *callback; ///< Callback to call when a date has been selected void *callback_data; ///< Callback data pointer. - TimerGameCalendar::YearMonthDay date; ///< The currently selected date - TimerGameCalendar::Year min_year; ///< The minimum year in the year dropdown - TimerGameCalendar::Year max_year; ///< The maximum year (inclusive) in the year dropdown + TimerGameEconomy::YearMonthDay date; ///< The currently selected date + TimerGameEconomy::Year min_year; ///< The minimum year in the year dropdown + TimerGameEconomy::Year max_year; ///< The maximum year (inclusive) in the year dropdown /** * Create the new 'set date' window @@ -39,19 +39,19 @@ struct SetDateWindow : Window { * @param max_year the maximum year (inclusive) to show in the year dropdown * @param callback the callback to call once a date has been selected */ - SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data) : + SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data) : Window(desc), callback(callback), callback_data(callback_data), - min_year(std::max(CalendarTime::MIN_YEAR, min_year)), - max_year(std::min(CalendarTime::MAX_YEAR, max_year)) + min_year(std::max(EconomyTime::MIN_YEAR, min_year)), + max_year(std::min(EconomyTime::MAX_YEAR, max_year)) { assert(this->min_year <= this->max_year); this->parent = parent; this->InitNested(window_number); - if (initial_date == 0) initial_date = TimerGameCalendar::date; - TimerGameCalendar::ConvertDateToYMD(initial_date, &this->date); + if (initial_date == 0) initial_date = TimerGameEconomy::date; + TimerGameEconomy::ConvertDateToYMD(initial_date, &this->date); this->date.year = Clamp(this->date.year, min_year, max_year); } @@ -88,7 +88,7 @@ struct SetDateWindow : Window { break; case WID_SD_YEAR: - for (TimerGameCalendar::Year i = this->min_year; i <= this->max_year; i++) { + for (TimerGameEconomy::Year i = this->min_year; i <= this->max_year; i++) { SetDParam(0, i); list.push_back(std::make_unique(STR_JUST_INT, i.base(), false)); } @@ -147,7 +147,7 @@ struct SetDateWindow : Window { break; case WID_SD_SET_DATE: - if (this->callback != nullptr) this->callback(this, TimerGameCalendar::ConvertYMDToDate(this->date.year, this->date.month, this->date.day), this->callback_data); + if (this->callback != nullptr) this->callback(this, TimerGameEconomy::ConvertYMDToDate(this->date.year, this->date.month, this->date.day), this->callback_data); this->Close(); break; } @@ -212,7 +212,7 @@ static WindowDesc _set_date_desc(__FILE__, __LINE__, * @param callback the callback to call once a date has been selected * @param callback_data extra callback data */ -void ShowSetDateWindow(Window *parent, int window_number, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data) +void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data) { CloseWindowByClass(WC_SET_DATE); new SetDateWindow(&_set_date_desc, window_number, parent, initial_date, min_year, max_year, callback, callback_data); diff --git a/src/date_gui.h b/src/date_gui.h index d2e9a3cd37..4733f50600 100644 --- a/src/date_gui.h +++ b/src/date_gui.h @@ -18,8 +18,8 @@ * @param w the window that sends the callback * @param date the date that has been chosen */ -typedef void SetDateCallback(const Window *w, TimerGameCalendar::Date date, void *data); +typedef void SetDateCallback(const Window *w, TimerGameEconomy::Date date, void *data); -void ShowSetDateWindow(Window *parent, int window_number, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data); +void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data); #endif /* DATE_GUI_H */ diff --git a/src/timetable.h b/src/timetable.h index 5f8bb2d6ec..16b6ceb03f 100644 --- a/src/timetable.h +++ b/src/timetable.h @@ -11,10 +11,10 @@ #define TIMETABLE_H #include "timer/timer_game_tick.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "vehicle_type.h" -static const TimerGameCalendar::Year MAX_TIMETABLE_START_YEARS = 15; ///< The maximum start date offset, in years. +static const TimerGameEconomy::Year MAX_TIMETABLE_START_YEARS = 15; ///< The maximum start date offset, in economy years. enum class TimetableMode : uint8_t { Days, @@ -22,8 +22,8 @@ enum class TimetableMode : uint8_t { Ticks, }; -TimerGameTick::TickCounter GetStartTickFromDate(TimerGameCalendar::Date start_date); -TimerGameCalendar::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick); +TimerGameTick::TickCounter GetStartTickFromDate(TimerGameEconomy::Date start_date); +TimerGameEconomy::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick); void ShowTimetableWindow(const Vehicle *v); void UpdateVehicleTimetable(Vehicle *v, bool travelling); diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 9c923bdeff..5e70b09147 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -11,7 +11,7 @@ #include "command_func.h" #include "company_func.h" #include "timer/timer_game_tick.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "window_func.h" #include "vehicle_base.h" #include "timetable_cmd.h" @@ -26,13 +26,13 @@ * @param start_date The date when the timetable starts. * @return The first tick of this date. */ -TimerGameTick::TickCounter GetStartTickFromDate(TimerGameCalendar::Date start_date) +TimerGameTick::TickCounter GetStartTickFromDate(TimerGameEconomy::Date start_date) { /* Calculate the offset in ticks from the current date. */ - TimerGameTick::Ticks tick_offset = (start_date - TimerGameCalendar::date).base() * Ticks::DAY_TICKS; + TimerGameTick::Ticks tick_offset = (start_date - TimerGameEconomy::date).base() * Ticks::DAY_TICKS; /* Compensate for the current date_fract. */ - tick_offset -= TimerGameCalendar::date_fract; + tick_offset -= TimerGameEconomy::date_fract; /* Return the current tick plus the offset. */ return TimerGameTick::counter + tick_offset; @@ -43,16 +43,16 @@ TimerGameTick::TickCounter GetStartTickFromDate(TimerGameCalendar::Date start_da * @param start_tick The TimerGameTick::TickCounter when the timetable starts. * @return The date when we reach this tick. */ -TimerGameCalendar::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick) +TimerGameEconomy::Date GetDateFromStartTick(TimerGameTick::TickCounter start_tick) { /* Calculate the offset in ticks from the current counter tick. */ TimerGameTick::Ticks tick_offset = start_tick - TimerGameTick::counter; /* Compensate for the current date_fract. */ - tick_offset += TimerGameCalendar::date_fract; + tick_offset += TimerGameEconomy::date_fract; /* Return the current date plus the offset in days. */ - return TimerGameCalendar::date + (tick_offset / Ticks::DAY_TICKS); + return TimerGameEconomy::date + (tick_offset / Ticks::DAY_TICKS); } /** @@ -347,21 +347,21 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim TimerGameTick::Ticks total_duration = v->orders->GetTimetableTotalDuration(); - TimerGameCalendar::Date start_date = GetDateFromStartTick(start_tick); + TimerGameEconomy::Date start_date = GetDateFromStartTick(start_tick); /* Don't let a timetable start at an invalid date. */ - if (start_date < 0 || start_date > CalendarTime::MAX_DATE) return CMD_ERROR; + if (start_date < 0 || start_date > EconomyTime::MAX_DATE) return CMD_ERROR; /* Don't let a timetable start more than 15 years into the future... */ - if (start_date - TimerGameCalendar::date > TimerGameCalendar::DateAtStartOfYear(MAX_TIMETABLE_START_YEARS)) return CMD_ERROR; + if (start_date - TimerGameEconomy::date > TimerGameEconomy::DateAtStartOfYear(MAX_TIMETABLE_START_YEARS)) return CMD_ERROR; /* ...or 1 year in the past. */ - if (TimerGameCalendar::date - start_date > CalendarTime::DAYS_IN_LEAP_YEAR) return CMD_ERROR; + if (TimerGameEconomy::date - start_date > EconomyTime::DAYS_IN_LEAP_YEAR) return CMD_ERROR; /* If trying to distribute start dates over a shared order group, we need to know the total duration. */ if (timetable_all && !v->orders->IsCompleteTimetable()) return CommandCost(STR_ERROR_TIMETABLE_INCOMPLETE); /* Don't allow invalid start dates for other vehicles in the shared order group. */ - if (timetable_all && start_date + (total_duration / Ticks::DAY_TICKS) > CalendarTime::MAX_DATE) return CMD_ERROR; + if (timetable_all && start_date + (total_duration / Ticks::DAY_TICKS) > EconomyTime::MAX_DATE) return CMD_ERROR; if (flags & DC_EXEC) { std::vector vehs; diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index be8941187e..d4bdf0d06d 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -20,7 +20,7 @@ #include "company_func.h" #include "timer/timer.h" #include "timer/timer_game_tick.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_window.h" #include "date_gui.h" #include "vehicle_gui.h" @@ -192,7 +192,7 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID * @param w the window related to the setting of the date * @param date the actually chosen date */ -static void ChangeTimetableStartCallback(const Window *w, TimerGameCalendar::Date date, void *data) +static void ChangeTimetableStartCallback(const Window *w, TimerGameEconomy::Date date, void *data) { Command::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast(data) != 0, GetStartTickFromDate(date)); } @@ -235,7 +235,7 @@ struct TimetableWindow : Window { TimerGameTick::Ticks start_time = -v->current_order_time; /* If arrival and departure times are in days, compensate for the current date_fract. */ - if (_settings_client.gui.timetable_mode != TimetableMode::Seconds) start_time += TimerGameCalendar::date_fract; + if (_settings_client.gui.timetable_mode != TimetableMode::Seconds) start_time += TimerGameEconomy::date_fract; FillTimetableArrivalDepartureTable(v, v->cur_real_order_index % v->GetNumOrders(), travelling, table, start_time); @@ -252,7 +252,7 @@ struct TimetableWindow : Window { SetDParamMaxDigits(1, 4, FS_SMALL); size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width; } else { - SetDParamMaxValue(1, TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR), 0, FS_SMALL); + SetDParamMaxValue(1, TimerGameEconomy::DateAtStartOfYear(EconomyTime::MAX_YEAR), 0, FS_SMALL); size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_DATE).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_DATE).width) + WidgetDimensions::scaled.hsep_wide + padding.width; } FALLTHROUGH; @@ -525,7 +525,7 @@ struct TimetableWindow : Window { DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK); } else { /* Show a date. */ - SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS); + SetDParam(1, TimerGameEconomy::date + (arr_dep[i / 2].arrival + this_offset) / Ticks::DAY_TICKS); DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_ARRIVAL_DATE, i == selected ? TC_WHITE : TC_BLACK); } } @@ -538,7 +538,7 @@ struct TimetableWindow : Window { DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_SECONDS_IN_FUTURE, i == selected ? TC_WHITE : TC_BLACK); } else { /* Show a date. */ - SetDParam(1, TimerGameCalendar::date + (arr_dep[i / 2].departure + offset) / Ticks::DAY_TICKS); + SetDParam(1, TimerGameEconomy::date + (arr_dep[i / 2].departure + offset) / Ticks::DAY_TICKS); DrawString(tr.left, tr.right, tr.top, STR_TIMETABLE_DEPARTURE_DATE, i == selected ? TC_WHITE : TC_BLACK); } } @@ -572,7 +572,7 @@ struct TimetableWindow : Window { SetDParam(0, (static_cast(v->timetable_start - TimerGameTick::counter) / Ticks::TICKS_PER_SECOND)); DrawString(tr, STR_TIMETABLE_STATUS_START_IN_SECONDS); } else { - /* Calendar units use dates. */ + /* Other units use dates. */ SetDParam(0, STR_JUST_DATE_TINY); SetDParam(1, GetDateFromStartTick(v->timetable_start)); DrawString(tr, STR_TIMETABLE_STATUS_START_AT_DATE); @@ -643,7 +643,7 @@ struct TimetableWindow : Window { this->change_timetable_all = _ctrl_pressed; ShowQueryString(STR_EMPTY, STR_TIMETABLE_START_SECONDS_QUERY, 6, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); } else { - ShowSetDateWindow(this, v->index, TimerGameCalendar::date, TimerGameCalendar::year, TimerGameCalendar::year + MAX_TIMETABLE_START_YEARS, ChangeTimetableStartCallback, reinterpret_cast(static_cast(_ctrl_pressed))); + ShowSetDateWindow(this, v->index, TimerGameEconomy::date, TimerGameEconomy::year, TimerGameEconomy::year + MAX_TIMETABLE_START_YEARS, ChangeTimetableStartCallback, reinterpret_cast(static_cast(_ctrl_pressed))); } break;