// Loads the map into the memory bool CMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool loadNewMusic, bool stategame ) { std::string levelname = "level"; if(level < 10) levelname += "0"; levelname += itoa(level) + ".ck" + itoa(episode); mp_map->resetScrolls(); mp_map->m_gamepath = path; mp_map->m_worldmap = (level == 80); // HQ Music. Load Music for a level if you have HQP if(loadNewMusic) { g_pMusicPlayer->stop(); // If no music from the songlist could be loaded try the normal table which // has another format. It is part of HQP if(!g_pMusicPlayer->LoadfromSonglist(path, level)) g_pMusicPlayer->LoadfromMusicTable(path, levelname); } // decompress map RLEW data std::ifstream MapFile; bool fileopen = OpenGameFileR(MapFile, getResourceFilename(levelname,path,true,false), std::ios::binary); if (!fileopen) { // only record this error message on build platforms that log errors // to a file and not to the screen. g_pLogFile->ftextOut("MapLoader: unable to open file %s<br>", levelname.c_str()); return 0; } g_pLogFile->ftextOut("MapLoader: file %s opened. Loading...<br>", levelname.c_str()); MapFile.seekg (0, std::ios::beg); // load the compressed data into the memory std::vector<Uint8> compdata; while( !MapFile.eof() ) { compdata.push_back(static_cast<Uint8>(MapFile.get())); } MapFile.close(); CRLE RLE; std::vector<Uint16> planeitems; RLE.expandSwapped(planeitems,compdata, 0xFEFE); // Here goes the memory allocation function mp_map->createEmptyDataPlane(1, planeitems.at(1), planeitems.at(2)); int t; unsigned int planesize = 0; unsigned int curmapx=0, curmapy=0; planesize = planeitems.at(8); planesize /= 2; // Size of two planes, but we only need one const char &fixlevel_error = g_pBehaviorEngine->m_option[OPT_FIXLEVELERRORS].value; Uint32 c; for( c=17 ; c<planesize+17 ; c++ ) // Check against Tilesize { t = planeitems.at(c); if( fixlevel_error ) fixLevelTiles(t, curmapx, curmapy, episode, level); addTile(t, curmapx, curmapy); curmapx++; if (curmapx >= mp_map->m_width) { curmapx = 0; curmapy++; if (curmapy >= mp_map->m_height) break; } if(t > 255) t=0; // If there are some invalid values in the file } // now do the sprites // get sprite data int resetcnt, resetpt; curmapx = curmapy = 0; resetcnt = resetpt = 0; if(mp_objvect && stategame == false) { std::vector<CObject*>::iterator obj = mp_objvect->begin(); for( ; obj != mp_objvect->end() ; obj++ ) { delete *obj; mp_objvect->pop_back(); } mp_objvect->reserve(2000); for( c=planesize+17 ; c<2*planesize+16 ; c++ ) { // in case the planesizes are bigger than the actual file content itself if(planeitems.size() <= c) break; t = planeitems.at(c); if (mp_map->m_worldmap) addWorldMapObject(t, curmapx, curmapy, episode ); else addEnemyObject(t, curmapx, curmapy, episode, level); curmapx++; if (curmapx >= mp_map->m_width) { curmapx = 0; curmapy++; if (curmapy >= mp_map->m_height) break; } if (++resetcnt==resetpt) curmapx = curmapy = 0; } } planeitems.clear(); // Do some post calculations // Limit the scroll screens so the blocking (blue in EP1) tiles are3 never seen SDL_Rect gamerect = g_pVideoDriver->getGameResolution(); mp_map->m_maxscrollx = (mp_map->m_width<<4) - gamerect.w - 32; mp_map->m_maxscrolly = (mp_map->m_height<<4) - gamerect.h - 32; // Set Scrollbuffer g_pVideoDriver->setScrollBuffer(&mp_map->m_scrollx_buf, &mp_map->m_scrolly_buf); return true; }
bool CVorticonMapLoaderBase::loadBase( Uint8 episode, Uint8 level, const std::string& path, bool loadNewMusic ) { std::vector<Uint16> planeitems; std::string levelname = "level"; if(level < 10) levelname += "0"; levelname += itoa(level) + ".ck" + itoa(episode); mpMap->resetScrolls(); mpMap->m_gamepath = path; mpMap->m_worldmap = (level == 80); // HQ Music. Load Music for a level if you have HQP if(loadNewMusic) { gMusicPlayer.stop(); // If no music from the songlist could be loaded try the normal table which // has another format. It is part of HQP if(!gMusicPlayer.LoadfromSonglist(path, level)) gMusicPlayer.LoadfromMusicTable(path, levelname); } // decompress map RLEW data std::ifstream MapFile; bool fileopen = OpenGameFileR(MapFile, getResourceFilename(levelname,path,true,false), std::ios::binary); if (!fileopen) { // only record this error message on build platforms that log errors // to a file and not to the screen. gLogging.ftextOut("MapLoader: unable to open file %s<br>", levelname.c_str()); return false; } gLogging.ftextOut("MapLoader: file %s opened. Loading...<br>", levelname.c_str()); MapFile.seekg (0, std::ios::beg); // load the compressed data into the memory std::vector<Uint8> compdata; while( !MapFile.eof() ) { compdata.push_back(static_cast<Uint8>(MapFile.get())); } MapFile.close(); CRLE RLE; RLE.expandSwapped(planeitems, compdata, 0xFEFE); // Here goes the memory allocation function const Uint16 w = planeitems.at(1); const Uint16 h = planeitems.at(2); mpMap->setupEmptyDataPlanes(3, w, h); unsigned int planesize = 0; planesize = planeitems.at(8); planesize /= 2; // We have two planes blitPlaneToMap( planeitems, planesize, 0, 0); blitPlaneToMap( planeitems, planesize, 0, 1); blitPlaneToMap( planeitems, planesize, 1, 2); mpMap->collectBlockersCoordiantes(); mpMap->setupAnimationTimer(); return true; }