Subversion Repositories Games.Chess Giants

Rev

Rev 2 | Rev 11 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
// main.cpp
2
 
3
#define DEFINE_GLOBALS
4
#include "common.h"
5
 
6
 
7
// handy macros
8
#define GUIBUTTON_ENABLE(button) { if ((button).state == 0) (button).state = 1; }
9
#define GUIBUTTON_DISABLE(button) { if ((button).state > 0) (button).state = 0; }
10
 
11
 
12
// prototypes of locally used functions
13
static void MainLoop_FindCurrentViewer (void);
14
static void MainLoop_EvaluateGameState (void);
15
 
16
 
17
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow)
18
{
19
   // the entry point for any Windows program
20
 
21
   WNDCLASSEX wc;
22
   MENUINFO menu_info;
23
   MSG msg;
24
   HBITMAP hSplashBmp;
25
   BITMAP splash_bmp;
26
   HDC hdc;
27
   HMENU hMenu;
28
   HMENU hDropDownMenu;
29
   RECT rect;
30
   PAINTSTRUCT ps;
31
   HBITMAP hbmTmp;
32
   HDC hdcMem;
33
   float previous_time;
34
   int frame_count;
35
   int array_index;
36
   bool is_success;
37
   char *endptr;
38
   wchar_t app_pathname[MAX_PATH];
39
   wchar_t language_file[MAX_PATH];
40
   struct _stat fileinfo;
41
   HACCEL hAccelerators;
42
   ACCEL accelerators[] =
43
   {
44
      {FVIRTKEY | FCONTROL, L'O',     MENUID_GAME_LOAD},
45
      {FVIRTKEY | FCONTROL, L'S',     MENUID_GAME_SAVE},
46
      {FVIRTKEY | FCONTROL, L'Z',     MENUID_CHESSBOARD_CANCELLASTMOVE},
47
      {FVIRTKEY,            VK_HOME,  MENUID_CHESSBOARD_BEGINNINGOFGAME},
48
      {FVIRTKEY,            VK_LEFT,  MENUID_CHESSBOARD_PREVIOUSMOVE},
49
      {FVIRTKEY,            VK_RIGHT, MENUID_CHESSBOARD_NEXTMOVE},
50
      {FVIRTKEY,            VK_END,   MENUID_CHESSBOARD_CURRENTSTATEOFGAME},
51
      {FVIRTKEY | FCONTROL, L'G',     MENUID_CHESSBOARD_GOTOMOVE},
52
      {FVIRTKEY,            VK_F1,    MENUID_HELP_HELP},
53
      {FVIRTKEY,            VK_F2,    MENUID_GAME_NEWGAME},
54
      {FVIRTKEY,            VK_F3,    MENUID_GAME_STATISTICS},
55
      {FVIRTKEY,            VK_F4,    MENUID_GAME_OPTIONS},
56
      {FVIRTKEY,            VK_F5,    MENUID_CHESSBOARD_TOPVIEW},
57
      {FVIRTKEY,            VK_F6,    MENUID_CHESSBOARD_DEFAULTVIEW},
58
      {FVIRTKEY,            VK_F7,    MENUID_CHESSBOARD_RESETVIEW},
59
      {FVIRTKEY,            VK_UP,    MENUID_CHESSBOARD_ZOOMIN},
60
      {FVIRTKEY,            VK_DOWN,  MENUID_CHESSBOARD_ZOOMOUT},
61
      {FVIRTKEY | FCONTROL, VK_DOWN,  MENUID_CHESSBOARD_DISPLAYWINDOWSDESKTOP},
62
      {FVIRTKEY,            VK_F8,    MENUID_CHESSBOARD_CHANGEAPPEARANCE},
63
      {FVIRTKEY,            VK_F9,    MENUID_INTERNET_SHOWONLINEPLAYERS},
64
      {FVIRTKEY,            VK_F10,   MENUID_INTERNET_SHOWSOUGHTGAMES},
65
   };
66
 
67
   // save application instance
68
   hAppInstance = hInstance;
69
 
70
   // find module and path names, and *IMPORTANT*, set the current working directory there
71
   GetModuleFileName (NULL, app_pathname, WCHAR_SIZEOF (app_pathname));
72
   GetDirectoryPath (app_pathname, app_path);
73
   SetCurrentDirectoryW (app_path);
74
 
75
   // initialize stuff
76
   terminate_everything = false;
77
   hMainWnd = NULL;
78
   hChatterChannelsWnd = NULL;
79
   hGamesWnd = NULL;
80
   hMOTDWnd = NULL;
81
   hOpponentsWnd = NULL;
82
   hSoughtWnd = NULL;
83
#ifdef NDEBUG
84
   want_framerate = false; // release mode, don't display framerate
85
#else
2 pmbaty 86
   want_framerate = true; // display framerate in debug mode
1 pmbaty 87
#endif // NDEBUG
88
   is_dialogbox_about_validated = false;
89
   is_dialogbox_challenge_validated = false;
90
   is_dialogbox_changeappearance_validated = false;
91
   is_dialogbox_comment_validated = false;
92
   is_dialogbox_endgame_validated = false;
93
   is_dialogbox_gotomove_validated = false;
94
   is_dialogbox_load_validated = false;
95
   is_dialogbox_message_validated = false;
96
   is_dialogbox_newgame_validated = false;
97
   is_dialogbox_options_validated = false;
98
   is_dialogbox_pawnpromotion_validated = false;
99
   is_dialogbox_playercard_validated = false;
100
   is_dialogbox_playerinfoname_validated = false;
101
   is_dialogbox_quit_validated = false;
102
   is_dialogbox_resign_validated = false;
103
   is_dialogbox_save_validated = false;
104
   is_dialogbox_saveposition_validated = false;
105
   is_dialogbox_sendchallenge_validated = false;
106
   is_dialogbox_sendseek_validated = false;
107
   is_dialogbox_takeback_validated = false;
108
   is_window_chat_validated = false;
109
   is_window_chatterchannels_validated = false;
110
   is_window_games_validated = false;
111
   is_window_motd_validated = false;
112
   is_window_opponents_validated = false;
113
   is_window_sought_validated = false;
114
   save_pathname[0] = 0;
115
   srand ((unsigned int) time (NULL)); // initialize PRNG
116
 
117
   // read configuration data
118
   Config_Load ();
119
 
120
   // read texts in the right language, if such a translation exists
121
   is_success = false;
122
   GetLocaleInfo (LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, os_language, WCHAR_SIZEOF (os_language));
123
   swprintf_s (language_file, WCHAR_SIZEOF (language_file), L"data/languages/%s.ini", os_language);
124
   is_success = LocalizedTexts_Init (language_file);
125
 
126
   // fallback to English if language not found
127
   if (!is_success)
128
      is_success = LocalizedTexts_Init (L"data/languages/English.ini");
129
 
130
   // consistency check: don't go further if texts aren't available
131
   if (!is_success)
132
      return (-1); // bomb out on error
133
 
134
   // create the main menu line
135
   hMenu = CreateMenu ();
136
   hDropDownMenu = CreateMenu (); // create the first drop-down item
137
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_NEWGAME, LOCALIZE (L"Menu_GameNewGame"));
138
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_LOAD, LOCALIZE (L"Menu_GameLoadGame"));
139
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_SETUPPOSITION, LOCALIZE (L"Menu_GameSetupPosition"));
140
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVE, LOCALIZE (L"Menu_GameSaveGame")); // initially grayed
141
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVEAS, LOCALIZE (L"Menu_GameSaveGameAs")); // initially grayed
142
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_SAVEPOSITIONAS, LOCALIZE (L"Menu_GameSavePositionAs")); // initially grayed
143
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_RESIGN, LOCALIZE (L"Menu_GameResign"));
144
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
145
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_GAME_STATISTICS, LOCALIZE (L"Menu_GameStatistics"));
146
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_OPTIONS, LOCALIZE (L"Menu_GameOptions"));
147
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
148
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_GAME_QUIT, LOCALIZE (L"Menu_GameQuit"));
149
   AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Game"));
