16 extern struct options options
;
17 extern struct game_states states
;
18 extern Square legal_moves
[100];
20 extern GtkWidget
*main_window
;
23 GtkWidget
*PlayerSettingsWindow
;
26 GtkWidget
*file_selector
;
27 gchar
*selected_filename
;
29 /* Local Prototypes */
30 void load_new_theme (GtkFileSelection
*selector
, gpointer user_data
);
31 void save_game_history(GtkFileSelection
*selector
, gpointer user_data
);
32 void on_ThemeCancelButton_clicked(GtkButton
*button
, gpointer user_data
);
33 void on_save_as1CancelButton_clicked(GtkButton
*button
, gpointer user_data
);
34 void on_OpenCancelButton_clicked(GtkButton
*button
, gpointer user_data
);
35 void load_saved_game(GtkFileSelection
*selector
, gpointer user_data
);
39 on_new1_activate (GtkMenuItem
*menuitem
,
43 if (bstate_get_moving_piece())
45 gnome_warning_dialog("Unable to start a new game while a piece is being moved. Please try again.");
52 init_game_board(main_window
);
53 load_values_from_file();
55 bstate_set_just_finished(NEW_GAME
);
56 while (bstate_get_what_next() == WAIT_FOR_AI
)
57 move_ai(); //if both players are AI, keeps on running
64 on_quit1_activate (GtkMenuItem
*menuitem
,
69 bstate_set_just_finished(QUIT_GAME
);
77 on_clear1_activate (GtkMenuItem
*menuitem
,
85 on_preferences1_activate (GtkMenuItem
*menuitem
,
93 on_about1_activate (GtkMenuItem
*menuitem
,
96 static GtkWidget
*about
;
97 GdkPixbuf
*pixbuf
= NULL
;
99 const gchar
*authors
[] = {"Ron Yorgason", "Sean McMillen", NULL
};
100 gchar
*documenters
[] = {
103 /* Translator credits */
104 gchar
*translator_credits
= _("translator_credits");
107 gdk_window_raise (about
->window
);
108 gdk_window_show (about
->window
);
115 strcpy(filename
, PACKAGE_DATA_DIR
"/pixmaps/gnome-gamazons.png");
116 pixbuf
= gdk_pixbuf_new_from_file(filename
, NULL
);
119 about
= gnome_about_new (_("Gamazons"), VERSION
,
120 "(C) 2002 Ronald Yorgason and Sean McMillen",
121 _("Send comments and bug reports to: "
122 "yorgasor@cs.pdx.edu"),
123 (const char **)authors
,
124 (const char **)documenters
,
125 strcmp (translator_credits
, "translator_credits") != 0 ? translator_credits
: NULL
,
127 g_signal_connect (G_OBJECT (about
), "destroy", G_CALLBACK
128 (gtk_widget_destroyed
), &about
);
129 gtk_widget_show (about
);
134 on_network1_activate (GtkMenuItem
*menuitem
,
142 on_player1_activate (GtkMenuItem
*menuitem
,
145 GtkWidget
*time
, *width
, *depth
;
146 GtkWidget
*white_ai
, *white_h
, *black_ai
, *black_h
;
149 if (bstate_get_open_dialog())
152 bstate_set_open_dialog(TRUE
);
153 PlayerSettingsWindow
= create_PlayerSettings();
155 /* grab all the widgets */
156 time
= lookup_widget(PlayerSettingsWindow
, "TimeSpinner");
157 width
= lookup_widget(PlayerSettingsWindow
, "WidthSpinner");
158 depth
= lookup_widget(PlayerSettingsWindow
, "DepthSpinner");
159 white_ai
= lookup_widget(PlayerSettingsWindow
, "WhiteAIRadio");
160 white_h
= lookup_widget(PlayerSettingsWindow
, "WhiteHumanRadio");
161 black_ai
= lookup_widget(PlayerSettingsWindow
, "BlackAIRadio");
162 black_h
= lookup_widget(PlayerSettingsWindow
, "BlackHumanRadio");
167 /* Load current values */
168 load_values_from_file();
169 gtk_spin_button_set_value( (GtkSpinButton
*)time
, options
.engine
.timeout
);
170 gtk_spin_button_set_value( (GtkSpinButton
*)width
, options
.engine
.maxwidth
);
171 gtk_spin_button_set_value( (GtkSpinButton
*)depth
, options
.engine
.maxdepth
);
173 if (options
.white_player
== HUMAN
)
174 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(white_h
), TRUE
);
176 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(white_ai
), TRUE
);
178 if (options
.black_player
== HUMAN
)
179 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black_h
), TRUE
);
181 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(black_ai
), TRUE
);
184 gtk_widget_show(PlayerSettingsWindow
);
190 on_how_to_play1_activate (GtkMenuItem
*menuitem
,
193 GError
*error
= NULL
;
194 if (gnome_help_display("gamazons",NULL
,&error
))
197 printf("I should pop up the help display now\n");
203 printf("I couldn't display the help screen, sorry.\n");
205 printf("%s\n", error
->message
);
211 on_help2_activate (GtkMenuItem
*menuitem
,
218 on_BT_UNDO_clicked (GtkButton
*button
,
222 GtkWidget
*undo_button
;
225 if (bstate_get_moving_piece())
227 if (bstate_get_open_dialog())
230 if (bstate_get_what_next() == FIRE_ARROW
) //Undo during mid-move
232 int to_col
, from_col
, to_row
, from_row
;
235 from
= bstate_get_move_to();
236 to
= bstate_get_move_from();
238 bstate_set_move_to(to
);
239 bstate_set_move_from(from
);
241 move_piece_to (to
, board
->selected_queen
);
243 //roll back the state of the board
244 from_col
= get_x_int_from_square(bstate_get_move_from());
245 from_row
= get_y_int_from_square(bstate_get_move_from());
247 to_col
= get_x_int_from_square(bstate_get_move_to());
248 to_row
= get_y_int_from_square(bstate_get_move_to());
250 board
->squares
[to_row
][to_col
] = board
->squares
[from_row
][from_col
];
251 board
->squares
[from_row
][from_col
] = NOTHING
;
252 gen_legal_moves(bstate_get_move_to());
254 if (board
->squares
[to_row
][to_col
] == WHITE
)
256 bstate_set_just_finished(UNDO
);
257 for (i
=0; i
<4; i
++) //update queen to square mapping
259 if (board
->square_to_wh_queen_map
[i
] == to_row
*10 + to_col
)
261 board
->square_to_wh_queen_map
[i
] = from_row
*10 + from_col
;
268 bstate_set_just_finished(UNDO
);
269 for (i
=0; i
<4; i
++) //update queen to square mapping
271 if (board
->square_to_bl_queen_map
[i
] == to_row
*10 + to_col
)
273 board
->square_to_bl_queen_map
[i
] = from_row
*10 + from_col
;
285 /*==============================================================================
286 * on_BT_FORCEMOVE_clicked
288 * This sets the global timeout variable, forcing the AI to take the best move
289 * currently available.
292 on_BT_FORCEMOVE_clicked (GtkButton
*button
,
295 if (bstate_get_moving_piece())
297 if (bstate_get_open_dialog())
299 bstate_set_just_finished(FORCE_MOVE
);
303 /*==============================================================================
304 * on_BT_AUTOFINISH_clicked
306 * This starts the auto-finish process if allowed. This can't be done inbetween
307 * a human player moving & firing an arrow, or while an AI is moving.
311 on_BT_AUTOFINISH_clicked (GtkButton
*button
,
314 if (bstate_get_moving_piece())
316 if (bstate_get_open_dialog())
318 options
.white_player
= AI
;
319 options
.black_player
= AI
;
320 options
.engine
.timeout
= 1;
321 options
.engine
.maxdepth
= 5;
322 options
.engine
.maxwidth
= 15;
323 bstate_set_just_finished(AUTO_FINISH
);
324 while (bstate_get_what_next() == WAIT_FOR_AI
)
325 move_ai(); //if both players are AI, keeps on running
331 on_GamazonsMain_destroy (GtkObject
*object
,
336 bstate_set_just_finished(QUIT_GAME
);
342 /*==============================================================================
345 * This is the main board handling routine. Determines what the user is clicking
346 * on and what a click means.
348 int board_press_cb (GnomeCanvasItem
*item
, GdkEvent
*event
, gpointer data
)
350 double drop_x
, drop_y
;
352 int from_row
, from_col
, to_row
, to_col
;
355 GtkWidget
*auto_button
, *undo_button
;
359 if (bstate_get_moving_piece())
361 //printf("Can't do that while a piece is moving\n");
364 if (bstate_get_open_dialog())
366 //printf("Can't do that while another window is open\n");
369 if (bstate_get_what_next() == NEW_GAME
)
371 //printf("Can't do that while I'm expecting a new game to start\n");
374 if (bstate_get_replay_mode())
377 switch (event
->type
) {
378 case GDK_BUTTON_PRESS
:
379 if (event
->button
.button
!= 1)
383 printf("what_next = %d\n", bstate_get_what_next());
385 //Set where a piece is coming from
386 board
->orig_x
= board
->curr_x
= event
->button
.x
;
387 board
->orig_y
= board
->curr_y
= event
->button
.y
;
388 from
= get_square (board
->curr_x
, board
->curr_y
);
389 from_col
= get_x_int_from_square(from
);
390 from_row
= get_y_int_from_square(from
);
396 //Make sure it's time to move a queen before letting the user do it,
397 //as well as make sure he's moving his own queen. Also make sure it's
400 printf("checking row %d, col %d\n", from_row
, from_col
);
401 square_contains(from
);
402 printf("board->squares = %d\n",board
->squares
[from_row
][from_col
]);
404 if ((board
->squares
[from_row
][from_col
] == WHITE
&&
405 bstate_get_what_next() == MOVE_WHITE_QUEEN
&&
406 options
.white_player
== HUMAN
) ||
407 (board
->squares
[from_row
][from_col
] == BLACK
&&
408 bstate_get_what_next() == MOVE_BLACK_QUEEN
&&
409 options
.black_player
== HUMAN
))
411 //Human is moving a queen
413 printf("board->squares = %d, what_next = %d\n", board
->squares
[from_row
][from_col
], bstate_get_what_next());
415 grabbed_queen
= TRUE
;
416 gen_legal_moves(from
);
418 printf("grabbing queen\n");
420 gnome_canvas_item_raise_to_top (item
);
421 gnome_canvas_item_grab (item
,
422 GDK_POINTER_MOTION_MASK
|
423 GDK_BUTTON_RELEASE_MASK
,
427 board
->selected_queen
= item
;
429 from
= get_square (board
->curr_x
, board
->curr_y
);
432 printf("GDK_BUTTON_PRESS: to = %d from = %d\n", to
, from
);
436 case GDK_MOTION_NOTIFY
:
437 if (event
&& (event
->motion
.state
& GDK_BUTTON1_MASK
))
441 new_x
= event
->motion
.x
;
442 new_y
= event
->motion
.y
;
443 gnome_canvas_item_raise_to_top (item
);
444 gnome_canvas_item_move (item
,
445 new_x
- board
->curr_x
,
446 new_y
- board
->curr_y
);
449 board
->curr_x
= new_x
;
450 board
->curr_y
= new_y
;
454 case GDK_BUTTON_RELEASE
:
455 if (event
->button
.button
!= 1)
458 printf("what_next = %d\n", bstate_get_what_next());
460 if (grabbed_queen
== FALSE
)
463 grabbed_queen
= FALSE
;
466 gnome_canvas_item_ungrab (item
, event
->button
.time
);
470 printf("GDK_BUTTON_RELEASE: to = %d from = %d\n", to
, from
);
472 drop_x
= event
->button
.x
;
473 drop_y
= event
->button
.y
;
475 //something funny here?
476 if (is_queen_square(get_square (drop_x
, drop_y
)))
478 move_piece_to (to
, item
);
483 printf("Queen is dropped at coords %f, %f\n", drop_x
, drop_y
);
485 to
= get_square (drop_x
, drop_y
);
487 printf("new square is %d\n", to
);
490 /* Register the queen move with the board */
491 from_col
= get_x_int_from_square(from
);
492 from_row
= get_y_int_from_square(from
);
494 to_col
= get_x_int_from_square(to
);
495 to_row
= get_y_int_from_square(to
);
497 printf("setting square %d%d to hold %d\n", to_row
, to_col
, board
->squares
[from_row
][from_col
]);
500 //Queen is being moved to a different square
503 //put the piece back if it's not a legal move
504 if (!is_move_legal(to
))
506 //bstate_set_move_to(from);
507 move_piece_to(from
, item
);
512 bstate_set_move_to(to
);
513 bstate_set_move_from(from
);
514 bstate_set_just_finished(MOVE_WHITE_QUEEN
);
516 board
->squares
[to_row
][to_col
] = board
->squares
[from_row
][from_col
];
517 for (k
=0; k
<4; k
++) //update square to queen mapping
519 if (board
->square_to_wh_queen_map
[k
] == from_row
*10 + from_col
)
521 board
->square_to_wh_queen_map
[k
] = to_row
*10 + to_col
;
524 if (board
->square_to_bl_queen_map
[k
] == from_row
*10 + from_col
)
526 board
->square_to_bl_queen_map
[k
] = to_row
*10 + to_col
;
530 board
->squares
[from_row
][from_col
] = NOTHING
;
531 gen_legal_moves(to
); //prepare moves for arrow
537 square_contains(from
);
541 move_piece_to(to
, item
);
543 printf("what_next = %d\n", bstate_get_what_next());
552 /*==============================================================================
555 * Determines the square the arrow is fired at and marks it as such.
556 * Also checks that this is the appropriate time to fire an arrow and that the
557 * given square is in the list of legal moves.
559 int arrow_fire_cb(GnomeCanvasItem
*item
, GdkEvent
*event
, gpointer data
)
561 double x_coord
, y_coord
;
565 //GtkWidget *auto_button, *undo_button;
567 if (bstate_get_moving_piece())
569 if (bstate_get_open_dialog())
571 if (bstate_get_what_next() == NEW_GAME
)
573 if (bstate_get_replay_mode())
579 case GDK_BUTTON_PRESS
:
580 if (event
->button
.button
!= 1)
582 if (bstate_get_what_next() != FIRE_ARROW
)
585 x_coord
= event
->button
.x
-4;
586 y_coord
= event
->button
.y
-4;
588 sq
= get_square(x_coord
, y_coord
);
589 if (!is_move_legal(sq
))
592 /* Make sure the square is empty first */
593 col
= get_x_int_from_square(sq
);
594 row
= get_y_int_from_square(sq
);
597 printf("what_next = %d\n", bstate_get_what_next());
598 printf("arrow fire: ");
601 if (board
->squares
[row
][col
] != NOTHING
)
605 s
= states
.s
[states
.current_state
];
606 register_move_with_engine(sq
);
608 bstate_set_just_finished(FIRE_ARROW
);
615 dup_state(s
, states
.s
[++(states
.current_state
)]);
616 if (bstate_get_what_next() == WAIT_FOR_AI
)
625 /*==============================================================================
626 * on_PlayerOKButton_clicked
628 * This processes the information from the Player settings window. If a change
629 * is made, sometimes the state of the game must reflect this change. For
630 * instance, if it was a humans turn, and this player was set to AI, the game
631 * state must stop waiting for the human to move and must instead instruct the
632 * AI to start thinking.
635 on_PlayerOKButton_clicked (GtkButton
*button
,
638 GtkWidget
*time
, *width
, *depth
;
639 GtkWidget
*white_ai
, *white_h
, *black_ai
, *black_h
;
641 load_values_from_file();
643 /* grab all the widgets */
644 time
= lookup_widget(PlayerSettingsWindow
, "TimeSpinner");
645 width
= lookup_widget(PlayerSettingsWindow
, "WidthSpinner");
646 depth
= lookup_widget(PlayerSettingsWindow
, "DepthSpinner");
647 white_ai
= lookup_widget(PlayerSettingsWindow
, "WhiteAIRadio");
648 white_h
= lookup_widget(PlayerSettingsWindow
, "WhiteHumanRadio");
649 black_ai
= lookup_widget(PlayerSettingsWindow
, "BlackAIRadio");
650 black_h
= lookup_widget(PlayerSettingsWindow
, "BlackHumanRadio");
653 /* Store new values */
654 options
.engine
.timeout
= gtk_spin_button_get_value_as_int( (GtkSpinButton
*)time
);
655 options
.engine
.maxwidth
= gtk_spin_button_get_value_as_int( (GtkSpinButton
*)width
);
656 options
.engine
.maxdepth
= gtk_spin_button_get_value_as_int( (GtkSpinButton
*)depth
);
658 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(white_h
)))
659 options
.white_player
= HUMAN
;
661 options
.white_player
= AI
;
663 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(black_h
)))
664 options
.black_player
= HUMAN
;
666 options
.black_player
= AI
;
668 store_values_in_file();
669 gtk_widget_destroy(PlayerSettingsWindow
);
671 bstate_update_player_settings();
672 bstate_set_open_dialog(FALSE
);
673 //checks to see if the AI is supposed to move after changes to the player have been made
674 //if the ai is already moving, don't muck things up by calling it again.
675 if (!bstate_get_moving_ai())
677 while (bstate_get_what_next() == WAIT_FOR_AI
)
687 on_PlayerCancelButton_clicked (GtkButton
*button
,
690 gtk_widget_destroy(PlayerSettingsWindow
);
691 bstate_set_open_dialog(FALSE
);
696 on_theme1_activate (GtkMenuItem
*menuitem
,
700 if (bstate_get_open_dialog())
702 bstate_set_open_dialog(TRUE
);
703 file_selector
= gtk_file_selection_new ("Pick your theme file.");
705 gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_selector
), PACKAGE_DATA_DIR
"/gamazons/");
706 gtk_file_selection_complete (GTK_FILE_SELECTION (file_selector
), "*.theme");
707 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
709 G_CALLBACK (load_new_theme
),
711 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
713 G_CALLBACK (on_ThemeCancelButton_clicked
),
716 /* Ensure that the dialog box is destroyed when the user clicks a button. */
718 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
720 G_CALLBACK (gtk_widget_destroy
),
721 (gpointer
) file_selector
);
723 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
725 G_CALLBACK (gtk_widget_destroy
),
726 (gpointer
) file_selector
);
728 /* Display that dialog */
730 gtk_widget_show (file_selector
);
735 void load_new_theme (GtkFileSelection
*selector
, gpointer user_data
)
737 if (bstate_get_moving_piece())
739 gnome_warning_dialog("Warning: Theme can't be updated while a game piece is moving. Please try again.");
740 bstate_set_open_dialog(FALSE
);
744 selected_filename
= (gchar
*) gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector
));
745 load_values_from_file(); //Get current settings
746 if (!load_images_from_theme (selected_filename
)) //load new theme settings
748 gnome_error_dialog("Theme file doesn't exist!\n");
749 bstate_set_open_dialog(FALSE
);
752 store_values_in_file(); //store new settings
755 bstate_set_open_dialog(FALSE
);
759 void on_ThemeCancelButton_clicked(GtkButton
*button
, gpointer user_data
)
761 bstate_set_open_dialog(FALSE
);
766 on_save_as1_activate (GtkMenuItem
*menuitem
,
772 if (bstate_get_open_dialog())
774 bstate_set_open_dialog(TRUE
);
776 file_selector
= gtk_file_selection_new ("Save your move history to a file");
778 gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_selector
), options
.hist_dir
);
779 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
781 G_CALLBACK (save_game_history
),
783 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
785 G_CALLBACK (on_save_as1CancelButton_clicked
),
788 /* Ensure that the dialog box is destroyed when the user clicks a button. */
790 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
792 G_CALLBACK (gtk_widget_destroy
),
793 (gpointer
) file_selector
);
795 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
797 G_CALLBACK (gtk_widget_destroy
),
798 (gpointer
) file_selector
);
800 /* Display that dialog */
802 gtk_widget_show (file_selector
);
807 void save_game_history(GtkFileSelection
*selector
, gpointer user_data
)
811 GtkTextBuffer
*buffer
;
812 GtkTextIter
*iter_start
= (GtkTextIter
*) malloc(sizeof(GtkTextIter
));
813 GtkTextIter
*iter_end
= (GtkTextIter
*) malloc(sizeof(GtkTextIter
));
817 selected_filename
= (gchar
*)gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector
));
818 if (strcmp(options
.hist_dir
, selected_filename
) == 0)
820 bstate_set_open_dialog(FALSE
);
824 load_values_from_file(); //Get current settings
825 strcpy(options
.hist_dir
, selected_filename
);
826 temp_dir
= dirname(options
.hist_dir
);
827 strcpy(options
.hist_dir
, temp_dir
);
828 options
.hist_dir
[strlen(options
.hist_dir
)+1] = '\0';
829 options
.hist_dir
[strlen(options
.hist_dir
)] = '/';
830 store_values_in_file(); //save new dir
832 view
= (GtkTextView
*) lookup_widget(main_window
, "textview1");
833 buffer
= gtk_text_view_get_buffer (view
);
834 gtk_text_buffer_get_start_iter(buffer
, iter_start
);
835 gtk_text_buffer_get_end_iter(buffer
, iter_end
);
837 text
= gtk_text_buffer_get_text(buffer
, iter_start
, iter_end
, FALSE
);
838 history_fd
= fopen(selected_filename
, "w");
840 if (history_fd
== NULL
)
842 gnome_error_dialog("Unable to save move history");
843 bstate_set_open_dialog(FALSE
);
847 fprintf(history_fd
, "%s", text
);
849 bstate_set_open_dialog(FALSE
);
852 void on_save_as1CancelButton_clicked(GtkButton
*button
, gpointer user_data
)
854 bstate_set_open_dialog(FALSE
);
859 on_open_activate (GtkMenuItem
*menuitem
,
865 if (bstate_get_open_dialog())
867 bstate_set_open_dialog(TRUE
);
869 file_selector
= gtk_file_selection_new ("Load saved Gamazons history file you wish to continue");
871 gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_selector
), options
.hist_dir
);
872 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
874 G_CALLBACK (load_saved_game
),
876 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
878 G_CALLBACK (on_OpenCancelButton_clicked
),
881 /* Ensure that the dialog box is destroyed when the user clicks a button. */
883 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
885 G_CALLBACK (gtk_widget_destroy
),
886 (gpointer
) file_selector
);
888 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
890 G_CALLBACK (gtk_widget_destroy
),
891 (gpointer
) file_selector
);
893 /* Display that dialog */
895 gtk_widget_show (file_selector
);
900 void load_saved_game(GtkFileSelection
*selector
, gpointer user_data
)
906 selected_filename
= (gchar
*)gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector
));
907 if (strcmp(options
.hist_dir
, selected_filename
) == 0)
909 bstate_set_open_dialog(FALSE
);
913 load_values_from_file(); //Get current settings
914 strcpy(options
.hist_dir
, selected_filename
);
915 temp_dir
= dirname(options
.hist_dir
);
916 strcpy(options
.hist_dir
, temp_dir
);
917 options
.hist_dir
[strlen(options
.hist_dir
)+1] = '\0';
918 options
.hist_dir
[strlen(options
.hist_dir
)] = '/';
919 store_values_in_file();
921 history_fd
= fopen(selected_filename
, "ro");
922 if (history_fd
== NULL
)
924 gnome_error_dialog("Error opening history file\n");
925 bstate_set_open_dialog(FALSE
);
928 gtk_widget_destroy(file_selector
);
929 bstate_set_open_dialog(FALSE
);
930 bstate_set_replay_mode(FALSE
);
935 init_game_board(main_window
);
937 if (read_in_moves(history_fd
))
938 bstate_set_just_finished(LOAD_GAME
);
940 gnome_error_dialog("Error: Corrupted history file\n");
943 //printf("finished loading history file\n");
946 if (bstate_get_what_next() == NEW_GAME
) //game over
948 while (bstate_get_what_next() == WAIT_FOR_AI
)
949 move_ai(); //if both players are AI, keeps on running
953 void on_OpenCancelButton_clicked(GtkButton
*button
, gpointer user_data
)
955 bstate_set_open_dialog(FALSE
);
959 on_BT_REPLAY_clicked (GtkButton
*button
,
965 if (bstate_get_open_dialog())
967 bstate_set_open_dialog(TRUE
);
969 file_selector
= gtk_file_selection_new ("Load saved Gamazons history file you wish to replay");
971 gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_selector
), options
.hist_dir
);
972 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
974 G_CALLBACK (replay_saved_game
),
976 g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
978 G_CALLBACK (on_OpenCancelButton_clicked
),
981 /* Ensure that the dialog box is destroyed when the user clicks a button. */
983 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->ok_button
),
985 G_CALLBACK (gtk_widget_destroy
),
986 (gpointer
) file_selector
);
988 g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector
)->cancel_button
),
990 G_CALLBACK (gtk_widget_destroy
),
991 (gpointer
) file_selector
);
993 /* Display that dialog */
995 gtk_widget_show (file_selector
);
1000 void replay_saved_game(GtkFileSelection
*selector
, gpointer user_data
)
1005 int game_life
= bstate_get_game_life();
1007 selected_filename
= (gchar
*)gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector
));
1008 if (strcmp(options
.hist_dir
, selected_filename
) == 0)
1010 bstate_set_open_dialog(FALSE
);
1014 load_values_from_file(); //Get current settings
1015 strcpy(options
.hist_dir
, selected_filename
);
1016 temp_dir
= dirname(options
.hist_dir
);
1017 strcpy(options
.hist_dir
, temp_dir
);
1018 options
.hist_dir
[strlen(options
.hist_dir
)+1] = '\0';
1019 options
.hist_dir
[strlen(options
.hist_dir
)] = '/';
1020 store_values_in_file();
1022 history_fd
= fopen(selected_filename
, "ro");
1023 if (history_fd
== NULL
)
1025 gnome_error_dialog("Error opening history file\n");
1026 bstate_set_open_dialog(FALSE
);
1029 gtk_widget_destroy(file_selector
);
1030 bstate_set_open_dialog(FALSE
);
1031 bstate_set_just_finished(START_REPLAY
);
1036 init_game_board(main_window
);
1038 //bstate_set_replay_mode(TRUE);
1039 if (read_in_moves(history_fd
))
1042 else if (bstate_get_replay_mode()) //if still in replay mode, there must have been an error. Otherwise
1043 { //the stop button was pressed and all is well.
1044 gnome_error_dialog("Error: Corrupted history file\n");
1046 else if (game_life
!= bstate_get_game_life())
1051 bstate_set_just_finished(STOP_REPLAY
); //cleans up replay mode if successfully finished
1052 //bstate_set_replay_mode(FALSE);
1055 //printf("finished loading history file\n");
1058 if (bstate_get_what_next() == NEW_GAME
) //game over
1060 while (bstate_get_what_next() == WAIT_FOR_AI
)
1061 move_ai(); //if both players are AI, keeps on running
1067 on_BT_REPLAY_STOP_clicked (GtkButton
*button
,
1070 //bstate_set_replay_mode(FALSE);
1071 bstate_set_just_finished(STOP_REPLAY
);