Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: apply all clang-tidy fixes #5548

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1297,7 +1297,7 @@
int level_cap = std::min<int>( MAX_SKILL,
( static_cast<int>( corpse->size ) + ( cbms.size() * 2 + 1 ) ) );
int size_mult = corpse->size > creature_size::medium ? ( corpse->size * corpse->size ) : 8;
int practice_amt = ( size_mult + 1 ) * ( ( time_to_cut / 150 ) + 1 ) *

Check warning on line 1300 in src/activity_handlers.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
( cbms.size() * cbms.size() / 2 + 1 );
p->practice( skill_firstaid, practice_amt, level_cap );
add_msg( m_debug, "Experience: %d, Level cap: %d, Time to cut: %d", practice_amt, level_cap,
Expand Down Expand Up @@ -1772,11 +1772,11 @@
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 @@ -440,13 +440,13 @@
{
std::vector<detached_ptr<item>> vec;
vec.push_back( std::move( it ) );
return put_into_vehicle_or_drop( c, reason, vec, c.pos() );

Check warning on line 443 in src/activity_item_handling.cpp

View workflow job for this annotation

GitHub Actions / build

return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]
}

void put_into_vehicle_or_drop( Character &c, item_drop_reason reason,
std::vector<detached_ptr<item>> &items )
{
return put_into_vehicle_or_drop( c, reason, items, c.pos() );

Check warning on line 449 in src/activity_item_handling.cpp

View workflow job for this annotation

GitHub Actions / build

return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]
}

void put_into_vehicle_or_drop( Character &c, item_drop_reason reason,
Expand Down Expand Up @@ -579,7 +579,7 @@
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 @@
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 @@
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 @@
} 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 @@
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 All @@ -1322,7 +1322,7 @@
// If we make it here and haven't found anything to reload, start looking elsewhere.
vehicle *veh = veh_pointer_or_null( here.veh_at( u.pos() ) );
turret_data turret;
if( veh && ( turret = veh->turret_query( u.pos() ) ) && turret.can_reload() ) {

Check warning on line 1325 in src/avatar_action.cpp

View workflow job for this annotation

GitHub Actions / build

an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
item_reload_option opt = character_funcs::select_ammo( u, turret.base(), true );
if( opt ) {
u.assign_activity( std::make_unique<player_activity>( activity_id( "ACT_RELOAD" ), opt.moves(),
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 @@
}

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 @@ -290,7 +290,7 @@
}
auto &res = iter->second;
if( res.season_tile ) {
return *res.season_tile;

Check warning on line 293 in src/cata_tiles.cpp

View workflow job for this annotation

GitHub Actions / build

conversion from 'std::optional<tile_lookup_res>' into 'tile_lookup_res' and back into 'std::optional<tile_lookup_res>', remove potentially error-prone optional dereference [bugprone-optional-value-conversion]
} else if( res.default_tile ) { // can skip this check, but just in case
return tile_lookup_res( iter->first, *res.default_tile );
}
Expand Down Expand Up @@ -542,7 +542,7 @@
}
// for debugging only: force a very small maximal texture size, as to trigger
// splitting the tile atlas.
#if 0

Check warning on line 545 in src/cata_tiles.cpp

View workflow job for this annotation

GitHub Actions / build

preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
// +1 to check correct rounding
info.max_texture_width = sprite_width * 10 + 1;
info.max_texture_height = sprite_height * 20 + 1;
Expand Down Expand Up @@ -946,7 +946,7 @@
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 @@
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
Loading