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

Removing long (part 7): Various miscellaneous changes #31550

Merged
merged 19 commits into from
Jun 18, 2019
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/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace
class basic_animation
{
public:
basic_animation( const long scale ) :
basic_animation( const int scale ) :
delay{ 0, get_option<int>( "ANIMATION_DELAY" ) * scale * 1000000l } {
}

Expand Down
2 changes: 1 addition & 1 deletion src/char_validity_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param ch The char to check.
* @return true if the char is allowed in a name, false if not.
*/
bool is_char_allowed( long ch )
bool is_char_allowed( int ch )
{
if( !std::isprint( ch ) && ch <= 127 ) {
// above 127 are non-ASCII, therefore Unicode, therefore OK
Expand Down
2 changes: 1 addition & 1 deletion src/char_validity_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#ifndef CHAR_VALIDITY_CHECK_H
#define CHAR_VALIDITY_CHECK_H

bool is_char_allowed( long ch );
bool is_char_allowed( int ch );

#endif
2 changes: 1 addition & 1 deletion src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ void draw_benchmark( const int max_difference )
// call the draw procedure as many times as possible in max_difference milliseconds
auto start_tick = std::chrono::steady_clock::now();
auto end_tick = std::chrono::steady_clock::now();
long difference = 0;
int64_t difference = 0;
int draw_counter = 0;
while( true ) {
end_tick = std::chrono::steady_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ static void smash()
if( vol > 20 ) {
// Hurt left arm too, if it was big
u.deal_damage( nullptr, bp_hand_l, damage_instance( DT_CUT, rng( 0,
static_cast<long>( vol * .5 ) ) ) );
static_cast<int>( vol * .5 ) ) ) );
}
u.remove_weapon();
u.check_dead_state();
Expand Down
8 changes: 4 additions & 4 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3956,10 +3956,10 @@ static player &best_installer( player &p, player &null_player, int difficulty )
skill_computer,
skill_electronics );