150
   DestroyMenu (hDropDownMenu);
151
   hDropDownMenu = CreateMenu (); // create the second drop-down item
152
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_SUGGESTMOVE, LOCALIZE (L"Menu_ChessboardSuggestMove")); // initially grayed
153
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_CANCELLASTMOVE, LOCALIZE (L"Menu_ChessboardCancelLastMove")); // initially grayed
154
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_COMMENTMOVE, LOCALIZE (L"Menu_ChessboardCommentMove")); // initially grayed
155
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_GOTOMOVE, LOCALIZE (L"Menu_ChessboardGoToMove")); // initially grayed
156
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_CHESSBOARD_SWAPSIDES, LOCALIZE (L"Menu_ChessboardSwapSides")); // initially grayed
157
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
158
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_TOPVIEW, LOCALIZE (L"Menu_ChessboardTopView"));
159
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_DEFAULTVIEW, LOCALIZE (L"Menu_ChessboardDefaultView"));
160
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_RESETVIEW, LOCALIZE (L"Menu_ChessboardResetView"));
161
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
162
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_CHANGEAPPEARANCE, LOCALIZE (L"Menu_ChessboardChangeAppearance"));
163
   if (options.want_fullscreen)
164
   {
165
      AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
166
      AppendMenu (hDropDownMenu, MF_STRING, MENUID_CHESSBOARD_DISPLAYWINDOWSDESKTOP, LOCALIZE (L"Menu_ChessboardDisplayWindowsDesktop"));
167
   }
168
   AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Chessboard"));
169
   DestroyMenu (hDropDownMenu);
170
   hDropDownMenu = CreateMenu (); // create the third drop-down item
