rewrite how monster attacks read spells #38585
Merged
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: Bugfixes "Rewrite fake_spell code to fix crazy monster spells"
Purpose of change
Fixes #33938 (hopefully?)
Describe the solution
While looking into the code that caused the above linked bug, I realized that fake_spell::get_spell() was really... messy. so much so, in fact, that it wasn't exactly clear what it did. So i rearranged it a little bit and renamed some of the variables to make it a lot clearer what's going on:
You have a couple important values. first, the bottom values, which can be a maximum of (0, min_level, min_level_override). min_level is fake_spell::level. min_level_override is actually specifically from casting spells that have additional effects; the level of the parent spell gets passed down as a minimum spell, and it's stored as a fake_spell.
The max level can either be defined in the fake_spell, or the spell's max level, whichever is lower.
I needed to also add some error checking here, just in case the minimum got to be greater than the maximum: i reset the min to be max. Therefore, the priority is as follows: <= spell max level. <= fake_spell::max level. >= 0. >= min_level_override. >= fake_spell::level.
Then, I noticed that the spell data that was loaded in for monster spell attacks was actually more of an ad-hoc code, rather than reusing the fake_spell code i implemented (which is a pretty general-use and lightweight way of storing a spell) so i made that happen.
These two things combined should overpower this bug! also it's clearer. and it reuses code.
Describe alternatives you've considered
stare into the eye of a krabgek and have my insides becomes my outsides
Testing
set a breakpoint in the load_internal function in the monster spell attack class to see that the spell it stores (a spell, not a fake spell) is the right level. It's an issue with loading; it's only loaded the one time.
Additional context
i also fixed a minor thing with the black pudding's message. Additionally, this will break 3rd-party mods that use monster spells, as I changed how the json works. It's pretty important to take a look at the other mods in repo to see if they have monster spells, though i don't think there are any. anyway, it's WIP until i confirm.