diff --git a/tests/game/ClassicDayRhythm.cpp b/tests/game/ClassicDayRhythm.cpp index 940d0085f0..0cb30755cb 100644 --- a/tests/game/ClassicDayRhythm.cpp +++ b/tests/game/ClassicDayRhythm.cpp @@ -17,6 +17,7 @@ #include "tc_catch2.h" #include "../../src/modules/PlayerbotV2/Fleet/DayRhythm.h" +#include "DayCycle.h" using namespace Playerbot::V2::Fleet; @@ -38,3 +39,83 @@ TEST_CASE("The target follows the hour but never passes the world cap", "[Classi CHECK(RhythmTarget(1, 3, 220) == 1); // a nonzero target stays nonzero CHECK(RhythmTarget(0, 20, 220) == 0); } + +// The sky's clock (game/Time/DayCycle.h, Forever.DayCycle.Speed and .time): here with the bots' day rhythm, both are about the hour. +TEST_CASE("At speed 1 the sky shows the realm's own time of day", "[ClassicDayCycle]") +{ + using namespace DayCycle; + // 2026-11-14 08:51:30 on the realm's wall clock + int64 const t = 1794646290; + SkyClock c = ShownClock(t, 1, SkyMode::Auto); + CHECK(c.Hour == 8); + CHECK(c.Minute == 51); + CHECK(c.Speed == NormalSpeed); + c = ShownClock(t - 8 * 3600 - 51 * 60 - 30, 1, SkyMode::Auto); // midnight + CHECK(c.Hour == 0); + CHECK(c.Minute == 0); +} + +TEST_CASE("A faster sky runs speed times as fast and goes on without a jump at midnight", "[ClassicDayCycle]") +{ + using namespace DayCycle; + int64 const midnight = 1794614400; // 2026-11-14 00:00:00 + SkyClock c = ShownClock(midnight + 6 * 3600, 2, SkyMode::Auto); // 06:00 real at 2x: noon + CHECK(c.Hour == 12); + CHECK(c.Minute == 0); + CHECK(c.Speed == NormalSpeed * 2.0f); + c = ShownClock(midnight + 4 * 3600, 3, SkyMode::Auto); // 04:00 real at 3x: noon + CHECK(c.Hour == 12); + c = ShownClock(midnight + 12 * 3600 + 20 * 60, 2, SkyMode::Auto); // 12:20 real at 2x: 00:40 of the second day + CHECK(c.Hour == 0); + CHECK(c.Minute == 40); + // the last minute before the real midnight and the first after it: 23:58 and 00:00 at 2x + c = ShownClock(midnight - 60, 2, SkyMode::Auto); + CHECK(c.Hour == 23); + CHECK(c.Minute == 58); + c = ShownClock(midnight, 2, SkyMode::Auto); + CHECK(c.Hour == 0); + CHECK(c.Minute == 0); + // 24x: a day in an hour + c = ShownClock(midnight + 30 * 60, 24, SkyMode::Auto); + CHECK(c.Hour == 12); +} + +TEST_CASE("Every player sees the same sky: the clock depends on the time alone", "[ClassicDayCycle]") +{ + using namespace DayCycle; + for (int64 t : { int64(0), int64(1794614400), int64(1794646290), int64(-3600) }) + for (uint32 s : { 1u, 2u, 3u, 24u }) + { + SkyClock a = ShownClock(t, s, SkyMode::Auto), b = ShownClock(t, s, SkyMode::Auto); + CHECK(a.Hour == b.Hour); + CHECK(a.Minute == b.Minute); + CHECK(a.Hour >= 0); + CHECK(a.Hour < 24); + CHECK(a.Minute >= 0); + CHECK(a.Minute < 60); + } +} + +TEST_CASE(".time day and .time night keep noon and midnight, still", "[ClassicDayCycle]") +{ + using namespace DayCycle; + SkyClock c = ShownClock(1794646290, 3, SkyMode::Day); + CHECK(c.Hour == 12); + CHECK(c.Minute == 0); + CHECK(c.Speed == 0.0f); + c = ShownClock(1794646290, 1, SkyMode::Night); + CHECK(c.Hour == 0); + CHECK(c.Minute == 0); + CHECK(c.Speed == 0.0f); +} + +TEST_CASE("A speed out of range and an unknown saved mode are read safely", "[ClassicDayCycle]") +{ + using namespace DayCycle; + CHECK(ShownClock(1794646290, 0, SkyMode::Auto).Speed == NormalSpeed); + CHECK(ShownClock(1794646290, 100, SkyMode::Auto).Speed == NormalSpeed * float(MaxSpeed)); + CHECK(SkyModeFromDb(0) == SkyMode::Auto); + CHECK(SkyModeFromDb(1) == SkyMode::Day); + CHECK(SkyModeFromDb(2) == SkyMode::Night); + CHECK(SkyModeFromDb(7) == SkyMode::Auto); +}