Subversion Repositories Games.Chess Giants

Rev

Rev 177 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 185
Line 40... Line 40...
40
   int column;
40
   int column;
41
   int index_line;
41
   int index_line;
42
   int index_column;
42
   int index_column;
43
   int part_index;
43
   int part_index;
44
   int part_color;
44
   int part_color;
-
 
45
   int part_count;
45
   int viewer_index;
46
   int viewer_index;
46
   RECT rect;
47
   RECT rect;
47
   POINT point;
48
   POINT point;
48
 
49
 
49
   // filter out the commonly used message values
50
   // filter out the commonly used message values
Line 207... Line 208...
207
 
208
 
208
      // chessboard menu, beginning of game
209
      // chessboard menu, beginning of game
209
      else if (wParam_loword == MENUID_CHESSBOARD_BEGINNINGOFGAME)
210
      else if (wParam_loword == MENUID_CHESSBOARD_BEGINNINGOFGAME)
210
      {
211
      {
211
         the_board.viewed_move = 0; // enter view mode and go to the beginning of the game
212
         the_board.viewed_move = 0; // enter view mode and go to the beginning of the game
212
         Audio_PlaySound (SOUNDTYPE_CLICK, 0.0f, 0.0f, 0.04f); // make a click sound at the center of the board
213
         Audio_PlaySoundAtCenter (SOUNDTYPE_CLICK); // make a click sound at the center of the board
213
         the_board.reevaluate = true; // evaluate board again
214
         the_board.reevaluate = true; // evaluate board again
214
      }
215
      }
215
 
216
 
216
      // chessboard menu, previous move (only if arrow is enabled)
217
      // chessboard menu, previous move (only if arrow is enabled)
217
      else if ((wParam_loword == MENUID_CHESSBOARD_PREVIOUSMOVE) && (the_scene.gui.larrow.state != 0))
218
      else if ((wParam_loword == MENUID_CHESSBOARD_PREVIOUSMOVE) && (the_scene.gui.larrow.state != 0))
218
      {
219
      {
219
         the_board.viewed_move--; // enter view mode and go back one move
220
         the_board.viewed_move--; // enter view mode and go back one move
220
         Audio_PlaySound (SOUNDTYPE_CLICK, 0.0f, 0.0f, 0.04f); // make a click sound at the center of the board
221
         Audio_PlaySoundAtCenter (SOUNDTYPE_CLICK); // make a click sound at the center of the board
221
         the_board.reevaluate = true; // evaluate board again
222
         the_board.reevaluate = true; // evaluate board again
222
      }
223
      }
223
 
224
 
224
      // chessboard menu, next move (only if arrow is enabled)
225
      // chessboard menu, next move (only if arrow is enabled)
225
      else if ((wParam_loword == MENUID_CHESSBOARD_NEXTMOVE) && (the_scene.gui.rarrow.state != 0))
226
      else if ((wParam_loword == MENUID_CHESSBOARD_NEXTMOVE) && (the_scene.gui.rarrow.state != 0))
226
      {
227
      {
227
         the_board.viewed_move++; // enter view mode and go forward one move
228
         the_board.viewed_move++; // enter view mode and go forward one move
228
         Audio_PlaySound (SOUNDTYPE_CLICK, 0.0f, 0.0f, 0.04f); // make a click sound at the center of the board
229
         Audio_PlaySoundAtCenter (SOUNDTYPE_CLICK); // make a click sound at the center of the board
229
         the_board.reevaluate = true; // evaluate board again
230
         the_board.reevaluate = true; // evaluate board again
230
      }
231
      }
231
 
232
 
232
      // chessboard menu, current state of game
233
      // chessboard menu, current state of game
233
      else if (wParam_loword == MENUID_CHESSBOARD_CURRENTSTATEOFGAME)
234
      else if (wParam_loword == MENUID_CHESSBOARD_CURRENTSTATEOFGAME)
