mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
Codechange: Use proper date types in various places (#11177)
This commit is contained in:
parent
c9c9cfa4fd
commit
c7b51a8c3a
@ -14,8 +14,9 @@
|
||||
#include "string_func.h"
|
||||
#include "strings_type.h"
|
||||
|
||||
static const int CF_NOEURO = 0; ///< Currency never switches to the Euro (as far as known).
|
||||
static const int CF_ISEURO = 1; ///< Currency _is_ the Euro.
|
||||
static constexpr TimerGameCalendar::Year CF_NOEURO = 0; ///< Currency never switches to the Euro (as far as known).
|
||||
static constexpr TimerGameCalendar::Year CF_ISEURO = 1; ///< Currency _is_ the Euro.
|
||||
static constexpr TimerGameCalendar::Year MIN_EURO_YEAR = 2000; ///< The earliest year custom currencies may switch to the Euro.
|
||||
|
||||
/**
|
||||
* This enum gives the currencies a unique id which must be maintained for
|
||||
|
@ -582,7 +582,7 @@ public:
|
||||
}
|
||||
|
||||
int mo = (TimerGameCalendar::month / 3 - nums) * 3;
|
||||
int yr = TimerGameCalendar::year;
|
||||
auto yr = TimerGameCalendar::year;
|
||||
while (mo < 0) {
|
||||
yr--;
|
||||
mo += 12;
|
||||
|
@ -6512,7 +6512,7 @@ bool GetGlobalVariable(byte param, uint32_t *value, const GRFFile *grffile)
|
||||
{
|
||||
switch (param) {
|
||||
case 0x00: // current date
|
||||
*value = std::max(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
|
||||
*value = std::max(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::Date(0));
|
||||
return true;
|
||||
|
||||
case 0x01: // current year
|
||||
|
@ -1944,7 +1944,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||
case OCV_AGE: skip_order = OrderConditionCompare(occ, DateToYear(v->age), value); break;
|
||||
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
||||
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
||||
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), 0), value); break;
|
||||
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Date(0)), value); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
|
@ -2844,13 +2844,13 @@ struct CustomCurrencyWindow : Window {
|
||||
break;
|
||||
|
||||
case WID_CC_YEAR_DOWN:
|
||||
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
|
||||
_custom_currency.to_euro = (_custom_currency.to_euro <= MIN_EURO_YEAR) ? CF_NOEURO : _custom_currency.to_euro - 1;
|
||||
if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
|
||||
this->EnableWidget(WID_CC_YEAR_UP);
|
||||
break;
|
||||
|
||||
case WID_CC_YEAR_UP:
|
||||
_custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
|
||||
_custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, MIN_EURO_YEAR, MAX_YEAR);
|
||||
if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
|
||||
this->EnableWidget(WID_CC_YEAR_DOWN);
|
||||
break;
|
||||
@ -2895,9 +2895,9 @@ struct CustomCurrencyWindow : Window {
|
||||
break;
|
||||
|
||||
case WID_CC_YEAR: { // Year to switch to euro
|
||||
int val = atoi(str);
|
||||
TimerGameCalendar::Year val = atoi(str);
|
||||
|
||||
_custom_currency.to_euro = (val < 2000 ? CF_NOEURO : std::min(val, MAX_YEAR));
|
||||
_custom_currency.to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, MAX_YEAR));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2505,7 +2505,7 @@ struct ScenarioEditorToolbarWindow : Window {
|
||||
/* Was 'cancel' pressed? */
|
||||
if (str == nullptr) return;
|
||||
|
||||
int32_t value;
|
||||
TimerGameCalendar::Year value;
|
||||
if (!StrEmpty(str)) {
|
||||
value = atoi(str);
|
||||
} else {
|
||||
|
@ -761,7 +761,7 @@ uint32_t Vehicle::GetGRFID() const
|
||||
*/
|
||||
void Vehicle::ShiftDates(int interval)
|
||||
{
|
||||
this->date_of_last_service = std::max(this->date_of_last_service + interval, 0);
|
||||
this->date_of_last_service = std::max(this->date_of_last_service + interval, TimerGameCalendar::Date(0));
|
||||
/* date_of_last_service_newgrf is not updated here as it must stay stable
|
||||
* for vehicles outside of a depot. */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user