171
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SHOWONLINEPLAYERS, LOCALIZE (L"Menu_InternetShowOnlinePlayers")); // initially grayed
172
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SHOWSOUGHTGAMES, LOCALIZE (L"Menu_InternetShowSoughtGames")); // initially grayed
173
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_SEEKGAME, LOCALIZE (L"Menu_InternetSeekGame")); // initially grayed
174
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
175
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_CHATTERCHANNELS, LOCALIZE (L"Menu_InternetChatterChannels")); // initially grayed
176
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_ENTERCHATTEXT, LOCALIZE (L"Menu_InternetEnterChatText")); // initially grayed
177
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
178
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_DISPLAYPLAYERCARD, LOCALIZE (L"Menu_InternetDisplayPlayerCard")); // initially grayed
179
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_DISPLAYYOURCARD, LOCALIZE (L"Menu_InternetDisplayYourCard")); // initially grayed
180
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
181
   AppendMenu (hDropDownMenu, MF_STRING | MF_GRAYED, MENUID_INTERNET_MOTD, LOCALIZE (L"Menu_InternetDisplayMOTD")); // initially grayed
182
   AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Internet"));
183
   DestroyMenu (hDropDownMenu);
184
   hDropDownMenu = CreateMenu (); // create the fourth drop-down item
185
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_HELP, LOCALIZE (L"Menu_HelpDisplayHelp"));
186
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_GETCHESSGAMES, LOCALIZE (L"Menu_HelpGetChessGames"));
187
   AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL);
188
   AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ABOUT, LOCALIZE (L"Menu_HelpAbout"));
189
   AppendMenu (hMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Help"));
190
   DestroyMenu (hDropDownMenu);
191
 
192
   // create the accelerators
193
   hAccelerators = CreateAcceleratorTable (accelerators, sizeof (accelerators) / sizeof (ACCEL));
194
 
195
   // register the window class, create the window and show it
196
   memset (&wc, 0, sizeof (wc));
197
   wc.cbSize = sizeof (wc);
198
   wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // double-clicks support
199
   wc.lpfnWndProc = WindowProc_Main;
200
   wc.hInstance = hAppInstance;
201
   wc.hIcon = LoadIcon (hAppInstance, (wchar_t *) ICON_MAIN);
202
   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
203
   wc.lpszClassName = PROGRAM_NAME L" WndClass";
204
   RegisterClassEx (&wc);
205
   if (options.want_fullscreen)
206
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, PROGRAM_NAME, WS_POPUPWINDOW,
207
                                 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN),
208
                                 NULL, hMenu, hAppInstance, NULL);
209
   else
210
   {
3 pmbaty 211
      // in windowed mode, ensure window width and height aren't greater than screen size nor lower than a safe minimum
1 pmbaty 212
      if (options.window_width > GetSystemMetrics (SM_CXMAXTRACK))
3 pmbaty 213
         options.window_width = GetSystemMetrics (SM_CXMAXTRACK); // check this first in case screen size is reported incorrect
1 pmbaty 214
      if (options.window_height > GetSystemMetrics (SM_CYMAXTRACK))
215
         options.window_height = GetSystemMetrics (SM_CYMAXTRACK);
3 pmbaty 216
      if (options.window_width < 640)
217
         options.window_width = 640; // check this secondly in case screen size is reported incorrect
218
      if (options.window_height < 480)
219
         options.window_height = 480;
1 pmbaty 220
 
221
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, PROGRAM_NAME, WS_OVERLAPPEDWINDOW,
222
                                 GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2,
223
                                 GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2,
224
                                 options.window_width,
225
                                 options.window_height,
226
                                 NULL, hMenu, hAppInstance, NULL);
227
   }
228
   ShowWindow (hMainWnd, nCmdShow);
229
 
230
   // display the splash screen
231
   memset ((void *) &splash_bmp, 0, sizeof (splash_bmp));
