Skip to content

Commit

Permalink
refactor: apply all clang-tidy fixes (cataclysmbnteam#5548)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 authored Oct 9, 2024
1 parent 58e6e61 commit 9405f05
Show file tree
Hide file tree
Showing 189 changed files with 858 additions and 865 deletions.
2 changes: 1 addition & 1 deletion src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class aim_activity_actor : public activity_actor
std::vector<tripoint> fin_trajectory;

public:
std::string action = "";
std::string action;
int aif_duration = 0; // Counts aim-and-fire duration
bool aiming_at_critter = false; // Whether aiming at critter or a tile
bool snap_to_target = false;
Expand Down
4 changes: 2 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,11 +1772,11 @@ void activity_handlers::hotwire_finish( player_activity *act, player *p )
p->posz() ) ) ) ) {
vehicle *const veh = &vp->vehicle();
const int mech_skill = act->values[2];
if( mech_skill > static_cast<int>( rng( 1, 6 ) ) ) {
if( mech_skill > rng( 1, 6 ) ) {
//success
veh->is_locked = false;
add_msg( _( "This wire will start the engine." ) );
} else if( mech_skill > static_cast<int>( rng( 0, 4 ) ) ) {
} else if( mech_skill > rng( 0, 4 ) ) {
//soft fail
veh->is_locked = false;
veh->is_alarm_on = veh->has_security_working();
Expand Down
6 changes: 3 additions & 3 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ std::list<act_item> reorder_for_dropping( Character &p, const drop_locations &dr
const_invslice old_inv = p.inv_const_slice();
for( size_t i = 0; i < old_inv.size() && excessive_volume > 0_ml; i++ ) {
// TODO: Reimplement random dropping?
if( inv_indices.count( i ) != 0 ) {
if( inv_indices.contains( i ) ) {
continue;
}
const std::vector<item *> &inv_stack = *old_inv[i];
Expand Down Expand Up @@ -1149,15 +1149,15 @@ static activity_reason_info find_base_construction(
pq.pop();

auto con = cur.id;
if( used.count( con ) != 0 ) {
if( used.contains( con ) ) {
continue; // already evaluated this one
}
if( strict && con->group != id->group ) {
continue; // evaluating strictly and this item is not in group
}
used.insert( con );

auto con_build = con.obj();
const auto &con_build = con.obj();
if(
( !con_build.post_terrain.is_empty() && con_build.post_terrain.id() == ter ) ||
( !con_build.post_furniture.is_empty() && con_build.post_furniture.id() == furn )
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ void advanced_inventory::display()

w_height = TERMY < min_w_height + head_height ? min_w_height : TERMY - head_height;
w_width = TERMX < min_w_width ? min_w_width : TERMX > max_w_width ? max_w_width :
static_cast<int>( TERMX );
TERMX;

//(TERMY>w_height)?(TERMY-w_height)/2:0;
headstart = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ammunition_type::load_ammunition_type( const JsonObject &jsobj )
template<>
bool string_id<ammunition_type>::is_valid() const
{
return all_ammunition_types().count( *this ) > 0;
return all_ammunition_types().contains( *this );
}

/** @relates string_id */
Expand Down
2 changes: 1 addition & 1 deletion src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void draw_sct_curses( const game &g )
continue;
}

const bool is_old = text.getStep() >= SCT.iMaxSteps / 2;
const bool is_old = text.getStep() >= scrollingcombattext::iMaxSteps / 2;

nc_color const col1 = msgtype_to_color( text.getMsgType( "first" ), is_old );
nc_color const col2 = msgtype_to_color( text.getMsgType( "second" ), is_old );
Expand Down
12 changes: 6 additions & 6 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,17 @@ std::vector<std::string> clothing_protection( const item &worn_item, const int w
const std::string space = " ";
prot.push_back( string_format( "<color_c_green>[%s]</color>", _( "Protection" ) ) );
prot.push_back( name_and_value( space + _( "Bash:" ),
string_format( "%3d", static_cast<int>( worn_item.bash_resist() ) ), width ) );
string_format( "%3d", worn_item.bash_resist() ), width ) );
prot.push_back( name_and_value( space + _( "Cut:" ),
string_format( "%3d", static_cast<int>( worn_item.cut_resist() ) ), width ) );
string_format( "%3d", worn_item.cut_resist() ), width ) );
prot.push_back( name_and_value( space + _( "Ballistic:" ),
string_format( "%3d", static_cast<int>( worn_item.bullet_resist() ) ), width ) );
string_format( "%3d", worn_item.bullet_resist() ), width ) );
prot.push_back( name_and_value( space + _( "Acid:" ),
string_format( "%3d", static_cast<int>( worn_item.acid_resist() ) ), width ) );
string_format( "%3d", worn_item.acid_resist() ), width ) );
prot.push_back( name_and_value( space + _( "Fire:" ),
string_format( "%3d", static_cast<int>( worn_item.fire_resist() ) ), width ) );
string_format( "%3d", worn_item.fire_resist() ), width ) );
prot.push_back( name_and_value( space + _( "Environmental:" ),
string_format( "%3d", static_cast<int>( worn_item.get_env_resist() ) ), width ) );
string_format( "%3d", worn_item.get_env_resist() ), width ) );
return prot;
}

