Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Loading savegames loses upgrade effects #4215

Closed
wzdev-ci opened this issue Sep 25, 2014 · 11 comments
Closed

Loading savegames loses upgrade effects #4215

wzdev-ci opened this issue Sep 25, 2014 · 11 comments

Comments

@wzdev-ci
Copy link
Contributor

resolution_fixed type_bug | by Althalus


This bug is related to both #4178 and #4020, and I suspect they have the same causes.

The observable bug is that whenever I load a savegame in skirmish mode, all the upgradable stats (hitpoints, armor, damage, research points, ...) are reset to the base values.
I haven't tried with campaign saves, but #4178 is about campaign, so I think the bug could trigger too.

I have tracked down the possible causes, and I found that the actual application of the upgrades is done via javascript (mainly the eventResearched function in rules.js), but the code that initializes the relevant data structures, which I believe is mainly the function registerFunctions in qtscriptfuncs.cpp, is called after the events have been processed.

The nearest common caller of these functions is levLoadData in levels.cpp, with the research events being triggered by loadGame at line 887, while initialization of the scripts is done by loadMultiScripts at line 1004.

I have tried to put the call to loadMultiScripts earlier, but putting it around line 852 leads to a crash, and putting it around line 885 leads to a game playable, with upgrades as they should be, but I get a number of assertion failures so I suspect this is not a good solution either.

As a reference, I am attaching a late-game save, where it is obvious whether upgrades are applied or not (factory has 1000 hp without upgrades, 3700 with, for example).


Issue migrated from trac:4215 at 2022-04-16 11:44:28 -0700

@wzdev-ci
Copy link
Contributor Author

Althalus uploaded file tmp.tar.gz (4610.0 KiB)

Late game skirmish save

@wzdev-ci
Copy link
Contributor Author

NoQ commented


Per is actively working on it in qt5andjson branch, not sure if already fixed, but these mechanisms would be significantly reworked.

@wzdev-ci
Copy link
Contributor Author

Per changed blocking which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Per changed blockedby which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Per commented


I'm not changing the loading sequence, though, which is a horrid mess due to all the partial loading in campaign.

@wzdev-ci
Copy link
Contributor Author

Althalus commented


I have made a patch that solves the problem. It introduces a flag tracking whether scripts are usable or not, and a queue to which events that come when the above flag is not set are added. When the flag is set to true, the queue is emptied and its events are re-triggered.

For consideration :

  • I'm not sure the place where I switch the flag to true (and re-trigger the events) is the best one.
    It seems to work so far, but there might be a better place for this.
  • I'm using the class QQueue from Qt to preserve the order in which events are triggered, but given that they seem to happen in a random order anyway, it might be simpler to use a QList.

@wzdev-ci
Copy link
Contributor Author

Althalus uploaded file researchResultsOnLoad.diff (2.3 KiB)

output of git diff from master branch

@wzdev-ci
Copy link
Contributor Author

per changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

per changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

per commented


Fix issue where loading savegames loses upgrade effects. Also fix duplicate
loading of map labels. Based on patch by Althalus. Closes #4215.

Changeset: b800411b580d3343f32b6391e45875e6c7bc6ea8

@wzdev-ci
Copy link
Contributor Author

Per commented


Sorry it took so long to commit this. I really wanted to find a less hacky fix, but that turned out to require way too much work. Also found another, related bug with map labels that I fixed at the same time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant