From 159413daa279694aeaf7885edde67f496d61d473 Mon Sep 17 00:00:00 2001 From: John Bytheway <52664+jbytheway@users.noreply.github.com> Date: Mon, 12 Jul 2021 13:17:17 -0400 Subject: [PATCH] Enable clang-tidy bugprone-branch-clone (#49629) * Enable bugprone-branch-clone This check looks for multiple branches of an else-if-chain or switch that are the same. This is often a sign of a copy/paste error. The cases that hit in these changes did not include any copy/paste errors, as far as I could see, but they did highlight quite a few cases where the code could be usefully refactored. I did that, and in other cases I just suppressed the error. Did fix one small bug related to furniture moving weariness, but that was just because I happened to be pointed at nearby code, not because it specifically related to the check. * Move utf32_to_utf8 to json.cpp When I deduplicated this function I previously kept the version in catacharset.cpp, but that breaks the link for the json formatter, so instead keep the version in json.cpp. Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com> Co-authored-by: Kevin Granade --- .clang-tidy | 1 - src/action.cpp | 12 ++-- src/activity_handlers.cpp | 6 +- src/activity_item_handling.cpp | 10 ++- src/advanced_inv.cpp | 4 +- src/auto_pickup.cpp | 5 +- src/cata_tiles.cpp | 26 +++----- src/catacharset.cpp | 40 ------------ src/cellular_automata.h | 15 ++--- src/character.cpp | 73 ++++++++++------------ src/computer.cpp | 4 +- src/construction.cpp | 5 +- src/consumption.cpp | 7 +-- src/crafting.cpp | 6 +- src/cursesport.cpp | 3 +- src/editmap.cpp | 7 +-- src/effect.cpp | 10 ++- src/faction_camp.cpp | 7 +-- src/game.cpp | 54 ++++++++-------- src/game_inventory.cpp | 6 +- src/handle_action.cpp | 23 +++---- src/handle_liquid.cpp | 4 +- src/input.cpp | 5 +- src/item.cpp | 20 ++---- src/json.cpp | 24 +++---- src/main_menu.cpp | 7 +-- src/map.cpp | 12 ++-- src/map_extras.cpp | 1 - src/map_field.cpp | 10 ++- src/mapgen.cpp | 36 +++++------ src/mapgen_functions.cpp | 4 +- src/martialarts.cpp | 10 +-- src/mission_companion.cpp | 13 ++-- src/monattack.cpp | 16 +++-- src/monmove.cpp | 18 +++--- src/monster.cpp | 30 ++++----- src/mtype.cpp | 5 +- src/mutation.cpp | 7 +-- src/newcharacter.cpp | 20 +++--- src/npc.cpp | 21 ++----- src/npcmove.cpp | 30 ++++----- src/npctalk.cpp | 8 +-- src/options.cpp | 10 ++- src/output.cpp | 16 +++-- src/overmap.cpp | 57 +++++------------ src/panels.cpp | 4 +- src/pickup.cpp | 3 +- src/player.cpp | 2 +- src/player_hardcoded_effects.cpp | 6 -- src/ranged.cpp | 5 +- src/relic.cpp | 3 +- src/savegame_json.cpp | 5 +- src/scent_block.h | 8 +-- src/shadowcasting.cpp | 52 +++++++++------ src/sounds.cpp | 7 +-- src/string_formatter.h | 2 +- src/string_input_popup.cpp | 3 +- src/trapfunc.cpp | 38 ++++++----- src/ui.cpp | 23 +++---- src/vehicle.cpp | 14 ++--- src/vehicle_part.cpp | 2 +- src/weather.cpp | 16 +---- tests/shadowcasting_test.cpp | 8 +-- tests/unseal_and_spill_test.cpp | 32 +--------- tools/clang-tidy-plugin/TextStyleCheck.cpp | 5 +- 65 files changed, 365 insertions(+), 581 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7d8916ba46fdb..538eff031f715 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -46,7 +46,6 @@ modernize-*,\ performance-*,\ readability-*,\ -readability-braces-around-statements,\ --bugprone-branch-clone,\ -bugprone-infinite-loop,\ -bugprone-misplaced-widening-cast,\ -bugprone-narrowing-conversions,\ diff --git a/src/action.cpp b/src/action.cpp index 4e4e5b39e4ca0..6fd969408d033 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -69,8 +69,8 @@ void parse_keymap( std::istream &keymap_txt, std::map &kmap, while( !keymap_txt.eof() ) { std::string id; keymap_txt >> id; - if( id.empty() ) { - // Empty line, chomp it + if( id.empty() || id[0] == '#' ) { + // Empty line or comment, chomp it getline( keymap_txt, id ); } else if( id == "unbind" ) { keymap_txt >> id; @@ -79,7 +79,7 @@ void parse_keymap( std::istream &keymap_txt, std::map &kmap, unbound_keymap.insert( act ); } break; - } else if( id[0] != '#' ) { + } else { const action_id act = look_up_action( id ); if( act == ACTION_NULL ) { debugmsg( "Warning! keymap.txt contains an unknown action, \"%s\"\n" @@ -101,9 +101,6 @@ void parse_keymap( std::istream &keymap_txt, std::map &kmap, } } } - } else { - // Clear the whole line - getline( keymap_txt, id ); } } } @@ -659,7 +656,8 @@ bool can_examine_at( const tripoint &p ) if( here.has_furn( p ) && xfurn_t.can_examine() ) { return true; - } else if( xter_t.can_examine() ) { + } + if( xter_t.can_examine() ) { return true; } diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index 6a30308d8b8bf..e2768289cbc94 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -892,10 +892,10 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player & // QUICK BUTCHERY if( action == butcher_type::QUICK ) { if( entry.type == "flesh" ) { - roll = roll / 4; - } else if( entry.type == "bone" ) { + roll /= 4; + } else if( entry.type == "bone" ) { // NOLINT(bugprone-branch-clone) roll /= 2; - } else if( corpse_item->get_mtype()->size >= creature_size::medium && ( entry.type == "skin" ) ) { + } else if( corpse_item->get_mtype()->size >= creature_size::medium && entry.type == "skin" ) { roll /= 2; } else if( entry.type == "offal" ) { roll /= 5; diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index c15b5502b2fcb..cbb4a39f40d9b 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -2336,10 +2336,14 @@ static std::unordered_set generic_multi_activity_locations( player &p, const tripoint set_pt = here.getlocal( *it2 ); if( here.dangerous_field_at( set_pt ) ) { it2 = src_set.erase( it2 ); - // remove tiles in darkness, if we aren't lit-up ourselves - } else if( !dark_capable && p.fine_detail_vision_mod( set_pt ) > 4.0 ) { + continue; + } + // remove tiles in darkness, if we aren't lit-up ourselves + if( !dark_capable && p.fine_detail_vision_mod( set_pt ) > 4.0 ) { it2 = src_set.erase( it2 ); - } else if( act_id == ACT_MULTIPLE_FISH ) { + continue; + } + if( act_id == ACT_MULTIPLE_FISH ) { const ter_id terrain_id = here.ter( set_pt ); if( !terrain_id.obj().has_flag( TFLAG_DEEP_WATER ) ) { it2 = src_set.erase( it2 ); diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index 8765c31d671c0..341ebf798f4c9 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -845,7 +845,9 @@ bool advanced_inventory::move_all_items() if( dpane.get_area() == AIM_DRAGGED && sarea.pos == darea.pos && spane.in_vehicle() == dpane.in_vehicle() ) { return false; - } else if( spane.get_area() == dpane.get_area() && spane.in_vehicle() == dpane.in_vehicle() ) { + } + + if( spane.get_area() == dpane.get_area() && spane.in_vehicle() == dpane.in_vehicle() ) { return false; } diff --git a/src/auto_pickup.cpp b/src/auto_pickup.cpp index 881f84cd54bf8..b3955430d678f 100644 --- a/src/auto_pickup.cpp +++ b/src/auto_pickup.cpp @@ -672,8 +672,9 @@ void rule_list::create_rule( cache &map_items, const item &it ) for( const rule &elem : *this ) { if( !elem.bActive ) { continue; - } else if( !check_special_rule( it.made_of(), elem.sRule ) && - !wildcard_match( to_match, elem.sRule ) ) { + } + if( !check_special_rule( it.made_of(), elem.sRule ) && + !wildcard_match( to_match, elem.sRule ) ) { continue; } diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index b6f9d2fee67a0..51e3705048ba8 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -327,15 +327,10 @@ static void get_tile_information( const std::string &config_path, std::string &j std::string sOption; fin >> sOption; - if( sOption.empty() ) { - getline( fin, sOption ); - } else if( sOption[0] == '#' ) { - // Skip comment - getline( fin, sOption ); - } else if( sOption.find( "JSON" ) != std::string::npos ) { + if( string_starts_with( sOption, "JSON" ) ) { fin >> json_path; dbg( D_INFO ) << "JSON path set to [" << json_path << "]."; - } else if( sOption.find( "TILESET" ) != std::string::npos ) { + } else if( string_starts_with( sOption, "TILESET" ) ) { fin >> tileset_path; dbg( D_INFO ) << "TILESET path set to [" << tileset_path << "]."; } else { @@ -2395,25 +2390,20 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &, const furn_t &curr_furn = here.furn( pbelow ).obj(); int part_below; int sizefactor = 2; - const vehicle *veh; - // const vehicle *veh; - if( curr_furn.has_flag( TFLAG_SEEN_FROM_ABOVE ) ) { + if( curr_furn.has_flag( TFLAG_SEEN_FROM_ABOVE ) || curr_furn.movecost < 0 ) { tercol = curses_color_to_SDL( curr_furn.color() ); - } else if( curr_furn.movecost < 0 ) { - tercol = curses_color_to_SDL( curr_furn.color() ); - } else if( ( veh = here.veh_at_internal( pbelow, part_below ) ) != nullptr ) { + } else if( const vehicle *veh = here.veh_at_internal( pbelow, part_below ) ) { const int roof = veh->roof_at_part( part_below ); const auto vpobst = vpart_position( const_cast( *veh ), part_below ).obstacle_at_part(); tercol = curses_color_to_SDL( ( roof >= 0 || vpobst ) ? c_light_gray : c_magenta ); sizefactor = ( roof >= 0 || vpobst ) ? 4 : 2; - } else if( curr_ter.has_flag( TFLAG_SEEN_FROM_ABOVE ) || curr_ter.movecost == 0 ) { - tercol = curses_color_to_SDL( curr_ter.color() ); - } else if( !curr_ter.has_flag( TFLAG_NO_FLOOR ) ) { - sizefactor = 4; + } else if( curr_ter.has_flag( TFLAG_SEEN_FROM_ABOVE ) || curr_ter.has_flag( TFLAG_NO_FLOOR ) || + curr_ter.movecost == 0 ) { tercol = curses_color_to_SDL( curr_ter.color() ); } else { + sizefactor = 4; tercol = curses_color_to_SDL( curr_ter.color() ); } @@ -3546,8 +3536,6 @@ void cata_tiles::draw_custom_explosion_frame() rotation = 3; break; case N_NO_NEIGHBORS: - subtile = edge; - break; case N_WEST | N_EAST | N_NORTH | N_SOUTH: // Needs some special tile subtile = edge; diff --git a/src/catacharset.cpp b/src/catacharset.cpp index a41b13f9eb6d4..92c0137bdee4a 100644 --- a/src/catacharset.cpp +++ b/src/catacharset.cpp @@ -98,46 +98,6 @@ uint32_t UTF8_getch( const char **src, int *srclen ) return ch; } -std::string utf32_to_utf8( uint32_t ch ) -{ - char out[5]; - char *buf = out; - static const unsigned char utf8FirstByte[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - int utf8Bytes; - if( ch < 0x80 ) { - utf8Bytes = 1; - } else if( ch < 0x800 ) { - utf8Bytes = 2; - } else if( ch < 0x10000 ) { - utf8Bytes = 3; - } else if( ch <= 0x10FFFF ) { - utf8Bytes = 4; - } else { - utf8Bytes = 3; - ch = UNKNOWN_UNICODE; - } - - buf += utf8Bytes; - switch( utf8Bytes ) { - case 4: - *--buf = ( ch | 0x80 ) & 0xBF; - ch >>= 6; - /* fallthrough */ - case 3: - *--buf = ( ch | 0x80 ) & 0xBF; - ch >>= 6; - /* fallthrough */ - case 2: - *--buf = ( ch | 0x80 ) & 0xBF; - ch >>= 6; - /* fallthrough */ - case 1: - *--buf = ch | utf8FirstByte[utf8Bytes]; - } - out[utf8Bytes] = '\0'; - return out; -} - //Calculate width of a Unicode string //Latin characters have a width of 1 //CJK characters have a width of 2, etc diff --git a/src/cellular_automata.h b/src/cellular_automata.h index 477bac72af379..b443c8ac4be7e 100644 --- a/src/cellular_automata.h +++ b/src/cellular_automata.h @@ -82,16 +82,13 @@ inline std::vector> generate_cellular_automaton( const int widt // Count our neighbors. const int neighbors = neighbor_count( current, width, height, point( i, j ) ); - // Dead and > birth_limit neighbors, so become alive. - if( ( current[i][j] == 0 ) && ( neighbors > birth_limit ) ) { + // Dead and > birth_limit neighbors, become alive. + // Alive and > stasis_limit neighbors, stay alive. + const int to_live = current[i][j] ? stasis_limit : birth_limit; + if( neighbors > to_live ) { next[i][j] = 1; - } - // Alive and > statis_limit neighbors, so stay alive. - else if( ( current[i][j] == 1 ) && ( neighbors > stasis_limit ) ) { - next[i][j] = 1; - } - // Else, die. - else { + // Else, die. + } else { next[i][j] = 0; } } diff --git a/src/character.cpp b/src/character.cpp index 10f974a68b90c..8f4626d8d6b93 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -724,9 +724,7 @@ double Character::aim_cap_from_volume( const item &gun ) const double aim_cap = std::min( 49.0, 49.0 - static_cast( wielded_volume / 75_ml ) ); // TODO: also scale with skill level. - if( gun_skill == skill_smg ) { - aim_cap = std::max( 12.0, aim_cap ); - } else if( gun_skill == skill_shotgun ) { + if( gun_skill == skill_smg || gun_skill == skill_shotgun ) { aim_cap = std::max( 12.0, aim_cap ); } else if( gun_skill == skill_pistol ) { aim_cap = std::max( 15.0, aim_cap * 1.25 ); @@ -2298,7 +2296,8 @@ bool Character::can_fuel_bionic_with( const item &it ) const for( const material_id &fuel : bid->fuel_opts ) { if( fuel == it.get_base_material().id ) { return true; - } else if( it.type->magazine && fuel == item( it.ammo_current() ).get_base_material().id ) { + } + if( it.type->magazine && fuel == item( it.ammo_current() ).get_base_material().id ) { return true; } } @@ -2313,9 +2312,8 @@ std::vector Character::get_bionic_fueled_with( const item &it ) const for( const bionic_id &bid : get_bionics() ) { for( const material_id &fuel : bid->fuel_opts ) { - if( fuel == it.get_base_material().id ) { - bionics.emplace_back( bid ); - } else if( it.type->magazine && fuel == item( it.ammo_current() ).get_base_material().id ) { + if( fuel == it.get_base_material().id || + ( it.type->magazine && fuel == item( it.ammo_current() ).get_base_material().id ) ) { bionics.emplace_back( bid ); } } @@ -6997,7 +6995,7 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) // Some mutants have different comfort needs if( !plantsleep && !webforce ) { - if( in_shell ) { + if( in_shell ) { // NOLINT(bugprone-branch-clone) comfort += 1 + static_cast( comfort_level::slightly_comfortable ); // Note: shelled individuals can still use sleeping aids! } else if( vp ) { @@ -7091,9 +7089,8 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) } } } - if( fungaloid_cosplay && here.has_flag_ter_or_furn( "FUNGUS", pos() ) ) { - comfort += static_cast( comfort_level::very_comfortable ); - } else if( watersleep && here.has_flag_ter( "SWIMMABLE", pos() ) ) { + if( ( fungaloid_cosplay && here.has_flag_ter_or_furn( "FUNGUS", pos() ) ) || + ( watersleep && here.has_flag_ter( "SWIMMABLE", pos() ) ) ) { comfort += static_cast( comfort_level::very_comfortable ); } } else if( plantsleep ) { @@ -7227,11 +7224,9 @@ bodypart_id Character::body_window( const std::string &menu_header, const bool limb_is_broken = is_limb_broken( bp ); const bool limb_is_mending = worn_with_flag( flag_SPLINT, bp ); - if( show_all ) { + if( show_all || has_curable_effect ) { // NOLINT(bugprone-branch-clone) e.allowed = true; - } else if( has_curable_effect ) { - e.allowed = true; - } else if( limb_is_broken ) { + } else if( limb_is_broken ) { // NOLINT(bugprone-branch-clone) e.allowed = false; } else if( current_hp < maximal_hp && ( e.bonus != 0 || bandage_power > 0.0f || disinfectant_power > 0.0f ) ) { @@ -9044,9 +9039,6 @@ int Character::item_wear_cost( const item &it ) const double mv = item_handling_cost( it ); switch( it.get_layer() ) { - case layer_level::PERSONAL: - break; - case layer_level::UNDERWEAR: mv *= 1.5; break; @@ -9063,9 +9055,8 @@ int Character::item_wear_cost( const item &it ) const mv /= 2.0; break; + case layer_level::PERSONAL: case layer_level::AURA: - break; - default: break; } @@ -11239,13 +11230,11 @@ int Character::temp_corrected_by_climate_control( int temperature ) const temperature = BODYTEMP_VERY_HOT; } else if( temperature > BODYTEMP_VERY_HOT ) { temperature = BODYTEMP_HOT; - } else if( temperature > BODYTEMP_HOT ) { - temperature = BODYTEMP_NORM; } else if( temperature < BODYTEMP_FREEZING ) { temperature = BODYTEMP_VERY_COLD; } else if( temperature < BODYTEMP_VERY_COLD ) { temperature = BODYTEMP_COLD; - } else if( temperature < BODYTEMP_COLD ) { + } else { temperature = BODYTEMP_NORM; } } @@ -11448,11 +11437,14 @@ bool Character::has_fire( const int quantity ) const if( get_map().has_nearby_fire( pos() ) ) { return true; - } else if( has_item_with_flag( flag_FIRE ) ) { + } + if( has_item_with_flag( flag_FIRE ) ) { return true; - } else if( !find_firestarter_with_charges( quantity ).is_null() ) { + } + if( !find_firestarter_with_charges( quantity ).is_null() ) { return true; - } else if( is_npc() ) { + } + if( is_npc() ) { // HACK: A hack to make NPCs use their Molotovs return true; } @@ -11497,21 +11489,22 @@ void Character::use_fire( const int quantity ) if( get_map().has_nearby_fire( pos() ) ) { return; - } else if( has_item_with_flag( flag_FIRE ) ) { + } + if( has_item_with_flag( flag_FIRE ) ) { + return; + } + + const item firestarter = find_firestarter_with_charges( quantity ); + if( firestarter.is_null() ) { + return; + } + if( firestarter.type->has_flag( flag_USES_BIONIC_POWER ) ) { + mod_power_level( -quantity * 5_kJ ); + return; + } + if( firestarter.typeId()->can_have_charges() ) { + use_charges( firestarter.typeId(), quantity ); return; - } else { - const item firestarter = find_firestarter_with_charges( quantity ); - if( firestarter.is_null() ) { - return; - } - if( firestarter.type->has_flag( flag_USES_BIONIC_POWER ) ) { - mod_power_level( -quantity * 5_kJ ); - return; - } - if( firestarter.typeId()->can_have_charges() ) { - use_charges( firestarter.typeId(), quantity ); - return; - } } } diff --git a/src/computer.cpp b/src/computer.cpp index 2561be2794bfd..84a6d97a9ac8b 100644 --- a/src/computer.cpp +++ b/src/computer.cpp @@ -203,7 +203,7 @@ static computer_action computer_action_from_legacy_enum( const int val ) switch( val ) { // Used to migrate old saves. Do not change the numbers! // *INDENT-OFF* - default: return COMPACT_NULL; + default: case 0: return COMPACT_NULL; case 1: return COMPACT_OPEN; case 2: return COMPACT_LOCK; @@ -263,7 +263,7 @@ static computer_failure_type computer_failure_type_from_legacy_enum( const int v switch( val ) { // Used to migrate old saves. Do not change the numbers! // *INDENT-OFF* - default: return COMPFAIL_NULL; + default: case 0: return COMPFAIL_NULL; case 1: return COMPFAIL_SHUTDOWN; case 2: return COMPFAIL_ALARM; diff --git a/src/construction.cpp b/src/construction.cpp index 4bffe44e529c7..707e592f29550 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -1933,9 +1933,8 @@ build_reqs get_build_reqs_for_furn_ter_ids( } total_reqs.reqs[build.requirements] += count; for( const auto &req_skill : build.required_skills ) { - if( total_reqs.skills.find( req_skill.first ) == total_reqs.skills.end() ) { - total_reqs.skills[req_skill.first] = req_skill.second; - } else if( total_reqs.skills[req_skill.first] < req_skill.second ) { + auto it = total_reqs.skills.find( req_skill.first ); + if( it == total_reqs.skills.end() || it->second < req_skill.second ) { total_reqs.skills[req_skill.first] = req_skill.second; } } diff --git a/src/consumption.cpp b/src/consumption.cpp index a79bf3d071944..203d788cde68b 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1641,10 +1641,9 @@ time_duration Character::get_consume_time( const item &it ) } } else if( smoking != nullptr ) { time = time_duration::from_minutes( 1 );//about five minutes for a cig or joint so 1 minute a charge - } else if( adrenaline_injector != nullptr ) { - time = time_duration::from_seconds( 15 );//epi-pens are fairly quick - } else if( heal != nullptr ) { - time = time_duration::from_seconds( 15 );//bandages and disinfectant are fairly quick + } else if( adrenaline_injector != nullptr || heal != nullptr ) { + //epi-pens, bandages and disinfectant are fairly quick + time = time_duration::from_seconds( 15 ); } else { time = time_duration::from_seconds( 5 ); //probably pills so quick } diff --git a/src/crafting.cpp b/src/crafting.cpp index f587ed3f276a7..56e4a77590335 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -1523,10 +1523,8 @@ comp_selection Character::select_item_component( const std::vector 0 ) { - player_has.push_back( component ); - found = true; - } else if( has_amount( type, count, false, filter ) ) { + if( ( item_sought.is_software() && count_softwares( type ) > 0 ) || + has_amount( type, count, false, filter ) ) { player_has.push_back( component ); found = true; } diff --git a/src/cursesport.cpp b/src/cursesport.cpp index 268e982592c5a..ccd0e4ead38c2 100644 --- a/src/cursesport.cpp +++ b/src/cursesport.cpp @@ -233,7 +233,8 @@ static inline int fill( const char *&fmt, int &len, std::string &target ) if( cw > 0 && dlen > 0 ) { // Stop at the *second* non-zero-width character break; - } else if( cw == -1 && start == fmt ) { + } + if( cw == -1 && start == fmt ) { // First char is a control character: they only disturb the screen, // so replace it with a single space (e.g. instead of a '\t'). // Newlines at the begin of a sequence are handled in printstring diff --git a/src/editmap.cpp b/src/editmap.cpp index 57dd5b5cf4471..ab62ea6d80693 100644 --- a/src/editmap.cpp +++ b/src/editmap.cpp @@ -1005,7 +1005,6 @@ void apply( const ter_t &t, const shapetype editshape, const tripoint &ta const tripoint &origin, const std::vector &target_list ) { bool isvert = false; - bool ishori = false; bool doalt = false; ter_id teralt = undefined_ter_id; int alta = -1; @@ -1016,7 +1015,6 @@ void apply( const ter_t &t, const shapetype editshape, const tripoint &ta isvert = true; teralt = get_alt_ter( isvert, sel_ter ); } else if( t.symbol() == LINE_OXOX || t.symbol() == '-' ) { - ishori = true; teralt = get_alt_ter( isvert, sel_ter ); } if( teralt != undefined_ter_id ) { @@ -1035,9 +1033,8 @@ void apply( const ter_t &t, const shapetype editshape, const tripoint &ta for( const tripoint &elem : target_list ) { ter_id wter = sel_ter; if( doalt ) { - if( isvert && ( elem.y == alta || elem.y == altb ) ) { - wter = teralt; - } else if( ishori && ( elem.x == alta || elem.x == altb ) ) { + int coord = isvert ? elem.y : elem.x; + if( coord == alta || coord == altb ) { wter = teralt; } } diff --git a/src/effect.cpp b/src/effect.cpp index 4d021d0a7e88d..796b07282a40d 100644 --- a/src/effect.cpp +++ b/src/effect.cpp @@ -556,7 +556,10 @@ bool effect_type::load_decay_msgs( const JsonObject &jo, const std::string &memb } else if( r == "mixed" ) { rate = m_mixed; } else { - rate = m_neutral; + inner.throw_error( + string_format( "Unexpected message type \"%s\"; expected \"good\", " + "\"neutral\", " "\"bad\", or \"mixed\"", r ), + 1 ); } decay_msgs.emplace_back( msg, rate ); } @@ -1396,7 +1399,10 @@ void load_effect_type( const JsonObject &jo ) } else if( r == "mixed" ) { new_etype.rating = e_mixed; } else { - new_etype.rating = e_neutral; + jo.throw_error( + string_format( "Unexpected rating \"%s\"; expected \"good\", \"neutral\", " + "\"bad\", or \"mixed\"", r ), + "rating" ); } } else { new_etype.rating = e_neutral; diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index bb43b99e2d512..4ee8b1daf612e 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -1874,7 +1874,8 @@ void basecamp::job_assignment_ui() smenu.query(); if( smenu.ret == UILIST_CANCEL ) { break; - } else if( smenu.ret == 0 ) { + } + if( smenu.ret == 0 ) { cur_npc->job.clear_all_priorities(); } else if( smenu.ret > 0 && smenu.ret <= static_cast( job_vec.size() ) ) { activity_id sel_job = job_vec[smenu.ret - 1]; @@ -3392,13 +3393,11 @@ time_duration companion_travel_time_calc( const std::vector &j for( const tripoint_abs_omt &om : journey ) { const oter_id &omt_ref = overmap_buffer.ter( om ); std::string om_id = omt_ref.id().c_str(); - //Player walks 1 om is roughly 30 seconds + // Player walks 1 om in roughly 30 seconds if( om_id == "field" ) { one_way += 30 + 30 * haulage; } else if( is_ot_match( "forest_trail", omt_ref, ot_match_type::type ) ) { one_way += 35 + 30 * haulage; - } else if( om_id == "forest" ) { - one_way += 40 + 30 * haulage; } else if( om_id == "forest_thick" ) { one_way += 50 + 30 * haulage; } else if( om_id == "forest_water" ) { diff --git a/src/game.cpp b/src/game.cpp index e7284fe52b176..2c9962121a542 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -875,14 +875,10 @@ vehicle *game::place_vehicle_nearby( std::vector search_types = omt_search_types; if( search_types.empty() ) { vehicle veh( id ); - if( veh.max_ground_velocity() > 0 ) { - search_types.emplace_back( "road" ); - search_types.emplace_back( "field" ); - } else if( veh.can_float() ) { + if( veh.max_ground_velocity() == 0 && veh.can_float() ) { search_types.emplace_back( "river" ); search_types.emplace_back( "lake" ); } else { - // some default locations search_types.emplace_back( "road" ); search_types.emplace_back( "field" ); } @@ -5631,7 +5627,8 @@ bool game::forced_door_closing( const tripoint &p, const ter_id &door_type, int if( elem.made_of( phase_id::LIQUID ) ) { // Liquids are OK, will be destroyed later continue; - } else if( elem.volume() < 250_ml ) { + } + if( elem.volume() < 250_ml ) { // Dito for small items, will be moved away continue; } @@ -6065,17 +6062,17 @@ void game::examine( const tripoint &examp ) const tripoint player_pos = u.pos(); - if( m.has_furn( examp ) && !u.is_mounted() ) { - xfurn_t.examine( u, examp ); - } else if( m.has_furn( examp ) && u.is_mounted() ) { - add_msg( m_warning, _( "You cannot do that while mounted." ) ); - } else { - if( !u.is_mounted() ) { - xter_t.examine( u, examp ); - } else if( u.is_mounted() && !xter_t.can_examine() ) { - xter_t.examine( u, examp ); + if( m.has_furn( examp ) ) { + if( u.is_mounted() ) { + add_msg( m_warning, _( "You cannot do that while mounted." ) ); } else { + xfurn_t.examine( u, examp ); + } + } else { + if( u.is_mounted() && xter_t.can_examine() ) { add_msg( m_warning, _( "You cannot do that while mounted." ) ); + } else { + xter_t.examine( u, examp ); } } @@ -9615,7 +9612,7 @@ std::vector game::get_dangerous_tile( const tripoint &dest_loc ) co for( const field_effect &fe : e.second.field_effects() ) { if( !danger_dest ) { danger_dest = true; - if( fe.immune_in_vehicle && veh_dest ) { + if( fe.immune_in_vehicle && veh_dest ) { // NOLINT(bugprone-branch-clone) danger_dest = false; } else if( fe.immune_inside_vehicle && veh_dest_inside ) { danger_dest = false; @@ -9625,7 +9622,7 @@ std::vector game::get_dangerous_tile( const tripoint &dest_loc ) co } if( has_field_here && !danger_here ) { danger_here = true; - if( fe.immune_in_vehicle && veh_here ) { + if( fe.immune_in_vehicle && veh_here ) { // NOLINT(bugprone-branch-clone) danger_here = false; } else if( fe.immune_inside_vehicle && veh_here_inside ) { danger_here = false; @@ -9667,7 +9664,7 @@ std::vector game::get_dangerous_tile( const tripoint &dest_loc ) co if( m.has_flag( "ROUGH", dest_loc ) && !m.has_flag( "ROUGH", u.pos() ) && !veh_dest && ( u.get_armor_bash( bodypart_id( "foot_l" ) ) < 5 || - u.get_armor_bash( bodypart_id( "foot_r" ) ) < 5 ) ) { + u.get_armor_bash( bodypart_id( "foot_r" ) ) < 5 ) ) { // NOLINT(bugprone-branch-clone) harmful_stuff.emplace_back( m.name( dest_loc ) ); } else if( m.has_flag( "SHARP", dest_loc ) && !m.has_flag( "SHARP", u.pos() ) && !( u.in_vehicle || m.veh_at( dest_loc ) ) && @@ -10045,11 +10042,11 @@ point game::place_player( const tripoint &dest_loc ) body_part_name_accusative( bp ), m.has_flag_ter( "SHARP", dest_loc ) ? m.tername( dest_loc ) : m.furnname( dest_loc ) ); - if( ( u.has_trait( trait_INFRESIST ) ) && ( one_in( 1024 ) ) ) { - u.add_effect( effect_tetanus, 1_turns, true ); - } else if( ( !u.has_trait( trait_INFIMMUNE ) || !u.has_trait( trait_INFRESIST ) ) && - ( one_in( 256 ) ) ) { - u.add_effect( effect_tetanus, 1_turns, true ); + if( !u.has_trait( trait_INFIMMUNE ) ) { + const int chance_in = u.has_trait( trait_INFRESIST ) ? 1024 : 256; + if( one_in( chance_in ) ) { + u.add_effect( effect_tetanus, 1_turns, true ); + } } } } @@ -10501,10 +10498,10 @@ int game::grabbed_furn_move_time( const tripoint &dp ) str_req += furniture_contents_weight / 4_kilogram; const float weary_mult = 1.0f / u.exertion_adjusted_move_multiplier(); - if( !canmove ) { + if( !canmove ) { // NOLINT(bugprone-branch-clone) return 50 * weary_mult; } else if( str_req > u.get_str() && - one_in( std::max( 20 - str_req - u.get_str(), 2 ) ) ) { + one_in( std::max( 20 - ( str_req - u.get_str() ), 2 ) ) ) { return 100 * weary_mult; } else if( !src_item_ok && !dst_item_ok && dst_items > 0 ) { return 50 * weary_mult; @@ -11462,9 +11459,10 @@ cata::optional game::find_or_make_stairs( map &mp, const int z_after, !query_yn( _( "There is a LOT of heat coming out of there, even the stairs have melted away. Jump down? You won't be able to get back up." ) ) ) { return cata::nullopt; - } else if( movez > 0 && - !query_yn( - _( "There is a LOT of heat coming out of there. Push through the half-molten rocks and ascend? You will not be able to get back down." ) ) ) { + } + if( movez > 0 && + !query_yn( + _( "There is a LOT of heat coming out of there. Push through the half-molten rocks and ascend? You will not be able to get back down." ) ) ) { return cata::nullopt; } diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index 0af7c740a3a54..153b04c67ef40 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -571,8 +571,6 @@ class comestible_inventory_preset : public inventory_selector_preset return "!!!"; } else if( health < 0 ) { return "-"; - } else if( loc->is_medication() ) { - return ""; } else { return ""; } @@ -892,9 +890,7 @@ class fuel_inventory_preset : public inventory_selector_preset protected: int get_order( const item_location &loc, const time_duration &time ) const { - if( loc->rotten() ) { - return 2; - } else if( time == 0_turns ) { + if( loc->rotten() || time == 0_turns ) { return 2; } else { return 1; diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 632dea762fdb2..0a0a93cbd4c4a 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -1741,10 +1741,7 @@ static void do_deathcam_action( const action_id &act, avatar &player_character ) g->look_around(); break; - case ACTION_KEYBINDINGS: - // already handled by input context - break; - + case ACTION_KEYBINDINGS: // already handled by input context default: break; } @@ -1754,13 +1751,12 @@ bool game::do_regular_action( action_id &act, avatar &player_character, const cata::optional &mouse_target ) { switch( act ) { - case ACTION_NULL: - case NUM_ACTIONS: - break; // dummy entries - case ACTION_ACTIONMENU: + case ACTION_NULL: // dummy entry + case NUM_ACTIONS: // dummy entry + case ACTION_ACTIONMENU: // handled above case ACTION_MAIN_MENU: case ACTION_KEYBINDINGS: - break; // handled above + break; case ACTION_TIMEOUT: if( check_safe_mode_allowed( false ) ) { @@ -2506,12 +2502,6 @@ bool game::do_regular_action( action_id &act, avatar &player_character, break; case ACTION_DISPLAY_SCENT: - if( MAP_SHARING::isCompetitive() && !MAP_SHARING::isDebugger() ) { - break; //don't do anything when sharing and not debugger - } - display_scent(); - break; - case ACTION_DISPLAY_SCENT_TYPE: if( MAP_SHARING::isCompetitive() && !MAP_SHARING::isDebugger() ) { break; //don't do anything when sharing and not debugger @@ -2702,7 +2692,8 @@ bool game::handle_action() const cata::optional mouse_pos = ctxt.get_coordinates( w_terrain ); if( !mouse_pos ) { return false; - } else if( !player_character.sees( *mouse_pos ) ) { + } + if( !player_character.sees( *mouse_pos ) ) { // Not clicked in visible terrain return false; } diff --git a/src/handle_liquid.cpp b/src/handle_liquid.cpp index 840a43f004c6f..051ddc80c04c3 100644 --- a/src/handle_liquid.cpp +++ b/src/handle_liquid.cpp @@ -337,7 +337,7 @@ static bool get_liquid_target( item &liquid, const item *const source, const int static bool perform_liquid_transfer( item &liquid, const tripoint *const source_pos, const vehicle *const source_veh, const int part_num, - const monster *const source_mon, liquid_dest_opt &target ) + const monster *const /*source_mon*/, liquid_dest_opt &target ) { if( !liquid.made_of_from_type( phase_id::LIQUID ) ) { dbg( D_ERROR ) << "game:handle_liquid: Tried to handle_liquid a non-liquid!"; @@ -356,8 +356,6 @@ static bool perform_liquid_transfer( item &liquid, const tripoint *const source_ player_character.assign_activity( activity_id( "ACT_FILL_LIQUID" ) ); serialize_liquid_source( player_character.activity, *source_pos, liquid ); return true; - } else if( source_mon != nullptr ) { - return false; } else { return false; } diff --git a/src/input.cpp b/src/input.cpp index 588350f13015b..e044c125a1eb1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1354,9 +1354,7 @@ action_id input_context::display_menu( const bool permit_execute_action ) // We're trying to add a global, but this action has a local // defined, so gray out the invlet. mvwprintz( w_help, point( 2, i + 10 ), c_dark_gray, "%c ", invlet ); - } else if( status == s_add || status == s_add_global ) { - mvwprintz( w_help, point( 2, i + 10 ), c_light_blue, "%c ", invlet ); - } else if( status == s_remove ) { + } else if( status == s_add || status == s_add_global || status == s_remove ) { mvwprintz( w_help, point( 2, i + 10 ), c_light_blue, "%c ", invlet ); } else if( status == s_execute ) { mvwprintz( w_help, point( 2, i + 10 ), c_white, "%c ", invlet ); @@ -1565,7 +1563,6 @@ void input_manager::wait_for_any_key() } break; case input_event_t::keyboard_code: - return; // errors are accepted as well to avoid an infinite loop case input_event_t::error: return; diff --git a/src/item.cpp b/src/item.cpp index 05f1502d3a75b..c39a5e8ccdb5d 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -4441,7 +4441,7 @@ nc_color item::color_in_inventory() const } } else if( has_flag( flag_WET ) ) { ret = c_cyan; - } else if( has_flag( flag_LITCIG ) ) { + } else if( has_flag( flag_LITCIG ) ) { // NOLINT(bugprone-branch-clone) ret = c_red; } else if( is_armor() && player_character.has_trait( trait_WOOLALLERGY ) && ( made_of( material_id( "wool" ) ) || has_own_flag( flag_wooled ) ) ) { @@ -4456,11 +4456,8 @@ nc_color item::color_in_inventory() const } } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) { ret = c_light_green; - } else if( active && !has_temperature() && !is_corpse() ) { - // Active items show up as yellow - ret = c_yellow; - } else if( is_corpse() && can_revive() ) { - // Only reviving corpses are yellow + } else if( ( active && !has_temperature() && !is_corpse() ) || ( is_corpse() && can_revive() ) ) { + // Active items show up as yellow (corpses only if reviving) ret = c_yellow; } else if( const item *food = get_food() ) { // Give color priority to allergy (allergy > inedible by freeze or other conditions) @@ -4563,7 +4560,8 @@ nc_color item::color_in_inventory() const if( tmp.skill && // Book can improve skill: blue player_character.get_skill_level_object( tmp.skill ).can_train() && player_character.get_skill_level( tmp.skill ) >= tmp.req && - player_character.get_skill_level( tmp.skill ) < tmp.level ) { + player_character.get_skill_level( tmp.skill ) < tmp.level + ) { //NOLINT(bugprone-branch-clone) ret = c_light_blue; } else if( type->can_use( "MA_MANUAL" ) && !player_character.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) { @@ -6364,13 +6362,7 @@ int item::count() const bool item::craft_has_charges() { - if( count_by_charges() ) { - return true; - } else if( ammo_types().empty() ) { - return true; - } - - return false; + return count_by_charges() || ammo_types().empty(); } #if defined(_MSC_VER) diff --git a/src/json.cpp b/src/json.cpp index 335e59c97d35a..e240883c11193 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -33,8 +33,10 @@ static bool is_whitespace( char ch ) return ( ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r' ); } -// for parsing \uxxxx escapes -static std::string utf16_to_utf8( uint32_t ch ) +// Thw following function would fit more logically in catacharset.cpp, but it's +// needed for the json formatter and we can't easily include that file in that +// binary. +std::string utf32_to_utf8( uint32_t ch ) { char out[5]; char *buf = out; @@ -49,14 +51,13 @@ static std::string utf16_to_utf8( uint32_t ch ) } else if( ch <= 0x10FFFF ) { utf8Bytes = 4; } else { - std::stringstream err; - err << "unknown unicode: " << ch; - throw std::runtime_error( err.str() ); + utf8Bytes = 3; + ch = UNKNOWN_UNICODE; } buf += utf8Bytes; switch( utf8Bytes ) { - case 4: + case 4: // NOLINT(bugprone-branch-clone) *--buf = ( ch | 0x80 ) & 0xBF; ch >>= 6; /* fallthrough */ @@ -1077,12 +1078,7 @@ static bool get_escaped_or_unicode( std::istream &stream, std::string &s, std::s return false; } } - try { - s += utf16_to_utf8( u ); - } catch( const std::exception &e ) { - err = e.what(); - return false; - } + s += utf32_to_utf8( u ); } break; default: @@ -1362,9 +1358,7 @@ number_sci_notation JsonIn::get_any_number() if( ch == 'e' || ch == 'E' ) { stream->get( ch ); bool neg; - if( ( neg = ch == '-' ) ) { - stream->get( ch ); - } else if( ch == '+' ) { + if( ( neg = ch == '-' ) || ch == '+' ) { stream->get( ch ); } while( ch >= '0' && ch <= '9' ) { diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 2cc79817e917b..09ff64d4b9e08 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -142,7 +142,6 @@ void main_menu::print_menu( const catacurses::window &w_open, int iSel, const po switch( current_holiday ) { case holiday::new_year: - break; case holiday::easter: break; case holiday::halloween: @@ -151,9 +150,7 @@ void main_menu::print_menu( const catacurses::window &w_open, int iSel, const po 25, 0, c_white, halloween_graves() ); break; case holiday::thanksgiving: - break; case holiday::christmas: - break; case holiday::none: case holiday::num_holiday: default: @@ -412,9 +409,7 @@ void main_menu::display_text( const std::string &text, const std::string &title, const auto vFolded = foldstring( text, width ); int iLines = vFolded.size(); - if( selected < 0 ) { - selected = 0; - } else if( iLines < height ) { + if( selected < 0 || iLines < height ) { selected = 0; } else if( selected >= iLines - height ) { selected = iLines - height; diff --git a/src/map.cpp b/src/map.cpp index 7c5758d6aae35..45cb4ddd98f48 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3186,7 +3186,7 @@ void map::bash_ter_furn( const tripoint &p, bash_params ¶ms ) // Only allow bashing floors when we want to bash floors and we're in z-level mode // Unless we're destroying, then it gets a little weird if( smash_ter && bash->bash_below && ( !zlevels || !params.bash_floor ) ) { - if( !params.destroy ) { + if( !params.destroy ) { // NOLINT(bugprone-branch-clone) smash_ter = false; bash = nullptr; } else if( !bash->ter_set && zlevels ) { @@ -5923,9 +5923,7 @@ bool map::draw_maptile( const catacurses::window &w, const tripoint &p, tercol = c_magenta; } else if( u_vision[NV_GOGGLES] ) { tercol = param.bright_light() ? c_white : c_light_green; - } else if( param.low_light() ) { - tercol = c_dark_gray; - } else if( u_vision[DARKNESS] ) { + } else if( param.low_light() || u_vision[DARKNESS] ) { tercol = c_dark_gray; } @@ -6017,9 +6015,7 @@ void map::draw_from_above( const catacurses::window &w, const tripoint &p, tercol = c_magenta; } else if( u_vision[NV_GOGGLES] ) { tercol = params.bright_light() ? c_white : c_light_green; - } else if( params.low_light() ) { - tercol = c_dark_gray; - } else if( u_vision[DARKNESS] ) { + } else if( params.low_light() || u_vision[DARKNESS] ) { tercol = c_dark_gray; } @@ -7673,7 +7669,7 @@ int map::determine_wall_corner( const tripoint &p ) const return LINE_XXXO; case 0 | 2 | 1 | 0: return LINE_OXXO; - case 8 | 0 | 1 | 0: + case 8 | 0 | 1 | 0: // NOLINT(bugprone-branch-clone) return LINE_XOXO; case 0 | 0 | 1 | 0: return LINE_XOXO; // LINE_OOXO would be better diff --git a/src/map_extras.cpp b/src/map_extras.cpp index 3d31042f2fd6e..1ef477cfdca83 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -487,7 +487,6 @@ static bool mx_helicopter( map &m, const tripoint &abs_sub ) case 7: // Empty clown car case 8: - break; default: break; } diff --git a/src/map_field.cpp b/src/map_field.cpp index b4534c20dd602..c468a8cd8bd54 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -331,9 +331,8 @@ void map::spread_gas( field_entry &cur, const tripoint &p, int percent_spread, const auto &neigh = neighs[i].second; if( ( neigh.pos_.x != remove_tile.pos_.x && neigh.pos_.y != remove_tile.pos_.y ) || ( neigh.pos_.x != remove_tile2.pos_.x && neigh.pos_.y != remove_tile2.pos_.y ) || - ( neigh.pos_.x != remove_tile3.pos_.x && neigh.pos_.y != remove_tile3.pos_.y ) ) { - neighbour_vec.push_back( i ); - } else if( x_in_y( 1, std::max( 2, windpower ) ) ) { + ( neigh.pos_.x != remove_tile3.pos_.x && neigh.pos_.y != remove_tile3.pos_.y ) || + x_in_y( 1, std::max( 2, windpower ) ) ) { neighbour_vec.push_back( i ); } } @@ -1113,9 +1112,8 @@ void field_processor_fd_fire( const tripoint &p, field_entry &cur, field_proc_da const auto &neigh = neighs[i].second; if( ( neigh.pos().x != remove_tile.pos().x && neigh.pos().y != remove_tile.pos().y ) || ( neigh.pos().x != remove_tile2.pos().x && neigh.pos().y != remove_tile2.pos().y ) || - ( neigh.pos().x != remove_tile3.pos().x && neigh.pos().y != remove_tile3.pos().y ) ) { - neighbour_vec.push_back( i ); - } else if( x_in_y( 1, std::max( 2, windpower ) ) ) { + ( neigh.pos().x != remove_tile3.pos().x && neigh.pos().y != remove_tile3.pos().y ) || + x_in_y( 1, std::max( 2, windpower ) ) ) { neighbour_vec.push_back( i ); } } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index b0faf9718836b..6ab45d4ddc8d9 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -3177,9 +3177,8 @@ void map::draw_lab( mapgendata &dat ) for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { if( i <= 1 || i >= SEEX * 2 - 2 || - ( j > 1 && j < SEEY * 2 - 2 && ( i == SEEX - 2 || i == SEEX + 1 ) ) ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( j <= 1 || j >= SEEY * 2 - 2 ) { + j <= 1 || j >= SEEY * 2 - 2 || + i == SEEX - 2 || i == SEEX + 1 ) { ter_set( point( i, j ), t_concrete_wall ); } else { ter_set( point( i, j ), t_floor ); @@ -3348,11 +3347,10 @@ void map::draw_lab( mapgendata &dat ) for( int j = 0; j < SEEY * 2; j++ ) { if( ( i < lw || i > EAST_EDGE - rw ) || ( ( j < SEEY - 1 || j > SEEY ) && - ( i == SEEX - 2 || i == SEEX + 1 ) ) ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( ( j < tw || j > SOUTH_EDGE - bw ) || - ( ( i < SEEX - 1 || i > SEEX ) && - ( j == SEEY - 2 || j == SEEY + 1 ) ) ) { + ( i == SEEX - 2 || i == SEEX + 1 ) ) || + ( j < tw || j > SOUTH_EDGE - bw ) || + ( ( i < SEEX - 1 || i > SEEX ) && + ( j == SEEY - 2 || j == SEEY + 1 ) ) ) { ter_set( point( i, j ), t_concrete_wall ); } else { ter_set( point( i, j ), t_thconc_floor ); @@ -3453,11 +3451,10 @@ void map::draw_lab( mapgendata &dat ) // tic-tac-toe # layout for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( i < lw || i > EAST_EDGE - rw || i == SEEX - 4 || - i == SEEX + 3 ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( j < tw || j > SOUTH_EDGE - bw || j == SEEY - 4 || - j == SEEY + 3 ) { + if( i < lw || i > EAST_EDGE - rw || + i == SEEX - 4 || i == SEEX + 3 || + j < tw || j > SOUTH_EDGE - bw || + j == SEEY - 4 || j == SEEY + 3 ) { ter_set( point( i, j ), t_concrete_wall ); } else { ter_set( point( i, j ), t_thconc_floor ); @@ -3514,9 +3511,8 @@ void map::draw_lab( mapgendata &dat ) // Big room for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( i < lw || i >= EAST_EDGE - rw ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( j < tw || j >= SOUTH_EDGE - bw ) { + if( i < lw || i >= EAST_EDGE - rw || + j < tw || j >= SOUTH_EDGE - bw ) { ter_set( point( i, j ), t_concrete_wall ); } else { ter_set( point( i, j ), t_thconc_floor ); @@ -3881,9 +3877,7 @@ void map::draw_lab( mapgendata &dat ) // Start by setting up a large, empty room. for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( i < lw || i > EAST_EDGE - rw ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( j < tw || j > SOUTH_EDGE - bw ) { + if( i < lw || i > EAST_EDGE - rw || j < tw || j > SOUTH_EDGE - bw ) { ter_set( point( i, j ), t_concrete_wall ); } else { ter_set( point( i, j ), t_thconc_floor ); @@ -3997,9 +3991,7 @@ void map::draw_lab( mapgendata &dat ) } else { ter_set( point( i, j ), t_reinforced_glass ); } - } else if( ( i - lw ) % 2 == 0 ) { - ter_set( point( i, j ), t_concrete_wall ); - } else if( j == tw + 2 ) { + } else if( ( i - lw ) % 2 == 0 || j == tw + 2 ) { ter_set( point( i, j ), t_concrete_wall ); } else { // Empty space holds monsters! place_spawns( GROUP_NETHER, 1, point( i, j ), point( i, j ), 1, true ); diff --git a/src/mapgen_functions.cpp b/src/mapgen_functions.cpp index f6390f6226c2e..557965de65f27 100644 --- a/src/mapgen_functions.cpp +++ b/src/mapgen_functions.cpp @@ -2539,9 +2539,7 @@ void mapgen_tutorial( mapgendata &dat ) map *const m = &dat.m; for( int i = 0; i < SEEX * 2; i++ ) { for( int j = 0; j < SEEY * 2; j++ ) { - if( j == 0 || j == SEEY * 2 - 1 ) { - m->ter_set( point( i, j ), t_wall ); - } else if( i == 0 || i == SEEX * 2 - 1 ) { + if( j == 0 || j == SEEY * 2 - 1 || i == 0 || i == SEEX * 2 - 1 ) { m->ter_set( point( i, j ), t_wall ); } else if( j == SEEY ) { if( i % 4 == 2 ) { diff --git a/src/martialarts.cpp b/src/martialarts.cpp index 4299b4cfb4c8c..8fa835938b39c 100644 --- a/src/martialarts.cpp +++ b/src/martialarts.cpp @@ -932,7 +932,8 @@ bool character_martial_arts::can_leg_block( const Character &owner ) const if( owner.get_working_leg_count() >= 1 ) { if( unarmed_skill >= ma.leg_block ) { return true; - } else if( ma.leg_block_with_bio_armor_legs && owner.has_bionic( bio_armor_legs ) ) { + } + if( ma.leg_block_with_bio_armor_legs && owner.has_bionic( bio_armor_legs ) ) { return true; } } @@ -952,7 +953,8 @@ bool character_martial_arts::can_arm_block( const Character &owner ) const !owner.is_limb_broken( bodypart_id( "arm_r" ) ) ) { if( unarmed_skill >= ma.arm_block ) { return true; - } else if( ma.arm_block_with_bio_armor_arms && owner.has_bionic( bio_armor_arms ) ) { + } + if( ma.arm_block_with_bio_armor_arms && owner.has_bionic( bio_armor_arms ) ) { return true; } } @@ -1532,9 +1534,7 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event } ); do { - if( selected < 0 ) { - selected = 0; - } else if( iLines < height ) { + if( selected < 0 || iLines < height ) { selected = 0; } else if( selected >= iLines - height ) { selected = iLines - height; diff --git a/src/mission_companion.cpp b/src/mission_companion.cpp index 9b158d9695340..474ec0ab2eb51 100644 --- a/src/mission_companion.cpp +++ b/src/mission_companion.cpp @@ -1791,7 +1791,7 @@ std::vector talk_function::companion_list( const npc &p, const std::str for( const auto &elem : overmap_buffer.get_companion_mission_npcs() ) { npc_companion_mission c_mission = elem->get_companion_mission(); if( c_mission.position == omt_pos && c_mission.mission_id == mission_id && - c_mission.role_id == p.companion_mission_role_id ) { + c_mission.role_id == p.companion_mission_role_id ) { // NOLINT(bugprone-branch-clone) available.push_back( elem ); } else if( contains && c_mission.mission_id.find( mission_id ) != std::string::npos ) { available.push_back( elem ); @@ -2033,13 +2033,10 @@ npc_ptr talk_function::companion_choose_return( const tripoint_abs_omt &omt_pos, ( by_mission && c_mission.mission_id != mission_id ) || c_mission.role_id != role_id ) { continue; } - if( player_character.has_trait( trait_DEBUG_HS ) ) { - available.push_back( guy ); - } else if( deadline == calendar::before_time_starts ) { - if( guy->companion_mission_time_ret <= calendar::turn ) { - available.push_back( guy ); - } - } else if( guy->companion_mission_time <= deadline ) { + if( player_character.has_trait( trait_DEBUG_HS ) || + guy->companion_mission_time <= deadline || + ( deadline == calendar::before_time_starts && + guy->companion_mission_time_ret <= calendar::turn ) ) { available.push_back( guy ); } } diff --git a/src/monattack.cpp b/src/monattack.cpp index 5c79ed52ac5f1..75f283f4aa72b 100644 --- a/src/monattack.cpp +++ b/src/monattack.cpp @@ -3527,15 +3527,13 @@ bool mattack::searchlight( monster *z ) if( !one_in( 5 ) ) { settings.set_var( "SL_DIR", rng_dir ); } else { - const int rng_pref = rng( 0, 3 ) * 2; - if( rng_pref == 0 && settings.get_var( "SL_PREFER_UP" ) == "TRUE" ) { - settings.set_var( "SL_DIR", rng_pref ); - } else if( rng_pref == 2 && settings.get_var( "SL_PREFER_RIGHT" ) == "TRUE" ) { - settings.set_var( "SL_DIR", rng_pref ); - } else if( rng_pref == 4 && settings.get_var( "SL_PREFER_DOWN" ) == "TRUE" ) { - settings.set_var( "SL_DIR", rng_pref ); - } else if( rng_pref == 6 && settings.get_var( "SL_PREFER_LEFT" ) == "TRUE" ) { - settings.set_var( "SL_DIR", rng_pref ); + const int rng_pref = rng( 0, 3 ); + static const std::array settings_names = {{ + "SL_PREFER_UP", "SL_PREFER_RIGHT", "SL_PREFER_DOWN", "SL_PREFER_LEFT" + } + }; + if( settings.get_var( settings_names[rng_pref] ) == "TRUE" ) { + settings.set_var( "SL_DIR", rng_pref * 2 ); } } } diff --git a/src/monmove.cpp b/src/monmove.cpp index 4893fd7b667e4..d15e49c606837 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -824,12 +824,10 @@ void monster::move() optional_vpart_position vp = here.veh_at( pos() ); bool harness_part = static_cast( here.veh_at( pos() ).part_with_feature( "ANIMAL_CTRL", true ) ); - if( friendly != 0 && vp && vp->vehicle().is_moving() && - vp->vehicle().get_monster( vp->part_index() ) ) { - moves = 0; - return; - // Don't move if harnessed, even if vehicle is stationary - } else if( vp && has_effect( effect_harnessed ) ) { + if( vp && ( ( friendly != 0 && vp->vehicle().is_moving() && + vp->vehicle().get_monster( vp->part_index() ) ) || + // Don't move if harnessed, even if vehicle is stationary + has_effect( effect_harnessed ) ) ) { moves = 0; return; // If harnessed monster finds itself moved from the harness point, the harness probably broke! @@ -1011,12 +1009,14 @@ void monster::move() moved = true; next_step = candidate_abs; break; - } else if( att == Attitude::FRIENDLY && ( target->is_player() || target->is_npc() || - target->has_flag( MF_QUEEN ) ) ) { + } + if( att == Attitude::FRIENDLY && ( target->is_player() || target->is_npc() || + target->has_flag( MF_QUEEN ) ) ) { // Friendly firing the player or an NPC is illegal for gameplay reasons. // Monsters should instinctively avoid attacking queens that regenerate their own population. continue; - } else if( !has_flag( MF_ATTACKMON ) && !has_flag( MF_PUSH_MON ) ) { + } + if( !has_flag( MF_ATTACKMON ) && !has_flag( MF_PUSH_MON ) ) { // Bail out if there's a non-hostile monster in the way and we're not pushy. continue; } diff --git a/src/monster.cpp b/src/monster.cpp index 9227abef2d727..a80fe4a06014e 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -1097,6 +1097,7 @@ Creature::Attitude monster::attitude_to( const Creature &other ) const // Friendly (to player) monsters are friendly to each other // Unfriendly monsters go by faction attitude return Attitude::FRIENDLY; + // NOLINTNEXTLINE(bugprone-branch-clone) } else if( ( friendly == 0 && m->friendly == 0 && faction_att == MFA_HATE ) ) { // Stuff that hates a specific faction will always attack that faction return Attitude::HOSTILE; @@ -1424,21 +1425,15 @@ bool monster::is_immune_effect( const efftype_id &effect ) const bool monster::is_immune_damage( const damage_type dt ) const { switch( dt ) { - case damage_type::NONE: - return true; case damage_type::PURE: - return false; - case damage_type::BIOLOGICAL: - // NOTE: Unused - return false; + case damage_type::BIOLOGICAL: // NOTE: Unused case damage_type::BASH: - return false; case damage_type::CUT: + case damage_type::STAB: + case damage_type::BULLET: return false; case damage_type::ACID: return has_flag( MF_ACIDPROOF ); - case damage_type::STAB: - return false; case damage_type::HEAT: // Ugly hardcode - remove later return made_of( material_id( "steel" ) ) || made_of( material_id( "stone" ) ); @@ -1448,8 +1443,7 @@ bool monster::is_immune_damage( const damage_type dt ) const return type->sp_defense == &mdefense::zapback || has_flag( MF_ELECTRIC ) || has_flag( MF_ELECTRIC_FIELD ); - case damage_type::BULLET: - return false; + case damage_type::NONE: default: return true; } @@ -3043,16 +3037,18 @@ bool monster::will_join_horde( int size ) const monster_horde_attraction mha = get_horde_attraction(); if( mha == MHA_NEVER ) { return false; - } else if( mha == MHA_ALWAYS ) { + } + if( mha == MHA_ALWAYS ) { return true; - } else if( get_map().has_flag( TFLAG_INDOORS, pos() ) && ( mha == MHA_OUTDOORS || - mha == MHA_OUTDOORS_AND_LARGE ) ) { + } + if( get_map().has_flag( TFLAG_INDOORS, pos() ) && + ( mha == MHA_OUTDOORS || mha == MHA_OUTDOORS_AND_LARGE ) ) { return false; - } else if( size < 3 && ( mha == MHA_LARGE || mha == MHA_OUTDOORS_AND_LARGE ) ) { + } + if( size < 3 && ( mha == MHA_LARGE || mha == MHA_OUTDOORS_AND_LARGE ) ) { return false; - } else { - return true; } + return true; } void monster::on_unload() diff --git a/src/mtype.cpp b/src/mtype.cpp index cf45b2938957b..f17da63217314 100644 --- a/src/mtype.cpp +++ b/src/mtype.cpp @@ -200,10 +200,9 @@ field_type_id mtype::gibType() const itype_id mtype::get_meat_itype() const { if( has_flag( MF_POISON ) ) { - if( made_of( material_id( "flesh" ) ) || made_of( material_id( "hflesh" ) ) ) { - return itype_meat_tainted; - } else if( made_of( material_id( "iflesh" ) ) ) { + if( made_of( material_id( "flesh" ) ) || made_of( material_id( "hflesh" ) ) || //In the future, insects could drop insect flesh rather than plain ol' meat. + made_of( material_id( "iflesh" ) ) ) { return itype_meat_tainted; } else if( made_of( material_id( "veggy" ) ) ) { return itype_veggy_tainted; diff --git a/src/mutation.cpp b/src/mutation.cpp index 02456df4f4a4f..45fad76c4dcec 100644 --- a/src/mutation.cpp +++ b/src/mutation.cpp @@ -73,7 +73,6 @@ static const trait_id trait_WEB_WEAVER( "WEB_WEAVER" ); static const json_character_flag json_flag_TINY( "TINY" ); static const json_character_flag json_flag_SMALL( "SMALL" ); -static const json_character_flag json_flag_MEDIUM( "MEDIUM" ); static const json_character_flag json_flag_LARGE( "LARGE" ); static const json_character_flag json_flag_HUGE( "HUGE" ); @@ -380,8 +379,6 @@ void Character::recalculate_size() size_class = creature_size::tiny; } else if( has_trait_flag( json_flag_SMALL ) ) { size_class = creature_size::small; - } else if( has_trait_flag( json_flag_MEDIUM ) ) { - size_class = creature_size::medium; } else if( has_trait_flag( json_flag_LARGE ) ) { size_class = creature_size::large; } else if( has_trait_flag( json_flag_HUGE ) ) { @@ -1291,10 +1288,8 @@ bool Character::mutate_towards( const trait_id &mut ) rating = m_bad; } else if( mdata.points > cancel_mdata.points ) { rating = m_good; - } else if( mdata.points == cancel_mdata.points ) { - rating = m_neutral; } else { - rating = m_mixed; + rating = m_neutral; } // If this new mutation cancels a base trait, remove it and add the mutation at the same time add_msg_player_or_npc( rating, diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index c8e80598dae39..1bc90c7fe7f9d 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -1706,7 +1706,7 @@ tab_direction set_profession( avatar &u, points_left &points, std::string buffer_worn; std::string buffer_inventory; for( const auto &it : prof_items ) { - if( it.has_flag( json_flag_no_auto_equip ) ) { + if( it.has_flag( json_flag_no_auto_equip ) ) { // NOLINT(bugprone-branch-clone) buffer_inventory += it.display_name() + "\n"; } else if( it.has_flag( json_flag_auto_wield ) ) { buffer_wielded += it.display_name() + "\n"; @@ -2094,9 +2094,7 @@ tab_direction set_skills( avatar &u, points_left &points ) const auto vFolded = foldstring( rec_disp, getmaxx( w_description ) ); int iLines = vFolded.size(); - if( selected < 0 ) { - selected = 0; - } else if( iLines < iContentHeight ) { + if( selected < 0 || iLines < iContentHeight ) { selected = 0; } else if( selected >= iLines - iContentHeight ) { selected = iLines - iContentHeight; @@ -3156,10 +3154,12 @@ tab_direction set_description( avatar &you, const bool allow_reroll, popup( _( "Too many points allocated, change some features and try again." ) ); } continue; - } else if( points.has_spare() && - !query_yn( _( "Remaining points will be discarded, are you sure you want to proceed?" ) ) ) { + } + if( points.has_spare() && + !query_yn( _( "Remaining points will be discarded, are you sure you want to proceed?" ) ) ) { continue; - } else if( you.name.empty() ) { + } + if( you.name.empty() ) { no_name_entered = true; ui_manager::redraw(); if( !query_yn( _( "Are you SURE you're finished? Your name will be randomly generated." ) ) ) { @@ -3168,11 +3168,11 @@ tab_direction set_description( avatar &you, const bool allow_reroll, you.pick_name(); return tab_direction::FORWARD; } - } else if( query_yn( _( "Are you SURE you're finished?" ) ) ) { + } + if( query_yn( _( "Are you SURE you're finished?" ) ) ) { return tab_direction::FORWARD; - } else { - continue; } + continue; } else if( action == "PREV_TAB" ) { return tab_direction::BACKWARD; } else if( action == "DOWN" ) { diff --git a/src/npc.cpp b/src/npc.cpp index a2a8ca3a0b66d..903f2f7b61f5d 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -366,13 +366,7 @@ void npc::randomize( const npc_class_id &type ) } if( type.is_null() ) { // Untyped; no particular specialization - } else if( type == NC_EVAC_SHOPKEEP ) { - personality.collector += rng( 1, 5 ); - - } else if( type == NC_BARTENDER ) { - personality.collector += rng( 1, 5 ); - - } else if( type == NC_JUNK_SHOPKEEP ) { + } else if( type == NC_EVAC_SHOPKEEP || type == NC_BARTENDER || type == NC_JUNK_SHOPKEEP ) { personality.collector += rng( 1, 5 ); } else if( type == NC_ARSONIST ) { @@ -409,11 +403,7 @@ void npc::randomize( const npc_class_id &type ) personality.bravery -= rng( 2, 8 ); personality.collector += rng( 0, 2 ); - } else if( type == NC_BOUNTY_HUNTER ) { - personality.aggression += rng( 1, 6 ); - personality.bravery += rng( 0, 5 ); - - } else if( type == NC_THUG ) { + } else if( type == NC_BOUNTY_HUNTER || type == NC_THUG ) { personality.aggression += rng( 1, 6 ); personality.bravery += rng( 0, 5 ); @@ -2048,8 +2038,9 @@ bool npc::is_ally( const Character &p ) const Character &player_character = get_player_character(); if( is_ally( player_character ) && guy.is_ally( player_character ) ) { return true; - } else if( get_attitude_group( get_attitude() ) == - guy.get_attitude_group( guy.get_attitude() ) ) { + } + if( get_attitude_group( get_attitude() ) == + guy.get_attitude_group( guy.get_attitude() ) ) { return true; } } @@ -2315,7 +2306,7 @@ int npc::follow_distance() const nc_color npc::basic_symbol_color() const { - if( attitude == NPCATT_KILL ) { + if( attitude == NPCATT_KILL ) { // NOLINT(bugprone-branch-clone) return c_red; } else if( attitude == NPCATT_FLEE || attitude == NPCATT_FLEE_TEMP ) { return c_light_red; diff --git a/src/npcmove.cpp b/src/npcmove.cpp index 3daf953d9a999..55da7e2f6e31b 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -230,7 +230,8 @@ static bool clear_shot_reach( const tripoint &from, const tripoint &to, bool che Creature *inter = g->critter_at( p ); if( check_ally && inter != nullptr ) { return false; - } else if( get_map().impassable( p ) ) { + } + if( get_map().impassable( p ) ) { return false; } } @@ -440,7 +441,6 @@ void npc::assess_danger() case combat_engagement::HIT: return c.has_effect( effect_hit_by_player ); case combat_engagement::NO_MOVE: - return dist <= max_range; case combat_engagement::FREE_FIRE: return dist <= max_range; case combat_engagement::ALL: @@ -831,9 +831,8 @@ void npc::move() map &here = get_map(); if( !ai_cache.dangerous_explosives.empty() ) { action = npc_escape_explosion; - } else if( target == &player_character && attitude == NPCATT_FLEE_TEMP ) { - action = method_of_fleeing(); - } else if( has_effect( effect_npc_run_away ) ) { + } else if( ( target == &player_character && attitude == NPCATT_FLEE_TEMP ) || + has_effect( effect_npc_run_away ) ) { action = method_of_fleeing(); } else if( has_effect( effect_asthma ) && ( has_charges( itype_inhaler, 1 ) || has_charges( itype_oxygen_tank, 1 ) || @@ -1202,13 +1201,13 @@ void npc::execute_action( npc_action action ) } case npc_follow_player: update_path( player_character.pos() ); - if( static_cast( path.size() ) <= follow_distance() && - player_character.posz() == posz() ) { // We're close enough to u. + if( path.empty() || + ( static_cast( path.size() ) <= follow_distance() && + player_character.posz() == posz() ) ) { + // We're close enough to u. move_pause(); - } else if( !path.empty() ) { - move_to_next(); } else { - move_pause(); + move_to_next(); } // TODO: Make it only happen when it's safe complain(); @@ -1860,8 +1859,9 @@ npc_action npc::address_needs( float danger ) if( danger <= 0.01 ) { if( get_fatigue() >= fatigue_levels::TIRED ) { return true; - } else if( is_walking_with() && player_character.in_sleep_state() && - get_fatigue() > ( fatigue_levels::TIRED / 2 ) ) { + } + if( is_walking_with() && player_character.in_sleep_state() && + get_fatigue() > ( fatigue_levels::TIRED / 2 ) ) { return true; } } @@ -1875,9 +1875,11 @@ npc_action npc::address_needs( float danger ) return npc_undecided; } - if( rules.has_flag( ally_rule::allow_sleep ) || get_fatigue() > fatigue_levels::MASSIVE_FATIGUE ) { + if( rules.has_flag( ally_rule::allow_sleep ) || + get_fatigue() > fatigue_levels::MASSIVE_FATIGUE ) { return npc_sleep; - } else if( player_character.in_sleep_state() ) { + } + if( player_character.in_sleep_state() ) { // TODO: "Guard me while I sleep" command return npc_sleep; } diff --git a/src/npctalk.cpp b/src/npctalk.cpp index fd05e42bb81d1..1c61bbdf8ad83 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -697,6 +697,7 @@ void npc::handle_sound( const sounds::sound_t spriority, const std::string &desc bool should_check = rl_dist( pos(), spos ) < investigate_dist; if( should_check ) { const zone_manager &mgr = zone_manager::get_manager(); + // NOLINTNEXTLINE(bugprone-branch-clone) if( mgr.has( zone_type_NPC_NO_INVESTIGATE, s_abs_pos, fac_id ) ) { should_check = false; } else if( mgr.has( zone_type_NPC_INVESTIGATE_ONLY, my_abs_pos, fac_id ) && @@ -2124,10 +2125,9 @@ void talk_effect_fun_t::set_message( const JsonObject &jo, const std::string &me bool display = false; map &here = get_map(); if( !target->has_effect( effect_sleep ) && !target->is_deaf() ) { - if( !outdoor_only || here.get_abs_sub().z >= 0 ) { - display = true; - } else if( one_in( std::max( roll_remainder( 2.0f * here.get_abs_sub().z / - target->mutation_value( "hearing_modifier" ) ), 1 ) ) ) { + if( !outdoor_only || here.get_abs_sub().z >= 0 || + one_in( std::max( roll_remainder( 2.0f * here.get_abs_sub().z / + target->mutation_value( "hearing_modifier" ) ), 1 ) ) ) { display = true; } } diff --git a/src/options.cpp b/src/options.cpp index 10da65b59273b..f54876789d974 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -479,8 +479,8 @@ bool options_manager::cOpt::is_hidden() const return false; #endif - case COPT_CURSES_HIDE: -#if !defined(TILES) // If not defined. it's curses interface. + case COPT_CURSES_HIDE: // NOLINT(bugprone-branch-clone) +#if !defined(TILES) // If not defined, it's the curses interface. return true; #else return false; @@ -924,10 +924,8 @@ static std::vector build_resource_list( std::string sOption; fin >> sOption; - if( sOption.empty() ) { - getline( fin, sOption ); // Empty line, chomp it - } else if( sOption[0] == '#' ) { // # indicates a comment - getline( fin, sOption ); + if( sOption.empty() || sOption[0] == '#' ) { + getline( fin, sOption ); // Empty line or comment, chomp it } else { if( sOption.find( "NAME" ) != std::string::npos ) { resource_name.clear(); diff --git a/src/output.cpp b/src/output.cpp index 551d0f108b9f8..ae6922390b267 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -990,9 +990,8 @@ input_event draw_item_info( const std::function &init_wind width = getmaxx( win ) - ( data.use_full_win ? 1 : b * 2 ); height = getmaxy( win ) - ( data.use_full_win ? 0 : 2 ); folded = foldstring( buffer, width - 1 ); - if( *data.ptr_selected < 0 ) { - *data.ptr_selected = 0; - } else if( height < 0 || folded.size() < static_cast( height ) ) { + if( *data.ptr_selected < 0 || height < 0 || + folded.size() < static_cast( height ) ) { *data.ptr_selected = 0; } else if( static_cast( *data.ptr_selected + height ) >= folded.size() ) { *data.ptr_selected = static_cast( folded.size() ) - height; @@ -1051,8 +1050,7 @@ input_event draw_item_info( const std::function &init_wind } std::string action; - bool exit = false; - while( !exit ) { + while( true ) { ui_manager::redraw(); action = ctxt.handle_input(); if( data.handle_scrolling && action == "PAGE_UP" ) { @@ -1064,10 +1062,10 @@ input_event draw_item_info( const std::function &init_wind ( height > 0 && static_cast( *data.ptr_selected + height ) < folded.size() ) ) { ++*data.ptr_selected; } - } else if( action == "CONFIRM" || action == "QUIT" ) { - exit = true; - } else if( data.any_input && action == "ANY_INPUT" && !ctxt.get_raw_input().sequence.empty() ) { - exit = true; + } else if( action == "CONFIRM" || action == "QUIT" || + ( data.any_input && action == "ANY_INPUT" && + !ctxt.get_raw_input().sequence.empty() ) ) { + break; } } diff --git a/src/overmap.cpp b/src/overmap.cpp index aaee8e7c639f6..87f9782b5da8e 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1581,7 +1581,8 @@ bool overmap::generate_sub( const int z ) ter_set( p, oter_id( "cavern" ) ); chip_rock( p ); } else if( oter_above == "lab_core" || - ( z == -1 && oter_above == "lab_stairs" ) ) { + ( z == -1 && oter_above == "lab_stairs" ) || + is_ot_match( "hidden_lab_stairs", oter_above, ot_match_type::contains ) ) { lab_points.emplace_back( p.xy(), rng( 1, 5 + z ) ); } else if( oter_above == "lab_stairs" ) { ter_set( p, oter_id( "lab" ) ); @@ -1594,8 +1595,6 @@ bool overmap::generate_sub( const int z ) central_lab_points.emplace_back( p.xy(), rng( std::max( 1, 7 + z ), 9 + z ) ); } else if( oter_above == "central_lab_stairs" ) { ter_set( p, oter_id( "central_lab" ) ); - } else if( is_ot_match( "hidden_lab_stairs", oter_above, ot_match_type::contains ) ) { - lab_points.emplace_back( p.xy(), rng( 1, 5 + z ) ); } else if( is_ot_match( "mine_entrance", oter_ground, ot_match_type::prefix ) && z == -2 ) { mine_points.emplace_back( ( p + tripoint_west ).xy(), rng( 6 + z, 10 + z ) ); requires_sub = true; @@ -4688,23 +4687,15 @@ std::string enum_to_string( ot_match_type data ) } // namespace io constexpr tripoint_abs_omt overmap::invalid_tripoint; +static const std::array suffixes = {{ "_north", "_west", "_south", "_east" }}; std::string oter_no_dir( const oter_id &oter ) { - std::string base_oter_id = oter.id().c_str(); - size_t oter_len = base_oter_id.size(); - if( oter_len > 7 ) { - if( base_oter_id.substr( oter_len - 6, 6 ) == "_south" ) { - return base_oter_id.substr( 0, oter_len - 6 ); - } else if( base_oter_id.substr( oter_len - 6, 6 ) == "_north" ) { - return base_oter_id.substr( 0, oter_len - 6 ); - } - } - if( oter_len > 6 ) { - if( base_oter_id.substr( oter_len - 5, 5 ) == "_west" ) { - return base_oter_id.substr( 0, oter_len - 5 ); - } else if( base_oter_id.substr( oter_len - 5, 5 ) == "_east" ) { - return base_oter_id.substr( 0, oter_len - 5 ); + std::string base_oter_id = oter.id().str(); + for( const std::string &suffix : suffixes ) { + if( string_ends_with( base_oter_id, suffix ) ) { + base_oter_id.erase( base_oter_id.end() - suffix.size(), base_oter_id.end() ); + break; } } return base_oter_id; @@ -4713,19 +4704,9 @@ std::string oter_no_dir( const oter_id &oter ) int oter_get_rotation( const oter_id &oter ) { std::string base_oter_id = oter.id().c_str(); - size_t oter_len = base_oter_id.size(); - if( oter_len > 7 ) { - if( base_oter_id.substr( oter_len - 6, 6 ) == "_south" ) { - return 2; - } else if( base_oter_id.substr( oter_len - 6, 6 ) == "_north" ) { - return 0; - } - } - if( oter_len > 6 ) { - if( base_oter_id.substr( oter_len - 5, 5 ) == "_west" ) { - return 1; - } else if( base_oter_id.substr( oter_len - 5, 5 ) == "_east" ) { - return 3; + for( size_t i = 0; i < suffixes.size(); ++i ) { + if( string_ends_with( base_oter_id, suffixes[i] ) ) { + return i; } } return 0; @@ -4734,19 +4715,9 @@ int oter_get_rotation( const oter_id &oter ) std::string oter_get_rotation_string( const oter_id &oter ) { std::string base_oter_id = oter.id().c_str(); - size_t oter_len = base_oter_id.size(); - if( oter_len > 7 ) { - if( base_oter_id.substr( oter_len - 6, 6 ) == "_south" ) { - return "_south"; - } else if( base_oter_id.substr( oter_len - 6, 6 ) == "_north" ) { - return "_north"; - } - } - if( oter_len > 6 ) { - if( base_oter_id.substr( oter_len - 5, 5 ) == "_west" ) { - return "_west"; - } else if( base_oter_id.substr( oter_len - 5, 5 ) == "_east" ) { - return "_east"; + for( const std::string &suffix : suffixes ) { + if( string_ends_with( base_oter_id, suffix ) ) { + return suffix; } } return ""; diff --git a/src/panels.cpp b/src/panels.cpp index dd45ac491dd4f..7b47b4b3fbd8d 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -777,7 +777,7 @@ static std::string morale_emotion( const int morale_cur, const face_type face, } else if( morale_cur >= -200 ) { return "XvX"; } else { - return "@v@"; + return "@^@"; } } else if( morale_cur >= 200 ) { return "@U@"; @@ -1132,7 +1132,7 @@ static void draw_time_graphic( const catacurses::window &w ) bool bAddTrail = false; for( int i = 0; i < 14; i += 2 ) { - if( iHour >= 8 + i && iHour <= 13 + ( i / 2 ) ) { + if( iHour >= 8 + i && iHour <= 13 + ( i / 2 ) ) { // NOLINT(bugprone-branch-clone) wputch( w, hilite( c_white ), ' ' ); } else if( iHour >= 6 + i && iHour <= 7 + i ) { diff --git a/src/pickup.cpp b/src/pickup.cpp index 40a86fd992952..b9396cc1a3c65 100644 --- a/src/pickup.cpp +++ b/src/pickup.cpp @@ -529,7 +529,8 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from ) // Bail out if this square cannot be auto-picked-up if( g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), p ) ) { return; - } else if( local.has_flag( "SEALED", p ) ) { + } + if( local.has_flag( "SEALED", p ) ) { return; } } diff --git a/src/player.cpp b/src/player.cpp index 9765db5e56c1c..67ca9f1e05212 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2047,7 +2047,7 @@ void player::use( item_location loc, int pre_obtain_moves ) } else if( used.type->can_use( "DOGFOOD" ) || used.type->can_use( "CATFOOD" ) || used.type->can_use( "BIRDFOOD" ) || - used.type->can_use( "CATTLEFODDER" ) ) { + used.type->can_use( "CATTLEFODDER" ) ) { // NOLINT(bugprone-branch-clone) invoke_item( &used, loc.position(), pre_obtain_moves ); } else if( !used.is_craft() && ( used.is_medication() || ( !used.type->has_use() && diff --git a/src/player_hardcoded_effects.cpp b/src/player_hardcoded_effects.cpp index cc46a9a53e9ac..1ab21c2f411da 100644 --- a/src/player_hardcoded_effects.cpp +++ b/src/player_hardcoded_effects.cpp @@ -844,9 +844,7 @@ static void eff_fun_redcells_anemia( Character &u, effect &it ) u.mod_fatigue( intense * 3 ); break; case 7: // 7-9 empty for variability, as messages stack on higher intensity - break; case 8: - break; case 9: break; } @@ -876,9 +874,7 @@ static void eff_fun_redcells_anemia( Character &u, effect &it ) u.mod_pain( intense * 9 ); break; case 7: // 7-9 empty for variability, as messages stack on higher intensity - break; case 8: - break; case 9: break; } @@ -912,9 +908,7 @@ static void eff_fun_redcells_anemia( Character &u, effect &it ) u.add_effect( effect_downed, rng( 1_minutes, 2_minutes ) ); break; case 7: // 7-9 empty for variability, as messages stack on higher intensity - break; case 8: - break; case 9: break; } diff --git a/src/ranged.cpp b/src/ranged.cpp index 5379b3539d157..ce40ce2c39740 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -2564,12 +2564,13 @@ bool target_ui::try_reacquire_target( bool critter, tripoint &new_dst ) void target_ui::update_status() { std::vector msgbuf; - if( mode == TargetMode::Turrets && turrets_in_range.empty() ) { + if( mode == TargetMode::Turrets && turrets_in_range.empty() ) { // NOLINT(bugprone-branch-clone) // None of the turrets are in range status = Status::OutOfRange; } else if( mode == TargetMode::Fire && ( !gunmode_checks_common( *you, get_map(), msgbuf, relevant->gun_current_mode() ) || - !gunmode_checks_weapon( *you, get_map(), msgbuf, relevant->gun_current_mode() ) ) ) { + !gunmode_checks_weapon( *you, get_map(), msgbuf, relevant->gun_current_mode() ) ) + ) { // NOLINT(bugprone-branch-clone) // Selected gun mode is empty // TODO: it might be some other error, but that's highly unlikely to happen, so a catch-all 'Out of ammo' is fine status = Status::OutOfAmmo; diff --git a/src/relic.cpp b/src/relic.cpp index 1e50c2c43322b..a9ee9d8defba4 100644 --- a/src/relic.cpp +++ b/src/relic.cpp @@ -425,7 +425,8 @@ void relic::try_recharge( item &parent, Character *carrier, const tripoint &pos { if( charge.regenerate_ammo && item_can_not_load_ammo( parent ) ) { return; - } else if( !charge.regenerate_ammo && charge.charges >= charge.max_charges ) { + } + if( !charge.regenerate_ammo && charge.charges >= charge.max_charges ) { return; } diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 4c3975b74c349..4a5f97596cc2f 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -2605,9 +2605,8 @@ void item::migrate_content_item( const item &contained ) } else if( typeId() == itype_usb_drive ) { // as of this migration, only usb_drive has any software in it. put_in( contained, item_pocket::pocket_type::SOFTWARE ); - } else if( contents.insert_item( contained, item_pocket::pocket_type::MAGAZINE ).success() ) { - // left intentionally blank - } else if( contents.insert_item( contained, item_pocket::pocket_type::MAGAZINE_WELL ).success() ) { + } else if( contents.insert_item( contained, item_pocket::pocket_type::MAGAZINE ).success() || + contents.insert_item( contained, item_pocket::pocket_type::MAGAZINE_WELL ).success() ) { // left intentionally blank } else if( is_corpse() ) { put_in( contained, item_pocket::pocket_type::CORPSE ); diff --git a/src/scent_block.h b/src/scent_block.h index 9708242d4d208..398d6f7aa3116 100644 --- a/src/scent_block.h +++ b/src/scent_block.h @@ -90,17 +90,15 @@ struct scent_block { dat.intensity = intensity; break; } + case data_mode::MAX: + // Already max for some reason, shouldn't occur. + // If it does we want to grow if possible case data_mode::SET: { // new intensity is going to be dat.intensity, so we just need to make it larger // but cannot change dat.intensity = std::max( dat.intensity, intensity ); break; } - case data_mode::MAX: { - // Already max for some reason, shouldn't occur. If it does we want to grow if possible - dat.intensity = std::max( dat.intensity, intensity ); - break; - } } ++modification_count; } diff --git a/src/shadowcasting.cpp b/src/shadowcasting.cpp index 9e2e48ac2f340..32dcedecc4f62 100644 --- a/src/shadowcasting.cpp +++ b/src/shadowcasting.cpp @@ -206,11 +206,13 @@ void cast_horizontal_zlight_segment( if( current.z > max_z || current.z < min_z ) { // Current tile is out of bounds, advance to the next tile. continue; - } else if( this_span->start_major > leading_edge_major ) { + } + if( this_span->start_major > leading_edge_major ) { // Current span has a higher z-value, // jump to next iteration to catch up. continue; - } else if( this_span->skip_first_row && this_span->start_major == leading_edge_major ) { + } + if( this_span->skip_first_row && this_span->start_major == leading_edge_major ) { // Prevents an infinite loop in some cases after splitting off the D span. // We don't want to recheck the row that just caused the D span to be split off, // since that can lead to an identical span being split off again, hence the @@ -219,7 +221,8 @@ void cast_horizontal_zlight_segment( // This could also be accomplished by adding a small epsilon to the start_major // of the D span but that causes artifacts. continue; - } else if( this_span->end_major < trailing_edge_major ) { + } + if( this_span->end_major < trailing_edge_major ) { // We've escaped the bounds of the current span we're considering, // So continue to the next span. break; @@ -237,10 +240,12 @@ void cast_horizontal_zlight_segment( if( !bounds.contains( current.xy() ) ) { // Current tile is out of bounds, advance to the next tile. continue; - } else if( this_span->start_minor > leading_edge_minor ) { + } + if( this_span->start_minor > leading_edge_minor ) { // Current tile comes before the span we're considering, advance to the next tile. continue; - } else if( this_span->end_minor < trailing_edge_minor ) { + } + if( this_span->end_minor < trailing_edge_minor ) { // Current tile is after the span we're considering, continue to next row. break; } @@ -304,15 +309,16 @@ void cast_horizontal_zlight_segment( } } - if( !started_block ) { - // If we didn't scan at least 1 z-level, don't iterate further + if( // If we didn't scan at least 1 z-level, don't iterate further // Otherwise we may "phase" through tiles without checking them or waste time // checking spans that are out of bounds. - this_span = spans.erase( this_span ); - } else if( !is_transparent( current_transparency, last_intensity ) ) { - // If we reach the end of the span with terrain being opaque, we don't iterate further. + !started_block || + // If we reach the end of the span with terrain being opaque, we don't iterate + // further. // This means that any encountered transparent tiles from the current span have been // split off into new spans + !is_transparent( current_transparency, last_intensity ) + ) { this_span = spans.erase( this_span ); } else { // Cumulative average of the values encountered. @@ -372,11 +378,13 @@ void cast_vertical_zlight_segment( if( current.y < 0 || current.y >= MAPSIZE_Y ) { // Current tile is out of bounds, advance to the next tile. continue; - } else if( this_span->start_major > leading_edge_major ) { + } + if( this_span->start_major > leading_edge_major ) { // Current span has a higher z-value, // jump to next iteration to catch up. continue; - } else if( this_span->skip_first_row && this_span->start_major == leading_edge_major ) { + } + if( this_span->skip_first_row && this_span->start_major == leading_edge_major ) { // Prevents an infinite loop in some cases after splitting off the D span. // We don't want to recheck the row that just caused the D span to be split off, // since that can lead to an identical span being split off again, hence the @@ -385,7 +393,8 @@ void cast_vertical_zlight_segment( // This could also be accomplished by adding a small epsilon to the start_major // of the D span but that causes artifacts. continue; - } else if( this_span->end_major < trailing_edge_major ) { + } + if( this_span->end_major < trailing_edge_major ) { // We've escaped the bounds of the current span we're considering, // So continue to the next span. break; @@ -403,10 +412,12 @@ void cast_vertical_zlight_segment( current.z > max_z || current.z < min_z ) { // Current tile is out of bounds, advance to the next tile. continue; - } else if( this_span->start_minor > leading_edge_minor ) { + } + if( this_span->start_minor > leading_edge_minor ) { // Current tile comes before the span we're considering, advance to the next tile. continue; - } else if( this_span->end_minor < trailing_edge_minor ) { + } + if( this_span->end_minor < trailing_edge_minor ) { // Current tile is after the span we're considering, continue to next row. break; } @@ -470,15 +481,16 @@ void cast_vertical_zlight_segment( } } - if( !started_block ) { - // If we didn't scan at least 1 z-level, don't iterate further + if( // If we didn't scan at least 1 z-level, don't iterate further // Otherwise we may "phase" through tiles without checking them or waste time // checking spans that are out of bounds. - this_span = spans.erase( this_span ); - } else if( !is_transparent( current_transparency, last_intensity ) ) { - // If we reach the end of the span with terrain being opaque, we don't iterate further. + !started_block || + // If we reach the end of the span with terrain being opaque, we don't iterate + // further. // This means that any encountered transparent tiles from the current span have been // split off into new spans + !is_transparent( current_transparency, last_intensity ) + ) { this_span = spans.erase( this_span ); } else { // Cumulative average of the values encountered. diff --git a/src/sounds.cpp b/src/sounds.cpp index 36a2ac21830f0..50987415bb2d0 100644 --- a/src/sounds.cpp +++ b/src/sounds.cpp @@ -1237,13 +1237,10 @@ void sfx::do_projectile_hit( const Creature &target ) return mon.made_of( m ); } ); - if( is_fleshy ) { - play_variant_sound( "bullet_hit", "hit_flesh", heard_volume, angle, 0.8, 1.2 ); - return; - } else if( mon.made_of( material_id( "stone" ) ) ) { + if( !is_fleshy && mon.made_of( material_id( "stone" ) ) ) { play_variant_sound( "bullet_hit", "hit_wall", heard_volume, angle, 0.8, 1.2 ); return; - } else if( mon.made_of( material_id( "steel" ) ) ) { + } else if( !is_fleshy && mon.made_of( material_id( "steel" ) ) ) { play_variant_sound( "bullet_hit", "hit_metal", heard_volume, angle, 0.8, 1.2 ); return; } else { diff --git a/src/string_formatter.h b/src/string_formatter.h index c58167be8cd8b..387452f08321b 100644 --- a/src/string_formatter.h +++ b/src/string_formatter.h @@ -267,7 +267,7 @@ class string_formatter consume_next_input_if( 'l' ); } else if( consume_next_input_if( 'h' ) ) { consume_next_input_if( 'h' ); - } else if( consume_next_input_if( 'z' ) ) { + } else if( consume_next_input_if( 'z' ) ) { // NOLINT(bugprone-branch-clone) // done with it } else if( consume_next_input_if( 't' ) ) { // done with it diff --git a/src/string_input_popup.cpp b/src/string_input_popup.cpp index 0c034f98c982b..7babb0dee3e20 100644 --- a/src/string_input_popup.cpp +++ b/src/string_input_popup.cpp @@ -439,7 +439,8 @@ const std::string &string_input_popup::query_string( const bool loop, const bool } else { _handled = false; } - } else if( ch == KEY_DOWN || ch == KEY_NPAGE || ch == KEY_PPAGE || ch == KEY_BTAB || ch == 9 ) { + // NOLINTNEXTLINE(bugprone-branch-clone) + } else if( ch == KEY_NPAGE || ch == KEY_PPAGE || ch == KEY_BTAB || ch == '\t' ) { _handled = false; } else if( ch == KEY_RIGHT ) { if( _position + 1 <= static_cast( ret.size() ) ) { diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index b2efe70854310..6ade5dae2e8e2 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -171,11 +171,9 @@ bool trapfunc::beartrap( const tripoint &p, Creature *c, item * ) c->deal_damage( nullptr, hit, d ); player *n = dynamic_cast( c ); - if( n != nullptr ) { - if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 512 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); - } else if( ( !n->has_trait( trait_INFIMMUNE ) || !n->has_trait( trait_INFRESIST ) ) && - ( one_in( 128 ) ) ) { + if( n != nullptr && !n->has_trait( trait_INFIMMUNE ) ) { + const int chance_in = n->has_trait( trait_INFRESIST ) ? 512 : 128; + if( one_in( chance_in ) ) { n->add_effect( effect_tetanus, 1_turns, true ); } } @@ -215,11 +213,11 @@ bool trapfunc::board( const tripoint &, Creature *c, item * ) 10 ) ) ); c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( damage_type::CUT, rng( 6, 10 ) ) ); - if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); - } else if( ( !n->has_trait( trait_INFIMMUNE ) || !n->has_trait( trait_INFRESIST ) ) && - ( one_in( 35 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); + if( !n->has_trait( trait_INFIMMUNE ) ) { + const int chance_in = n->has_trait( trait_INFRESIST ) ? 256 : 35; + if( one_in( chance_in ) ) { + n->add_effect( effect_tetanus, 1_turns, true ); + } } } c->check_dead_state(); @@ -889,11 +887,11 @@ bool trapfunc::pit_spikes( const tripoint &p, Creature *c, item * ) n->add_msg_if_player( m_bad, _( "The spikes impale your %s!" ), body_part_name_accusative( hit ) ); n->deal_damage( nullptr, hit, damage_instance( damage_type::CUT, damage ) ); - if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); - } else if( ( !n->has_trait( trait_INFIMMUNE ) || !n->has_trait( trait_INFRESIST ) ) && - ( one_in( 35 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); + if( !n->has_trait( trait_INFIMMUNE ) ) { + const int chance_in = n->has_trait( trait_INFRESIST ) ? 256 : 35; + if( one_in( chance_in ) ) { + n->add_effect( effect_tetanus, 1_turns, true ); + } } } } else if( z != nullptr ) { @@ -977,11 +975,11 @@ bool trapfunc::pit_glass( const tripoint &p, Creature *c, item * ) n->add_msg_if_player( m_bad, _( "The glass shards slash your %s!" ), body_part_name_accusative( hit ) ); n->deal_damage( nullptr, hit, damage_instance( damage_type::CUT, damage ) ); - if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); - } else if( ( !n->has_trait( trait_INFIMMUNE ) || !n->has_trait( trait_INFRESIST ) ) && - ( one_in( 35 ) ) ) { - n->add_effect( effect_tetanus, 1_turns, true ); + if( !n->has_trait( trait_INFIMMUNE ) ) { + const int chance_in = n->has_trait( trait_INFRESIST ) ? 256 : 35; + if( one_in( chance_in ) ) { + n->add_effect( effect_tetanus, 1_turns, true ); + } } } } else if( z != nullptr ) { diff --git a/src/ui.cpp b/src/ui.cpp index ff634f4eba8ac..5d76b53703b22 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -314,12 +314,12 @@ void uilist::filterlist() if( notfiltering || ( !nocase && static_cast( entries[i].txt.find( filter ) ) != -1 ) || lcmatch( entries[i].txt, fstr ) ) { fentries.push_back( i ); - if( i == selected && ( hilight_disabled || entries[i].enabled ) ) { - fselected = f; - } else if( i > selected && fselected == -1 && ( hilight_disabled || entries[i].enabled ) ) { - // Past the previously selected entry, which has been filtered out, - // choose another nearby entry instead. - fselected = f; + if( hilight_disabled || entries[i].enabled ) { + if( i == selected || ( i > selected && fselected == -1 ) ) { + // Either this is selected, or we are past the previously selected entry, + // which has been filtered out, so choose another nearby entry instead. + fselected = f; + } } f++; } @@ -925,10 +925,8 @@ void uilist::query( bool loop, int timeout ) inputfilter(); } else if( iter != keymap.end() ) { selected = iter->second; - if( entries[ selected ].enabled ) { - ret = entries[ selected ].retval; // valid - } else if( allow_disabled ) { - ret = entries[selected].retval; // disabled + if( entries[ selected ].enabled || allow_disabled ) { + ret = entries[selected].retval; } if( callback != nullptr ) { callback->select( this ); @@ -946,10 +944,7 @@ void uilist::query( bool loop, int timeout ) } } } else if( !fentries.empty() && ret_act == "CONFIRM" ) { - if( entries[ selected ].enabled ) { - ret = entries[ selected ].retval; // valid - } else if( allow_disabled ) { - // disabled + if( entries[ selected ].enabled || allow_disabled ) { ret = entries[selected].retval; } } else if( allow_cancel && ret_act == "QUIT" ) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 4f8891b75c4fa..98c5031ab4074 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -4426,17 +4426,15 @@ bool vehicle::handle_potential_theft( player &p, bool check_only, bool prompt ) } } // the vehicle is yours, that's fine. - if( is_owned_by_player ) { + if( is_owned_by_player ) { // NOLINT(bugprone-branch-clone) return true; // if There is no owner // handle transfer of ownership - } else if( !has_owner() ) { - set_owner( p.get_faction()->id ); - remove_old_owner(); - return true; - // if there is a marker for having been stolen, but 15 minutes have passed, then officially transfer ownership - } else if( witnesses.empty() && has_old_owner() && !is_old_owner( p ) && theft_time && - calendar::turn - *theft_time > 15_minutes ) { + } else if( !has_owner() || + // if there is a marker for having been stolen, but 15 minutes have passed, then + // officially transfer ownership + ( witnesses.empty() && has_old_owner() && !is_old_owner( p ) && theft_time && + calendar::turn - *theft_time > 15_minutes ) ) { set_owner( p.get_faction()->id ); remove_old_owner(); return true; diff --git a/src/vehicle_part.cpp b/src/vehicle_part.cpp index ada5f4806b35d..9e60d904b71ee 100644 --- a/src/vehicle_part.cpp +++ b/src/vehicle_part.cpp @@ -362,7 +362,7 @@ bool vehicle_part::can_reload( const item &obj ) const return false; } // forbid putting liquids, gasses, and plasma in things that aren't tanks - else if( !obj.made_of( phase_id::SOLID ) && !is_tank() ) { + if( !obj.made_of( phase_id::SOLID ) && !is_tank() ) { return false; } // prevent mixing of different ammo diff --git a/src/weather.cpp b/src/weather.cpp index ff04584a1674a..044a53d5cdbd4 100644 --- a/src/weather.cpp +++ b/src/weather.cpp @@ -698,31 +698,19 @@ int get_local_windchill( double temperature_f, double humidity, double wind_mph nc_color get_wind_color( double windpower ) { nc_color windcolor; - if( windpower < 1 ) { - windcolor = c_dark_gray; - } else if( windpower < 3 ) { + if( windpower < 3 ) { windcolor = c_dark_gray; - } else if( windpower < 7 ) { - windcolor = c_light_gray; } else if( windpower < 12 ) { windcolor = c_light_gray; - } else if( windpower < 18 ) { - windcolor = c_blue; } else if( windpower < 24 ) { windcolor = c_blue; - } else if( windpower < 31 ) { - windcolor = c_light_blue; } else if( windpower < 38 ) { windcolor = c_light_blue; - } else if( windpower < 46 ) { - windcolor = c_cyan; } else if( windpower < 54 ) { windcolor = c_cyan; - } else if( windpower < 63 ) { - windcolor = c_light_cyan; } else if( windpower < 72 ) { windcolor = c_light_cyan; - } else if( windpower > 72 ) { + } else { windcolor = c_white; } return windcolor; diff --git a/tests/shadowcasting_test.cpp b/tests/shadowcasting_test.cpp index c5c04c1368789..43cdcba790e69 100644 --- a/tests/shadowcasting_test.cpp +++ b/tests/shadowcasting_test.cpp @@ -581,11 +581,9 @@ static void run_spot_check( const grid_overlay &test_case, const grid_overlay &e trans_grid << caches[gz]->transparency_cache[gx][gy]; expected_grid << ( expected.get_transparency_global( { gx, gy, gz } ) > 0 ? 'V' : 'O' ); actual_grid << ( ( *seen_squares[gz] )[gx][gy] > 0 ? 'V' : 'O' ); - if( V == expected.get_transparency_global( { gx, gy, gz } ) && - ( *seen_squares[gz] )[gx][gy] == 0 ) { - passed = false; - } else if( O == expected.get_transparency_global( { gx, gy, gz } ) && - ( *seen_squares[gz] )[gx][gy] > 0 ) { + const float expected_trans = expected.get_transparency_global( { gx, gy, gz } ); + const float seen = ( *seen_squares[gz] )[gx][gy]; + if( ( V == expected_trans && seen == 0 ) || ( O == expected_trans && seen > 0 ) ) { passed = false; } } diff --git a/tests/unseal_and_spill_test.cpp b/tests/unseal_and_spill_test.cpp index 697eaad287c7b..5dd8c5f2fd800 100644 --- a/tests/unseal_and_spill_test.cpp +++ b/tests/unseal_and_spill_test.cpp @@ -595,7 +595,7 @@ void test_scenario::run() {} } }; - } else if( !will_spill_outer && !do_spill ) { + } else if( !do_spill ) { original_location = final_result { test_watertight_open_sealed_container_1L, false, @@ -623,7 +623,7 @@ void test_scenario::run() } } }; - } else if( do_spill ) { + } else { original_location = final_result { test_watertight_open_sealed_container_1L, false, @@ -644,34 +644,6 @@ void test_scenario::run() {} } }; - } else { - original_location = final_result { - test_watertight_open_sealed_container_1L, - false, - false, - {} - }; - ground = { - final_result { - test_watertight_open_sealed_multipocket_container_2x250ml, - false, - false, - { - final_result { - test_liquid_1ml, - false, - false, - {} - }, - final_result { - test_liquid_1ml, - false, - false, - {} - } - } - } - }; } break; case scenario::recursive_multi_pocket: diff --git a/tools/clang-tidy-plugin/TextStyleCheck.cpp b/tools/clang-tidy-plugin/TextStyleCheck.cpp index ae23900593eea..51dce94945537 100644 --- a/tools/clang-tidy-plugin/TextStyleCheck.cpp +++ b/tools/clang-tidy-plugin/TextStyleCheck.cpp @@ -89,8 +89,9 @@ void TextStyleCheck::check( const MatchFinder::MatchResult &Result ) const SourceLocation &loc = text.getStrTokenLoc( i ); if( loc.isInvalid() ) { return; - } else if( StringRef( SrcMgr.getPresumedLoc( SrcMgr.getSpellingLoc( - loc ) ).getFilename() ).equals( "" ) ) { + } + if( StringRef( SrcMgr.getPresumedLoc( SrcMgr.getSpellingLoc( + loc ) ).getFilename() ).equals( "" ) ) { return; } }