-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.c
9089 lines (7262 loc) · 207 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
/*
* Our default options.
*/
options opt =
{
.num_players = 3,
};
/*
* Keyfile with our preferences.
*/
static GKeyFile *pref_file;
/*
* AI verbosity.
*/
int verbose = 0;
/*
* Current (real) game state.
*/
game real_game;
/*
* Number of undo positions saved.
*/
static int num_undo;
/*
* Choice logs for each player.
*/
static int *orig_log[MAX_PLAYER];
static int *orig_history[MAX_PLAYER];
/*
* Player we're playing as.
*/
int player_us;
/*
* We have restarted the main game loop.
*/
int restart_loop;
/*
* Player names.
*/
static char *player_names[MAX_PLAYER] =
{
"Blue",
"Red",
"Green",
"Yellow",
"Cyan",
"Purple",
};
/*
* Player color names.
*/
static char *player_colors[MAX_PLAYER] =
{
"#8888aa",
"#aa8888",
"#88aa88",
"#aaaa88",
"#88aaaa",
"#aa88aa",
};
/*
* Card image size.
*/
#define CARD_WIDTH 372
#define CARD_HEIGHT 520
/*
* Goal image size.
*/
#define GOALF_WIDTH 260
#define GOALF_HEIGHT 297
#define GOALM_WIDTH 296
#define GOALM_HEIGHT 447
/*
* Colors to highlight with.
*/
#define HIGH_NONE 0
#define HIGH_YELLOW 1
#define HIGH_RED 2
/*
* Information about a displayed card.
*/
typedef struct displayed
{
/* Card's index in the deck */
int index;
/* Card's design pointer */
design *d_ptr;
/* Card is in hand (instead of on table) */
int hand;
/* Card is eligible for being chosen */
int eligible;
/* Card should be seperated from others */
int gapped;
/* Card is selected */
int selected;
/* Card should deselect all others when selected */
int greedy;
/* Card should be highlighted in this color when selected */
int highlight;
/* Card should be highlighted in this color when not selected */
int highlight_else;
/* Card should be "pushed up" when selected */
int push;
/* Card is not eligible for selection, but should be colored anyway */
int color;
/* Card is covered (by a good) */
int covered;
/* Order card was played in (if on table) */
int order;
/* Tooltip to display (if any) */
char *tooltip;
} displayed;
/*
* List of cards in hand.
*/
static displayed hand[MAX_DECK];
static int hand_size;
/*
* List of cards on table (per player).
*/
static displayed table[MAX_PLAYER][MAX_DECK];
static int table_size[MAX_PLAYER];
/*
* Cached status information to be displayed per player.
*/
typedef struct status_display
{
/* Name to display */
char name[80];
/* Actions */
int action[2];
/* Victory point chips */
int vp;
/* Total victory points */
int end_vp;
/* Cards in hand */
int cards_hand;
/* Prestige */
int prestige;
/* Military strength */
int military;
/* Text of military strength tooltip */
char military_tip[1024];
/* Array of goals to display */
int goal_display[MAX_GOAL];
/* Array of goals to be grayed out */
int goal_gray[MAX_GOAL];
/* Array of goal tooltips */
char goal_tip[MAX_GOAL][1024];
} status_display;
/*
* Array of displayed status information per player.
*/
static status_display status_player[MAX_PLAYER];
/*
* Other displayed status information.
*/
static int display_deck, display_discard, display_pool;
/*
* Restriction types on action button sensitivity.
*/
#define RESTRICT_NUM 1
#define RESTRICT_BOTH 2
#define RESTRICT_PAY 3
#define RESTRICT_GOOD 4
#define RESTRICT_TAKEOVER 5
#define RESTRICT_DEFEND 6
#define RESTRICT_UPGRADE 7
#define RESTRICT_CONSUME 8
#define RESTRICT_START 9
/*
* Restriction on action button.
*/
static int action_restrict;
static int action_min, action_max, action_payment_which, action_payment_mil;
static int action_cidx, action_oidx;
/*
* Number of icon images.
*/
#define MAX_ICON 19
/*
* Special icon numbers.
*/
#define ICON_NO_ACT 10
#define ICON_HANDSIZE 11
#define ICON_VP 12
#define ICON_MILITARY 13
#define ICON_PRESTIGE 14
#define ICON_WAITING 15
#define ICON_READY 16
#define ICON_OPTION 17
#define ICON_DISCARD 18
/*
* Number of action card images.
*/
#define MAX_ACT_CARD 11
/*
* 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.
*/
static 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);
}
/*
* Use simple random number generator.
*/
int game_rand(game *g)
{
/* Call simple random number generator */
return simple_rand(&g->random_seed);
}
/*
* Clear message log.
*/
static 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);
}
}
}
/*
* Function to determine whether enough cards are selected.
*/
static gboolean action_check_number(void)
{
displayed *i_ptr;
int i, n = 0;
/* Loop over cards in hand */
for (i = 0; i < hand_size; i++)
{
/* Get displayed card pointer */
i_ptr = &hand[i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Count selected cards */
n++;
}
/* Loop over cards on table */
for (i = 0; i < table_size[player_us]; i++)
{
/* Get displayed card pointer */
i_ptr = &table[player_us][i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Count selected cards */
n++;
}
/* Check for not enough */
if (n < action_min) return FALSE;
/* Check for too many */
if (n > action_max) return FALSE;
/* Just right */
return TRUE;
}
/*
* Function to determine whether enough cards in hand and on table
* are selected.
*/
static gboolean action_check_both(void)
{
displayed *i_ptr;
int i, n = 0, ns = 0;
/* Loop over cards in hand */
for (i = 0; i < hand_size; i++)
{
/* Get displayed card pointer */
i_ptr = &hand[i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Count selected cards */
n++;
}
/* Loop over cards on table */
for (i = 0; i < table_size[player_us]; i++)
{
/* Get displayed card pointer */
i_ptr = &table[player_us][i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Count selected cards */
ns++;
}
/* Check for not enough */
if (n < action_min) return FALSE;
if (ns < action_min) return FALSE;
/* Check for too many */
if (n > action_max) return FALSE;
if (ns > action_max) return FALSE;
/* Check for hand selected but not table */
if (n && !ns) return FALSE;
/* Just right */
return TRUE;
}
/*
* Function to determine whether selected cards meet payment.
*/
static gboolean action_check_payment(void)
{
game sim;
displayed *i_ptr;
int i, n = 0, ns = 0;
int list[MAX_DECK], special[MAX_DECK];
/* Loop over cards in hand */
for (i = 0; i < hand_size; i++)
{
/* Get hand pointer */
i_ptr = &hand[i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Add to regular list */
list[n++] = i_ptr->index;
}
/* Loop over cards on table */
for (i = 0; i < table_size[player_us]; i++)
{
/* Get table card pointer */
i_ptr = &table[player_us][i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Add to special list */
special[ns++] = i_ptr->index;
}
/* Copy game */
sim = real_game;
/* Set simulation flag */
sim.simulation = 1;
/* Loop over players */
for (i = 0; i < sim.num_players; i++)
{
/* Have AI make any pending decisions for this player */
sim.p[i].control = &ai_func;
}
/* Try to make payment */
return payment_callback(&sim, player_us, action_payment_which,
list, n, special, ns, action_payment_mil);
}
/*
* Function to determine whether selected goods can be consumed.
*/
static gboolean action_check_goods(void)
{
game sim;
displayed *i_ptr;
int i, n = 0;
int list[MAX_DECK];
/* Loop over cards on table */
for (i = 0; i < table_size[player_us]; i++)
{
/* Get displayed card pointer */
i_ptr = &table[player_us][i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Add to regular list */
list[n++] = i_ptr->index;
}
/* Check for too few */
if (n < action_min) return 0;
/* Check for too many */
if (n > action_max) return 0;
/* Copy game */
sim = real_game;
/* Set simulation flag */
sim.simulation = 1;
/* Try to make payment */
return good_chosen(&sim, player_us, action_cidx, action_oidx, list, n);
}
/*
* Function to determine whether selected card can be taken over.
*/
static gboolean action_check_takeover(void)
{
game sim;
displayed *i_ptr;
int i, j;
int target = -1, special = -1;
/* Loop over opponents */
for (i = 0; i < real_game.num_players; i++)
{
/* Skip ourself */
if (i == player_us) continue;
/* Loop over player's table area */
for (j = 0; j < table_size[i]; j++)
{
/* Get displayed card pointer */
i_ptr = &table[i][j];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Check for too many targets */
if (target != -1) return 0;
/* Remember target world */
target = i_ptr->index;
}
}
/* Loop over cards on table */
for (i = 0; i < table_size[player_us]; i++)
{
/* Get table card pointer */
i_ptr = &table[player_us][i];
/* Skip unselected */
if (!i_ptr->selected) continue;
/* Check for too many special cards */
if (special != -1) return 0;
/* Remember special card used */
special = i_ptr->index;
}
/* Check for no target or special card */
if (target == -1 && special == -1) return 1;
/* Check for only no target */
if (target == -1) return 0;
/* Check for only no special card */
if (special == -1) return 0;
/* Copy game */
sim = real_game;
/* Set simulation flag */
sim.simulation = 1;
/* Check takeover legality */
return takeover_callback(&sim, special, target);
}
/*
* Function to determine whether selected cards are a legal defense.
*/
static gboolean action_check_defend(void)
{
game sim;
displayed *i_ptr;
int i, n = 0, ns = 0;
int list[MAX_DECK], special[MAX_DECK];
/* Loop over cards in hand */
for (i = 0; i < hand_size; i++)
{