Expand Down
4 changes: 2 additions & 2 deletions src/auto_note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void auto_note_settings::set_discovered( const string_id<map_extra> &mapExtId )

bool auto_note_settings::was_discovered( const string_id<map_extra> &mapExtId ) const
{
return discovered.count( mapExtId ) != 0;
return discovered.contains( mapExtId );
}

void auto_note_settings::show_gui()
Expand All @@ -131,7 +131,7 @@ void auto_note_settings::show_gui()

bool auto_note_settings::has_auto_note_enabled( const string_id<map_extra> &mapExtId ) const
{
return autoNoteEnabled.count( mapExtId ) != 0;
return autoNoteEnabled.contains( mapExtId );
}

void auto_note_settings::set_auto_note_status( const string_id<map_extra> &mapExtId,
Expand Down
8 changes: 4 additions & 4 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ bool avatar::read( item *loc, const bool continuous )
}
act.index = menu.ret;
}
if( it.type->use_methods.count( "MA_MANUAL" ) ) {
if( it.type->use_methods.contains( "MA_MANUAL" ) ) {

if( martial_arts_data->has_martialart( martial_art_learned_from( *it.type ) ) ) {
add_msg_if_player( m_info, _( "You already know all this book has to teach." ) );
Expand Down Expand Up @@ -636,7 +636,7 @@ bool avatar::read( item *loc, const bool continuous )
}

// push an indentifier of martial art book to the action handling
if( it.type->use_methods.count( "MA_MANUAL" ) ) {
if( it.type->use_methods.contains( "MA_MANUAL" ) ) {

if( get_stamina() < get_stamina_max() / 10 ) {
add_msg( m_info, _( "You are too exhausted to train martial arts." ) );
Expand Down Expand Up @@ -706,7 +706,7 @@ static void skim_book_msg( const item &book, avatar &u )
character_funcs::get_book_fun_for( u, book ) );
}

if( book.type->use_methods.count( "MA_MANUAL" ) ) {
if( book.type->use_methods.contains( "MA_MANUAL" ) ) {
const matype_id style_to_learn = martial_art_learned_from( *book.type );
add_msg( m_info, _( "You can learn %s style from it." ), style_to_learn->name );
add_msg( m_info, _( "This fighting style is %s to learn." ),
Expand Down Expand Up @@ -958,7 +958,7 @@ void avatar::do_read( item *loc )

bool avatar::has_identified( const itype_id &item_id ) const
{
return items_identified.count( item_id ) > 0;
return items_identified.contains( item_id );
}

void avatar::wake_up()
Expand Down
8 changes: 4 additions & 4 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
monster &critter = *mon_ptr;
// Additional checking to make sure we won't take a swing at friendly monsters.
Character &u = get_player_character();
monster_attitude att = critter.attitude( const_cast<Character *>( &u ) );
monster_attitude att = critter.attitude( ( &u ) );
if( critter.friendly == 0 &&
!critter.has_effect( effect_pet ) && att != MATT_FRIEND ) {
if( you.is_auto_moving() ) {
Expand Down Expand Up @@ -768,7 +768,7 @@ void avatar_action::fire_wielded_weapon( avatar &you )
} else if( !weapon.is_gun() ) {
return;
} else if( weapon.ammo_data() && weapon.type->gun &&
!weapon.ammo_types().count( weapon.ammo_data()->ammo->type ) ) {
!weapon.ammo_types().contains( weapon.ammo_data()->ammo->type ) ) {
std::string ammoname = weapon.ammo_current()->nname( 1 );
add_msg( m_info, _( "The %s can't be fired while loaded with incompatible ammunition %s" ),
weapon.tname(), ammoname );
Expand Down Expand Up @@ -1294,8 +1294,8 @@ void avatar_action::reload_weapon( bool try_everything )
return true;
}
// Second sort by affiliation with wielded gun
const bool mag_ap = compatible_magazines.count( ap->typeId() ) > 0;
const bool mag_bp = compatible_magazines.count( bp->typeId() ) > 0;
const bool mag_ap = compatible_magazines.contains( ap->typeId() );
const bool mag_bp = compatible_magazines.contains( bp->typeId() );
if( mag_ap != mag_bp ) {
return mag_ap;
}
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void mend_item( avatar &you, item &obj, bool interactive )
menu.text = _( "Toggle which fault?" );
std::vector<std::pair<fault_id, bool>> opts;
for( const auto &f : obj.faults_potential() ) {
opts.emplace_back( f, !!obj.faults.count( f ) );
opts.emplace_back( f, !!obj.faults.contains( f ) );
menu.addentry( -1, true, -1, string_format(
opts.back().second ? pgettext( "fault", "Mend: %s" ) : pgettext( "fault", "Set: %s" ),
f.obj().name() ) );
Expand Down
10 changes: 5 additions & 5 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ std::vector<bodypart_id> get_occupied_bodyparts( const bionic_id &bid )

bool bionic_data::has_flag( const flag_id &flag ) const
{
return flags.count( flag ) > 0;
return flags.contains( flag );
}

itype_id bionic_data::itype() const
Expand Down Expand Up @@ -873,7 +873,7 @@ bool Character::activate_bionic( bionic &bio, bool eff_only, bool *close_bionics
if( water && water->charges < avail ) {
add_msg_activate();
extracted = true;
it->set_var( "remaining_water", static_cast<int>( water->charges ) );
it->set_var( "remaining_water", water->charges );
}
break;
}
Expand Down Expand Up @@ -2100,7 +2100,7 @@ bool Character::can_uninstall_bionic( const bionic_id &b_id, player &installer,
} else {
if( !g->u.query_yn(
_( "WARNING: %i percent chance of SEVERE damage to all body parts! Continue anyway?" ),
( 100 - static_cast<int>( chance_of_success ) ) ) ) {
( 100 - chance_of_success ) ) ) {
return false;
}
}
Expand Down Expand Up @@ -2508,7 +2508,7 @@ void Character::do_damage_for_bionic_failure( int min_damage, int max_damage )
std::set<bodypart_id> bp_hurt;
for( const bodypart_id &bp : get_all_body_parts() ) {
if( has_effect( effect_under_op, bp.id() ) ) {
if( bp_hurt.count( bp->main_part ) > 0 ) {
if( bp_hurt.contains( bp->main_part ) ) {
continue;
}
bp_hurt.emplace( bp->main_part );
Expand Down Expand Up @@ -2753,7 +2753,7 @@ void Character::remove_bionic( const bionic_id &b )

// any spells you learn from installing a bionic you forget.
for( const std::pair<const spell_id, int> &spell_pair : b->learned_spells ) {
if( cbm_spells.count( spell_pair.first ) == 0 ) {
if( !cbm_spells.contains( spell_pair.first ) ) {
magic->forget_spell( spell_pair.first );
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/calendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,41 +453,41 @@ class time_point
return point.turn_;
}

friend constexpr inline bool operator<( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator<( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) < to_turn<int>( rhs );
}
friend constexpr inline bool operator<=( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator<=( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) <= to_turn<int>( rhs );
}
friend constexpr inline bool operator>( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator>( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) > to_turn<int>( rhs );
}
friend constexpr inline bool operator>=( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator>=( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) >= to_turn<int>( rhs );
}
friend constexpr inline bool operator==( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator==( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) == to_turn<int>( rhs );
}
friend constexpr inline bool operator!=( const time_point &lhs, const time_point &rhs ) {
friend constexpr bool operator!=( const time_point &lhs, const time_point &rhs ) {
return to_turn<int>( lhs ) != to_turn<int>( rhs );
}

friend constexpr inline time_duration operator-(
friend constexpr time_duration operator-(
const time_point &lhs, const time_point &rhs ) {
return time_duration::from_turns( to_turn<int>( lhs ) - to_turn<int>( rhs ) );
}
friend constexpr inline time_point operator+(
friend constexpr time_point operator+(
const time_point &lhs, const time_duration &rhs ) {
return time_point::from_turn( to_turn<int>( lhs ) + to_turns<int>( rhs ) );
}
friend time_point inline &operator+=( time_point &lhs, const time_duration &rhs ) {
friend time_point &operator+=( time_point &lhs, const time_duration &rhs ) {
return lhs = time_point::from_turn( to_turn<int>( lhs ) + to_turns<int>( rhs ) );
}
friend constexpr inline time_point operator-(
friend constexpr time_point operator-(
const time_point &lhs, const time_duration &rhs ) {
return time_point::from_turn( to_turn<int>( lhs ) - to_turns<int>( rhs ) );
}
friend time_point inline &operator-=( time_point &lhs, const time_duration &rhs ) {
friend time_point &operator-=( time_point &lhs, const time_duration &rhs ) {
return lhs = time_point::from_turn( to_turn<int>( lhs ) - to_turns<int>( rhs ) );
}

Expand Down
6 changes: 3 additions & 3 deletions src/cata_arena.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#ifndef CATA_SRC_ARENA_H
#define CATA_SRC_ARENA_H
#ifndef CATA_SRC_CATA_ARENA_H
#define CATA_SRC_CATA_ARENA_H

#include <unordered_map>
#include <set>
Expand Down Expand Up @@ -61,4 +61,4 @@ class cata_arena

void cleanup_arenas();

#endif
#endif // CATA_SRC_CATA_ARENA_H
12 changes: 6 additions & 6 deletions src/cata_libintl.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ class trans_catalogue

explicit trans_catalogue( std::string buffer );

inline void set_buffer( std::string buffer ) {
void set_buffer( std::string buffer ) {
this->buffer = std::move( buffer );
}
inline u32 buf_size() const {
u32 buf_size() const {
return static_cast<u32>( buffer.size() );
}

u8 get_u8( u32 offs ) const;
inline u8 get_u8_unsafe( u32 offs ) const {
u8 get_u8_unsafe( u32 offs ) const {
return static_cast<u8>( buffer[offs] );
}

u32 get_u32( u32 offs ) const;
inline u32 get_u32_unsafe( u32 offs ) const {
u32 get_u32_unsafe( u32 offs ) const {
if( is_little_endian ) {
return get_u8_unsafe( offs ) |
get_u8_unsafe( offs + 1 ) << 8 |
Expand All @@ -135,7 +135,7 @@ class trans_catalogue
string_descr get_string_descr( u32 offs ) const;
string_descr get_string_descr_unsafe( u32 offs ) const;

inline const char *offs_to_cstr( u32 offs ) const {
const char *offs_to_cstr( u32 offs ) const {
return &buffer[offs];
}

Expand All @@ -159,7 +159,7 @@ class trans_catalogue
static trans_catalogue load_from_memory( std::string mo_file );

/** Number of entries in the catalogue. */
inline u32 get_num_strings() const {
u32 get_num_strings() const {
return number_of_strings;
}
/** Get singular translated string of given entry. */
Expand Down
6 changes: 3 additions & 3 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void idle_animation_manager::prepare_for_redraw()
}

struct tile_render_info {
tripoint pos{};
tripoint pos;
// accumulator for 3d tallness of sprites rendered here so far;
int height_3d = 0;
lit_level ll;
Expand Down Expand Up @@ -946,7 +946,7 @@ void tileset_loader::load( const std::string &tileset_id, const bool precheck,
dbg( DL::Warn ) << "tile " << it->first << " has no (valid) foreground nor background";
// remove the id from seasonal variations!
for( auto &container : ts.tile_ids_by_season ) {
if( container.count( it->first ) != 0 ) {
if( container.contains( it->first ) ) {
container.erase( it->first );
}
}
Expand Down Expand Up @@ -3710,7 +3710,7 @@ void cata_tiles::draw_sct_frame( std::multimap<point, formatted_text> &overlay_s
for( int j = 0; j < 2; ++j ) {
std::string sText = iter->getText( ( j == 0 ) ? "first" : "second" );
int FG = msgtype_to_tilecolor( iter->getMsgType( ( j == 0 ) ? "first" : "second" ),
iter->getStep() >= SCT.iMaxSteps / 2 );
iter->getStep() >= scrollingcombattext::iMaxSteps / 2 );

if( use_font ) {
const auto direction = iter->getDirecton();
Expand Down
Loading

0 comments on commit 9405f05

Please sign in to comment.