18 protocol::Weather weather;
22constexpr std::array<Odds, 5>
kMeadows = {{{protocol::WEATHER_CLEAR, 7},
23 {protocol::WEATHER_CLOUDY, 4},
24 {protocol::WEATHER_RAIN, 5},
25 {protocol::WEATHER_STORM, 2},
26 {protocol::WEATHER_MIST, 2}}};
27constexpr std::array<Odds, 3>
kAshlands = {{{protocol::WEATHER_CLEAR, 7},
28 {protocol::WEATHER_ASH, 6},
29 {protocol::WEATHER_FIRE, 7}}};
30constexpr std::array<Odds, 2>
kCrypt = {
31 {{protocol::WEATHER_CLEAR, 1}, {protocol::WEATHER_MIST, 1}}};
36constexpr float kMistFrom = 0.1f;
37constexpr float kMistTo = 0.35f;
40uint64_t Mixed(uint64_t z) {
41 z += 0x9E3779B97F4A7C15ull;
42 z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull;
43 z = (z ^ (z >> 27)) * 0x94D049BB133111EBull;
48float Fraction(uint64_t seed,
int n) {
49 return static_cast<float>(Mixed(seed +
static_cast<uint64_t
>(n)) >> 40) /
50 static_cast<float>(1ull << 24);
53template <std::
size_t N>
54protocol::Weather Pick(
const std::array<Odds, N>& odds,
float roll) {
56 for (
const Odds& o : odds) {
59 float left = roll *
static_cast<float>(total);
60 for (
const Odds& o : odds) {
61 left -=
static_cast<float>(o.weight);
66 return odds.back().weather;
69protocol::Weather PickFor(
int land,
float roll) {
80float DayAt(int64_t unix_ms) {
82 return static_cast<float>(into) /
static_cast<float>(
kDayMs);
87protocol::Sky
SkyAt(
int land, int64_t unix_ms) {
89 sky.set_day(DayAt(unix_ms));
92 const int64_t start = slot *
kSlotMs;
94 Mixed(
static_cast<uint64_t
>(slot) * 7919u +
95 kLands[
static_cast<std::size_t
>(land) %
kLands.size()].seed);
96 protocol::Weather weather = PickFor(land, Fraction(seed, 0));
97 if (weather == protocol::WEATHER_MIST && !
kLands[land].dungeon) {
98 const float day = DayAt(start);
99 if (day < kMistFrom || day > kMistTo) {
100 weather = protocol::WEATHER_CLOUDY;
103 const int64_t lasts =
105 static_cast<int64_t
>(Fraction(seed, 1) *
107 const float peak = 0.55f + 0.45f * Fraction(seed, 2);
108 const int64_t into = unix_ms - start;
111 std::clamp(
static_cast<float>(std::min(into, lasts - into)) /
114 if (into < lasts && weather != protocol::WEATHER_CLEAR) {
115 sky.set_weather(weather);
116 sky.set_strength(peak * ramp);
119 const float turn = 6.2831853f * Fraction(seed, 3);
120 const float storm = sky.weather() == protocol::WEATHER_STORM ||
121 sky.weather() == protocol::WEATHER_FIRE
124 const float speed = 1.0f + 2.0f * Fraction(seed, 4) + 4.0f * storm;
125 sky.set_wind_x(speed * std::cos(turn));
126 sky.set_wind_z(speed * std::sin(turn));
131 return std::chrono::duration_cast<std::chrono::milliseconds>(
132 std::chrono::system_clock::now().time_since_epoch())
constexpr int64_t kShortestSpellMs
int64_t UnixMs()
Now, by the wall clock, in milliseconds since 1970.
constexpr int64_t kDayMs
From one midnight to the next, in milliseconds of the wall clock.
constexpr std::array< Land, 3 > kLands
protocol::Sky SkyAt(int land, int64_t unix_ms)
constexpr int64_t kSlotMs
constexpr int64_t kRampMs
How long a spell takes to come, and to go, in milliseconds.