char inkey(void){ int i; command_count=0; while(TRUE){ i=msdos_getch(); if(i==EOF){ eof_flag++; msg_flag=FALSE; if(!character_generated||character_saved) exit_game(); disturb(1,0); if(eof_flag>100){ panic_save=1; strcpy(died_from,"(end of input: panic saved)"); if(!save_char()){ strcpy(died_from,"panic: unexpected eof"); death=TRUE; } exit_game(); } return ESCAPE; } if(i!=CTRL('R')) return (char) i; msdos_raw(); break; } return (CTRL('R')); }
/** * @brief Function to exit the main menu and game. * @param str Unused. */ static void menu_exit( unsigned int wid, char* str ) { (void) str; (void) wid; exit_game(); }
void init_main_sel_conf( GraphConf *cnf ) { // 各種初期化 gPcgDun.init( cnf ); configure_map(); change_scene_gui( SCENE_N_TOWN ); gGuiMenu.init(); gGuiMessage.init(); gGuiStat.init(); gGuiNum.init(); gKey.init(); initMouseMotionFunc(); pos_t *draw = get_map_draw_pos(); pos_t *draw_gui = get_map_draw_pos_gui(); if( (draw != NULL) && (draw_gui != NULL) ){ draw_gui->x = draw->x; draw_gui->y = draw->y; gPcgDun.scrollTile( draw_gui->x, draw_gui->y ); } gPcgDun.redraw(); if( !call_game_thread_create( main_thread ) ) exit_game( EXIT_FAILURE ); }
void upon_death() { /*{ Handles the gravestone and top-twenty routines -RAK- }*/ GDBM_FILE f2; master_key mkey; vtype dstr[20]; /*{ What happens upon dying... -RAK- }*/ if (!master_file_open(&f2)) { msg_print("ERROR opening file MASTER. Contact your local wizard."); //msg_print("Status = "+itos(status(f1))); msg_print(" "); } else { mkey.creation_time = PM.creation_time; master_file_delete(f2, &mkey); master_file_close(&f2); } /* I think this says "delete the file"... open(f1,file_name:=finam,record_length:=1024,history:=old, disposition:=delete,error:=continue); */ unlink(finam); if (total_winner) { ud__kingly(); } ud__print_tomb(dstr); print_dead_character(); top_twenty(max_score); exit_game(); };
void window(char *file) { int loop; unsigned int framelimit; framelimit = 0; loop = 0; game.file = file; if (init_all() == 0 && game.map != NULL) { load_audio(); //load_intro(); while (loop == 0) { loop = get_input_menu(); load_menu(); while (loop == 1) { loop = get_input_game(); load_game(); framelimit = delay(framelimit); } framelimit = delay(framelimit); } } exit_game(); }
/** * @brief Menu to ask if player really wants to quit. */ int menu_askQuit (void) { /* Asked twice, quit. */ if (menu_isOpen( MENU_ASKQUIT )) { exit_game(); return 1; } /* Ask if should quit. */ menu_Open( MENU_ASKQUIT ); if (dialogue_YesNoRaw( _("Quit Naev"), _("Are you sure you want to quit Naev?") )) { exit_game(); return 1; } menu_Close( MENU_ASKQUIT ); return 0; }
int main(int argc, char **argv) { init_allegro_elements(); if (main_menu()==0) { exit_game(); return 0; } }
/* initializes curses routines */ void init_curses() { int i, y, x; (void) ioctl(0, TCGETA, (char *)&save_termio); if (initscr() == NULL) { (void) printf("Error allocating screen in curses package.\n"); exit(1); } if (LINES < 24 || COLS < 80) /* Check we have enough screen. -CJS- */ { (void) printf("Screen too small for moria.\n"); exit (1); } #ifdef SIGTSTP (void) signal (SIGTSTP, suspend); #endif if ((savescr = newwin (0, 0, 0, 0)) == NULL) { (void) printf ("Out of memory in starting up curses.\n"); exit_game(); } (void) clear(); (void) refresh(); moriaterm (); /* check tab settings, exit with error if they are not 8 spaces apart */ (void) move(0, 0); for (i = 1; i < 10; i++) { (void) addch('\t'); getyx(stdscr, y, x); if (y != 0 || x != i*8) break; } if (i != 10) { msg_print("Tabs must be set 8 spaces apart."); exit_game(); } }
void pause_exit(int prt_line, int delay) { char dummy; #ifdef __TURBOC__ /* Otherwise, TURBO C complains that delay is never used. */ dummy = (char) delay; #endif prt("[Press any key to continue, or Q to exit.]", prt_line, 10); dummy = inkey(); if (dummy == 'Q') { erase_line(prt_line, 0); exit_game(); } erase_line(prt_line, 0); }
/** * @brief Main menu closing prompt. */ static void main_menu_promptClose( unsigned int wid, char *unused ) { (void) wid; (void) unused; exit_game(); }
void top_twenty(integer this_many) { /*{ Enters a players name on the top twenty list -JWT- }*/ string list[MAX_HIGH_SCORES+2]; integer players_line = 0; integer i1,i2,i3,i4; int n1; vtype o1,s1; FILE *f1; boolean flag; char ch; if (py.misc.cheated) { exit_game(); } clear_screen(); if (!read_top_scores(&f1, MORIA_TOP, list, MAX_HIGH_SCORES, &n1, s1)) { prt(s1,2,1); prt("",3,1); } else { i3 = total_points(); flag = false; if (i3 == 0) { i1 = n1; } else { for (i1=1; (i1 <= n1) && !flag ; ) { /* XXXX check for corruption */ sscanf(&(list[i1][13]),"%ld",&i4); if (i4 < i3) { flag = true; } else { i1++; } } } if ((i3 > 0) && ((flag) || (n1 == 0) || (n1 < MAX_HIGH_SCORES))) { for (i2 = MAX_HIGH_SCORES-1; i2 >= i1 ; i2--) { strcpy(list[i2+1], list[i2]); } user_name(o1); format_top_score(list[i1], o1, i3, PM.diffic, PM.name, PM.lev, PM.race, PM.tclass); if (n1 < MAX_HIGH_SCORES) { n1++; } max_score = n1; players_line = i1; flag = false; write_top_scores(&f1, list, n1); } else { /* did not get a high score */ max_score = 20; } if (!close_top_scores(&f1)) { prt("Error unlocking score file.",2,1); prt("",3,1); } put_buffer("Username Points Diff Character name Level Race Class",1,1); put_buffer("____________ ________ _ ________________________ __ __________ ________________",2,1); i2 = 3; if (max_score > n1) { max_score = n1; } if (this_many > 0) { if (this_many > MAX_HIGH_SCORES) { max_score = MAX_HIGH_SCORES; } else { max_score = this_many; } } for (i1 = 1; i1 <= max_score; i1++) { /*insert_str(list[i1],chr(7),''); XXXX why? */ if (i1 == players_line) { put_buffer_attr(list[i1],i2,1, A_REVERSE); } else { put_buffer(list[i1],i2,1); } if ((i1 != 1) && ((i1 % 20) == 0) && (i1 != max_score)) { prt("[Press any key to continue, or <Control>-Z to exit]", 24,1); ch = inkey(); switch (ch) { case 3: case 25: case 26: erase_line(24,1); put_buffer(" ",23,13); exit_game(); break; } clear_rc(3,1); i2 = 2; } i2++; } /* end for */ erase_line(23,1); put_qio(); } /* end if read_top_scores */ };
int main( int argc, char **argv ) { init_arg(); g_flg_gui = TRUE; g_flg_cui_mouse = TRUE; #if defined( NDEBUG ) g_flg_cui = FALSE; #elif defined( DEBUG ) g_flg_cui = TRUE; #else g_flg_cui = FALSE; #endif // メイン処理の初期化 chk_arg( argc, argv ); init_game(); change_scene_gui( SCENE_N_INIT ); if( g_flg_cui_mouse ) gCuiMouse.init(); if( g_flg_gui ){ init_gtk_gui( argc, argv ); // GUI のメイン・ループを開始 gtk_main(); // 終了 close_game( EXIT_SUCCESS ); gtk_exit( EXIT_SUCCESS ); } else if( g_flg_cui_mouse ){ init_gtk_cui_mouse( argc, argv ); // CUI のメイン・ループを開始 game_main(); // 終了 close_game( EXIT_SUCCESS ); } else if( g_flg_cui ){ init_gtk_cui( argc, argv ); // CUI のメイン・ループを開始 game_main(); // 終了 close_game( EXIT_SUCCESS ); } exit_game( EXIT_SUCCESS ); return EXIT_SUCCESS; }
void init_main_win( void ) { GtkAttachOptions xOpt, yOpt; gMapWin = gtk_window_new( GTK_WINDOW_TOPLEVEL ); if( gMapWin == NULL ){ print_msg( FLG_MSG_ERR, "gtk_window_new()" ); exit_game( EXIT_FAILURE ); } GtkWidget *vBox = gtk_vbox_new( FALSE, 0 ); gtk_container_add( GTK_CONTAINER( gMapWin ), vBox ); gtk_widget_show( vBox ); // メイン・ウィンドウへのイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( gMapWin ), "delete_event", GTK_SIGNAL_FUNC( handle_delete ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapWin ), "destroy", GTK_SIGNAL_FUNC( handle_destroy ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapWin ), "key-press-event", GTK_SIGNAL_FUNC( handleKeyPress ), NULL ); // ツール・バーを作成 GtkWidget *handleBox = gtk_handle_box_new(); gtk_box_pack_start( GTK_BOX( vBox ), handleBox, FALSE, FALSE, 0 ); gtk_widget_show( handleBox ); GtkWidget *toolBar = gtk_toolbar_new(); gtk_toolbar_set_orientation( GTK_TOOLBAR( toolBar ), GTK_ORIENTATION_HORIZONTAL ); gtk_toolbar_set_style( GTK_TOOLBAR( toolBar ), GTK_TOOLBAR_ICONS ); gtk_widget_show( toolBar ); gtk_container_add( GTK_CONTAINER( handleBox ), toolBar ); // ツール・バーのボタンを作成 btnMapExec = gtk_button_new_with_label( MSG_GUI_MAP_EXEC ); gMapButtonContExec = gtk_button_new_with_label( MSG_GUI_MAP_CONT_EXEC_OFF ); #if FLAG_BTN_MAP_LABEL_IS_NAME btnMapAutoMark = gtk_button_new_with_label( MSG_GUI_MAP_AUTO_MARK ); btnMapUserMenu = gtk_button_new_with_label( MSG_GUI_MAP_USER_MENU ); btnMapSpell = gtk_button_new_with_label( MSG_GUI_MAP_SPELL ); btnMapSquare = gtk_button_new_with_label( MSG_GUI_MAP_SQUARE ); #else btnMapAutoMark = gtk_button_new_with_label( " / " ); btnMapUserMenu = gtk_button_new_with_label( " * " ); btnMapSpell = gtk_button_new_with_label( " - " ); btnMapSquare = gtk_button_new_with_label( " + " ); #endif btnMapCancel = gtk_button_new_with_label( MSG_GUI_MAP_CANCEL ); btnMapOk = gtk_button_new_with_label( MSG_GUI_MAP_OK ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapExec, MSG_GUI_MAP_TOOL_TIP_EXEC, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), gMapButtonContExec, MSG_GUI_MAP_TOOL_TIP_CONT_EXEC, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapAutoMark, MSG_GUI_MAP_TOOL_TIP_AUTO_MARK, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapUserMenu, MSG_GUI_MAP_TOOL_TIP_USER_MENU, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapSpell, MSG_GUI_MAP_TOOL_TIP_SPELL, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapSquare, MSG_GUI_MAP_TOOL_TIP_SQUARE, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapCancel, MSG_GUI_MAP_TOOL_TIP_CANCEL, NULL ); gtk_toolbar_append_widget( GTK_TOOLBAR( toolBar ), btnMapOk, MSG_GUI_MAP_TOOL_TIP_OK, NULL ); gtk_widget_show( btnMapExec ); gtk_widget_show( gMapButtonContExec ); gtk_widget_show( btnMapAutoMark ); gtk_widget_show( btnMapUserMenu ); gtk_widget_show( btnMapSpell ); gtk_widget_show( btnMapSquare ); gtk_widget_show( btnMapCancel ); gtk_widget_show( btnMapOk ); // ツール・バーへのイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( btnMapExec ), "clicked", GTK_SIGNAL_FUNC( handle_exec_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapButtonContExec ), "clicked", GTK_SIGNAL_FUNC( handle_cont_exec_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapAutoMark ), "clicked", GTK_SIGNAL_FUNC( handle_auto_mark_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapUserMenu ), "clicked", GTK_SIGNAL_FUNC( handle_user_menu_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapSpell ), "clicked", GTK_SIGNAL_FUNC( handle_spell_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapSquare ), "clicked", GTK_SIGNAL_FUNC( handle_square_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapCancel ), "clicked", GTK_SIGNAL_FUNC( handle_cancel_clicked ), NULL ); gtk_signal_connect( GTK_OBJECT( btnMapOk ), "clicked", GTK_SIGNAL_FUNC( handle_ok_clicked ), NULL ); // 描画エリアを作成 GtkWidget *pTab = gtk_table_new( 2, 2, FALSE ); gtk_box_pack_start( GTK_BOX( vBox ), pTab, TRUE, TRUE, 0 ); gtk_widget_show( pTab ); gMapDrawingArea = gtk_drawing_area_new(); if( gMapDrawingArea == NULL ){ print_msg( FLG_MSG_ERR, "gtk_drawing_area_new()" ); exit_game( EXIT_FAILURE ); } gtk_drawing_area_size( GTK_DRAWING_AREA( gMapDrawingArea ), MAP_WIN_INIT_WIDTH(), MAP_WIN_INIT_HEIGHT() ); xOpt = (GtkAttachOptions)(GTK_EXPAND | GTK_SHRINK | GTK_FILL); yOpt = (GtkAttachOptions)(GTK_EXPAND | GTK_SHRINK | GTK_FILL); gtk_table_attach( GTK_TABLE( pTab ), gMapDrawingArea, 0, 1, 0, 1, xOpt, yOpt, 0, 0 ); gtk_widget_show( gMapDrawingArea ); // 描画エリアへのイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "expose_event", GTK_SIGNAL_FUNC( handle_map_expose ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "configure_event", GTK_SIGNAL_FUNC( handle_map_configure ), NULL ); // 描画エリアのマウス・モーションのイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "motion_notify_event", GTK_SIGNAL_FUNC( handle_map_motion_notify ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "button_press_event", GTK_SIGNAL_FUNC( handle_map_button_press ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "button_release_event", GTK_SIGNAL_FUNC( handle_map_button_release ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapDrawingArea ), "scroll_event", GTK_SIGNAL_FUNC( handle_map_scroll ), NULL ); gtk_widget_set_events( gMapDrawingArea, (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_SCROLL_MASK) ); // 水平スクロール・バーの調整を作成 gMapHScrollBarAdjustment = gtk_adjustment_new( 0, 0, MAP_PIX_MAX_X(), 1 * TILE_X_SIZE(), AREA_MAX_X * TILE_X_SIZE() / 2, AREA_MAX_X * TILE_X_SIZE() ); if( gMapHScrollBarAdjustment == NULL ){ print_msg( FLG_MSG_ERR, "gtk_adjustment_new()" ); exit_game( EXIT_FAILURE ); } // 水平スクロール・バーの調整のイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( gMapHScrollBarAdjustment ), "changed", GTK_SIGNAL_FUNC( handle_map_scroll_changed ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapHScrollBarAdjustment ), "value_changed", GTK_SIGNAL_FUNC( handle_map_scroll_changed ), NULL ); // 水平スクロール・バーを作成 gMapHScrollBar = gtk_hscrollbar_new( GTK_ADJUSTMENT( gMapHScrollBarAdjustment ) ); if( gMapHScrollBar == NULL ){ print_msg( FLG_MSG_ERR, "gtk_hscrollbar_new()" ); exit_game( EXIT_FAILURE ); } xOpt = (GtkAttachOptions)(GTK_SHRINK | GTK_FILL); yOpt = (GtkAttachOptions)(GTK_FILL); gtk_table_attach( GTK_TABLE( pTab ), gMapHScrollBar, 0, 1, 1, 2, xOpt, yOpt, 0, 0 ); gtk_widget_show( gMapHScrollBar ); // 垂直スクロール・バーの調整を作成 gMapVScrollBarAdjustment = gtk_adjustment_new( 0, 0, MAP_PIX_MAX_Y(), 1 * TILE_Y_SIZE(), AREA_MAX_Y * TILE_Y_SIZE() / 2, AREA_MAX_Y * TILE_Y_SIZE() ); if( gMapVScrollBarAdjustment == NULL ){ print_msg( FLG_MSG_ERR, "gtk_adjustment_new()" ); exit_game( EXIT_FAILURE ); } // 垂直スクロール・バーの調整のイベント・ハンドラを設定 gtk_signal_connect( GTK_OBJECT( gMapVScrollBarAdjustment ), "changed", GTK_SIGNAL_FUNC( handle_map_scroll_changed ), NULL ); gtk_signal_connect( GTK_OBJECT( gMapVScrollBarAdjustment ), "value_changed", GTK_SIGNAL_FUNC( handle_map_scroll_changed ), NULL ); // 垂直スクロール・バーを作成 gMapVScrollBar = gtk_vscrollbar_new( GTK_ADJUSTMENT( gMapVScrollBarAdjustment ) ); if( gMapVScrollBar == NULL ){ print_msg( FLG_MSG_ERR, "gtk_vscrollbar_new()" ); exit_game( EXIT_FAILURE ); } xOpt = (GtkAttachOptions)(GTK_FILL); yOpt = (GtkAttachOptions)(GTK_SHRINK | GTK_FILL); gtk_table_attach( GTK_TABLE( pTab ), gMapVScrollBar, 1, 2, 0, 1, xOpt, yOpt, 0, 0 ); gtk_widget_show( gMapVScrollBar ); // ステータス・バーを作成 statBarMap = gtk_statusbar_new(); if( statBarMap == NULL ){ print_msg( FLG_MSG_ERR, "gtk_statusbar_new()" ); exit_game( EXIT_FAILURE ); } gtk_box_pack_start( GTK_BOX( vBox ), statBarMap, FALSE, FALSE, 0 ); statBarMapContextId = gtk_statusbar_get_context_id( GTK_STATUSBAR( statBarMap ), "Status bar" ); gtk_statusbar_set_has_resize_grip( GTK_STATUSBAR( statBarMap ), TRUE ); statBarMapMesId = gtk_statusbar_push( GTK_STATUSBAR( statBarMap ), statBarMapContextId, "OK" ); gtk_widget_show( statBarMap ); // メイン・ウィンドウを表示 gWinPos[WIN_KIND_MAP].draw( WIN_KIND_MAP ); gtk_drawing_area_size( GTK_DRAWING_AREA( gMapDrawingArea ), MAP_WIN_MIN_WIDTH(), MAP_WIN_MIN_HEIGHT() ); }
void press_btnA() { switch(work) { case MAIN_MENU:into_menu(); break; case BOOK_MENU:{ strcpy(book_name, "book/"); strcat(book_name, file_list[file_list_point]); into_book(book_name, 0); break; } case BOOK_CONFIG:if(!in_pallet) { switch(book_config_point) { case 0: case 1:{ draw_book_config_point(book_config_point, 255, 255, 255); show_pallet(book_config_point); break; } case 4:{ txtbr = temp_r[0]; txtbg = temp_g[0]; txtbb = temp_b[0]; txtfr = temp_r[1]; txtfg = temp_g[1]; txtfb = temp_b[1]; txtdot = temp_dot; if(txt_offset_changed) { txt_now_offset = txt_max_offset * temp_offset_rate / 100; if(txt_now_offset >= txt_max_offset) txt_now_offset -= 20; check_txt_offset(); } } case 5:exit_book_config(); break; } } else if(temp_point == 3) { myGLCD.setColor(temp_r[book_config_point], temp_g[book_config_point], temp_b[book_config_point]); myGLCD.fillRect(146, 2 + 66 * book_config_point, 209, 2 + 66 * book_config_point + 63); in_pallet = false; draw_book_config_point(book_config_point, 255, 0, 0); } break; case MUSIC_MENU:{ strcpy(music_name, file_list[file_list_point]); into_music(music_name); break; } case MUSIC_PLAY: stop_music(); break; case IMAGE_MENU:{ strcpy(image_name, "image/"); strcat(image_name, file_list[file_list_point]); into_image(image_name); break; } case IMAGE_SHOW:switch(image_point) { case 3: image_update(); break; case 4: image_left_spin(); break; case 5: image_right_spin(); break; case 6: image_next(-1); break; case 7: image_next(1); break; } break; case GAME_MENU: { strcpy(game_name, "game/"); strcat(game_name, file_list[file_list_point]); into_game(game_name); break; } case GAME_START:switch(game_menu_point) { case 0: game_start(); break; case 1: show_game_save(); break; case 2: show_game_help(); break; case 3: exit_game(); break; } break; case GAME_CLEAR:if(game_clear_point == 0) clear_cancel(); else clear_save(); break; case FILE_MENU: file_into(); break; case FILE_DELETE: if(file_delete_point == 0) file_no_delete(); else file_yes_delete(); break; case ABOUT_MENU:if(about_menu_point == 0) into_help(); else into_ap(); break; case ABOUT_HELP:show_help(about_help_point); break; } }
int get_char(char *fnam) { int i; int j; FILE *f1; int error; vtype temp; double version; #ifdef USG struct stat buf; struct stat buf2; #else struct stat lbuf; struct stat buf; struct stat buf2; #endif char char_tmp; char char_tmp_array[3]; cave_type *c_ptr; long age; clear_screen(0, 0); no_controlz(); #ifdef USG /* No symbolic links */ if(stat(fnam, &buf) == -1) { sprintf(temp, "Cannot stat file &s", fnam); prt(temp, 0, 0); exit_game(); } #else if((lstat(fnam, &lbuf) == -1) || (stat(fnam, &buf) == -1)) { sprintf(temp, "Cannot stat file %s", fnam); prt(temp, 0, 0); exit_game(); } #endif #ifdef USG /* No symbolic links */ #else if(lbuf.st_ino != buf.st_ino) { sprintf(temp, "Cannot restore from symbolic link %s", fnam); prt(temp, 0, 0); exit_game(); } #endif if(buf.st_nlink != 1) { sprintf(temp, "Too many links to file %s", fnam); prt(temp, 0, 0); exit_game(); } if(chmod(fnam, (IREAD | IWRITE)) == -1) { sprintf(temp, "Can not change file mode for %s", fnam); prt(temp, 0, 0); } f1 = fopen(fnam, "r"); if(f1 == NULL) { sprintf(temp, "Cannot open file %s for reading", fnam); prt(temp, 0, 0); exit_game(); } prt("Restoring Character...", 0, 0); put_qio(); error = 0; error |= !fread((char *)&version, sizeof(version), 1, f1); error |= !fread((char *)&py, sizeof(py), 1, f1); error |= !fread((char *)&char_row, sizeof(char_row), 1, f1); error |= !fread((char *)&char_col, sizeof(char_col), 1, f1); error |= !fread((char *)&inven_ctr, sizeof(inven_ctr), 1, f1); error |= !fread((char *)&inven_weight, sizeof(inven_weight), 1, f1); error |= !fread((char *)&equip_ctr, sizeof(equip_ctr), 1, f1); error |= !fread((char *)&dun_level, sizeof(dun_level), 1, f1); error |= !fread((char *)&missile_ctr, sizeof(missile_ctr), 1, f1); error |= !fread((char *)&mon_tot_mult, sizeof(mon_tot_mult), 1, f1); error |= !fread((char *)&turn, sizeof(turn), 1, f1); error |= !fread((char *)inventory, sizeof(inventory), 1, f1); error |= !fread((char *)magic_spell[py.misc.pclass], sizeof(spell_type), 31, f1); error |= !fread((char *)&cur_height, sizeof(cur_height), 1, f1); error |= !fread((char *)&cur_width, sizeof(cur_width), 1, f1); error |= !fread((char *)&max_panel_rows, sizeof(max_panel_rows), 1, f1); error |= !fread((char *)&max_panel_cols, sizeof(max_panel_cols), 1, f1); for(i = 0; i < MAX_HEIGHT; ++i) { for(j = 0; j < MAX_WIDTH; ++j) { c_ptr = &cave[i][j]; error |= !fread((char *)&c_ptr->cptr, sizeof(c_ptr->cptr), 1, f1); error |= !fread((char *)&c_ptr->tptr, sizeof(c_ptr->tptr), 1, f1); error |= !fread((char *)&char_tmp, sizeof(char_tmp), 1, f1); c_ptr->fval = char_tmp & 0xF; c_ptr->fopen = (char_tmp >> 4) & 0x1; c_ptr->fm = (char_tmp >> 5) & 0x1; c_ptr->pl = (char_tmp >> 6) & 0x1; c_ptr->tl = (char_tmp >> 7) & 0x1; } } error |= !fread((char *)t_list, sizeof(t_list), 1, f1); error |= !fread((char *)&tcptr, sizeof(tcptr), 1, f1); error |= !fread((char *)object_ident, sizeof(object_ident), 1, f1); error |= !fread((char *)m_list, sizeof(m_list), 1, f1); error |= !fread((char *)&mfptr, sizeof(mfptr), 1, f1); error |= !fread((char *)&muptr, sizeof(muptr), 1, f1); if(version == 4.83) { /* insult_cur was a byte in 4.83, but is now a short */ for(i = 0; i < MAX_STORES; ++i) { error |= !fread((char *)&store[i].store_open, sizeof(short), 1, f1); /* This is different */ error |= !fread((char *)&char_tmp, sizeof(char), 1, f1); store[i].insult_cur = (short)char_tmp; error |= !fread((char *)&store[i].owner, sizeof(char), 1, f1); error |= !fread((char *)&store[i].store_ctr, sizeof(char), 1, f1); /* * Quick compatibility hack for a local vax ignore three bytes of * fill character */ error |= !fread((char *)char_tmp_array, sizeof(char), 3, f1); error |= !fread((char *)store[i].store_inven, sizeof(inven_record), STORE_INVEN_MAX, f1); } } else { error |= !fread((char *)store, sizeof(store), 1, f1); } error |= !fread((char *)&buf2, sizeof(buf2), 1, f1); error |= !fread((char *)norm_state, sizeof(norm_state), 1, f1); error |= !fread((char *)randes_state, sizeof(randes_state), 1, f1); error |= !fread((char *)&randes_seed, sizeof(randes_seed), 1, f1); error |= !fread((char *)town_state, sizeof(town_state), 1, f1); error |= !fread((char *)&town_seed, sizeof(town_seed), 1, f1); if(version >= 4.87) { error |= !fread((char *)&panic_save, sizeof(panic_save), 1, f1); } error |= fclose(f1); controlz(); if(buf.st_atime >= (buf2.st_atime + 5)) { sprintf(temp, "File %s has been touched, sorry.", fnam); prt(temp, 0, 0); exit_game(); } if(error) { sprintf(temp, "Error reading in file %s", fnam); prt(temp, 0, 0); exit_game(); } /* * Rotate store inventory, depending on how old the save file is foreach day * or fraction thereof old, call store_maint once must do this before delete * file */ if(stat(fnam, &buf2) == -1) { sprintf(temp, "Cannot stat file %s?", fnam); prt(temp, 0, 0); } else { /* Age in seconds */ age = (long)buf2.st_atime - (long)buf.st_atime; /* Age in days */ age = (age / 86400) + 1; for(i = 0; i < age; ++i) { store_maint(); } } if(unlink(fnam) == -1) { sprintf(temp, "Cannot delete file %s", fnam); prt(temp, 0, 0); exit_game(); } if(panic_save == 1) { sprintf(temp, "This game is from a panic save. Score will not be added to scoreboard."); msg_print(temp); /* Make sure player will see message before change_name is called */ msg_print(" "); } /* * Reidentify objects. * Very inefficient, should write new routine perhaps? */ for(i = 0; i < MAX_OBJECTS; ++i) { if(object_ident[i] == TRUE) { identify(object_list[i]); } } /* * In case restoring a dead character, this can happen if a signal is caught * after a character's hit points go below zero, but before the game ends */ if(py.misc.chp <= -1) { prt("Your character has already died.", 23, 0); strcpy(died_from, "Unknown."); death = 1; } return FALSE; }
void save_char(int exit, int no_ask) { int i; int j; int flag; int error; vtype fnam; vtype temp; double version; struct stat buf; FILE *f1; char char_tmp; cave_type *c_ptr; flag = FALSE; if(!no_ask) { prt("Enter Filename:", 0, 0); if(!get_string(fnam, 0, 16, 60)) { /* Only return if exit TRUE, i.e. this is not a panic save */ if(exit) { return; } else { strcpy(fnam, "MORIACHR.SAV"); } } else if(strlen(fnam) == 0) { /* If get_string succeeded, but returned zero length */ strcpy(fnam, "MORIACHR.SAV"); } } else { strcpy(fnam, "MORIACHR.SAV"); } no_controlz(); /* Open the user's save file -JEW- */ f1 = fopen(fnam, "w"); if(f1 == NULL) { sprintf(temp, "Error creating %s", fnam); msg_print(temp); return; } flag = TRUE; clear_screen(0, 0); prt("Saving character...", 0, 0); put_qio(); version = CUR_VERSION; error = 0; error |= !fwrite((char *)&version, sizeof(version), 1, f1); error |= !fwrite((char *)&py, sizeof(py), 1, f1); error |= !fwrite((char *)&char_row, sizeof(char_row), 1, f1); error |= !fwrite((char *)&char_col, sizeof(char_col), 1, f1); error |= !fwrite((char *)&inven_ctr, sizeof(inven_ctr), 1, f1); error |= !fwrite((char *)&inven_weight, sizeof(inven_weight), 1, f1); error |= !fwrite((char *)&equip_ctr, sizeof(equip_ctr), 1, f1); error |= !fwrite((char *)&dun_level, sizeof(dun_level), 1, f1); error |= !fwrite((char *)&missile_ctr, sizeof(missile_ctr), 1, f1); error |= !fwrite((char *)&mon_tot_mult, sizeof(mon_tot_mult), 1, f1); error |= !fwrite((char *)&turn, sizeof(turn), 1, f1); error |= !fwrite((char *)inventory, sizeof(inventory), 1, f1); error |= !fwrite((char *)magic_spell[py.misc.pclass], sizeof(spell_type), 31, f1); error |= !fwrite((char *)&cur_height, sizeof(cur_height), 1, f1); error |= !fwrite((char *)&cur_width, sizeof(cur_width), 1, f1); error |= !fwrite((char *)&max_panel_rows, sizeof(max_panel_rows), 1, f1); error |= !fwrite((char *)&max_panel_cols, sizeof(max_panel_cols), 1, f1); for(i = 0; i < MAX_HEIGHT; ++i) { for(j = 0; j < MAX_WIDTH; ++j) { c_ptr = &cave[i][j]; char_tmp = c_ptr->fval | (c_ptr->fopen << 4) | (c_ptr->fm << 5) | (c_ptr->pl << 6) | (c_ptr->tl << 7); error |= !fwrite((char *)&c_ptr->cptr, sizeof(c_ptr->cptr), 1, f1); error |= !fwrite((char *)&c_ptr->tptr, sizeof(c_ptr->tptr), 1, f1); error |= !fwrite((char *)&char_tmp, sizeof(char_tmp), 1, f1); } } error |= !fwrite((char *)t_list, sizeof(t_list), 1, f1); error |= !fwrite((char *)&tcptr, sizeof(tcptr), 1, f1); error |= !fwrite((char *)object_ident, sizeof(object_ident), 1, f1); error |= !fwrite((char *)m_list, sizeof(m_list), 1, f1); error |= !fwrite((char *)&mfptr, sizeof(mfptr), 1, f1); error |= !fwrite((char *)&muptr, sizeof(muptr), 1, f1); error |= !fwrite((char *)store, sizeof(store), 1, f1); if(stat(fnam, &buf) == -1) { sprintf(temp, "Can not stat file %s", fnam); msg_print(temp); return; } error |= !fwrite((char *)&buf, sizeof(buf), 1, f1); error |= !fwrite((char *)norm_state, sizeof(norm_state), 1, f1); error |= !fwrite((char *)randes_state, sizeof(randes_state), 1, f1); error |= !fwrite((char *)&randes_seed, sizeof(randes_seed), 1, f1); error |= !fwrite((char *)town_state, sizeof(town_state), 1, f1); error |= !fwrite((char *)&town_seed, sizeof(town_seed), 1, f1); /* This indicates 'cheating' if it is a one */ error |= !fwrite((char *)&panic_save, sizeof(panic_save), 1, f1); error |= fclose(f1); character_saved = 1; if(!wizard1) { if(chmod(fnam, 0) == -1) { sprintf(temp, "Can not change file mode for %s", fnam); msg_print(temp); return; } } /* Make sure user can't touch save file for 5 seconds */ sleep(5); controlz(); if(error) { sprintf(temp, "Error writing to file %s", fnam); prt(temp, 0, 0); prt("Game not saved.", 0, 0); } else if(flag) { sprintf(temp, "Character saved. [Moria Version %lf]", CUR_VERSION); prt(temp, 0, 0); if(exit) { exit_game(); } } }