232
   hSplashBmp = (HBITMAP) LoadImage (NULL, L"data/splash.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); // load the splash bitmap
233
   GetObject (hSplashBmp, sizeof (splash_bmp), (void *) &splash_bmp); // get a structure containing its size (among others)
234
   hdcMem = CreateCompatibleDC (NULL); // create a device context compatible with the screen
235
   hbmTmp = SelectBitmap (hdcMem, hSplashBmp); // select our bitmap to use in it
236
   hdc = BeginPaint (hMainWnd, &ps); // begin painting on the main window
237
   GetClientRect (hMainWnd, &rect);
238
   StretchBlt (hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, splash_bmp.bmWidth, splash_bmp.bmHeight, SRCCOPY); // bit blit the bitmap into it
239
   EndPaint (hMainWnd, &ps); // end painting on the main window
240
   SelectObject (hdcMem, hbmTmp); // restore the previous selection
241
   DeleteDC (hdcMem); // and delete the handles to the device context
242
   DeleteObject (hSplashBmp); // and to the bitmap that we used
243
 
244
   // make the menu modeless
245
   memset (&menu_info, 0, sizeof (menu_info)); // prepare menu info structure
246
   menu_info.cbSize = sizeof (MENUINFO);
247
   menu_info.fMask = MIM_STYLE;
248
   GetMenuInfo (GetMenu (hMainWnd), &menu_info); // get current style
249
   menu_info.dwStyle |= MNS_MODELESS; // add the "modeless" flag
250
   SetMenuInfo (GetMenu (hMainWnd), &menu_info); // and send it back
251
 
252
   // temporarily add the files for the font we'll use to the system resources
253
   AddFontResourceEx (L"data/fonts/papyrus.ttf", FR_PRIVATE, 0);
254
 
255
   // load status icons, bitmaps and texts
256
   handlestatus[HANDLESTATUS_AVAILABLE].icon = (HICON) LoadImage (NULL, L"data/icons/available.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
257
   handlestatus[HANDLESTATUS_AVAILABLE].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/available.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
258
   handlestatus[HANDLESTATUS_AVAILABLE].text = LOCALIZE (L"Opponents_StatusAvailable");
259
   handlestatus[HANDLESTATUS_INGAME].icon = (HICON) LoadImage (NULL, L"data/icons/ingame.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
260
   handlestatus[HANDLESTATUS_INGAME].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/ingame.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
261
   handlestatus[HANDLESTATUS_INGAME].text = LOCALIZE (L"Opponents_StatusInGame");
262
   handlestatus[HANDLESTATUS_INSIMULATION].icon = (HICON) LoadImage (NULL, L"data/icons/insimulation.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
263
   handlestatus[HANDLESTATUS_INSIMULATION].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/insimulation.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
264
   handlestatus[HANDLESTATUS_INSIMULATION].text = LOCALIZE (L"Opponents_StatusInSimulation");
265
   handlestatus[HANDLESTATUS_INTOURNAMENT].icon = (HICON) LoadImage (NULL, L"data/icons/intournament.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
266
   handlestatus[HANDLESTATUS_INTOURNAMENT].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/intournament.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
267
   handlestatus[HANDLESTATUS_INTOURNAMENT].text = LOCALIZE (L"Opponents_StatusInTournament");
268
   handlestatus[HANDLESTATUS_EXAMININGAGAME].icon = (HICON) LoadImage (NULL, L"data/icons/examiningagame.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
269
   handlestatus[HANDLESTATUS_EXAMININGAGAME].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/examiningagame.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
270
   handlestatus[HANDLESTATUS_EXAMININGAGAME].text = LOCALIZE (L"Opponents_StatusExaminingAGame");
271
   handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].icon = (HICON) LoadImage (NULL, L"data/icons/notopenforamatch.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
272
   handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/notopenforamatch.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
273
   handlestatus[HANDLESTATUS_NOTOPENFORAMATCH].text = LOCALIZE (L"Opponents_StatusNotOpenForAMatch");
274
   handlestatus[HANDLESTATUS_INACTIVEORBUSY].icon = (HICON) LoadImage (NULL, L"data/icons/inactiveorbusy.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
275
   handlestatus[HANDLESTATUS_INACTIVEORBUSY].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/inactiveorbusy.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
276
   handlestatus[HANDLESTATUS_INACTIVEORBUSY].text = LOCALIZE (L"Opponents_StatusInactiveOrBusy");
277
   handlestatus[HANDLESTATUS_OFFLINE].icon = (HICON) LoadImage (NULL, L"data/icons/offline.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
278
   handlestatus[HANDLESTATUS_OFFLINE].bitmap = (HBITMAP) LoadImage (NULL, L"data/status/offline.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
279
   handlestatus[HANDLESTATUS_OFFLINE].text = LOCALIZE (L"Opponents_StatusOffline");
280
 
281
   // load fonts
282
   hFontChat = CreateFont (17, 0, 0, 0, FW_DONTCARE, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
283
                           CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Comic Sans MS");
284
 
285
   // initialize renderer
286
   if (!Render_Init ())
287
      return (-1); // bomb out on error
288
 
289
   // load sprites
290
   larrow_spriteindex = Render_LoadSprite (L"data/sprites/arrow-left.*");
291
   rarrow_spriteindex = Render_LoadSprite (L"data/sprites/arrow-right.*");
292
   chatbutton_spriteindex = Render_LoadSprite (L"data/sprites/chat.*");
293
   gamesbutton_spriteindex = Render_LoadSprite (L"data/sprites/games.*");
294
   peoplebutton_spriteindex = Render_LoadSprite (L"data/sprites/people.*");
295
   sepia_spriteindex = Render_LoadSprite (L"data/sprites/sepia.*");
296
   for (array_index = 0; array_index < 12; array_index++)
297
      spinner_spriteindex[array_index] = Render_LoadSprite (L"data/sprites/spinner-%d.png", array_index * 30); // spinning wheel
298
 
299
   // load fonts
300
   arrow_fontindex = Render_LoadFont (L"Papyrus", 20, false, false);
301
   chat_fontindex = Render_LoadFont (L"Papyrus", 24, false, false);
302
   players_fontindex = Render_LoadFont (L"Papyrus", 32, false, true);
303
   centermsg_fontindex = Render_LoadFont (L"Papyrus", 48, false, true);
304
 
305
   // load themes, initialize a new human vs. human game and setup the scene
306
   if (!Themes_Init ())
307
      return (-1); // bomb out on error
308
   Board_Init (&the_board, PLAYER_HUMAN, PLAYER_HUMAN, FENSTARTUP_STANDARDCHESS);
309
   Scene_Init (&the_scene, &the_board);
310
 
311
   // has a filename been specifed on the command-line AND that file exists ?
312
   if ((lpCmdLine != NULL) && (lpCmdLine[0] != 0))
313
   {
314
      while (*lpCmdLine == '"')
315
         lpCmdLine++; // skip leading quotes
316
      if ((endptr = strchr (lpCmdLine, '"')) != NULL)
317
         *endptr = 0; // break the string at the first ending quote
318
      if (_stat (lpCmdLine, &fileinfo) == 0)
319
      {
320
         ConvertToWideChar (load_pathname, WCHAR_SIZEOF (load_pathname), lpCmdLine); // save pathname string
321
         is_dialogbox_load_validated = true; // and act as if the user just validated a load dialog box
322
      }
323
      else
324
         DialogBox_NewGame (); // if specified filename doesn't exist, fallback to the "new game" dialog box
325
   }
326
   else
327
      DialogBox_NewGame (); // when no filename is specified, display the new game dialog box
328
 
329
   // enter the main loop
330
   animation_endtime = 0.0f;
331
   sound_playtime = 0.0f;
332
   highlight_endtime = 0.0f;
333
   previous_time = 0.0f;
334
   frame_count = 0;
335
   while (!terminate_everything)
336
   {
337
      // see what time it is
338
      current_time = ProcessTime ();
339
 
340
#ifdef DEMO
341
      // are we in demo mode and is it time to quit ?
342
      if (current_time > DEMO_TIMEOUT)
343
         terminate_everything = true; // if so, send a quit message in order to break the loop
344
#endif
345
 
346
      // grab the current window size
347
      GetWindowRect (hMainWnd, &rect);
348
      options.window_width = rect.right - rect.left;
349
      options.window_height = rect.bottom - rect.top;
350
 
351
      // are we in the middle of an animation or just after it ?
352
      if (current_time < animation_endtime + 0.5f)
353
         the_scene.update = true; // always update during animations
354
      else
355
         the_scene.update |= Board_Think (&the_board); // make the board (i.e, both players) think
356
 
357
      MainLoop_FindCurrentViewer ();  // determine current viewer
358
 
359
      // see if we have a message waiting for any window in the current thread and dispatch it
360
      while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
361
      {
362
         // check for accelerator keystrokes from the main window
363
         if ((msg.hwnd != hMainWnd) || !TranslateAccelerator (hMainWnd, hAccelerators, &msg))
364
         {
365
            TranslateMessage (&msg); // translate and dispatch all other messages
366
            DispatchMessage (&msg);
367
         }
368
      }
369
 
370
      // handle dialog box and window return codes
371
      if (is_dialogbox_about_validated) DialogBox_About_Validated ();
372
      if (is_dialogbox_challenge_validated) DialogBox_Challenge_Validated ();
373
      if (is_dialogbox_changeappearance_validated) DialogBox_ChangeAppearance_Validated ();
374
      if (is_dialogbox_comment_validated) DialogBox_Comment_Validated ();
375
      if (is_dialogbox_endgame_validated) DialogBox_EndGame_Validated ();
376
      if (is_dialogbox_gotomove_validated) DialogBox_GoToMove_Validated ();
377
      if (is_dialogbox_load_validated) DialogBox_Load_Validated ();
378
      if (is_dialogbox_message_validated) DialogBox_Message_Validated ();
379
      if (is_dialogbox_newgame_validated) DialogBox_NewGame_Validated ();
380
      if (is_dialogbox_options_validated) DialogBox_Options_Validated ();
381
      if (is_dialogbox_pawnpromotion_validated) DialogBox_PawnPromotion_Validated ();
382
      if (is_dialogbox_playercard_validated) DialogBox_PlayerCard_Validated ();
383
      if (is_dialogbox_playerinfoname_validated) DialogBox_PlayerInfoName_Validated ();
384
      if (is_dialogbox_quit_validated) DialogBox_Quit_Validated ();
385
      if (is_dialogbox_resign_validated) DialogBox_Resign_Validated ();
386
      if (is_dialogbox_save_validated) DialogBox_Save_Validated ();
387
      if (is_dialogbox_saveposition_validated) DialogBox_SavePosition_Validated ();
388
      if (is_dialogbox_sendchallenge_validated) DialogBox_SendChallenge_Validated ();
389
      if (is_dialogbox_sendseek_validated) DialogBox_SendSeek_Validated ();
390
      if (is_dialogbox_takeback_validated) DialogBox_Takeback_Validated ();
391
      if (is_window_chat_validated) Window_Chat_Validated ();
392
      if (is_window_chatterchannels_validated) Window_ChatterChannels_Validated ();
393
      if (is_window_games_validated) Window_Games_Validated ();
394
      if (is_window_motd_validated) Window_MOTD_Validated ();
395
      if (is_window_opponents_validated) Window_Opponents_Validated ();
396
      if (is_window_sought_validated) Window_Sought_Validated ();
397
 
398
      MainLoop_EvaluateGameState (); // evaluate game state
399
 
400
      // is the table rotating ?
401
      if (Player_RotateTable (&the_board.players[current_viewer], current_time - previous_time))
402
         the_scene.update = true; // if so, update the scene
403
 
404
      // are we highlighting something ?
405
      if (highlight_endtime > current_time)
406
         the_scene.update = true; // if so, update the scene
407
 
408
      // else if we WERE just highlighting something, clear the hovered positions
409
      else if (highlight_endtime + 0.1f > current_time)
410
      {
411
         the_board.hovered_position[0] = -1;
412
         the_board.hovered_position[1] = -1;
413
         the_scene.update = true; // and update the scene
414
      }
415
 
416
      // if we want the game clock, update scene every second
417
      if (options.want_clock && ((int) current_time != (int) previous_time))
418
         the_scene.update = true;
419
 
420
      // if there's something in the central text buffer, update scene too
421
      if (the_scene.gui.central_text.is_displayed)
422
         the_scene.update = true;
423
 
424
      // if we have a spinning wheel, update scene too
425
      if (the_scene.gui.want_spinwheel)
426
         the_scene.update = true;
427
 
428
      // do we NOT need to update the scene ?
429
      if (!the_scene.update)
430
      {
431
         // cycle through all themes and see if one of them needs to be loaded
432
         for (array_index = 0; array_index < theme_count; array_index++)
433
            if (!themes[array_index].is_loaded)
434
            {
435
               Theme_Load (&themes[array_index], false); // load a bit more of this theme
436
               break; // and stop looping (see you next pass)
437
            }
438
      }
439
 
440
      // do we need to update the scene ?
441
      if (the_scene.update || want_framerate)
442
      {
443
         Scene_Update (&the_scene, &the_board); // evaluate which parts need to be placed
444
         Render_RenderFrame (&the_scene); // render a game frame
445
 
446
         the_scene.update = false; // scene no longer needs to be updated now
447
      }
448
 
449
      Audio_Think (); // ensure audio is playing
450
 
451
      previous_time = current_time; // save previous time
452
      if (frame_count == 100)
453
      {
454
         frame_count = 0; // reset frame count every 100 frames
455
         Sleep (1); // once every 100 frames, wait a millisecond
456
      }
457
      else
458
         Sleep (0); // else just allow context switching
459
      frame_count++; // increase the frame count
460
   }
461
 
462
   /////////////////////////////////////////////////////////////////////////
463
   // at this point, we exited the main loop and we are returning to Windows
464
 
465
   // release scene, game, themes and shutdown Direct3D
466
   Scene_Shutdown (&the_scene);
467
   Board_Shutdown (&the_board);
468
   Themes_Shutdown ();
469
   Render_Shutdown ();
470
 
471
   // delete the font resources
472
   DeleteObject (hFontChat);
473
 
474
   // delete the bitmap and icon ressources
475
   for (array_index = 1; array_index < sizeof (handlestatus) / sizeof (handlestatus[0]); array_index++)
476
   {
477
      DeleteObject (handlestatus[array_index].bitmap);
478
      DestroyIcon (handlestatus[array_index].icon);
479
   }
480
 
481
   // unregister window class
482
   UnregisterClass (wc.lpszClassName, hAppInstance);
483
 
484
   // destroy the accelerators table
485
   if (hAccelerators)
486
      DestroyAcceleratorTable (hAccelerators);
487
   hAccelerators = NULL;
488
 
489
   // destroy the game menu
490
   if (IsMenu (hMenu))
491
      DestroyMenu (hMenu);
492
   hMenu = NULL;
493
 
494
   // save configuration data
495
   Config_Save ();
496
 
497
   // unload localized texts
498
   LocalizedTexts_Shutdown ();
499
 
500
   return (0); // and return to Windows.
501
}
502
 
503
 
504
static void MainLoop_FindCurrentViewer (void)
505
{
506
   // helper function that tells who is the current viewer
507
 
508
   if ((the_board.players[COLOR_WHITE].type == PLAYER_HUMAN) && (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN))
509
      current_viewer = Board_ColorToMove (&the_board); // if both players are human, track them both
510
   else if (the_board.players[COLOR_WHITE].type == PLAYER_HUMAN)
511
      current_viewer = COLOR_WHITE; // else if only the white is human, track the white
512
   else if (the_board.players[COLOR_BLACK].type == PLAYER_HUMAN)
513
      current_viewer = COLOR_BLACK; // else if it's the black, track the black
514
   else
515
      current_viewer = COLOR_WHITE; // else no human in game, track just the white
516
 
517
   return; // finished, current viewer is known
518
}
519
 
520
 
521
static void MainLoop_EvaluateGameState (void)
522
{
523
   // function to evaluate the game state in the main loop when a part has just moved
524
 
525
   wchar_t window_title[256];
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
   if (!the_board.reevaluate)
534
      return; // if the board doesn't need to be reevaluated, don't do anything
535
 
536
   // get current and opposite players
537
   current_player = Player_GetCurrent ();
538
   opposite_player = Player_GetOpposite ();
539
 
540
   // see if we're online
541
   network_player = Player_FindByType (PLAYER_INTERNET);
542
 
543
   // has the game started ?
544
   if (the_board.move_count > 1)
545
   {
546
      // game has started, enable the "save" and "save as" menu options
547
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_ENABLED);
548
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_ENABLED);
549
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED);
550
 
551
      // enable the "go to move" menu option
552
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_ENABLED);
553
 
554
      // are we watching the last move ?
555
      if (the_board.viewed_move == the_board.move_count - 1)
556
      {
557
         // get a quick acccess to the last move
558
         last_move = &the_board.moves[the_board.move_count - 1];
559
 
560
         // if the current player is a human AND its opponent is a computer, allow him to ask us for a hint
561
         if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
562
            EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_ENABLED);
563
         else
564
            EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED);
565
 
566
         // (if the current player is a human
567
         //  AND (its opponent is another human AND there's at least one move played)
568
         //       OR (its opponent is a computer AND there are at least two moves played)
569
         //       OR (its opponent is a remote player AND we're in game AND there are at least two moves played))
570
         // 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
571
         if (((current_player->type == PLAYER_HUMAN)
572
              && ((opposite_player->type == PLAYER_HUMAN)
573
                  || ((opposite_player->type == PLAYER_COMPUTER) && (the_board.move_count > 2))
574
                  || ((opposite_player->type == PLAYER_INTERNET) && (opposite_player->is_in_game) && (the_board.move_count > 2))))
575
             || ((current_player->type == PLAYER_INTERNET) && (current_player->is_in_game) && (the_board.move_count > 2)))
576
            EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_ENABLED);
577
         else
578
            EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED);
579
 
580
         // is the current player in check ? (to play the right sound)
581
         // read as: was the last move an opponent's move AND did it put us to check ?
582
         if (last_move->is_check)
583
         {
584
            // is it a checkmate ? (checkmate == check + stalemate)
585
            if (last_move->is_stalemate)
586
            {
587
               // display the game over dialog box
588
               the_board.game_state = (Board_ColorToMove (&the_board) == COLOR_WHITE ? STATE_BLACKWIN_CHECKMATE : STATE_WHITEWIN_CHECKMATE);
589
               DialogBox_EndGame ();
590
            }
591
         }
592
         else
593
         {
594
            // is it a stalemate ?
595
            if (last_move->is_stalemate)
596
            {
597
               // display the game over dialog box
598
               the_board.game_state = STATE_DRAW_STALEMATE;
599
               DialogBox_EndGame ();
600
            }
601
         }
602
 
603
         // have there 50 moves been played each side (i.e, 100 plies) AND is the current player human ?
604
         if ((the_board.move_count > 100) && (current_player->type == PLAYER_HUMAN))
605
         {
606
            // go backwards and see when is the latest move that took an opponent's piece OR the latest pawn move
607
            for (move_index = the_board.move_count - 1; move_index >= 0; move_index--)
608
               if (the_board.moves[move_index].has_captured || (the_board.moves[move_index].part == PART_PAWN))
609
                  break; // stop as soon as we find one
610
 
611
            // can the fifty moves draw rule be claimed AND does the current player claims it ?
612
            if (move_index + 1 + 100 < the_board.move_count)
613
            {
614
               // yes. Propose it to the side that's on move
615
// TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values)
616
            }
617
         }
618
 
619
         if (the_scene.gui.larrow.state == 0)
620
            the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet
621
         if (the_scene.gui.rarrow.state != 0)
622
            the_scene.gui.rarrow.state = 0; // disable "forward" arrow if it's already displayed
623
 
624
         if (the_board.game_state == STATE_PLAYING)
625
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
626
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Current"));
627
         else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE))
628
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
629
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_CheckMate"));
630
         else if ((the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT) || (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT))
631
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
632
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Resign"));
633
         else if (the_board.game_state == STATE_DRAW_STALEMATE)
634
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
635
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_StaleMate"));
636
         else if (the_board.game_state == STATE_DRAW_AGREEMENT)
637
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
638
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_Agreement"));
639
         else if (the_board.game_state == STATE_DRAW_OTHER)
640
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
641
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"EndGame_DrawOther"));
642
 
