Split date types into calendar and economy dates

See: 735abfe1
This commit is contained in:
Jonathan G Rennison
2024-02-13 21:34:09 +00:00
parent fad5ee56e7
commit 7ce06e22b8
141 changed files with 1325 additions and 1082 deletions

View File

@@ -22,7 +22,7 @@
{
if (bridge_id >= MAX_BRIDGES) return false;
const BridgeSpec *b = ::GetBridgeSpec(bridge_id);
return b->avail_year <= _cur_year && !HasBit(b->ctrl_flags, BSCF_NOT_AVAILABLE_AI_GS);
return b->avail_year <= CalTime::CurYear() && !HasBit(b->ctrl_flags, BSCF_NOT_AVAILABLE_AI_GS);
}
/* static */ bool ScriptBridge::IsBridgeTile(TileIndex tile)

View File

@@ -25,7 +25,7 @@
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
{
return (ScriptDate::Date)_date.base();
return (ScriptDate::Date)::CalTime::CurDate().base();
}
/* static */ SQInteger ScriptDate::GetDayLengthFactor()
@@ -37,15 +37,15 @@
{
if (date < 0) return DATE_INVALID;
::YearMonthDay ymd = ::ConvertDateToYMD(date);
return ymd.year;
::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date);
return ymd.year.base();
}
/* static */ SQInteger ScriptDate::GetMonth(ScriptDate::Date date)
{
if (date < 0) return DATE_INVALID;
::YearMonthDay ymd = ::ConvertDateToYMD(date);
::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date);
return ymd.month + 1;
}
@@ -53,7 +53,7 @@
{
if (date < 0) return DATE_INVALID;
::YearMonthDay ymd = ::ConvertDateToYMD(date);
::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date);
return ymd.day;
}
@@ -61,9 +61,9 @@
{
if (month < 1 || month > 12) return DATE_INVALID;
if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID;
if (year < 0 || year > MAX_YEAR) return DATE_INVALID;
if (year < 0 || year > CalTime::MAX_YEAR) return DATE_INVALID;
return (ScriptDate::Date)::ConvertYMDToDate(year, month - 1, day_of_month).base();
return (ScriptDate::Date)::CalTime::ConvertYMDToDate(year, month - 1, day_of_month).base();
}
/* static */ SQInteger ScriptDate::GetSystemTime()

View File

@@ -31,7 +31,7 @@ public:
* compose valid date values for a known year, month and day.
*/
enum Date {
DATE_INVALID = ::INVALID_DATE.base(), ///< A value representing an invalid date.
DATE_INVALID = ::CalTime::INVALID_DATE.base(), ///< A value representing an invalid date.
};
/**

View File

@@ -221,7 +221,7 @@
{
Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return 0;
return i->last_prod_year;
return i->last_prod_year.base();
}
/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
@@ -230,7 +230,7 @@
if (i == nullptr) return ScriptDate::DATE_INVALID;
if (cargo_type == INVALID_CARGO) {
return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), Date(0), [](Date a, Date b) { return std::max(a, b); }).base();
return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), EconTime::Date(0), [](EconTime::Date a, EconTime::Date b) { return std::max(a, b); }).base();
} else {
int index = i->GetCargoAcceptedIndex(cargo_type);
if (index < 0) return ScriptDate::DATE_INVALID;