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

Weight cache invalidation where needed #44661

Merged
merged 1 commit into from
Oct 7, 2020
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
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