From b549b38e3dbbb7dd14d930d2b285e5bf60aa9443 Mon Sep 17 00:00:00 2001 From: Gabriel-SE Date: Sun, 8 Feb 2015 02:14:25 +0700 Subject: [PATCH] Prevent non-reversible items from appearing in sleep menu --- src/game.cpp | 2 +- src/item.cpp | 15 +++++++++++++++ src/item.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/game.cpp b/src/game.cpp index 985b2ca101f49..8c6988368a627 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3274,7 +3274,7 @@ bool game::handle_action() // List all active items, bionics or mutations so player can deactivate them std::vector active; for ( auto &it : g->u.inv_dump() ) { - if ( it->active && it->is_tool() && it->charges > 0 ) { + if ( it->active && it->charges > 0 && it->is_tool_reversible() ) { active.push_back( it->tname() ); } } diff --git a/src/item.cpp b/src/item.cpp index d41237882277c..c505c256644b7 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -2875,6 +2875,21 @@ bool item::is_tool() const return type->is_tool(); } +bool item::is_tool_reversible() const +{ + const it_tool *source = dynamic_cast( type ); + if( source != nullptr && source->revert_to != "null" ) { + item revert( source->revert_to, 0 ); + npc n; + revert.type->invoke( &n, &revert, false, point(-999, -999) ); + const it_tool *target = dynamic_cast( revert.type ); + if ( target != nullptr ) { + return ( source->id == target->id ); + } + } + return false; +} + bool item::is_software() const { return type->software.get() != nullptr; diff --git a/src/item.h b/src/item.h index 4830e73487211..b9f82ace0cf9f 100644 --- a/src/item.h +++ b/src/item.h @@ -495,6 +495,7 @@ class item : public JsonSerializer, public JsonDeserializer bool is_funnel_container(int &bigger_than) const; bool is_tool() const; + bool is_tool_reversible() const; bool is_software() const; bool is_var_veh_part() const; bool is_artifact() const;