// -------------------------------------------------------------------------------- // handle a menu click // -------------------------------------------------------------------------------- bool t_game::menu_click( int id ) { switch (id) { case IDM_EXIT: close_game(); return true; } return false; }
/** * Play Angband */ void play_game(bool new_game) { /* Load a savefile or birth a character, or both */ start_game(new_game); /* Get commands from the user, then process the game world until the * command queue is empty and a new player command is needed */ while (!player->is_dead && player->upkeep->playing) { cmd_get_hook(CMD_GAME); run_game_loop(); } /* Close game on death or quitting */ close_game(); }
CxlnldowsApp::~CxlnldowsApp() { if( m_pMainWnd != NULL ){ m_pMainWnd->DestroyWindow(); delete m_pMainWnd; m_pMainWnd = NULL; } // bowkenken BEGIN #ifdef D_MFC g_Dir3d.Destroy(); #endif // D_MFC close_game( EXIT_SUCCESS ); // bowkenken END }
int main(){ //variaveis que tem alguma coisa a ver com o jogados, como exp recebida e level int game_status = 0, option = 0, school = 0; //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //Variaveis internas relacionadas as bibliotecas usadas e erros do jogo em si. int status_allegro = 0, tecla = 0; //A variavel teclado tem 5 estados /* 0 - Neutro 1 - Tecla para cima 2 - Tecla para Baixo 3 - Tecla para Direita 4 - Tecla para Esquerda */ //iniciando o Allegro e todos as suas bibliotecas e funções usadas. al_init(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_install_keyboard(); //Iniciando o jogo. display = al_create_display(SCREEN_W, SCREEN_H); background = al_load_bitmap("img/background.jpg"); start_menu_img = al_load_bitmap("img/start_screen.jpg"); font_text = al_load_font("font/font.ttf", 50, 0); timer = al_create_timer(0.1); tcont = al_create_timer(1.0); sections_event = al_create_event_queue(); al_set_window_title(display, "M.I.P. - Matemática, Português e Inglês"); al_start_timer(timer); al_start_timer(tcont); //Qualquer valor que seja colocado apos a imagem, ira interferir na sua posição em relação a tela. fadeout(7, SCREEN_W, SCREEN_H, display); al_draw_bitmap(background, 0,0,0); al_flip_display(); //Verificando erros no allegro e suas bibliotecas. status_allegro = check_allegro(background, start_menu_img, sections_event, display, font_text, timer, tcont); if(status_allegro == -1){ close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; } al_register_event_source(sections_event, al_get_keyboard_event_source()); al_register_event_source(sections_event, al_get_display_event_source(display)); //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //menu_background(); fadeout(1, SCREEN_W, SCREEN_H, display); al_draw_bitmap(start_menu_img, 0,0,0); printf("Menu Principal\n"); //capture_event(); al_flip_display(); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / 4, SCREEN_W / 4, ALLEGRO_ALIGN_LEFT, "Novo Jogo"); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / (3.7), SCREEN_W / 3, ALLEGRO_ALIGN_LEFT, "Continuar"); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / (3.4), SCREEN_W / (2.5), ALLEGRO_ALIGN_LEFT, "Sair do jogo"); al_flip_display(); option = capture_event_queue(SCREEN_H, SCREEN_W, keyboard, display, sections_event, tecla, font_text); if(option == -1){ close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; } switch(option){ case 0: game_start(); printf("game_start\n"); break; case 1: game_load(); printf("game_load\n"); break; case 2: printf("Finalizando Jogo\n"); close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; break; } //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //Apos a escolha entre continuar ou começar novamente o usuário estará na tela de seleção de escolas printf("Selecione a escola\n"); scanf("%d", &school); switch(school){ case 0: open_math(); break; case 1: open_ing(); break; case 2: open_port(); break; } //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- return 0; }
/* * Handle signals -- simple (interrupt and quit) * * This function was causing a *huge* number of problems, so it has * been simplified greatly. We keep a global variable which counts * the number of times the user attempts to kill the process, and * we commit suicide if the user does this a certain number of times. * * We attempt to give "feedback" to the user as he approaches the * suicide thresh-hold, but without penalizing accidental keypresses. * * To prevent messy accidents, we should reset this global variable * whenever the user enters a keypress, or something like that. */ static void handle_signal_simple(int sig) { /* Protect errno from library calls in signal handler */ int save_errno = errno; /* Disable handler */ (void)(*signal_aux)(sig, SIG_IGN); /* Nothing to save, just quit */ if (!character_generated || character_saved) quit(NULL); /* Count the signals */ signal_count++; /* Terminate dead characters */ if (p_ptr->is_dead) { /* Mark the savefile */ my_strcpy(p_ptr->died_from, "Abortion", sizeof(p_ptr->died_from)); close_game(); /* Quit */ quit("interrupt"); } /* Allow suicide (after 5) */ else if (signal_count >= 5) { /* Cause of "death" */ my_strcpy(p_ptr->died_from, "Interrupting", sizeof(p_ptr->died_from)); /* Commit suicide */ p_ptr->is_dead = TRUE; /* Stop playing */ p_ptr->playing = FALSE; /* Leaving */ p_ptr->leaving = TRUE; /* Close stuff */ close_game(); /* Quit */ quit("interrupt"); } /* Give warning (after 4) */ else if (signal_count >= 4) { /* Make a noise */ Term_xtra(TERM_XTRA_NOISE, 0); /* Clear the top line */ Term_erase(0, 0, 255); /* Display the cause */ Term_putstr(0, 0, -1, TERM_WHITE, "Contemplating suicide!"); /* Flush */ Term_fresh(); } /* Give warning (after 2) */ else if (signal_count >= 2) { /* Make a noise */ Term_xtra(TERM_XTRA_NOISE, 0); } /* Restore handler */ (void)(*signal_aux)(sig, handle_signal_simple); /* Restore errno */ errno = save_errno; }
int main(int argc, char **argv) { srand(time(NULL)); int err = 0; char homedir[50]; strncpy(homedir, getenv("HOME"), sizeof(homedir)); const char *word_file = argc > 1 ? argv[1] : strncat(homedir, "/.words", sizeof(homedir)); printf("using dictionary file %s\n", word_file); FILE *words = fopen(word_file, "r"); if(!words) { perror("Problem opening file"); return errno; } char secret[35] = {'\0'}; get_word(words, secret); int secret_len = strlen(secret); if(!secret_len) { fprintf(stderr, "Secret word chosen is 0 characters long!\n"); return 1; } if(EOF == fclose(words)) { perror("Error closing dictionary file"); return errno; } stats *stats = malloc(sizeof(*stats)); err = readwrite_stats(stats, "r"); if(err) return err; //prep secret int known[35] = {0}; int used[26] = {0}; // tracks which letters have been tried for(int i=0; i < secret_len; i++) { if(secret[i] >= 'a' && secret[i] <= 'z') secret[i] -= 32; known[i] += (secret[i] == ' '); } int wrong = 0; int guesses = 0; while(wrong < 6) { for(int i=0; i < wrong; i++) printf("%s", man[i]); printf("\n"); for(int i=0; i < secret_len; i++) { if(secret[i] == ' ') printf(" "); else printf("%c ", known[i] ? secret[i] : '_'); } double avg = stats->wins > 0 ? (double)stats->guesses/(double)stats->wins : 0; printf("\n%i Game%s\n%i Win%s\n%.1f Avg. Guess%s per Winning Game\n", stats->games, stats->games == 1 ? "" : "s", stats->wins, stats->wins == 1 ? "" : "s", avg, avg < 1 || avg > 1 ? "es": ""); printf("\nUsed: "); for(int i=0; i < 26; i++) if(used[i]) printf("%c ", i+65); printf("\nGuess: "); char c = getchar(); while('\n' != getchar()); if(system("clear") < 0) fprintf(stderr, "Error clearing screen.\n"); if(c < 'A' || (c > 'Z' && c < 'a') || c > 'z') continue; guesses++; c -= (c >= 'a' && c <= 'z') ? 32 : 0; // Capitalize the guess used[c-'A']++; int flag = 0; for(int i=0; i < secret_len; i++) { flag += (c == secret[i]); known[i] += (c == secret[i]); } wrong += (!flag); int i; for(i=0; i < secret_len; i++) { if(!known[i]) break; } if(i == secret_len) { printf("\n"); for(int i=0; i < secret_len; i++) { if(secret[i] == ' ') printf(" "); else printf("%c ", known[i] ? secret[i] : '_'); } printf("\nYou win!\n"); stats->wins++; stats->games++; stats->guesses += guesses; return close_game(stats); } } printf("You lose! The answer was %s\n", secret); stats->games++; return close_game(stats); }
static int main(int argc, char *argv[]) { if (!PHYSFSX_init(argc, argv)) return 1; con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (CGameArg.SysShowCmdHelp) { print_commandline_help(); return(0); } printf("\nType '%s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); #if defined(DXX_BUILD_DESCENT_I) if (! PHYSFSX_contfile_init("descent.hog", 1)) #define DXX_NAME_NUMBER "1" #define DXX_HOGFILE_NAMES "descent.hog" #elif defined(DXX_BUILD_DESCENT_II) if (! PHYSFSX_contfile_init("descent2.hog", 1) && ! PHYSFSX_contfile_init("d2demo.hog", 1)) #define DXX_NAME_NUMBER "2" #define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog" #endif { #if defined(__unix__) && !defined(__APPLE__) #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \ "\t" SHAREPATH "\n" #else #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tDirectory containing D" DXX_NAME_NUMBER "X\n" #endif #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) #define DXX_HOGFILE_APPLICATION_BUNDLE \ "\tIn 'Resources' inside the application bundle\n" #else #define DXX_HOGFILE_APPLICATION_BUNDLE "" #endif #define DXX_MISSING_HOGFILE_ERROR_TEXT \ "Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \ DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." UserError(DXX_MISSING_HOGFILE_ERROR_TEXT); } #if defined(DXX_BUILD_DESCENT_I) switch (PHYSFSX_fsize("descent.hog")) { case D1_MAC_SHARE_MISSION_HOGSIZE: case D1_MAC_MISSION_HOGSIZE: MacHog = 1; // used for fonts and the Automap break; } #endif load_text(); //print out the banner title #if defined(DXX_BUILD_DESCENT_I) con_printf(CON_NORMAL, "%s %s", DESCENT_VERSION, g_descent_build_datetime); // D1X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 2005-2013 Christian Beckhaeuser"); #elif defined(DXX_BUILD_DESCENT_II) con_printf(CON_NORMAL, "%s%s %s", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2013 Christian Beckhaeuser"); #endif if (CGameArg.DbgVerbose) con_puts(CON_VERBOSE, TXT_VERBOSE_1); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(CGameArg.DbgTexMap); #if defined(DXX_BUILD_DESCENT_II) Lighting_on = 1; #endif con_printf(CON_VERBOSE, "Going into graphics mode..."); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system..." ); #if defined(DXX_BUILD_DESCENT_I) gr_use_palette_table( "PALETTE.256" ); #elif defined(DXX_BUILD_DESCENT_II) gr_use_palette_table(D2_DEFAULT_PALETTE ); #endif con_printf(CON_DEBUG, "Initializing font system..." ); gamefont_init(); // must load after palette data loaded. #if defined(DXX_BUILD_DESCENT_II) con_printf( CON_DEBUG, "Initializing movie libraries..." ); init_movies(); //init movie libraries #endif show_titles(); set_screen_mode(SCREEN_MENU); #ifdef DEBUG_MEMORY_ALLOCATIONS /* Memdebug runs before global destructors, so it incorrectly * reports as leaked any allocations that would be freed by a global * destructor. This local will force the newmenu globals to be * reset before memdebug scans, which prevents memdebug falsely * reporting them as leaked. * * External tools, such as Valgrind, know to run global destructors * before checking for leaks, so this hack is only necessary when * memdebug is used. */ struct hack_free_global_backgrounds { ~hack_free_global_backgrounds() { newmenu_free_background(); } }; hack_free_global_backgrounds hack_free_global_background; #endif con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (GameArg.EdiSaveHoardData) { save_hoard_data(); exit(1); } #endif #endif if (CGameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init(); // 10 cache bitmaps #if defined(DXX_BUILD_DESCENT_II) piggy_init_pigfile("groupa.pig"); //get correct pigfile #endif con_printf( CON_DEBUG, "\nRunning game..." ); init_game(); get_local_player().callsign = {}; #if defined(DXX_BUILD_DESCENT_I) key_flush(); #elif defined(DXX_BUILD_DESCENT_II) // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR if (!GameArg.EdiAutoLoad.empty()) { Players[0].callsign = "dummy"; } else #endif #endif { if (!CGameArg.SysPilot.empty()) { char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4]; /* Step over the literal PLAYER_DIRECTORY_TEXT when it is * present. Point at &filename[0] when * PLAYER_DIRECTORY_TEXT is absent. */ const auto b = &filename[-CGameArg.SysUsePlayersDir]; snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), CGameArg.SysPilot.c_str()); /* The pilot name is never used after this. Clear it to * free the allocated memory, if any. */ CGameArg.SysPilot.clear(); auto p = b; for (const auto &facet = std::use_facet<std::ctype<char>>(std::locale::classic()); char &c = *p; ++p) { c = facet.tolower(static_cast<uint8_t>(c)); } auto j = p - filename; if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it { strcpy(&filename[j], ".plr"); j += 4; } if(PHYSFSX_exists(filename,0)) { get_local_player().callsign.copy(b, std::distance(b, &filename[j - 4])); read_player_file(); WriteConfigFile(); } } } #if defined(DXX_BUILD_DESCENT_II) #if DXX_USE_EDITOR if (!GameArg.EdiAutoLoad.empty()) { /* Any number >= FILENAME_LEN works */ Level_names[0].copy_if(GameArg.EdiAutoLoad.c_str(), GameArg.EdiAutoLoad.size()); LoadLevel(1, 1); } else #endif #endif { Game_mode = GM_GAME_OVER; DoMenu(); } while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup..." ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); Current_mission.reset(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
int main(int argc, char *argv[]) { char *rom_name; #ifdef __AMIGA__ BPTR file_lock = GetProgramDir(); SetProgramDir(file_lock); #endif signal(SIGSEGV, catch_me); #ifdef WII // SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE); fatInitDefault(); #endif cf_init(); /* must be the first thing to do */ cf_init_cmd_line(); cf_open_file(NULL); /* Open Default configuration file */ rom_name=cf_parse_cmd_line(argc,argv); /* print effect/blitter list if asked by user */ if (!strcmp(CF_STR(cf_get_item_by_name("effect")),"help")) { print_effect_list(); exit(0); } if (!strcmp(CF_STR(cf_get_item_by_name("blitter")),"help")) { print_blitter_list(); exit(0); } init_sdl(); /* GP2X stuff */ #ifdef GP2X gp2x_init(); #endif if (gn_init_skin()!=SDL_TRUE) { printf("Can't load skin...\n"); exit(1); } reset_frame_skip(); if (conf.debug) conf.sound=0; /* Launch the specified game, or the rom browser if no game was specified*/ if (!rom_name) { // rom_browser_menu(); run_menu(); printf("GAME %s\n",conf.game); if (conf.game==NULL) return 0; } else { if (init_game(rom_name)!=SDL_TRUE) { printf("Can't init %s...\n",rom_name); exit(1); } } /* If asked, do a .gno dump and exit*/ if (CF_BOOL(cf_get_item_by_name("dump"))) { char dump[8+4+1]; sprintf(dump,"%s.gno",rom_name); dr_save_gno(&memory.rom,dump); close_game(); return 0; } if (conf.debug) debug_loop(); else main_loop(); close_game(); return 0; }
int main(int argc, char *argv[]) { mem_init(); #ifdef __LINUX__ error_init(NULL); #else error_init(msgbox_error); set_warn_func(msgbox_warning); #endif PHYSFSX_init(argc, argv); con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (GameArg.SysShowCmdHelp) { print_commandline_help(); return(0); } printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); if (! PHYSFSX_contfile_init("descent2.hog", 1)) { if (! PHYSFSX_contfile_init("d2demo.hog", 1)) #define DXX_NAME_NUMBER "2" #define DXX_HOGFILE_NAMES "descent2.hog or d2demo.hog" #if defined(__unix__) && !defined(__APPLE__) #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n" \ "\t" SHAREPATH "\n" #else #define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tDirectory containing D" DXX_NAME_NUMBER "X\n" #endif #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) #define DXX_HOGFILE_APPLICATION_BUNDLE \ "\tIn 'Resources' inside the application bundle\n" #else #define DXX_HOGFILE_APPLICATION_BUNDLE "" #endif #define DXX_MISSING_HOGFILE_ERROR_TEXT \ "Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n" \ DXX_HOGFILE_PROGRAM_DATA_DIRECTORY \ "\tIn a subdirectory called 'Data'\n" \ DXX_HOGFILE_APPLICATION_BUNDLE \ "Or use the -hogdir option to specify an alternate location." Error(DXX_MISSING_HOGFILE_ERROR_TEXT); } load_text(); //print out the banner title con_printf(CON_NORMAL, "%s%s %s\n", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? " Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.\n", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2011 Christian Beckhaeuser\n\n"); if (GameArg.DbgVerbose) con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n"); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(GameArg.DbgTexMap); Lighting_on = 1; con_printf(CON_VERBOSE, "Going into graphics mode...\n"); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system...\n" ); gr_use_palette_table(D2_DEFAULT_PALETTE ); con_printf(CON_DEBUG, "Initializing font system...\n" ); gamefont_init(); // must load after palette data loaded. set_default_handler(standard_handler); con_printf( CON_DEBUG, "Initializing movie libraries...\n" ); init_movies(); //init movie libraries show_titles(); set_screen_mode(SCREEN_MENU); con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); #ifdef EDITOR if (GameArg.EdiSaveHoardData) { save_hoard_data(); exit(1); } #endif if (GameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init( 10 ); // 10 cache bitmaps piggy_init_pigfile("groupa.pig"); //get correct pigfile con_printf( CON_DEBUG, "\nRunning game...\n" ); init_game(); Players[Player_num].callsign[0] = '\0'; // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR if (GameArg.EdiAutoLoad) { strcpy(Auto_file, GameArg.EdiAutoLoad); strcpy(Players[0].callsign, "dummy"); } else #endif { if(GameArg.SysPilot) { char filename[32] = ""; int j; if (GameArg.SysUsePlayersDir) strcpy(filename, "Players/"); strncat(filename, GameArg.SysPilot, 12); filename[8 + 12] = '\0'; // unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n' for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) { switch (filename[j]) { case ' ': filename[j] = '\0'; } } if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it strcat(filename,".plr"); if(PHYSFSX_exists(filename,0)) { strcpy(strstr(filename,".plr"),"\0"); strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename); read_player_file(); WriteConfigFile(); } } } #ifdef EDITOR if (GameArg.EdiAutoLoad) { strcpy((char *)&Level_names[0], Auto_file); LoadLevel(1, 1); } else #endif { Game_mode = GM_GAME_OVER; DoMenu(); } setjmp(LeaveEvents); while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup...\n" ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); free_text(); args_exit(); newmenu_free_background(); free_mission(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
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; }
int main(int argc, char *argv[]) { mem_init(); #ifdef __LINUX__ error_init(NULL, NULL); #else error_init(msgbox_error, NULL); set_warn_func(msgbox_warning); #endif PHYSFSX_init(argc, argv); con_init(); // Initialise the console setbuf(stdout, NULL); // unbuffered output via printf #ifdef _WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif if (GameArg.SysShowCmdHelp) { print_commandline_help(); set_exit_message(""); return(0); } printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME); PHYSFSX_listSearchPathContent(); if (!PHYSFSX_checkSupportedArchiveTypes()) return(0); if (! PHYSFSX_contfile_init("descent.hog", 1)) Error("Could not find a valid hog file (descent.hog)\nPossible locations are:\n" #if defined(__unix__) && !defined(__APPLE__) "\t$HOME/.d1x-rebirth\n" "\t" SHAREPATH "\n" #else "\tDirectory containing D1X\n" #endif "\tIn a subdirectory called 'Data'\n" #if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh) "\tIn 'Resources' inside the application bundle\n" #endif "Or use the -hogdir option to specify an alternate location."); switch (PHYSFSX_fsize("descent.hog")) { case D1_MAC_SHARE_MISSION_HOGSIZE: case D1_MAC_MISSION_HOGSIZE: MacHog = 1; // used for fonts and the Automap break; } load_text(); //print out the banner title con_printf(CON_NORMAL, "%s", DESCENT_VERSION); // D1X version con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__); con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.\n", BASED_VERSION); con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK); con_printf(CON_NORMAL, "Copyright (C) 2005-2011 Christian Beckhaeuser\n\n"); if (GameArg.DbgVerbose) con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n"); ReadConfigFile(); PHYSFSX_addArchiveContent(); arch_init(); select_tmap(GameArg.DbgTexMap); con_printf(CON_VERBOSE, "Going into graphics mode...\n"); gr_set_mode(Game_screen_mode); // Load the palette stuff. Returns non-zero if error. con_printf(CON_DEBUG, "Initializing palette system...\n" ); gr_use_palette_table( "PALETTE.256" ); con_printf(CON_DEBUG, "Initializing font system...\n" ); gamefont_init(); // must load after palette data loaded. set_default_handler(standard_handler); show_titles(); set_screen_mode(SCREEN_MENU); con_printf( CON_DEBUG, "\nDoing gamedata_init..." ); gamedata_init(); if (GameArg.DbgNoRun) return(0); con_printf( CON_DEBUG, "\nInitializing texture caching system..." ); texmerge_init( 10 ); // 10 cache bitmaps con_printf( CON_DEBUG, "\nRunning game...\n" ); init_game(); Players[Player_num].callsign[0] = '\0'; key_flush(); if(GameArg.SysPilot) { char filename[32] = ""; int j; if (GameArg.SysUsePlayersDir) strcpy(filename, "Players/"); strncat(filename, GameArg.SysPilot, 12); filename[8 + 12] = '\0'; // unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n' for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) { switch (filename[j]) { case ' ': filename[j] = '\0'; } } if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it strcat(filename,".plr"); if(PHYSFSX_exists(filename,0)) { strcpy(strstr(filename,".plr"),"\0"); strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename); read_player_file(); WriteConfigFile(); } } Game_mode = GM_GAME_OVER; DoMenu(); setjmp(LeaveEvents); while (window_get_front()) // Send events to windows and the default handler event_process(); // Tidy up - avoids a crash on exit { window *wind; show_menus(); while ((wind = window_get_front())) window_close(wind); } WriteConfigFile(); show_order_form(); con_printf( CON_DEBUG, "\nCleanup...\n" ); close_game(); texmerge_close(); gamedata_close(); gamefont_close(); free_text(); args_exit(); newmenu_free_background(); free_mission(); PHYSFSX_removeArchiveContent(); return(0); //presumably successful exit }
/* true return value indicates that connection must be closed */ int process_msg(int fd, char* msg) { int client_proto_major; int client_proto_minor; char * args; char * ptr, * ptr2; char * msg_orig; /* check for leading protocol tag */ if (!str_begins_static_str(msg, "FB/") || strlen(msg) < 8) { // 8 stands for "FB/M.m f"(oo) send_line_log(fd, fl_line_unrecognized, msg); return 1; } /* check if client protocol is compatible; for simplicity, we don't support client protocol more recent * than server protocol, we suppose that our servers are upgraded when a new release appears (but of * course client protocol older is supported within the major protocol) */ client_proto_major = charstar_to_int(msg + 3); client_proto_minor = charstar_to_int(msg + 5); if (client_proto_major != proto_major || client_proto_minor > proto_minor) { send_line_log(fd, fl_proto_mismatch, msg); return 1; } if (remote_proto_minor[fd] == -1) remote_proto_minor[fd] = client_proto_minor; msg_orig = strdup(msg); /* after protocol, first word is command, then possible args */ current_command = msg + 7; // 7 stands for "FB/M.m " if ((ptr = strchr(current_command, ' '))) { *ptr = '\0'; args = current_command + strlen(current_command) + 1; } else args = NULL; if (streq(current_command, "PING")) { send_line_log(fd, ok_pong, msg_orig); } else if (streq(current_command, "NICK")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { if ((ptr = strchr(args, ' '))) *ptr = '\0'; if (strlen(args) > 10) args[10] = '\0'; if (!is_nick_ok(args)) { send_line_log(fd, wn_nick_invalid, msg_orig); } else { if (nick[fd] != NULL) { free(nick[fd]); } nick[fd] = strdup(args); calculate_list_games(); send_ok(fd, msg_orig); } } } else if (streq(current_command, "GEOLOC")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { if ((ptr = strchr(args, ' '))) *ptr = '\0'; if (strlen(args) > 13) // sign, 4 digits, dot, colon, sign, 4 digits, dot args[13] = '\0'; if (geoloc[fd] != NULL) { free(geoloc[fd]); } geoloc[fd] = strdup(args); calculate_list_games(); send_ok(fd, msg_orig); } } else if (streq(current_command, "CREATE")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { if ((ptr = strchr(args, ' '))) *ptr = '\0'; if (strlen(args) > 10) args[10] = '\0'; if (!is_nick_ok(args)) { send_line_log(fd, wn_nick_invalid, msg_orig); } else if (!nick_available(args)) { send_line_log(fd, wn_nick_in_use, msg_orig); } else if (already_in_game(fd)) { send_line_log(fd, wn_already_in_game, msg_orig); } else if (games_open == 16) { // FB client can display 16 max send_line_log(fd, wn_max_open_games, msg_orig); } else { create_game(fd, strdup(args)); send_ok(fd, msg_orig); } } } else if (streq(current_command, "JOIN")) { if (!args || !(ptr = strchr(args, ' '))) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { struct game * g; char* nick = ptr + 1; *ptr = '\0'; if ((ptr2 = strchr(ptr, ' '))) *ptr2 = '\0'; if (strlen(nick) > 10) nick[10] = '\0'; if (!is_nick_ok(nick)) { send_line_log(fd, wn_nick_invalid, msg_orig); } else if (!nick_available(nick)) { send_line_log(fd, wn_nick_in_use, msg_orig); } else if (already_in_game(fd)) { send_line_log(fd, wn_already_in_game, msg_orig); } else if (!(g = find_game_by_nick(args))) { send_line_log(fd, wn_no_such_game, msg_orig); } else { if (add_player(g, fd, strdup(nick))) send_ok(fd, msg_orig); else send_line_log(fd, wn_game_full, msg_orig); } } } else if (streq(current_command, "KICK")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { if ((ptr = strchr(args, ' '))) *ptr = '\0'; if (strlen(args) > 10) args[10] = '\0'; if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { struct game * g = find_game_by_fd(fd); if (g->players_conn[0] != fd) { send_line_log(fd, wn_not_creator, msg_orig); } else { kick_player(fd, g, args); } } } } else if (streq(current_command, "PART")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { player_part_game(fd); send_ok(fd, msg_orig); } } else if (streq(current_command, "LIST")) { send_line_log(fd, list_games_str, msg_orig); } else if (streq(current_command, "STATUS")) { // 1.0 command if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { status(fd, msg_orig); } } else if (streq(current_command, "STATUSGEO")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { status_geo(fd, msg_orig); } } else if (streq(current_command, "PROTOCOL_LEVEL")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { protocol_level(fd, msg_orig); } } else if (streq(current_command, "TALK")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else { talk(fd, args); } } else if (streq(current_command, "START")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { start_game(fd); } } else if (streq(current_command, "CLOSE")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { close_game(fd); } } else if (streq(current_command, "SETOPTIONS")) { if (!args) { send_line_log(fd, wn_missing_arguments, msg_orig); } else if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { setoptions(fd, args); } } else if (streq(current_command, "LEADER_CHECK_GAME_START")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { leader_check_game_start(fd); } } else if (streq(current_command, "OK_GAME_START")) { if (!already_in_game(fd)) { send_line_log(fd, wn_not_in_game, msg_orig); } else { ok_start_game(fd); } } else if (streq(current_command, "ADMIN_REREAD")) { if (!admin_authorized[fd]) { send_line_log(fd, wn_denied, msg_orig); } else { reread(); send_ok(fd, "ADMIN_REREAD"); } } else { send_line_log(fd, wn_unknown_command, msg); } free(msg_orig); current_command = NULL; return 0; }