643
         // enable the "comment on this move" menu option
644
         EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED);
645
      }
646
 
647
      // else are we watching another move, but not the beginning of the game ?
648
      else if (the_board.viewed_move > 0)
649
      {
650
         if (the_scene.gui.larrow.state == 0)
651
            the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet
652
         if (the_scene.gui.rarrow.state == 0)
653
            the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet
654
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
655
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false,
656
                        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")));
657
 
658
         // enable the "save position as" and "comment on this move" menu options
659
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_ENABLED);
660
         EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_ENABLED);
661
      }
662
 
663
      // else we must be watching the beginning of the game (no move yet)
664
      else
665
      {
666
         if (the_scene.gui.larrow.state != 0)
667
            the_scene.gui.larrow.state = 0; // disable "back" arrow if it's already displayed
668
         if (the_scene.gui.rarrow.state == 0)
669
            the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet
670
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
671
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Beginning"));
672
 
673
         // disable the "save position as" and "comment on this move" menu options
674
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
675
         EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED);
676
      }
677
   }
678
   else
679
   {
680
      // game has not started, disable the "save", "save as" and "save position as" menu options
681
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVE, MF_GRAYED);
682
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEAS, MF_GRAYED);
683
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
684
 
685
      // also disable the "suggest move", "cancel last move", "comment move" and "go to move" menu options
