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 3): Use ints for invlets #31468

Merged
merged 1 commit into from
Jun 15, 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/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum bionic_menu_mode {
};
} // namespace

bionic *player::bionic_by_invlet( const long ch )
bionic *player::bionic_by_invlet( const int ch )
{
if( ch == ' ' ) { // space is a special case for unassigned
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class Character : public Creature, public visitable<Character>
/** Returns true if player has a trait with a flag */
bool has_trait_flag( const std::string &flag ) const;
/** Returns the trait id with the given invlet, or an empty string if no trait has that invlet */
trait_id trait_by_invlet( long ch ) const;
trait_id trait_by_invlet( int ch ) const;

/** Toggles a trait on the player and in their mutation list */
void toggle_trait( const trait_id &flag );
Expand Down
4 changes: 2 additions & 2 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,8 @@ void game_menus::inv::compare( player &p, const cata::optional<tripoint> &offset
void game_menus::inv::reassign_letter( player &p, item &it )
{
while( true ) {
const long invlet = popup_getkey(
_( "Enter new letter. Press SPACE to clear a manually assigned letter, ESCAPE to cancel." ) );
const int invlet = popup_getkey(
_( "Enter new letter. Press SPACE to clear a manually assigned letter, ESCAPE to cancel." ) );

if( invlet == KEY_ESCAPE ) {
break;
Expand Down
2 changes: 1 addition & 1 deletion src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct itype;
const invlet_wrapper
inv_chars( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#&()+.:;=@[\\]^_{|}" );

bool invlet_wrapper::valid( const long invlet ) const
bool invlet_wrapper::valid( const int invlet ) const
{
if( invlet > std::numeric_limits<char>::max() || invlet < std::numeric_limits<char>::min() ) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ using invlets_bitset = std::bitset<std::numeric_limits<char>::max()>;
* Wrapper to handled a set of valid "inventory" letters. "inventory" can be any set of
* objects that the player can access via a single character (e.g. bionics).
* The class is (currently) derived from std::string for compatibility and because it's
* simpler. But it may be changed to derive from `std::set<long>` or similar to get the full
* simpler. But it may be changed to derive from `std::set<int>` or similar to get the full
* range of possible characters.
*/
class invlet_wrapper : private std::string
{
public:
invlet_wrapper( const char *chars ) : std::string( chars ) { }

bool valid( long invlet ) const;
bool valid( int invlet ) const;
std::string get_allowed_chars() const {
return *this;
}
Expand Down
16 changes: 8 additions & 8 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct navigation_mode_data {

struct inventory_input {
std::string action;
long ch;
int ch;
inventory_entry *entry;
};

Expand Down Expand Up @@ -132,9 +132,9 @@ size_t inventory_entry::get_available_count() const
}
}

long inventory_entry::get_invlet() const
int inventory_entry::get_invlet() const
{
if( custom_invlet != LONG_MIN ) {
if( custom_invlet != INT_MIN ) {
return custom_invlet;
}
return location ? location->invlet : '\0';
Expand Down Expand Up @@ -171,7 +171,7 @@ bool inventory_column::activatable() const
} );
}

inventory_entry *inventory_column::find_by_invlet( long invlet ) const
inventory_entry *inventory_column::find_by_invlet( int invlet ) const
{
for( const auto &elem : entries ) {
if( elem.is_item() && elem.get_invlet() == invlet ) {
Expand Down Expand Up @@ -794,9 +794,9 @@ size_t inventory_column::get_entry_indent( const inventory_entry &entry ) const
return res;
}

long inventory_column::reassign_custom_invlets( const player &p, long min_invlet, long max_invlet )
int inventory_column::reassign_custom_invlets( const player &p, int min_invlet, int max_invlet )
{
long cur_invlet = min_invlet;
int cur_invlet = min_invlet;
for( auto &elem : entries ) {
// Only items on map/in vehicles: those that the player does not possess.
if( elem.is_selectable() && !p.has_item( *elem.location ) ) {
Expand Down Expand Up @@ -1179,7 +1179,7 @@ bool inventory_selector::select( const item_location &loc )
return res;
}

inventory_entry *inventory_selector::find_entry_by_invlet( long invlet ) const
inventory_entry *inventory_selector::find_entry_by_invlet( int invlet ) const
{
for( const auto elem : columns ) {
const auto res = elem->find_by_invlet( invlet );
Expand Down Expand Up @@ -1219,7 +1219,7 @@ void inventory_selector::prepare_layout( size_t client_width, size_t client_heig
visible_columns.front()->set_width( client_width );
}

long custom_invlet = '0';
int custom_invlet = '0';
for( auto &elem : columns ) {
elem->prepare_paging();
custom_invlet = elem->reassign_custom_invlets( u, custom_invlet, '9' );
Expand Down
10 changes: 5 additions & 5 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class inventory_entry
item_location location;

size_t chosen_count = 0;
long custom_invlet = LONG_MIN;
int custom_invlet = INT_MIN;
std::string cached_name;

inventory_entry( const item_location &location, size_t stack_size,
Expand Down Expand Up @@ -122,7 +122,7 @@ class inventory_entry

size_t get_available_count() const;
const item_category *get_category_ptr() const;
long get_invlet() const;
int get_invlet() const;
nc_color get_invlet_color() const;
void update_cache();

Expand Down Expand Up @@ -264,7 +264,7 @@ class inventory_column
std::vector<inventory_entry *> get_entries(
const std::function<bool( const inventory_entry &entry )> &filter_func ) const;

inventory_entry *find_by_invlet( long invlet ) const;
inventory_entry *find_by_invlet( int invlet ) const;

void draw( const catacurses::window &win, size_t x, size_t y ) const;

Expand Down Expand Up @@ -304,7 +304,7 @@ class inventory_column
/** Resets width to original (unchanged). */
void reset_width();
/** Returns next custom inventory letter. */
long reassign_custom_invlets( const player &p, long min_invlet, long max_invlet );
int reassign_custom_invlets( const player &p, int min_invlet, int max_invlet );
/** Reorder entries, repopulate titles, adjust to the new height. */
virtual void prepare_paging( const std::string &filter = "" );
/**
Expand Down Expand Up @@ -527,7 +527,7 @@ class inventory_selector
void draw_frame( const catacurses::window &w ) const;

/** @return an entry from all entries by its invlet */
inventory_entry *find_entry_by_invlet( long invlet ) const;
inventory_entry *find_entry_by_invlet( int invlet ) const;

const std::vector<inventory_column *> &get_all_columns() const {
return columns;
Expand Down
2 changes: 1 addition & 1 deletion src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ void player::deactivate_mutation( const trait_id &mut )
recalc_sight_limits();
}

trait_id Character::trait_by_invlet( const long ch ) const
trait_id Character::trait_by_invlet( const int ch ) const
{
for( auto &mut : my_mutations ) {
if( mut.second.key == ch ) {
Expand Down
6 changes: 3 additions & 3 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6992,10 +6992,10 @@ item player::reduce_charges( item *it, int quantity )
return result;
}

int player::invlet_to_position( const long linvlet ) const
int player::invlet_to_position( const int linvlet ) const
{
// Invlets may come from curses, which may also return any kind of key codes, those being
// of type long and they can become valid, but different characters when casted to char.
// of type int and they can become valid, but different characters when casted to char.
// Example: KEY_NPAGE (returned when the player presses the page-down key) is 0x152,
// casted to char would yield 0x52, which happens to be 'R', a valid invlet.
if( linvlet > std::numeric_limits<char>::max() || linvlet < std::numeric_limits<char>::min() ) {
Expand Down Expand Up @@ -9174,7 +9174,7 @@ bool player::invoke_item( item *used, const std::string &method, const tripoint
return false;
}

void player::reassign_item( item &it, long invlet )
void player::reassign_item( item &it, int invlet )
{
bool remove_old = true;
if( invlet ) {
Expand Down
6 changes: 3 additions & 3 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class player : public Character
/** Returns the bionic at a given index in my_bionics[] */
bionic &bionic_at_index( int i );
/** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */
bionic *bionic_by_invlet( long ch );
bionic *bionic_by_invlet( int ch );
/** Returns player luminosity based on the brightest active item they are carrying */
float active_light() const;

Expand Down Expand Up @@ -1099,7 +1099,7 @@ class player : public Character
bool invoke_item( item * );
bool invoke_item( item *, const std::string & );
/** Reassign letter. */
void reassign_item( item &it, long invlet );
void reassign_item( item &it, int invlet );

/** Consume charges of a tool or comestible item, potentially destroying it in the process
* @param used item consuming the charges
Expand Down Expand Up @@ -1268,7 +1268,7 @@ class player : public Character
/** Return the item position of the item with given invlet, return INT_MIN if
* the player does not have such an item with that invlet. Don't use this on npcs.
* Only use the invlet in the user interface, otherwise always use the item position. */
int invlet_to_position( long invlet ) const;
int invlet_to_position( int invlet ) const;

/**
* Check whether player has a bionic power armor interface.
Expand Down