void plyr_read_stats_v(int *k, int *d){ char filename[PATH_MAX]; int k1=-1,k2=0,d1=-1,d2=0; PHYSFS_file *f; *k=0;*d=0;//in case the file doesn't exist. memset(filename, '\0', PATH_MAX); snprintf(filename,PATH_MAX,GameArg.SysUsePlayersDir?"Players/%s.eff":"%s.eff",Players[Player_num].callsign); f = PHYSFSX_openReadBuffered(filename); if(f) { char line[256],*word; if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"kills")) *k=atoi(line); d_free(word); } if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"deaths")) *d=atoi(line); d_free(word); } if(!PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); if(!strcmp(word,"key") && strlen(line)>10){ unsigned char *p; if (line[0]=='0' && line[1]=='1'){ if ((p=decode_stat((unsigned char*)line+3,&k1,effcode1))&& (p=decode_stat(p+1,&k2,effcode2))&& (p=decode_stat(p+1,&d1,effcode3))){ decode_stat(p+1,&d2,effcode4); } } } d_free(word); } if (k1!=k2 || k1!=*k || d1!=d2 || d1!=*d) { *k=0;*d=0; } } if(f) PHYSFS_close(f); }
void medkey_init() { PHYSFS_file * keyfile; char keypress[100]; char line_buffer[200]; int key; int i; //, size; int np; char * LispCommand; MALLOC( LispCommand, char, DIAGNOSTIC_MESSAGE_MAX ); for (i=0; i<2048; i++ ) KeyFunction[i] = NULL; keyfile = PHYSFSX_openReadBuffered( "GLOBAL.KEY" ); if (keyfile) { while (PHYSFSX_fgets(line_buffer, 200, keyfile)) { sscanf(line_buffer, " %s %s ", keypress, LispCommand); //ReadLispMacro( keyfile, LispCommand ); if ( (key=DecodeKeyText( keypress ))!= -1 ) { Assert( key < 2048); KeyFunction[key] = func_get( LispCommand, &np ); } else { Error( "Bad key %s in GLOBAL.KEY!", keypress ); } } PHYSFS_close(keyfile); } d_free( LispCommand ); }
void load_hostage_data(PHYSFS_file * fp,int do_read) { int version,i,num,num_hostages; hostage_init_all(); num_hostages = 0; // Find number of hostages in mine... for (i=0; i<=Highest_object_index; i++ ) { if ( Objects[i].type == OBJ_HOSTAGE ) { num = Objects[i].id; if (num+1 > num_hostages) num_hostages = num+1; if (Hostages[num].objnum != -1) { //slot already used num = hostage_get_next_slot(); //..so get new slot if (num+1 > num_hostages) num_hostages = num+1; Objects[i].id = num; } if ( num > -1 && num < MAX_HOSTAGES ) { Assert(Hostages[num].objnum == -1); //make sure not used // -- Matt -- commented out by MK on 11/19/94, hit often in level 3, level 4. Assert(Hostages[num].objnum == -1); //make sure not used Hostages[num].objnum = i; Hostages[num].objsig = Objects[i].signature; } } } if (do_read) { version = PHYSFSX_readInt(fp); for (i=0;i<num_hostages;i++) { Assert(Hostages[i].objnum != -1); //make sure slot filled in Hostages[i].vclip_num = PHYSFSX_readInt(fp); #ifndef SHAREWARE if (Hostages[i].vclip_num<0 || Hostages[i].vclip_num>=MAX_HOSTAGES || Hostage_face_clip[Hostages[i].vclip_num].num_frames<=0) Hostages[i].vclip_num=0; Assert(Hostage_face_clip[Hostages[i].vclip_num].num_frames); #endif PHYSFSX_fgets(Hostages[i].text, HOSTAGE_MESSAGE_LEN, fp); } } else for (i=0;i<num_hostages;i++) { Assert(Hostages[i].objnum != -1); //make sure slot filled in Hostages[i].vclip_num = 0; } }
//reads a line, returns ptr to value of passed parm. returns NULL if none char *get_parm_value(char *parm,PHYSFS_file *f) { static char buf[80]; if (!PHYSFSX_fgets(buf,80,f)) return NULL; if (istok(buf,parm)) return get_value(buf); else return NULL; }
static void AppendIniArgs(const char *filename, Arglist &Args) { if (auto f = PHYSFSX_openReadBuffered(filename)) { PHYSFSX_gets_line_t<1024> line; while (Args.size() < MAX_ARGS && PHYSFSX_fgets(line, f)) { const auto separator = " \t"; for(char *token = strtok(line, separator); token != NULL; token = strtok(NULL, separator)) { if (*token == ';') break; Args.push_back(token); } } } }
char *fgets_unlimited(PHYSFS_file *f) { int mem = 256; char *word, *buf, *p; MALLOC(word, char, mem); p = word; while (word && PHYSFSX_fgets(p, mem, f) == word + mem) { int i; // Make a bigger buffer, because it read to the end of the buffer. buf = word; mem *= 2; MALLOC(word, char, mem); for (i = 0; i < mem/2; i++) word[i] = buf[i]; d_free(buf); p = word + mem/2; } return word; }
//loads the specfied mission from the mission list. //build_mission_list() must have been called. //Returns true if mission loaded ok, else false. static int load_mission(mle *mission) { PHYSFS_file *mfile; char buf[PATH_MAX], *v; if (Current_mission) free_mission(); MALLOC(Current_mission, Mission, 1); if (!Current_mission) return 0; *(mle *) Current_mission = *mission; Current_mission->path = d_strdup(mission->path); Current_mission->filename = Current_mission->path + (mission->filename - mission->path); Current_mission->n_secret_levels = 0; Current_mission->enhanced = 0; //init vars Last_level = 0; Last_secret_level = 0; memset(&Briefing_text_filename, '\0', sizeof(Briefing_text_filename)); memset(&Ending_text_filename, '\0', sizeof(Ending_text_filename)); // for Descent 1 missions, load descent.hog if (EMULATING_D1) { if (!PHYSFSX_contfile_init("descent.hog", 1)) Warning("descent.hog not available, this mission may be missing some files required for briefings and exit sequence\n"); if (!stricmp(Current_mission_filename, D1_MISSION_FILENAME)) return load_mission_d1(); } if (PLAYING_BUILTIN_MISSION) { switch (Current_mission->builtin_hogsize) { case SHAREWARE_MISSION_HOGSIZE: case MAC_SHARE_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE_SHARE); strcpy(Ending_text_filename,BIMD2_ENDING_FILE_SHARE); return load_mission_shareware(); break; case OEM_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE_OEM); strcpy(Ending_text_filename,BIMD2_ENDING_FILE_OEM); return load_mission_oem(); break; default: Int3(); // fall through case FULL_MISSION_HOGSIZE: case FULL_10_MISSION_HOGSIZE: case MAC_FULL_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE); // continue on... (use d2.mn2 from hogfile) break; } } //read mission from file switch (mission->location) { case ML_MISSIONDIR: strcpy(buf,MISSION_DIR); break; default: Int3(); //fall through case ML_CURDIR: strcpy(buf,""); break; } strcat(buf, mission->path); if (mission->descent_version == 2) strcat(buf,".mn2"); else strcat(buf,".msn"); PHYSFSEXT_locateCorrectCase(buf); mfile = PHYSFSX_openReadBuffered(buf); if (mfile == NULL) { free_mission(); return 0; //error! } //for non-builtin missions, load HOG if (!PLAYING_BUILTIN_MISSION) { strcpy(buf+strlen(buf)-4,".hog"); //change extension PHYSFSEXT_locateCorrectCase(buf); if (PHYSFSX_exists(buf,1)) PHYSFSX_contfile_init(buf, 0); snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Briefing_text_filename,1)) snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.txb",Current_mission_filename); snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Ending_text_filename,1)) snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename); } while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { if (istok(buf,"name") && !Current_mission->enhanced) { Current_mission->enhanced = 0; continue; //already have name, go to next line } if (istok(buf,"xname") && !Current_mission->enhanced) { Current_mission->enhanced = 1; continue; //already have name, go to next line } if (istok(buf,"zname") && !Current_mission->enhanced) { Current_mission->enhanced = 2; continue; //already have name, go to next line } else if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"ending")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Ending_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"num_levels")) { if ((v=get_value(buf))!=NULL) { int n_levels,i; n_levels = atoi(v); for (i=0;i<n_levels;i++) { PHYSFSX_fgets(buf,sizeof(buf),mfile); add_term(buf); if (strlen(buf) <= 12) { strcpy(Level_names[i],buf); Last_level++; } else break; } } } else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { int i; N_secret_levels = atoi(v); Assert(N_secret_levels <= MAX_SECRET_LEVELS_PER_MISSION); for (i=0;i<N_secret_levels;i++) { char *t; PHYSFSX_fgets(buf,sizeof(buf),mfile); if ((t=strchr(buf,','))!=NULL) *t++=0; else break; add_term(buf); if (strlen(buf) <= 12) { strcpy(Secret_level_names[i],buf); Secret_level_table[i] = atoi(t); if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level) break; Last_secret_level--; } else break; } } } } PHYSFS_close(mfile); if (Last_level <= 0) { free_mission(); //no valid mission loaded return 0; } // re-read default HAM file, in case this mission brings it's own version of it free_polygon_models(); read_hamfile(); if (Current_mission->enhanced) { char t[50]; sprintf(t,"%s.ham",Current_mission_filename); bm_read_extra_robots(t, Current_mission->enhanced); init_extra_robot_movie(Current_mission_filename); } return 1; }
//returns 1 if file read ok, else 0 static int read_mission_file(mle *mission, const char *filename, int location) { char filename2[100]; snprintf(filename2, sizeof(filename2), "%s%s", location == ML_MISSIONDIR ? MISSION_DIR : (location == ML_CURDIR ? "" : (Int3(), "")), filename); PHYSFS_file *mfile; mfile = PHYSFSX_openReadBuffered(filename2); if (mfile) { char *p; char temp[PATH_MAX], *ext; strcpy(temp,filename); p = strrchr(temp, '/'); // get the filename at the end of the path if (!p) p = temp; else p++; if ((ext = strchr(p, '.')) == NULL) return 0; //missing extension // look if it's .mn2 or .msn mission->descent_version = (ext[3] == '2') ? 2 : 1; *ext = 0; //kill extension mission->path = d_strdup(temp); mission->anarchy_only_flag = 0; mission->filename = mission->path + (p - temp); mission->location = location; if (PHYSFSX_fgets(temp,sizeof(temp),mfile) && (p = get_mission_name(temp))) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) *t-- = 0; // remove trailing whitespace if (strlen(p) > MISSION_NAME_LEN) p[MISSION_NAME_LEN] = 0; strncpy(mission->mission_name, p, MISSION_NAME_LEN + 1); } else { PHYSFS_close(mfile); d_free(mission->path); return 0; } if (PHYSFSX_fgets(temp,sizeof(temp),mfile)) { if (istok(temp,"type")) { p = get_value(temp); //get mission type if (p) mission->anarchy_only_flag = istok(p,"anarchy"); } } PHYSFS_close(mfile); return 1; } return 0; }
int read_player_d1x(char *filename) { PHYSFS_file *f; int rc = 0; char line[50],*word; int Stop=0; plyr_read_stats(); f = PHYSFSX_openReadBuffered(filename); if(!f || PHYSFS_eof(f) ) return errno; while( !Stop && !PHYSFS_eof(f) ) { PHYSFSX_fgets(line,50,f); word=splitword(line,':'); strupr(word); if (strstr(word,"WEAPON REORDER")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { unsigned int wo0=0,wo1=0,wo2=0,wo3=0,wo4=0,wo5=0; if(!strcmp(word,"PRIMARY")) { sscanf(line,"0x%x,0x%x,0x%x,0x%x,0x%x,0x%x",&wo0, &wo1, &wo2, &wo3, &wo4, &wo5); PlayerCfg.PrimaryOrder[0]=wo0; PlayerCfg.PrimaryOrder[1]=wo1; PlayerCfg.PrimaryOrder[2]=wo2; PlayerCfg.PrimaryOrder[3]=wo3; PlayerCfg.PrimaryOrder[4]=wo4; PlayerCfg.PrimaryOrder[5]=wo5; } else if(!strcmp(word,"SECONDARY")) { sscanf(line,"0x%x,0x%x,0x%x,0x%x,0x%x,0x%x",&wo0, &wo1, &wo2, &wo3, &wo4, &wo5); PlayerCfg.SecondaryOrder[0]=wo0; PlayerCfg.SecondaryOrder[1]=wo1; PlayerCfg.SecondaryOrder[2]=wo2; PlayerCfg.SecondaryOrder[3]=wo3; PlayerCfg.SecondaryOrder[4]=wo4; PlayerCfg.SecondaryOrder[5]=wo5; } d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"JOYSTICK")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"SENSITIVITY0")) PlayerCfg.JoystickSens[0] = atoi(line); if(!strcmp(word,"SENSITIVITY1")) PlayerCfg.JoystickSens[1] = atoi(line); if(!strcmp(word,"SENSITIVITY2")) PlayerCfg.JoystickSens[2] = atoi(line); if(!strcmp(word,"SENSITIVITY3")) PlayerCfg.JoystickSens[3] = atoi(line); if(!strcmp(word,"SENSITIVITY4")) PlayerCfg.JoystickSens[4] = atoi(line); if(!strcmp(word,"SENSITIVITY5")) PlayerCfg.JoystickSens[5] = atoi(line); if(!strcmp(word,"DEADZONE0")) PlayerCfg.JoystickDead[0] = atoi(line); if(!strcmp(word,"DEADZONE1")) PlayerCfg.JoystickDead[1] = atoi(line); if(!strcmp(word,"DEADZONE2")) PlayerCfg.JoystickDead[2] = atoi(line); if(!strcmp(word,"DEADZONE3")) PlayerCfg.JoystickDead[3] = atoi(line); if(!strcmp(word,"DEADZONE4")) PlayerCfg.JoystickDead[4] = atoi(line); if(!strcmp(word,"DEADZONE5")) PlayerCfg.JoystickDead[5] = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"MOUSE")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"FLIGHTSIM")) PlayerCfg.MouseFlightSim = atoi(line); if(!strcmp(word,"SENSITIVITY0")) PlayerCfg.MouseSens[0] = atoi(line); if(!strcmp(word,"SENSITIVITY1")) PlayerCfg.MouseSens[1] = atoi(line); if(!strcmp(word,"SENSITIVITY2")) PlayerCfg.MouseSens[2] = atoi(line); if(!strcmp(word,"SENSITIVITY3")) PlayerCfg.MouseSens[3] = atoi(line); if(!strcmp(word,"SENSITIVITY4")) PlayerCfg.MouseSens[4] = atoi(line); if(!strcmp(word,"SENSITIVITY5")) PlayerCfg.MouseSens[5] = atoi(line); if(!strcmp(word,"FSDEAD")) PlayerCfg.MouseFSDead = atoi(line); if(!strcmp(word,"FSINDI")) PlayerCfg.MouseFSIndicator = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"WEAPON KEYS V2")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { int kc1=0,kc2=0,kc3=0; int i=atoi(word); if(i==0) i=10; i=(i-1)*3; sscanf(line,"0x%x,0x%x,0x%x",&kc1,&kc2,&kc3); PlayerCfg.KeySettingsD1X[i] = kc1; PlayerCfg.KeySettingsD1X[i+1] = kc2; PlayerCfg.KeySettingsD1X[i+2] = kc3; d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"COCKPIT")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"MODE")) PlayerCfg.CockpitMode[0] = PlayerCfg.CockpitMode[1] = atoi(line); else if(!strcmp(word,"HUD")) PlayerCfg.HudMode = atoi(line); else if(!strcmp(word,"RETTYPE")) PlayerCfg.ReticleType = atoi(line); else if(!strcmp(word,"RETRGBA")) sscanf(line,"%i,%i,%i,%i",&PlayerCfg.ReticleRGBA[0],&PlayerCfg.ReticleRGBA[1],&PlayerCfg.ReticleRGBA[2],&PlayerCfg.ReticleRGBA[3]); else if(!strcmp(word,"RETSIZE")) PlayerCfg.ReticleSize = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"TOGGLES")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"PERSISTENTDEBRIS")) PlayerCfg.PersistentDebris = atoi(line); if(!strcmp(word,"PRSHOT")) PlayerCfg.PRShot = atoi(line); if(!strcmp(word,"NOREDUNDANCY")) PlayerCfg.NoRedundancy = atoi(line); if(!strcmp(word,"MULTIMESSAGES")) PlayerCfg.MultiMessages = atoi(line); if(!strcmp(word,"BOMBGAUGE")) PlayerCfg.BombGauge = atoi(line); if(!strcmp(word,"AUTOMAPFREEFLIGHT")) PlayerCfg.AutomapFreeFlight = atoi(line); if(!strcmp(word,"NOFIREAUTOSELECT")) PlayerCfg.NoFireAutoselect = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"GRAPHICS")) { d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { if(!strcmp(word,"ALPHAEFFECTS")) PlayerCfg.AlphaEffects = atoi(line); if(!strcmp(word,"DYNLIGHTCOLOR")) PlayerCfg.DynLightColor = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } } else if (strstr(word,"PLX VERSION")) // know the version this pilot was used last with - allow modifications { int v1=0,v2=0,v3=0; d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); while(!strstr(word,"END") && !PHYSFS_eof(f)) { sscanf(line,"%i.%i.%i",&v1,&v2,&v3); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); strupr(word); } if (v1 == 0 && v2 == 56 && v3 == 0) // was 0.56.0 if (D1XMAJORi != v1 || D1XMINORi != v2 || D1XMICROi != v3) // newer (presumably) { // reset mouse cycling fields PlayerCfg.KeySettings[1][44] = 255; PlayerCfg.KeySettings[1][45] = 255; PlayerCfg.KeySettings[1][46] = 255; PlayerCfg.KeySettings[1][47] = 255; PlayerCfg.KeySettings[2][27] = 255; PlayerCfg.KeySettings[2][28] = 255; } } else if (strstr(word,"END") || PHYSFS_eof(f)) { Stop=1; } else { if(word[0]=='['&&!strstr(word,"D1X OPTIONS")) { while(!strstr(line,"END") && !PHYSFS_eof(f)) { PHYSFSX_fgets(line,50,f); strupr(line); } } } if(word) d_free(word); } PHYSFS_close(f); return rc; }
static window_event_result credits_handler(window *, const d_event &event, credits *cr) { int l, y; window_event_result result; switch (event.type) { case EVENT_KEY_COMMAND: if ((result = call_default_handler(event)) == window_event_result::ignored) // if not print screen, debug etc { return window_event_result::close; } return result; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { return window_event_result::close; } break; case EVENT_IDLE: if (cr->done>NUM_LINES) { return window_event_result::close; } break; case EVENT_WINDOW_DRAW: #if defined(DXX_BUILD_DESCENT_I) timer_delay(F1_0/17); #elif defined(DXX_BUILD_DESCENT_II) timer_delay(F1_0/28); #endif if (cr->row == 0) { do { cr->buffer_line = (cr->buffer_line+1) % NUM_LINES; #if defined(DXX_BUILD_DESCENT_II) get_line:; #endif if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], cr->file )) { char *p; if (cr->have_bin_file) // is this a binary tbl file decode_text_line (cr->buffer[cr->buffer_line]); #if defined(DXX_BUILD_DESCENT_I) p = strchr(&cr->buffer[cr->buffer_line][0],'\n'); if (p) *p = '\0'; #elif defined(DXX_BUILD_DESCENT_II) p = cr->buffer[cr->buffer_line]; if (p[0] == ';') goto get_line; if (p[0] == '%') { if (p[1] == ALLOWED_CHAR) { for (int i = 0; p[i]; i++) p[i] = p[i+2]; } else goto get_line; } #endif } else { //fseek( file, 0, SEEK_SET); cr->buffer[cr->buffer_line][0] = 0; cr->done++; } } while (cr->extra_inc--); cr->extra_inc = 0; } // cheap but effective: towards end of credits sequence, fade out the music volume if (cr->done >= NUM_LINES-16) { static int curvol = -10; if (curvol == -10) curvol = GameCfg.MusicVolume; if (curvol > (NUM_LINES-cr->done)/2) { curvol = (NUM_LINES-cr->done)/2; songs_set_volume(curvol); } } y = cr->first_line_offset - cr->row; show_fullscr(cr->backdrop); for (uint_fast32_t j=0; j != NUM_LINES; ++j, y += ROW_SPACING) { l = (cr->buffer_line + j + 1 ) % NUM_LINES; const char *s = cr->buffer[l]; if (!s) continue; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { gr_set_curfont( HUGE_FONT ); s++; } else if ( s[0] == '*' ) { gr_set_curfont( MEDIUM3_FONT ); s++; } else gr_set_curfont( MEDIUM2_FONT ); const auto tempp = strchr( s, '\t' ); if ( !tempp ) { // Wacky Fast Credits thing gr_string( 0x8000, y, s ); } } cr->row += SHEIGHT/200; if (cr->row >= ROW_SPACING) cr->row = 0; break; case EVENT_WINDOW_CLOSE: songs_set_volume(GameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); std::default_delete<credits>()(cr); break; default: break; } return window_event_result::ignored; }
static int read_mission_file(mission_list_type &mission_list, mission_candidate_search_path &pathname) { if (auto mfile = PHYSFSX_openReadBuffered(pathname.data())) { char *p; char *ext; p = strrchr(pathname.data(), '/'); if (!p) p = pathname.data(); if ((ext = strchr(p, '.')) == NULL) return 0; //missing extension mission_list.emplace_back(); mle *mission = &mission_list.back(); mission->path.assign(pathname.data(), ext); #if defined(DXX_BUILD_DESCENT_II) // look if it's .mn2 or .msn mission->descent_version = (ext[3] == MISSION_EXTENSION_DESCENT_II[3]) ? Mission::descent_version_type::descent2 : Mission::descent_version_type::descent1; #endif mission->anarchy_only_flag = 0; mission->filename = next(begin(mission->path), mission->path.find_last_of('/') + 1); PHYSFSX_gets_line_t<80> buf; p = get_parm_value(buf, "name",mfile); #if defined(DXX_BUILD_DESCENT_II) if (!p) { //try enhanced mission PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "xname",mfile); } if (!p) { //try super-enhanced mission! PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "zname",mfile); } if (!p) { //try extensible-enhanced mission! PHYSFSX_fseek(mfile,0,SEEK_SET); p = get_parm_value(buf, "!name",mfile); } #endif if (p) { char *t; if ((t=strchr(p,';'))!=NULL) *t=0; t = p + strlen(p)-1; while (isspace(*t)) *t-- = 0; // remove trailing whitespace mission->mission_name.copy_if(p, mission->mission_name.size() - 1); } else { mission_list.pop_back(); return 0; } { PHYSFSX_gets_line_t<4096> temp; if (PHYSFSX_fgets(temp,mfile)) { if (istok(temp,"type")) { p = get_value(temp); //get mission type if (p) mission->anarchy_only_flag = istok(p,"anarchy"); } } } return 1; } return 0; }
//loads the specfied mission from the mission list. //build_mission_list() must have been called. //Returns true if mission loaded ok, else false. int load_mission(mle *mission) { PHYSFS_file *mfile; char buf[PATH_MAX], *v; if (Current_mission) free_mission(); Current_mission = d_malloc(sizeof(Mission)); if (!Current_mission) return 0; *(mle *) Current_mission = *mission; Current_mission->path = d_strdup(mission->path); Current_mission->filename = Current_mission->path + (mission->filename - mission->path); Current_mission->n_secret_levels = 0; //init vars Last_level = 0; Last_secret_level = 0; memset(&Briefing_text_filename, '\0', sizeof(Briefing_text_filename)); memset(&Ending_text_filename, '\0', sizeof(Ending_text_filename)); Secret_level_table = NULL; Level_names = NULL; Secret_level_names = NULL; // for Descent 1 missions, load descent.hog if (!PHYSFSX_contfile_init("descent.hog", 1)) Error("descent.hog not available!\n"); if (!d_stricmp(Current_mission_filename, D1_MISSION_FILENAME)) return load_mission_d1(); //read mission from file switch (mission->location) { case ML_MISSIONDIR: strcpy(buf,MISSION_DIR); break; default: Int3(); //fall through case ML_CURDIR: strcpy(buf,""); break; } strcat(buf, mission->path); strcat(buf,".msn"); PHYSFSEXT_locateCorrectCase(buf); mfile = PHYSFSX_openReadBuffered(buf); if (mfile == NULL) { free_mission(); return 0; //error! } //for non-builtin missions, load HOG strcpy(buf+strlen(buf)-4,".hog"); //change extension PHYSFSEXT_locateCorrectCase(buf); if (PHYSFSX_exists(buf,1)) PHYSFSX_contfile_init(buf, 0); snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Briefing_text_filename,1)) snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.txb",Current_mission_filename); snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Ending_text_filename,1)) snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename); while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"ending")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Ending_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"num_levels")) { if ((v=get_value(buf))!=NULL) { int n_levels,i; n_levels = atoi(v); Assert(n_levels <= MAX_LEVELS_PER_MISSION); n_levels = min(n_levels, MAX_LEVELS_PER_MISSION); MALLOC(Level_names, d_fname, n_levels); if (!Level_names) { free_mission(); return 0; } for (i=0;i<n_levels;i++) { PHYSFSX_fgets(buf,sizeof(buf),mfile); add_term(buf); if (strlen(buf) <= 12) { strcpy(Level_names[i],buf); Last_level++; } else break; } } } else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { int i; N_secret_levels = atoi(v); Assert(N_secret_levels <= MAX_SECRET_LEVELS_PER_MISSION); N_secret_levels = min(N_secret_levels, MAX_SECRET_LEVELS_PER_MISSION); MALLOC(Secret_level_names, d_fname, N_secret_levels); if (!Secret_level_names) { free_mission(); return 0; } MALLOC(Secret_level_table, ubyte, N_secret_levels); if (!Secret_level_table) { free_mission(); return 0; } for (i=0;i<N_secret_levels;i++) { char *t; PHYSFSX_fgets(buf,sizeof(buf),mfile); if ((t=strchr(buf,','))!=NULL) *t++=0; else break; add_term(buf); if (strlen(buf) <= 12) { strcpy(Secret_level_names[i],buf); Secret_level_table[i] = atoi(t); if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level) break; Last_secret_level--; } else break; } } } } PHYSFS_close(mfile); if (Last_level <= 0) { free_mission(); //no valid mission loaded return 0; } return 1; }
int credits_handler(window *wind, d_event *event, credits *cr) { int j, l, y; char * tempp; switch (event->type) { case EVENT_KEY_COMMAND: if (!call_default_handler(event)) // if not print screen, debug etc window_close(wind); return 1; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { window_close(wind); return 1; } break; case EVENT_IDLE: if (cr->done>NUM_LINES) { window_close(wind); return 0; } break; case EVENT_WINDOW_DRAW: timer_delay(F1_0/28); if (cr->row == 0) { do { cr->buffer_line = (cr->buffer_line+1) % NUM_LINES; get_line:; if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], 80, cr->file )) { char *p; if (cr->have_bin_file) // is this a binary tbl file decode_text_line (cr->buffer[cr->buffer_line]); p = cr->buffer[cr->buffer_line]; if (p[0] == ';') goto get_line; if (p[0] == '%') { if (p[1] == ALLOWED_CHAR) { int i = 0, len = strlen(p); for (i = 0; i < len; i++) p[i] = p[i+2]; } else goto get_line; } } else { //fseek( file, 0, SEEK_SET); cr->buffer[cr->buffer_line][0] = 0; cr->done++; } } while (cr->extra_inc--); cr->extra_inc = 0; } // cheap but effective: towards end of credits sequence, fade out the music volume if (cr->done >= NUM_LINES-16) { static int curvol = -10; if (curvol == -10) curvol = GameCfg.MusicVolume; if (curvol > (NUM_LINES-cr->done)/2) { curvol = (NUM_LINES-cr->done)/2; songs_set_volume(curvol); } } y = cr->first_line_offset - cr->row; show_fullscr(&cr->backdrop); for (j=0; j<NUM_LINES; j++ ) { char *s; l = (cr->buffer_line + j + 1 ) % NUM_LINES; s = cr->buffer[l]; if ( s[0] == '!' ) { s++; } else if ( s[0] == '$' ) { gr_set_curfont( HUGE_FONT ); s++; } else if ( s[0] == '*' ) { gr_set_curfont( MEDIUM3_FONT ); s++; } else gr_set_curfont( MEDIUM2_FONT ); tempp = strchr( s, '\t' ); if ( !tempp ) { // Wacky Fast Credits thing int w, h, aw; gr_get_string_size( s, &w, &h, &aw); gr_string( 0x8000, y, s ); } y += ROW_SPACING; } cr->row += SHEIGHT/200; if (cr->row >= ROW_SPACING) cr->row = 0; break; case EVENT_WINDOW_CLOSE: gr_free_bitmap_data (&cr->backdrop); PHYSFS_close(cr->file); songs_set_volume(GameCfg.MusicVolume); songs_play_song( SONG_TITLE, 1 ); d_free(cr); break; default: break; } return 0; }
void menubar_init( char * file ) { int i,j, np; int aw, w, h; PHYSFS_file * infile; char buffer[200]; char buf1[200]; char buf2[200]; int menu, item; num_menus = state = 0; // This method should be faster than explicitly setting all the variables (I think) memset(Menu, 0, sizeof(Menu)); for (i=0; i < MAXMENUS; i++ ) for (j=0; j< MAXITEMS; j++ ) Menu[i].Item[j].Hotkey = -1; infile = PHYSFSX_openReadBuffered( file ); if (!infile) return; while ( PHYSFSX_fgets( buffer, 200, infile) != NULL ) { if ( buffer[0] == ';' ) continue; CommaParse( 0, buf1, buffer ); menu = atoi( buf1 ); if (menu >= MAXMENUS) Error("Too many menus (%d).",menu); CommaParse( 1, buf1, buffer ); item = atoi(buf1 ); if (item >= MAXITEMS) Error("Too many items (%d) in menu %d.",item+1,menu); CommaParse( 2, buf1, buffer ); ul_xlate(buf1); if (buf1[0] != '-' ) { sprintf( buf2, " %s ", buf1 ); Menu[menu].Item[item].Text = d_strdup(buf2); } else Menu[menu].Item[item].Text = d_strdup(buf1); Menu[menu].Item[item].InactiveText = d_strdup(Menu[menu].Item[item].Text); j= 0; for (i=0; i<=strlen(Menu[menu].Item[item].Text); i++ ) { np = Menu[menu].Item[item].Text[i]; if (np != CC_UNDERLINE) Menu[menu].Item[item].InactiveText[j++] = np; } CommaParse( 3, buf1, buffer ); if (buf1[0]=='{' && buf1[1] =='}') Menu[menu].Item[item].Hotkey = -1; else { i = DecodeKeyText(buf1); if (i<1) { Error("Unknown key, %s, in %s\n", buf1, file ); } else { Menu[menu].Item[item].Hotkey = i; } } CommaParse( 4, buf1, buffer ); if (strlen(buf1)) { Menu[menu].Item[item].user_function = func_get(buf1, &np); if (Menu[menu].Item[item].user_function==NULL) { Error( "Unknown function, %s, in %s\n", buf1, file ); //ui_messagebox( -2, -2, 1, buffer, "Ok" ); } } Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y; if ( Menu[menu].Item[item].Text[0] == '-' ) { w = 1; h = 3; } else { gr_get_string_size( Menu[menu].Item[item].Text, &w, &h, &aw ); w += 2; h += 2; } if (menu==0) { Menu[0].h = h; Menu[0].Item[item].x = Menu[0].x + Menu[0].w; Menu[0].Item[item].y = Menu[0].y; Menu[item+1].x = Menu[0].x + Menu[0].w; Menu[item+1].y = Menu[0].h - 2; Menu[0].Item[item].w = w; Menu[0].Item[item].h = h; Menu[0].w += w; }else { if ( w > Menu[menu].w ) { Menu[menu].w = w; for (i=0; i< Menu[menu].NumItems; i++ ) Menu[menu].Item[i].w = Menu[menu].w; } Menu[menu].Item[item].w = Menu[menu].w; Menu[menu].Item[item].x = Menu[menu].x; Menu[menu].Item[item].y = Menu[menu].y+Menu[menu].h; Menu[menu].Item[item].h = h; Menu[menu].h += h; } if ( item >= Menu[menu].NumItems ) { Menu[menu].NumItems = item+1; } if ( menu >= num_menus ) num_menus = menu+1; } Menu[0].w = 700; PHYSFS_close( infile ); }
// Set up everything for our music // NOTE: you might think this is done once per runtime but it's not! It's done for EACH song so that each mission can have it's own descent.sng structure. We COULD optimize that by only doing this once per mission. void songs_init() { int i = 0; char inputline[80+1]; PHYSFS_file * fp = NULL; char sng_file[PATH_MAX]; Songs_initialized = 0; if (BIMSongs != NULL) d_free(BIMSongs); memset(sng_file, '\0', sizeof(sng_file)); if (Current_mission != NULL) // try MISSION_NAME.sngdxx - might be rarely used but handy if you want a songfile for a specific mission outside of the mission hog file. use special extension to not crash with other ports of the game { snprintf(sng_file, strlen(Current_mission_filename)+8, "%s.sngdxx", Current_mission_filename); fp = PHYSFSX_openReadBuffered(sng_file); } if (fp == NULL) // try descent.sngdxx - a songfile specifically for dxx which level authors CAN use (dxx does not care if descent.sng contains MP3/OGG/etc. as well) besides the normal descent.sng containing files other versions of the game cannot play. this way a mission can contain a DOS-Descent compatible OST (hmp files) as well as a OST using MP3, OGG, etc. fp = PHYSFSX_openReadBuffered( "descent.sngdxx" ); if (fp == NULL) // try to open regular descent.sng fp = PHYSFSX_openReadBuffered( "descent.sng" ); if ( fp == NULL ) // No descent.sng available. Define a default song-set { int predef=30; // define 30 songs - period MALLOC(BIMSongs, bim_song_info, predef); if (!BIMSongs) return; strncpy(BIMSongs[SONG_TITLE].filename, "descent.hmp",sizeof(BIMSongs[SONG_TITLE].filename)); strncpy(BIMSongs[SONG_BRIEFING].filename, "briefing.hmp",sizeof(BIMSongs[SONG_BRIEFING].filename)); strncpy(BIMSongs[SONG_CREDITS].filename, "credits.hmp",sizeof(BIMSongs[SONG_CREDITS].filename)); strncpy(BIMSongs[SONG_ENDLEVEL].filename, "endlevel.hmp",sizeof(BIMSongs[SONG_ENDLEVEL].filename)); // can't find it? give a warning strncpy(BIMSongs[SONG_ENDGAME].filename, "endgame.hmp",sizeof(BIMSongs[SONG_ENDGAME].filename)); // ditto for (i = SONG_FIRST_LEVEL_SONG; i < predef; i++) { snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i - SONG_FIRST_LEVEL_SONG + 1); if (!PHYSFSX_exists(BIMSongs[i].filename,1)) snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%d.hmp", i - SONG_FIRST_LEVEL_SONG); if (!PHYSFSX_exists(BIMSongs[i].filename,1)) { memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename)); // music not available break; } } } else { while (!PHYSFS_eof(fp)) { PHYSFSX_fgets(inputline, 80, fp ); if ( strlen( inputline ) ) { BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+1)); memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename)); sscanf( inputline, "%15s", BIMSongs[i].filename ); if (strrchr(BIMSongs[i].filename, '.')) if (!stricmp(strrchr(BIMSongs[i].filename, '.'), ".hmp") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mp3") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".ogg") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".aif") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mid") || !stricmp(strrchr(BIMSongs[i].filename, '.'), ".flac") ) i++; } } // HACK: If Descent.hog is patched from 1.0 to 1.5, descent.sng is turncated. So let's patch it up here if (i==12 && PHYSFSX_fsize("descent.sng")==422) { BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+15)); for (i = 12; i <= 26; i++) snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i-4); } } Num_bim_songs = i; Songs_initialized = 1; if (fp != NULL) PHYSFS_close(fp); if (GameArg.SndNoMusic) GameCfg.MusicType = MUSIC_TYPE_NONE; // If SDL_Mixer is not supported (or deactivated), switch to no-music type if SDL_mixer-related music type was selected #ifdef USE_SDLMIXER if (GameArg.SndDisableSdlMixer) #else if (1) #endif { #ifndef _WIN32 if (GameCfg.MusicType == MUSIC_TYPE_BUILTIN) GameCfg.MusicType = MUSIC_TYPE_NONE; #endif if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM) GameCfg.MusicType = MUSIC_TYPE_NONE; } if (GameCfg.MusicType == MUSIC_TYPE_REDBOOK) RBAInit(); #ifdef USE_SDLMIXER else if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM) jukebox_load(); #endif songs_set_volume(GameCfg.MusicVolume); }
// -------------------------------------------------------------------- // Load game // Loads all the relevant data for a level. // If level != -1, it loads the filename with extension changed to .min // Otherwise it loads the appropriate level mine. // returns 0=everything ok, 1=old version, -1=error int load_game_data(PHYSFS_file *LoadFile) { int i,j; short game_top_fileinfo_version; int object_offset; int gs_num_objects; int trig_size; //===================== READ FILE INFO ======================== #if 0 PHYSFS_read(LoadFile, &game_top_fileinfo, sizeof(game_top_fileinfo), 1); #endif // Check signature if (PHYSFSX_readShort(LoadFile) != 0x6705) return -1; // Read and check version number game_top_fileinfo_version = PHYSFSX_readShort(LoadFile); if (game_top_fileinfo_version < GAME_COMPATIBLE_VERSION ) return -1; // We skip some parts of the former game_top_fileinfo PHYSFSX_fseek(LoadFile, 31, SEEK_CUR); object_offset = PHYSFSX_readInt(LoadFile); gs_num_objects = PHYSFSX_readInt(LoadFile); PHYSFSX_fseek(LoadFile, 8, SEEK_CUR); Num_walls = PHYSFSX_readInt(LoadFile); PHYSFSX_fseek(LoadFile, 20, SEEK_CUR); Num_triggers = PHYSFSX_readInt(LoadFile); PHYSFSX_fseek(LoadFile, 24, SEEK_CUR); trig_size = PHYSFSX_readInt(LoadFile); Assert(trig_size == sizeof(ControlCenterTriggers)); (void)trig_size; PHYSFSX_fseek(LoadFile, 4, SEEK_CUR); Num_robot_centers = PHYSFSX_readInt(LoadFile); PHYSFSX_fseek(LoadFile, 4, SEEK_CUR); if (game_top_fileinfo_version >= 31) //load mine filename // read newline-terminated string, not sure what version this changed. PHYSFSX_fgets(Current_level_name,sizeof(Current_level_name),LoadFile); else if (game_top_fileinfo_version >= 14) { //load mine filename // read null-terminated string char *p=Current_level_name; //must do read one char at a time, since no PHYSFSX_fgets() do *p = PHYSFSX_fgetc(LoadFile); while (*p++!=0); } else Current_level_name[0]=0; if (game_top_fileinfo_version >= 19) { //load pof names N_save_pof_names = PHYSFSX_readShort(LoadFile); if (N_save_pof_names != 0x614d && N_save_pof_names != 0x5547) { // "Ma"de w/DMB beta/"GU"ILE Assert(N_save_pof_names < MAX_POLYGON_MODELS); PHYSFS_read(LoadFile,Save_pof_names,N_save_pof_names,FILENAME_LEN); } } //===================== READ PLAYER INFO ========================== //===================== READ OBJECT INFO ========================== Gamesave_num_org_robots = 0; Gamesave_num_players = 0; if (object_offset > -1) { if (PHYSFSX_fseek( LoadFile, object_offset, SEEK_SET )) Error( "Error seeking to object_offset in gamesave.c" ); for (i = 0; i < gs_num_objects; i++) { read_object(&Objects[i], LoadFile, game_top_fileinfo_version); Objects[i].signature = obj_get_signature(); verify_object( &Objects[i] ); } } //===================== READ WALL INFO ============================ for (i = 0; i < Num_walls; i++) { if (game_top_fileinfo_version >= 20) wall_read(&Walls[i], LoadFile); // v20 walls and up. else if (game_top_fileinfo_version >= 17) { v19_wall w; v19_wall_read(&w, LoadFile); Walls[i].segnum = w.segnum; Walls[i].sidenum = w.sidenum; Walls[i].linked_wall = w.linked_wall; Walls[i].type = w.type; Walls[i].flags = w.flags; Walls[i].hps = w.hps; Walls[i].trigger = w.trigger; Walls[i].clip_num = convert_wclip(w.clip_num); Walls[i].keys = w.keys; Walls[i].state = WALL_DOOR_CLOSED; } else { v16_wall w; v16_wall_read(&w, LoadFile); Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1; Walls[i].type = w.type; Walls[i].flags = w.flags; Walls[i].hps = w.hps; Walls[i].trigger = w.trigger; Walls[i].clip_num = convert_wclip(w.clip_num); Walls[i].keys = w.keys; } } #if 0 //===================== READ DOOR INFO ============================ if (game_fileinfo.doors_offset > -1) { if (!PHYSFSX_fseek( LoadFile, game_fileinfo.doors_offset,SEEK_SET )) { for (i=0;i<game_fileinfo.doors_howmany;i++) { if (game_top_fileinfo_version >= 20) active_door_read(&ActiveDoors[i], LoadFile); // version 20 and up else { v19_door d; int p; v19_door_read(&d, LoadFile); ActiveDoors[i].n_parts = d.n_parts; for (p=0;p<d.n_parts;p++) { int cseg,cside; cseg = Segments[d.seg[p]].children[d.side[p]]; cside = find_connect_side(&Segments[d.seg[p]],&Segments[cseg]); ActiveDoors[i].front_wallnum[p] = Segments[d.seg[p]].sides[d.side[p]].wall_num; ActiveDoors[i].back_wallnum[p] = Segments[cseg].sides[cside].wall_num; } } } } } #endif // 0 //==================== READ TRIGGER INFO ========================== for (i = 0; i < Num_triggers; i++) { if (game_top_fileinfo_version <= 25) trigger_read(&Triggers[i], LoadFile); else { int type; switch ((type = PHYSFSX_readByte(LoadFile))) { case 0: // door Triggers[i].type = 0; Triggers[i].flags = TRIGGER_CONTROL_DOORS; break; case 2: // matcen Triggers[i].type = 0; Triggers[i].flags = TRIGGER_MATCEN; break; case 3: // exit Triggers[i].type = 0; Triggers[i].flags = TRIGGER_EXIT; break; case 4: // secret exit Triggers[i].type = 0; Triggers[i].flags = TRIGGER_SECRET_EXIT; break; case 5: // illusion off Triggers[i].type = 0; Triggers[i].flags = TRIGGER_ILLUSION_OFF; break; case 6: // illusion on Triggers[i].type = 0; Triggers[i].flags = TRIGGER_ILLUSION_ON; break; default: con_printf(CON_URGENT,"Warning: unsupported trigger type %d (%d)\n", type, i); } if (PHYSFSX_readByte(LoadFile) & 2) // one shot Triggers[i].flags |= TRIGGER_ONE_SHOT; Triggers[i].num_links = PHYSFSX_readShort(LoadFile); Triggers[i].value = PHYSFSX_readInt(LoadFile); Triggers[i].time = PHYSFSX_readInt(LoadFile); for (j=0; j<MAX_WALLS_PER_LINK; j++ ) Triggers[i].seg[j] = PHYSFSX_readShort(LoadFile); for (j=0; j<MAX_WALLS_PER_LINK; j++ ) Triggers[i].side[j] = PHYSFSX_readShort(LoadFile); } } //================ READ CONTROL CENTER TRIGGER INFO =============== control_center_triggers_read_n(&ControlCenterTriggers, 1, LoadFile); //================ READ MATERIALOGRIFIZATIONATORS INFO =============== for (i = 0; i < Num_robot_centers; i++) { matcen_info_read(&RobotCenters[i], LoadFile, game_top_fileinfo_version); // Set links in RobotCenters to Station array for (j = 0; j <= Highest_segment_index; j++) if (Segments[j].special == SEGMENT_IS_ROBOTMAKER) if (Segments[j].matcen_num == i) RobotCenters[i].fuelcen_num = Segments[j].value; } //========================= UPDATE VARIABLES ====================== reset_objects(gs_num_objects); for (i=0; i<MAX_OBJECTS; i++) { Objects[i].next = Objects[i].prev = -1; if (Objects[i].type != OBJ_NONE) { int objsegnum = Objects[i].segnum; if (objsegnum > Highest_segment_index) //bogus object Objects[i].type = OBJ_NONE; else { Objects[i].segnum = -1; //avoid Assert() obj_link(i,objsegnum); } } } clear_transient_objects(1); //1 means clear proximity bombs // Make sure non-transparent doors are set correctly. for (i=0; i< Num_segments; i++) for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) { side *sidep = &Segments[i].sides[j]; if ((sidep->wall_num != -1) && (Walls[sidep->wall_num].clip_num != -1)) { if (WallAnims[Walls[sidep->wall_num].clip_num].flags & WCF_TMAP1) { sidep->tmap_num = WallAnims[Walls[sidep->wall_num].clip_num].frames[0]; sidep->tmap_num2 = 0; } } } reset_walls(); #if 0 Num_open_doors = game_fileinfo.doors_howmany; #endif // 0 Num_open_doors = 0; //go through all walls, killing references to invalid triggers for (i=0;i<Num_walls;i++) if (Walls[i].trigger >= Num_triggers) { Walls[i].trigger = -1; //kill trigger } //go through all triggers, killing unused ones for (i=0;i<Num_triggers;) { int w; // Find which wall this trigger is connected to. for (w=0; w<Num_walls; w++) if (Walls[w].trigger == i) break; #ifdef EDITOR if (w == Num_walls) { remove_trigger_num(i); } else #endif i++; } // MK, 10/17/95: Make walls point back at the triggers that control them. // Go through all triggers, stuffing controlling_trigger field in Walls. { int t; for (t=0; t<Num_triggers; t++) { int l; for (l=0; l<Triggers[t].num_links; l++) { int seg_num; seg_num = Triggers[t].seg[l]; //check to see that if a trigger requires a wall that it has one, //and if it requires a matcen that it has one if (Triggers[t].type == TRIGGER_MATCEN) { if (Segments[seg_num].special != SEGMENT_IS_ROBOTMAKER) Int3(); //matcen trigger doesn't point to matcen } } } } //fix old wall structs if (game_top_fileinfo_version < 17) { int segnum,sidenum,wallnum; for (segnum=0; segnum<=Highest_segment_index; segnum++) for (sidenum=0;sidenum<6;sidenum++) if ((wallnum=Segments[segnum].sides[sidenum].wall_num) != -1) { Walls[wallnum].segnum = segnum; Walls[wallnum].sidenum = sidenum; } } #ifndef NDEBUG { int sidenum; for (sidenum=0; sidenum<6; sidenum++) { int wallnum = Segments[Highest_segment_index].sides[sidenum].wall_num; if (wallnum != -1) if ((Walls[wallnum].segnum != Highest_segment_index) || (Walls[wallnum].sidenum != sidenum)) Int3(); // Error. Bogus walls in this segment. // Consult Yuan or Mike. } } #endif //create_local_segment_data(); fix_object_segs(); #ifndef NDEBUG dump_mine_info(); #endif if (game_top_fileinfo_version < GAME_VERSION) return 1; //means old version else return 0; }
void ui_pad_read( int n, char * filename ) { char * ptr; char buffer[100]; char text[100]; char line_buffer[200]; PHYSFS_file * infile; int linenumber = 0; int i; int keycode, functionnumber; infile = PHYSFSX_openReadBuffered( filename ); if (!infile) { Warning( "Couldn't find %s\n", filename ); return; } MALLOC( KeyPad[n], UI_KEYPAD, 1 ); for (i=0; i < 17; i++ ) { MALLOC( KeyPad[n]->buttontext[i], char, 100 ); } KeyPad[n]->numkeys = 0; for (i=0; i<100; i++ ) { KeyPad[n]->keycode[i] = -1; KeyPad[n]->function_number[i] = 0; } while ( linenumber < 22) { PHYSFSX_fgets( buffer, 100, infile ); switch( linenumber+1 ) { case 1: strncpy( KeyPad[n]->description, buffer, 100 ); break; //===================== ROW 0 ============================== case 3: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[0], "%s\n", text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[1], "%s\n", text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[2], "%s\n", text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[3], "%s\n", text ); break; case 4: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[0], "%s%s\n", KeyPad[n]->buttontext[0],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[1], "%s%s\n", KeyPad[n]->buttontext[1],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[2], "%s%s\n", KeyPad[n]->buttontext[2],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[3], "%s%s\n", KeyPad[n]->buttontext[3],text ); break; case 5: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[0], "%s%s", KeyPad[n]->buttontext[0],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[1], "%s%s", KeyPad[n]->buttontext[1],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[2], "%s%s", KeyPad[n]->buttontext[2],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[3], "%s%s", KeyPad[n]->buttontext[3],text ); break; //===================== ROW 1 ============================== case 7: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[4], "%s\n", text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[5], "%s\n", text ); LineParse( 3, text, buffer); sprintf( KeyPad[n]->buttontext[6], "%s\n", text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s\n", text ); break; case 8: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[4], "%s%s\n", KeyPad[n]->buttontext[4],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[5], "%s%s\n", KeyPad[n]->buttontext[5],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[6], "%s%s\n", KeyPad[n]->buttontext[6],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text ); break; case 9: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[4], "%s%s", KeyPad[n]->buttontext[4],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[5], "%s%s", KeyPad[n]->buttontext[5],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[6], "%s%s", KeyPad[n]->buttontext[6],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text ); break; case 10: ptr = strrchr( buffer, (char) 179 ); *ptr = 0; ptr = strrchr( buffer, (char) 180 ); ptr++; sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],ptr ); break; //======================= ROW 2 ============================== case 11: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[8], "%s\n", text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[9], "%s\n", text ); LineParse( 3, text, buffer); sprintf( KeyPad[n]->buttontext[10], "%s\n", text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text ); break; case 12: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[8], "%s%s\n", KeyPad[n]->buttontext[8],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[9], "%s%s\n", KeyPad[n]->buttontext[9],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[10], "%s%s\n", KeyPad[n]->buttontext[10],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s%s\n", KeyPad[n]->buttontext[7],text ); break; case 13: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[8], "%s%s", KeyPad[n]->buttontext[8],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[9], "%s%s", KeyPad[n]->buttontext[9],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[10], "%s%s", KeyPad[n]->buttontext[10],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[7], "%s%s", KeyPad[n]->buttontext[7],text ); break; // ====================== ROW 3 ========================= case 15: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[11], "%s\n", text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[12], "%s\n", text ); LineParse( 3, text, buffer); sprintf( KeyPad[n]->buttontext[13], "%s\n", text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s\n", text ); break; case 16: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[11], "%s%s\n", KeyPad[n]->buttontext[11],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[12], "%s%s\n", KeyPad[n]->buttontext[12],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[13], "%s%s\n", KeyPad[n]->buttontext[13],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text ); break; case 17: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[11], "%s%s", KeyPad[n]->buttontext[11],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[12], "%s%s", KeyPad[n]->buttontext[12],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[13], "%s%s", KeyPad[n]->buttontext[13],text ); LineParse( 4, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text ); break; case 18: ptr = strrchr( buffer, (char) 179 ); *ptr = 0; ptr = strrchr( buffer, (char) 180 ); ptr++; sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14], ptr ); break; //======================= ROW 4 ========================= case 19: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[15], "%s\n", text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[16], "%s\n", text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text ); break; case 20: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[15], "%s%s\n", KeyPad[n]->buttontext[15],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[16], "%s%s\n", KeyPad[n]->buttontext[16],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s%s\n", KeyPad[n]->buttontext[14],text ); break; case 21: LineParse( 1, text, buffer ); sprintf( KeyPad[n]->buttontext[15], "%s%s", KeyPad[n]->buttontext[15],text ); LineParse( 2, text, buffer ); sprintf( KeyPad[n]->buttontext[16], "%s%s", KeyPad[n]->buttontext[16],text ); LineParse( 3, text, buffer ); sprintf( KeyPad[n]->buttontext[14], "%s%s", KeyPad[n]->buttontext[14],text ); break; } linenumber++; } // Get the keycodes... while (PHYSFSX_fgets(line_buffer, 200, infile)) { sscanf(line_buffer, " %s %s ", text, buffer); keycode = DecodeKeyText(text); functionnumber = func_get_index(buffer); if (functionnumber==-1) { Error( "Unknown function, %s, in %s\n", buffer, filename ); } else if (keycode==-1) { Error( "Unknown keystroke, %s, in %s\n", text, filename ); //ui_messagebox( -2, -2, 1, buffer, "Ok" ); } else { KeyPad[n]->keycode[KeyPad[n]->numkeys] = keycode; KeyPad[n]->function_number[KeyPad[n]->numkeys] = functionnumber; KeyPad[n]->numkeys++; } } PHYSFS_close(infile); }