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