Subversion Repositories Games.Chess Giants

Rev

Rev 179 | Rev 189 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // main.cpp
  2.  
  3. #define DEFINE_GLOBALS
  4. #include "common.h"
  5.  
  6.  
  7. // prototypes of locally used functions
  8. static void MainLoop_FindCurrentViewer (void);
  9. static void MainLoop_EvaluateGameState (void);
  10.  
  11.  
  12. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow)
  13. {
  14.    // the entry point for any Windows program
  15.  
  16.    WNDCLASSEX wc;
  17.    MENUINFO menu_info;
  18.    MSG msg;
  19.    HBITMAP hSplashBmp;
  20.    BITMAP splash_bmp;
  21.    HDC hdc;
  22.    RECT rect;
  23.    PAINTSTRUCT ps;
  24.    HBITMAP hbmTmp;
  25.    HDC hdcMem;
  26.    HKEY hRegistryKey;
  27.    INPUT mousemove_input;
  28.    float previous_time;
  29.    float screensaverwatchdog_feedtime;
  30.    int frame_count;
  31.    int array_index;
  32.    char *endptr;
  33.    wchar_t app_pathname[MAX_PATH];
  34.    wchar_t font_pathname[MAX_PATH];
  35.    wchar_t temp_string[MAX_PATH];
  36.    DWORD ascii_buffersize;
  37.    WSADATA wsa_data;
  38.  
  39.    // does an InstallerPath registry key exist? if so, it means we've just been installed
  40.    ascii_buffersize = sizeof (temp_string);
  41.    if ((RegOpenKeyEx (HKEY_CURRENT_USER, L"SOFTWARE\\Chess Giants", 0, KEY_READ | KEY_SET_VALUE, &hRegistryKey) == 0)
  42.        && (RegQueryValueEx (hRegistryKey, L"InstallerPath", 0, NULL, (BYTE *) temp_string, &ascii_buffersize) == 0))
  43.    {
  44.       temp_string[ascii_buffersize / sizeof (wchar_t)] = 0; // terminate the string ourselves (strings in the registry MAY have no null terminator)
  45.  
  46.       // delete the installer
  47.       DeleteFile (temp_string);
  48.  
  49.       // delete the registry value and close the registry key
  50.       RegDeleteValue (hRegistryKey, L"InstallerPath");
  51.       RegCloseKey (hRegistryKey);
  52.    }
  53.  
  54.    // save application instance
  55.    hAppInstance = hInstance;
  56.  
  57.    // find module and path names, and *IMPORTANT*, set the current working directory there
  58.    GetModuleFileName (NULL, app_pathname, WCHAR_SIZEOF (app_pathname));
  59.    GetDirectoryPath (app_pathname, app_path);
  60.    SetCurrentDirectoryW (app_path);
  61.  
  62.    // initialize stuff
  63.    terminate_everything = false;
  64.    hMainWnd = NULL;
  65.    hChatterChannelsWnd = NULL;
  66.    hGamesWnd = NULL;
  67.    hMOTDWnd = NULL;
  68.    hOpponentsWnd = NULL;
  69.    hSoughtWnd = NULL;
  70.    is_paused = false; // clear pause status
  71. #ifdef NO_REGISTRATION
  72.    is_registered = true;
  73.    want_framerate = true; // display framerate in debug mode
  74. #else // !NO_REGISTRATION
  75.    is_registered = false;
  76.    dont_nag = false;
  77.    want_framerate = false; // release mode, don't display framerate
  78. #endif // NO_REGISTRATION
  79.    is_dialogbox_displayed = false;
  80.    is_dialogbox_about_validated = false;
  81.    is_dialogbox_challenge_validated = false;
  82.    is_dialogbox_changeappearance_validated = false;
  83.    is_dialogbox_comment_validated = false;
  84.    is_dialogbox_endgame_validated = false;
  85.    is_dialogbox_gotomove_validated = false;
  86.    is_dialogbox_renamesides_validated = false;
  87.    is_dialogbox_load_validated = false;
  88.    is_dialogbox_message_validated = false;
  89.    is_dialogbox_newgame_validated = false;
  90.    is_dialogbox_options_validated = false;
  91.    is_dialogbox_pawnpromotion_validated = false;
  92.    is_dialogbox_playercard_validated = false;
  93.    is_dialogbox_playerinfoname_validated = false;
  94.    is_dialogbox_quit_validated = false;
  95.    is_dialogbox_resign_validated = false;
  96.    is_dialogbox_save_validated = false;
  97.    is_dialogbox_saveposition_validated = false;
  98.    is_dialogbox_sendchallenge_validated = false;
  99.    is_dialogbox_sendseek_validated = false;
  100.    is_dialogbox_takeback_validated = false;
  101.    is_window_chat_validated = false;
  102.    is_window_chatterchannels_validated = false;
  103.    is_window_games_validated = false;
  104.    is_window_motd_validated = false;
  105.    is_window_opponents_validated = false;
  106.    is_window_sought_validated = false;
  107.    save_pathname[0] = 0;
  108.    srand ((unsigned int) time (NULL)); // initialize PRNG
  109.    animation_endtime = 0.0f;
  110.    command_ignoretime = 0.0f;
  111.    highlight_endtime = 0.0f;
  112.    previous_time = 0.0f;
  113.    frame_count = 0;
  114.  
  115.    // load the texts and ensure we have at least one display language
  116.    LocalizedTexts_Init ();
  117.    if (language_count < 1)
  118.    {
  119.       MessageBox (NULL, L"Chess Giants was unable to load its data files.\nThe game cannot start.\n\nPlease reinstall this program to fix the problem.", L"Chess Giants", MB_ICONERROR | MB_OK);
  120.       return (-1); // bomb out on error
  121.    }
  122.  
  123.    // initialize WinSock. God knows why it's necessary.
  124.    if (WSAStartup (MAKEWORD (2, 2), &wsa_data) != 0)
  125.    {
  126.       MessageBox (NULL, LOCALIZE (L"Error_NetworkInitializationFailed"), LOCALIZE (L"ImportantMessage"), MB_ICONERROR | MB_OK);
  127.       return (-1); // bomb out if network couldn't be initialized
  128.    }
  129.  
  130.    // read configuration data
  131.    Config_Load ();
  132.  
  133.    // see if the program is registered
  134. #ifndef NO_REGISTRATION
  135.    is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code);
  136.  
  137.    // is it not ? if so, try to read alternate registration data from the registry
  138.    if (!is_registered && (RegOpenKeyEx (HKEY_CURRENT_USER, L"SOFTWARE\\Chess Giants", 0, KEY_READ, &hRegistryKey) == 0))
  139.    {
  140.       ascii_buffersize = sizeof (options.registration.user_email); // in bytes
  141.       if (RegQueryValueEx (hRegistryKey, L"UserEmail", 0, NULL, (BYTE *) options.registration.user_email, &ascii_buffersize) == 0)
  142.          options.registration.user_email[ascii_buffersize / sizeof (wchar_t)] = 0; // terminate the string ourselves (strings in the registry MAY have no null terminator)
  143.       ascii_buffersize = sizeof (options.registration.activation_code); // in bytes
  144.       if (RegQueryValueEx (hRegistryKey, L"ActivationCode", 0, NULL, (BYTE *) &options.registration.activation_code, &ascii_buffersize) != 0)
  145.          options.registration.activation_code = 0; // if we can't read the activation code DWORD properly, reset it
  146.       RegCloseKey (hRegistryKey); // once we've read the data we were interested in, close the registry key
  147.  
  148.       // now check again if we're registered
  149.       is_registered = IsRegistrationCorrect (options.registration.user_email, options.registration.activation_code);
  150.    }
  151. #endif // !NO_REGISTRATION
  152.  
  153.    // if we're not registered, display a dialog box to invite the user to enter his donor email to unlock the program
  154.    //if (!is_registered)
  155.    //{
  156.    //   DialogBox_Registration ();
  157.    //}
  158.    //DialogBox_Registration ();
  159.    //return (0);
  160.  
  161.    // register the window class, create the window and show it
  162.    memset (&wc, 0, sizeof (wc));
  163.    wc.cbSize = sizeof (wc);
  164.    wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // double-clicks support
  165.    wc.lpfnWndProc = WindowProc_Main;
  166.    wc.hInstance = hAppInstance;
  167.    wc.hIcon = LoadIcon (hAppInstance, (wchar_t *) ICON_MAIN);
  168.    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  169.    wc.lpszClassName = PROGRAM_NAME L" WndClass";
  170.    RegisterClassEx (&wc);
  171.    swprintf_s (temp_string, WCHAR_SIZEOF (temp_string), PROGRAM_NAME L"%s", (is_registered ? L"" : LOCALIZE (L"EvaluationMode"))); // build window title
  172.    if (options.want_fullscreen)
  173.       hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_POPUPWINDOW, // temp_string holds window title
  174.                                  0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), NULL, NULL, hAppInstance, NULL);
  175.    else
  176.    {
  177.       // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum
  178.       if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK))
  179.          options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect
  180.       if (options.window_height > GetSystemMetrics (SM_CYMAXTRACK))
  181.          options.window_height = GetSystemMetrics (SM_CYMAXTRACK);
  182.       if (options.window_width < 640)
  183.          options.window_width = 640; // check this secondly in case screen size is reported incorrect
  184.       if (options.window_height < 480)
  185.          options.window_height = 480;
  186.  
  187.       hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title
  188.                                  GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2,
  189.                                  GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2,
  190.                                  options.window_width, options.window_height, NULL, NULL, hAppInstance, NULL);
  191.    }
  192.    ShowWindow (hMainWnd, (options.want_maximized ? SW_SHOWMAXIMIZED : nCmdShow)); // show it maximized if it was closed so
  193.  
  194.    // create the main menu line, and its accelerators
  195.    hMainMenu = NULL;
  196.    hMainAccelerators = NULL;
  197.    CreateOrUpdateApplicationMenu ();
  198.  
  199.    // display the splash screen (uglily first, using GDI functions)
  200.    memset ((void *) &splash_bmp, 0, sizeof (splash_bmp));
  201.    hSplashBmp = W32LoadImage (L"%s/data/splash.bmp", app_path); // load the splash bitmap
  202.    GetObject (hSplashBmp, sizeof (splash_bmp), (void *) &splash_bmp); // get a structure containing its size (among others)
  203.    hdcMem = CreateCompatibleDC (NULL); // create a device context compatible with the screen
  204.    hbmTmp = SelectBitmap (hdcMem, hSplashBmp); // select our bitmap to use in it
  205.    hdc = BeginPaint (hMainWnd, &ps); // begin painting on the main window
  206.    GetClientRect (hMainWnd, &rect);
  207.    StretchBlt (hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, splash_bmp.bmWidth, splash_bmp.bmHeight, SRCCOPY); // bit blit the bitmap into it
  208.    EndPaint (hMainWnd, &ps); // end painting on the main window
  209.    SelectObject (hdcMem, hbmTmp); // restore the previous selection
  210.    DeleteDC (hdcMem); // and delete the handles to the device context
  211.    DeleteObject (hSplashBmp); // and to the bitmap that we used
  212.  
  213.    // make the menu modeless
  214.    memset (&menu_info, 0, sizeof (menu_info)); // prepare menu info structure
  215.    menu_info.cbSize = sizeof (MENUINFO);
  216.    menu_info.fMask = MIM_STYLE;
  217.    GetMenuInfo (GetMenu (hMainWnd), &menu_info); // get current style
  218.    menu_info.dwStyle |= MNS_MODELESS; // add the "modeless" flag
  219.    SetMenuInfo (GetMenu (hMainWnd), &menu_info); // and send it back
  220.  
  221.    // load status icons, bitmaps and texts
  222.    handlestatus[HANDLESTATUS_AVAILABLE].icon = W32LoadIcon (L"%s/data/icons/available.ico", app_path);
  223.    handlestatus[HANDLESTATUS_AVAILABLE].bitmap = W32LoadImage (L"%s/data/status/available.bmp", app_path);
  224.    handlestatus[HANDLESTATUS_AVAILABLE].text = LOCALIZE (L"Opponents_StatusAvailable");
  225.    handlestatus[HANDLESTATUS_INGAME].icon = W32LoadIcon (L"%s/data/icons/ingame.ico", app_path);
  226.    handlestatus[HANDLESTATUS_INGAME].bitmap = W32LoadImage (L"%s/data/status/ingame.bmp", app_path);
  227.    handlestatus[HANDLESTATUS_INGAME].text = LOCALIZE (L"Opponents_StatusInGame");
  228.    handlestatus[HANDLESTATUS_INSIMULATION].icon = W32LoadIcon (L"%s/data/icons/insimulation.ico", app_path);
  229.    handlestatus[HANDLESTATUS_INSIMULATION].bitmap = W32LoadImage (L"%s/data/status/insimulation.bmp", app_path);
  230.    handlestatus[HANDLESTATUS_INSIMULATION].text = LOCALIZE (L"Opponents_StatusInSimulation");
  231.    handlestatus[HANDLESTATUS_INTOURNAMENT].icon = W32LoadIcon (L"%s/data/icons/intournament.ico", app_path);
  232.    handlestatus[HANDLESTATUS_INTOURNAMENT].bitmap = W32LoadImage (L"%s/data/status/intournament.bmp", app_path);
  233.    handlestatus[HANDLESTATUS_INTOURNAMENT].text = LOCALIZE (L"Opponents_StatusInTournament");
  234.    handlestatus[HANDLESTATUS_EXAMININGAGAME].icon = W32LoadIcon (L"%s/data/icons/examiningagame.ico", app_path);
  235.    handlestatus[HANDLESTATUS_EXAMININGAGAME].bitmap = W32LoadImage (L"%s/data/status/examiningagame.bmp", app_path);
  236.    handlestatus[HANDLESTATUS_EXAMININGAGAME].text = LOCALIZE (L"Opponents_StatusExaminingAGame");
  237.    handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].icon = W32LoadIcon (L"%s/data/icons/notopenforamatch.ico", app_path);
  238.    handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].bitmap = W32LoadImage (L"%s/data/status/notopenforamatch.bmp", app_path);
  239.    handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].text = LOCALIZE (L"Opponents_StatusNotOpenForAMatch");
  240.    handlestatus[HANDLESTATUS_INACTIVEORBUSY].icon = W32LoadIcon (L"%s/data/icons/inactiveorbusy.ico", app_path);
  241.    handlestatus[HANDLESTATUS_INACTIVEORBUSY].bitmap = W32LoadImage (L"%s/data/status/inactiveorbusy.bmp", app_path);
  242.    handlestatus[HANDLESTATUS_INACTIVEORBUSY].text = LOCALIZE (L"Opponents_StatusInactiveOrBusy");
  243.    handlestatus[HANDLESTATUS_OFFLINE].icon = W32LoadIcon (L"%s/data/icons/offline.ico", app_path);
  244.    handlestatus[HANDLESTATUS_OFFLINE].bitmap = W32LoadImage (L"%s/data/status/offline.bmp", app_path);
  245.    handlestatus[HANDLESTATUS_OFFLINE].text = LOCALIZE (L"Opponents_StatusOffline");
  246.  
  247.    // load the system fonts
  248.    hFontChat = CreateFont (17, 0, 0, 0, FW_DONTCARE, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
  249.                            CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Comic Sans MS");
  250.  
  251.    // before any rendering is done, it's a good idea to know what time it is
  252.    current_time = ProcessTime ();
  253.    stoppage_time = 0;
  254.    screensaverwatchdog_feedtime = current_time + 50.0f; // feed screensaver watchdog every 50 seconds
  255.  
  256.    // initialize audio and renderer, and display a cleaner version of the splash screen this time :)
  257.    if (!Audio_Init () || !Render_Init (L"%s/data/splash.bmp", app_path))
  258.       return (-1); // bomb out on error
  259.  
  260.    // load sprites
  261.    llarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-leftmost.png", app_path);
  262.    larrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-left.png", app_path);
  263.    rarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-right.png", app_path);
  264.    rrarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-rightmost.png", app_path);
  265.    newgamebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/newgame.png", app_path);
  266.    opengamebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/opengame.png", app_path);
  267.    chatbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/chat.png", app_path);
  268.    gamesbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/games.png", app_path);
  269.    peoplebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/people.png", app_path);
  270.    sepia_spriteindex = Render_LoadSprite (L"%s/data/sprites/sepia.png", app_path);
  271.    for (array_index = 0; array_index < 12; array_index++)
  272.       spinner_spriteindex[array_index] = Render_LoadSprite (L"%s/data/sprites/spinner-%d.png", app_path, array_index * 30); // spinning wheel
  273.  
  274.    // add our custom fonts to the list of available fonts for the duration of the process
  275.    swprintf_s (font_pathname, WCHAR_SIZEOF (font_pathname), L"%s/data/fonts/papyrus.ttf", app_path);
  276.    AddFontResourceEx (font_pathname, FR_PRIVATE, 0);
  277.  
  278.    // load themes, initialize a new human vs. human game and setup the scene
  279.    if (!Themes_Init ())
  280.       return (-1); // bomb out on error
  281.    Board_Init (&the_board, PLAYER_HUMAN, PLAYER_HUMAN, L"standard", FENSTARTUP_STANDARDCHESS);
  282.    Scene_Init (&the_scene, &the_board);
  283.  
  284.    // has a filename been specifed on the command-line AND that file exists ?
  285.    if ((lpCmdLine != NULL) && (lpCmdLine[0] != 0))
  286.    {
  287.       while (*lpCmdLine == '"')
  288.          lpCmdLine++; // skip leading quotes
  289.       if ((endptr = strchr (lpCmdLine, '"')) != NULL)
  290.          *endptr = 0; // break the string at the first ending quote
  291.  
  292.       // is it a file that exists ? (don't use stat() which is broken on WinXP)
  293.       if (_access (lpCmdLine, 0) == 0)
  294.       {
  295.          ConvertToWideChar (load_pathname, WCHAR_SIZEOF (load_pathname), lpCmdLine); // save pathname string
  296.          is_dialogbox_load_validated = true; // and act as if the user just validated a load dialog box
  297.       }
  298. #ifndef NO_REGISTRATION
  299.       // else is it a registration info ? if so, parse it
  300.       else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL))
  301.       {
  302.          *endptr = 0; // break the string at the separator between user email and activation code
  303.          ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email
  304.          is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not
  305.       }
  306. #endif // !NO_REGISTRATION
  307.    }
  308.  
  309.    // TODO: this + offline statistics
  310.  
  311.    // enter the main loop
  312.    while (!terminate_everything)
  313.    {
  314.       // see what time it is
  315.       current_time = ProcessTime ();
  316.       if (is_paused)
  317.          stoppage_time += (current_time - previous_time); // if we're paused, increase stoppage time
  318.  
  319.       // is it time to feed the screensaver watchdog ? (to prevent it from starting)
  320.       if (screensaverwatchdog_feedtime < current_time)
  321.       {
  322.          mousemove_input.type = INPUT_MOUSE;
  323.          memset (&mousemove_input.mi, 0, sizeof (mousemove_input.mi)); // blank out struct = no move at all :)
  324.          mousemove_input.mi.dwFlags = MOUSEEVENTF_MOVE;
  325.          SendInput (1, &mousemove_input, sizeof (mousemove_input)); // send a fake mouse move input event
  326.  
  327.          screensaverwatchdog_feedtime = current_time + 50.0f; // feed screensaver watchdog again in 50 seconds
  328.       }
  329.  
  330.       // are we in demo mode and is it time to quit ?
  331.       if (!is_registered && (current_time > DEMO_TIMEOUT))
  332.          DestroyWindow (hMainWnd); // if so, send a quit message in order to break the loop
  333.  
  334.       // are we in the middle of an animation or just after it ?
  335.       if (current_time < animation_endtime + 0.5f)
  336.          the_scene.update = true; // always update during animations
  337.       else
  338.          the_scene.update |= Board_Think (&the_board); // make the board (i.e, both players) think
  339.  
  340.       MainLoop_FindCurrentViewer ();  // determine current viewer
  341.  
  342.       // see if we have a message waiting for any window in the current thread and dispatch it
  343.       while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  344.       {
  345.          // check for accelerator keystrokes from the main window
  346.          if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, hMainAccelerators, &msg))
  347.          {
  348.             TranslateMessage (&msg); // translate and dispatch all other messages
  349.             DispatchMessage (&msg);
  350.          }
  351.       }
  352.  
  353.       // handle dialog box and window return codes
  354.       if (is_dialogbox_about_validated) DialogBox_About_Validated ();
  355.       if (is_dialogbox_challenge_validated) DialogBox_Challenge_Validated ();
  356.       if (is_dialogbox_changeappearance_validated) DialogBox_ChangeAppearance_Validated ();
  357.       if (is_dialogbox_comment_validated) DialogBox_Comment_Validated ();
  358.       if (is_dialogbox_endgame_validated) DialogBox_EndGame_Validated ();
  359.       if (is_dialogbox_gotomove_validated) DialogBox_GoToMove_Validated ();
  360.       if (is_dialogbox_renamesides_validated) DialogBox_RenameSides_Validated ();
  361.       if (is_dialogbox_load_validated) DialogBox_Load_Validated ();
  362.       if (is_dialogbox_message_validated) DialogBox_Message_Validated ();
  363.       if (is_dialogbox_newgame_validated) DialogBox_NewGame_Validated ();
  364.       if (is_dialogbox_options_validated) DialogBox_Options_Validated ();
  365.       if (is_dialogbox_pawnpromotion_validated) DialogBox_PawnPromotion_Validated ();
  366.       if (is_dialogbox_playercard_validated) DialogBox_PlayerCard_Validated ();
  367.       if (is_dialogbox_playerinfoname_validated) DialogBox_PlayerInfoName_Validated ();
  368.       if (is_dialogbox_quit_validated) DialogBox_Quit_Validated ();
  369.       if (is_dialogbox_resign_validated) DialogBox_Resign_Validated ();
  370.       if (is_dialogbox_save_validated) DialogBox_Save_Validated ();
  371.       if (is_dialogbox_saveposition_validated) DialogBox_SavePosition_Validated ();
  372.       if (is_dialogbox_sendchallenge_validated) DialogBox_SendChallenge_Validated ();
  373.       if (is_dialogbox_sendseek_validated) DialogBox_SendSeek_Validated ();
  374.       if (is_dialogbox_takeback_validated) DialogBox_Takeback_Validated ();
  375.       if (is_window_chat_validated) Window_Chat_Validated ();
  376.       if (is_window_chatterchannels_validated) Window_ChatterChannels_Validated ();
  377.       if (is_window_games_validated) Window_Games_Validated ();
  378.       if (is_window_motd_validated) Window_MOTD_Validated ();
  379.       if (is_window_opponents_validated) Window_Opponents_Validated ();
  380.       if (is_window_sought_validated) Window_Sought_Validated ();
  381.  
  382.       MainLoop_EvaluateGameState (); // evaluate game state
  383.  
  384.       // is the table rotating ?
  385.       if (Player_RotateTable (&the_board.players[current_viewer], current_time - previous_time))
  386.          the_scene.update = true; // if so, update the scene
  387.  
  388.       // are we highlighting something ?
  389.       if (highlight_endtime > current_time)
  390.          the_scene.update = true; // if so, update the scene
  391.  
  392.       // else if we WERE just highlighting something, clear the hovered positions
  393.       else if (highlight_endtime + 0.1f > current_time)
  394.       {
  395.          the_board.hovered_position[0] = -1;
  396.          the_board.hovered_position[1] = -1;
  397.          the_scene.update = true; // and update the scene
  398.       }
  399.  
  400.       // if we want the game clock, update scene every second
  401.       if (options.want_clock && ((int) current_time != (int) previous_time))
  402.          the_scene.update = true;
  403.  
  404.       // if there's something in the central text buffer, update scene too
  405.       if (the_scene.gui.central_text.is_displayed)
  406.          the_scene.update = true;
  407.  
  408.       // if we have a spinning wheel, update scene too
  409.       if (the_scene.gui.want_spinwheel)
  410.          the_scene.update = true;
  411.  
  412.       // is our theme not loaded yet ?
  413.       if (!theme->is_loaded)
  414.          Theme_LoadABitMore (theme); // load a bit more of it
  415.  
  416.       // else do we NOT need to update the scene ?
  417.       else if (!the_scene.update)
  418.       {
  419.          // cycle through all themes and see if one of them needs to be loaded
  420.          for (array_index = 0; array_index < theme_count; array_index++)
  421.             if (!themes[array_index].is_loaded)
  422.             {
  423.                Theme_LoadABitMore (&themes[array_index]); // load a bit more of this theme
  424.                break; // and stop looping (see you next pass)
  425.             }
  426.       }
  427.  
  428.       // either we need to update the scene, or we want to do it continuously
  429.       else
  430.       {
  431.          Scene_Update (&the_scene, &the_board); // evaluate which parts need to be placed
  432.          Render_RenderFrame (&the_scene); // render a game frame
  433.  
  434.          the_scene.update = false; // scene no longer needs to be updated now
  435.       }
  436.  
  437.       Audio_Think (); // ensure audio is playing
  438.  
  439.       previous_time = current_time; // save previous time
  440.       if (frame_count == 100)
  441.       {
  442.          frame_count = 0; // reset frame count every 100 frames
  443.          Sleep (1); // once every 100 frames, wait a millisecond
  444.       }
  445.       else
  446.          Sleep (0); // else just allow context switching
  447.       frame_count++; // increase the frame count
  448.    }
  449.  
  450.    /////////////////////////////////////////////////////////////////////////
  451.    // at this point, we exited the main loop and we are returning to Windows
  452.  
  453.    // release scene, game, themes and shutdown renderer and audio
  454.    Scene_Shutdown (&the_scene);
  455.    Board_Shutdown (&the_board);
  456.    Themes_Shutdown ();
  457.    Render_Shutdown ();
  458.    Audio_Shutdown ();
  459.  
  460.    // delete the font resources
  461.    DeleteObject (hFontChat);
  462.  
  463.    // delete the bitmap and icon ressources
  464.    for (array_index = 1; array_index < sizeof (handlestatus) / sizeof (handlestatus[0]); array_index++)
  465.    {
  466.       DeleteObject (handlestatus[array_index].bitmap);
  467.       DestroyIcon (handlestatus[array_index].icon);
  468.    }
  469.  
  470.    // unregister window class
  471.    UnregisterClass (wc.lpszClassName, hAppInstance);
  472.  
  473.    // destroy the accelerators table
  474.    if (hMainAccelerators)
  475.       DestroyAcceleratorTable (hMainAccelerators);
  476.    hMainAccelerators = NULL;
  477.  
  478.    // destroy the application menu object
  479.    if (IsMenu (hMainMenu))
  480.       DestroyMenu (hMainMenu);
  481.    hMainMenu = NULL;
  482.  
  483.    // are we not registered yet AND have we NOT been told to don't nag?
  484. #ifndef NO_REGISTRATION
  485.    if (!is_registered && !dont_nag)
  486.       DialogBox_Registration ();
  487. #endif // !NO_REGISTRATION
  488.  
  489.    // save configuration data
  490.    Config_Save ();
  491.  
  492.    // unload localized texts
  493.    LocalizedTexts_Shutdown ();
  494.  
  495.    // shutdown WinSock
  496.    WSACleanup ();
  497.  
  498.    ExitProcess (0); // it looks like this is needed to terminate reluctant Chess Giants instances...
  499.    return (0); // and return to Windows.
  500. }
  501.  
  502.  
  503. static void MainLoop_FindCurrentViewer (void)
  504. {
  505.    // helper function that tells who is the current viewer
  506.  
  507.    if ((the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) && (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN))
  508.       current_viewer = Board_ColorToMove (&the_board); // if both players are human, track them both
  509.    else if (the_board.players[COLOR_WHITE].type == PLAYER_HUMAN)
  510.       current_viewer = COLOR_WHITE; // else if only the white is human, track the white
  511.    else if (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN)
  512.       current_viewer = COLOR_BLACK; // else if it's the black, track the black
  513.    else
  514.       current_viewer = COLOR_WHITE; // else no human in game, track just the white
  515.  
  516.    return; // finished, current viewer is known
  517. }
  518.  
  519.  
  520. static void MainLoop_EvaluateGameState (void)
  521. {
  522.    // function to evaluate the game state in the main loop when a part has just moved
  523.  
  524.    static wchar_t window_title[256];
  525.  
  526.    player_t *current_player;
  527.    player_t *opposite_player;
  528.    player_t *network_player;
  529.    boardmove_t *last_move;
  530.    int enabled_value;
  531.    int move_index;
  532.  
  533.    // get current and opposite players, and see if we're online
  534.    current_player = Player_GetCurrent ();
  535.    opposite_player = Player_GetOpposite ();
  536.    network_player = Player_FindByType (PLAYER_INTERNET);
  537.  
  538.    // if no dialog box is in focus AND the view distance and pitch is lower than the minimum, enable the "new game" and "open game" buttons
  539.    if (!is_dialogbox_displayed && (network_player == NULL) && (current_distance == CLOSEUP_VIEW_DISTANCE) && (current_pitch == CLOSEUP_VIEW_PITCH))
  540.    {
  541.       GUIBUTTON_ENABLE (the_scene.gui.newgamebutton);
  542.       GUIBUTTON_ENABLE (the_scene.gui.opengamebutton);
  543.    }
  544.    else
  545.    {
  546.       GUIBUTTON_DISABLE (the_scene.gui.newgamebutton);
  547.       GUIBUTTON_DISABLE (the_scene.gui.opengamebutton);
  548.    }
  549.  
  550.    if (!the_board.reevaluate)
  551.       return; // if the board doesn't need to be reevaluated, don't do anything
  552.  
  553.    // has the game started ?
  554.    if (the_board.move_count > 1)
  555.    {
  556.       // game has started, enable the "save" and "save as" menu options
  557.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_ENABLED);
  558.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_ENABLED);
  559.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED);
  560.  
  561.       // disable the start position setup mode
  562.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SETUPPOSITION, MF_GRAYED);
  563.  
  564.       // enable the "go to move" menu option
  565.       EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_GOTOMOVE, MF_ENABLED);
  566.  
  567.       // are we watching the last move ?
  568.       if (the_board.viewed_move == the_board.move_count - 1)
  569.       {
  570.          // get a quick acccess to the last move
  571.          last_move = &the_board.moves[the_board.move_count - 1];
  572.  
  573.          // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint
  574.          if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
  575.             EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_ENABLED);
  576.          else
  577.             EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_GRAYED);
  578.  
  579.          // (if the current player is a human
  580.          //  AND (its opponent is another human AND there's at least one move played)
  581.          //       OR (its opponent is a computer AND there are at least two moves played)
  582.          //       OR (its opponent is a remote player AND we're in game AND there are at least two moves played))
  583.          // OR the current player is a remote player AND we're in game AND there are at least two moves played), allow him to cancel move
  584.          if (((current_player->type == PLAYER_HUMAN)
  585.               && ((opposite_player->type == PLAYER_HUMAN)
  586.                   || ((opposite_player->type == PLAYER_COMPUTER) && (the_board.move_count > 2))
  587.                   || ((opposite_player->type == PLAYER_INTERNET) && (opposite_player->is_in_game) && (the_board.move_count > 2))))
  588.              || ((current_player->type == PLAYER_INTERNET) && (current_player->is_in_game) && (the_board.move_count > 2)))
  589.             EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_CANCELLASTMOVE, MF_ENABLED);
  590.          else
  591.             EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_CANCELLASTMOVE, MF_GRAYED);
  592.  
  593.          // is the current player in check ? (to play the right sound)
  594.          // read as: was the last move an opponent's move AND did it put us to check ?
  595.          if (last_move->is_check)
  596.          {
  597.             // is it a checkmate ? (checkmate == check + stalemate)
  598.             if (last_move->is_stalemate)
  599.             {
  600.                // display the game over dialog box
  601.                the_board.game_state = (Board_ColorToMove (&the_board) == COLOR_WHITE ? STATE_BLACKWIN_CHECKMATE : STATE_WHITEWIN_CHECKMATE);
  602.                DialogBox_EndGame ();
  603.             }
  604.          }
  605.          else
  606.          {
  607.             // is it a stalemate ?
  608.             if (last_move->is_stalemate)
  609.             {
  610.                // display the game over dialog box
  611.                the_board.game_state = STATE_DRAW_STALEMATE;
  612.                DialogBox_EndGame ();
  613.             }
  614.          }
  615.  
  616.          // have there 50 moves been played each side (i.e, 100 plies) AND is the current player human ?
  617.          if ((the_board.move_count > 100) && (current_player->type == PLAYER_HUMAN))
  618.          {
  619.             // go backwards and see when is the latest move that took an opponent's piece OR the latest pawn move
  620.             for (move_index = the_board.move_count - 1; move_index >= 0; move_index--)
  621.                if (the_board.moves[move_index].has_captured || (the_board.moves[move_index].part == PART_PAWN))
  622.                   break; // stop as soon as we find one
  623.  
  624.             // can the fifty moves draw rule be claimed AND does the current player claims it ?
  625.             if (move_index + 1 + 100 < the_board.move_count)
  626.             {
  627.                // yes. Propose it to the side that's on move
  628. // TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values)
  629.             }
  630.          }
  631.  
  632.          GUIBUTTON_ENABLE (the_scene.gui.llarrow); // enable "jump to beginning" arrow if it isn't displayed yet
  633.          GUIBUTTON_ENABLE (the_scene.gui.larrow); // enable "back" arrow if it isn't displayed yet
  634.          GUIBUTTON_DISABLE (the_scene.gui.rarrow); // disable "forward" arrow if it's already displayed
  635.          GUIBUTTON_DISABLE (the_scene.gui.rrarrow); // disable "jump to end" arrow if it's already displayed
  636.  
  637.          if (the_board.game_state == STATE_PLAYING)
  638.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, LOCALIZE (is_paused ? L"Paused" : L"Current"));
  639.          else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE))
  640.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s\n%s", LOCALIZE (L"EndGame_CheckMate"), LOCALIZE (L"EndGame_Title"));
  641.          else if ((the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) || (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT))
  642.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s\n%s", LOCALIZE (L"EndGame_Resign"), LOCALIZE (L"EndGame_Title"));
  643.          else if (the_board.game_state == STATE_DRAW_STALEMATE)
  644.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s\n%s", LOCALIZE (L"EndGame_StaleMate"), LOCALIZE (L"EndGame_Title"));
  645.          else if (the_board.game_state == STATE_DRAW_AGREEMENT)
  646.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s\n%s", LOCALIZE (L"EndGame_Agreement"), LOCALIZE (L"EndGame_Title"));
  647.          else if (the_board.game_state == STATE_DRAW_OTHER)
  648.             Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s\n%s", LOCALIZE (L"EndGame_DrawOther"), LOCALIZE (L"EndGame_Title"));
  649.  
  650.          // enable the "comment on this move" menu option
  651.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_COMMENTMOVE, MF_ENABLED);
  652.       }
  653.  
  654.       // else are we watching another move, but not the beginning of the game ?
  655.       else if (the_board.viewed_move > 0)
  656.       {
  657.          GUIBUTTON_ENABLE (the_scene.gui.llarrow); // enable "jump to beginning" arrow if it isn't displayed yet
  658.          GUIBUTTON_ENABLE (the_scene.gui.larrow); // enable "back" arrow if it isn't displayed yet
  659.          GUIBUTTON_ENABLE (the_scene.gui.rarrow); // enable "forward" arrow if it isn't displayed yet
  660.          GUIBUTTON_ENABLE (the_scene.gui.rrarrow); // enable "jump to end" arrow if it isn't displayed yet
  661.          Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, L"%s %d\n%s", LOCALIZE (L"Move"), (the_board.viewed_move + 1) / 2, (the_board.viewed_move % 2 ? LOCALIZE (L"Games_White"): LOCALIZE (L"Games_Black")));
  662.  
  663.          // hints are not usable when watching the game history
  664.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_GRAYED);
  665.  
  666.          // enable the "save position as" and "comment on this move" menu options
  667.          EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED);
  668.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_COMMENTMOVE, MF_ENABLED);
  669.       }
  670.  
  671.       // else we must be watching the beginning of the game (no move yet)
  672.       else
  673.       {
  674.          GUIBUTTON_DISABLE (the_scene.gui.llarrow); // disable "jump to beginning" arrow if it's already displayed
  675.          GUIBUTTON_DISABLE (the_scene.gui.larrow); // disable "back" arrow if it's already displayed
  676.          GUIBUTTON_ENABLE (the_scene.gui.rarrow); // enable "forward" arrow if it isn't displayed yet
  677.          GUIBUTTON_ENABLE (the_scene.gui.rrarrow); // enable "jump to end" arrow if it isn't displayed yet
  678.          Scene_UpdateText (&the_scene.gui.arrow_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, LOCALIZE (L"Beginning"));
  679.  
  680.          // hints are not usable when watching the game history
  681.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_GRAYED);
  682.  
  683.          // disable the "save position as" and "comment on this move" menu options
  684.          EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
  685.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_COMMENTMOVE, MF_GRAYED);
  686.       }
  687.    }
  688.    else
  689.    {
  690.       // game has not started, disable the "save", "save as" and "save position as" menu options
  691.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_GRAYED);
  692.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_GRAYED);
  693.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
  694.  
  695.       // if we are NOT on Internet play AND no longer in closeup mode, enable the start position setup mode
  696.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SETUPPOSITION, ((network_player == NULL) && (current_distance != CLOSEUP_VIEW_DISTANCE) && (current_pitch != CLOSEUP_VIEW_PITCH) ? MF_ENABLED : MF_GRAYED));
  697.  
  698.       // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint
  699.       if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
  700.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_ENABLED);
  701.       else
  702.          EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_SUGGESTMOVE, MF_GRAYED);
  703.  
  704.       // disable the "cancel last move", "comment move" and "go to move" menu options
  705.       EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_CANCELLASTMOVE, MF_GRAYED);
  706.       EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_COMMENTMOVE, MF_GRAYED);
  707.       EnableMenuItem (GetMenu (hMainWnd), MENUID_MOVE_GOTOMOVE, MF_GRAYED);
  708.  
  709.       is_paused = false; // clear pause status (we can only pause a game when it's been started)
  710.  
  711.       // and disable the navigation arrows and the arrow text
  712.       GUIBUTTON_DISABLE (the_scene.gui.llarrow);
  713.       GUIBUTTON_DISABLE (the_scene.gui.larrow);
  714.       GUIBUTTON_DISABLE (the_scene.gui.rarrow);
  715.       GUIBUTTON_DISABLE (the_scene.gui.rrarrow);
  716.       the_scene.gui.arrow_text.is_displayed = false;
  717.    }
  718.  
  719.    // no matter whether the game started or not, if the current player is a human AND its opponent is a computer, allow him to swap sides
  720.    if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
  721.       EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_ENABLED);
  722.    else
  723.       EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_GRAYED);
  724.  
  725.    // no matter whether the game started or not, enable players renaming only if we are NOT in internet mode
  726.    EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_RENAMESIDES, (network_player == NULL ? MF_ENABLED : MF_GRAYED));
  727.  
  728.    // update window title
  729.    if ((the_board.players[COLOR_WHITE].name[0] != 0) && (the_board.players[COLOR_BLACK].name[0] != 0))
  730.    {
  731.       swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s %s %s - " PROGRAM_NAME L"%s", the_board.players[COLOR_WHITE].name, LOCALIZE (L"Versus"), the_board.players[COLOR_BLACK].name, (is_registered ? L"" : LOCALIZE (L"EvaluationMode")));
  732.       SetWindowText (hMainWnd, window_title); // update window title
  733.    }
  734.    else if (the_board.players[COLOR_WHITE].name[0] != 0)
  735.    {
  736.       swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s - " PROGRAM_NAME L"%s", the_board.players[COLOR_WHITE].name, (is_registered ? L"" : LOCALIZE (L"EvaluationMode")));
  737.       SetWindowText (hMainWnd, window_title); // update window title
  738.    }
  739.  
  740.    // are we in internet mode AND are we logged in ?
  741.    if ((network_player != NULL) && network_player->is_logged_in)
  742.    {
  743.       // are we currently playing a game ?
  744.       if (network_player->is_in_game)
  745.       {
  746.          GUIBUTTON_ENABLE (the_scene.gui.chatbutton); // enable chat button if it's not enabled yet
  747.          GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled
  748.          GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled
  749.          EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1) ? MF_ENABLED : MF_GRAYED)); // allow resigning if the game has started AND it's not terminated)
  750.       }
  751.       else
  752.       {
  753.          GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled
  754.          GUIBUTTON_ENABLE (the_scene.gui.gamesbutton); // enable games button if it's not enabled yet
  755.          GUIBUTTON_ENABLE (the_scene.gui.peoplebutton); // enable people button if it's not enabled yet
  756.          EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_GRAYED); // disable ability to resign
  757.       }
  758.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_PAUSE, MF_DISABLED); // disallow pause
  759.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_ENABLED); // enable stats
  760.  
  761.       enabled_value = MF_ENABLED; // remember to enable the internet-related menu items
  762.    }
  763.    // else it's a local or vs. computer game
  764.    else
  765.    {
  766.       GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled
  767.       GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled
  768.       GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled
  769.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_PAUSE, ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1) ? MF_ENABLED : MF_GRAYED)); // allow pause if the game has started
  770.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, ((the_board.game_state == STATE_PLAYING) && (the_board.move_count > 1) ? MF_ENABLED : MF_GRAYED)); // allow resigning if the game has started AND it's not terminated)
  771.       EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_GRAYED); // disable stats
  772.  
  773.       enabled_value = MF_GRAYED; // remember to disable the internet-related menu items
  774.    }
  775.  
  776.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWONLINEPLAYERS, enabled_value);
  777.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWSOUGHTGAMES, enabled_value);
  778.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SEEKGAME, enabled_value);
  779.    if (!options.network.want_publicchat)
  780.    {
  781.       EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, MF_GRAYED); // always grayed if we don't want public chat
  782.       EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, MF_GRAYED);
  783.    }
  784.    else
  785.    {
  786.       EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, enabled_value); // else enabled only in internet mode
  787.       EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, enabled_value);
  788.    }
  789.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYPLAYERCARD, enabled_value);
  790.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYYOURCARD, enabled_value);
  791.    EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_MOTD, enabled_value);
  792.  
  793.    the_board.reevaluate = false; // board evaluation has been done
  794.    return; // finished, new board state is known
  795. }
  796.