234
      {
235
      {
235
         the_board.viewed_move = the_board.move_count - 1; // enter view mode and go to the current state of the game
236
         the_board.viewed_move = the_board.move_count - 1; // enter view mode and go to the current state of the game
236
         Audio_PlaySound (SOUNDTYPE_CLICK, 0.0f, 0.0f, 0.04f); // make a click sound at the center of the board
237
         Audio_PlaySoundAtCenter (SOUNDTYPE_CLICK); // make a click sound at the center of the board
237
         the_board.reevaluate = true; // evaluate board again
238
         the_board.reevaluate = true; // evaluate board again
238
      }
239
      }
239
 
240
 
240
      // chessboard menu, top view
241
      // chessboard menu, top view
241
      else if (wParam_loword == MENUID_CHESSBOARD_TOPVIEW)
242
      else if (wParam_loword == MENUID_CHESSBOARD_TOPVIEW)
Line 536... Line 537...
536
         // for each selectable part, if the mouse is on it, mark it as selected
537
         // for each selectable part, if the mouse is on it, mark it as selected
537
         for (part_index = 0; part_index < 13; part_index++)
538
         for (part_index = 0; part_index < 13; part_index++)
538
            if (Render_IsMouseInBox (gui_x, gui_y, part_index * (100.0f / 13.0f), 0, 100.0f / 13.0f, 11.0f))
539
            if (Render_IsMouseInBox (gui_x, gui_y, part_index * (100.0f / 13.0f), 0, 100.0f / 13.0f, 11.0f))
539
            {
540
            {
540
               the_scene.gui.partspick_selectedpart = selectable_parts[part_index]; // mark it as selected
541
               the_scene.gui.partspick_selectedpart = selectable_parts[part_index]; // mark it as selected
541
               Audio_PlaySound (SOUNDTYPE_CLICK, 0.0f, 0.0f, 0.04f); // make a click sound at the center of the board
542
               Audio_PlaySoundAtCenter (SOUNDTYPE_CLICK); // make a click sound at the center of the board
542
               break; // no need to search further if one selection was found
543
               break; // no need to search further if one selection was found
543
            }
544
            }
544
      }
545
      }
545
 
546
 
546
      // if we are not allowed to select anything, don't even try
547
      // if we are not allowed to select anything, don't even try
Line 589... Line 590...
589
         if (the_scene.gui.partspick_selectedpart == tolower (the_scene.gui.partspick_selectedpart))
590
         if (the_scene.gui.partspick_selectedpart == tolower (the_scene.gui.partspick_selectedpart))
590
            part_color = COLOR_BLACK; // black color
591
            part_color = COLOR_BLACK; // black color
591
         else
592
         else
592
            part_color = COLOR_WHITE; // white color
593
            part_color = COLOR_WHITE; // white color
593
 
594
 
594
         // are we erasing a king ? if so, replace it at its default location
595
         // in parts placement mode, we must not allow for the creation of a deliring chessboard. A few rules have to be respected.
595
         if ((current_move->slots[line][column].part == PART_KING) && (current_move->slots[line][column].color == COLOR_BLACK)
596
         // for each color:
596
             && (the_scene.gui.partspick_selectedpart != 'k'))
597
         // - no more than 16 parts per color, i.e. the equivalent of 2 rows