686
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SUGGESTMOVE, MF_GRAYED);
687
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_CANCELLASTMOVE, MF_GRAYED);
688
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_COMMENTMOVE, MF_GRAYED);
689
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_GRAYED);
690
 
691
      // and disable the two arrows and the arrow text
692
      the_scene.gui.larrow.state = 0;
693
      the_scene.gui.rarrow.state = 0;
694
      the_scene.gui.arrow_text.is_displayed = false;
695
   }
696
 
697
   // 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
698
   if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
699
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_ENABLED);
700
   else
701
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_SWAPSIDES, MF_GRAYED);
702
 
703
   // update window title
704
   if ((the_board.players[COLOR_WHITE].name[0] != 0) && (the_board.players[COLOR_BLACK].name[0] != 0))
705
   {
706
      swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s %s %s - " PROGRAM_NAME, the_board.players[COLOR_WHITE].name, LOCALIZE (L"Versus"), the_board.players[COLOR_BLACK].name);
707
      SetWindowText (hMainWnd, window_title); // update window title
708
   }
709
   else if (the_board.players[COLOR_WHITE].name[0] != 0)
710
   {
711
      swprintf_s (window_title, WCHAR_SIZEOF (window_title), L"%s - " PROGRAM_NAME, the_board.players[COLOR_WHITE].name);
712
      SetWindowText (hMainWnd, window_title); // update window title
713
   }
