DaloLorn / Rising-Stars

A large-scale mod for Star Ruler 2.
http://steamcommunity.com/sharedfiles/filedetails/?id=812827373
Other
18 stars 7 forks source link

Logistics mechanic discounts are reset after loading game #85

Closed BottledByte closed 1 year ago

BottledByte commented 1 year ago

Build and maintenance cost discounts provided by logistics mechanic after building several ships of the same design get reset after saving and loading the game.

Found in commit 61e21ee0201440d7b88028254a6b3f20760e35cd

Screenshot at the time of save:

before

After loading (Net budget and Scout cost are different):

after

Reproduction steps

  1. Start a new game in singleplayer
  2. Build a lots of Scouts, so that logistics mechanic kicks in quickly
  3. Save the game
  4. Reload
  5. Build and maintenace costs of existing and new Scouts are reset to values before logistics mechanic discounts

Additional notes

I have skimmed through the scripts and tried to figure out the reason and it appears that the DesignManager object is not saved and loaded along with ObjectManager.

Adding DesignManager to save() and load() methods of ObjectManager seemingly fixed the issue, but I am not sure if it is a correct solution.

DaloLorn commented 1 year ago

... How could I miss something as big as that?! 😱

Yeah, it's the correct solution. Shouldn't be too hard, just have to get around to it tomorrow or something.

BottledByte commented 1 year ago

I see you have fixed this with commit deeef551e38afe171b1907c5dbde6ea73e7f138d using the solution I described... and now there is a segfault when loading existing saves :smile:

I was not sure about whether simply adding DesignManager deserialization to save file loading without any checks is a proper solution, because it breaks existing saves (which makes the engine crash with a segfault). I do not know your policy when it comes to backwards compatibility and I am completely OK with this solution - I am using "nightly" version of the mod and I am well-aware that it comes with both benefits and drawbacks :slightly_smiling_face:

However, it would make sense to me to either:

  1. Add some conditional to save loading to prevent the segfault and also allow easy migration of save files
  2. Put a notice somewhere that save files are incompatible with previous mod versions

If it is possible, I think first solution is better in long-term, because of the save migration it offers. Other players may have save files they would like to keep and use.

Otherwise, the fix works :+1: and you can close this issue if you are OK with this saves thing.

DaloLorn commented 1 year ago

Mmm, I can't think of any versioning mechanism available to me that would salvage the savefile... and it occurs to me that the Launchpad won't be able to roll back to the preceding commit on its own. Ouch. That's a bit of functionality I hadn't considered before...

You should be able to keep playing your if you manually install the right version, though.

BottledByte commented 1 year ago

I see... if I understood you correctly, now all save files created prior to aforementioned commit stopped working and you cannot migrate them in any way now...

Good thing is that it is possible to salvage save files. It is in fact relatively simple. I will write the steps down here for posterity.

  1. In the mod's directory, go to scripts/server/components/
  2. Open ObjectManager.as there
  3. Go to method load(SaveFile& file) of ObjectManager class
  4. Comment-out line file >> designs; and save the file
  5. Start the game and load savefile created before this fix
  6. Save it again
  7. After you are done with re-saving your saves, exit the Game
  8. Uncomment the previously commented-out line in ObjectManager.as
  9. Your save files should no longer cause segfaults

Not exactly optimal save migration, but it works OK for me.

However, is there a way to allow hotfixing save file migrations in the future? Is mod's version info/number stored somewhere in the save files, so it can be reused in load() hooks to properly deserialize (and migrate) them?

From what I understood

  1. Mods can have their own save file format, incompatible with base game and/or other mods.
  2. The base game itself embeds version info into saves and handles migrations this way.

If such versioning mechanism is not in place yet, then I am thinking about whether it does not worth to break the save file format once more and adding it. Having a versioning mechanism like that seems useful to me in long-term.

DaloLorn commented 1 year ago

There's not really any convenient place to put it, as far as I know... 😐

BottledByte commented 1 year ago

I see... :slightly_frowning_face:

I guess there is not much to be done here anyway. The issue is fixed, so it's time to close this.

And thanks for a such fast response and fix :+1:

PS: I suggest to label this issue post-mortem as a bug for posterity. I saw you were using that label in the past.