std::vector< std::pair<float, long>> ally_skills;
std::vector< std::pair<float, int>> ally_skills;
ally_skills.reserve( g->allies().size() );
for( size_t i = 0; i < g->allies().size() ; i ++ ) {
std::pair<float, long> ally_skill;
std::pair<float, int> ally_skill;
const npc *e = g->allies()[ i ];

player &ally = *g->critter_by_id<player>( e->getID() );
Expand All @@ -3969,8 +3969,8 @@ static player &best_installer( player &p, player &null_player, int difficulty )
skill_electronics );
ally_skills.push_back( ally_skill );
}
std::sort( ally_skills.begin(), ally_skills.end(), [&]( const std::pair<float, long> &lhs,
const std::pair<float, long> &rhs ) {
std::sort( ally_skills.begin(), ally_skills.end(), [&]( const std::pair<float, int> &lhs,
const std::pair<float, int> &rhs ) {
return rhs.first < lhs.first;
} );
int player_cos = bionic_manip_cos( player_skill, true, difficulty );
Expand Down
5 changes: 3 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ void item::set_var( const std::string &name, const int value )
item_vars[name] = tmpstream.str();
}

// NOLINTNEXTLINE(cata-no-long)
void item::set_var( const std::string &name, const long value )
{
std::ostringstream tmpstream;
Expand Down Expand Up @@ -3864,12 +3865,12 @@ std::string item::get_property_string( const std::string &prop, const std::strin
return it != type->properties.end() ? it->second : def;
}

long item::get_property_long( const std::string &prop, long def ) const
int64_t item::get_property_int64_t( const std::string &prop, int64_t def ) const
{
const auto it = type->properties.find( prop );
if( it != type->properties.end() ) {
char *e = nullptr;
long r = std::strtol( it->second.c_str(), &e, 10 );
int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
if( !it->second.empty() && *e == '\0' ) {
return r;
}
Expand Down
5 changes: 3 additions & 2 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,6 @@ class item : public visitable<item>
* All numeric values are returned as doubles and may be cast to the desired type.
* <code>
* int v = itm.get_var("v", 0); // v will be an int
* long l = itm.get_var("v", 0l); // l will be a long
* double d = itm.get_var("v", 0.0); // d will be a double
* std::string s = itm.get_var("v", ""); // s will be a std::string
* // no default means empty string as default:
Expand All @@ -1235,6 +1234,8 @@ class item : public visitable<item>
*/
/*@{*/
void set_var( const std::string &name, int value );
// Acceptable to use long as part of overload set
// NOLINTNEXTLINE(cata-no-long)
void set_var( const std::string &name, long value );
void set_var( const std::string &name, double value );
double get_var( const std::string &name, double default_value ) const;
Expand Down Expand Up @@ -1292,7 +1293,7 @@ class item : public visitable<item>
* Return same type as the passed default value, or string where no default provided
*/
std::string get_property_string( const std::string &prop, const std::string &def = "" ) const;
long get_property_long( const std::string &prop, long def = 0 ) const;
int64_t get_property_int64_t( const std::string &prop, int64_t def = 0 ) const;
/*@}*/

/**
Expand Down
8 changes: 1 addition & 7 deletions src/item_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class item_location
bool operator==( const item_location &rhs ) const;
bool operator!=( const item_location &rhs ) const;

operator bool() const;
explicit operator bool() const;

item &operator*();
const item &operator*() const;
Expand Down Expand Up @@ -106,12 +106,6 @@ class item_location
class impl;

std::shared_ptr<impl> ptr;

/* Not implemented on purpose. This triggers a compiler / linker
* error when used in any implicit conversion. It prevents the
* implicit conversion to int. */
template<typename T>
operator T() const;
};

#endif
2 changes: 1 addition & 1 deletion src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ mission_type_id mission::get_follow_up() const
return follow_up;
}

long mission::get_value() const
int mission::get_value() const
{
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class mission
const mission_type &get_type() const;
bool has_follow_up() const;
mission_type_id get_follow_up() const;
long get_value() const;
int get_value() const;
int get_id() const;
const std::string &get_item_id() const;
int get_npc_id() const;
Expand Down
4 changes: 2 additions & 2 deletions src/mod_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class mod_ui
void try_rem( size_t selection, std::vector<mod_id> &active_list );
void try_shift( char direction, size_t &selection, std::vector<mod_id> &active_list );

bool can_shift_up( long selection, const std::vector<mod_id> &active_list );
bool can_shift_down( long selection, const std::vector<mod_id> &active_list );
bool can_shift_up( size_t selection, const std::vector<mod_id> &active_list );
bool can_shift_down( size_t selection, const std::vector<mod_id> &active_list );
};

#endif
10 changes: 5 additions & 5 deletions src/mod_manager_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ void mod_ui::try_shift( char direction, size_t &selection, std::vector<mod_id> &
selection += selshift;
}

bool mod_ui::can_shift_up( long selection, const std::vector<mod_id> &active_list )
bool mod_ui::can_shift_up( size_t selection, const std::vector<mod_id> &active_list )
{
// error catch for out of bounds
if( selection < 0 || selection >= static_cast<int>( active_list.size() ) ) {
if( selection >= active_list.size() ) {
return false;
}
// dependencies of this active element
Expand All @@ -239,17 +239,17 @@ bool mod_ui::can_shift_up( long selection, const std::vector<mod_id> &active_lis
}
}

bool mod_ui::can_shift_down( long selection, const std::vector<mod_id> &active_list )
bool mod_ui::can_shift_down( size_t selection, const std::vector<mod_id> &active_list )
{
// error catch for out of bounds
if( selection < 0 || selection >= static_cast<int>( active_list.size() ) ) {
if( selection >= active_list.size() ) {
return false;
}
std::vector<mod_id> dependents = mm_tree.get_dependents_of_X_as_strings(
active_list[selection] );

// figure out if we can move down!
if( selection == static_cast<int>( active_list.size() ) - 1 ) {
if( selection == active_list.size() - 1 ) {
// can't move down, don't bother trying
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ find_empty_neighbors( const Creature &c )
*/
static size_t get_random_index( const size_t size )
{
return static_cast<size_t>( rng( 0, static_cast<long>( size - 1 ) ) );
return static_cast<size_t>( rng( 0, static_cast<int>( size - 1 ) ) );
}

//--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in
}

std::string effects = get_effect_status();
long long used_space = att.first.length() + name().length() + 3;
size_t used_space = att.first.length() + name().length() + 3;
trim_and_print( w, vStart++, used_space, getmaxx( w ) - used_space - 2,
h_white, effects );

Expand Down Expand Up @@ -2447,7 +2447,7 @@ void monster::on_hit( Creature *source, body_part,
return;
}

if( rng( 0, 100 ) <= static_cast<long>( type->def_chance ) ) {
if( rng( 0, 100 ) <= static_cast<int>( type->def_chance ) ) {
type->sp_defense( *this, source, proj );
}

Expand Down
2 changes: 1 addition & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ int npc::print_info( const catacurses::window &w, int line, int vLines, int colu
size_t split;
do {
split = ( str_in.length() <= iWidth ) ? std::string::npos : str_in.find_last_of( ' ',
static_cast<long>( iWidth ) );
static_cast<int>( iWidth ) );
if( split == std::string::npos ) {
mvwprintz( w, line, column, color, str_in );
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ bool npc::can_reload_current()
return false;
}

return find_usable_ammo( weapon );
return static_cast<bool>( find_usable_ammo( weapon ) );
}

item_location npc::find_usable_ammo( const item &weap )
Expand Down
2 changes: 1 addition & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ void options_manager::cOpt::setNext()
}

} else if( sType == "int_map" ) {
long unsigned int iNext = getIntPos( iSet ) + 1;
unsigned int iNext = getIntPos( iSet ) + 1;
if( iNext >= mIntValues.size() ) {
iNext = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ dealt_projectile_attack player::throw_item( const tripoint &target, const item &

// Item will burst upon landing, destroying the item, and spilling its contents
const bool burst = thrown.has_property( "burst_when_filled" ) && thrown.is_container() &&
thrown.get_property_long( "burst_when_filled" ) <= static_cast<double>
thrown.get_property_int64_t( "burst_when_filled" ) <= static_cast<double>
( thrown.get_contained().volume().value() ) / thrown.get_container_capacity().value() * 100;

// Add some flags to the projectile
Expand Down
Loading