Monday, July 12, 2010

Saving, Loading and the Complications Involved

The save/load code is proving more tedious than difficult. There's a lot of variables that need to be dealt with individually. I had to make several functions to process saved data into something the game can read. Most of that is out of the way but I need to think about how I'm going to handle the save data as a whole.

Saving every individual creature, item and tile alteration would severely inflate the size of the save file, even for a single map. Currently I'm only saving creature information but that alone puts the save file at 200k. That's not too bad but I haven't even added items to non-player creatures yet.

There's several things I can do to lower the size of the save and all of them come with a catch.

First I can setup creatures and items to load all their information from a template. This would destroy any possibility of customized creatures and items and at the very least they require a position to be saved, plus stat changes for creatures. When a map is first generated this stuff gets all their information from a template anyway and modifies it. I could just save the data that gets modified but that is still a lot of data.

Second, I can let everything reset to it's original, randomly generated state when the game is loaded. This is obviously bad for several reasons. The player will have killed off a bunch of creatures in a dungeon and collected a bunch of loot, then load the game to find themselves surrounded by those same creatures and items.

The third option and the option I plan to use is a combination of the first two, except the player will only be allowed to save between maps. Much like in JRPGs where the player can only save on the world map. The catch is...well there's several.

Creatures and items will have reset every time the map is loaded. This can be good or bad depending on the player's tastes. To extend the replay value of a map I will set the majority of creatures and items to be randomized each time. For important creatures and items like non-hostile NPCs, bosses and special items, I will tag them as persistent. Persistent objects will not be randomized when a map is loaded but I will only have to save their dead/alive/picked up status. They will use the same seed the map uses to be generated. Other objects will use a random seed.

When all is said and done I should only have to save the player character's information and a few variables from each map.

I implied earlier that changes to map tiles may be a possibility. A handful of changes wouldn't be a problem but I also have to consider the possibility of the player tearing down every wall and tree he comes across. I may allow for some maps to be completely saved to the hard drive to let the player construct a home or something. That's going to be pretty far down on the list of added features so I'll cross that bridge when I come to it. For now expect any map changes to be discarded when it's loaded again.

No comments:

Post a Comment