/* calculate table to translate d1 bitmaps to current palette, * return -1 on error */ CPalette* CPaletteManager::LoadD1 (void) { CPalette palette; CFile cf; if (!cf.Open (D1_PALETTE, gameFolders.szDataDir, "rb", 1) || (cf.Length () != 9472)) return NULL; palette.Read (cf); cf.Close (); palette.Raw () [254] = SUPER_TRANSP_COLOR; palette.Raw () [255] = TRANSPARENCY_COLOR; SetD1 (Add (palette)); return D1 (); }
CPalette *CPaletteManager::Load (const char *pszFile, const char *pszLevel) { CFile cf; int i = 0, fsize; CPalette palette; #ifdef SWAP_0_255 ubyte c; #endif if (pszLevel) { char ifile_name [FILENAME_LEN]; CFile::ChangeFilenameExtension (ifile_name, pszLevel, ".pal"); i = cf.Open (ifile_name, gameFolders.szDataDir, "rb", 0); } if (!i) i = cf.Open (pszFile, gameFolders.szDataDir, "rb", 0); // the following is a hack to enable the loading of d2 levels // even if only the d2 mac shareware datafiles are present. // However, if the pig file is present but the palette file isn't, // the textures in the level will look wierd... if (!i) i = cf.Open (DEFAULT_LEVEL_PALETTE, gameFolders.szDataDir, "rb", 0); if (!i) { Error(TXT_PAL_FILES, pszFile, DEFAULT_LEVEL_PALETTE); return NULL; } fsize = cf.Length (); Assert (fsize == 9472); palette.Read (cf); cf.Read (m_data.fadeTable, sizeof (m_data.fadeTable), 1); cf.Close (); // This is the TRANSPARENCY COLOR for (i = 0; i < MAX_FADE_LEVELS; i++) m_data.fadeTable [i * 256 + 255] = 255; // swap colors 0 and 255 of the palette along with fade table entries #ifdef SWAP_0_255 palette.SwapTransparency (); for (i = 0; i < MAX_FADE_LEVELS * 256; i++) if (m_fadeTable [i] == 0) m_fadeTable [i] = 255; for (i = 0; i < MAX_FADE_LEVELS; i++) m_fadeTable [i * 256] = TRANSPARENCY_COLOR; #endif ClearEffect (&palette); return Add (palette); }