-
Notifications
You must be signed in to change notification settings - Fork 0
/
GAME.C
2110 lines (1885 loc) · 50.4 KB
/
GAME.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
#include <dos.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <alloc.h>
#include <time.h>
#include <mem.h>
extern unsigned _stklen = 45000; // The stack is usually only 4K
#define USAGESIZE 89200LU
FILE *resfile;
static far int mousex, mousey, mousebut;
#include "resindex.h"
#include "gametags.h"
#include "mouse.h"
#include "sound.h"
#include "game.h"
#include "game386.h"
#include "font.h"
#include "pal.h"
#include "logic.h"
#include "keys.h"
#include "vsync.h"
static int far level1[16] = {0,4,0,1,2,7,3,8,4,1,5,6,7,2,8,3};
static int far level2[16] = {1,0,2,3,1,4,1,0,0,2,3,0,2,1,0,1};
static int far level3[16] = {0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0};
struct{
unsigned int X; // Sprite X positions
unsigned int Y; // Sprite Y positions
unsigned int W; // Sprite WIDTH
unsigned int H; // Sprite HEIGHT
unsigned char far *image; // Sprite data
}sprite[MAXSPRITES];
unsigned char far *bg_buf;
unsigned char far *bg_buf2;
unsigned char *sp_image[MAXSPRITES]; // Pointers to bitmaps for each sprite
unsigned long int raflength[MAXRAFS];
unsigned char far *rafdata[MAXRAFS];
unsigned char far *palette[MAXPALETTES];
unsigned int far boardx[BSIZE];
unsigned int far boardy[BSIZE];
int registered;
int maxboardscanuse=MAXBOARDS;
//#define DEBUG 1
//#define SKIP 1
#ifdef DEBUG
void displayfreemem( void );
#endif
void check_serial_number( void );
int getkey( void );
int build_board( board_t , int board_level);
int calc_x( int xx );
int calc_y( int yy );
void capture( board_t board, int player, int to_x, int to_y);
int check_kbd( void );
void checkforhit(void);
int checkpieces( board_t board, int player );
void decode( unsigned char * stringdst, unsigned char * stringsrc );
void display_cells( void );
void display_digits( int number, int x, int y );
int do_game( board_t board, int player );
void door_open( int x, int y );
void door_close( int x, int y );
int draw_board( board_t );
void exitwerr( void );
void explode( int x, int y );
void flush_kbd( void );
void flushit( int x, int y, int player );
void free_memory( void );
SAMPLE *getraf( unsigned long int *length);
SAMPLE *getboard( int board_level );
int hint( board_t board, int player );
void intro( void );
void load_pic( unsigned char far * buffer, unsigned long int picpos );
int mainmenu( void );
void put_avail_moves( board_t board, int player, int from_x, int from_y );
void put_piece( int player, int to_x, int to_y );
void read_res( void );
void shootout( int x, int y, int player );
void spot_screen( void );
void startup( void );
int switch_players( int player );
void toggle_show_moves( void );
void toggle_sound( void );
void update_menu_ops( void );
void v_delay( int times );
unsigned char far * _scrn = (unsigned char far *)0xA0000000L;
unsigned char far *boardin;
unsigned long int lboardin;
int hintsused = 0;
int gameinprogress = FALSE;
int allsound=ON;
int show_avail=ON;
int board_level = 1;
int skip=TRUE;
int bombs_left = 0;
int killers=ON;
int cell=1;
char cell_name[MAXBOARDS+2][13];
int playerXtype, playerOtype, curplayertype;
int playerXdepth, playerOdepth, curplayerdepth;
int master_snd_sys;
///////////////////////////////////////////////////////////
// MAIN Function
///////////////////////////////////////////////////////////
void main( void )
{
int menustate, player, rndcnt, c,i;
char cheat[10];
board_t board;
registered = FALSE;
if((resfile = fopen("standard.res","rb"))==NULL)
{
printf("\nERROR: Couldn't open resource file!\n");
exit( 1 );
}
check_serial_number();
startup();
read_res();
#ifdef SKIP
i=0;
while(kbhit())
{
c=getch();
cheat[i++]=c;
}
if(strstr( cheat, "skip" )!=NULL)
skip=TRUE;
#endif
player = PLAYERX;
curplayertype = playerXtype;
playerXtype = HUMAN;
playerOtype = COMPUTER;
playerOdepth = 1;
SetVgaMode(VGALOWRES); // to 320x200x256
SetPal( palette[TITLEPAL] );
#ifdef SKIP
if(!skip)
#endif
intro();
set_mouse_pos( 0,0 );
set_mouse_range( 0, 0, 620, 185 );
randomize();
while( menustate!=EXITTODOS )
{
menustate = mainmenu();
if( menustate==STARTNEWGAME )
{
hintsused=0;
board_level = cell;
build_board( board, cell );
player = PLAYERX;
curplayertype = playerXtype;
}
else if(menustate==INFO )
{
FadeOut( palette[MENUPAL], 5 );
hide_mouse();
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC5_FOFFSET );
show_mouse();
FadeIn( palette[INFOPAL], 5 );
v_delay(20);
checkforhit();
FadeOut( palette[INFOPAL], 3 );
hide_mouse();
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC6_FOFFSET );
show_mouse();
FadeIn( palette[INFOPAL], 3 );
v_delay(20);
checkforhit();
FadeOut( palette[INFOPAL], 3 );
hide_mouse();
continue;
}
else if( menustate==CREDITS )
{
FadeOut( palette[MENUPAL], 5 );
hide_mouse();
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC7_FOFFSET );
show_mouse();
FadeIn( palette[CREDITSPAL], 5 );
v_delay(20);
checkforhit();
FadeOut( palette[CREDITSPAL], 5 );
hide_mouse();
continue;
}
else if( menustate==EXITTODOS )
{
while(sounds_in_queue!=0);
if(master_snd_sys) playsound(rafdata[ALARMSND], raflength[ALARMSND]);
FadeToRed( palette[MENUPAL], 1 );
FadeToRed( palette[MENUPAL], 1 );
while(sounds_in_queue!=0);
break;
}
else if( menustate==STOPGAME )
{
FadeOut( palette[MENUPAL], 5 );
gameinprogress=FALSE;
hide_mouse();
continue;
}
FadeOut( palette[MENUPAL], 5 );
hide_mouse();
Clear(0);
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC8_FOFFSET );
draw_board( board );
PutBlock( 237, 16, sprite[PLAYERX_GFX].W, sprite[PLAYERX_GFX].H, sp_image[PLAYERX_GFX] );
PutBlock( 237, 38, sprite[PLAYERO_GFX].W, sprite[PLAYERO_GFX].H, sp_image[PLAYERO_GFX] );
if(allsound)
PutBlock(233,145,sprite[RADIOON].W,sprite[RADIOON].H,sp_image[RADIOON]);
else
PutBlock(233,145,sprite[RADIOOFF].W,sprite[RADIOOFF].H,sp_image[RADIOOFF]);
if(show_avail)
PutBlock(233,155,sprite[RADIOON].W,sprite[RADIOON].H,sp_image[RADIOON]);
else
PutBlock(233,155,sprite[RADIOOFF].W,sprite[RADIOOFF].H,sp_image[RADIOOFF]);
Text( 86,6,cell_name[board_level],16,0);
Text( 85,5,cell_name[board_level],28,0);
#ifdef DEBUG
displayfreemem();
#endif
checkpieces( board, player );
show_mouse();
FadeIn( palette[GAMEPAL], 5 );
rndcnt = (rand() % 10);
if(master_snd_sys&&rndcnt>=7)
{
while(sounds_in_queue!=0);
v_delay( 15 );
playsound(rafdata[STARTSND], raflength[STARTSND]);
}
flush_kbd();
player = do_game( board, player );
FadeOut( palette[GAMEPAL], 5 );
hide_mouse();
}
v_delay( 10 );
FadeOut( palette[MENUPAL], 3 );
hide_mouse();
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC9_FOFFSET );
FadeIn( palette[GAMEPAL], 5 );
v_delay( 60 );
#ifdef DEBUG
free_memory();
displayfreemem();
getch();
#endif
FadeOut( palette[GAMEPAL], 5 );
if(master_snd_sys) Dropdead_Varmint(); // Release Varmint's interrupt
SetVgaMode( TEXTRES ); // Reset old graphics mode
free_memory();
printf("Thank-you for playing Assimilation!\n");
if (registered == FALSE)
printf("\tPlease Register!");
flush_kbd();
}
//**********************[ END OF MAIN ]************************
void computers_turn( board_t board, int player )
{
int i, from_x, from_y, to_x, to_y;
gameinprogress = TRUE;
depth = curplayerdepth;
while(sounds_in_queue!=0);
hide_mouse();
i = checkpieces( board, player ); //check to see if there is a move available.
if(i!=NULL) //if not give control back to other player.
return;
v_delay( 10 );
play(board, 0, player); //calculate move
from_x = best_from_x[0];
from_y = best_from_y[0];
to_x = best_to_x[0];
to_y = best_to_y[0];
put_avail_moves( board, player, from_x, from_y );
v_delay( 15 );
if ((ABS(from_x-to_x)==1&&ABS(from_y-to_y)==1)||(ABS(from_x-to_x)==0&&ABS(from_y-to_y)==1)||(ABS(from_x-to_x)==1&&ABS(from_y-to_y)==0))
{
put_piece( player, to_x, to_y );
if(allsound) playsound(rafdata[MOVESND], raflength[MOVESND]);
while(sounds_in_queue!=0);
}
else if ((ABS(from_x-to_x) == 2 && ABS(from_y-to_y) == 2) || (ABS(from_x-to_x)==2 &&ABS(from_y-to_y) == 0) || (ABS(from_x-to_x)==0 &&ABS(from_y-to_y) == 2))
{
put_piece( player, to_x, to_y );
board[from_x][from_y] = EMPTY;
PutSprite( boardx[from_x], boardy[from_y], sprite[TILE1].W, sprite[TILE1].H, sp_image[TILE1] );
if(allsound) playsound(rafdata[JUMPSND], raflength[JUMPSND]);
while(sounds_in_queue!=0);
}
if(board[to_x][to_y]==SETBOMB)
{
i = rand() % 3;
if(i==0)
{
shootout( boardx[to_x], boardy[to_y], player );
board[to_x][to_y] = TOMBED;
}
else if(i==1)
{
explode( boardx[to_x], boardy[to_y] );
board[to_x][to_y] = BOMBED;
}
else
{
flushit( boardx[to_x], boardy[to_y], player );
board[to_x][to_y] = FLUSHED;
}
bombs_left--;
while(sounds_in_queue!=0);
draw_board( board );
show_mouse();
return;
}
else
board[to_x][to_y] = player;
// DELAY BEFORE CAPTURE PIECES
v_delay( 10 );
capture( board, player, to_x, to_y );
draw_board( board );
while(sounds_in_queue!=0);
show_mouse();
}
int players_turn( board_t board, int player )
{
int nx, ny, i, operation, from_x, from_y, to_x, to_y, xx, yy, buttons;
operation=0;
// LOOP UNTIL HUMAN PLAYER DOES A VALID MOVE OR BUTTON PRESS
while(operation==0) //while no operations have been made...
{
check_mouse( &mousex, &mousey, &mousebut );
i = check_kbd();
if(i==1)
{
hide_mouse();
PutBlock( 277, 178, sprite[MENUBTN].W, sprite[MENUBTN].H, sp_image[MENUBTN] );
show_mouse();
if(master_snd_sys) playsound( rafdata[HITMAINSND], raflength[HITMAINSND] );
operation = 2; //set to 2 for go back to menu.
}
else if(i==9)
hint( board, player );
if( mousebut == 1)
{
xx = (mousex/2); // DIVIDE MOUSE X / 2
yy = mousey;
if((xx>279&&xx<310)&&(yy>180&&yy<191)) // IF USER HIT MENU BUTTON
{
hide_mouse();
PutBlock( 277, 178, sprite[MENUBTN].W, sprite[MENUBTN].H, sp_image[MENUBTN] );
show_mouse();
if(master_snd_sys) playsound( rafdata[HITMAINSND], raflength[HITMAINSND] );
operation = 2;
continue;
}
else if((xx>228&&xx<255)&&(yy>180&&yy<191))
{
hint( board, player );
}
else if((xx>230&&xx<308)&&(yy>145&&yy<151))
{
toggle_sound();
v_delay( 10 );
}
else if((xx>230&&xx<308)&&(yy>155&&yy<161))
{
toggle_show_moves();
v_delay( 10 );
}
else if ((xx>boardx[0]) && (xx<(boardx[7]+sprite[TILE1].W))&&(yy>boardy[0]) && (yy<(boardy[7]+sprite[TILE1].H)))
{
from_x = calc_x( xx );
from_y = calc_y( yy );
if(board[from_x][from_y]==player)
{
hide_mouse();
put_avail_moves( board, player, from_x, from_y );
v_delay( 12 );
show_mouse();
mousebut = 0;
while(mousebut!=1)
{
check_mouse( &mousex, &mousey, &mousebut );
check_kbd();
}
to_x = calc_x( mousex/2 );
to_y = calc_y( mousey );
if(to_x>=BSIZE||to_y>=BSIZE)
{
to_x = 0;
to_y = 0;
operation = 0;
draw_board( board );
continue; //selected a different piece, start over.
}
if( board[to_x][to_y]==NA || board[to_x][to_y]==BOMBED || board[to_x][to_y]==TOMBED || board[to_x][to_y]==FLUSHED || board[to_x][to_y]==OTHER(player))
{
if(allsound) playsound(rafdata[INVALIDSND], raflength[INVALIDSND]);
draw_board( board );
while(sounds_in_queue!=0);
continue; //invalid tiles, start over at top.
}
else if( board[to_x][to_y]==player)
{
draw_board( board );
continue; //selected a different piece, start over.
}
// CHECK IF PLAYER MOVED 1 SQUARE AWAY
if(board[to_x][to_y]==EMPTY||board[to_x][to_y]==SETBOMB)
{
if ((ABS(from_x-to_x)==1&&ABS(from_y-to_y)==1)||(ABS(from_x-to_x)==0&&ABS(from_y-to_y)==1)||(ABS(from_x-to_x)==1&&ABS(from_y-to_y)==0))
{
hide_mouse();
operation = 1; //move was made, switch players
put_piece( player, to_x, to_y );
if(allsound) playsound(rafdata[MOVESND], raflength[MOVESND]);
while(sounds_in_queue!=0);
}
else if ((ABS(from_x-to_x) == 2 && ABS(from_y-to_y) == 2) || (ABS(from_x-to_x)==2 &&ABS(from_y-to_y) == 0) || (ABS(from_x-to_x)==0 &&ABS(from_y-to_y) == 2))
{
hide_mouse();
board[from_x][from_y] = EMPTY;
PutSprite( boardx[from_x], boardy[from_y], sprite[TILE1].W, sprite[TILE1].H, sp_image[TILE1] );
operation = 1; //move was made, switch players
put_piece( player, to_x, to_y );
if(allsound) playsound(rafdata[JUMPSND], raflength[JUMPSND]);
while(sounds_in_queue!=0);
}
else
{
draw_board( board );
continue; //invalid destination, start over.
}
}
else
{
draw_board( board );
continue; //invalid destination, start over.
}
if(board[to_x][to_y]==SETBOMB)
{
i = rand() % 2;
if(i==0)
{
shootout( boardx[to_x], boardy[to_y], player );
board[to_x][to_y] = TOMBED;
}
else if(i==1)
{
explode( boardx[to_x], boardy[to_y] );
board[to_x][to_y] = BOMBED;
}
else
{
flushit( boardx[to_x], boardy[to_y], player );
board[to_x][to_y] = FLUSHED;
}
bombs_left--;
while(sounds_in_queue!=0);
draw_board( board );
show_mouse();
continue;
}
else
board[to_x][to_y] = player;
gameinprogress = TRUE;
// DELAY BEFORE CAPTURE PIECES
v_delay( 10 );
capture( board, player, to_x, to_y );
draw_board( board );
while(sounds_in_queue!=0);
show_mouse();
}// IF(PIECE==PLAYER)
else if(board[from_x][from_y]==OTHER(player))
{
if(allsound) playsound(rafdata[INVALIDSND], raflength[INVALIDSND]);
while(sounds_in_queue!=0); //invalid sound play
continue;
}
}// IF USER HIT ICONS OR BOARD
}// IF(BUTTONS==1)
}// while( no valid move );
return( operation );
}
int do_game( board_t board, int player)
{
int xx, yy, buttons, x, y, from_x, from_y, to_x, to_y, i, nx, ny;
int gameover = FALSE;
if(player==PLAYERX) //restore players type and depth for resume game.
{
curplayertype=playerXtype;
curplayerdepth=playerXdepth;
}
else
{
curplayertype=playerOtype;
curplayerdepth=playerOdepth;
}
while(gameover!=TRUE) // QUIT
{
if(curplayertype==COMPUTER)
{
brain = rand() % 2;
computers_turn( board, player );
}
else if(curplayertype==HUMAN)
{
i = players_turn( board, player );
if(i==2)
gameover=TRUE;
}
if(gameover!=TRUE) //if game still going on, switch players.
player = switch_players(player);
i = checkpieces( board, player ); //check if game over, update score...
if(i!=NULL)
{
gameover = TRUE;
gameinprogress = FALSE;
continue;
}
//returns TRUE if mainmenu is selected.
i = check_kbd(); //check in between turns for key presses
if(i==TRUE)
{
hide_mouse();
PutBlock( 277, 178, sprite[MENUBTN].W, sprite[MENUBTN].H, sp_image[MENUBTN] );
show_mouse();
if(master_snd_sys) playsound( rafdata[HITMAINSND], raflength[HITMAINSND] );
gameover = TRUE;
}
}// WHILE(gameover!=TRUE)
return player;
}
int hint( board_t board, int player )
{
int from_x, from_y, to_x, to_y, i;
hide_mouse();
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
PutBlock( 226, 178, sprite[HINTBTN].W, sprite[HINTBTN].H, sp_image[HINTBTN+1] );
hintselected=TRUE;
play(board, 0, player); //calculate move
hintsused++;
from_x = best_from_x[0];
from_y = best_from_y[0];
to_x = best_to_x[0];
to_y = best_to_y[0];
for(i=0;i<5;i++)
{
if(player==PLAYERX)
PutBlock( boardx[from_x], boardy[from_y], sprite[BLUESELECTED].W, sprite[BLUESELECTED].H, sp_image[BLUESELECTED] );
else
PutBlock( boardx[from_x], boardy[from_y], sprite[REDSELECTED].W, sprite[REDSELECTED].H, sp_image[REDSELECTED] );
PutBlock( boardx[to_x], boardy[to_y], sprite[TILEAVAIL].W, sprite[TILEAVAIL].H, sp_image[TILEAVAIL] );
v_delay( 8 );
if(player==PLAYERX)
PutBlock( boardx[from_x], boardy[from_y], sprite[PLAYERX_GFX].W, sprite[PLAYERX_GFX].H, sp_image[PLAYERX_GFX] );
else
PutBlock( boardx[from_x], boardy[from_y], sprite[PLAYERO_GFX].W, sprite[PLAYERO_GFX].H, sp_image[PLAYERO_GFX] );
PutBlock( boardx[to_x], boardy[to_y], sprite[TILE1].W, sprite[TILE1].H, sp_image[TILE1] );
v_delay( 8 );
}
PutBlock( 226, 178, sprite[HINTBTN].W, sprite[HINTBTN].H, sp_image[HINTBTN] );
show_mouse();
hintselected=FALSE;
return (0);
}
int switch_players( int player )
{
if(player == PLAYERX) // SWITCH PLAYERS
{
curplayertype = playerOtype;
curplayerdepth = playerOdepth;
}
else
{
curplayertype = playerXtype;
curplayerdepth = playerXdepth;
}
player = OTHER(player);
return(player);
}
int check_kbd( void )
{
char ch;
if(kbhit())
{
ch=getkey();
if(ch==LM)
return(1);
else if(ch==LS)
toggle_sound();
else if(ch==LO)
toggle_show_moves();
else if(ch==LH&&curplayertype==HUMAN)
return(9);
}
return(0);
}
void capture( board_t board, int player, int to_x, int to_y)
{
int i,nx,ny,total;
total=0;
for (i=0; i<BSIZE; i++)
{
if(brain==0)
{
nx = to_x+aix[i];
ny = to_y+aiy[i];
}
else
{
nx = to_x+bix[i];
ny = to_y+biy[i];
}
if (ON_BOARD(nx, ny) && board[nx][ny] == OTHER(player))
{
total++;
board[nx][ny] = player;
if(sounds_in_queue==0&&allsound) playsound(rafdata[CAPTURESND+player-1], raflength[CAPTURESND+player-1]);
if(player==PLAYERX)
PutSprite( boardx[nx], boardy[ny], sprite[PLAYERX_GFX].W, sprite[PLAYERX_GFX].H, sp_image[PLAYERX_GFX] );
else
PutSprite( boardx[nx], boardy[ny], sprite[PLAYERO_GFX].W, sprite[PLAYERO_GFX].H, sp_image[PLAYERO_GFX] );
}
}
if(allsound)
{
while(sounds_in_queue!=0);
v_delay( 10 );
if(total==8)
{
if(curplayertype==COMPUTER)
playsound( rafdata[COMP8SND], raflength[COMP8SND] );
else
playsound( rafdata[PLAY8SND], raflength[PLAY8SND] );
}
else if(total>=6)
{
if(curplayertype==COMPUTER)
playsound( rafdata[COMP7SND], raflength[COMP7SND] );
else
playsound( rafdata[PLAY7SND], raflength[PLAY7SND] );
}
}
}
void intro( void )
{
Black_Pal();
load_pic( _scrn+(35*320), PIC1_FOFFSET );
FadeIn( palette[TITLEPAL], 10 );
v_delay( 60 );
if(!kbhit())
v_delay( 85 );
load_pic( _scrn+(180*320), PIC2_FOFFSET );
v_delay( 30 );
if(!kbhit())
v_delay( 120 );
FadeOut( palette[TITLEPAL], 10 );
Clear(0);
load_pic( _scrn+(40*320), PIC3_FOFFSET );
if(master_snd_sys) playsound( rafdata[INTROSND], raflength[INTROSND] );
SetPal( palette[TITLE2PAL] );
v_delay( 60 );
while(sounds_in_queue!=0);
if(!kbhit())
v_delay( 85 );
SetPal( palette[WHITEPAL] );
v_delay( 8 );
FadeOut( palette[WHITEPAL], 5 );
}
int mainmenu( void )
{
int x, y, menustate;
char ch, valid, scroll;
Black_Pal();
_scrn = (unsigned char far *)0xA0000000L;
load_pic( _scrn, PIC4_FOFFSET );
update_menu_ops();
display_cells();
if(gameinprogress==TRUE)
{
PutBlock( 124,132,sprite[RESUMEGAMEGFX].W,sprite[RESUMEGAMEGFX].H,sp_image[RESUMEGAMEGFX] );
PutSprite( 124,113,sprite[STOPBTNOUT].W,sprite[STOPBTNOUT].H,sp_image[STOPBTNOUT] );
PutSprite( 281,115, sprite[OPSCOVER].W, sprite[OPSCOVER].H, sp_image[OPSCOVER] );
PutSprite( 281, 66, sprite[OPSCOVER].W, sprite[OPSCOVER].H, sp_image[OPSCOVER] );
//PutSprite( 113,174, sprite[OPSCOVER].W, sprite[OPSCOVER].H, sp_image[OPSCOVER] );
//PutSprite( 127,174, sprite[OPSCOVER].W, sprite[OPSCOVER].H, sp_image[OPSCOVER] );
//PutSprite( 133,174, sprite[OPSCOVER].W, sprite[OPSCOVER].H, sp_image[OPSCOVER] );
}
if(registered==FALSE)
{
PutSprite( 50,88, sprite[XPIC].W,sprite[XPIC].H,sp_image[XPIC]);
PutSprite( 50,160, sprite[XPIC].W,sprite[XPIC].H,sp_image[XPIC]);
PutSprite( 119,177, sprite[XPIC].W,sprite[XPIC].H,sp_image[XPIC]);
}
show_mouse();
FadeIn( palette[MENUPAL], 5 );
flush_kbd();
menustate = 0;
while(1)
{
valid=FALSE;
scroll=FALSE;
if(kbhit())
{
//ch=getkey();
ch = getch();
if(ch=='n')
{
menustate = STARTNEWGAME;
hide_mouse();
PutSprite(124,56,sprite[NEWBTN].W,sprite[NEWBTN].H, sp_image[NEWBTN] );
if(master_snd_sys) playsound(rafdata[NEWGAMESND], raflength[NEWGAMESND]);
show_mouse();
break;
}
else if(ch=='q')
{
menustate = EXITTODOS;
hide_mouse();
PutBlock(174,168,sprite[QUITBTN].W,sprite[QUITBTN].H, sp_image[QUITBTN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
break;
}
else if(ch=='r'&&gameinprogress==TRUE)
{
menustate=RESUMEGAME;
hide_mouse();
PutSprite(124,132,sprite[RESBTN].W,sprite[RESBTN].H, sp_image[RESBTN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
cell=board_level;
break;
}
else if(ch=='s'&&gameinprogress==TRUE)
{
menustate=STOPGAME;
hide_mouse();
PutSprite(124,113,sprite[STOPBTNIN].W,sprite[STOPBTNIN].H, sp_image[STOPBTNIN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
break;
}
else if(ch=='o')
{
menustate = INFO;
hide_mouse();
PutSprite(124,75,sprite[INFOBTN].W,sprite[INFOBTN].H, sp_image[INFOBTN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
break;
}
else if(ch=='d')
{
menustate = CREDITS;
hide_mouse();
PutSprite(124,94,sprite[CREDBTN].W,sprite[CREDBTN].H, sp_image[CREDBTN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
break;
}
else if(ch=='h')
{
playerXtype=HUMAN;
valid=TRUE;
}
else if(ch=='m')
{
playerXtype=COMPUTER;
playerXdepth=1;
valid=TRUE;
}
else if(ch=='i')
{
playerXtype=COMPUTER;
playerXdepth=2;
valid=TRUE;
}
else if(ch=='c'&®istered == TRUE)
{
playerXtype=COMPUTER;
playerXdepth=3;
valid=TRUE;
}
else if(ch=='a')
{
playerOtype=HUMAN;
valid=TRUE;
}
else if(ch=='1')
{
playerOtype=COMPUTER;
playerOdepth=1;
valid=TRUE;
}
else if(ch=='2')
{
playerOtype=COMPUTER;
playerOdepth=2;
valid=TRUE;
}
else if(ch=='3'&®istered == TRUE)
{
playerOtype=COMPUTER;
playerOdepth=3;
valid=TRUE;
}
else if(ch=='k'&&gameinprogress==FALSE&®istered == TRUE)
{
killers=!killers;
valid=TRUE;
}
else if(ch==UP&&gameinprogress==FALSE) //ARROW UP
{
if((cell-1)>0)
{
cell--;
scroll=TRUE;
}
}
else if(ch==DOWN&&gameinprogress==FALSE) //ARROW DOWN
{
if((cell+1)<maxboardscanuse+1)
{
cell++;
scroll=TRUE;
}
}
else if(ch==PGUP&&gameinprogress==FALSE) //PAGE UP
{
if((cell-10)>0)
{
cell-=10;
scroll=TRUE;
}
else if(cell!=1)
{
cell=1;
scroll=TRUE;
}
}
else if(ch==PGDOWN&&gameinprogress==FALSE) //PAGE DOWN
{
if((cell+10)<maxboardscanuse+1)
{
cell+=10;
scroll=TRUE;
}
else if(cell!=maxboardscanuse)
{
cell=maxboardscanuse;
scroll=TRUE;
}
}
else if(ch==HOME&&gameinprogress==FALSE) //HOME
{
if(cell!=1)
{
cell=1;
scroll=TRUE;
}
}
else if(ch==END&&gameinprogress==FALSE) //END
{
if(cell!=maxboardscanuse)
{
cell=maxboardscanuse;
scroll=TRUE;
}
}
}
check_mouse( &mousex, &mousey, &mousebut );
if(mousebut==1)
{
x = (mousex/2);
y = mousey;
if((x>175&&y>169) && (x<224&&y<177))
{
menustate = EXITTODOS;
hide_mouse();
PutBlock(174,168,sprite[QUITBTN].W,sprite[QUITBTN].H, sp_image[QUITBTN] );
if(master_snd_sys) playsound(rafdata[DULLTHUDSND], raflength[DULLTHUDSND]);
show_mouse();
break;
}
else if((x>125&&y>57) && (x<215&&y<68))
{
menustate = STARTNEWGAME;
hide_mouse();
PutSprite(124,56,sprite[NEWBTN].W,sprite[NEWBTN].H, sp_image[NEWBTN] );
if(master_snd_sys) playsound(rafdata[NEWGAMESND], raflength[NEWGAMESND]);
show_mouse();
break;