-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.c
5657 lines (4528 loc) · 139 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Race for the Galaxy AI
*
* Copyright (C) 2009-2011 Keldon Jones
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "rftg.h"
#include "client.h"
#include "comm.h"
/* Apple OS X specific-code */
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#include "ige-mac-menu.h"
#endif
/*
* Keyfile with our preferences.
*/
static GKeyFile *pref_file;
/*
* AI verbosity.
*/
int verbose = 0;
/*
* Number of undo positions saved.
*/
int num_undo;
/*
* Choice logs for each player.
*/
int *orig_log[MAX_PLAYER];
int *orig_history[MAX_PLAYER];
/*
* Player we're playing as.
*/
int player_us;
/*
* We have restarted the main game loop.
*/
int restart_loop;
/*
* Player color names.
*/
static char *player_colors[MAX_PLAYER] =
{
"#8888aa",
"#aa8888",
"#88aa88",
"#aaaa88",
"#88aaaa",
"#aa88aa",
};
/*
* Expansion level names.
*/
char *exp_names[] =
{
"Base game only",
"The Gathering Storm",
"Rebel vs Imperium",
"The Brink of War",
NULL
};
/*
* Labels for number of players.
*/
char *player_labels[] =
{
"Two players",
"Three players",
"Four players",
"Five players",
"Six players",
NULL
};
/*
* Full-size image option names.
*/
char *reduce_names[] =
{
"Original size",
"Half size",
"Hidden",
NULL
};
/*
* Action names/action combination names.
*/
char *ai_debug_action[2][23] =
{
{
"Explore +5",
"Explore +1,+1",
"Develop",
"Settle",
"Consume-Trade",
"Consume-x2",
"Produce",
"Search",
"Prestige Explore +5",
"Prestige Explore +1,+1",
"Prestige Develop",
"Prestige Settle",
"Prestige Consume-Trade",
"Prestige Consume-x2",
"Prestige Produce",
},
{
"E5/E1",
"E5/D",
"E5/S",
"E5/CT",
"E5/C2",
"E5/P",
"E1/D",
"E1/S",
"E1/CT",
"E1/C2",
"E1/P",
"D/D",
"D/S",
"D/CT",
"D/C2",
"D/P",
"S/S",
"S/CT",
"S/C2",
"S/P",
"CT/C2",
"CT/P",
"C2/P",
}
};
/*
* Goal image size.
*/
#define GOALF_WIDTH 260
#define GOALF_HEIGHT 297
#define GOALM_WIDTH 296
#define GOALM_HEIGHT 447
/*
* List of cards in hand.
*/
displayed hand[MAX_DECK];
int hand_size;
/*
* Other displayed status information.
*/
//static int display_deck, display_discard, display_pool;
int display_deck, display_discard, display_pool;
/*
* Restriction on action button.
*/
int action_restrict;
int action_min, action_max, action_payment_which, action_payment_mil;
int action_cidx, action_oidx;
/*
* Number of icon images.
*/
#define MAX_ICON 19
/*
* Card images.
*/
static GdkPixbuf *image_cache[MAX_DESIGN];
/*
* Goal card images.
*/
static GdkPixbuf *goal_cache[MAX_GOAL];
/*
* Icon images.
*/
static GdkPixbuf *icon_cache[MAX_ICON];
/*
* Action card images.
*/
static GdkPixbuf *action_cache[MAX_ACT_CARD];
/*
* Card back image.
*/
static GdkPixbuf *card_back;
/*
* Widgets used in multiple functions.
*/
static GtkWidget *full_image;
static GtkWidget *hand_area;
static GtkWidget *player_area[MAX_PLAYER], *orig_area[MAX_PLAYER];
static GtkWidget *player_status[MAX_PLAYER], *orig_status[MAX_PLAYER];
static GtkWidget *player_box[MAX_PLAYER], *player_sep[MAX_PLAYER];
static GtkWidget *goal_area;
static GtkWidget *game_status;
static GtkWidget *main_hbox, *lobby_vbox;
static GtkWidget *phase_labels[MAX_ACTION];
static GtkWidget *action_box;
static GtkWidget *undo_item, *save_item;
static GtkWidget *entry_hbox;
/*
* Lists for online functions.
*/
GtkListStore *user_list;
GtkTreeStore *game_list;
/*
* Widgets used by network functions.
*/
GtkWidget *entry_label, *chat_view;
GtkWidget *games_view, *password_entry;
GtkWidget *create_button, *join_button, *leave_button, *kick_button;
GtkWidget *addai_button, *start_button;
GtkWidget *action_prompt, *action_button;
/*
* Keyboard accelerator group for main window.
*/
static GtkAccelGroup *window_accel;
/*
* Text buffer for message area.
*/
GtkWidget *message_view;
/*
* Mark at end of message area text buffer.
*/
GtkTextMark *message_end;
/*
* y-coordinate of line of "last seen" text in buffer.
*/
int message_last_y;
/*
* Add text to the message buffer.
*/
void message_add(game *g, char *msg)
{
GtkTextIter end_iter;
GtkTextBuffer *message_buffer;
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Get end mark */
gtk_text_buffer_get_iter_at_mark(message_buffer, &end_iter,
message_end);
/* Add message */
gtk_text_buffer_insert(message_buffer, &end_iter, msg, -1);
/* Scroll to end mark */
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(message_view),
message_end);
}
/*
* Clear message log.
*/
void clear_log(void)
{
GtkTextBuffer *message_buffer;
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Clear text buffer */
gtk_text_buffer_set_text(message_buffer, "", 0);
/* Reset last seen line */
message_last_y = 0;
}
/*
* Draw a line across the message text view.
*/
static gboolean message_view_expose(GtkWidget *text_view, GdkEventExpose *event,
gpointer data)
{
int x, y;
int w;
/* Convert buffer coordinates to window coordinates */
gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(text_view),
GTK_TEXT_WINDOW_WIDGET,
0, message_last_y, &x, &y);
/* Don't draw line at very top of window */
if (!y) return FALSE;
/* Get widget width */
w = text_view->allocation.width;
/* Draw line across window */
gdk_draw_line(event->window, text_view->style->black_gc, 0, y, w, y);
/* Continue handling event */
return FALSE;
}
/*
* Add a separator at the end of all previously seen text.
*/
static void reset_text_separator(void)
{
GtkTextIter end_iter;
GtkTextBuffer *message_buffer;
GdkRectangle rect;
int x, y;
/* Convert current line coordinates to window coordinates */
gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(message_view),
GTK_TEXT_WINDOW_WIDGET,
0, message_last_y, &x, &y);
/* Invalidate old line */
gtk_widget_queue_draw_area(message_view, 0, y,
message_view->allocation.width, 1);
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Get end mark */
gtk_text_buffer_get_iter_at_mark(message_buffer, &end_iter,
message_end);
/* Get location (in buffer coordinates) of end iterator */
gtk_text_view_get_iter_location(GTK_TEXT_VIEW(message_view), &end_iter,
&rect);
/* Remember y-coordinate */
message_last_y = rect.y;
}
/*
* Load pixbufs with card images from image bundle.
*
* The image bundle format is nothing special -- it exists mainly to make
* it difficult for people to get at the images directly.
*
* This was requested by Tom Lehmann.
*/
static void load_image_bundle(void)
{
GFile *bundle;
GInputStream *fs, *ms;
GdkPixbuf **pix_ptr;
char buf[1024], *data_buf;
int count, x;
/* Create bundle file handle */
bundle = g_file_new_for_path(RFTGDIR "/images.data");
/* Open file for reading */
fs = G_INPUT_STREAM(g_file_read(bundle, NULL, NULL));
/* Check for error */
if (!fs)
{
/* Try reading from current directory instead */
bundle = g_file_new_for_path("images.data");
/* Open file for reading */
fs = G_INPUT_STREAM(g_file_read(bundle, NULL, NULL));
}
/* Check for error */
if (!fs)
{
/* Error */
printf("Can't open raw images or image bundle!\n");
return;
}
/* Read header */
count = g_input_stream_read(fs, buf, 4, NULL, NULL);
/* Check header */
if (strncmp(buf, "RFTG", 4))
{
/* Error */
printf("Image bundle missing header!\n");
return;
}
/* Loop until end of file */
while (1)
{
/* Get next type of image */
count = g_input_stream_read(fs, buf, 1, NULL, NULL);
/* Check for end of file */
if (buf[0] == 0) break;
/* Check for card image */
if (buf[0] == 1)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 4, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &image_cache[x];
}
/* Check for card back image */
else if (buf[0] == 2)
{
/* Get pointer to pixbuf */
pix_ptr = &card_back;
}
/* Check for goal image */
else if (buf[0] == 3)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &goal_cache[x];
}
/* Check for icon image */
else if (buf[0] == 4)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &icon_cache[x];
}
/* Check for action card image */
else if (buf[0] == 5)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &action_cache[x];
}
/* Check for something else */
else
{
/* Error */
printf("Bad image type!\n");
break;
}
/* Read file size */
count = g_input_stream_read(fs, buf, 8, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Create buffer for image data */
data_buf = (char *)malloc(x);
/* Read into buffer */
count = g_input_stream_read(fs, data_buf, x, NULL, NULL);
/* Check for not enough read */
if (count < x)
{
/* Error */
printf("Did not read enough image data!\n");
break;
}
/* Create memory stream from image data */
ms = g_memory_input_stream_new_from_data(data_buf, x, NULL);
/* Read image from file stream */
*pix_ptr = gdk_pixbuf_new_from_stream(ms, NULL, NULL);
/* Close memory stream */
g_input_stream_close(ms, NULL, NULL);
/* Free memory */
free(data_buf);
/* Check for error */
if (!(*pix_ptr))
{
/* Print error */
printf("Error reading image from bundle!\n");
break;
}
}
/* Close stream */
g_input_stream_close(fs, NULL, NULL);
}
/*
* Load pixbufs with card images.
*/
static void load_images(void)
{
int i;
char fn[1024];
/* Load card back image */
card_back = gdk_pixbuf_new_from_file("image/cardback.jpg",NULL);
/* Check for failure */
if (!card_back)
{
/* Try to load image data from bundle instead */
load_image_bundle();
return;
}
/* Loop over designs */
for (i = 0; i < MAX_DESIGN; i++)
{
/* Construct image filename */
sprintf(fn, "image/card%03d.jpg", i);
/* Load image */
image_cache[i] = gdk_pixbuf_new_from_file(fn, NULL);
/* Check for error */
if (!image_cache[i])
{
/* Print error */
printf("Cannot open card image %s!\n", fn);
}
}
/* Loop over goals */
for (i = 0; i < MAX_GOAL; i++)
{
/* Construct image filename */
sprintf(fn, "image/goal%02d.jpg", i);
/* Load image */
goal_cache[i] = gdk_pixbuf_new_from_file(fn, NULL);
/* Check for error */
if (!goal_cache[i])
{
/* Print error */
printf("Cannot open goal image %s!\n", fn);
}
}
/* Loop over icons */
for (i = 0; i < MAX_ICON; i++)
{
/* Skip second develop/settle action */
if (i == ACT_DEVELOP2 || i == ACT_SETTLE2) continue;
/* Construct image filename */
sprintf(fn, "image/icon%02d.png", i);
/* Load image */
icon_cache[i] = gdk_pixbuf_new_from_file(fn, NULL);
/* Check for error */
if (!icon_cache[i])
{
/* Print error */
printf("Cannot open icon image %s!\n", fn);
}
}
/* Loop over actions */
for (i = 0; i < MAX_ACT_CARD; i++)
{
/* Skip second develop/settle action */
if (i == ACT_DEVELOP2 || i == ACT_SETTLE2) continue;
/* Construct image filename */
sprintf(fn, "image/action%02d.jpg", i);
/* Load image */
action_cache[i] = gdk_pixbuf_new_from_file(fn, NULL);
/* Check for error */
if (!action_cache[i])
{
/* Print error */
printf("Cannot open action card image %s!\n", fn);
}
}
}
/*
* Refresh the full-size card image.
*
* Called when the pointer moves over a small card image.
*/
static gboolean redraw_full(GtkWidget *widget, GdkEventCrossing *event,
gpointer data)
{
design *d_ptr = (design *)data;
GdkPixbuf *buf;
/* Check for no design */
if (!d_ptr)
{
/* Set image to card back */
buf = card_back;
}
else
{
/* Set image to card face */
buf = image_cache[d_ptr->index];
}
/* Check for halfsize image */
if (opt.full_reduced == 1)
{
/* Scale image */
buf = gdk_pixbuf_scale_simple(buf, CARD_WIDTH / 2,
CARD_HEIGHT / 2, GDK_INTERP_BILINEAR);
}
/* Set image */
gtk_image_set_from_pixbuf(GTK_IMAGE(full_image), buf);
/* Check for halfsize image */
if (opt.full_reduced == 1)
{
/* Remove our scaled buffer */
g_object_unref(G_OBJECT(buf));
}
/* Event handled */
return TRUE;
}
/*
* Refresh the full-size card image with an action card.
*
* Called when the pointer moves over a action button.
*/
static gboolean redraw_action(GtkWidget *widget, GdkEventCrossing *event,
gpointer data)
{
int a = GPOINTER_TO_INT(data);
GdkPixbuf *buf;
/* Set image to card face */
buf = action_cache[a];
/* Check for halfsize image */
if (opt.full_reduced == 1)
{
/* Scale image */
buf = gdk_pixbuf_scale_simple(buf, CARD_WIDTH / 2,
CARD_HEIGHT / 2, GDK_INTERP_BILINEAR);
}
/* Set image */
gtk_image_set_from_pixbuf(GTK_IMAGE(full_image), buf);
/* Check for halfsize image */
if (opt.full_reduced == 1)
{
/* Remove our scaled buffer */
g_object_unref(G_OBJECT(buf));
}
/* Continue to handle event */
return FALSE;
}
/*
* Create an event box containing the given card's image.
*/
static GtkWidget *new_image_box(design *d_ptr, int w, int h, int color,
int highlight, int back)
{
GdkPixbuf *buf, *border_buf, *blank_buf;
GtkWidget *image, *box;
int bw;
/* Check for no image */
if (back)
{
/* Scale card back image */
buf = gdk_pixbuf_scale_simple(card_back, w, h,
GDK_INTERP_BILINEAR);
}
else
{
/* Scale image */
buf = gdk_pixbuf_scale_simple(image_cache[d_ptr->index], w, h,
GDK_INTERP_BILINEAR);
}
/* Check for grayscale */
if (!color)
{
/* Desaturate */
gdk_pixbuf_saturate_and_pixelate(buf, buf, 0, TRUE);
}
/* Check for border placed around image */
if (highlight == HIGH_YELLOW)
{
/* Compute border width */
bw = w / 20;
/* Enforce minimum border width */
if (bw < 5) bw = 5;
/* Create a border pixbuf */
border_buf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
/* Fill pixbuf with highlight color */
gdk_pixbuf_fill(border_buf, 0xffff00ff);
/* Create a blank pixbuf */
blank_buf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
/* Fill pixbuf with transparent black */
gdk_pixbuf_fill(blank_buf, 0);
/* Copy blank space onto middle of border buffer */
gdk_pixbuf_copy_area(blank_buf, bw, bw, w - 2 * bw, h - 2 * bw,
border_buf, bw, bw);
/* Composite border onto card image buffer */
gdk_pixbuf_composite(border_buf, buf, 0, 0, w, h, 0, 0, 1, 1,
GDK_INTERP_BILINEAR, 255);
/* Release our copies of pixbufs */
g_object_unref(G_OBJECT(blank_buf));
g_object_unref(G_OBJECT(border_buf));
}
/* Check for red discard highlight */
else if (highlight == HIGH_RED)
{
/* Scale discard icon */
border_buf = gdk_pixbuf_scale_simple(icon_cache[ICON_DISCARD],
w, h, GDK_INTERP_BILINEAR);
/* Composite discard symbol onto card image buffer */
gdk_pixbuf_composite(border_buf, buf, 0, 0, w, h,
0, 0, 1, 1, GDK_INTERP_BILINEAR, 255);
/* Release our copy of scaled discard icon */
g_object_unref(G_OBJECT(border_buf));
}
/* Make image widget */
image = gtk_image_new_from_pixbuf(buf);
/* Destroy our copy of the pixbuf */
g_object_unref(G_OBJECT(buf));
/* Make event box for image */
box = gtk_event_box_new();
/* Add image to event box */
gtk_container_add(GTK_CONTAINER(box), image);
/* Connect "pointer enter" signal */
g_signal_connect(G_OBJECT(box), "enter-notify-event",
G_CALLBACK(redraw_full), d_ptr);
/* Return event box widget */
return box;
}
/*
* Card selected/deselected.
*/
static gboolean card_selected(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
displayed *i_ptr = (displayed *)data;
displayed *j_ptr;
int i, j;
/* Change selection status */
i_ptr->selected = !i_ptr->selected;
/* Check for greedy card */
if (i_ptr->greedy && i_ptr->selected)
{
/* Check for hand */
if (i_ptr->hand)
{
/* Loop over other cards in hand */
for (i = 0; i < hand_size; i++)
{
/* Get displayed card pointer */
j_ptr = &hand[i];
/* Skip current card */
if (i_ptr == j_ptr) continue;
/* Clear selected */
j_ptr->selected = 0;
}
}
else
{
/* Loop over all table areas */
for (i = 0; i < MAX_PLAYER; i++)
{
/* Loop over cards in table area */
for (j = 0; j < table_size[i]; j++)
{
/* Get displayed card pointer */
j_ptr = &table[i][j];
/* Skip current card */
if (i_ptr == j_ptr) continue;
/* Clear selected */
j_ptr->selected = 0;
}
}
}
}
/* Check for "number" restriction on action button */
if (action_restrict == RESTRICT_NUM)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_number());
}
/* Check for "both hand and active" restriction on action button */
else if (action_restrict == RESTRICT_BOTH)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_both());
}
/* Check for "payment" restriction on action button */
else if (action_restrict == RESTRICT_PAY)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_payment());
}
/* Check for "goods" restriction on action button */
else if (action_restrict == RESTRICT_GOOD)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_goods());
}
/* Check for "takeover" restriction on action button */
else if (action_restrict == RESTRICT_TAKEOVER)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button,action_check_takeover());
}
/* Check for "defend" restriction on action button */
else if (action_restrict == RESTRICT_DEFEND)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_defend());
}
/* Check for "upgrade" restriction on action button */
else if (action_restrict == RESTRICT_UPGRADE)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_upgrade());
}
/* Check for "consume" restriction on action button */
else if (action_restrict == RESTRICT_CONSUME)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_consume());
}
/* Check for "start world" restriction on action button */
else if (action_restrict == RESTRICT_START)
{
/* Set sensitivity */
gtk_widget_set_sensitive(action_button, action_check_start());
}
/* Check for card in hand */
if (i_ptr->hand)
{
/* Redraw hand */
redraw_hand();
}
else
{
/* Redraw table */
redraw_table();
}
/* Event handled */
return TRUE;
}
/*
* Card selected by keypress.
*/
static void card_keyed(GtkWidget *widget, gpointer data)
{
/* Call regular handler */
card_selected(widget, NULL, data);
}
/*
* Callback to destroy child widgets so that new ones can take their place.
*/
static void destroy_widget(GtkWidget *widget, gpointer data)
{
/* Destroy widget */
gtk_widget_destroy(widget);
}
/*
* Redraw hand area.
*/
void redraw_hand(void)
{
GtkWidget *box;
displayed *i_ptr;
int count = 0, gap = 1, n, num_gap = 0;
int key_count = 1, key_code;
int width, height, highlight;
int card_w, card_h;
int i, j;
/* Sort hand */
qsort(hand, hand_size, sizeof(displayed), cmp_hand);
/* First destroy all pre-existing card widgets */
gtk_container_foreach(GTK_CONTAINER(hand_area), destroy_widget, NULL);
/* Get number of cards in hand */
n = hand_size;
/* Loop over cards in hand */
for (i = 0; i < n; i++)
{
/* Get card pointer */
i_ptr = &hand[i];
/* Check for "gapped" card */
if (i_ptr->gapped)
{