CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.65k stars 4.18k forks source link

Loot zones disapear after reaching new Z-level #49309

Open schauveau opened 3 years ago

schauveau commented 3 years ago

I am using the Debian package 0.E so not quite up to date. The bug may already be solved but I could not find any related bug report.

For a long time, my loot zones were disappearing in a rare but unpredictable manner. Fortunately, they can be restored by saving and reloading. I now believe that the problem is quite reproducible by reaching a new Z-level.

For example, I am currently playing a Lab Escape below a research facility. I was lucky to spawn near the lab exit so I setup my loot areas in the guard room. Then I climb the stairs to reach the roof and when I come back to the guard room, my loot zones are gone. I suspect that they are now at a wrong level but that needs to be verified. I save and reload the game to restore the loot areas. Then I start exploring down until I reach z-level -3 for the first time and when I come back my loot areas are gone again.

Versions and configuration

schauveau commented 3 years ago

I started another Lab game today and that did not happen so this is not systematic. I still think that this is related to reaching a new z-level but there is probably one or more additional factors to consider.

OliveChukar commented 3 years ago

Tested on (cdda-windows-tiles-x64-2021-06-20-0737) with no mods core content pack only. Setup an unsorted loot zone and a custom zone with no limitations on the ground floor of a hospital then climbed to the roof and back down. the zones were still there. Going to the basement also did not remove the zones.

You can check the z level thing by using the show all zones command in the zone menu.

schauveau commented 3 years ago

As I wrote I my second comment, the bug does not always happen. However, I was just able to reproduce it from a brand new Lab game by doing pretty much nothing. I did not take note of al my steps but that basically went like that:

  1. explore. I find stairs going down.
  2. Create two zones (Unsorted and Clothing)
  3. Go down
  4. Open Zone menu and "Show all zones" : They are both listed UP_NE
  5. Go up
  6. Open Zone menu and "Show all zones" : They are both listed NE
  7. Go down
  8. Explore until I find other stairs going down
  9. Go down
  10. Explore a few rooms. I forgot to check the Zone menu. Sorry!
  11. Go back to my loot area
  12. Open Zone menu: both zones are now gone
  13. Toggle "Show all zones" : They are listed at 10 UP_NE and 9 UP_NE
  14. Save and Reload game
  15. Open Zone menu: both zones are back at 3 NE and 2 NE

Interestingly, the distance was wrong both vertically and horizontally (e.g. 10 UP_NE vs 3 NE)

I will try to reproduce it while recording the screen.

schauveau commented 3 years ago

Here it is https://www.youtube.com/watch?v=SmIs-E5IZQw

At 1:23, the zones are duplicated with crazy distances when I list them at level -1 and they are gone when I reach the initial level.

And in case that is not obvious, the zones are not gone (yet) at 1:13. I was a bit confused and I forgot to enable "Show All" so I had to reopen the Zone menu a few seconds later.

schauveau commented 3 years ago

I wonder if leaving the room at 1:05 could be important (because that would cause the whole map to be resized).

schauveau commented 3 years ago

I just figured out that the zones with crazy distances are from my previous game which is strange because my option "World End Handling" is set to "Reset". Could it bethat an incorrect reset of the Zones is causing the problem?

schauveau commented 3 years ago

Yeah! There is definitely a problem with the Zones when a game is finished and a new one is immediately restarted without closing the cdda program. The old zones still appear when using "Show all". That also happens if the world is physically destroyed between the two games.

schauveau commented 3 years ago

Steps to reproduce:

  1. Start cdda.exe
  2. Create new world and new game
  3. Create one or more Zones
  4. Suicide
  5. Destroy world
  6. Create new world and new game
  7. Open Zone menu and use "Show all" : The zones from the previous game are still there
  8. Save and Reload : the 'old' zones are still there
  9. Save game
  10. Quit and restart cdda
  11. Load the saved game: the 'old' zones are gone
schauveau commented 3 years ago

I browsed through the code and the problem described in my last two comments is because the static zone_manager is neither cleared after quitting a game nor when creating a new game. However, it is cleared by zone_manager::deserialize() while loading the save file.

For a quick and dirty verification, I added zone_manager::get_manager() = zone_manager(); in game::cleanup_at_end() and that seems to solve the problem. zone_manager is quite complex, so I cannot say for sure that this is not introducing other problems. A proper 'clear()' member would be better.

anothersimulacrum commented 3 years ago

Clearing it in DynamicDataLoader::unload_data seems like the solution here.

schauveau commented 3 years ago

Indeed! I will create a zone_manager::reset() and submit a pull request.