Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the builds #2789

Merged
merged 4 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ WARNINGS = \
-Wunused-macros \
-Wzero-as-null-pointer-constant \
-Wno-unknown-warning-option \
-Wno-dangling-reference \
-Wno-range-loop-analysis # TODO: Fix warnings instead of disabling
# Uncomment below to disable warnings
#WARNINGS = -w
Expand Down
23 changes: 13 additions & 10 deletions src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

bool lcmatch( const std::string &str, const std::string &qry )
{
if( std::locale().name() != "en_US.UTF-8" && std::locale().name() != "C" ) {
auto &f = std::use_facet<std::ctype<wchar_t>>( std::locale() );
std::locale temp_locale = std::locale();
if( temp_locale.name() != "en_US.UTF-8" && temp_locale.name() != "C" ) {
auto &f = std::use_facet<std::ctype<wchar_t>>( temp_locale );
std::wstring wneedle = utf8_to_wstr( qry );
std::wstring whaystack = utf8_to_wstr( str );

Expand Down Expand Up @@ -225,30 +226,32 @@ std::string trim_punctuation_marks( const std::string &s )
using char_t = std::string::value_type;
std::string to_upper_case( const std::string &s )
{
if( std::locale().name() != "en_US.UTF-8" && std::locale().name() != "C" ) {
const auto &f = std::use_facet<std::ctype<wchar_t>>( std::locale() );
auto temp_locale = std::locale();
if( temp_locale.name() != "en_US.UTF-8" && temp_locale.name() != "C" ) {
const auto &f = std::use_facet<std::ctype<wchar_t>>( temp_locale );
std::wstring wstr = utf8_to_wstr( s );
f.toupper( &wstr[0], &wstr[0] + wstr.size() );
return wstr_to_utf8( wstr );
}
std::string res;
std::transform( s.begin(), s.end(), std::back_inserter( res ), []( char_t ch ) {
return std::use_facet<std::ctype<char_t>>( std::locale() ).toupper( ch );
std::transform( s.begin(), s.end(), std::back_inserter( res ), [&temp_locale]( char_t ch ) {
return std::use_facet<std::ctype<char_t>>( temp_locale ).toupper( ch );
} );
return res;
}

std::string to_lower_case( const std::string &s )
{
if( std::locale().name() != "en_US.UTF-8" && std::locale().name() != "C" ) {
const auto &f = std::use_facet<std::ctype<wchar_t>>( std::locale() );
auto temp_locale = std::locale();
if( temp_locale.name() != "en_US.UTF-8" && temp_locale.name() != "C" ) {
const auto &f = std::use_facet<std::ctype<wchar_t>>( temp_locale );
std::wstring wstr = utf8_to_wstr( s );
f.tolower( &wstr[0], &wstr[0] + wstr.size() );
return wstr_to_utf8( wstr );
}
std::string res;
std::transform( s.begin(), s.end(), std::back_inserter( res ), []( char_t ch ) {
return std::use_facet<std::ctype<char_t>>( std::locale() ).tolower( ch );
std::transform( s.begin(), s.end(), std::back_inserter( res ), [&temp_locale]( char_t ch ) {
return std::use_facet<std::ctype<char_t>>( temp_locale ).tolower( ch );
} );
return res;
}
Expand Down
38 changes: 19 additions & 19 deletions src/weather_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,40 +214,40 @@ const weather_type_id &weather_generator::get_weather_conditions( const w_point
w_point wp2 = w;
const weather_type_id *current_conditions = &weather_type_id::NULL_ID();
for( const weather_type_id &type : weather_types ) {
const weather_requirements &requires = type->requirements;
weather_requirements rq2 = requires;
const weather_requirements &wrequires = type->requirements;
weather_requirements rq2 = wrequires;
bool test_pressure =
requires.pressure_max > w.pressure &&
requires.pressure_min < w.pressure;
wrequires.pressure_max > w.pressure &&
wrequires.pressure_min < w.pressure;
bool test_humidity =
requires.humidity_max > w.humidity &&
requires.humidity_min < w.humidity;
if( ( requires.humidity_and_pressure && !( test_pressure && test_humidity ) ) ||
( !requires.humidity_and_pressure && !( test_pressure || test_humidity ) ) ) {
wrequires.humidity_max > w.humidity &&
wrequires.humidity_min < w.humidity;
if( ( wrequires.humidity_and_pressure && !( test_pressure && test_humidity ) ) ||
( !wrequires.humidity_and_pressure && !( test_pressure || test_humidity ) ) ) {
continue;
}
bool test_temperature =
requires.temperature_max > units::to_fahrenheit( w.temperature ) &&
requires.temperature_min < units::to_fahrenheit( w.temperature );
wrequires.temperature_max > units::to_fahrenheit( w.temperature ) &&
wrequires.temperature_min < units::to_fahrenheit( w.temperature );
bool test_windspeed =
requires.windpower_max > w.windpower &&
requires.windpower_min < w.windpower;
bool test_acidic = !requires.acidic || w.acidic;
wrequires.windpower_max > w.windpower &&
wrequires.windpower_min < w.windpower;
bool test_acidic = !wrequires.acidic || w.acidic;
if( !( test_temperature && test_windspeed && test_acidic ) ) {
continue;
}

if( !requires.required_weathers.empty() ) {
if( std::find( requires.required_weathers.begin(), requires.required_weathers.end(),
*current_conditions ) == requires.required_weathers.end() ) {
if( !wrequires.required_weathers.empty() ) {
if( std::find( wrequires.required_weathers.begin(), wrequires.required_weathers.end(),
*current_conditions ) == wrequires.required_weathers.end() ) {
continue;
}
}

if( requires.time != weather_time_requirement_type::both ) {
if( wrequires.time != weather_time_requirement_type::both ) {
bool day = is_day( calendar::turn );
if( ( requires.time == weather_time_requirement_type::day && !day ) ||
( requires.time == weather_time_requirement_type::night && day ) ) {
if( ( wrequires.time == weather_time_requirement_type::day && !day ) ||
( wrequires.time == weather_time_requirement_type::night && day ) ) {
continue;
}
}
Expand Down