From 5b127ed23e55909ccf0f00779a5f211d3e60a047 Mon Sep 17 00:00:00 2001 From: glx22 Date: Sat, 23 Mar 2024 17:41:13 +0100 Subject: [PATCH] Revert bbdbf9a: ScriptTimeMode was not the best solution for economy/calendar support (cherry picked from commit 704e871a0eec119d27df1a5a21abb6f9da1cb8da) # Conflicts: # src/script/api/script_date.cpp # src/script/script_storage.hpp --- src/script/api/CMakeLists.txt | 2 -- src/script/api/ai_changelog.hpp | 1 - src/script/api/game_changelog.hpp | 1 - src/script/api/script_date.cpp | 20 ------------- src/script/api/script_date.hpp | 2 +- src/script/api/script_object.cpp | 10 ------- src/script/api/script_object.hpp | 14 ---------- src/script/api/script_timemode.cpp | 29 ------------------- src/script/api/script_timemode.hpp | 45 ------------------------------ src/script/script_storage.hpp | 2 -- 10 files changed, 1 insertion(+), 125 deletions(-) delete mode 100644 src/script/api/script_timemode.cpp delete mode 100644 src/script/api/script_timemode.hpp diff --git a/src/script/api/CMakeLists.txt b/src/script/api/CMakeLists.txt index 05e9a294d2..585d2d43fd 100644 --- a/src/script/api/CMakeLists.txt +++ b/src/script/api/CMakeLists.txt @@ -151,7 +151,6 @@ add_files( script_basestation.hpp script_bridge.hpp script_bridgelist.hpp - script_timemode.hpp script_cargo.hpp script_cargolist.hpp script_cargomonitor.hpp @@ -227,7 +226,6 @@ add_files( script_basestation.cpp script_bridge.cpp script_bridgelist.cpp - script_timemode.cpp script_cargo.cpp script_cargolist.cpp script_cargomonitor.cpp diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index e6b524a857..39037efd06 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -20,7 +20,6 @@ * \b 14.0 * * API additions: - * \li AITimeMode * \li AITown::ROAD_LAYOUT_RANDOM * \li AIVehicle::IsPrimaryVehicle * \li AITileList_StationCoverage diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 8ebf05310c..8963190e26 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -24,7 +24,6 @@ * \li GSAsyncMode * \li GSCompanyMode::IsValid * \li GSCompanyMode::IsDeity - * \li GSTimeMode * \li GSTown::ROAD_LAYOUT_RANDOM * \li GSVehicle::IsPrimaryVehicle * \li GSOrder::SetOrderJumpTo diff --git a/src/script/api/script_date.cpp b/src/script/api/script_date.cpp index eda165c56e..7158b7c8ca 100644 --- a/src/script/api/script_date.cpp +++ b/src/script/api/script_date.cpp @@ -9,7 +9,6 @@ #include "../../stdafx.h" #include "script_date.hpp" -#include "script_timemode.hpp" #include "../../date_func.h" #include "../../settings_type.h" @@ -26,8 +25,6 @@ /* static */ ScriptDate::Date ScriptDate::GetCurrentDate() { - if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)::CalTime::CurDate().base(); - return (ScriptDate::Date)EconTime::CurDate().base(); } @@ -40,11 +37,6 @@ { if (date < 0) return DATE_INVALID; - if (ScriptTimeMode::IsCalendarMode()) { - ::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date); - return ymd.year.base(); - } - ::EconTime::YearMonthDay ymd = ::EconTime::ConvertDateToYMD(date); return ymd.year.base(); } @@ -53,11 +45,6 @@ { if (date < 0) return DATE_INVALID; - if (ScriptTimeMode::IsCalendarMode()) { - ::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date); - return ymd.month + 1; - } - ::EconTime::YearMonthDay ymd = ::EconTime::ConvertDateToYMD(date); return ymd.month + 1; } @@ -66,11 +53,6 @@ { if (date < 0) return DATE_INVALID; - if (ScriptTimeMode::IsCalendarMode()) { - ::CalTime::YearMonthDay ymd = ::CalTime::ConvertDateToYMD(date); - return ymd.day; - } - ::EconTime::YearMonthDay ymd = ::EconTime::ConvertDateToYMD(date); return ymd.day; } @@ -81,8 +63,6 @@ if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID; if (year < 0 || year > CalTime::MAX_YEAR) return DATE_INVALID; - if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)::CalTime::ConvertYMDToDate(year, month - 1, day_of_month).base(); - return (ScriptDate::Date)::EconTime::ConvertYMDToDate(year, month - 1, day_of_month).base(); } diff --git a/src/script/api/script_date.hpp b/src/script/api/script_date.hpp index 73149e3ae0..47532aad42 100644 --- a/src/script/api/script_date.hpp +++ b/src/script/api/script_date.hpp @@ -31,7 +31,7 @@ public: * compose valid date values for a known year, month and day. */ enum Date { - DATE_INVALID = ::CalTime::INVALID_DATE.base(), ///< A value representing an invalid date. + DATE_INVALID = ::EconTime::INVALID_DATE.base(), ///< A value representing an invalid date. }; /** diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 2196f4e1d5..25c8a3c688 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -277,16 +277,6 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->allow_do_command; } -/* static */ void ScriptObject::SetTimeMode(bool calendar) -{ - GetStorage()->time_mode = calendar; -} - -/* static */ bool ScriptObject::IsCalendarTimeMode() -{ - return GetStorage()->time_mode; -} - /* static */ void ScriptObject::SetCompany(CompanyID company) { if (GetStorage()->root_company == INVALID_OWNER) GetStorage()->root_company = company; diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 70938e48d9..1430f613f4 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -255,20 +255,6 @@ protected: */ static bool GetAllowDoCommand(); - /** - * Set if the script is running in calendar time or economy time mode. - * Calendar time is used by OpenTTD for technology like vehicle introductions and expiration, and variable snowline. It can be sped up or slowed down by the player. - * Economy time always runs at the same pace and handles things like cargo production, everything related to money, etc. - * @param Calendar Should we use calendar time mode? (Set to false for economy time mode.) - */ - static void SetTimeMode(bool calendar); - - /** - * Check if the script is operating in calendar time mode, or in economy time mode. See SetTimeMode() for more information. - * @return True if we are in calendar time mode, false if we are in economy time mode. - */ - static bool IsCalendarTimeMode(); - /** * Set the current company to execute commands for or request * information about. diff --git a/src/script/api/script_timemode.cpp b/src/script/api/script_timemode.cpp deleted file mode 100644 index f927368f8a..0000000000 --- a/src/script/api/script_timemode.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ - -/** @file script_timemode.cpp Implementation of ScriptTimeMode. */ - -#include "../../stdafx.h" -#include "script_timemode.hpp" - -#include "../../safeguards.h" - -ScriptTimeMode::ScriptTimeMode(bool calendar) -{ - this->last_time_mode = ScriptObject::IsCalendarTimeMode(); - ScriptObject::SetTimeMode(calendar); -} - -ScriptTimeMode::~ScriptTimeMode() -{ - ScriptObject::SetTimeMode(this->last_time_mode); -} - -/* static */ bool ScriptTimeMode::IsCalendarMode() -{ - return ScriptObject::IsCalendarTimeMode(); -} diff --git a/src/script/api/script_timemode.hpp b/src/script/api/script_timemode.hpp deleted file mode 100644 index eb03b0b3f9..0000000000 --- a/src/script/api/script_timemode.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ - -/** @file script_timemode.hpp Switch the time mode. */ - -#ifndef SCRIPT_TIMEMODE_HPP -#define SCRIPT_TIMEMODE_HPP - -#include "script_object.hpp" - -/** - * Class to switch the current time. - * If you create an instance of this class, the mode will be switched to either calendar time or economy time mode. - * @note Destroying this object will restore the previous time mode. - * @api ai game - */ -class ScriptTimeMode : public ScriptObject { -private: - bool last_time_mode; ///< The last time mode we were using. -public: - /** - * Creating an instance of this class switches the time mode used for queries and commands. - * Calendar time is used by OpenTTD for technology like vehicle introductions and expiration, and variable snowline. It can be sped up or slowed down by the player. - * Economy time always runs at the same pace and handles things like cargo production, everything related to money, etc. - * @param Calendar Should we use calendar time mode? (Set to false for economy time mode.) - */ - ScriptTimeMode(bool calendar); - - /** - * Destroying this instance resets the time mode to the mode it was in when the instance was created. - */ - ~ScriptTimeMode(); - - /** - * Check if the script is operating in calendar time mode, or in economy time mode. See ScriptTimeMode() for more information. - * @return True if we are in calendar time mode, false if we are in economy time mode. - */ - static bool IsCalendarMode(); -}; - -#endif /* SCRIPT_TIMEMODE_HPP */ diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp index 98b7b903c8..c0802e4d22 100644 --- a/src/script/script_storage.hpp +++ b/src/script/script_storage.hpp @@ -43,7 +43,6 @@ private: class ScriptObject *mode_instance; ///< The instance belonging to the current build mode. ScriptAsyncModeProc *async_mode; ///< The current command async mode we are in. class ScriptObject *async_mode_instance; ///< The instance belonging to the current command async mode. - bool time_mode; ///< True if we in calendar time mode, or false (default) if we are in economy time mode. CompanyID root_company; ///< The root company, the company that the script really belongs to. CompanyID company; ///< The current company. @@ -85,7 +84,6 @@ public: mode_instance (nullptr), async_mode (nullptr), async_mode_instance (nullptr), - time_mode (false), root_company (INVALID_OWNER), company (INVALID_OWNER), delay (1),