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

Fix NewsEvent not doing it's thing after save/load cycle #5192

Merged
merged 1 commit into from
May 24, 2021

Conversation

impaktor
Copy link
Member

@impaktor impaktor commented May 17, 2021

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 equipmentStock table in SpaceStation was reset, but updating it just didn't work.

I eventually figured out the equipmentStock table is keyed on the EquipType i.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 of Equipment.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.cargo are guaranteed to be the same as .<item>.name. Looks like the .name is 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):
2021-05-17-115201_1600x900_scrot

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.

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.
@impaktor impaktor merged commit 663990e into pioneerspacesim:master May 24, 2021
@impaktor impaktor deleted the fix_newsevent branch May 24, 2021 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Game crashes on arriving on system with News Event (no crop).
1 participant