597
         {
598
         // - no more than 8 pawns
598
            // is it ALREADY the king's default location ? if so, give up
599
         // - no more than 10 knights, i.e. 2 genuine + 8 promoted
599
            if ((line == 7) && (column == 4))
600
         // - no more than 10 bishops, i.e. 2 genuine + 8 promoted
600
            {
601
         // - no more than 10 rooks,   i.e. 2 genuine + 8 promoted
601
               Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the "illegal move" sound
602
         // - no more than 9 queens,   i.e. 1 genuine + 8 promoted
-
 
603
         // - no more than 1 king
602
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
604
         // - no pawns on the 1st (back) or the 8th (promotion) row
603
            }
605
         // and also:
-
 
606
         // - the side not on move must not be in check (TODO)
604
 
607
 
-
 
608
         // count limits
-
 
609
         part_count = 0; // count the number of pieces of the color we want to place
-
 
610
         for (index_line = 0; index_line < 8; index_line++)
-
 
611
            for (index_column = 0; index_column < 8; index_column++)
-
 
612
               if ((current_move->slots[index_line][index_column].part != PART_NONE) && (current_move->slots[index_line][index_column].color == part_color))
-
 
613
                  part_count++;
-
 
614
         if (part_count >= 16) // if we already have 16 parts of this color...
-
 
615
         {
605
            Move_SetSlot (current_move, 7, 4, COLOR_BLACK, PART_KING); // replace black king
616
            Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
617
            Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan16PiecesInTotal"));
-
 
618
            return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
606
         }
619
         }
-
 
620
 
-
 
621
         // are we erasing the king ? if so, replace it at his default location
-
 
622
         if ((current_move->slots[line][column].part == PART_KING)
607
         else if ((current_move->slots[line][column].part == PART_KING) && (current_move->slots[line][column].color == COLOR_WHITE)
623
             && (   ((current_move->slots[line][column].color == COLOR_BLACK) && (the_scene.gui.partspick_selectedpart != 'k'))
608
                  && (the_scene.gui.partspick_selectedpart != 'K'))
624
                 || ((current_move->slots[line][column].color == COLOR_WHITE) && (the_scene.gui.partspick_selectedpart != 'K'))))
609
         {
625
         {
610
            // is it ALREADY the king's default location ? if so, give up
626
            // is it ALREADY the king's default location ? if so, silently prevent the user from doing that
611
            if ((line == 0) && (column == 4))
627
            if ((line == (current_move->slots[line][column].color == COLOR_BLACK ? 7 : 0)) && (column == 4))
612
            {
-
 
613
               Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the "illegal move" sound
-
 
614
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
628
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
615
            }
-
 
616
 
629
 
-
 
630
            // replace the king at his default location
617
            Move_SetSlot (current_move, 0, 4, COLOR_WHITE, PART_KING); // replace white king
631
            Move_SetSlot (current_move, (current_move->slots[line][column].color == COLOR_BLACK ? 7 : 0), 4, current_move->slots[line][column].color, PART_KING);
618
         }
632
         }
619
 
633
 
620
         // place the selected part on the board
634
         // place the selected part on the board
-
 
635
         #define COUNT_PARTS(part_type) part_count = 0; for (index_line = 0; index_line < 8; index_line++) for (index_column = 0; index_column < 8; index_column++) if ((current_move->slots[index_line][index_column].color == part_color) && (current_move->slots[index_line][index_column].part == (part_type))) part_count++;
621
         if (tolower (the_scene.gui.partspick_selectedpart) == 'p')
636
         if (tolower (the_scene.gui.partspick_selectedpart) == 'p')
-
 
637
         {
-
 
638
            COUNT_PARTS (PART_PAWN); // count the number of pawns of the color we want to place
-
 
639
            if ((part_count >= 8) || (line == 0) || (line == 7)) // if we already have 8 pawns of this color OR if we are attempting to place a pawn on the 1st or 8th line...
-
 
640
            {
-
 
641
               Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
642
               Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan8Pawns"));
-
 
643
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
-
 
644
            }
622
            Move_SetSlot (current_move, line, column, part_color, PART_PAWN); // pawn
645
            Move_SetSlot (current_move, line, column, part_color, PART_PAWN); // pawn
-
 
646
         }
623
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'r')
647
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'r')
-
 
