Skip to content

Commit

Permalink
Weight cache invalidation where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyBerube committed Oct 6, 2020
1 parent ccff323 commit 98923e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8124,6 +8124,7 @@ bool item::reload( Character &u, item_location ammo, int qty )
return false;
}

bool ammo_from_map = !ammo.held_by( u );
item_location container;
if( ammo->has_flag( flag_SPEEDLOADER ) ) {
container = ammo;
Expand Down Expand Up @@ -8215,6 +8216,9 @@ bool item::reload( Character &u, item_location ammo, int qty )

put_in( *ammo, item_pocket::pocket_type::MAGAZINE_WELL );
ammo.remove_item();
if( ammo_from_map ) {
u.invalidate_weight_carried_cache();
}
return true;
}

Expand All @@ -8224,6 +8228,9 @@ bool item::reload( Character &u, item_location ammo, int qty )
u.inv->restack( u ); // emptied containers do not stack with non-empty ones
}
}
if( ammo_from_map ) {
u.invalidate_weight_carried_cache();
}
return true;
}

Expand Down Expand Up @@ -8721,6 +8728,8 @@ int item::fill_with( const item &contained, const int amount )
debugmsg( "tried to put an item (%s) in a container (%s) that cannot contain it",
contained_item.typeId().str(), typeId().str() );
}
on_contents_changed();
get_avatar().invalidate_weight_carried_cache();
return num_contained;
}

Expand Down
2 changes: 2 additions & 0 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ bool pick_one_up( item_location &loc, int quantity, bool &got_water, bool &offer
loc.remove_item();
}
player_character.moves -= moves_taken;
player_character.flag_encumbrance();
player_character.invalidate_weight_carried_cache();
}

return picked_up || !did_prompt;
Expand Down
1 change: 1 addition & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,7 @@ bool player::unload( item_location &loc, bool bypass_activity )

if( changed ) {
it.on_contents_changed();
invalidate_weight_carried_cache();
}
return true;
}
Expand Down

0 comments on commit 98923e2

Please sign in to comment.