Skip to content

Commit

Permalink
Use a slightly more accurate lunar month
Browse files Browse the repository at this point in the history
Previously the in-game lunar month was exactly one third of a season
(30.333 days, by default).  This meant that the lunar cycle matched
perfectly with the seasons / years, unlike the real-world lunar cycle
which is inconveniently mismatched with other calendar units.

Switch it so that, for the default season length, the lunar cycle
matches the real-world synodic month of about 29.5 days.

Also tidy up the code so that it's clearer how this value is arrived at.
  • Loading branch information
jbytheway committed Dec 31, 2019
1 parent b1541cd commit 514fedc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ double default_daylight_level()

moon_phase get_moon_phase( const time_point &p )
{
//One full phase every 1 rl months = 1/3 season length
const time_duration moon_phase_duration = calendar::season_length() / 3.0;
//Switch moon phase at noon so it stays the same all night
static constexpr time_duration synodic_month = 29.530588853 * 1_days;
const time_duration moon_phase_duration =
calendar::season_from_default_ratio() * synodic_month;
// Switch moon phase at noon so it stays the same all night
const time_duration current_day = ( p - calendar::turn_zero ) + 1_days / 2;
const double phase_change = current_day / moon_phase_duration;
const int current_phase = static_cast<int>( round( phase_change * MOON_PHASE_MAX ) ) %
Expand Down

0 comments on commit 514fedc

Please sign in to comment.