648
         {
-
 
649
            COUNT_PARTS (PART_ROOK); // count the number of rooks of the color we want to place
-
 
650
            if (part_count >= 10) // if we already have 10 rooks of this color (2 genuine + 8 promoted)...
-
 
651
            {
-
 
652
               Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
653
               Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan10Rooks"));
-
 
654
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
-
 
655
            }
624
            Move_SetSlot (current_move, line, column, part_color, PART_ROOK); // rook
656
            Move_SetSlot (current_move, line, column, part_color, PART_ROOK); // rook
-
 
657
         }
625
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'n')
658
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'n')
-
 
659
         {
-
 
660
            COUNT_PARTS (PART_KNIGHT); // count the number of bishops of the color we want to place
-
 
661
            if (part_count >= 10) // if we already have 10 knights of this color (2 genuine + 8 promoted)...
-
 
662
            {
-
 
663
               Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
664
               Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan10Knights"));
-
 
665
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
-
 
666
            }
626
            Move_SetSlot (current_move, line, column, part_color, PART_KNIGHT); // knight
667
            Move_SetSlot (current_move, line, column, part_color, PART_KNIGHT); // knight
-
 
668
         }
627
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'b')
669
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'b')
-
 
670
         {
-
 
671
            COUNT_PARTS (PART_BISHOP); // count the number of bishops of the color we want to place
-
 
672
            if (part_count >= 10) // if we already have 10 bishops of this color (2 genuine + 8 promoted)...
-
 
673
            {
-
 
674
               Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
675
               Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan10Bishops"));
-
 
676
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
-
 
677
            }
628
            Move_SetSlot (current_move, line, column, part_color, PART_BISHOP); // bishop
678
            Move_SetSlot (current_move, line, column, part_color, PART_BISHOP); // bishop
-
 
679
         }
629
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'q')
680
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'q')
-
 
681
         {
-
 
682
            COUNT_PARTS (PART_QUEEN); // count the number of queens of the color we want to place
-
 
683
            if (part_count >= 9) // if we already have 9 queens of this color (1 genuine + 8 promoted)...
-
 
684
            {
-
 
685
               Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, line, column); // play the "illegal move" sound
-
 
686
               Scene_AddCCAnnouncement (&the_scene, NULL, LOCALIZE (L"NoMoreThan9Queens"));
-
 
687
               return (DefWindowProc (hWnd, message, wParam, lParam)); // call the default window message proc
-
 
688
            }
630
            Move_SetSlot (current_move, line, column, part_color, PART_QUEEN); // queen
689
            Move_SetSlot (current_move, line, column, part_color, PART_QUEEN); // queen
-
 
690
         }
631
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'k')
691
         else if (tolower (the_scene.gui.partspick_selectedpart) == 'k')
632
         {
692
         {
633
            // parse the board for other kings of the same color and erase them
693
            // parse the board for other kings of the same color and erase them
634
            for (index_line = 0; index_line < 8; index_line++)
694
            for (index_line = 0; index_line < 8; index_line++)
635
               for (index_column = 0; index_column < 8; index_column++)
695
               for (index_column = 0; index_column < 8; index_column++)
Line 642... Line 702...
642
         else
702
         else
643
            Move_SetSlot (current_move, line, column, 0, PART_NONE); // no part
703
            Move_SetSlot (current_move, line, column, 0, PART_NONE); // no part
644
 
704
 
645
         // figure out which sound to play
705
         // figure out which sound to play
646
         if (the_scene.gui.partspick_selectedpart != ' ')
706
         if (the_scene.gui.partspick_selectedpart != ' ')
647
            Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play a move sound when placing a part
707
            Audio_PlaySoundAtSlot (SOUNDTYPE_MOVE, line, column); // play a move sound when placing a part
648
 
708
 
649
         the_scene.update = true; // update the 3D scene
709
         the_scene.update = true; // update the 3D scene
650
 
710
 
651
         // call the default window message processing function to keep things going
711
         // call the default window message processing function to keep things going
652
         return (DefWindowProc (hWnd, message, wParam, lParam));
712
         return (DefWindowProc (hWnd, message, wParam, lParam));
Line 706... Line 766...
706
               || (current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].flags & FLAG_TAKEABLE))
