int packAdd(const char* packDir, int isDLC) { char* buf = malloc(sizeof(char)*2048); char* buf2= malloc(sizeof(char)*1024); char* val = malloc(sizeof(char)*1024); char* set = malloc(sizeof(char)*1024); //This block is for playlists list_t* playList=0; listItem* li=0; playListItem* pli=0; int i; //Counter FILE* f=0; packInfoType* ti = malloc(sizeof(packInfoType)); ti->lives=3; //Default 3 lives, if pack do not define another number. ti->isDLC=isDLC; //Any levels? (Packs are invalid without a levels folder and atleast one level) sprintf(buf, "%s/levels/level000.wzp", packDir); //Initialize list for playlist playList = listInit(_freePlaylistItem); //Open packs/packname/info.ini sprintf(buf, "%s/info.ini", packDir); f = android_fopen(buf, "r"); if(f) { while( fgets(buf, 128, f) ) { stripNewLine(buf); if(splitVals('=',buf,set,val)) { if(strcmp("author", set)==0) { ti->author = malloc( sizeof(char)*(strlen(val)+1+3) ); sprintf(ti->author, "By %s", val); } else if(strcmp("packname", set)==0) { ti->name = malloc( sizeof(char)*(strlen(val)+1) ); strcpy(ti->name,val); } else if(strcmp("comment", set)==0) { ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) ); sprintf(ti->comment, "-%s", val); } else if(strcmp("mus", set)==0) { //mus=00,song if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) ) { //val= from buf2=to set=song name pli = malloc( sizeof( playListItem ) ); pli->from=atoi(val); pli->to=atoi(buf2); pli->song=malloc(sizeof(char)*strlen(set)+1); strcpy( pli->song, set ); listAppendData( playList, (void*)pli ); } else { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n"); } } else if(strcmp("lives", set)==0) { ti->lives = atoi(val); } } //Found = } //reading file //Close the info file. fclose(f); } else { //Fall back if no file was found. SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf); ti->author = malloc( sizeof(char)* 20 ); strcpy(ti->author, "info.ini not found"); ti->comment=ti->author; ti->name = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->name, packDir); } //Set path ti->path = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->path,packDir); //Set pack icon sprintf(buf, "%s/icon.png", packDir); ti->icon = loadImg(buf); if(!ti->icon) { ti->icon = loadImg( "data/noicon.png" ); } //Check if pack have a "finished" icon. sprintf(buf, "%s/finished.png", packDir); //Set ps.cp before entering makeLevelist, it makes use of packGetFile ps.cp = ti; //Add levels. ti->levels=0; ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/ //set number of levels in pack ti->numLevels = ti->levels->count - 1 ; //The last level does not count (because it is just a "completed" screen). //Add to list of packages listAppendData( ps.packs, (void*)ti ); //Increase number of available packages ps.numPacks++; //Put playlist songs into levelfiles. li=&playList->begin; while( LISTFWD(playList,li) ) { pli=(playListItem*)li->data; for(i=0; i<ti->numLevels;i++) { if(i >= pli->from && i <= pli->to) { levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 ); strcpy(levelInfo(i)->musicFile, pli->song); } } } //Clear playlist data listFree( playList ); free(buf); free(buf2); free(val); free(set); return(ps.numPacks-1); }
int initGame(SDL_Surface* screen) { if(player()->gameStarted) { printf("ERROR: Called init when a game was running\n"); return(0); } //Only load the back-image once. if( !ptrRestart ) { ptrRestart = loadImg( DATADIR"data/ptr-restart.png" ); ptrRestartRect.x=HSCREENW-160; ptrRestartRect.w=ptrRestartRect.x+ptrRestart->w; ptrRestartRect.y=HSCREENH+120-ptrRestart->h; ptrRestartRect.h=ptrRestartRect.y+ptrRestart->h; } debugNumInit++; initCursor(&cur); restartConfirm=0; //Read info's for level. (this is done instead of using the one in packInfo so it don't need resetting) pf.levelInfo = mkLevelInfo( player()->levelFile ); if(!loadField(&pf, player()->levelFile )) { printf("Error: Couldn't init playfield.\n"); return(0); } if(!initDraw(pf.levelInfo,screen)) { printf("Error: Couldn't init graphics.\n"); return(0); } char* buf = malloc(sizeof(char)*128); sprintf(buf, "themes/%s",pf.levelInfo->soundDir); loadSamples( buf, levelInfo( player()->level)->musicFile ); //Load samples from sounddir, note we use the levelInfo from packInfo for the music since the playlist is hacked onto that. free(buf); txtLoadGameCharSet( pf.levelInfo->fontName ); pf.levelInfo->time *= 1000; //Convert seconds to ms countdown=500; countdownSeconds=3; gameState=GAMESTATECOUNTDOWN; player()->gameStarted=1; //Clear player stats memset( &player()->hsEntry, 0, sizeof( hsEntry_t ) ); //Set the levelNum player()->hsEntry.levelNum = player()->level; startStopImg=0; if(pf.levelInfo->startImg) { gameState=GAMESTATESTARTIMAGE; } //We also simulate the first switch tick here so all looks right at the countdown. switchUpdateAll( &pf ); justWon=0; return(1); }