GliderPRO/Sources/SavedGames.c

1 line
9.0 KiB
C
Raw Normal View History

//============================================================================ //---------------------------------------------------------------------------- // SavedGames.c //---------------------------------------------------------------------------- //============================================================================ #include <StringCompare.h> #include "Externs.h" #include "House.h" #define kSavedGameVersion 0x0200 void SavedGameMismatchError (StringPtr); gameType smallGame; extern FSSpecPtr theHousesSpecs; extern short numStarsRemaining, thisHouseIndex; extern Boolean twoPlayerGame; //============================================================== Functions //-------------------------------------------------------------- SaveGame2 void SaveGame2 (void) { // Add NavServices later. /* StandardFileReply theReply; FSSpec tempSpec; Str255 gameNameStr; Size byteCount; OSErr theErr; houseType *thisHousePtr; roomType *srcRoom; savedRoom *destRoom; gamePtr savedGame; short r, i, numRooms, gameRefNum; char wasState; FlushEvents(everyEvent, 0); wasState = HGetState((Handle)thisHouse); HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; HSetState((Handle)thisHouse, wasState); byteCount = sizeof(game2Type) + sizeof(savedRoom) * numRooms; savedGame = (gamePtr)NewPtr(byteCount); if (savedGame == nil) { YellowAlert(kYellowFailedSaveGame, MemError()); return; } GetFirstWordOfString(thisHouseName, gameNameStr); if (gameNameStr[0] > 23) gameNameStr[0] = 23; PasStringConcat(gameNameStr, "\p Game"); StandardPutFile("\pSave Game As:", gameNameStr, &theReply); if (!theReply.sfGood) return; if (theReply.sfReplacing) { theErr = FSMakeFSSpec(theReply.sfFile.vRefNum, theReply.sfFile.parID, theReply.sfFile.name, &tempSpec); if (!CheckFileError(theErr, "\pSaved Game")) return; theErr = FSpDelete(&tempSpec); if (!CheckFileError(theErr, "\pSaved Game")) return; } wasState = HGetState((Handle)thisHouse); HLock((Handle)thisHouse); thisHousePtr = *thisHouse; savedGame->house = theHousesSpecs[thisHouseIndex]; savedGame->version = kSavedGameVersion; savedGame->wasStarsLeft = numStarsRemaining; savedGame->timeStamp = thisHousePtr->timeStamp; savedGame->where.h = theGlider.dest.left; savedGame->where.v = theGlider.dest.top; savedGame->score = theScore; savedGame->unusedLong = 0L; savedGame->unusedLong2 = 0L; savedGame->energy = batteryTotal; savedGame->bands = bandsTotal; savedGame->roomNumber = thisRoomNumber; savedGame->gliderState = theGlider.mode; savedGame->numGliders = mortals; savedGame->foil = foilTotal; savedGame->nRooms = numRooms; savedGame->facing = theGlider.facing; savedGame->showFoil = showFoil; for (r = 0; r < numRooms; r++) { destRoom = &(savedGame->savedData[r]); srcRoom = &(thisHousePtr->rooms[r]); destRoom->unusedShort = 0; destRoom->unusedByte = 0; destRoom->visited = srcRoom->visited; for (i = 0; i < kMaxRoomObs; i++) destRoom->objects[i] = srcRoom->objects[i]; } HSetState((Handle)thisHouse, wasState); theErr = FSpCreate(&theReply.sfFile, 'ozm5', 'gliG', theReply.sfScript); if (CheckFileError(theErr, "\pSaved Game")) { theErr = FSpOpenDF(&theReply.sfFile, fsCurPerm, &gameRefNum); if (CheckFileError(theErr, "\pSaved Game")) { theErr = SetFPos(gameRefNum, fsFromStart, 0L); if (CheckFileError(theErr, "\pSaved Game")) { theErr = FSWrite(gameRefNum, &byteCount, (Ptr)savedGame); if (CheckFileError(theErr, "\pSaved Game")) { theErr = SetEOF(gameRefNum, byteCount); if (CheckFileError(theErr, "\pSaved Game")) { } } } theErr = FSClose(gameRefNum); if (CheckFileError(theErr, "\pSaved Game")) { } } } DisposePtr((Ptr)savedGame); */ } //-------------------------------------------------------------- SavedGameMismatchError void SavedGameMismatchError (StringPtr gameName) { #define kSavedGameErrorAlert 1044 short whoCares; InitCursor(); //