////// Funnels. weather_sum sum_conditions( const time_point &start, const time_point &end, const tripoint &location ) { time_duration tick_size = 0_turns; weather_sum data; const auto wgen = g->get_cur_weather_gen(); for( time_point t = start; t < end; t += tick_size ) { const time_duration diff = end - t; if( diff < 10_turns ) { tick_size = 1_turns; } else if( diff > 7_days ) { tick_size = 1_hours; } else { tick_size = 1_minutes; } weather_type wtype; if( g->weather_override == WEATHER_NULL ) { wtype = wgen.get_weather_conditions( location, t, g->get_seed() ); } else { wtype = g->weather_override; } proc_weather_sum( wtype, data, t, tick_size ); w_point w = wgen.get_weather( location, t, g->get_seed() ); data.wind_amount += get_local_windpower( g->windspeed, overmap_buffer.ter( location ), location, g->winddirection, false ) * to_turns<int>( tick_size ); } return data; }
////// Funnels. weather_sum sum_conditions( const calendar &startturn, const calendar &endturn, const tripoint &location ) { int tick_size = MINUTES(1); weather_sum data; const auto wgen = g->get_cur_weather_gen(); for( calendar turn(startturn); turn < endturn; turn += tick_size ) { const int diff = endturn - startturn; if( diff <= 0 ) { return data; } else if( diff < 10 ) { tick_size = 1; } else if( diff > DAYS(7) ) { tick_size = HOURS(1); } else { tick_size = MINUTES(1); } const auto wtype = wgen.get_weather_conditions( location, turn, g->get_seed() ); proc_weather_sum( wtype, data, turn, tick_size ); } return data; }
weather_type weather_generator::get_weather_conditions(const point &location, const calendar &t) const { w_point w(get_weather(location, t)); weather_type wt = get_weather_conditions(w); // Make sure we don't say it's sunny at night! =P if (wt == WEATHER_SUNNY && t.is_night()) { return WEATHER_CLEAR; } return wt; }
weather_type weather_generator::get_weather_conditions( const tripoint &location, const time_point &t, unsigned seed ) const { w_point w( get_weather( location, t, seed ) ); weather_type wt = get_weather_conditions( w ); // Make sure we don't say it's sunny at night! =P if( wt == WEATHER_SUNNY && calendar( to_turn<int>( t ) ).is_night() ) { return WEATHER_CLEAR; } return wt; }
////// Funnels. weather_sum sum_conditions( const time_point &start, const time_point &end, const tripoint &location ) { time_duration tick_size = 0; weather_sum data; const auto wgen = g->get_cur_weather_gen(); for( time_point t = start; t < end; t += tick_size ) { const time_duration diff = end - t; if( diff < 10_turns ) { tick_size = 1_turns; } else if( diff > 7_days ) { tick_size = 1_hours; } else { tick_size = 1_minutes; } const auto wtype = wgen.get_weather_conditions( location, to_turn<int>( t ), g->get_seed() ); proc_weather_sum( wtype, data, t, tick_size ); } return data; }
/** * Generate textual weather forecast for the specified radio tower. */ std::string weather_forecast( const point &abs_sm_pos ) { std::ostringstream weather_report; // Local conditions const auto cref = overmap_buffer.closest_city( tripoint( abs_sm_pos, 0 ) ); const std::string city_name = cref ? cref.city->name : std::string( _( "middle of nowhere" ) ); // Current time weather_report << string_format( _( "The current time is %s Eastern Standard Time. At %s in %s, it was %s. The temperature was %s. " ), to_string_time_of_day( calendar::turn ), print_time_just_hour( calendar::turn ), city_name, weather_data( g->weather ).name, print_temperature( g->temperature ) ); //weather_report << ", the dewpoint ???, and the relative humidity ???. "; //weather_report << "The wind was <direction> at ? mi/km an hour. "; //weather_report << "The pressure was ??? in/mm and steady/rising/falling."; // Regional conditions (simulated by choosing a random range containing the current conditions). // Adjusted for weather volatility based on how many weather changes are coming up. //weather_report << "Across <region>, skies ranged from <cloudiest> to <clearest>. "; // TODO: Add fake reports for nearby cities // TODO: weather forecast // forecasting periods are divided into 12-hour periods, day (6-18) and night (19-5) // Accumulate percentages for each period of various weather statistics, and report that // (with fuzz) as the weather chances. // int weather_proportions[NUM_WEATHER_TYPES] = {0}; double high = -100.0; double low = 100.0; const tripoint abs_ms_pos = tripoint( sm_to_ms_copy( abs_sm_pos ), 0 ); // TODO: wind direction and speed const time_point last_hour = calendar::turn - ( calendar::turn - calendar::time_of_cataclysm ) % 1_hours; for( int d = 0; d < 6; d++ ) { weather_type forecast = WEATHER_NULL; const auto wgen = g->get_cur_weather_gen(); for( time_point i = last_hour + d * 12_hours; i < last_hour + ( d + 1 ) * 12_hours; i += 1_hours ) { w_point w = wgen.get_weather( abs_ms_pos, i, g->get_seed() ); forecast = std::max( forecast, wgen.get_weather_conditions( w ) ); high = std::max( high, w.temperature ); low = std::min( low, w.temperature ); } std::string day; bool started_at_night; const time_point c = last_hour + 12_hours * d; if( d == 0 && calendar( to_turn<int>( c ) ).is_night() ) { day = _( "Tonight" ); started_at_night = true; } else { day = _( "Today" ); started_at_night = false; } if( d > 0 && ( ( started_at_night && !( d % 2 ) ) || ( !started_at_night && d % 2 ) ) ) { day = string_format( pgettext( "Mon Night", "%s Night" ), to_string( day_of_week( c ) ) ); } else { day = to_string( day_of_week( c ) ); } weather_report << string_format( _( "%s... %s. Highs of %s. Lows of %s. " ), day, weather_data( forecast ).name, print_temperature( high ), print_temperature( low ) ); } return weather_report.str(); }