Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Infrastructure "Create enchantment cache for use with enchantment values"
Purpose of change
As part of the ongoing project of the artifact project. This particular PR puts down the infrastructure needed in order to calculate values for things that do not already have a "bonus" (like the stats and speed) This effectively makes an enchantment object on Character that has a list of bonuses.
Describe the solution
Add an
enchantment_cache
member toCharacter
and logic for building the cache every turn. This cache will be built for avatar and npcs, so this is likely something that can and should be optimized. However, due to the fact that enchantments in mainline will likely only be on artifacts, and artifacts are few and far between, the cost might be negligible.Also, to demonstrate the use for the cache and that the cache works, implements
MOVE_COST
from the list in #33837 and adds a small buff to ice gliders in magiclysm.Describe alternatives you've considered
getting the values from all the items in your inventory, worn, and wielded, checking if they're active, etc. every single time a variable in the code might be modified by an enchantment value. Obviously this thought didn't go too far, since building the cache would be miles better, as you don't have to iterate through who knows how many items.
However, one thing that can be considered is the location of the recalculate_enchantment_cache function; i put it in update_body, since the cache lives in Character, but it doesn't feel quite right to me, as it doesn't really feel like something that would be part of the "body," but that might just be a matter of nomenclature.
Additional context
It might be possible to use this cache rather than the separate logic I wrote in process_artifacts altogether. I might think of that later on in the project's life, when considering removing the previous artifact infrastructure.