static id0_boolean_t LoadGameState(BE_FILE_T file, gametype *state) { return ((BE_Cross_readInt16LE(file, &state->difficulty) == 2) && (BE_Cross_readInt16LE(file, &state->mapon) == 2) && (BE_Cross_readInt16LE(file, &state->bolts) == 2) && (BE_Cross_readInt16LE(file, &state->nukes) == 2) && (BE_Cross_readInt16LE(file, &state->potions) == 2) && (BE_Cross_readInt16LEBuffer(file, state->keys, sizeof(state->keys)) == sizeof(state->keys)) && (BE_Cross_readInt16LEBuffer(file, state->scrolls, sizeof(state->scrolls)) == sizeof(state->scrolls)) && (BE_Cross_readInt32LE(file, &state->score) == 4) && (BE_Cross_readInt16LE(file, &state->body) == 2) && (BE_Cross_readInt16LE(file, &state->shotpower) == 2) ); }
id0_boolean_t LoadTheGame(BE_FILE_T file) { id0_unsigned_t i,x,y; objtype /**obj,*/*prev,*next,*followed; id0_unsigned_t compressed,expanded; id0_unsigned_t id0_far *map,tile; memptr bigbuffer; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); SetupGameLevel (); // load in and cache the base old level expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Read planes 0 and 2 { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],expanded,RLETAG); } MM_FreePtr (&bigbuffer); // // copy the wall data to a data segment array again, to handle doors and // bomb walls that are allready opened // memset (tilemap,0,sizeof(tilemap)); memset (actorat,0,sizeof(actorat)); map = mapsegs[0]; for (y=0;y<mapheight;y++) for (x=0;x<mapwidth;x++) { tile = *map++; if (tile<NUMFLOORS) { tilemap[x][y] = tile; if (tile>0) actorat[x][y] = tile; //(id0_unsigned_t)actorat[x][y] = tile; } } // Read the object list back in - assumes at least one object in list InitObjList (); newobj = player; while (true) { prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; actorat[newobj->tilex][newobj->tiley] = COMPAT_OBJ_CONVERT_OBJ_PTR_TO_DOS_PTR(newobj); // drop a new marker //actorat[newobj->tilex][newobj->tiley] = newobj; // drop a new marker if (followed) GetNewObj (false); else break; } return(true); }
id0_boolean_t LoadGame(BE_FILE_T file) { id0_word_t i/*,j,size*/; //objtype *o; //id0_int_t orgx,orgy; objtype *prev,*next,*followed; id0_unsigned_t compressed,expanded; memptr bigbuffer; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); // drop down a cache level and mark everything, so when the option screen // is exited it will be cached ca_levelbit >>= 1; ca_levelnum--; SetupGameLevel (false); // load in and cache the base old level titleptr[ca_levelnum] = levelnames[mapon]; ca_levelbit <<= 1; ca_levelnum ++; expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i++) // Read all three planes of the map { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],compressed,RLETAG); } MM_FreePtr (&bigbuffer); // Read the object list back in - assumes at least one object in list InitObjArray (); newobj = player; prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); newobj->prev = prev; newobj->next = next; newobj->needtoreact = true; newobj->sprite = NULL; newobj = scoreobj; while (true) { prev = newobj->prev; next = newobj->next; // And again if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; newobj->needtoreact = true; newobj->sprite = NULL; if (followed) GetNewObj (false); else break; } scoreobj->temp1 = scoreobj->temp2 = -1; // force score to be updated scoreobj->temp3 = -1; // and flower power scoreobj->temp4 = -1; // and lives #if 0 *((id0_long_t *)&(scoreobj->temp1)) = -1; // force score to be updated scoreobj->temp3 = -1; // and flower power scoreobj->temp4 = -1; // and lives #endif return(true); }
id0_boolean_t LoadTheGame(BE_FILE_T file) { id0_unsigned_t i,x,y; objtype /**obj,*/*prev,*next,*followed; id0_unsigned_t compressed,expanded; id0_unsigned_t id0_far *map,tile; memptr bigbuffer; screenpage = 0; FreeUpMemory(); playstate = ex_loadedgame; // load the sky and ground colors // REFKEEN - But not before converting from original 16-bit pointers (reusing i variable) if (BE_Cross_readInt16LE(file, &i) != 2) //if (!CA_FarRead(file,(void id0_far *)&skycolor,sizeof(skycolor))) return(false); skycolor = GetSkyGndColorPtrFromDOSPointer(i); if (BE_Cross_readInt16LE(file, &i) != 2) //if (!CA_FarRead(file,(void id0_far *)&groundcolor,sizeof(groundcolor))) return(false); groundcolor = GetSkyGndColorPtrFromDOSPointer(i); if (BE_Cross_readInt16LE(file, &FreezeTime) != 2) //if (!CA_FarRead(file,(void id0_far *)&FreezeTime,sizeof(FreezeTime))) return(false); // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); if (BE_Cross_read_boolean_From16LE(file, &EASYMODEON) != 2) //if (!CA_FarRead(file,(void id0_far *)&EASYMODEON,sizeof(EASYMODEON))) return(false); SetupGameLevel (); // load in and cache the base old level // (REFKEEN) DIFFERENCE FROM VANILLA CATACOMB ADVENTURES: // Don't do this check, we've already opened the file anyway // and this can lead to unexpected behaviors! #if 0 if (!FindRewritableFile(Filename,"SAVE GAME",-1)) Quit("Error: Can't find saved game file!"); #endif expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Read planes 0 and 2 { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],expanded,RLETAG); } MM_FreePtr (&bigbuffer); // // copy the wall data to a data segment array again, to handle doors and // bomb walls that are allready opened // memset (tilemap,0,sizeof(tilemap)); memset (actorat,0,sizeof(actorat)); map = mapsegs[0]; for (y=0;y<mapheight;y++) for (x=0;x<mapwidth;x++) { tile = *map++; if (tile<NUMFLOORS) { if (tile != INVISIBLEWALL) tilemap[x][y] = tile; if (tile>0) actorat[x][y] = tile; //(id0_unsigned_t)actorat[x][y] = tile; } } // Read the object list back in - assumes at least one object in list InitObjList (); newobj = player; while (true) { prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; actorat[newobj->tilex][newobj->tiley] = COMPAT_OBJ_CONVERT_OBJ_PTR_TO_DOS_PTR(newobj); // drop a new marker //actorat[newobj->tilex][newobj->tiley] = newobj; // drop a new marker if (followed) GetNewObj (false); else break; } return(true); }