sky(phase-3c.1): feed AbsoluteYear (Year+ZeroYear) to retail LCG picker

Live verification (2026-04-23, Phase 3c launch): acdream picked
DayGroup[17] "Rainy" for PY106 day46 while retail at the same server
tick showed clear blue sky with white clouds (Sunny-ish). Root cause:
our port passed the RELATIVE year (106, i.e. years since tick-0) into
the LCG seed, while retail's TimeOfDay+0x64 is ABSOLUTE Year =
floor(...) + ZeroYear (baseYear=10 for Dereth GameTime). The offset
seeds the LCG with `seed = 106×7620+46` vs retail's `seed =
116×7620+46` — `10 × SecondsPerDay = 76200` apart, guaranteed to
land on a different DayGroup index.

Fix:
- DerethDateTime.ZeroYear constant (= 10) + AbsoluteYear(ticks) helper.
- GameWindow.RefreshSkyForCurrentDay feeds AbsoluteYear into the picker.
- LoadedSkyDesc.ActiveDayGroup(ticks) same.
- Calendar display and generic Year(ticks) stay relative; only the
  LCG-seed path uses the offset. Matches retail FUN_005a7510:5300 which
  explicitly adds baseYear to the relative year before stashing in
  TimeOfDay+0x64.

Build + 717 tests green. Next visual check should show matching
weather with retail client side-by-side.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-24 08:51:42 +02:00
parent 6ea87b7ea8
commit f466c337ce
3 changed files with 43 additions and 20 deletions

View file

@ -57,6 +57,15 @@ public static class DerethDateTime
/// </summary>
public const double MaxTicks = 1_073_741_828.0;
/// <summary>
/// Base/anchor year for the Portal Year calendar (retail
/// <c>GameTime.ZeroYear</c> = 10). Tick 0 corresponds to PY 10,
/// Morningthaw 1, Morntide-and-Half. Retail's <c>TimeOfDay+0x64</c>
/// ("absolute year") includes this offset, and <c>SkyDesc::PickCurrentDayGroup</c>
/// (<c>FUN_00501990</c>) feeds the absolute year into its LCG seed.
/// </summary>
public const int ZeroYear = 10;
/// <summary>
/// The 16 named hour slots (r12 §1.2). Each one is half a Derethian
/// hour; the "-and-Half" variants are the second half.
@ -178,13 +187,11 @@ public static class DerethDateTime
}
/// <summary>
/// Absolute year since tick-0 (PY 0, Snowreap 1, Morntide-and-Half).
/// Matches retail's <c>TimeOfDay + 0x64</c> field which is
/// <c>floor((worldTime + base) / secsPerYear) + baseYear</c>. For
/// acdream's purposes we treat ZeroYear=0 since only the RELATIVE
/// year is needed for deterministic day-group rolling (retail and
/// acdream agree as long as both apply the same derivation to the
/// server's PortalYearTicks).
/// Year offset from tick-0 (number of Derethian years elapsed since
/// the PY <see cref="ZeroYear"/> anchor). Use for time-delta math.
/// For calendar display and for the retail
/// <c>SkyDesc::PickCurrentDayGroup</c> LCG seed, use
/// <see cref="AbsoluteYear"/> which adds the <c>ZeroYear</c> base.
/// </summary>
public static int Year(double ticks)
{
@ -192,6 +199,17 @@ public static class DerethDateTime
return (int)(ticks / YearTicks);
}
/// <summary>
/// Absolute Portal Year (<see cref="ZeroYear"/> + relative year).
/// Matches retail's <c>TimeOfDay + 0x64</c> field
/// (<c>FUN_005a7510:5300</c>:
/// <c>floor((worldTime+base)/secsPerYear) + baseYear</c>). This is
/// the value the retail DayGroup picker (<c>FUN_00501990</c>) feeds
/// into its LCG seed, so acdream must match for identical weather
/// picks vs retail.
/// </summary>
public static int AbsoluteYear(double ticks) => Year(ticks) + ZeroYear;
/// <summary>
/// Day index within the current Derethian year in [0, 359] (360 days
/// per year = 12 months × 30). Matches retail's <c>TimeOfDay + 0x68</c>

View file

@ -235,10 +235,10 @@ public sealed class LoadedSkyDesc
/// </summary>
public DayGroupData? ActiveDayGroup(double serverTicks)
{
int year = DerethDateTime.Year(serverTicks);
int absYear = DerethDateTime.AbsoluteYear(serverTicks);
int dayOfYear = DerethDateTime.DayOfYear(serverTicks);
int secondsPerDay = (int)DerethDateTime.DayTicks; // 7620
int idx = SelectDayGroupIndex(year, secondsPerDay, dayOfYear);
int idx = SelectDayGroupIndex(absYear, secondsPerDay, dayOfYear);
return idx < DayGroups.Count ? DayGroups[idx] : null;
}