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

@ -4316,21 +4316,26 @@ public sealed class GameWindow : IDisposable
if (_loadedSkyDesc is null || _loadedSkyDesc.DayGroups.Count == 0) if (_loadedSkyDesc is null || _loadedSkyDesc.DayGroups.Count == 0)
return; return;
// Retail FUN_00501990 uses the full (Year, SecondsPerDay, DayOfYear) // Retail FUN_00501990 seeds the LCG with
// triple — NOT a flat dayIndex. The SecondsPerDay multiplier is // (Year_absolute, SecondsPerDay, DayOfYear)
// load-bearing: without it, adjacent years map to adjacent LCG // where Year_absolute = TimeOfDay+0x64 = floor(...) + baseYear
// seeds and convergence to acdream != retail would recur every // (baseYear=10 for Dereth per GameTime.ZeroYear). Our port uses
// year. We use the retail calendar constants from DerethDateTime. // AbsoluteYear which includes the +10 offset; without it, our
// seed would differ from retail's by `10 × SecondsPerDay` and we'd
// pick a different DayGroup (verified mismatch in the 2026-04-23
// live session — acdream picked "Rainy"[17] while retail showed
// "Sunny" at PY 116 ColdMeet 17).
double ticks = WorldTime.NowTicks; double ticks = WorldTime.NowTicks;
int year = AcDream.Core.World.DerethDateTime.Year(ticks); int absYear = AcDream.Core.World.DerethDateTime.AbsoluteYear(ticks);
int dayOfYear = AcDream.Core.World.DerethDateTime.DayOfYear(ticks); int dayOfYear = AcDream.Core.World.DerethDateTime.DayOfYear(ticks);
int secondsPerDay = (int)AcDream.Core.World.DerethDateTime.DayTicks; // 7620 int secondsPerDay = (int)AcDream.Core.World.DerethDateTime.DayTicks; // 7620
// Compute a composite "dayIndex" for our own change-detection // Composite day key for change-detection and logging only; the
// and logging (doesn't feed into the roll itself). // LCG seed is computed inside SelectDayGroupIndex from (absYear,
long dayIndex = (long)year * 360 + dayOfYear; // secondsPerDay, dayOfYear).
long dayIndex = (long)absYear * 360 + dayOfYear;
int idx = _loadedSkyDesc.SelectDayGroupIndex(year, secondsPerDay, dayOfYear); int idx = _loadedSkyDesc.SelectDayGroupIndex(absYear, secondsPerDay, dayOfYear);
var grp = idx >= 0 && idx < _loadedSkyDesc.DayGroups.Count var grp = idx >= 0 && idx < _loadedSkyDesc.DayGroups.Count
? _loadedSkyDesc.DayGroups[idx] ? _loadedSkyDesc.DayGroups[idx]
: null; : null;
@ -4350,7 +4355,7 @@ public sealed class GameWindow : IDisposable
grp.SkyTimes.Select(s => s.Keyframe).ToList())); grp.SkyTimes.Select(s => s.Keyframe).ToList()));
Console.WriteLine( Console.WriteLine(
$"sky: PY{year} day{dayOfYear} → DayGroup[{idx}] \"{grp.Name}\" " + $"sky: PY{absYear} day{dayOfYear} → DayGroup[{idx}] \"{grp.Name}\" " +
$"(Chance={grp.ChanceOfOccur:F2}, {grp.SkyObjects.Count} objects, " + $"(Chance={grp.ChanceOfOccur:F2}, {grp.SkyObjects.Count} objects, " +
$"{grp.SkyTimes.Count} keyframes)"); $"{grp.SkyTimes.Count} keyframes)");
} }

View file

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

View file

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