i spent the whole night trying to understand the db* stuff and then set myself to add my first property.
since drod quest is to be a sort of rpg, game events (like stabbing a roach, or getting stabbed) have random behaviour. so the savegame mechanism needed to be updated as when reproducing the game commands, the random numbers generated would be diferent than the originals. after long consideration i found a solution wich would require minimum coding: all i had to do was write a CRandom class wich provided two methods: one to obtain a random number for game-events, and another for everything else. by keeping track of how many game-event random numbers were asked since last seeded, when it detects that a non-game-event rand has been asked it just re-seeds the random number generator and calls rand() the exact number of times.
using this, i srand(time) every time the swordsman enters a room and all i have to keep in the savegame is the seed of the last room visited.
however i'm still having trouble with the db. heres exactely what i did:
in DBProps.h
DEFPROP(c4_IntProp, StartRoomSeed);
DEFTDEF(SAVEDGAMES_VIEWDEF,
"SavedGames"
"["
"SavedGameID:I,"
"PlayerID:I,"
"LastUpdated:I,"
"StartRoomSeed:I," // here
"StartRoomX:I,"
"StartRoomY:I,"
...
enum PROPTYPE
{
...
P_StartRoomO,
P_StartRoomSeed,
P_StartRoomX,
...
};
const char propTypeStr[P_Count][26] = {
...
"Settings", "ShowSequenceNo", "Squares", "StartRoomO", "StartRoomSeed", "StartRoomX",
...
};
in CDbSavedGame::Load()
this->wStartRoomSeed = (UINT) p_StartRoomSeed( SavedGamesView[dwSavedGameI] );
in CDbSavedGame::SetProperty()
case P_StartRoomSeed:
this->wStartRoomSeed = static_cast<UINT>(atoi(str));
break;
in CDbSavedGame::UpdateNew()
SavedGamesView.Add(
...
p_LastUpdated[ this->LastUpdated ] +
p_StartRoomSeed[ this->wStartRoomSeed ] +
p_StartRoomX[ this->wStartRoomX ] +
...);
and in CDbSavedGame::UpdateExisting()
p_StartRoomSeed( SavedGamesView[ dwSavedGameI ] ) = this->wStartRoomSeed;
i verified that wStartRoomSeed is being stored correctely
in UpdateExisting() because i get the right value if do a
UINT i = p_StartRoomSeed(SavedGamesView[dwSavedGameI]);
however if i close and restart Load() gives me a 0. any ideas? am i missing something?
____________________________
Marvin
"
The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
- Douglas Adams, The Hitchhikers Guide to the Galaxy