Skip to content

Commit

Permalink
avatar/item: update cached flags when transforming items (CleverRaven…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei8l authored Apr 10, 2023
1 parent 39d183e commit cc6b43c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ void avatar_action::use_item( avatar &you, item_location &loc, std::string const
parent_pocket->handle_liquid_or_spill( you, loc.parent_item().get_item() );
}
}
if( loc ) {
loc.on_contents_changed();
}

you.recoil = MAX_RECOIL;

Expand Down
8 changes: 4 additions & 4 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5423,10 +5423,10 @@ void item::properties_info( std::vector<iteminfo> &info, const iteminfo_query *p

if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
// concatenate base and acquired flags...
std::vector<flag_id> flags;
std::set_union( type->get_flags().begin(), type->get_flags().end(),
get_flags().begin(), get_flags().end(),
std::back_inserter( flags ) );
cata::flat_set<flag_id> flags;
flags.insert( get_flags().begin(), get_flags().end() );
flags.insert( type->get_flags().begin(), type->get_flags().end() );
flags.insert( inherited_tags_cache.begin(), inherited_tags_cache.end() );

// ...and display those which have an info description
for( const flag_id &e : sorted_lex( flags ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ class item_location::impl::item_in_container : public item_location::impl
}

void remove_item() override {
on_contents_changed();
container->remove_item( *target() );
container->on_contents_changed();
}

void on_contents_changed() override {
Expand Down
1 change: 1 addition & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4299,6 +4299,7 @@ std::optional<int> modify_gunmods_actor::use( Character &p, item &it, bool,
// set gun to default in case this changes anything
it.gun_set_mode( gun_mode_DEFAULT );
p.invoke_item( mods[prompt.ret], "transform", pnt );
it.on_contents_changed();
return 0;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "avatar.h"
#include "avatar_action.h"
#include "calendar.h"
#include "enums.h"
#include "flag.h"
Expand Down Expand Up @@ -40,6 +41,8 @@ static const itype_id itype_test_mp3( "test_mp3" );
static const itype_id itype_test_smart_phone( "test_smart_phone" );
static const itype_id itype_test_waterproof_bag( "test_waterproof_bag" );

static const json_character_flag json_flag_DEAF( "DEAF" );

TEST_CASE( "item_volume", "[item]" )
{
// Need to pick some item here which is count_by_charges and for which each
Expand Down Expand Up @@ -805,6 +808,17 @@ TEST_CASE( "module_inheritance", "[item][armor]" )
guy.worn.wear_item( guy, test_exo, false, false, false );

CHECK( guy.worn.worn_with_flag( json_flag_FIX_NEARSIGHT ) );

clear_avatar();
item miner_hat( "miner_hat" );
item ear_muffs( "attachable_ear_muffs" );
REQUIRE( miner_hat.put_in( ear_muffs, item_pocket::pocket_type::CONTAINER ).success() );
REQUIRE( !miner_hat.has_flag( json_flag_DEAF ) );
guy.wear_item( miner_hat );
item_location worn_hat = guy.worn.top_items_loc( guy ).front();
item_location worn_muffs( worn_hat, &worn_hat->only_item() );
avatar_action::use_item( guy, worn_muffs, "transform" );
CHECK( worn_hat->has_flag( json_flag_DEAF ) );
}

TEST_CASE( "rigid_armor_compliance", "[item][armor]" )
Expand Down

0 comments on commit cc6b43c

Please sign in to comment.