766
               || (current_move->slots[the_board.hovered_position[0]][the_board.hovered_position[1]].flags & FLAG_TAKEABLE))
707
      {
767
      {
708
         // are we in check after the move ? (FIXME: call EP version of this func for en passant moves)
768
         // are we in check after the move ? (FIXME: call EP version of this func for en passant moves)
709
         if (Move_IsColorInCheckAfterTestMove (current_move, the_board.selected_position[0], the_board.selected_position[1], the_board.hovered_position[0], the_board.hovered_position[1], Board_ColorToMove (&the_board)))
769
         if (Move_IsColorInCheckAfterTestMove (current_move, the_board.selected_position[0], the_board.selected_position[1], the_board.hovered_position[0], the_board.hovered_position[1], Board_ColorToMove (&the_board)))
710
         {
770
         {
711
            Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE, 17.5f - (7 - the_board.hovered_position[1]) * 5.0f, 17.5f - the_board.hovered_position[0] * 5.0f, 0.04f); // play the "illegal move" sound
771
            Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, the_board.hovered_position[0], the_board.hovered_position[1]); // play the "illegal move" sound
712
 
772
 
713
            the_scene.update = true; // update the 3D scene
773
            the_scene.update = true; // update the 3D scene
714
 
774
 
715
            // call the default window message processing function to keep things going
775
            // call the default window message processing function to keep things going
716
            return (DefWindowProc (hWnd, message, wParam, lParam));
776
            return (DefWindowProc (hWnd, message, wParam, lParam));
Line 746... Line 806...
746
         return (DefWindowProc (hWnd, message, wParam, lParam));
806
         return (DefWindowProc (hWnd, message, wParam, lParam));
747
      }
807
      }
748
 
808
 
749
      // else it's another location
809
      // else it's another location
750
 
810
 
751
      Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE, 17.5f - (7 - the_board.hovered_position[1]) * 5.0f, 17.5f - the_board.hovered_position[0] * 5.0f, 0.04f); // play the "illegal move" sound
811
      Audio_PlaySoundAtSlot (SOUNDTYPE_ILLEGALMOVE, the_board.hovered_position[0], the_board.hovered_position[1]); // play the "illegal move" sound
752
 
812
 
753
      the_scene.update = true; // update the 3D scene
813
      the_scene.update = true; // update the 3D scene
754
 
814
 
755
      // call the default window message processing function to keep things going
815
      // call the default window message processing function to keep things going
756
      return (DefWindowProc (hWnd, message, wParam, lParam));
816
      return (DefWindowProc (hWnd, message, wParam, lParam));
Line 1128... Line 1188...
1128
            else if (wParam == 0x0d)
1188
            else if (wParam == 0x0d)
1129
               the_scene.gui.is_entering_text = false; // enter, exit from the text entering mode (this will validate our reply)
1189
               the_scene.gui.is_entering_text = false; // enter, exit from the text entering mode (this will validate our reply)
1130
 
1190
 
1131
            // else it's an illegal character
1191
            // else it's an illegal character
1132
            else
1192
            else
1133
               Audio_PlaySound (SOUNDTYPE_ILLEGALMOVE, 0.0f, 0.0f, 0.04f); // illegal character, beep the illegal move sound at the center of the board
1193
               Audio_PlaySoundAtCenter (SOUNDTYPE_ILLEGALMOVE); // illegal character, beep the illegal move sound at the center of the board
1134
         }
1194
         }
1135
 
1195
 
1136
         the_scene.update = true; // update the 3D scene
1196
         the_scene.update = true; // update the 3D scene
1137
 
1197
 
1138
         // call the default window message processing function to keep things going
1198
         // call the default window message processing function to keep things going