Fix NewsEvent not doing it's thing after save/load cycle#5192
Merged
impaktor merged 1 commit intopioneerspacesim:masterfrom May 24, 2021
Merged
Fix NewsEvent not doing it's thing after save/load cycle#5192impaktor merged 1 commit intopioneerspacesim:masterfrom
impaktor merged 1 commit intopioneerspacesim:masterfrom
Conversation
The cargo to have its stock and price changed was saved as a EqupType object, which is not a "deep save", but will have a new memory hash every new game, thus price and stock for a commodity that was subject to high/low demand, was unchanged. This should be backwards compatible with older saves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When debugging SpaceStation.lua in #5173, I got sucked in for a number of hours when I discovered that the News Event in the load file provided by the @jimishol clearly wasn't working anymore. There were two "news events" in the save file I was given, I played the "drought news":
"Severe` drought has ruined the crop in the {system} system ({sectorx}, {sectory}, {sectorz}). System wide famine is feared."
which supposed to increase price of grain 10 fold and put stock to 0 in the commodity market, but it didn't seem to change anything on the commodity market.
It was like the
equipmentStocktable inSpaceStationwas reset, but updating it just didn't work.I eventually figured out the
equipmentStocktable is keyed on theEquipTypei.e. the memory address of the table(!), which is all fine and dandy, until you save, because the table is only "shallow-saved", i.g. saving the memory address of a table is bad, so basically, it was modifying the grain price object from previous session, but the grain in the commodity market now has a different memory address.I'm sure I tested save/load of News Event when I wrote it, but equipment system has changed several times since then, so perhaps that's what's caused it, yet I don't know in what universe this would have worked.
So now I save
Equipment.cargo.<item>.name(type:string) instead ofEquipment.cargo.<item>(type:EquipType).Of interest to @Web-eWorks, should be the new code this PR introduces that might stupid: I've added an assert in a for-loop that is redundant, if the keys in an
Equipment.cargoare guaranteed to be the same as.<item>.name. Looks like the.nameis populated from c++ side, and the keys from lua? Anyway, the idea is next time someone fiddles with Equipment/EquipType in a breaking way, this will go poof, thanks to the assert.Below, I demonstrate backwards compatibility with save from @jimishol, (grain now 0, and x10 the price):

EDIT: I think this fixes #5173, although SpaceStation.lua should still get a work over, as there are thing in there that look unstable, as described in #5173.