void CA_CacheMap(int mapnum) { long pos,compressed; int plane; byte *source; memptr buffer2seg; long expanded; mapon = mapnum; /* load the planes into the already allocated buffers */ for (plane = 0; plane < MAPPLANES; plane++) { pos = mapheaderseg[mapnum]->planestart[plane]; compressed = mapheaderseg[mapnum]->planelength[plane]; ReadSeek(maphandle, pos, SEEK_SET); MM_GetPtr((void *)&source, compressed); ReadBytes(maphandle, (byte *)source, compressed); expanded = source[0] | (source[1] << 8); MM_GetPtr(&buffer2seg, expanded); /* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map would (likely) need to be swapped in CA_RLEWexpand Wolfenstein 3D/Spear of Destiny maps are always Carmack'd so this case is OK. CA_RLEWexpand would need to be adjusted for Blake Stone and the like. */ CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded); MM_FreePtr((void *)&source); expanded = 64*64*2; CA_RLEWexpand(((word *)buffer2seg)+1, mapsegs[plane], expanded, RLEWtag); MM_FreePtr(&buffer2seg); } }
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); }