From eff0bb181267ae4612f1aac3f7980edbaef79aa9 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 18:23:28 +0300 Subject: [PATCH 01/12] Move rate_action_use --- src/game.cpp | 24 +++++++++++++++++++++++- src/player.cpp | 21 --------------------- src/player.h | 1 - 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 186edbd298e24..15bd81f7e6f50 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -193,6 +193,7 @@ static const mtype_id mon_manhack( "mon_manhack" ); static const skill_id skill_melee( "melee" ); static const skill_id skill_dodge( "dodge" ); +static const skill_id skill_gun( "gun" ); static const skill_id skill_firstaid( "firstaid" ); static const skill_id skill_survival( "survival" ); @@ -2010,6 +2011,27 @@ static void handle_contents_changed( const item_location &acted_item ) } while( parent.where() == item_location::type::container ); } +static hint_rating rate_action_use( const avatar &you, const item &it ) +{ + if( it.is_tool() ) { + return it.ammo_sufficient() ? hint_rating::good : hint_rating::iffy; + } else if( it.is_gunmod() ) { + /** @EFFECT_GUN >0 allows rating estimates for gun modifications */ + if( you.get_skill_level( skill_gun ) == 0 ) { + return hint_rating::iffy; + } else { + return hint_rating::good; + } + } else if( it.is_food() || it.is_medication() || it.is_book() || it.is_armor() ) { + // The rating is subjective, could be argued as hint_rating::cant or hint_rating::good as well + return hint_rating::iffy; + } else if( it.type->has_use() ) { + return hint_rating::good; + } + + return hint_rating::cant; +} + /* item submenu for 'i' and '/' * It use draw_item_info to draw item info and action menu * @@ -2058,7 +2080,7 @@ int game::inventory_item_menu( item_location locThisItem, break; } }; - addentry( 'a', pgettext( "action", "activate" ), u.rate_action_use( oThisItem ) ); + addentry( 'a', pgettext( "action", "activate" ), rate_action_use( u, oThisItem ) ); addentry( 'R', pgettext( "action", "read" ), u.rate_action_read( oThisItem ) ); addentry( 'E', pgettext( "action", "eat" ), u.rate_action_eat( oThisItem ) ); addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) ); diff --git a/src/player.cpp b/src/player.cpp index d26177f65e2af..22cecbb31788b 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3110,27 +3110,6 @@ hint_rating player::rate_action_disassemble( const item &it ) } } -hint_rating player::rate_action_use( const item &it ) const -{ - if( it.is_tool() ) { - return it.ammo_sufficient() ? hint_rating::good : hint_rating::iffy; - - } else if( it.is_gunmod() ) { - /** @EFFECT_GUN >0 allows rating estimates for gun modifications */ - if( get_skill_level( skill_gun ) == 0 ) { - return hint_rating::iffy; - } else { - return hint_rating::good; - } - } else if( it.is_food() || it.is_medication() || it.is_book() || it.is_armor() ) { - return hint_rating::iffy; //the rating is subjective, could be argued as hint_rating::cant or hint_rating::good as well - } else if( it.type->has_use() ) { - return hint_rating::good; - } - - return hint_rating::cant; -} - void player::use( int inventory_position ) { item &used = i_at( inventory_position ); diff --git a/src/player.h b/src/player.h index 39ff6b583445b..527ff42ba6c4d 100644 --- a/src/player.h +++ b/src/player.h @@ -492,7 +492,6 @@ class player : public Character /** Used to determine player feedback on item use for the inventory code. * rates usability lower for non-tools (books, etc.) */ - hint_rating rate_action_use( const item &it ) const; hint_rating rate_action_wear( const item &it ) const; hint_rating rate_action_takeoff( const item &it ) const; hint_rating rate_action_reload( const item &it ) const; From c4cbadb2282cf98a53cb49bcb1f8bad980e28c4c Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 18:41:00 +0300 Subject: [PATCH 02/12] Move rate_action_eat --- src/character.h | 2 -- src/consumption.cpp | 16 ---------------- src/game.cpp | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/character.h b/src/character.h index 8627516f5ccbc..8cd62171fc71d 100644 --- a/src/character.h +++ b/src/character.h @@ -2083,8 +2083,6 @@ class Character : public Creature, public visitable */ item &get_consumable_from( item &it ) const; - hint_rating rate_action_eat( const item &it ) const; - /** Get calorie & vitamin contents for a comestible, taking into * account character traits */ /** Get range of possible nutrient content, for a particular recipe, diff --git a/src/consumption.cpp b/src/consumption.cpp index ee6809c41c1a0..94dde8ab521f2 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1346,22 +1346,6 @@ bool Character::consume_effects( item &food ) return true; } -hint_rating Character::rate_action_eat( const item &it ) const -{ - if( !can_consume( it ) ) { - return hint_rating::cant; - } - - const auto rating = will_eat( it ); - if( rating.success() ) { - return hint_rating::good; - } else if( rating.value() == INEDIBLE || rating.value() == INEDIBLE_MUTATION ) { - return hint_rating::cant; - } - - return hint_rating::iffy; -} - bool Character::can_feed_reactor_with( const item &it ) const { static const std::set acceptable = {{ diff --git a/src/game.cpp b/src/game.cpp index 15bd81f7e6f50..14f11e38ae88f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2011,6 +2011,22 @@ static void handle_contents_changed( const item_location &acted_item ) } while( parent.where() == item_location::type::container ); } +static hint_rating rate_action_eat( const avatar &you, const item &it ) +{ + if( !you.can_consume( it ) ) { + return hint_rating::cant; + } + + const auto rating = you.will_eat( it ); + if( rating.success() ) { + return hint_rating::good; + } else if( rating.value() == INEDIBLE || rating.value() == INEDIBLE_MUTATION ) { + return hint_rating::cant; + } + + return hint_rating::iffy; +} + static hint_rating rate_action_use( const avatar &you, const item &it ) { if( it.is_tool() ) { @@ -2082,7 +2098,7 @@ int game::inventory_item_menu( item_location locThisItem, }; addentry( 'a', pgettext( "action", "activate" ), rate_action_use( u, oThisItem ) ); addentry( 'R', pgettext( "action", "read" ), u.rate_action_read( oThisItem ) ); - addentry( 'E', pgettext( "action", "eat" ), u.rate_action_eat( oThisItem ) ); + addentry( 'E', pgettext( "action", "eat" ), rate_action_eat( u, oThisItem ) ); addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) ); addentry( 'w', pgettext( "action", "wield" ), hint_rating::good ); addentry( 't', pgettext( "action", "throw" ), hint_rating::good ); From d7233c7948350e1e69a1b5bf772a71d23edae432 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 18:54:43 +0300 Subject: [PATCH 03/12] Move rate_action_read --- src/avatar.cpp | 10 ---------- src/avatar.h | 2 -- src/game.cpp | 12 +++++++++++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index f1fbe873b3071..41e836ec1761e 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -935,16 +935,6 @@ bool avatar::has_identified( const itype_id &item_id ) const return items_identified.count( item_id ) > 0; } -hint_rating avatar::rate_action_read( const item &it ) const -{ - if( !it.is_book() ) { - return hint_rating::cant; - } - - std::vector dummy; - return get_book_reader( it, dummy ) == nullptr ? hint_rating::iffy : hint_rating::good; -} - void avatar::wake_up() { if( has_effect( effect_sleep ) ) { diff --git a/src/avatar.h b/src/avatar.h index 9e38f71cfec25..4da97e1b7c29d 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -164,8 +164,6 @@ class avatar : public player /** Note that we've read a book at least once. **/ bool has_identified( const itype_id &item_id ) const override; - hint_rating rate_action_read( const item &it ) const; - void wake_up(); // Grab furniture / vehicle void grab( object_type grab_type, const tripoint &grab_point = tripoint_zero ); diff --git a/src/game.cpp b/src/game.cpp index 14f11e38ae88f..44961c796ae50 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2027,6 +2027,16 @@ static hint_rating rate_action_eat( const avatar &you, const item &it ) return hint_rating::iffy; } +static hint_rating rate_action_read( const avatar &you, const item &it ) +{ + if( !it.is_book() ) { + return hint_rating::cant; + } + + std::vector dummy; + return you.get_book_reader( it, dummy ) ? hint_rating::good : hint_rating::iffy; +} + static hint_rating rate_action_use( const avatar &you, const item &it ) { if( it.is_tool() ) { @@ -2097,7 +2107,7 @@ int game::inventory_item_menu( item_location locThisItem, } }; addentry( 'a', pgettext( "action", "activate" ), rate_action_use( u, oThisItem ) ); - addentry( 'R', pgettext( "action", "read" ), u.rate_action_read( oThisItem ) ); + addentry( 'R', pgettext( "action", "read" ), rate_action_read( u, oThisItem ) ); addentry( 'E', pgettext( "action", "eat" ), rate_action_eat( u, oThisItem ) ); addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) ); addentry( 'w', pgettext( "action", "wield" ), hint_rating::good ); From df6162074ed863c1166f084ae7fc2982510ca53d Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 18:58:56 +0300 Subject: [PATCH 04/12] Move rate_action_mend --- src/game.cpp | 11 ++++++++++- src/player.cpp | 9 --------- src/player.h | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 44961c796ae50..1ef828e740132 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2027,6 +2027,15 @@ static hint_rating rate_action_eat( const avatar &you, const item &it ) return hint_rating::iffy; } +static hint_rating rate_action_mend( const avatar &, const item &it ) +{ + // TODO: check also if item damage could be repaired via a tool + if( !it.faults.empty() ) { + return hint_rating::good; + } + return it.faults_potential().empty() ? hint_rating::cant : hint_rating::iffy; +} + static hint_rating rate_action_read( const avatar &you, const item &it ) { if( !it.is_book() ) { @@ -2118,7 +2127,7 @@ int game::inventory_item_menu( item_location locThisItem, addentry( 'U', pgettext( "action", "unload" ), u.rate_action_unload( oThisItem ) ); addentry( 'r', pgettext( "action", "reload" ), u.rate_action_reload( oThisItem ) ); addentry( 'p', pgettext( "action", "part reload" ), u.rate_action_reload( oThisItem ) ); - addentry( 'm', pgettext( "action", "mend" ), u.rate_action_mend( oThisItem ) ); + addentry( 'm', pgettext( "action", "mend" ), rate_action_mend( u, oThisItem ) ); addentry( 'D', pgettext( "action", "disassemble" ), u.rate_action_disassemble( oThisItem ) ); if( oThisItem.has_pockets() ) { addentry( 'i', pgettext( "action", "insert" ), hint_rating::good ); diff --git a/src/player.cpp b/src/player.cpp index 22cecbb31788b..6b64aa048eb1c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3088,15 +3088,6 @@ hint_rating player::rate_action_unload( const item &it ) const return hint_rating::iffy; } -hint_rating player::rate_action_mend( const item &it ) const -{ - // TODO: check also if item damage could be repaired via a tool - if( !it.faults.empty() ) { - return hint_rating::good; - } - return it.faults_potential().empty() ? hint_rating::cant : hint_rating::iffy; -} - hint_rating player::rate_action_disassemble( const item &it ) { if( can_disassemble( it, crafting_inventory() ).success() ) { diff --git a/src/player.h b/src/player.h index 527ff42ba6c4d..c9e9563b53856 100644 --- a/src/player.h +++ b/src/player.h @@ -496,7 +496,6 @@ class player : public Character hint_rating rate_action_takeoff( const item &it ) const; hint_rating rate_action_reload( const item &it ) const; hint_rating rate_action_unload( const item &it ) const; - hint_rating rate_action_mend( const item &it ) const; hint_rating rate_action_disassemble( const item &it ); //returns true if the warning is now beyond final and results in hostility. From 990fbc285e8ee59a89fa2ad95ce8d5cf676793be Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 21:30:02 +0300 Subject: [PATCH 05/12] Move rate_action_wear --- src/game.cpp | 15 ++++++++++++++- src/player.cpp | 11 ----------- src/player.h | 1 - 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 1ef828e740132..6d735f31cca0f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2067,6 +2067,19 @@ static hint_rating rate_action_use( const avatar &you, const item &it ) return hint_rating::cant; } +static hint_rating rate_action_wear( const avatar &you, const item &it ) +{ + if( !it.is_armor() ) { + return hint_rating::cant; + } + + if( you.is_worn( it ) ) { + return hint_rating::iffy; + } + + return you.can_wear( it ).success() ? hint_rating::good : hint_rating::iffy; +} + /* item submenu for 'i' and '/' * It use draw_item_info to draw item info and action menu * @@ -2118,7 +2131,7 @@ int game::inventory_item_menu( item_location locThisItem, addentry( 'a', pgettext( "action", "activate" ), rate_action_use( u, oThisItem ) ); addentry( 'R', pgettext( "action", "read" ), rate_action_read( u, oThisItem ) ); addentry( 'E', pgettext( "action", "eat" ), rate_action_eat( u, oThisItem ) ); - addentry( 'W', pgettext( "action", "wear" ), u.rate_action_wear( oThisItem ) ); + addentry( 'W', pgettext( "action", "wear" ), rate_action_wear( u, oThisItem ) ); addentry( 'w', pgettext( "action", "wield" ), hint_rating::good ); addentry( 't', pgettext( "action", "throw" ), hint_rating::good ); addentry( 'c', pgettext( "action", "change side" ), u.rate_action_change_side( oThisItem ) ); diff --git a/src/player.cpp b/src/player.cpp index 6b64aa048eb1c..e4d7f8710aa6a 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2445,17 +2445,6 @@ bool character_martial_arts::pick_style( const avatar &you ) // Style selection return true; } -hint_rating player::rate_action_wear( const item &it ) const -{ - // TODO: flag already-worn items as hint_rating::iffy - - if( !it.is_armor() ) { - return hint_rating::cant; - } - - return can_wear( it ).success() ? hint_rating::good : hint_rating::iffy; -} - bool player::can_reload( const item &it, const itype_id &ammo ) const { diff --git a/src/player.h b/src/player.h index c9e9563b53856..65d4e945c9fc0 100644 --- a/src/player.h +++ b/src/player.h @@ -492,7 +492,6 @@ class player : public Character /** Used to determine player feedback on item use for the inventory code. * rates usability lower for non-tools (books, etc.) */ - hint_rating rate_action_wear( const item &it ) const; hint_rating rate_action_takeoff( const item &it ) const; hint_rating rate_action_reload( const item &it ) const; hint_rating rate_action_unload( const item &it ) const; From d28ff304377976e11ca75b1927ccc4e3c5a95777 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 22:17:14 +0300 Subject: [PATCH 06/12] Move rate_action_takeoff --- src/game.cpp | 15 ++++++++++++++- src/player.cpp | 13 ------------- src/player.h | 1 - 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 6d735f31cca0f..31ef3abd3dc04 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2046,6 +2046,19 @@ static hint_rating rate_action_read( const avatar &you, const item &it ) return you.get_book_reader( it, dummy ) ? hint_rating::good : hint_rating::iffy; } +static hint_rating rate_action_take_off( const avatar &you, const item &it ) +{ + if( !it.is_armor() || it.has_flag( "NO_TAKEOFF" ) ) { + return hint_rating::cant; + } + + if( you.is_worn( it ) ) { + return hint_rating::good; + } + + return hint_rating::iffy; +} + static hint_rating rate_action_use( const avatar &you, const item &it ) { if( it.is_tool() ) { @@ -2135,7 +2148,7 @@ int game::inventory_item_menu( item_location locThisItem, addentry( 'w', pgettext( "action", "wield" ), hint_rating::good ); addentry( 't', pgettext( "action", "throw" ), hint_rating::good ); addentry( 'c', pgettext( "action", "change side" ), u.rate_action_change_side( oThisItem ) ); - addentry( 'T', pgettext( "action", "take off" ), u.rate_action_takeoff( oThisItem ) ); + addentry( 'T', pgettext( "action", "take off" ), rate_action_take_off( u, oThisItem ) ); addentry( 'd', pgettext( "action", "drop" ), rate_drop_item ); addentry( 'U', pgettext( "action", "unload" ), u.rate_action_unload( oThisItem ) ); addentry( 'r', pgettext( "action", "reload" ), u.rate_action_reload( oThisItem ) ); diff --git a/src/player.cpp b/src/player.cpp index e4d7f8710aa6a..47d8019fcfe40 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2751,19 +2751,6 @@ player::wear( item &to_wear, bool interactive ) return result; } -hint_rating player::rate_action_takeoff( const item &it ) const -{ - if( !it.is_armor() ) { - return hint_rating::cant; - } - - if( is_worn( it ) ) { - return hint_rating::good; - } - - return hint_rating::iffy; -} - ret_val player::can_takeoff( const item &it, const std::list *res ) { auto iter = std::find_if( worn.begin(), worn.end(), [ &it ]( const item & wit ) { diff --git a/src/player.h b/src/player.h index 65d4e945c9fc0..0a4ecc45772e8 100644 --- a/src/player.h +++ b/src/player.h @@ -492,7 +492,6 @@ class player : public Character /** Used to determine player feedback on item use for the inventory code. * rates usability lower for non-tools (books, etc.) */ - hint_rating rate_action_takeoff( const item &it ) const; hint_rating rate_action_reload( const item &it ) const; hint_rating rate_action_unload( const item &it ) const; hint_rating rate_action_disassemble( const item &it ); From 6345b2ce9ba4a64a5f7bff254e816215348d8086 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Thu, 4 Jun 2020 22:27:43 +0300 Subject: [PATCH 07/12] Move rate_action_change_side --- src/character.cpp | 13 ------------- src/character.h | 4 ---- src/game.cpp | 11 ++++++++++- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index fe849263df63d..ed185d52c3bfc 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3600,19 +3600,6 @@ int Character::extraEncumbrance( const layer_level level, const int bp ) const return encumbrance_cache[bp].layer_penalty_details[static_cast( level )].total; } -hint_rating Character::rate_action_change_side( const item &it ) const -{ - if( !is_worn( it ) ) { - return hint_rating::iffy; - } - - if( !it.is_sided() ) { - return hint_rating::cant; - } - - return hint_rating::good; -} - bool Character::change_side( item &it, bool interactive ) { if( !it.swap_side() ) { diff --git a/src/character.h b/src/character.h index 8cd62171fc71d..0842a073560f4 100644 --- a/src/character.h +++ b/src/character.h @@ -2118,10 +2118,6 @@ class Character : public Creature, public visitable bool change_side( item &it, bool interactive = true ); bool change_side( item_location &loc, bool interactive = true ); - /** Used to determine player feedback on item use for the inventory code. - * rates usability lower for non-tools (books, etc.) */ - hint_rating rate_action_change_side( const item &it ) const; - bool get_check_encumbrance() { return check_encumbrance; } diff --git a/src/game.cpp b/src/game.cpp index 31ef3abd3dc04..d16e26151d67f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2011,6 +2011,15 @@ static void handle_contents_changed( const item_location &acted_item ) } while( parent.where() == item_location::type::container ); } +static hint_rating rate_action_change_side( const avatar &you, const item &it ) +{ + if( !it.is_sided() ) { + return hint_rating::cant; + } + + return you.is_worn( it ) ? hint_rating::good : hint_rating::iffy; +} + static hint_rating rate_action_eat( const avatar &you, const item &it ) { if( !you.can_consume( it ) ) { @@ -2147,7 +2156,7 @@ int game::inventory_item_menu( item_location locThisItem, addentry( 'W', pgettext( "action", "wear" ), rate_action_wear( u, oThisItem ) ); addentry( 'w', pgettext( "action", "wield" ), hint_rating::good ); addentry( 't', pgettext( "action", "throw" ), hint_rating::good ); - addentry( 'c', pgettext( "action", "change side" ), u.rate_action_change_side( oThisItem ) ); + addentry( 'c', pgettext( "action", "change side" ), rate_action_change_side( u, oThisItem ) ); addentry( 'T', pgettext( "action", "take off" ), rate_action_take_off( u, oThisItem ) ); addentry( 'd', pgettext( "action", "drop" ), rate_drop_item ); addentry( 'U', pgettext( "action", "unload" ), u.rate_action_unload( oThisItem ) ); From 7a59cd6a857476a45ca8f50080c6b567af6015cc Mon Sep 17 00:00:00 2001 From: olanti-p Date: Fri, 5 Jun 2020 01:03:03 +0300 Subject: [PATCH 08/12] Move rate_action_disassemble --- src/crafting.cpp | 6 +++--- src/game.cpp | 16 +++++++++++++++- src/item.cpp | 5 +++++ src/item.h | 1 + src/iuse_actor.cpp | 2 +- src/player.cpp | 13 ------------- src/player.h | 1 - 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index b93d518b74191..67aa6a6a80660 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -1896,12 +1896,12 @@ void player::consume_tools( const std::vector &tools, int batch, ret_val player::can_disassemble( const item &obj, const inventory &inv ) const { - const auto &r = recipe_dictionary::get_uncraft( obj.typeId() ); - - if( !r || obj.has_flag( flag_ETHEREAL_ITEM ) ) { + if( !obj.is_disassemblable() ) { return ret_val::make_failure( _( "You cannot disassemble this." ) ); } + const recipe &r = recipe_dictionary::get_uncraft( obj.typeId() ); + // check sufficient light if( lighting_craft_speed_multiplier( r ) == 0.0f ) { return ret_val::make_failure( _( "You can't see to craft!" ) ); diff --git a/src/game.cpp b/src/game.cpp index d16e26151d67f..1a8964cdfb997 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2020,6 +2020,20 @@ static hint_rating rate_action_change_side( const avatar &you, const item &it ) return you.is_worn( it ) ? hint_rating::good : hint_rating::iffy; } +static hint_rating rate_action_disassemble( avatar &you, const item &it ) +{ + if( you.can_disassemble( it, you.crafting_inventory() ).success() ) { + // Possible right now + return hint_rating::good; + } else if( it.is_disassemblable() ) { + // Potentially possible, but we currently lack requirements + return hint_rating::iffy; + } else { + // Never possible + return hint_rating::cant; + } +} + static hint_rating rate_action_eat( const avatar &you, const item &it ) { if( !you.can_consume( it ) ) { @@ -2163,7 +2177,7 @@ int game::inventory_item_menu( item_location locThisItem, addentry( 'r', pgettext( "action", "reload" ), u.rate_action_reload( oThisItem ) ); addentry( 'p', pgettext( "action", "part reload" ), u.rate_action_reload( oThisItem ) ); addentry( 'm', pgettext( "action", "mend" ), rate_action_mend( u, oThisItem ) ); - addentry( 'D', pgettext( "action", "disassemble" ), u.rate_action_disassemble( oThisItem ) ); + addentry( 'D', pgettext( "action", "disassemble" ), rate_action_disassemble( u, oThisItem ) ); if( oThisItem.has_pockets() ) { addentry( 'i', pgettext( "action", "insert" ), hint_rating::good ); if( oThisItem.contents.num_item_stacks() > 0 ) { diff --git a/src/item.cpp b/src/item.cpp index abf9bdb81b8a6..4da7f3c847d0a 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -6550,6 +6550,11 @@ bool item::is_salvageable() const return !has_flag( flag_NO_SALVAGE ); } +bool item::is_disassemblable() const +{ + return recipe_dictionary::get_uncraft( typeId() ) && !has_flag( flag_ETHEREAL_ITEM ); +} + bool item::is_craft() const { return craft_data_ != nullptr; diff --git a/src/item.h b/src/item.h index 133b3ab9097a0..14ab0d4497ff3 100644 --- a/src/item.h +++ b/src/item.h @@ -1154,6 +1154,7 @@ class item : public visitable bool is_book() const; bool is_map() const; bool is_salvageable() const; + bool is_disassemblable() const; bool is_craft() const; bool is_deployable() const; diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index 2bb3e610b7769..5896bb5f58c48 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -1465,7 +1465,7 @@ bool salvage_actor::try_to_cut_up( player &p, item &it ) const // There must be some historical significance to these items. if( !it.is_salvageable() ) { add_msg( m_info, _( "Can't salvage anything from %s." ), it.tname() ); - if( p.rate_action_disassemble( it ) != hint_rating::cant ) { + if( it.is_disassemblable() ) { add_msg( m_info, _( "Try disassembling the %s instead." ), it.tname() ); } return false; diff --git a/src/player.cpp b/src/player.cpp index 47d8019fcfe40..0385af98a7489 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3064,19 +3064,6 @@ hint_rating player::rate_action_unload( const item &it ) const return hint_rating::iffy; } -hint_rating player::rate_action_disassemble( const item &it ) -{ - if( can_disassemble( it, crafting_inventory() ).success() ) { - return hint_rating::good; // possible - - } else if( recipe_dictionary::get_uncraft( it.typeId() ) ) { - return hint_rating::iffy; // potentially possible but we currently lack requirements - - } else { - return hint_rating::cant; // never possible - } -} - void player::use( int inventory_position ) { item &used = i_at( inventory_position ); diff --git a/src/player.h b/src/player.h index 0a4ecc45772e8..92da2fb1f70bb 100644 --- a/src/player.h +++ b/src/player.h @@ -494,7 +494,6 @@ class player : public Character * rates usability lower for non-tools (books, etc.) */ hint_rating rate_action_reload( const item &it ) const; hint_rating rate_action_unload( const item &it ) const; - hint_rating rate_action_disassemble( const item &it ); //returns true if the warning is now beyond final and results in hostility. bool add_faction_warning( const faction_id &id ); From b2e8b670b3d8f11b13b2af2d4acd5443d554c432 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Fri, 5 Jun 2020 02:25:56 +0300 Subject: [PATCH 09/12] Update hint_rating and its documentation --- src/item.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/item.h b/src/item.h index 14ab0d4497ff3..42d6dd29fd1bb 100644 --- a/src/item.h +++ b/src/item.h @@ -2270,18 +2270,16 @@ bool item_compare_by_charges( const item &left, const item &right ); bool item_ptr_compare_by_charges( const item *left, const item *right ); /** - * Hint value used in a hack to decide text color. - * - * This is assigned as a result of some legacy logic in @ref draw_item_info(). This - * will eventually be rewritten to eliminate the need for this hack. + * Hint value used for item examination screen and filtering items by action. + * Represents whether an item permits given action (reload, wear, read, etc.). */ -enum class hint_rating : int { - /** Item should display as gray */ - cant = 0, - /** Item should display as red */ - iffy = 1, - /** Item should display as green */ - good = -999 +enum class hint_rating { + /** Item permits this action */ + good, + /** Item permits this action, but circumstances don't */ + iffy, + /** Item does not permit this action */ + cant }; /** From ca64bb77fcb7b25ace9604a4a74e6196888761ec Mon Sep 17 00:00:00 2001 From: olanti-p Date: Fri, 5 Jun 2020 21:43:57 +0300 Subject: [PATCH 10/12] Move rate_action_unload into Character class --- src/character.cpp | 33 +++++++++++++++++++++++++++++++++ src/character.h | 2 ++ src/player.cpp | 33 --------------------------------- src/player.h | 1 - 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index ed185d52c3bfc..30e406327528f 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -6721,6 +6721,39 @@ int Character::ammo_count_for( const item &gun ) return ret; } +hint_rating Character::rate_action_unload( const item &it ) const +{ + if( it.is_container() && !it.contents.empty() && + it.can_unload_liquid() ) { + return hint_rating::good; + } + + if( it.has_flag( "NO_UNLOAD" ) ) { + return hint_rating::cant; + } + + if( it.magazine_current() ) { + return hint_rating::good; + } + + for( const item *e : it.gunmods() ) { + if( e->is_gun() && !e->has_flag( "NO_UNLOAD" ) && + ( e->magazine_current() || e->ammo_remaining() > 0 || e->casings_count() > 0 ) ) { + return hint_rating::good; + } + } + + if( it.ammo_types().empty() ) { + return hint_rating::cant; + } + + if( it.ammo_remaining() > 0 || it.casings_count() > 0 ) { + return hint_rating::good; + } + + return hint_rating::iffy; +} + float Character::rest_quality() const { // Just a placeholder for now. diff --git a/src/character.h b/src/character.h index 0842a073560f4..1d03efda491c4 100644 --- a/src/character.h +++ b/src/character.h @@ -1405,6 +1405,8 @@ class Character : public Creature, public visitable */ int ammo_count_for( const item &gun ); + hint_rating rate_action_unload( const item &it ) const; + /** Maximum thrown range with a given item, taking all active effects into account. */ int throw_range( const item & ) const; /** Dispersion of a thrown item, against a given target, taking into account whether or not the throw was blind. */ diff --git a/src/player.cpp b/src/player.cpp index 0385af98a7489..261bdd4b8502d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3031,39 +3031,6 @@ hint_rating player::rate_action_reload( const item &it ) const return can_reload( it ) ? hint_rating::good : hint_rating::iffy; } -hint_rating player::rate_action_unload( const item &it ) const -{ - if( it.is_container() && !it.contents.empty() && - it.can_unload_liquid() ) { - return hint_rating::good; - } - - if( it.has_flag( "NO_UNLOAD" ) ) { - return hint_rating::cant; - } - - if( it.magazine_current() ) { - return hint_rating::good; - } - - for( auto e : it.gunmods() ) { - if( e->is_gun() && !e->has_flag( "NO_UNLOAD" ) && - ( e->magazine_current() || e->ammo_remaining() > 0 || e->casings_count() > 0 ) ) { - return hint_rating::good; - } - } - - if( it.ammo_types().empty() ) { - return hint_rating::cant; - } - - if( it.ammo_remaining() > 0 || it.casings_count() > 0 ) { - return hint_rating::good; - } - - return hint_rating::iffy; -} - void player::use( int inventory_position ) { item &used = i_at( inventory_position ); diff --git a/src/player.h b/src/player.h index 92da2fb1f70bb..a19d43b7cd6ce 100644 --- a/src/player.h +++ b/src/player.h @@ -493,7 +493,6 @@ class player : public Character /** Used to determine player feedback on item use for the inventory code. * rates usability lower for non-tools (books, etc.) */ hint_rating rate_action_reload( const item &it ) const; - hint_rating rate_action_unload( const item &it ) const; //returns true if the warning is now beyond final and results in hostility. bool add_faction_warning( const faction_id &id ); From ab5e26435d278406f1cbbfda2766cd344b3c8f3d Mon Sep 17 00:00:00 2001 From: olanti-p Date: Fri, 5 Jun 2020 21:44:04 +0300 Subject: [PATCH 11/12] Move can_reload into Character class --- src/character.cpp | 16 ++++++++++++++++ src/character.h | 9 +++++++++ src/player.cpp | 17 ----------------- src/player.h | 9 --------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 30e406327528f..5060008a27268 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -6721,6 +6721,22 @@ int Character::ammo_count_for( const item &gun ) return ret; } +bool Character::can_reload( const item &it, const itype_id &ammo ) const +{ + if( !it.is_reloadable_with( ammo ) ) { + return false; + } + + if( it.is_ammo_belt() ) { + const cata::optional &linkage = it.type->magazine->linkage; + if( linkage && !has_charges( *linkage, 1 ) ) { + return false; + } + } + + return true; +} + hint_rating Character::rate_action_unload( const item &it ) const { if( it.is_container() && !it.contents.empty() && diff --git a/src/character.h b/src/character.h index 1d03efda491c4..6e54aec155454 100644 --- a/src/character.h +++ b/src/character.h @@ -1405,6 +1405,15 @@ class Character : public Creature, public visitable */ int ammo_count_for( const item &gun ); + /** + * Whether a tool or gun is potentially reloadable (optionally considering a specific ammo) + * @param it Thing to be reloaded + * @param ammo if set also check item currently compatible with this specific ammo or magazine + * @note items currently loaded with a detachable magazine are considered reloadable + * @note items with integral magazines are reloadable if free capacity permits (+/- ammo matches) + */ + bool can_reload( const item &it, const itype_id &ammo = itype_id() ) const; + hint_rating rate_action_unload( const item &it ) const; /** Maximum thrown range with a given item, taking all active effects into account. */ diff --git a/src/player.cpp b/src/player.cpp index 261bdd4b8502d..d6b34d93d7345 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2445,23 +2445,6 @@ bool character_martial_arts::pick_style( const avatar &you ) // Style selection return true; } -bool player::can_reload( const item &it, const itype_id &ammo ) const -{ - - if( !it.is_reloadable_with( ammo ) ) { - return false; - } - - if( it.is_ammo_belt() ) { - const auto &linkage = it.type->magazine->linkage; - if( linkage && !has_charges( *linkage, 1 ) ) { - return false; - } - } - - return true; -} - void player::mend_item( item_location &&obj, bool interactive ) { if( has_trait( trait_DEBUG_HS ) ) { diff --git a/src/player.h b/src/player.h index a19d43b7cd6ce..d6fc32b6a1b3e 100644 --- a/src/player.h +++ b/src/player.h @@ -381,15 +381,6 @@ class player : public Character bool unwield(); - /** - * Whether a tool or gun is potentially reloadable (optionally considering a specific ammo) - * @param it Thing to be reloaded - * @param ammo if set also check item currently compatible with this specific ammo or magazine - * @note items currently loaded with a detachable magazine are considered reloadable - * @note items with integral magazines are reloadable if free capacity permits (+/- ammo matches) - */ - bool can_reload( const item &it, const itype_id &ammo = itype_id() ) const; - /** * Attempt to mend an item (fix any current faults) * @param obj Object to mend From dc302e28559f083c90213de37197bbccb9175de3 Mon Sep 17 00:00:00 2001 From: olanti-p Date: Fri, 5 Jun 2020 21:44:10 +0300 Subject: [PATCH 12/12] Move rate_action_reload into Character class --- src/character.cpp | 25 +++++++++++++++++++++++++ src/character.h | 3 +++ src/player.cpp | 25 ------------------------- src/player.h | 4 ---- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 5060008a27268..a74d2e93d338a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -6737,6 +6737,31 @@ bool Character::can_reload( const item &it, const itype_id &ammo ) const return true; } +hint_rating Character::rate_action_reload( const item &it ) const +{ + hint_rating res = hint_rating::cant; + + // Guns may contain additional reloadable mods so check these first + for( const item *mod : it.gunmods() ) { + switch( rate_action_reload( *mod ) ) { + case hint_rating::good: + return hint_rating::good; + + case hint_rating::cant: + continue; + + case hint_rating::iffy: + res = hint_rating::iffy; + } + } + + if( !it.is_reloadable() ) { + return res; + } + + return can_reload( it ) ? hint_rating::good : hint_rating::iffy; +} + hint_rating Character::rate_action_unload( const item &it ) const { if( it.is_container() && !it.contents.empty() && diff --git a/src/character.h b/src/character.h index 6e54aec155454..af2be162ef06a 100644 --- a/src/character.h +++ b/src/character.h @@ -1414,6 +1414,9 @@ class Character : public Creature, public visitable */ bool can_reload( const item &it, const itype_id &ammo = itype_id() ) const; + /** Same as `Character::can_reload`, but checks for attached gunmods as well. */ + hint_rating rate_action_reload( const item &it ) const; + /** Whether a tool or a gun can be unloaded. */ hint_rating rate_action_unload( const item &it ) const; /** Maximum thrown range with a given item, taking all active effects into account. */ diff --git a/src/player.cpp b/src/player.cpp index d6b34d93d7345..94308472739a3 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2989,31 +2989,6 @@ void player::use_wielded() use( -1 ); } -hint_rating player::rate_action_reload( const item &it ) const -{ - hint_rating res = hint_rating::cant; - - // Guns may contain additional reloadable mods so check these first - for( const auto mod : it.gunmods() ) { - switch( rate_action_reload( *mod ) ) { - case hint_rating::good: - return hint_rating::good; - - case hint_rating::cant: - continue; - - case hint_rating::iffy: - res = hint_rating::iffy; - } - } - - if( !it.is_reloadable() ) { - return res; - } - - return can_reload( it ) ? hint_rating::good : hint_rating::iffy; -} - void player::use( int inventory_position ) { item &used = i_at( inventory_position ); diff --git a/src/player.h b/src/player.h index d6fc32b6a1b3e..45c3471332510 100644 --- a/src/player.h +++ b/src/player.h @@ -481,10 +481,6 @@ class player : public Character * if they will potentially have enough light when player gets there */ float fine_detail_vision_mod( const tripoint &p = tripoint_zero ) const; - /** Used to determine player feedback on item use for the inventory code. - * rates usability lower for non-tools (books, etc.) */ - hint_rating rate_action_reload( const item &it ) const; - //returns true if the warning is now beyond final and results in hostility. bool add_faction_warning( const faction_id &id ); int current_warnings_fac( const faction_id &id );