Skip to content

Commit b107a90

Browse files
authored
Merge pull request #82369 from ehughsbaird/fix-weather
Fix weather
2 parents 0a8ce52 + 1f8dec6 commit b107a90

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/weather_gen.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ static weather_gen_common get_common_data( const tripoint_abs_ms &location,
6767
result.modSEED = seed % SIMPLEX_NOISE_RANDOM_SEED_LIMIT;
6868
const double year_fraction( time_past_new_year( t.t ) /
6969
calendar::year_length() ); // [0,1)
70-
71-
result.cyf = std::cos( tau * ( year_fraction + .125 ) ); // [-1, 1]
72-
// We add one-eighth to line up `cyf` so that 1 is at
70+
// We add an offset to line up `cyf` so that 1 is at
7371
// midwinter and -1 at midsummer. (Cataclsym DDA years
74-
// start when spring starts. Gregorian years start when
75-
// winter starts.)
72+
// start season_length - turn_zero_offset days into winter.
73+
// Gregorian years start when winter starts.)
74+
// LATER: Do gregorian years start on winter? They start ~10 days into winter...
75+
const double days_year_start_to_midwinter = to_days<double>( ( calendar::season_length() / 2 ) -
76+
( calendar::season_length() - calendar::turn_zero_offset() ) );
77+
const double offset = days_year_start_to_midwinter / to_days<double>( calendar::year_length() );
78+
result.cyf = std::cos( tau * ( year_fraction - offset ) ); // [-1, 1]
7679
result.season = season_of_year( t.t );
7780

7881
return result;

tests/weather_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ static year_of_weather_data collect_weather_data( unsigned seed )
7777
// Collect generated weather data for a single year.
7878
for( time_point i = begin ; i < end ; i += 1_minutes ) {
7979
w_point w = wgen.get_weather( tripoint_abs_ms::zero, i, seed );
80-
int day = to_days<int>( time_past_new_year( i ) );
80+
int day = to_days<int>( i - begin );
8181
int minute = to_minutes<int>( time_past_midnight( i ) );
8282
result.temperature[day][minute] = units::to_fahrenheit( w.temperature );
83-
int hour = to_hours<int>( time_past_new_year( i ) );
83+
int hour = to_hours<int>( i - begin );
8484
*get_weather().weather_precise = w;
8585
result.hourly_precip[hour] +=
8686
precip_mm_per_hour(
@@ -131,8 +131,9 @@ TEST_CASE( "weather_realism", "[weather]" )
131131
CHECK( mean_of_ranges <= 25 );
132132

133133
// Check that summer and winter temperatures are very different.
134-
size_t summer_idx = data.lows.size() / 4;
135-
size_t winter_idx = 5 * data.highs.size() / 6;
134+
// 0 is the start of spring, 1/4 is the start of summer, 1/8 is halfway through
135+
size_t summer_idx = 3 * data.lows.size() / 8;
136+
size_t winter_idx = 7 * data.highs.size() / 8;
136137
double summer_low = data.lows[summer_idx];
137138
double winter_high = data.highs[winter_idx];
138139
{

0 commit comments

Comments
 (0)