Subversion Repositories Games.Chess Giants

Rev

Rev 116 | Rev 130 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 124
Line 4... Line 4...
4
#include "common.h"
4
#include "common.h"
5
 
-
 
6
 
-
 
7
// handy macros
-
 
8
#define GUIBUTTON_ENABLE(button) { if ((button).state == 0) (button).state = 1; }
-
 
9
#define GUIBUTTON_DISABLE(button) { if ((button).state > 0) (button).state = 0; }
-
 
10
 
5
 
11
 
6
 
12
// prototypes of locally used functions
7
// prototypes of locally used functions
13
static void MainLoop_FindCurrentViewer (void);
8
static void MainLoop_FindCurrentViewer (void);
14
static void MainLoop_EvaluateGameState (void);
9
static void MainLoop_EvaluateGameState (void);
Line 144... Line 139...
144
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title
139
      hMainWnd = CreateWindowEx (0, wc.lpszClassName, temp_string, WS_OVERLAPPEDWINDOW, // temp_string holds window title
145
                                 GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2,
140
                                 GetSystemMetrics (SM_CXSCREEN) / 2 - options.window_width / 2,
146
                                 GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2,
141
                                 GetSystemMetrics (SM_CYSCREEN) / 2 - options.window_height / 2,
147
                                 options.window_width, options.window_height, NULL, NULL, hAppInstance, NULL);
142
                                 options.window_width, options.window_height, NULL, NULL, hAppInstance, NULL);
148
   }
143
   }
149
   ShowWindow (hMainWnd, nCmdShow);
144
   ShowWindow (hMainWnd, (options.want_maximized ? SW_SHOWMAXIMIZED : nCmdShow)); // show it maximized if it was closed so
150
 
145
 
151
   // create the main menu line, and its accelerators
146
   // create the main menu line, and its accelerators
152
   hMainMenu = NULL;
147
   hMainMenu = NULL;
153
   hMainAccelerators = NULL;
148
   hMainAccelerators = NULL;
154
   CreateOrUpdateApplicationMenu ();
149
   CreateOrUpdateApplicationMenu ();
Line 213... Line 208...
213
   // initialize audio and renderer, and display a cleaner version of the splash screen this time :)
208
   // initialize audio and renderer, and display a cleaner version of the splash screen this time :)
214
   if (!Audio_Init () || !Render_Init (L"%s/data/splash.bmp", app_path))
209
   if (!Audio_Init () || !Render_Init (L"%s/data/splash.bmp", app_path))
215
      return (-1); // bomb out on error
210
      return (-1); // bomb out on error
216
 
211
 
217
   // load sprites
212
   // load sprites
218
   larrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-left.*", app_path);
213
   larrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-left.png", app_path);
219
   rarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-right.*", app_path);
214
   rarrow_spriteindex = Render_LoadSprite (L"%s/data/sprites/arrow-right.png", app_path);
-
 
215
   newgamebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/newgame.png", app_path);
-
 
216
   opengamebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/opengame.png", app_path);
220
   chatbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/chat.*", app_path);
217
   chatbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/chat.png", app_path);
221
   gamesbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/games.*", app_path);
218
   gamesbutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/games.png", app_path);
222
   peoplebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/people.*", app_path);
219
   peoplebutton_spriteindex = Render_LoadSprite (L"%s/data/sprites/people.png", app_path);
223
   sepia_spriteindex = Render_LoadSprite (L"%s/data/sprites/sepia.*", app_path);
220
   sepia_spriteindex = Render_LoadSprite (L"%s/data/sprites/sepia.png", app_path);
224
   for (array_index = 0; array_index < 12; array_index++)
221
   for (array_index = 0; array_index < 12; array_index++)
225
      spinner_spriteindex[array_index] = Render_LoadSprite (L"%s/data/sprites/spinner-%d.png", app_path, array_index * 30); // spinning wheel
222
      spinner_spriteindex[array_index] = Render_LoadSprite (L"%s/data/sprites/spinner-%d.png", app_path, array_index * 30); // spinning wheel
226
 
223
 
227
   // add our custom fonts to the list of available fonts for the duration of the process
224
   // add our custom fonts to the list of available fonts for the duration of the process
228
   swprintf_s (font_pathname, WCHAR_SIZEOF (font_pathname), L"%s/data/fonts/papyrus.ttf", app_path);
225
   swprintf_s (font_pathname, WCHAR_SIZEOF (font_pathname), L"%s/data/fonts/papyrus.ttf", app_path);
Line 258... Line 255...
258
      else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL))
255
      else if ((strncmp (lpCmdLine, "/r=", 3) == 0) && ((endptr = strchr (&lpCmdLine[3], ',')) != NULL))
259
      {
256
      {
260
         *endptr = 0; // break the string at the separator between user email and activation code
257
         *endptr = 0; // break the string at the separator between user email and activation code
261
         ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email
258
         ConvertToWideChar (temp_string, WCHAR_SIZEOF (temp_string), &lpCmdLine[3]); // read user email
262
         is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not
259
         is_registered = IsRegistrationCorrect (temp_string, atoi (endptr + 1)); // and see whether we're registered or not
263
         DialogBox_NewGame (); // still open the "new game" dialog box
-
 
264
      }
260
      }
