void start_replay(void *arg) { ReplayStage *rstg; StageInfo *gstg; int i; replay_copy(&global.replay, (Replay*)arg); global.replaymode = REPLAY_PLAY; if(global.replay.stgcount == 1) pickedstage = 0; init_player(&global.plr); for(i = pickedstage; i < global.replay.stgcount; ++i) { replay_select(&global.replay, i); rstg = global.replay.current; gstg = stage_get(rstg->stage); if(!gstg) { printf("start_replay(): Invalid stage %d in replay at %i skipped.\n", rstg->stage, i); continue; } gstg->loop(); if(global.game_over == GAMEOVER_ABORT) break; global.game_over = 0; } global.game_over = 0; global.replaymode = REPLAY_RECORD; replay_destroy(&global.replay); replayview->instantselect = False; }
void replay_play(Replay *rpy, int firstidx) { if(rpy != &global.replay) { replay_copy(&global.replay, rpy, true); } if(firstidx >= global.replay.numstages || firstidx < 0) { log_warn("No stage #%i in the replay", firstidx); return; } global.replaymode = REPLAY_PLAY; for(int i = firstidx; i < global.replay.numstages; ++i) { ReplayStage *rstg = global.replay_stage = global.replay.stages+i; StageInfo *gstg = stage_get(rstg->stage); if(!gstg) { log_warn("Invalid stage %x in replay at %i skipped.", rstg->stage, i); continue; } global.plr.mode = plrmode_find(rstg->plr_char, rstg->plr_shot); stage_loop(gstg); if(global.game_over == GAMEOVER_ABORT) { break; } if(global.game_over == GAMEOVER_RESTART) { --i; } global.game_over = 0; } global.game_over = 0; global.replaymode = REPLAY_RECORD; replay_destroy(&global.replay); global.replay_stage = NULL; free_resources(false); }
bool state_replaymanager_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); refind_files=true; SUBSTATE2=0; } /* if */ if (refind_files) { refind_files=false; files.Delete(); #ifdef _WIN32 /* Find files: */ WIN32_FIND_DATA finfo; HANDLE h; if (replay_source==0) h=FindFirstFile("replays/*.rpl",&finfo); else h=FindFirstFile("high/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; if (replay_source==0) dp = opendir (replay_dir); else dp = opendir (high_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); files.Add(tmp); } /* if */ } (void) closedir (dp); } #endif first_file=0; act_file=0; } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); if (replay_source==0) font_print_centered(sx/2,20,"REPLAY FILES [L - CHANGE SOURCE]:",screen); else font_print_centered(sx/2,20,"HIGH SCORE FILES [L - CHANGE SOURCE]:",screen); if (replay_source!=0) font_print_centered(sx/2,30,"PRESS FIRE TO VIEW OR R TO REBUILD",screen); { char *tmp; int i; files.Rewind(); i=0; while(files.Iterate(tmp)) { if (i>=first_file && i<first_file+18) { char *sname[3]={"SH.RNR.","PNTR.2","X-TRM."}; int ship,length; char tmp2[256],tmp3[256]; if (i==act_file) { SDL_Rect r; r.x=2; r.y=42+(i-first_file)*10-1; r.w=strlen(tmp)*6+2; r.h=9; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } /* if */ font_print(4,42+(i-first_file)*10,tmp,screen); if (replay_source==0) snprintf(tmp2, sizeof(tmp2), "%s/%s",replay_dir, tmp); else snprintf(tmp2, sizeof(tmp2), "%s/%s",high_dir, tmp); replay_parameters(tmp2,&ship,&length,tmp3); { int min,sec,dec; dec=(length*18)/10; sec=dec/100; dec=dec%100; min=sec/60; sec=sec%60; sprintf(tmp2,"%.2i:%.2i'%.2i %s",min,sec,dec,sname[ship]); font_print(220,42+(i-first_file)*10,tmp2,screen); } } /* if */ i++; } /* while */ } rectangle(screen,-1,40,321,185,SDL_MapRGB(screen->format,255,255,255)); rectangle(screen,214,40,0,185,SDL_MapRGB(screen->format,255,255,255)); if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { SDL_FreeSurface(image); image=0; if (SUBSTATE2==0) { STATE=1; SUBSTATE=0; } /* if */ if (SUBSTATE2==1) { int i; char tmp[256]; char levelname[256]; int v1,v2; int fuel; STATE=8; SUBSTATE=0; if (replay_source==0) snprintf(tmp,sizeof(tmp), "%s/%s", replay_dir, files[act_file]); else snprintf(tmp, sizeof(tmp), "%s/%s",high_dir, files[act_file]); replayfile=fopen(tmp,"rb"); v1=fgetc(replayfile); v2=fgetc(replayfile); // To maintain compatibility with a previous version level=0; for(i=0;i<256;i++) levelname[i]=fgetc(replayfile); fuel=fgetc(replayfile); ship_type=fgetc(replayfile); game=new TRANSBALL("graphics/","sound/","maps/",fuel,levelname,ship_type); timer=0; } /* if */ } /* if */ } /* if */ if (SUBSTATE==32) { if ((keyboard[SDLK_UP] && !old_keyboard[SDLK_UP]) || (keyboard[SDLK_LEFT] && !old_keyboard[SDLK_LEFT])) { if (act_file>0) act_file--; if (act_file<first_file) first_file=act_file; } /* if */ if ((keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN]) || (keyboard[SDLK_RIGHT] && !old_keyboard[SDLK_RIGHT])) { if (act_file<(files.Length()-1)) act_file++; if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_PAGEUP] && !old_keyboard[SDLK_PAGEUP]) { act_file-=18; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN] && !old_keyboard[SDLK_PAGEDOWN]) { act_file+=18; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_LCTRL] && !old_keyboard[SDLK_LCTRL]) { SUBSTATE2=1; if (files.EmptyP()) SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_TAB] && !old_keyboard[SDLK_TAB]) { if (replay_source==0) replay_source=1; else replay_source=0; act_file=0; first_file=0; refind_files=true; } /* if */ if (keyboard[SDLK_BACKSPACE] && !old_keyboard[SDLK_BACKSPACE] && replay_source==1) { { List<char> replays; char *replay; char complete_replayname[256]; /* look for files: */ #ifdef _WIN32 WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("replays/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); replays.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir (replay_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); replays.Add(tmp); } /* if */ } (void) closedir (dp); } #endif /* Check if this replay is a highscore: */ replays.Rewind(); while(replays.Iterate(replay)) { int level; int ship,current_time,previous_high=-1; char levelname[256]; snprintf(complete_replayname, sizeof(complete_replayname), "%s/%s",replay_dir, replay); if (replay_parameters(complete_replayname,&ship,¤t_time,levelname)==2) { for(level=0;level<NLEVELS;level++) { if (strcmp(levelname,levelnames[level])==0) { /* the replay corresponds to level 'i' of the current level pack: */ /* UPDATE THE HIGHSCORES: */ int best_time=-1; int i,j; char highname[256],filename2[256]; previous_high=-1; j=0; snprintf(highname, sizeof(highname), "%s/", high_dir); j+=strlen(highname); for(i=0;levelpack[i]!='.' && levelpack[i]!=0;i++) highname[j++]=levelpack[i]; highname[j++]='-'; sprintf(highname+j,"%.3i",level); j+=3; highname[j++]='-'; if (ship==0) highname[j++]='S'; if (ship==0) highname[j++]='R'; if (ship==1) highname[j++]='V'; if (ship==1) highname[j++]='P'; if (ship==2) highname[j++]='X'; if (ship==2) highname[j++]='T'; highname[j++]='.'; highname[j++]='r'; highname[j++]='p'; highname[j++]='l'; highname[j++]=0; { int retval; int s,l; char levelname[256]; retval=replay_parameters(highname,&s,&l,levelname); if (retval==2) { previous_high=l; } /* if */ } if (previous_high==-1 || previous_high>current_time) { snprintf(filename2, sizeof(filename2), "%s/%s",replay_dir, replay); replay_copy(filename2,highname); } /* if */ } /* if */ } /* if */ } /* if */ } /* while */ } act_file=0; first_file=0; refind_files=true; } /* if */ } /* if */ return true; } /* state_replaymanager_cycle */