Пример #1
0
//---------- Begin of function Game::main_menu ----------//
//
void Game::main_menu()
{
	enum { MAIN_OPTION_COUNT = 6 };

	static OptionInfo main_option_array[MAIN_OPTION_COUNT] =
	{
		{ 6+SWORD1_X,  11+SWORD1_Y, 282+SWORD1_X ,  63+SWORD1_Y },
		{ 6+SWORD1_X,  68+SWORD1_Y, 282+SWORD1_X , 113+SWORD1_Y },
		{ 6+SWORD1_X, 121+SWORD1_Y, 282+SWORD1_X , 176+SWORD1_Y },
		// ####### begin Gilbert 20/10 ######//
		// { 6+SWORD1_X, 189+SWORD1_Y, 282+SWORD1_X , 219+SWORD1_Y },
		{ 6+SWORD1_X, 184+SWORD1_Y, 282+SWORD1_X , 222+SWORD1_Y },
		// ####### end Gilbert 20/10 ######//
		{ 6+SWORD1_X, 224+SWORD1_Y, 282+SWORD1_X , 295+SWORD1_Y },
		{40+SWORD1_X, 297+SWORD1_Y, 254+SWORD1_X , 337+SWORD1_Y },
	};

	char main_option_flag[MAIN_OPTION_COUNT] = 
	{
		1, 1, 1, 1, 1, 1,
	};

	// test sys.game_version, skip single player
	main_option_flag[0] = (sys.game_version == VERSION_MULTIPLAYER_ONLY) ? 0 : 1;
//	main_option_flag[0] = 1;

	// ###### begin Gilbert 25/9 #######//
#ifdef DISABLE_MULTI_PLAYER
	// disable multiplayer game, Game::multi_player_menu is disabled
	main_option_flag[1] = 0;
#endif
	// ###### end Gilbert 25/9 #######//

	// skip encyclopedia if not found
	main_option_flag[2] = *sys.dir_encyc ? 1 : 0;

	//------------- display menu options -------------//

	int refreshFlag=1, i;

	mouse_cursor.set_icon(CURSOR_NORMAL);
	vga_front.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_BLACK);
	OptionInfo* optionInfo;
	char *menuBitmap = NULL;
	char *brightBitmap = NULL;
	char *darkBitmap = NULL;
	int pointingOption = -1;

	while(1)
	{
		game_mode = GAME_PREGAME;

		//------- Display game title and paint menu box --------//

		if( refreshFlag )
		{
			mouse_cursor.set_icon(CURSOR_NORMAL);

			image_interface.put_to_buf( &vga_back, "M_MAIN" );

			vga_util.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1);	// blt the main menu screen from the back buffer to the front buffer

			disp_version();

			if(!menuBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-1", resSize);
				menuBitmap = mem_add(resSize);
				resFile->file_read(menuBitmap, resSize);
			}
			if(!brightBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-1B", resSize);
				brightBitmap = mem_add(resSize);
				resFile->file_read(brightBitmap, resSize);
			}
			if(!darkBitmap)
			{
				int resSize;
				File *resFile;
				resFile = image_interface.get_file("SWRD-1C", resSize);
				darkBitmap = mem_add(resSize);
				resFile->file_read(darkBitmap, resSize);
			}
			
			for( i = 0; i < MAIN_OPTION_COUNT; ++i )
			{
				if( main_option_flag[i] >= 0 )
				{
					mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
						main_option_array[i].x2, main_option_array[i].y2);
					vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, 
						main_option_flag[i] ? menuBitmap : darkBitmap,
						main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
						main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
					mouse.show_area();
				}
			}
			pointingOption = -1;
			refreshFlag=0;
		}

		if( config.music_flag )
		{
			if( !music.is_playing(1) )
				music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
		}
		else
		{
			music.stop();
		}

		// display main menu
		int newPointingOption = -1;
		for(i = 0, optionInfo = main_option_array; i < MAIN_OPTION_COUNT; ++i, ++optionInfo)
		{
			if( main_option_flag[i] > 0 &&
				mouse.in_area(optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2) )
			{
				newPointingOption = i;
				break;
			}
		}

		if( pointingOption != newPointingOption)
		{
			err_when( !menuBitmap );
			err_when( !brightBitmap );
			err_when( !darkBitmap );

			// put un-highlighted option back
			i = pointingOption;
			if( i >= 0 && i < MAIN_OPTION_COUNT )
			{
				mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
					main_option_array[i].x2, main_option_array[i].y2);
				vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, menuBitmap,
					main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
					main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
				mouse.show_area();
			}

			// put new hightlighted option
			i = newPointingOption;
			if( i >= 0 && i < MAIN_OPTION_COUNT )
			{
				mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
					main_option_array[i].x2, main_option_array[i].y2);
				vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, brightBitmap,
					main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
					main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
				mouse.show_area();
			}
			pointingOption = newPointingOption;
		}
		// ######### end Gilbert 23/7 ##########//

		sys.blt_virtual_buf();		// blt the virtual front buffer to the screen

		//---------- detect buttons -----------//

		sys.yield();
		mouse.get_event();

		optionInfo = main_option_array;

		sys.signal_exit_flag = 0;

		for( i=0 ; i<MAIN_OPTION_COUNT ; i++, optionInfo++ )
		{
			if( main_option_flag[i] > 0 && 
				mouse.single_click( optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2 ) )
			{
				// ------- free some resource for a moment --------//
				if( menuBitmap )
				{
					mem_del(menuBitmap);
					menuBitmap = NULL;
				}
				if( brightBitmap)
				{
					mem_del(brightBitmap);
					brightBitmap = NULL;
				}
				if( darkBitmap)
				{
					mem_del(darkBitmap);
					darkBitmap = NULL;
				}

				run_main_menu_option(i+1);
				refreshFlag=1;
				break;
			}
		}

		//-------------------------------------//

		if( sys.signal_exit_flag == 1 || i == MAIN_OPTION_COUNT-1 )			// quit the system now
			break;
	}

	//--------------------------------------//

	music.stop();

	if( menuBitmap )
		mem_del(menuBitmap);

	if( brightBitmap)
		mem_del(brightBitmap);

	if( darkBitmap)
		mem_del(darkBitmap);

	//--------------------------------------//

}
Пример #2
0
int ACEApp::init(int argc, ACE_TCHAR* argv[])
{
    // get the program name
#ifdef WIN32
    char* ptr = ACE_OS::strrchr(argv[0], '\\');
#else
    char* ptr = ACE_OS::strrchr(argv[0], '/');
#endif    
    if (ptr)
    {
        // strip path name
        strcpy(program_, ptr + 1);
    }
    else
    {
        strcpy(program_, argv[0]);
    }
#ifdef WIN32
    // strip .exe extension on WIN32
    ptr = strchr(program_, '.');
    if (ptr)
    {
        *ptr = '\0';
    }
#endif

    int child_proc_num = 0;
    ACE_Get_Opt get_opt(argc, argv, "vdp:c:"); 
    char c;
    while ((c = get_opt()) != EOF)
    {
        switch (c)
        {
            case 'd': // run as daemon
                ACE::daemonize();
                break;
            case 'p': // specified program name
                strcpy(program_, get_opt.opt_arg());
                break;
            case 'c': // child process number
                child_proc_num = atoi(get_opt.opt_arg());
                break;
            case 'v':
                //disp version info
                disp_version();
                return 0;
            default:
                break;
        }
    }

    ACE_OS::signal (SIGPIPE, SIG_IGN);
    ACE_OS::signal (SIGTERM, SIG_IGN);
    ACE_OS::signal (SIGCHLD, SIG_IGN);
    ACE_Sig_Action sig_int((ACE_SignalHandler)daemon_quit, SIGINT);
    //ACE_Sig_Action sig_term((ACE_SignalHandler)daemon_quit, SIGTERM);
    //ACE_Sig_Action sig_chld((ACE_SignalHandler)child_sighdr, SIGCHLD);
    ACE_UNUSED_ARG(sig_int);
    //ACE_UNUSED_ARG(sig_term);
    //ACE_UNUSED_ARG(sig_chld);
    
    //在 init_log() 之前即可    
    if (init_reactor() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init reactor failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init reactor succ\n"));

    if (init_sys_path(program_) != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init sys path failed, program exit\n"));
        return -1;
    }

    if (init_conf() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init conf failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init conf succeed\n"));

    if (init_log() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init log failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init log succ\n"));
    
    //版本信息记录日志
    disp_version();

    if (init_app(argc, argv) != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init app failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init app succ\n"));

    write_pid_file();
    ACE_DEBUG((LM_INFO, "[%D] write pid file succ\n"));

    if (child_proc_num > 0)
    {
        parent_main(child_proc_num);
    }
    else
    {
        ACE_DEBUG((LM_INFO, "[%D] enter daemon main pid: %d\n",
            ACE_OS::getpid()));

        daemon_main();

        ACE_DEBUG((LM_INFO, "[%D] leave daemon main pid: %d\n",
            ACE_OS::getpid()));
    }

    quit_app();

    return 0;
}
Пример #3
0
void Game::main_menu()
{
	char optionFlag[5] = 
	{
		1, 1, 1, 1, 1,
	};

	// ----- disable some option -------//

	// test sys.game_version, skip single player and scenario editor
	optionFlag[0] = optionFlag[2] =
		(sys.game_version == VERSION_MULTIPLAYER_ONLY) ? 0 : 1;

	int emptyProfileTesting = 1;

	mouse_cursor.set_icon(CURSOR_NORMAL);
	vga_buffer.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_BLACK);

	{
		VgaFrontLock vgaLock;

		while(1)
		{
			if (!process_messages()) return;

			VgaFrontReLock vgaReLock;

			// -------- check auto load game request ------//

			// -------- display ----------//

			game_mode = GAME_PREGAME;

			vga.disp_image_file("M_main");

			// ------ display button -------//

			if( player_profile.is_registered() )
			{
				if( optionFlag[0] > 0 )		// single player
					font_thin_black.center_put_paragraph(
						BUTTON1_X1, BUTTON1_Y1, BUTTON1_X2, BUTTON1_Y2, 
						text_game_menu.str_single_player(), 0);
				if( optionFlag[1] > 0 )		// multi player
					font_thin_black.center_put_paragraph(
						BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2, 
						text_game_menu.str_multi_player(), 0);
				if( optionFlag[2] > 0 )		// scenario editor
					font_thin_black.center_put_paragraph(
						BUTTON3_X1, BUTTON3_Y1, BUTTON3_X2, BUTTON3_Y2, 
						text_game_menu.str_scenario_editor(), 0);
			}
			if( optionFlag[3] > 0 )
				font_thin_black.center_put_paragraph(
					BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2, 
					text_game_menu.str_hall_of_fame(), 0);
			if( optionFlag[4] > 0 )
				font_thin_black.center_put_paragraph(
					BUTTON5_X1, BUTTON5_Y1, BUTTON5_X2, BUTTON5_Y2, 
					text_game_menu.str_credits(), 0);
			font_thin_black.center_put_paragraph(
				BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2, 
				text_game_menu.str_player_register(), 0);
			font_thin_black.center_put_paragraph(
				BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2, 
				text_game_menu.str_quit(), 0);
			font_thin_black.center_put_paragraph(
				BUTTONA_X1, BUTTONA_Y1, BUTTONA_X2, BUTTONA_Y2, 
				text_game_menu.str_web_site(), 0);

			disp_version();

			String resStr;

			if( !DisplayModeInfo::get_display_info(config.display_mode_id) )
				config.display_mode_id = 0;

			resStr  = DisplayModeInfo::get_display_info(config.display_mode_id)->screen_width;
			resStr += "X";
			resStr += DisplayModeInfo::get_display_info(config.display_mode_id)->screen_height;

			font_thin_black.center_put( BUTTON9_X1, BUTTON9_Y1, BUTTON9_X2, BUTTON9_Y2, resStr );

			disp_version();

                        vga.flip();

			sys.yield();
			mouse.get_event();
			if( config.music_flag )
			{
				if( !music.is_playing(3) )
					music.play(3, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
			}
			else
			{
				music.stop();
			}

			sys.signal_exit_flag = 0;

			// -------- auto load game on request --------//

			if( auto_load_file_name )
			{
				int rc = game_file.load_game(NULL, auto_load_file_name);		// auto_load_file_name has the full path, no need to give path
				clear_load_game_in_main_menu();
				if( rc > 0 )
				{
					battle.run_loaded();
					deinit_all();
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();   // game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;
				}

				continue;
			}

			// ---------- detect new user ---------//

			if( emptyProfileTesting )		// do this testing only once
			{
				emptyProfileTesting = 0;

				if( PlayerProfile::load_count_profiles( NULL, 1) == 0 )		// maxLoad=1 for fast testing
				{
					box.msg( text_game_menu.str_first_welcome() );

					// run_main_menu_option(0);			don't call run_main_menu_option, we can't get it detect new profile
					if( player_profile.register_menu() == 1	// return 1 = new profile created
						&& player_profile.is_registered() 		// check is_registered for safety
						&& box.ask(text_game_menu.str_first_training()) )		// ask continue training
					{
						// ##### patch begin Gilbert 4/10 #####//
						game_file_array.init( player_profile.save_game_path(NULL), "*.sav" );	// necessary to set the path and extension
						// ##### patch end Gilbert 4/10 #####//
						tutor.building_size = 2;	// default small building size
						tutor.run( 2, 0 );			// 2 - is the first fryhtan training tutorial id, 0 - not inGameCall
					}
				}

				if( sys.signal_exit_flag == 1 )
					break;
				else
					continue;
			}

			// -------- detect --------//

			if( player_profile.is_registered() && optionFlag[0] > 0
				&& mouse.single_click(BUTTON1_X1, BUTTON1_Y1, BUTTON1_X2, BUTTON1_Y2) )
			{
				run_main_menu_option(1);		// single player
			}
			else if( player_profile.is_registered() && optionFlag[1] > 0
				&& mouse.single_click(BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2) )
			{
				run_main_menu_option(2);		// multi player
			}
			else if( player_profile.is_registered() && optionFlag[2] > 0
				&& mouse.single_click(BUTTON3_X1, BUTTON3_Y1, BUTTON3_X2, BUTTON3_Y2) )
			{
				run_main_menu_option(3);		// scenario editor
			}
			else if( optionFlag[3] > 0 
				&& mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2) )
			{
				run_main_menu_option(4);		// hall of fame
			}
			else if( optionFlag[4] > 0
				&& mouse.single_click( BUTTON5_X1, BUTTON5_Y1, BUTTON5_X2, BUTTON5_Y2) )
			{
				run_main_menu_option(5);		// credits
			}
			else if( mouse.single_click(BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2) )
			{
				run_main_menu_option(0);		// profile
			}
			else if( mouse.single_click( BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2) )
			{
				// quit
				break;
			}
			else if( mouse.single_click( BUTTON9_X1, BUTTON9_Y1, BUTTON9_X2, BUTTON9_Y2) )
			{
				if( DisplayModeInfo::get_display_info(config.display_mode_id+1) )
					++config.display_mode_id;
				else
					config.display_mode_id = 0;
			}
			else if( mouse.single_click( BUTTONA_X1, BUTTONA_Y1, BUTTONA_X2, BUTTONA_Y2) )
			{
				run_main_menu_option(6);		// home page
			}

			// ----- check signal exit flag -------//

			if( sys.signal_exit_flag == 1 )
				break;

		}	// end while
	}	// end the scope of vgaLock
}
Пример #4
0
void Game::main_menu()
{
	int refreshFlag = MMOPTION_ALL;

	char optionFlag[5] = 
	{
		1, 1, 1, 1, 1,
	};

	// ----- disable some option -------//

	// test sys.game_version, skip single player and scenario editor
	optionFlag[0] = optionFlag[2] =
#if(defined(DISABLE_SINGLE_PLAYER))
		0;
#elif(defined(DEBUG))
		1;
#elif(defined(BETA))
		1;
#else
		(sys.game_version == VERSION_MULTIPLAYER_ONLY) ? 0 : 1;
#endif


#ifdef DISABLE_MULTI_PLAYER
	// disable multiplayer game, Game::multi_player_menu is disabled
	optionFlag[1] = 0;
#endif

#ifdef DISABLE_SCENARIO_EDITOR
	optionFlag[2] = 0;
#endif

	int emptyProfileTesting = 1;

	mouse_cursor.set_icon(CURSOR_NORMAL);
	vga_front.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_BLACK);

	unsigned long lastRedrawTime = misc.get_time();

	{
		VgaFrontLock vgaLock;

		while(1)
		{
#if 0  // FIXME
			MSG msg;
			if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
			{
				if (!GetMessage( &msg, NULL, 0, 0))
				{
					sys.signal_exit_flag = 1;
					// BUGHERE : vga_front is unlocked
					return;
				}
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
			else if( sys.paused_flag || !sys.active_flag )
			{
				WaitMessage();
				continue;
			}
#endif
			if( sys.need_redraw_flag || misc.get_time() - lastRedrawTime > 8000 )
			{
				refreshFlag = MMOPTION_ALL;
				sys.need_redraw_flag = 0;
				lastRedrawTime = misc.get_time();	// redraw every 8 sec. Such that if background erased at the beginning, redraw
			}

			VgaFrontReLock vgaReLock;

			// -------- check auto load game request ------//

			if( auto_load_file_name )
			{
				refreshFlag = 0;
			}

			// -------- display ----------//

			game_mode = GAME_PREGAME;

			if( refreshFlag )
			{
				if( refreshFlag & MMOPTION_PAGE )
				{
					vga.use_back();
					vga_util.disp_image_file("M_MAIN");

				//	// ------ display copyright message --------//

				//	font_zoom.right_put( 755, 62, "(c) Copyright 1999 by Enlight Software and Trevor Chan" );

					// ------ display button -------//

					if( player_profile.is_registered() )
					{
						if( optionFlag[0] > 0 )		// single player
							font_thin_black.center_put_paragraph(
								BUTTON1_X1, BUTTON1_Y1, BUTTON1_X2, BUTTON1_Y2, 
								text_game_menu.str_single_player(), 0);
						if( optionFlag[1] > 0 )		// multi player
							font_thin_black.center_put_paragraph(
								BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2, 
								text_game_menu.str_multi_player(), 0);
						if( optionFlag[2] > 0 )		// scenario editor
							font_thin_black.center_put_paragraph(
								BUTTON3_X1, BUTTON3_Y1, BUTTON3_X2, BUTTON3_Y2, 
								text_game_menu.str_scenario_editor(), 0);
					}
					if( optionFlag[3] > 0 )
						font_thin_black.center_put_paragraph(
							BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2, 
							text_game_menu.str_hall_of_fame(), 0);
					if( optionFlag[4] > 0 )
						font_thin_black.center_put_paragraph(
							BUTTON5_X1, BUTTON5_Y1, BUTTON5_X2, BUTTON5_Y2, 
							text_game_menu.str_credits(), 0);
					font_thin_black.center_put_paragraph(
						BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2, 
						text_game_menu.str_player_register(), 0);
					font_thin_black.center_put_paragraph(
						BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2, 
						text_game_menu.str_quit(), 0);
					font_thin_black.center_put_paragraph(
						BUTTONA_X1, BUTTONA_Y1, BUTTONA_X2, BUTTONA_Y2, 
						text_game_menu.str_web_site(), 0);
					vga_util.blt_buf( 0, 0, VGA_WIDTH-1, VGA_HEIGHT-1, 0 );
					vga.use_front();

					disp_version();
				}

				if( refreshFlag & MMOPTION_RESOLUTION )
				{
					String resStr;

					if( !DisplayModeInfo::get_display_info(config.display_mode_id) )
						config.display_mode_id = MODE_ID_DEFAULT;

					resStr  = DisplayModeInfo::get_display_info(config.display_mode_id)->screen_width;
					resStr += "X";
					resStr += DisplayModeInfo::get_display_info(config.display_mode_id)->screen_height;

					vga_util.blt_buf( BUTTON9_X1, BUTTON9_Y1, BUTTON9_X2, BUTTON9_Y2, 0);
					font_thin_black.center_put( BUTTON9_X1, BUTTON9_Y1, BUTTON9_X2, BUTTON9_Y2, resStr );

					disp_version();
				}

				refreshFlag = 0;
			}

			sys.blt_virtual_buf();		// blt the virtual front buffer to the screen
			sys.yield();
			mouse.get_event();
			if( config.music_flag )
			{
				if( !music.is_playing(3) )
					music.play(3, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
			}
			else
			{
				music.stop();
			}

			sys.signal_exit_flag = 0;

			// -------- auto load game on request --------//

			if( auto_load_file_name )
			{
				int rc = game_file.load_game(NULL, auto_load_file_name);		// auto_load_file_name has the full path, no need to give path
				clear_load_game_in_main_menu();
				if( rc > 0 )
				{
					battle.run_loaded();
					deinit_all();
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();   // game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;
				}

				refreshFlag = MMOPTION_ALL;
				continue;
			}

			// ---------- detect new user ---------//

			if( emptyProfileTesting )		// do this testing only once
			{
				emptyProfileTesting = 0;

				if( PlayerProfile::load_count_profiles( NULL, 1) == 0 )		// maxLoad=1 for fast testing
				{
					box.msg( text_game_menu.str_first_welcome() );

					// run_main_menu_option(0);			don't call run_main_menu_option, we can't get it detect new profile
					if( player_profile.register_menu() == 1	// return 1 = new profile created
						&& player_profile.is_registered() 		// check is_registered for safety
						&& box.ask(text_game_menu.str_first_training()) )		// ask continue training
					{
						// ##### patch begin Gilbert 4/10 #####//
						game_file_array.init( player_profile.save_game_path(NULL), "*.SAV" );	// necessary to set the path and extension
						// ##### patch end Gilbert 4/10 #####//
						tutor.building_size = 2;	// default small building size
						tutor.run( 2, 0 );			// 2 - is the first fryhtan training tutorial id, 0 - not inGameCall
					}
				}

				if( sys.signal_exit_flag == 1 )
					break;
				else
					continue;
			}

			// -------- detect --------//

			if( player_profile.is_registered() && optionFlag[0] > 0
				&& mouse.single_click(BUTTON1_X1, BUTTON1_Y1, BUTTON1_X2, BUTTON1_Y2) )
			{
				run_main_menu_option(1);		// single player
				refreshFlag = MMOPTION_ALL;
			}
			else if( player_profile.is_registered() && optionFlag[1] > 0
				&& mouse.single_click(BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2) )
			{
				run_main_menu_option(2);		// multi player
				refreshFlag = MMOPTION_ALL;
			}
			else if( player_profile.is_registered() && optionFlag[2] > 0
				&& mouse.single_click(BUTTON3_X1, BUTTON3_Y1, BUTTON3_X2, BUTTON3_Y2) )
			{
				run_main_menu_option(3);		// scenario editor
				refreshFlag = MMOPTION_ALL;
			}
			else if( optionFlag[3] > 0 
				&& mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2) )
			{
				run_main_menu_option(4);		// hall of fame
				refreshFlag = MMOPTION_ALL;
			}
			else if( optionFlag[4] > 0
				&& mouse.single_click( BUTTON5_X1, BUTTON5_Y1, BUTTON5_X2, BUTTON5_Y2) )
			{
				run_main_menu_option(5);		// credits
				refreshFlag = MMOPTION_ALL;
			}
			else if( mouse.single_click(BUTTON6_X1, BUTTON6_Y1, BUTTON6_X2, BUTTON6_Y2) )
			{
				run_main_menu_option(0);		// profile
				refreshFlag = MMOPTION_ALL;
			}
			else if( mouse.single_click( BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2) )
			{
				// quit
				break;
			}
			else if( mouse.single_click( BUTTON9_X1, BUTTON9_Y1, BUTTON9_X2, BUTTON9_Y2) )
			{
				if( DisplayModeInfo::get_display_info(config.display_mode_id+1) )
					++config.display_mode_id;
				else
					config.display_mode_id = 0;
				refreshFlag |= MMOPTION_RESOLUTION;
			}
			else if( mouse.single_click( BUTTONA_X1, BUTTONA_Y1, BUTTONA_X2, BUTTONA_Y2) )
			{
				run_main_menu_option(6);		// home page
				refreshFlag = MMOPTION_ALL;
			}

			// ----- check signal exit flag -------//

			if( sys.signal_exit_flag == 1 )
				break;

		}	// end while
	}	// end the scope of vgaLock

//	#ifdef DEMO
//		demo_disp_ad_page();
//	#else
//		//---- display game end advertising page ----//
//		vga_util.disp_image_file("MAINMENU");
//		mouse.wait_press(60);
//		vga_util.finish_disp_image_file();
//	#endif
}