265
#endif // !NDEBUG
261
#endif // !NDEBUG
266
      else
-
 
267
         DialogBox_NewGame (); // if specified filename doesn't exist, fallback to the "new game" dialog box
-
 
268
   }
262
   }
269
   else
263
 
270
      DialogBox_NewGame (); // when no filename is specified, display the new game dialog box
264
   // TODO: this + offline statistics
271
 
265
 
272
   // enter the main loop
266
   // enter the main loop
273
   while (!terminate_everything)
267
   while (!terminate_everything)
274
   {
268
   {
275
      // see what time it is
269
      // see what time it is
Line 282... Line 276...
282
      {
276
      {
283
         mousemove_input.type = INPUT_MOUSE;
277
         mousemove_input.type = INPUT_MOUSE;
284
         memset (&mousemove_input.mi, 0, sizeof (mousemove_input.mi)); // blank out struct = no move at all :)
278
         memset (&mousemove_input.mi, 0, sizeof (mousemove_input.mi)); // blank out struct = no move at all :)
285
         mousemove_input.mi.dwFlags = MOUSEEVENTF_MOVE;
279
         mousemove_input.mi.dwFlags = MOUSEEVENTF_MOVE;
286
         SendInput (1, &mousemove_input, sizeof (mousemove_input)); // send a fake mouse move input event
280
         SendInput (1, &mousemove_input, sizeof (mousemove_input)); // send a fake mouse move input event
287
 
281
 
288
         screensaverwatchdog_feedtime = current_time + 50.0f; // feed screensaver watchdog again in 50 seconds
282
         screensaverwatchdog_feedtime = current_time + 50.0f; // feed screensaver watchdog again in 50 seconds
289
      }
283
      }
290
 
284
 
291
      // are we in demo mode and is it time to quit ?
285
      // are we in demo mode and is it time to quit ?
292
      if (!is_registered && (current_time > DEMO_TIMEOUT))
286
      if (!is_registered && (current_time > DEMO_TIMEOUT))
293
         DestroyWindow (hMainWnd); // if so, send a quit message in order to break the loop
287
         DestroyWindow (hMainWnd); // if so, send a quit message in order to break the loop
294
 
-
 
295
      // grab the current window size
-
 
296
      GetWindowRect (hMainWnd, &rect);
-
 
297
      options.window_width = rect.right - rect.left;
-
 
298
      options.window_height = rect.bottom - rect.top;
-
 
299
 
288
 
300
      // are we in the middle of an animation or just after it ?
289
      // are we in the middle of an animation or just after it ?
301
      if (current_time < animation_endtime + 0.5f)
290
      if (current_time < animation_endtime + 0.5f)
302
         the_scene.update = true; // always update during animations
291
         the_scene.update = true; // always update during animations
303
      else
292
      else
Line 488... Line 477...
488
   player_t *network_player;
477
   player_t *network_player;
489
   boardmove_t *last_move;
478
   boardmove_t *last_move;
490
   int enabled_value;
479
   int enabled_value;
491
   int move_index;
480
   int move_index;
492
 
481
 
493
   if (!the_board.reevaluate)
-
 
494
      return; // if the board doesn't need to be reevaluated, don't do anything
-
 
495
 
-
 
496
   // get current and opposite players
482
   // get current and opposite players, and see if we're online
497
   current_player = Player_GetCurrent ();
483
   current_player = Player_GetCurrent ();
498
   opposite_player = Player_GetOpposite ();
484
   opposite_player = Player_GetOpposite ();
499
 
-
 
500
   // see if we're online
-
 
501
   network_player = Player_FindByType (PLAYER_INTERNET);
485
   network_player = Player_FindByType (PLAYER_INTERNET);
-
 
486
 
-
 
487
   // if the view distance or pitch is lower than the minimum, enable the "new game" and "open game" buttons
-
 
488
   if ((network_player == NULL) && (current_distance == CLOSEUP_VIEW_DISTANCE) && (current_pitch == CLOSEUP_VIEW_PITCH))
-
 
489
   {
-
 
490
      GUIBUTTON_ENABLE (the_scene.gui.newgamebutton);
-
 
491
      GUIBUTTON_ENABLE (the_scene.gui.opengamebutton);
-
 
492
   }
-
 
493
   else
-
 
494
   {
-
 
495
      GUIBUTTON_DISABLE (the_scene.gui.newgamebutton);
-
 
496
      GUIBUTTON_DISABLE (the_scene.gui.opengamebutton);
-
 
497
   }
-
 
498
 
-
 
499
   if (!the_board.reevaluate)
-
 
500
      return; // if the board doesn't need to be reevaluated, don't do anything
502
 
501
 
503
   // has the game started ?
502
   // has the game started ?
504
   if (the_board.move_count > 1)
503
   if (the_board.move_count > 1)
505
   {
504
   {
506
      // game has started, enable the "save" and "save as" menu options
505
      // game has started, enable the "save" and "save as" menu options
Line 574... Line 573...
574
               // yes. Propose it to the side that's on move
573
               // yes. Propose it to the side that's on move
575
// TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values)
574
// TODO: non-modal MessageBox (copy dialog_newgame.cpp and use return values)
576
            }
575
            }
577
         }
576
         }
