ID:152254
 
Suppose we have a typical game world, divided into /areas. Within each area there is terrain, monsters, and items. Now, terrain can be manipulated, monsters can be destroyed, and items can be claimed. However, I'd like it so that when the player leaves an /area, everything is restored to normal - terrain is restored to its original condition, monsters are revived, EXCEPT items which were claimed do not return.

And remember, these area /areas, not individual chunks of turf, so doing the SwapMaps approach might not work so well. One area could very well be a donut shape around another area.

What would be the best way to go about this?
Are you deleting the monsters that have been killed?
Is anything being "deleted"?
Otherwise, couldn't you do something with the "initial" proc?
For restoring existing objects to their original state, you can just loop through all /turf and /atom/movable, and loop through their variables, setting each variable to initial(variable), excluding special variables obviously. This is the easier part which you have probably already figured out.

As for restoring deleted objects, except for claimed items, there are several ways you could go about that. As was said by the other replier, you could avoid actually deleting them and instead only locate them in the limbo of null loc, then when you set variables to their initial values they will reappear back where they were in their original condition.

If you are deleting them, you can give the area a list that keeps track of deleted objects that are to be brought back, and you can create a repop function for areas similar to the one that is built in for the entire world. If each object has the potential of being unique, you will probably want the list to keep track of more than just a bunch of object types to create; you would need to create an assossiative list where object types are assossiated with the information that they require. Or you could create a datum to keep track of the information and just have a list of datums, and if you did go the datum route, the datum itself could have a personal repop function to make things even easier to manage, as the area/repop would only have to loop through its list and call object.repop on each element.

As for keeping track of unique information for objects that need to be recreated, you can probably make it as simple as L=object.vars.Copy(). That will even preserve object references for you, then, when it needs to be recreated, you can loop through all variables that would normally be reset to initial(variable) for still-existing objects and have a similar behavior where you set the variables to L[variable].
Here's how I had a little monster setup a while back:

Upon death, the monster was set to a null location*, added to a list, and given a timer (an integer that said how many minutes the monster was to stay put). His old location was recorded. A global timer, called when a monster was added to the list, looped though the monsters and decremented the countdown variable every minute. When the countdown was equal to or less than zero, it checked for clients in view of the monster's old location. If there was, it'd loop through another minute. Otherwise, it'd place the monster back into it's old position. When no monsters were in the list, the procedure stopped.

I assume that you know this part, considering that it seems like you're making a little system that makes mobs lifeless if no mobs with clients are located in the area, but upon the entering of an area, the monsters were awaken, and when all clients left, the monsters were "turned off."

*You can put this monster off in a location covered by the same area loop through the dead list to see who belongs to what area (which can be just as easily accomplished through a variable), you can use one list per area and just loop through that, or you can associate an area with a specific turf that you can loop through.

Anyway, that takes care of the monster system. As for the terrain, initial() might do the job. I don't know how flexible and customizable your system gets. Otherwise, you may need to record the terrain when you initialize it or whatever. I'd take a list approach, associating "[x],[y]" values in the list with a "prototype" turf.
Edit* Nothermind, it's a single player game. I would add everything htat needs to be recycled to a list, and populate it from that list (give it coordinates, etc). just gotta check to make sure there's no mobs in the area (so you don't trap anyone in).