bool P_LoadBuildMap (BYTE *data, size_t len, FMapThing **sprites, int *numspr) { if (len < 26) { return false; } // Check for a Blood map. if (*(DWORD *)data == MAKE_ID('B','L','M','\x1a')) { return P_LoadBloodMap (data, len, sprites, numspr); } const int numsec = LittleShort(*(WORD *)(data + 20)); int numwalls; int numsprites; if (len < 26 + numsec*sizeof(sectortype) || (numwalls = LittleShort(*(WORD *)(data + 22 + numsec*sizeof(sectortype))), len < 24 + numsec*sizeof(sectortype) + numwalls*sizeof(walltype)) || LittleLong(*(DWORD *)data) != 7 || LittleShort(*(WORD *)(data + 16)) >= 2048) { // Can't possibly be a version 7 BUILD map return false; } numsectors = numsec; LoadSectors ((sectortype *)(data + 22)); LoadWalls ((walltype *)(data + 24 + numsectors*sizeof(sectortype)), numwalls, (sectortype *)(data + 22)); numsprites = *(WORD *)(data + 24 + numsectors*sizeof(sectortype) + numwalls*sizeof(walltype)); *sprites = new FMapThing[numsprites + 1]; CreateStartSpot ((fixed_t *)(data + 4), *sprites); *numspr = 1 + LoadSprites ((spritetype *)(data + 26 + numsectors*sizeof(sectortype) + numwalls*sizeof(walltype)), NULL, numsprites, (sectortype *)(data + 22), *sprites + 1); return true; }
static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **mapthings, int *numspr) { BYTE infoBlock[37]; int mapver = data[5]; DWORD matt; int numRevisions, numWalls, numsprites, skyLen, visibility, parallaxType; int i; int k; if (mapver != 6 && mapver != 7) { return false; } matt = *(DWORD *)(data + 28); if (matt != 0 && matt != MAKE_ID('M','a','t','t') && matt != MAKE_ID('t','t','a','M')) { Decrypt (infoBlock, data + 6, 37, 0x7474614d); } else { memcpy (infoBlock, data + 6, 37); } skyLen = 2 << LittleShort(*(WORD *)(infoBlock + 16)); visibility = LittleLong(*(DWORD *)(infoBlock + 18)); parallaxType = infoBlock[26]; numRevisions = LittleLong(*(DWORD *)(infoBlock + 27)); numsectors = LittleShort(*(WORD *)(infoBlock + 31)); numWalls = LittleShort(*(WORD *)(infoBlock + 33)); numsprites = LittleShort(*(WORD *)(infoBlock + 35)); Printf("Visibility: %d\n", visibility); if (mapver == 7) { // Version 7 has some extra stuff after the info block. This // includes a copyright, and I have no idea what the rest of // it is. data += 171; } else { data += 43; } // Skip the sky info. data += skyLen; sectortype *bsec = new sectortype[numsectors]; walltype *bwal = new walltype[numWalls]; spritetype *bspr = new spritetype[numsprites]; Xsprite *xspr = new Xsprite[numsprites]; // Read sectors k = numRevisions * sizeof(sectortype); for (i = 0; i < numsectors; ++i) { if (mapver == 7) { Decrypt (&bsec[i], data, sizeof(sectortype), k); } else { memcpy (&bsec[i], data, sizeof(sectortype)); } data += sizeof(sectortype); if (bsec[i].extra > 0) // skip Xsector { data += 60; } } // Read walls k |= 0x7474614d; for (i = 0; i < numWalls; ++i) { if (mapver == 7) { Decrypt (&bwal[i], data, sizeof(walltype), k); } else { memcpy (&bwal[i], data, sizeof(walltype)); } data += sizeof(walltype); if (bwal[i].extra > 0) // skip Xwall { data += 24; } } // Read sprites k = (numRevisions * sizeof(spritetype)) | 0x7474614d; for (i = 0; i < numsprites; ++i) { if (mapver == 7) { Decrypt (&bspr[i], data, sizeof(spritetype), k); } else { memcpy (&bspr[i], data, sizeof(spritetype)); } data += sizeof(spritetype); if (bspr[i].extra > 0) // copy Xsprite { assert(sizeof(Xsprite) == 56); memcpy(&xspr[i], data, sizeof(Xsprite)); data += sizeof(Xsprite); } else { memset(&xspr[i], 0, sizeof(Xsprite)); } } // Now convert to Doom format, since we've extracted all the standard // BUILD info from the map we need. (Sprites are ignored.) LoadSectors (bsec); LoadWalls (bwal, numWalls, bsec); *mapthings = new FMapThing[numsprites]; *numspr = LoadSprites (bspr, xspr, numsprites, bsec, *mapthings); delete[] bsec; delete[] bwal; delete[] bspr; delete[] xspr; return true; }
/* METODA WCZYTUJ¥CA DANE Za³o¿enia pliku s¹ proste. Na pocz¹tku podstawowe dane, a dalej jedziemy ze œcianami i ca³¹ reszt¹ danych. */ const bool CLevel::LoadLevel( const std::string &filename ) { if( filename == "" ) { Log.Error( "GLEVEL( " + file + " ): £añcuch znaków jest pusty!" ); return false; } // Najpierw definiujemy wskaŸnik na plik i go otwieramy std::fstream stream( filename, std::ios::in ); if( !stream ) { Log.Error( "GLEVEL( " + file + " ): Plik nie istnieje, lub podana œcie¿ka jest b³êdna: " + filename ); return false; } // definiujemy zmienne pomocnicze std::string str; // Pobieramy wersje poziomu oraz j¹ sprawdzamy str = GetClearLine( stream ); if( !sscanf_s( str.c_str(), "E3DTLEV=%u", &Version ) ) { Log.Error( "GLEVEL( " + file + " ): Nieprawid³owy plik poziomu!" ); return false; } if( Version > GAME_VERSION ) { Log.Error( "GLEVEL( " + file + " ): Zbyt wysoka wersja pliku!" ); return false; } /* Wczeœnijsze if'y by³y, by uzyskaæ pewnoœæ, ¿e wszystko z nowym plikiem jest w porz¹dku. Dlaczego tyle zachodu? By unikn¹æ sytuacji, kiedy ³adujemy plik, na ju¿ istniej¹cy level. Level istnieje, wiêc go kasujemy i czytamy plik. A teraz Zonk! Nie ma pliku! I co? zostajemy na lodzie bez levelu :). Teraz wiecie o co chodzi :) */ if( loaded ) { Log.Report( "GLEVEL( " + file + " ): Prze³adowanie poziomu na : " + filename ); Free(); Player.Reset(); } Log.Log( "GLEVEL( " + file + " ): Wczytywanie poziomu: " + filename ); //GUI.SendConMsg( "Wczytywanie poziomu: " + filename, false ); file = filename; while( stream ) { str = GetLine( stream ); if( str == "END E3DTLEV" ) break; str = ClearWhiteSpace( str ); if( str == "HEADER" ) { if( !LoadHeader( stream ) ) { Log.Error( "GLEVEL( " + file + " ): B³¹d odczytu nag³ówka!" ); continue; } } else if( str == "TEXTURES" ) { if( !LoadTextures( stream ) ) { Log.Error( "GLEVEL( " + file + " ): B³¹d odczytu tekstur!" ); continue; } } else if( str == "WALLS" ) { if( !LoadWalls( stream ) ) { Log.Error( "GLEVEL( " + file + " ): B³¹d odczytu œcian!" ); continue; } } else if( str == "ITEMLIST" ) { if( !LoadItemList( stream ) ) { Log.Error( "GLEVEL( " + file + " ): B³¹d odczytu listy przedmiotów!" ); continue; } } else Log.Error( "GLEVEL( " + file + " ): Nierozpoznany ci¹g " + str + "!" ); } for( unsigned row = 0; row < Rows; row++ ) { for( unsigned col = 0; col < Cols; col++ ) GetBlock( col, row )->Set( row, col, blockWidth, blockHeight, blockDepth ); } Player.SetStartPos( this->GetBlockPos( PlayerStartBlock ) ); Player.SetStartAngle( (float)PlayerStartAngle ); Player.Reset(); this->AddEntity( &Player ); loaded = true; BuildVisual(); BuildPhysic(); return true; }
Bool BSPRooFileLoad(char *fname, room_type *room) { int i, temp; BYTE byte; WORD num_nodes, num_walls, num_sectors, num_sidedefs; int node_pos, wall_pos, sidedef_pos, sector_pos, offset_adjust; file_node f; if (!MappedFileOpenCopy(fname, &f)) return False; // Check magic number and version for (i = 0; i < 4; i++) if (CliMappedFileRead(&f, &byte, 1) != 1 || byte != room_magic[i]) { MappedFileClose(&f); debug(("%s is not a roo file\n", fname)); return False; } security = 0; if (CliMappedFileRead(&f, &room_version, 4) != 4 || room_version < ROO_VERSION) { MappedFileClose(&f); debug(("Bad roo version %d; expecting %d\n", room_version, ROO_VERSION)); return False; } security += room_version; if (CliMappedFileRead(&f, &room->security, 4) != 4) { MappedFileClose(&f); return False; } // Read pointer to main info in file, and go there if (CliMappedFileRead(&f, &temp, 4) != 4) { MappedFileClose(&f); return False; } MappedFileGoto(&f, temp); // Read size of room if (CliMappedFileRead(&f, &room->width, 4) != 4) { MappedFileClose(&f); return False; } offset_adjust = 0; room->cols = room->width >> LOG_FINENESS; if (CliMappedFileRead(&f, &room->height, 4) != 4) { MappedFileClose(&f); return False; } room->rows = room->height >> LOG_FINENESS; // Read pointers to file sections if (CliMappedFileRead(&f, &node_pos, 4) != 4) { MappedFileClose(&f); return False; } if (CliMappedFileRead(&f, &wall_pos, 4) != 4) { MappedFileClose(&f); return False; } if (CliMappedFileRead(&f, &temp, 4) != 4) { MappedFileClose(&f); return False; } if (CliMappedFileRead(&f, &sidedef_pos, 4) != 4) { MappedFileClose(&f); return False; } if (CliMappedFileRead(&f, §or_pos, 4) != 4) { MappedFileClose(&f); return False; } node_pos += offset_adjust; wall_pos += offset_adjust; sidedef_pos += offset_adjust; sector_pos += offset_adjust; // Read nodes MappedFileGoto(&f, node_pos); if (CliMappedFileRead(&f, &num_nodes, 2) != 2) { MappedFileClose(&f); return False; } if (LoadNodes(&f, room, num_nodes) == False) { debug(("Failure loading %d nodes\n", num_nodes)); MappedFileClose(&f); return False; } // Read walls MappedFileGoto(&f, wall_pos); if (CliMappedFileRead(&f, &num_walls, 2) != 2) { MappedFileClose(&f); return False; } if (LoadWalls(&f, room, num_walls) == False) { debug(("Failure loading %d walls\n", num_walls)); MappedFileClose(&f); return False; } // Read sidedefs MappedFileGoto(&f, sidedef_pos); if (CliMappedFileRead(&f, &num_sidedefs, 2) != 2) { MappedFileClose(&f); return False; } if (LoadSidedefs(&f, room, num_sidedefs) == False) { debug(("Failure loading %d sidedefs\n", num_sidedefs)); MappedFileClose(&f); return False; } // Read sectors MappedFileGoto(&f, sector_pos); if (CliMappedFileRead(&f, &num_sectors, 2) != 2) { MappedFileClose(&f); return False; } if (LoadSectors(&f, room, num_sectors) == False) { debug(("Failure loading %d sectors\n", num_sectors)); MappedFileClose(&f); return False; } MappedFileClose(&f); if (num_nodes == 0) { debug(("LoadRoom found room with no nodes!\n")); room->tree = NULL; } else room->tree = &room->nodes[0]; if (RoomSwizzle(room, room->tree, num_nodes, num_walls, num_sidedefs, num_sectors) == False) { debug(("RoomSwizzle failed\n")); BSPRoomFree(room); return False; } security ^= 0x89ab786c; if (security != room->security) { debug(("Room security mismatch (got %d, expecting %d)!\n", security, room->security)); BSPRoomFree(room); return False; } room->num_nodes = num_nodes; room->num_walls = num_walls; room->num_sectors = num_sectors; room->num_sidedefs = num_sidedefs; // BSPDumpTree(room->tree, 0); // D3DGeometryBuild(room); gD3DRedrawAll |= D3DRENDER_REDRAW_ALL; SandstormInit(); playerOldPos.x = 0; playerOldPos.y = 0; playerOldPos.z = 0; CacheReport(); return True; }