578
 
577
 
579
         if (the_scene.gui.larrow.state == 0)
-
 
580
            the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet
578
         GUIBUTTON_ENABLE (the_scene.gui.larrow); // enable "back" arrow if it isn't displayed yet
581
         if (the_scene.gui.rarrow.state != 0)
-
 
582
            the_scene.gui.rarrow.state = 0; // disable "forward" arrow if it's already displayed
579
         GUIBUTTON_DISABLE (the_scene.gui.rarrow); // disable "forward" arrow if it's already displayed
583
 
580
 
584
         if (the_board.game_state == STATE_PLAYING)
581
         if (the_board.game_state == STATE_PLAYING)
585
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
582
            Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
586
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (is_paused ? L"Paused" : L"Current"));
583
                           RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (is_paused ? L"Paused" : L"Current"));
587
         else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE))
584
         else if ((the_board.game_state == STATE_BLACKWIN_CHECKMATE) || (the_board.game_state == STATE_WHITEWIN_CHECKMATE))
Line 605... Line 602...
605
      }
602
      }
606
 
603
 
607
      // else are we watching another move, but not the beginning of the game ?
604
      // else are we watching another move, but not the beginning of the game ?
608
      else if (the_board.viewed_move > 0)
605
      else if (the_board.viewed_move > 0)
609
      {
606
      {
610
         if (the_scene.gui.larrow.state == 0)
-
 
611
            the_scene.gui.larrow.state = 1; // enable "back" arrow if it isn't displayed yet
607
         GUIBUTTON_ENABLE (the_scene.gui.larrow); // enable "back" arrow if it isn't displayed yet
612
         if (the_scene.gui.rarrow.state == 0)
-
 
613
            the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet
608
         GUIBUTTON_ENABLE (the_scene.gui.rarrow); // enable "forward" arrow if it isn't displayed yet
614
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
609
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
615
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false,
610
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false,
616
                        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")));
611
                        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")));
617
 
612
 
618
         // enable the "save position as" and "comment on this move" menu options
613
         // enable the "save position as" and "comment on this move" menu options
Line 621... Line 616...
621
      }
616
      }
622
 
617
 
623
      // else we must be watching the beginning of the game (no move yet)
618
      // else we must be watching the beginning of the game (no move yet)
624
      else
619
      else
625
      {
620
      {
626
         if (the_scene.gui.larrow.state != 0)
-
 
627
            the_scene.gui.larrow.state = 0; // disable "back" arrow if it's already displayed
621
         GUIBUTTON_DISABLE (the_scene.gui.larrow); // disable "back" arrow if it's already displayed
628
         if (the_scene.gui.rarrow.state == 0)
-
 
629
            the_scene.gui.rarrow.state = 1; // enable "forward" arrow if it isn't displayed yet
622
         GUIBUTTON_ENABLE (the_scene.gui.rarrow); // enable "forward" arrow if it isn't displayed yet
630
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
623
         Scene_SetText (&the_scene.gui.arrow_text, 3.3f, 5.0f, -1, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex,
631
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Beginning"));
624
                        RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, LOCALIZE (L"Beginning"));
632
 
625
 
633
         // disable the "save position as" and "comment on this move" menu options
626
         // disable the "save position as" and "comment on this move" menu options
634
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
627
         EnableMenuItem (GetMenu (hMainWnd), MENUID_GAME_SAVEPOSITIONAS, MF_GRAYED);
Line 654... Line 647...
654
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_GRAYED);
647
      EnableMenuItem (GetMenu (hMainWnd), MENUID_CHESSBOARD_GOTOMOVE, MF_GRAYED);
655
 
648
 
656
      is_paused = false; // clear pause status (we can only pause a game when it's been started)
649
      is_paused = false; // clear pause status (we can only pause a game when it's been started)
657
 
650
 
658
      // and disable the two arrows and the arrow text
651
      // and disable the two arrows and the arrow text
659
      the_scene.gui.larrow.state = 0;
652
      GUIBUTTON_DISABLE (the_scene.gui.larrow);
660
      the_scene.gui.rarrow.state = 0;
653
      GUIBUTTON_DISABLE (the_scene.gui.rarrow);
661
      the_scene.gui.arrow_text.is_displayed = false;
654
      the_scene.gui.arrow_text.is_displayed = false;
662
   }
655
   }
663
 
656
 
664
   // 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
657
   // 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
665
   if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))
658
   if ((current_player->type == PLAYER_HUMAN) && (opposite_player->type == PLAYER_COMPUTER))