float calendar::sunlight() const { int seconds = seconds_past_midnight(); int sunrise_seconds = sunrise().seconds_past_midnight(); int sunset_seconds = sunset().seconds_past_midnight(); int current_phase = int(moon()); if ( current_phase > int(MOON_PHASE_MAX)/2 ) { current_phase = int(MOON_PHASE_MAX) - current_phase; } int moonlight = 1 + int(current_phase * MOONLIGHT_PER_QUATER); if( seconds > sunset_seconds + TWILIGHT_SECONDS || seconds < sunrise_seconds ) { // Night return moonlight; } else if( seconds >= sunrise_seconds && seconds <= sunrise_seconds + TWILIGHT_SECONDS ) { double percent = double(seconds - sunrise_seconds) / TWILIGHT_SECONDS; return double(moonlight) * (1. - percent) + double(DAYLIGHT_LEVEL) * percent; } else if( seconds >= sunset_seconds && seconds <= sunset_seconds + TWILIGHT_SECONDS ) { double percent = double(seconds - sunset_seconds) / TWILIGHT_SECONDS; return double(DAYLIGHT_LEVEL) * (1. - percent) + double(moonlight) * percent; } else { return DAYLIGHT_LEVEL; } }
float calendar::sunlight() const { //Recent lightning strike has lit the area if( g->lightning_active ) { return DAYLIGHT_LEVEL; } int seconds = seconds_past_midnight(); int sunrise_seconds = sunrise().seconds_past_midnight(); int sunset_seconds = sunset().seconds_past_midnight(); int moonlight = 1 + int(moon()) * MOONLIGHT_LEVEL; if( seconds > sunset_seconds + TWILIGHT_SECONDS || seconds < sunrise_seconds ) { // Night return moonlight; } else if( seconds >= sunrise_seconds && seconds <= sunrise_seconds + TWILIGHT_SECONDS ) { double percent = double(seconds - sunrise_seconds) / TWILIGHT_SECONDS; return double(moonlight) * (1. - percent) + double(DAYLIGHT_LEVEL) * percent; } else if( seconds >= sunset_seconds && seconds <= sunset_seconds + TWILIGHT_SECONDS ) { double percent = double(seconds - sunset_seconds) / TWILIGHT_SECONDS; return double(DAYLIGHT_LEVEL) * (1. - percent) + double(moonlight) * percent; } else { return DAYLIGHT_LEVEL; } }
bool calendar::is_night() const { int seconds = seconds_past_midnight(); int sunrise_seconds = sunrise().seconds_past_midnight(); int sunset_seconds = sunset().seconds_past_midnight(); return (seconds > sunset_seconds + TWILIGHT_SECONDS || seconds < sunrise_seconds); }