From f094518f8e3f16c226e6f40a9a687efce9cf2651 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 29 Oct 2020 17:47:05 +0000 Subject: [PATCH] Script: Add date methods for getting time in minutes --- docs/script-additions.html | 34 ++++++++++++++++++++++++++++++---- src/script/api/script_date.cpp | 27 +++++++++++++++++++++++++++ src/script/api/script_date.hpp | 10 ++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/docs/script-additions.html b/docs/script-additions.html index 16bce206fc..28e5bb5a2c 100644 --- a/docs/script-additions.html +++ b/docs/script-additions.html @@ -10,7 +10,7 @@ table { border-collapse: collapse; empty-cells: show; } .code { font-family: "Courier New", Courier, mono; color: darkgreen; } .methodtext{ margin-left: 3em; } - .indent { margin-left: 1em; } + .indent { margin-left: 1em; margin-bottom: 0.5em; } dt { font-weight: bold; } @@ -27,7 +27,33 @@

Additional Static Public Member Functions:

static int32 GetDayLengthFactor ()
-
Get current day length factor
+
Get current day length factor.
+
+
+
static bool IsTimeShownInMinutes ()
+
Get whether time is shown in minutes in the game settings.
+
This ignores the "Use client time settings instead of savegame time settings" setting.
+
+
+
static int32 GetTicksPerMinute ()
+
Get the ticks per minutes in the game settings.
+
This ignores the "Use client time settings instead of savegame time settings" setting.
+
+
+
static DateTicksScaled GetCurrentScaledDateTicks ()
+
Get the current scaled date ticks.
+
This increments at the same rate regardless of the day length factor.
+
Changing the day length factor will also change this value.
+
+
+
static int32 GetHour (DateTicksScaled ticks)
+
Get the hour of the given scaled date ticks value.
+
This ignores the "Use client time settings instead of savegame time settings" setting.
+
+
+
static int32 GetMinute (DateTicksScaled ticks)
+
Get the minute of the given scaled date ticks value.
+
This ignores the "Use client time settings instead of savegame time settings" setting.
@@ -36,8 +62,8 @@

Additional Static Public Member Functions:

static bool BuildRiver (TileIndex tile)
-
Builds a river on tile (subject to permissions/settings)
-
All other details are the same as BuildCanal
+
Builds a river on tile (subject to permissions/settings).
+
All other details are the same as BuildCanal.
diff --git a/src/script/api/script_date.cpp b/src/script/api/script_date.cpp index c103ba4527..a5870c332e 100644 --- a/src/script/api/script_date.cpp +++ b/src/script/api/script_date.cpp @@ -72,3 +72,30 @@ time(&t); return t; } + +/* static */ bool ScriptDate::IsTimeShownInMinutes() +{ + return _settings_game.game_time.time_in_minutes; +} + +/* static */ int32 ScriptDate::GetTicksPerMinute() +{ + return _settings_game.game_time.ticks_per_minute; +} + +/* static */ DateTicksScaled ScriptDate::GetCurrentScaledDateTicks() +{ + return _scaled_date_ticks; +} + +/* static */ int32 ScriptDate::GetHour(DateTicksScaled ticks) +{ + Minutes minutes = (ticks / _settings_game.game_time.ticks_per_minute) + _settings_game.game_time.clock_offset; + return MINUTES_HOUR(minutes); +} + +/* static */ int32 ScriptDate::GetMinute(DateTicksScaled ticks) +{ + Minutes minutes = (ticks / _settings_game.game_time.ticks_per_minute) + _settings_game.game_time.clock_offset; + return MINUTES_MINUTE(minutes); +} diff --git a/src/script/api/script_date.hpp b/src/script/api/script_date.hpp index f919cd34fb..f2cffbd773 100644 --- a/src/script/api/script_date.hpp +++ b/src/script/api/script_date.hpp @@ -89,6 +89,16 @@ public: * @note This uses the clock of the host system, which can skew or be set back. Use with caution. */ static int32 GetSystemTime(); + + static bool IsTimeShownInMinutes(); + + static int32 GetTicksPerMinute(); + + static DateTicksScaled GetCurrentScaledDateTicks(); + + static int32 GetHour(DateTicksScaled ticks); + + static int32 GetMinute(DateTicksScaled ticks); }; #endif /* SCRIPT_DATE_HPP */