int ExitEditor() { if (SafetyCheck()) { ModeFlag = 1; } return 1; }
// ----------------------------------------------------------------------------- // Load a situation file which consists of x,y,z, orientation matrix, mine name. int LoadSituation(void) { if (SafetyCheck()) { if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) { checkforext(sit_filename, "SIT"); if (med_load_situation(sit_filename)) return 0; // set_view_target_from_segment(Cursegp); Update_flags = UF_WORLD_CHANGED; // SetPlayerFromCurseg(); med_compress_mine(); init_info = 1; mine_changed = 0; } } return 1; }
// returns 1 if successful // returns 0 if unsuccessful int LoadGameData() { if (SafetyCheck()) { if (ui_get_filename( game_filename, "*.LVL", "LOAD GAME" )) { checkforgamext(game_filename); if (load_level(game_filename)) return 0; Current_level_num = 0; //not a real level gamestate_not_restored = 0; Update_flags = UF_WORLD_CHANGED; Perm_player_position = ConsoleObject->pos; Perm_player_orient = ConsoleObject->orient; Perm_player_segnum = ConsoleObject->segnum; } } return 1; }
int CreateNewMine() { if (SafetyCheck()) { texpage_goto_first(); create_new_mine(); LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix; set_view_target_from_segment(Cursegp); Seg_scale = {DEFAULT_X_SIZE, DEFAULT_Y_SIZE, DEFAULT_Z_SIZE}; Update_flags = UF_WORLD_CHANGED; SetPlayerFromCurseg(); SetPlayerPosition(); //say default is permanant position mine_changed = 0; Found_segs.clear(); Selected_segs.clear(); med_compress_mine(); gamestate = editor_gamestate::none; init_info = 1; ResetFilename(); Game_mode = GM_UNKNOWN; Current_level_num = 1; // make level 1 } return 1; }
int CreateNewMine() { if (SafetyCheck()) { texpage_goto_first(); create_new_mine(); LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix; set_view_target_from_segment(Cursegp); vm_vec_make(&Seg_scale,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE); Update_flags = UF_WORLD_CHANGED; SetPlayerFromCurseg(); SetPlayerPosition(); //say default is permanant position mine_changed = 0; N_found_segs = 0; N_selected_segs = 0; med_compress_mine(); gamestate_not_restored = 0; init_info = 1; ResetFilename(); Game_mode = GM_UNKNOWN; Current_level_num = 0; //0 means not a real game } return 1; }
bool FormatBoot (const std::string &path) { bool fRet = false; // Strip ":0" from end of string auto hdd = HDD::OpenDisk(path.substr(0, path.rfind(':'))); if (!hdd.get() || !hdd->Seek(0)) Error("open"); else if (hdd->SafetyCheck() && hdd->Lock()) { MEMORY mem(hdd->sector_size); if (!hdd->Write(mem, 1)) Error("write"); else fRet = true; hdd->Unlock(); } return fRet; }
//returns flag, true means quit menu void do_option ( int select) { switch (select) { case MENU_NEW_GAME: do_new_game_menu(); break; case MENU_GAME: break; case MENU_DEMO_PLAY: { char demo_file[16]; if (newmenu_get_filename( TXT_SELECT_DEMO, "*.dem", demo_file, 1 )) { newdemo_start_playback(demo_file); } } break; case MENU_LOAD_GAME: #ifdef SHAREWARE do_load_game_menu(); #else state_restore_all(0); #endif break; #ifdef EDITOR case MENU_EDITOR: Function_mode = FMODE_EDITOR; init_cockpit(); break; #endif case MENU_VIEW_SCORES: gr_palette_fade_out( gr_palette,32,0 ); scores_view(-1); break; #ifdef SHAREWARE case MENU_ORDER_INFO: show_order_form(); break; #endif case MENU_QUIT: #ifdef EDITOR if (! SafetyCheck()) break; #endif gr_palette_fade_out( gr_palette,32,0); Function_mode = FMODE_EXIT; break; case MENU_NEW_PLAYER: RegisterPlayer(); //1 == allow escape out of menu break; case MENU_HELP: do_show_help(); break; #ifndef RELEASE case MENU_PLAY_SONG: { int i; char * m[MAX_SONGS]; for (i=0;i<MAX_SONGS;i++) { m[i] = Songs[i].filename; } i = newmenu_listbox( "Select Song", MAX_SONGS, m, 1, NULL ); if ( i > -1 ) { songs_play_song( i, 0 ); } } break; case MENU_LOAD_LEVEL: { newmenu_item m; char text[10]=""; int new_level_num; m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text; newmenu_do( NULL, "Enter level to load", 1, &m, NULL ); new_level_num = atoi(m.text); if (new_level_num!=0 && new_level_num>=Last_secret_level && new_level_num<=Last_level) { gr_palette_fade_out( gr_palette, 32, 0 ); StartNewGame(new_level_num); } break; } #endif case MENU_START_NETGAME: #ifdef NETWORK //temp! #ifndef SHAREWARE load_mission(0); #endif read_player_file(); network_start_game(); #endif break; case MENU_JOIN_NETGAME: //temp! #ifdef NETWORK #ifndef SHAREWARE load_mission(0); #endif read_player_file(); network_join_game(); #endif break; #ifdef NETWORK case MENU_IPX_MULTIPLAYER: do_ipx_multi_player_menu(); break; case MENU_KALI_MULTIPLAYER: do_kali_multi_player_menu(); break; #ifdef SUPPORTS_NET_IP case MENU_IP_MULTIPLAYER: do_ip_multi_player_menu(); break; case MENU_IP_SERV_CONNECT: do_ip_serv_connect_menu(); break; case MENU_MANUAL_IP_JOIN: do_ip_manual_join_menu(); break; #endif case MENU_START_SERIAL: com_main_menu(); break; case MENU_MULTIPLAYER: do_multi_player_menu(); break; #endif //NETWORK case MENU_CONFIG: do_options_menu(); break; case MENU_SHOW_CREDITS: gr_palette_fade_out( gr_palette,32,0); credits_show(); break; default: Error("Unknown option %d in do_option",select); break; } }
// Default event handler for everything except the editor window_event_result standard_handler(const d_event &event) { int key; if (Quitting) { window *wind = window_get_front(); if (!wind) return window_event_result::ignored; // finished quitting if (wind == Game_wind) { int choice; Quitting = 0; choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME ); if (choice != 0) return window_event_result::handled; // aborted quitting else { CGameArg.SysAutoDemo = false; Quitting = 1; } } // Close front window, let the code flow continue until all windows closed or quit cancelled if (!window_close(wind)) { Quitting = 0; return window_event_result::handled; } return window_event_result::deleted; // tell the event system we deleted some window } switch (event.type) { case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: // No window selecting // We stay with the current one until it's closed/hidden or another one is made // Not the case for the editor break; case EVENT_KEY_COMMAND: key = event_key_get(event); switch (key) { #ifdef macintosh case KEY_COMMAND + KEY_SHIFTED + KEY_3: #endif case KEY_PRINT_SCREEN: { gr_set_current_canvas(NULL); save_screen_shot(0); return window_event_result::handled; } case KEY_ALTED+KEY_ENTER: case KEY_ALTED+KEY_PADENTER: if (Game_wind) if (Game_wind == window_get_front()) return window_event_result::ignored; gr_toggle_fullscreen(); return window_event_result::handled; #if defined(__APPLE__) || defined(macintosh) case KEY_COMMAND+KEY_Q: // Alt-F4 already taken, too bad Quitting = 1; return window_event_result::handled; #endif case KEY_SHIFTED + KEY_ESC: con_showup(); return window_event_result::handled; } break; case EVENT_WINDOW_DRAW: case EVENT_IDLE: //see if redbook song needs to be restarted RBACheckFinishedHook(); return window_event_result::handled; case EVENT_QUIT: #if DXX_USE_EDITOR if (SafetyCheck()) #endif Quitting = 1; return window_event_result::handled; default: break; } return window_event_result::ignored; }
bool FormatHdd (const std::string &path) { bool f = false; auto hdd = HDD::OpenDisk(path); /* MEMORY mem(SECTOR_SIZE); // Disk to be made BDOS-bootable? if (opt.boot) { // Provide a default boot sector memcpy(mem, abAtomLiteBoot, sizeof(abAtomLiteBoot)); // Boot sector file supplied? if (*opt.boot) { MFILE file; if (!file.Open(opt.boot)) return Error("boot"); else if (msize(&file) != SECTOR_SIZE) { throw util::exception("boot sector must be exactly 512 bytes"); return false; } else mread(mem, mem.size, 1, &file); } } */ if (!hdd) Error("open"); else if (hdd->SafetyCheck() && hdd->Lock()) { BDOS_CAPS bdc; GetBDOSCaps(hdd->total_sectors, bdc); bdc.need_byteswap = !!opt.byteswap; // A quick format stops after the MGT boot sector in record 1 int64_t total_sectors = opt.quick ? bdc.base_sectors + MGT_DIR_TRACKS*MGT_SECTORS + 1 : hdd->total_sectors; // Format the boot sector and record list f = hdd->Copy(nullptr, bdc.base_sectors, 0, 0, total_sectors, "Formatting"); MEMORY mem(MGT_DISK_SIZE); if (!opt.nosig) memcpy(mem + 232, "BDOS", 4); // Format the record data area for (int64_t uPos = bdc.base_sectors; f; uPos += MGT_DISK_SECTORS, f &= !g_fAbort) { // Determine how much to transfer in one go if (uPos > total_sectors) uPos = total_sectors; auto block_size = std::min(static_cast<int>(total_sectors - uPos), MGT_DISK_SECTORS); Message(msgStatus, "Formatting... %u%%", static_cast<unsigned>(uPos * 100 / total_sectors)); if (!block_size) break; // Locate and write the record block if (!hdd->Seek(uPos) || !hdd->Write(mem, block_size, bdc.need_byteswap)) { // If this is a raw format, report the sector offset if (opt.nosig) Message(msgStatus, "Write error at sector %u: %s", uPos, LastError()); else { // Report the record containing the error Message(msgStatus, "Write error in record %u: %s", 1 + (uPos - bdc.base_sectors) / MGT_DISK_SECTORS, LastError()); // Attempt to clear the BDOS signature in the bad record, to prevent its use MEMORY memblank(hdd->sector_size); hdd->Seek(uPos); hdd->Write(memblank, 1); } } } /* if (opt.boot) { UpdateBDOSBootSector(mem, &hdd); if (!hdd->Seek(0) || !hdd->Write(mem, 1, bdc.fNeedSwap)) return Error("boot"); } */ hdd->Unlock(); } return f; }