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

Rebuild active_item cache for vehicles after refresh #60952

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

robob27
Copy link
Contributor

@robob27 robob27 commented Sep 12, 2022

Summary

Bugfixes "Some items taken out of fridges rot immediately"

Purpose of change

Fixes #58824

Describe the solution

After we modified vehicle::refresh() to add/remove fake parts, it seems to have started causing issues with the active_item cache for vehicles. More information in my comment here. TL;DR, vehicle::refresh caused active_items to become empty, which caused items inside the vehicle not to be processed for rot etc.

It seems we need to refresh the active_item cache as part of vehicle::refresh now based on this. So I made the following changes:

  • Add a new method vehicle::refresh_active_item_cache to encapsulate the logic for setting up active_items
  • Call the new vehicle::refresh_active_item_cache method at the end of the vehicle::refresh method
  • Stop setting up active_item cache directly in vehicle::deserialize - this method calls vehicle::refresh which handles this now by calling vehicle::refresh_active_item_cache.

Describe alternatives you've considered

  • Maybe adding fake parts to vehicles isn't supposed to impact active_item cache and this isn't the right solution. At the very least I hope my naive attempt at fixing this might serve to push someone with a bit more context towards the right solution.

Testing

Using the debug stuff described here I verified that after applying the changes, items in fridges were no longer frozen in time after a save/load, and had rot values updated as expected while waiting nearby.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Vehicles Vehicles, parts, mechanics & interactions <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Sep 12, 2022
@NetSysFire NetSysFire added the Items: Food / Vitamins Comestibles and drinks label Sep 12, 2022
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 12, 2022
@robob27 robob27 marked this pull request as ready for review September 13, 2022 01:29
@dseguin dseguin merged commit 6e4d1f4 into CleverRaven:master Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Items: Food / Vitamins Comestibles and drinks json-styled JSON lint passed, label assigned by github actions Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(cool) Food stacks [E]aten from a fridge gets placed in player inventory and immediately spoils
3 participants