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