0

I've been working on a libtcod/C++ roguelike, and I've run into a small problem.

When the player goes between floors, the items from the previous floor stay on the new map, ending up in the walls, and each time I go between floors, more items generate until the map is swamped.

Is there any way to save a particular floor (perhaps with the seed) so that the actors' current x/y is preserved for reloading later?

  • How are you storing the map and its contents? – PomfCaster May 15 '14 at 04:43
  • Right now, it's just placing the items according to the PRNG, and then deleting them when the player goes down a level. I've tried storing them in my map->save (which keeps the map's FOV), but I get a dozen errors that I can't fix. – Graham Fielding May 15 '14 at 04:46

1 Answers1

1

Create a Map class which stores the map details (walls, stairs, etc), items on the floor and any monsters. Then you can create an std::map<int, Map> with the key being the floor number.

Then whenever you change floors you check the std::map to see if the Map object for that floor exists, if it does load it, if not create a new Map.

PomfCaster
  • 812
  • 1
  • 7
  • 12
  • Since I aleady have a Tile struct that uses a bool to store which tiles on the map have been explored, could I add a withActors bool to check which tiles have actors on them? – Graham Fielding May 15 '14 at 05:12
  • You could, but I can't really see why you would want to store that in the `Tile` structure. – PomfCaster May 15 '14 at 05:17
  • Well, the BSP functoion that generates the map does so by creating the map, then checking whether or not isExplored is true; I was thinking I could do the same for the actors (construct the map, then check if any of the actors have changed position). – Graham Fielding May 15 '14 at 05:25
  • I still don't understand what you're trying to achieve in doing that. Why does a tile need to know if it has an actor standing on it? – PomfCaster May 15 '14 at 05:28
  • Each tile has a flag for 'explored' and a tile for 'blocks sight'. By checking if a tile has an actor standing on it, I could tell the map generator whether to load new actors or just re-place the existing ones....(I might be way off on that...) :) – Graham Fielding May 15 '14 at 05:31
  • Are you talking about for when changing floors? Don't you want to be keeping track of actors on the previous floor in case you go back to it? Or are you going to just generate a new set of actors? – PomfCaster May 15 '14 at 05:35
  • Yes, actually...I'm getting a bit sidetracked :) I want to track actors on previous floors, but the major problem is the items from the previous floor getting stuck in the walls. – Graham Fielding May 15 '14 at 05:48
  • Simple solution would be to just remove every item when you're changing floors. If you want to keep track of them then store the items in a `vector` or something, then when going back to that floor read though the `vector` and put the items back where they originally were. – PomfCaster May 15 '14 at 05:56