714
 
715
   // are we in internet mode AND are we logged in ?
716
   if ((network_player != NULL) && network_player->is_logged_in)
717
   {
718
      // are we currently playing a game ?
719
      if (network_player->is_in_game)
720
      {
721
         GUIBUTTON_ENABLE (the_scene.gui.chatbutton); // enable chat button if it's not enabled yet
722
         GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled
723
         GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled
724
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning
725
      }
726
      else
727
      {
728
         GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled
729
         GUIBUTTON_ENABLE (the_scene.gui.gamesbutton); // enable games button if it's not enabled yet
730
         GUIBUTTON_ENABLE (the_scene.gui.peoplebutton); // enable people button if it's not enabled yet
731
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_GRAYED); // disable ability to resign
732
      }
733
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_ENABLED); // enable stats
734
 
735
      enabled_value = MF_ENABLED; // remember to enable the internet-related menu items
736
   }
737
   // else it's a local or vs. computer game
738
   else
739
   {
740
      GUIBUTTON_DISABLE (the_scene.gui.chatbutton); // disable chat button if it was enabled
741
      GUIBUTTON_DISABLE (the_scene.gui.gamesbutton); // disable games button if it was enabled
742
      GUIBUTTON_DISABLE (the_scene.gui.peoplebutton); // disable people button if it was enabled
743
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_RESIGN, MF_ENABLED); // allow resigning
744
      EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_STATISTICS, MF_GRAYED); // disable stats
745
 
746
      enabled_value = MF_GRAYED; // remember to disable the internet-related menu items
747
   }
748
 
749
   EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SETUPPOSITION, !enabled_value); // note the inversion
750
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWONLINEPLAYERS, enabled_value);
751
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SHOWSOUGHTGAMES, enabled_value);
752
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_SEEKGAME, enabled_value);
753
   if (!options.network.want_publicchat)
754
   {
755
      EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, MF_GRAYED); // always grayed if we don't want public chat
756
      EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, MF_GRAYED);
757
   }
758
   else
759
   {
760
      EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_CHATTERCHANNELS, enabled_value); // else enabled only in internet mode
761
      EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_ENTERCHATTEXT, enabled_value);
762
   }
763
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYPLAYERCARD, enabled_value);
764
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_DISPLAYYOURCARD, enabled_value);
765
   EnableMenuItem (GetMenu (hMainWnd), MENUID_INTERNET_MOTD, enabled_value);
766
 
767
   the_board.reevaluate = false; // board evaluation has been done
768
   return; // finished, new board state is known
769
}