forked from viridia/faery-tale-amiga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmain.c
3631 lines (3207 loc) · 104 KB
/
fmain.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
/* fmain.c - created Aug 86 by Talin - The Faerie Tale Adventure */
#include "ftale.h"
/****** this section defines the variables used to communicate with the
graphics routines */
#define PAGE_DEPTH 5
#define TEXT_DEPTH 4
#define SCREEN_WIDTH 288
#define PHANTA_WIDTH 320 /* two words added for horizontal scrolling */
#define PAGE_HEIGHT 143
#define RAST_HEIGHT 200
#define TEXT_HEIGHT 57
struct View v, *oldview;
struct ViewPort vp_page, vp_text, vp_title, *vp;
/* add name of setfig for generic messages?? */
struct {
BYTE cfile_entry,image_base,can_talk;
} setfig_table[] = {
13,0,1, /* "wizard" = 0 */
13,4,1, /* "priest" = 1 */
14,0,0, /* "guard" = 2 */
14,1,0, /* "guard" = 3 (back) */
14,2,0, /* "princess" = 4 */
14,4,1, /* "king" = 5 */
14,6,0, /* "noble" = 6 */
14,7,0, /* "sorceress" = 7 */
15,0,0, /* "bartender" = 8 */
16,0,0, /* "witch" = 9 */
16,6,0, /* "spectre" = 10 */
16,7,0, /* "ghost" = 11 */
17,0,1, /* "ranger" = 12 */
17,4,1 /* "begger" = 13 */
};
struct seq_info seq_list[7];
/* defines the variables for currently defined actors, on screen or off */
struct encounter {
char hitpoints,
agressive,
arms,
cleverness,
treasure,
file_id;
} encounter_chart[] = {
{ 18, TRUE,2,0,2, 6 }, /* 0 - Ogre */
{ 12, TRUE,4,1,1, 6 }, /* 1 - Orcs */
{ 16, TRUE,6,1,4, 7 }, /* 2 - Wraith */
{ 8, TRUE,3,0,3, 7 }, /* 3 - Skeleton */
{ 16, TRUE,6,1,0, 8 }, /* 4 - Snake - swamp region */
{ 9, TRUE,3,0,0, 7 }, /* 5 - Salamander - lava region */
{ 10, TRUE,6,1,0, 8 }, /* 6 - Spider - spider pits */
{ 40, TRUE,7,1,0, 8 }, /* 7 - DKnight - elf glade */
{ 12, TRUE,6,1,0, 9 }, /* 8 - Loraii - astral plane */
{ 50, TRUE,5,0,0, 9 }, /* 9 - Necromancer - final arena */
{ 4, NULL,0,0,0, 9 }, /* 10 - Woodcutter */
};
extern char treasure_probs[], weapon_probs[];
#define MAXSHAPES 25
struct shape anim_list[20]; /* 7 people + 7 objects */
/* weapon: 0=none, 1=dagger, 2=mace, 3=sword, 4=bow, 5=wand */
unsigned char anim_index[20]; /* for sorting */
short anix, anix2; /* allocation index - how many monsters + 1 */
short mdex;
struct missile {
unsigned short abs_x, abs_y;
char missile_type, /* NULL, arrow, rock, 'thing', or fireball */
time_of_flight, /* in frames? */
speed, /* 0 = still unshot */
direction,
archer; /* ID of archer */
} missile_list[6]; /* six missiles max */
char fiery_death;
/* motion states */
#define WALKING 12
#define STILL 13
#define FIGHTING 0
#define DYING 14
#define DEAD 15
#define SINK 16
#define OSCIL 17 /* and 18 */
#define TALKING 19
#define FROZEN 20
#define FLYING 21
#define FALL 22
#define SLEEP 23
#define SHOOT1 24 /* bow up - aiming */
#define SHOOT3 25 /* bow fired, arrow given velocity */
/* goal modes */
#define USER 0 /* character is user-controlled */
#define ATTACK1 1 /* attack character (stupidly) */
#define ATTACK2 2 /* attack character (cleverly) */
#define ARCHER1 3 /* archery attack style 1 */
#define ARCHER2 4 /* archery attack style 2 */
#define FLEE 5 /* run directly away */
#define STAND 6 /* don't move but face character */
#define DEATH 7 /* a dead character */
#define WAIT 8 /* wait to speak to character */
#define FOLLOWER 9 /* follow another character */
#define CONFUSED 10 /* run around randomly */
/* tactical modes (sub-goals) */
/* choices 2-5 can be selected randomly for getting around obstacles */
#define FRUST 0 /* all tactics frustrated - try sonething else */
#define PURSUE 1 /* go in the direction of the character */
#define FOLLOW 2 /* go toward another character */
#define BUMBLE_SEEK 3 /* bumble around looking for him */
#define RANDOM 4 /* move randomly */
#define BACKUP 5 /* opposite direction we were going */
#define EVADE 6 /* move 90 degrees from character */
#define HIDE 7 /* seek a hiding place */
#define SHOOT 8 /* shoot an arrow */
#define SHOOTFRUST 9 /* arrows not getting through */
#define EGG_SEEK 10 /* snakes going for the eggs */
extern char turtle_eggs;
extern UBYTE fallstates[];
struct transition
{ char newstate[4]; /* transition table */
} trans_list[9] = {
{ 1, 8, 0, 1 }, /* 0 - arm down, weapon low */
{ 2, 0, 1, 0 }, /* 1 - arm down, weapon diagonal down */
{ 3, 1, 2, 8 }, /* 2 - arm swing1, weapon horizontal */
{ 4, 2, 3, 7 }, /* 3 - arm swing2, weapon raised */
{ 5, 3, 4, 6 }, /* 4 - arm swing2, weapon diag up */
{ 6, 4, 5, 5 }, /* 5 - arm swing2, weapon high */
{ 8, 5, 6, 4 }, /* 6 - arm high, weapon up */
{ 8, 6, 7, 3 }, /* 7 - arm high, weapon horizontal */
{ 0, 6, 8, 2 }}; /* 8 - arm middle, weapon raise fwd */
struct state {
char figure, /* figure # to use */
wpn_no, /* weapon index to use */
wpn_x, wpn_y; /* weapon x,y coord */
} statelist[87] = {
/* 0 = southwalk sequence */
{ 0,11,-2,11 },{ 1,11,-3,11 },{ 2,11,-3,10 },{ 3,11,-3, 9 },
{ 4,11,-3,10 },{ 5,11,-3,11 },{ 6,11,-2,11 },{ 7,11,-1,11 },
/* 8 = westwalk sequence */
{ 8,9,-12,11 },{ 9,9,-11,12 },{ 10,9,-8,13 },{ 11,9,-4,13 },
{ 12,9,0,13 },{ 13,9,-4,13 },{ 14,9,-8,13 },{ 15,9,-11,12 },
/* 16 = northwalk sequence */
{ 16,14,-1,1 },{ 17,14,-1,2 },{ 18,14,-1,3 },{ 19,14,-1,4 },
{ 20,14,-1,3 },{ 21,14,-1,2 },{ 22,14,-1,1 },{ 23,14,-1,1 },
/* 24 = eastwalk sequence */
{ 24,10,5,12 },{ 25,10,3,12 },{ 26,10,2,12 },{ 27,10,3,12 },
{ 28,10,5,12 },{ 29,10,6,12 },{ 30,10,6,11 },{ 31,10,6,12 },
/* 32 = south fight = 32 + transition state */
{ 32,11,-2,12 },{ 32,10,0,12 },{ 33,0,2,10 },
{ 34,1,4,6 },{ 34,2,1,4 },{ 34,3,0,4 },
{ 36,4,-5,0 },{ 36,5,-10,1 },{ 35,12,-5,5 },
{ 36,0,0,+6 },{ 38,85,-6,5 },{ 37,81,-6,5 },
/* 44 = west fight = 44 + transition state */
{ 40,9,-7,12 },{ 40,8,-9,9 },{ 41,7,-10,5 },
{ 42,7,-12,4 },{ 42,6,-12,3 },{ 42,5,-12,3 },
{ 44,5,-8,3 },{ 44,14,-7,6 },{ 43,13,-7,8 },
{ 42,5,-12,3 },{ 46,86,-3,0 },{ 45,82,-3,0 },
/* 56 = north fight = 56 + transition state */
{ 48,14,-3,0 },{ 48,6,-3,-1 },{ 49,5,-2,-3 },
{ 50,5,-3,-4 },{ 50,4,0,0 },{ 50,3,3,0 },
{ 52,4,6,1 },{ 52,15,7,3 },{ 51,14,1,6 },
{ 50,4,0,0 },{ 54,87,3,0 },{ 53,83,3,0 },
/* 68 = east fight = 68 + transition state */
{ 56,10,5,11 },{ 56,0,6,9 },{ 57,1,10,6 },
{ 58,1,10,5 },{ 58,2,7,3 },{ 58,3,6,3 },
{ 60,4,1,0 },{ 60,3,3,2 },{ 59,15,4,1 },
{ 58,4,5,1 },{ 62,84,3,0 },{ 61,80,3,0 },
/* 80 = death sequence 1 */
{ 47,0,5,11 },{ 63,0,6,9 },{ 39,0,6,9 },
/* 83 = sinking sequence 1 (with bubbles??) */
{ 55,10,5,11 },
/* 84, 85 - oscillations (sword at side??) */
{ 64,10,5,11 },{ 65,10,5,11 },
/* 86 - asleep */
{ 66,10,5,11 }
};
extern char bow_x[], bow_y[], bowshotx[], bowshoty[], gunshoty[];
/* var1 is usually clock, var2 is usually direction */
/* three types of doors + F1/F9 doors, F1/F10 doors and F9/F10 doors */
/* horizontals all have lsb set */
#define HWOOD 1
#define VWOOD 2
#define HSTONE 3
#define VSTONE 4
#define HCITY 5
#define VCITY 6
#define CRYST 7
#define SECRET 8
#define BLACK 9
#define MARBLE 10
#define LOG 11
#define HSTON2 13
#define VSTON2 14
#define STAIR 15
#define DESERT 17
#define CAVE 18
#define VLOG 18 /* same as cave */
#define DOORCOUNT 86
struct door { /* mark locations of all doors */
unsigned short
xc1, yc1, /* outside image coords relative to F1 */
xc2, yc2; /* inside image coords relative to F9 */
char type; /* wood, stone */
char secs; /* what sectors are joined by this */
} doorlist[DOORCOUNT] = {
{ 0x1170,0x5060, 0x2870,0x8b60, HWOOD,1 }, /* desert fort */
{ 0x1170,0x5060, 0x2870,0x8b60, HWOOD,1 }, /* desert fort */
{ 0x1170,0x5060, 0x2870,0x8b60, HWOOD,1 }, /* desert fort */
{ 0x1170,0x5060, 0x2870,0x8b60, HWOOD,1 }, /* desert fort */
{ 0x1390,0x1b60, 0x1980,0x8c60, CAVE, 2 }, /* dragon cave */
{ 0x1770,0x6aa0, 0x2270,0x96a0, BLACK, 1 }, /* pass fort */
{ 0x1970,0x62a0, 0x1f70,0x96a0, BLACK, 1 }, /* gate fort */
{ 0x1aa0,0x4ba0, 0x13a0,0x95a0, DESERT,1 }, /* oasis #1 */
{ 0x1aa0,0x4c60, 0x13a0,0x9760, DESERT,1 }, /* oasis #4 */
{ 0x1b20,0x4b60, 0x1720,0x9560, DESERT,1 }, /* oasis #2 */
{ 0x1b80,0x4b80, 0x1580,0x9580, DESERT,1 }, /* oasis #3 */
{ 0x1b80,0x4c40, 0x1580,0x9740, DESERT,1 }, /* oasis #5 */
{ 0x1e70,0x3b60, 0x2880,0x9c60, HSTONE,1 }, /* west keep */
{ 0x2480,0x33a0, 0x2e80,0x8da0, HWOOD ,1 }, /* swamp shack */
{ 0x2960,0x8760, 0x2b00,0x92c0, STAIR ,1 }, /* stargate forwards */
{ 0x2b00,0x92c0, 0x2960,0x8780, STAIR ,2 }, /* stargate backwards */
{ 0x2c00,0x7160, 0x2af0,0x9360, BLACK ,1 }, /* doom tower */
{ 0x2f70,0x2e60, 0x3180,0x9a60, HSTONE,1 }, /* lakeside keep */
{ 0x2f70,0x63a0, 0x1c70,0x96a0, BLACK ,1 }, /* plain fort */
{ 0x3180,0x38c0, 0x2780,0x98c0, HWOOD ,1 }, /* road's end inn */
{ 0x3470,0x4b60, 0x0470,0x8ee0, STAIR ,2 }, /* tombs */
{ 0x3DE0,0x1BC0, 0x2EE0,0x93C0, CRYST ,1 }, /* crystal palace */
{ 0x3E00,0x1BC0, 0x2F00,0x93C0, CRYST ,1 }, /* crystal palace */
{ 0x4270,0x2560, 0x2e80,0x9a60, HSTONE,1 }, /* coast keepDB */
{ 0x4280,0x3bc0, 0x2980,0x98c0, HWOOD ,1 }, /* friendly inn */
{ 0x45e0,0x5380, 0x25d0,0x9680, MARBLE,1 }, /* mountain keep */
{ 0x4780,0x2fc0, 0x2580,0x98c0, HWOOD ,1 }, /* forest inn */
{ 0x4860,0x6640, 0x1c60,0x9a40, VLOG ,1 }, /* cabin yard #7 */
{ 0x4890,0x66a0, 0x1c90,0x9aa0, LOG ,1 }, /* cabin #7 */
{ 0x4960,0x5b40, 0x2260,0x9a40, VLOG ,1 }, /* cabin yard #6 */
{ 0x4990,0x5ba0, 0x2290,0x9aa0, LOG ,1 }, /* cabin #6 */
{ 0x49a0,0x3cc0, 0x0ba0,0x82c0, VWOOD ,1 }, /* village #2 */
{ 0x49d0,0x3dc0, 0x0bd0,0x84c0, VWOOD ,1 }, /* village #1.a */
{ 0x49d0,0x3e00, 0x0bd0,0x8500, VWOOD ,1 }, /* village #1.b */
{ 0x4a10,0x3c80, 0x0d10,0x8280, HWOOD ,1 }, /* village #3 */
{ 0x4a10,0x3d40, 0x0f10,0x8340, HWOOD ,1 }, /* village #5 */
{ 0x4a30,0x3dc0, 0x0e30,0x85c0, HWOOD ,1 }, /* village #7 */
{ 0x4a60,0x3e80, 0x1060,0x8580, HWOOD ,1 }, /* village #8 */
{ 0x4a70,0x3c80, 0x1370,0x8280, HWOOD ,1 }, /* village #4 */
{ 0x4a80,0x3d40, 0x1190,0x8340, HWOOD ,1 }, /* village #6 */
{ 0x4c70,0x3260, 0x2580,0x9c60, HSTONE,1 }, /* crag keep */
{ 0x4d60,0x5440, 0x1f60,0x9c40, VLOG ,1 }, /* cabin #2 */
{ 0x4d90,0x4380, 0x3080,0x8d80, HSTON2,1 }, /* crypt */
{ 0x4d90,0x54a0, 0x1f90,0x9ca0, LOG ,1 }, /* cabin yard #2 */
{ 0x4de0,0x6b80, 0x29d0,0x9680, MARBLE,1 }, /* river keep */
{ 0x5360,0x5840, 0x2260,0x9840, VLOG ,1 }, /* cabin yard #3 */
{ 0x5390,0x58a0, 0x2290,0x98a0, LOG ,1 }, /* cabin #3 */
{ 0x5460,0x4540, 0x1c60,0x9840, VLOG ,1 }, /* cabin yard #1 */
{ 0x5470,0x6480, 0x2c80,0x8d80, HSTONE,1 }, /* elf glade */
{ 0x5490,0x45a0, 0x1c90,0x98a0, LOG ,1 }, /* cabin #1 */
{ 0x55f0,0x52e0, 0x16e0,0x83e0, MARBLE,1 }, /* main castle */
{ 0x56c0,0x53c0, 0x1bc0,0x84c0, HSTON2,1 }, /* city #15.a */
{ 0x56c0,0x5440, 0x19c0,0x8540, HSTON2,1 }, /* city #17 */
{ 0x56f0,0x51a0, 0x19f0,0x82a0, HSTON2,1 }, /* city #10 */
{ 0x5700,0x5240, 0x1df0,0x8340, VSTON2,1 }, /* city #12 */
{ 0x5710,0x5440, 0x1c10,0x8640, HSTON2,1 }, /* city #18 */
{ 0x5730,0x5300, 0x1a50,0x8400, HSTON2,1 }, /* city #14 */
{ 0x5730,0x5380, 0x1c30,0x8480, VSTON2,1 }, /* city #15.b */
{ 0x5750,0x51a0, 0x1c60,0x82a0, HSTON2,1 }, /* city #11 */
{ 0x5750,0x5260, 0x2050,0x8360, HSTON2,1 }, /* city #13 */
{ 0x5760,0x53c0, 0x2060,0x84c0, HSTON2,1 }, /* city #16 */
{ 0x5760,0x5440, 0x1e60,0x8540, HSTON2,1 }, /* city #19 */
{ 0x5860,0x5d40, 0x1c60,0x9a40, VLOG ,1 }, /* cabin yard #4 */
{ 0x5890,0x5da0, 0x1c90,0x9ca0, LOG ,1 }, /* cabin #4 */
{ 0x58c0,0x2e60, 0x0ac0,0x8860, CAVE, 2 }, /* troll cave */
{ 0x5960,0x6f40, 0x2260,0x9a40, VLOG ,1 }, /* cabin yard #9 */
{ 0x5990,0x6fa0, 0x2290,0x9ca0, LOG ,1 }, /* cabin #9 */
{ 0x59a0,0x6760, 0x2aa0,0x8b60, STAIR ,1 }, /* unreachable castle */
{ 0x59e0,0x5880, 0x27d0,0x9680, MARBLE,1 }, /* farm keep */
{ 0x5e70,0x1a60, 0x2580,0x9a60, HSTONE,1 }, /* north keep */
{ 0x5ec0,0x2960, 0x11c0,0x8b60, CAVE ,2 }, /* spider exit */
{ 0x6060,0x7240, 0x1960,0x9c40, VLOG ,1 }, /* cabin yard #10 */
{ 0x6090,0x72a0, 0x1990,0x9ca0, LOG ,1 }, /* cabin #10 */
{ 0x60f0,0x32c0, 0x25f0,0x8bc0, HSTONE,1 }, /* mammoth manor */
{ 0x64c0,0x1860, 0x03c0,0x8660, CAVE ,2 }, /* maze cave 2 */
{ 0x6560,0x5d40, 0x1f60,0x9a40, VLOG ,1 }, /* cabin yard #5 */
{ 0x6590,0x5da0, 0x1f90,0x98a0, LOG ,1 }, /* cabin #5 */
{ 0x65c0,0x1a20, 0x04b0,0x8840, BLACK ,2 }, /* maze cave 1 */
{ 0x6670,0x2a60, 0x2b80,0x9a60, HSTONE,1 }, /* glade keep */
{ 0x6800,0x1b60, 0x2af0,0x9060, BLACK ,1 }, /* witch's castle */
{ 0x6b50,0x4380, 0x2850,0x8d80, HSTON2,1 }, /* light house */
{ 0x6be0,0x7c80, 0x2bd0,0x9680, MARBLE,1 }, /* lonely keep */
{ 0x6c70,0x2e60, 0x2880,0x9a60, HSTONE,1 }, /* sea keep */
{ 0x6d60,0x6840, 0x1f60,0x9a40, VLOG ,1 }, /* cabin yard #8 */
{ 0x6d90,0x68a0, 0x1f90,0x9aa0, LOG ,1 }, /* cabin #8 */
{ 0x6ee0,0x5280, 0x31d0,0x9680, MARBLE,1 } /* point keep */
};
/* 0-49 - regular encounters */
/* 50 = set group encounter */
/* 60 = special figure encounter */
/* 70 = bird or turtle */
/* need to define self-destructing extents?? */
struct extent {
UWORD x1, y1, x2, y2;
UBYTE etype, v1, v2, v3;
} *extn, extent_list[] = {
{ 2118,27237, 2618,27637, 70,0,1,11 }, /* bird extent */
{ 0, 0, 0, 0, 70,0,1,5 }, /* turtle extent */
{ 6749,34951, 7249,35351, 70,0,1,10 }, /* dragon extent */
{ 4063,34819, 4909,35125, 53, 4, 1, 6 }, /* spider pit */
{ 9563,33883, 10144,34462, 60, 1, 1, 9 }, /* necromancer */
{ 22945, 5597, 23225, 5747, 61, 3, 2, 4 }, /* turtle eggs */
{ 10820,35646, 10877,35670, 83, 1, 1, 0 }, /* princess extent */
{ 19596,17123, 19974,17401, 48, 8, 8, 2 }, /* graveyard ext */
{ 19400,17034, 20240,17484, 80, 4,20, 0 }, /* around city */
/* arena with lots of loraii?? (replenished for 10) */
/* dungeons with lotsa wraiths = 15, 31, etc. */
{0x2400,0x8200,0x3100,0x8a00,52,3, 1, 8 }, /* astral plane */
{ 5272,33300, 6112,34200, 81, 0, 1, 0 }, /* king pax */
{ 11712,37350, 12416,38020, 82, 0, 1, 0 }, /* sorceress pax */
{ 2752,33300, 8632,35400, 80, 0, 1, 0 }, /* peace 1 - buildings */
{ 10032,35550, 12976,40270, 80, 0, 1, 0 }, /* peace 2 - specials */
{ 4712,38100, 10032,40350, 80, 0, 1, 0 }, /* peace 3 - cabins */
{ 21405,25583, 21827,26028, 60, 1, 1, 7 }, /* hidden valley */
{ 6156,12755, 12316,15905, 7, 1, 8, 0 }, /* swamp region */
{ 5140,34860, 6260,37260, 8, 1, 8, 0 }, /* spider region */
{ 660,33510, 2060,34560, 8, 1, 8, 0 }, /* spider region */
{ 18687,15338, 19211,16136, 80, 0, 1, 0 }, /* village */
{ 16953,18719, 20240,17484, 3, 1, 3, 0 }, /* around village */
{ 20593,18719, 23113,22769, 3, 1, 3, 0 }, /* around city */
{ 0,0, 0x7fff, 0x9fff, 3, 1, 8, 0 }, /* whole world */
};
#define EXT_COUNT 22
unsigned char stone_list[] =
{ 54,43, 71,77, 78,102, 66,121, 12,85, 79,40,
107,38, 73,21, 12,26, 26,53, 84,60 };
extern struct object ob_listg[], ob_list8[];
struct inv_item inv_list[] = {
{ 12, 10, 0, 0, 0, 8, 1, "Dirk" },
{ 9, 10,10, 0, 0, 8, 1, "Mace" },
{ 8, 10,20, 0, 0, 8, 1, "Sword" },
{ 10, 10,30, 0, 0, 8, 1, "Bow" },
{ 17, 10,40, 0, 8, 8, 1, "Magic Wand" },
/* 5 */
{ 27, 10,50, 0, 0,8, 1, "Golden Lasso" },
{ 23, 10,60, 0, 8,8, 1, "Sea Shell" },
{ 27, 10,70, 0, 8,8, 1, "Sun Stone" },
{ 3, 30, 0, 3, 7, 1,45, "Arrows" },
{ 18, 50, 0, 9, 0, 8,15, "Blue Stone" },
/* 10 */
{ 19, 65, 0, 6, 0, 5,23, "Green Jewel" },
{ 22, 80, 0, 8, 0, 7,17, "Glass Vial" },
{ 21, 95, 0, 7, 0, 6,20, "Crystal Orb" },
{ 23,110, 0,10, 0, 9,14, "Bird Totem" },
{ 17,125, 0, 6, 0, 5,23, "Gold Ring" },
/* 15 */
{ 24,140, 0,10, 0, 9,14, "Jade Skull" },
{ 25,160, 0, 5, 0, 5,25, "Gold Key" },
{ 25,172, 0, 5, 8, 5,25, "Green Key" },
{ 114,184, 0, 5, 0, 5,25, "Blue Key" },
{ 114,196, 0, 5, 8, 5,25, "Red Key" },
/* 20 */
{ 26,208, 0, 5, 0, 5,25, "Grey Key" },
{ 26,220, 0, 5, 8, 5,25, "White Key" },
{ 11, 0, 80,0, 8,8, 1, "Talisman" },
{ 19, 0, 90,0, 8,8, 1, "Rose" },
{ 20, 0,100,0, 8,8, 1, "Fruit" },
/* 25 */
{ 21,232, 0,10, 8,8, 5, "Gold Statue" },
{ 22, 0,110,0, 8,8, 1, "Book" },
{ 8, 14, 80,0, 8,8, 1, "Herb" },
{ 9, 14, 90,0, 8,8, 1, "Writ" },
{ 10, 14,100,0, 8,8, 1, "Bone" },
/* 30 */
{ 12, 14,110,0, 8,8, 1, "Shard" },
{ 0, 0, 0, 0, 0, 0, 2, "2 Gold Pieces" },
{ 0, 0, 0, 0, 0, 0, 5, "5 Gold Pieces" },
{ 0, 0, 0, 0, 0, 0,10, "10 Gold Pieces" },
{ 0, 0, 0, 0, 0, 0,100,"100 Gold Pieces" },
{ 0, 0, 0, 0, 0, 0, 0, "quiver of arrows" }
};
#define MAGICBASE 9
#define KEYBASE 16
#define STATBASE 25
#define GOLDBASE 31
#define ARROWBASE 35
UBYTE *stuff, julstuff[ARROWBASE], philstuff[ARROWBASE], kevstuff[ARROWBASE];
/* defines the variables for on-screen animated shapes */
struct sshape {
unsigned char *backsave;
short savesize, blitsize, Coff, Cmod;
};
struct sshape *shp;
struct fpage fp_page1, fp_page2, *fp_drawing, *fp_viewing;
struct RasInfo ri_page1, ri_page2, ri_text, ri_title;
struct BitMap *bm_page1, *bm_page2, *bm_text, *bm_lim, *bm_draw, *bm_source;
struct BitMap bm_scroll, pagea, pageb;
struct RastPort rp_map, rp_text, rp_text2, *rp;
#define BM_SIZE (sizeof (struct BitMap))
PLANEPTR *pl;
LONG i;
SHORT j,k,n;
extern struct ColorMap *GetColorMap();
struct GfxBase *GfxBase;
struct Library *LayersBase;
UBYTE *nhinor, *nhivar;
extern UBYTE hinor, hivar;
struct SimpleSprite pointer = { 0,16,0,0,0 };
long *sprite_data, _sprite_data[] =
{ 0,
0x80060000, 0x60010002, 0x40012000, 0x10030000,
0x08FE0001, 0x0581007F, 0x03000081, 0x06010101,
0x0C800201, 0x08410401, 0x08200401, 0x08110401,
0x080C0401, 0x880F0401, 0x98074400, 0x75560FFC,
0,0,0
};
extern USHORT pagecolors [];
USHORT textcolors [] =
{ 0x000, 0xFFF, 0xC00, 0xF60, 0x00f, 0xc0f, 0x090, 0xFF0,
0xf90, 0xf0c, 0xA50, 0xFDB, 0xEB7, 0xCCC, 0x888, 0x444,
0x000, 0xDB0, 0x740, 0xC70 };
USHORT blackcolors [] =
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
USHORT introcolors[] =
{ 0x000, 0xFFF, 0xE00, 0xA00, 0xD80, 0xEC0, 0x390, 0x021,
0xEEB, 0xEDA, 0xEEA, 0xCB8, 0xA95, 0x973, 0x840, 0x620,
0xA52, 0xC74, 0xD96, 0xFCA, 0x449, 0x444, 0xDC9, 0x668,
0x33F, 0x888, 0xA60, 0xAAF, 0xBBB, 0xCCF, 0xDDD, 0xEEE };
char numbuf[11] = { 0,0,0,0,0,0,0,0,0,0,' '};
/* definitions for the option menus */
enum cmodes {ITEMS=0, MAGIC, TALK, BUY, GAME, SAVEX, KEYS, GIVE, USE, FILE};
char label1[] = "ItemsMagicTalk Buy Game ";
char label2[] = "List Take Look Use Give ";
char label3[] = "Yell Say Ask ";
char label4[] = "PauseMusicSoundQuit Load ";
char label5[] = "Food ArrowVial Mace SwordBow Totem";
char label6[] = "StoneJewelVial Orb TotemRing Skull";
char label7[] = "Dirk Mace SwordBow Wand LassoShellKey Sun Book ";
char label8[] = "Save Exit ";
char label9[] = "Gold GreenBlue Red Grey White";
char labelA[] = "Gold Book Writ Bone ";
char labelB[] = " A B C D E F G H ";
/* | | | | | | | | | | | | */
char keycolors[] = { 8,6,4,2,14,1 };
char hitgo; /* is the option we hit enabled */
/* bit0 = selected, bit1 = displayed, else = type
4 = toggle, 8 = immediate, 12 = radio buttons, 0 = not changeable */
char real_options[12];
struct menu {
char *label_list;
char num, color;
char enabled[12];
} menus[10] = {
{ label2, 10,6, 3,2,2,2,2,10,10,10,10,10,0,0 }, /* items */
{ label6, 12,5, 2,3,2,2,2,8,8,8,8,8,8,8 }, /* magic */
{ label3, 8,9, 2,2,3,2,2,10,10,10,0,0,0,0 }, /* talk */
{ label5, 12,10,2,2,2,3,2,10,10,10,10,10,10,10 }, /* buy */
{ label4, 10,2, 2,2,2,2,3,6,7,7,10,10,0,0 }, /* game */
{ label8, 7,0, 2,2,2,2,2,10,10,0,0,0,0 }, /* save/exit */
{ label9, 11,8, 2,2,2,2,2,10,10,10,10,10,10 }, /* keys */
{ labelA, 9,10, 2,2,2,2,2,10,0,0,0,0,0 }, /* give */
{ label7, 10,8, 10,10,10,10,10,10,10,10,10,0,10,10 }, /* use */
{ labelB, 10,5, 10,10,10,10,10,10,10,10,0,0,0,0 }}; /* files */
#define LMENUS 38
struct letters
{ char letter,menu,choice; }
letter_list[] = {
'I',ITEMS,5, 'T',ITEMS,6, '?',ITEMS,7, 'U',ITEMS,8, 'G',ITEMS,9,
'Y',TALK,5, 'S',TALK,6, 'A',TALK,7,
' ',GAME,5, 'M',GAME,6, 'F',GAME,7, 'Q',GAME,8, 'L',GAME,9,
'O',BUY,5, 'R',BUY,6, '8',BUY,7, 'C',BUY,8, 'W',BUY,9, 'B',BUY,10, 'E',BUY,11,
'V',SAVEX,5, 'X',SAVEX,6,
10,MAGIC,5, 11,MAGIC,6, 12,MAGIC,7, 13,MAGIC,8, 14,MAGIC,9, 15,MAGIC,10,
16,MAGIC,11,
'1',USE,0, '2',USE,1, '3',USE,2, '4',USE,3, '5',USE,4, '6',USE,5,
'7',USE,6, 'K',USE,7
};
char hit; /* which menu we hit */
/***** this section defines some variables that are used in maintaining
the playing map */
extern UBYTE place_tbl[], inside_tbl[];
extern char place_msg[], inside_msg[];
unsigned short map_x, map_y, /* absolute map coordinates in pixels */
hero_x, hero_y, /* shorthand variables for hero location */
safe_x, safe_y, safe_r, /* last 'safe zone' visited */
img_x, img_y; /* absolute sector coordinates */
/* 18 */
short cheat1;
short riding, flying, wcarry;
short turtleprox, raftprox;
short brave, luck, kind, wealth, hunger, fatigue;
/* 24 */
short brother;
short princess;
short hero_sector; /* what sector is the hero on?? */
USHORT hero_place; /* what place name is this? */
/* 8 */
USHORT daynight, lightlevel;
short actor_file, set_file; /* which actor or setfig file is loaded */
short active_carrier; /* is turtle of bird active */
USHORT xtype;
short leader; /* leader of the enemies */
short secret_timer, light_timer, freeze_timer;
short cmode;
USHORT encounter_type;
/* 28 */
USHORT pad1,pad2,pad3,pad4,pad5,pad6,pad7;
char viewstatus; /* 0 = normal, 1 = big, 99 = corrupt */
char flasher;
char actors_on_screen; /* is there anyone else on the screen?? */
char actors_loading; /* currently attempting to load actors */
char safe_flag; /* is this a safe area?? */
char battleflag; /* are we in battle? */
char frustflag; /* is the character blocked ?? */
char quitflag; /* is it time to quit?? */
char witchflag, wdir; /* is the witch on the screen */
unsigned char goodfairy; /* good fairy on screen? */
extern short s1,s2;
short nearest; /* nearest object/character to player */
short nearest_person, perdist;/* nearest character to player */
short last_person; /* last character near to player */
UBYTE witchindex;
short dayperiod;
short sleepwait;
unsigned char encounter_number, danger_level;
unsigned short encounter_x, encounter_y; /* encounter origin */
short mixflag, wt;
char *datanames[] = { "Julian","Phillip","Kevin", };
unsigned short xreg, yreg; /* where the region is */
#define TERRA_BLOCK 149
#define NO_REGION 10
#define MAP_STABLE (new_region >= NO_REGION)
#define MAP_FLUX (new_region < NO_REGION)
UWORD new_region, lregion, region_num = 3;
struct need current_loads = { 0,0,0,0, 1,2,0,0,0 };
struct need file_index[10] = {
{ 320,480,520,560, 0,1, 32,160,22 }, /* F1 - snowy region */
{ 320,360,400,440, 2,3, 32,160,21 }, /* F2 - witch wood */
{ 320,360,520,560, 2,1, 32,168,22 }, /* F3 - swampy region */
{ 320,360,400,440, 2,3, 32,168,21 }, /* F4 - plains and rocks */
{ 320,480,520,600, 0,4, 32,176, 0 }, /* F5 - desert area */
{ 320,280,240,200, 5,6, 32,176,23 }, /* F6 - bay / city / farms */
{ 320,640,520,600, 7,4, 32,184, 0 }, /* F7 - volcanic */
{ 320,280,240,200, 5,6, 32,184,24 }, /* F8 - forest and wilderness */
{ 680,720,800,840, 8,9, 96,192, 0 }, /* F9 - inside of buildings */
{ 680,760,800,840, 10,9, 96,192, 0 } /* F10 - dungeons and caves */
};
/* playing map is 6 * 19 = 114 */
extern short minimap[114];
#define MAXCOORD (16*16*128)
#define MAXMASK MAXCOORD - 1
#define SETFN(n) openflags |= n
#define TSTFN(n) openflags & n
#define QPLAN_SZ 4096 /* 1 plane of 64 chars */
#define IPLAN_SZ 16384 /* 1 plane of 256 chars */
#define IMAGE_SZ (IPLAN_SZ * 5) /* 5 planes of 256 chars - 81K */
#define SHAPE_SZ (78000)
#define SHADOW_SZ 8192+4096 /* background masks */
#define SECTOR_SZ ((128*256)+4096) /* 256 sectors - 32K+4K region map */
#define SECTOR_OFF (128*256) /* 256 sectors - 32K */
#define SAMPLE_SZ (5632) /* 5K for samples */
long LoadSeg(), seg;
struct DiskFontHeader *font;
struct TextFont *tfont, *afont;
struct TextAttr topaz_ta = { "topaz.font", 8, 0, FPF_ROMFONT };
unsigned char
*into_chip(),
*image_mem, *sector_mem, *map_mem, *shadow_mem,
*shape_mem,
*bmask_mem, *queue_mem,
*sample_mem,
*terra_mem; /* Terrain data */
#define free_chip(new,old,size) if (new!=old) FreeMem(new,size);
unsigned char *nextshape, *tempshape;
#define S_WAVBUF (128 * 8)
#define S_VOLBUF (10 * 256)
#define VOICE_SZ (S_WAVBUF + S_VOLBUF)
#define SCORE_SZ 5900
unsigned char *wavmem, *volmem, *scoremem;
short new_wave[] =
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0005,
0x0202, 0x0101, 0x0103, 0x0004, 0x0504,
0x0100, 0x0500 };
UWORD openflags;
PLANEPTR *planes;
unsigned char *mask_buffer, *shapedata;
short shift, aoff, boff, bmod, planesize, wmask;
#define CBK_SIZE (96<<6)+5
long seed1 = 19837325, seed2 = 23098324;
/* features:
1 = impassable, 2 = sink, 3 = slow/brush;
others: slippery, fiery, changing, climbable, pit trap, danger,
noisy, magnetic, stinks, slides, slopes, whirlpool, etc.
mask applications :
0 = never, 1 = when down, 2 = when right, 3 = always unless flying,
4 = only if below normal level, etc.
*/
struct in_work handler_data;
/* this function opens everything that needs to be opened */
/* allocation definitions */
#define AL_BMAP 0x0001
#define AL_GBASE 0x0002
#define AL_HANDLE 0x0004
#define AL_MUSIC 0x0008
#define AL_IMAGE 0x0010
#define AL_SECTOR 0x0020
#define AL_MASK 0x0040
#define AL_SHAPE 0x0080
#define AL_SHADOW 0x0100
#define AL_FONT 0x0200
#define AL_SAMPLE 0x0400
#define AL_PORT 0x0800
#define AL_IOREQ 0x1000
#define AL_TDISK 0x2000
#define AL_TERR 0x4000
struct BitMap *wb_bmap;
struct Layer_Info *li, /* *NewLayerInfo() */ ;
struct Process *thistask /* , *FindTask() */ ;
BPTR origDir;
int trapper();
struct IOAudio *ioaudio;
struct MsgPort *audioport;
BOOL audio_open;
struct BitMap work_bm;
open_all()
{ register long i;
long file;
openflags = 0;
if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)) == NULL) return 2;
if ((LayersBase = OpenLibrary("layers.library",0)) == NULL) return 2;
SETFN(AL_GBASE); /* opened the graphics library */
oldview = GfxBase->ActiView;
if (!MakeBitMap(&work_bm,2,640,200)) return 2;
li = NewLayerInfo();
InitRastPort(&rp_map);
InitRastPort(&rp_text);
InitRastPort(&rp_text2);
rp = &rp_text;
/* wb_bmap = oldview->ViewPort->RasInfo->BitMap; */ /* workbench bitmap */
wb_bmap = &work_bm;
rp_text.BitMap = wb_bmap; /* workbench screen (not!) */
SetBPen(rp,0);
SetDrMd(rp,JAM2);
SetRast(rp,0); /* clear workbench screen (not!) */
if ((bm_page1 =
(struct BitMap *)AllocMem(5*BM_SIZE,MEMF_CHIP | MEMF_CLEAR)) == NULL )
return 1;
SETFN(AL_BMAP); /* allocated the bitmap structures */
if (i = AllocDiskIO()) return i;
#if 0
if ((diskport = CreatePort(0,0))==0) return 30;
SETFN(AL_PORT);
if ((diskreq1=(struct IOExtTD *)CreateExtIO(diskport,sizeof(struct IOExtTD)))==0) return 31;
SETFN(AL_IOREQ);
if (OpenDevice(TD_NAME,0,(struct IORequest *)diskreq1,0)) return 32;
SETFN(AL_TDISK);
for (i=0; i<9; i++)
{ diskreqs[i] = *diskreq1;
}
#endif
if ((seg = LoadSeg("fonts/Amber/9")) == NULL) return 15;
font = (struct DiskFontHeader *) ((seg<<2)+8);
SETFN(AL_FONT); /* opened the font */
tfont = OpenFont(&topaz_ta);
SetFont(&rp_text,tfont);
SetFont(&rp_text2,tfont);
SetFont(&rp_map,tfont);
afont = &(font->dfh_TF);
/* add the input handler */
handler_data.xsprite = handler_data.ysprite = 320;
handler_data.gbase = GfxBase;
handler_data.pbase = 0;
if (add_device() == FALSE) return 4;
thistask = (struct Process *)FindTask(0);
thistask->pr_WindowPtr = (APTR)-1;
thistask->pr_Task.tc_TrapCode = (APTR)trapper;
/* set trap handler */
SETFN(AL_HANDLE);
FreeSprite(0);
GetSprite(&pointer,0); /* test for error */
InitView(&v); /* initialize view */
InitVPort(&vp_page); /* init view ports */
InitVPort(&vp_text); /* text page */
v.ViewPort = &vp_text; /* link view into viewport */
vp_text.Next = &vp_page; /* make links to additional viewports */
vp_page.Next = NULL;
vp_page.DWidth = 288; /* lo-res screen is 36 bytes wide */
vp_text.DWidth = 640; /* hi-res screen */
vp_page.DxOffset = 16;
vp_page.DyOffset = vp_text.DxOffset = 0;
vp_page.DHeight = 140;
vp_text.DyOffset = PAGE_HEIGHT;
vp_text.DHeight = TEXT_HEIGHT; /* make bigger later */
vp_text.Modes = HIRES | SPRITES | VP_HIDE;
/* init bit map (for rasinfo and rastport) */
bm_page2 = bm_page1 + 1;
bm_text = bm_page1 + 2;
bm_source = bm_page1 + 3;
bm_lim = bm_page1 + 4;
InitBitMap(bm_page1,PAGE_DEPTH,PHANTA_WIDTH,RAST_HEIGHT);
InitBitMap(bm_page2,PAGE_DEPTH,PHANTA_WIDTH,RAST_HEIGHT);
InitBitMap(bm_text,4,640,TEXT_HEIGHT);
InitBitMap(bm_lim,1,320,200);
InitBitMap(&pagea,5,320,200);
InitBitMap(&pageb,5,320,200);
InitBitMap(&bm_scroll,1,640,TEXT_HEIGHT);
InitBitMap(bm_source,3,64,24);
rp_text2.BitMap = bm_text;
/* (init RasInfo) */
ri_page1.BitMap = bm_page1;
ri_page2.BitMap = bm_page2;
ri_page1.RxOffset = ri_page2.RxOffset =
ri_page1.RyOffset = ri_page2.RyOffset = 0;
ri_page1.Next = ri_page2.Next = NULL;
ri_text.BitMap = bm_text;
ri_text.RxOffset = ri_text.RyOffset = 0;
ri_text.Next = NULL;
fp_page1.savecop = fp_page2.savecop = NULL;
fp_page1.ri_page = &ri_page1;
fp_page2.ri_page = &ri_page1;
fp_drawing = &fp_page1; fp_viewing = &fp_page2;
/* (init color table) */
vp_page.ColorMap = GetColorMap(32);
vp_text.ColorMap = GetColorMap(20);
/* reset all plane pointers */
for (i=0; i<5; i++) bm_page1->Planes[i] = bm_page2->Planes[i] = NULL;
/* allocate space for bitmap */
for (i=0; i<5; i++)
{ bm_page1->Planes[i] = AllocRaster(PHANTA_WIDTH,RAST_HEIGHT);
if(bm_page1->Planes[i] == NULL) return 4;
bm_page2->Planes[i] = AllocRaster(PHANTA_WIDTH,RAST_HEIGHT);
if(bm_page2->Planes[i] == NULL) return 5;
}
bm_text->Planes[0] = wb_bmap->Planes[0];
bm_text->Planes[1] = wb_bmap->Planes[1];
bm_text->Planes[2] = bm_text->Planes[0] + (TEXT_HEIGHT*80);
bm_text->Planes[3] = bm_text->Planes[1] + (TEXT_HEIGHT*80);
queue_mem = bm_text->Planes[2] + (TEXT_HEIGHT*80);
bmask_mem = bm_text->Planes[3] + (TEXT_HEIGHT*80);
fp_page1.backsave = queue_mem + 962;
fp_page2.backsave = bmask_mem + 962;
fp_page1.shape_queue = (struct sshape *) queue_mem;
fp_page2.shape_queue = (struct sshape *)
(queue_mem + ((sizeof (struct sshape))*MAXSHAPES));
vp_text.RasInfo = &ri_text;
MakeVPort( &v, &vp_text );
if (audioport = CreatePort(NULL,0))
{
if (ioaudio = (struct IOAudio *)CreateExtIO(audioport,sizeof *ioaudio))
{ UBYTE data = 0x0f;
ioaudio->ioa_Data = &data;
ioaudio->ioa_Length = 1;
if (!OpenDevice("audio.device", 0L, &ioaudio->ioa_Request,0L))
{
ioaudio->ioa_Request.io_Command = CMD_RESET;
ioaudio->ioa_Request.io_Flags = IOF_QUICK;
BeginIO(&ioaudio->ioa_Request);
if ( !(ioaudio->ioa_Request.io_Flags & IOF_QUICK) )
WaitIO(&ioaudio->ioa_Request);
audio_open = 1;
}
}
}
if ((wavmem = AllocMem(VOICE_SZ,MEMF_CHIP)) == NULL) return 16;
if ((scoremem = AllocMem(SCORE_SZ,0)) == NULL) return 17;
volmem = wavmem + S_WAVBUF;
init_music(new_wave,wavmem,volmem);
SETFN(AL_MUSIC);
if ((image_mem = AllocMem(IMAGE_SZ,MEMF_CHIP)) == NULL) return 6;
SETFN(AL_IMAGE);
if ((sector_mem = AllocMem(SECTOR_SZ,MEMF_CHIP)) == NULL) return 7;
map_mem = sector_mem + SECTOR_OFF;
SETFN(AL_SECTOR);
if ((shape_mem = AllocMem(SHAPE_SZ,MEMF_CHIP)) == NULL) return 8;
SETFN(AL_SHAPE);
if ((shadow_mem = AllocMem(SHADOW_SZ,MEMF_CHIP)) == NULL) return 10;
SETFN(AL_SHADOW);
if ((sample_mem = AllocMem(SAMPLE_SZ,MEMF_CHIP)) == NULL) return 11;
SETFN(AL_SAMPLE);
if ((terra_mem = AllocMem(1024,MEMF_CHIP)) == NULL) return 34;
SETFN(AL_TERR);
if (file = Open("v6",1005))
{ Read(file,wavmem,S_WAVBUF);
Seek(file,S_WAVBUF,0);
Read(file,volmem,S_VOLBUF);
Close(file);
}
bm_scroll.Planes[0] = bm_text->Planes[0];
sprite_data = (long *)into_chip((void *)_sprite_data,88);
ChangeSprite(&vp_text,&pointer,(void *)sprite_data);
handler_data.vbase = &vp_text;
nhinor = into_chip(&hinor,(16*16));
nhivar = into_chip(&hivar,(16*16));
return 0;
}
close_all()
{ register long i;
if (TSTFN(AL_TERR)) FreeMem(terra_mem,1024);
if (TSTFN(AL_SAMPLE)) FreeMem(sample_mem,SAMPLE_SZ);
if (TSTFN(AL_SHADOW)) FreeMem(shadow_mem,SHADOW_SZ);
if (TSTFN(AL_SHAPE)) FreeMem(shape_mem,SHAPE_SZ);
if (TSTFN(AL_SECTOR)) FreeMem(sector_mem,SECTOR_SZ);
if (TSTFN(AL_IMAGE)) FreeMem(image_mem,IMAGE_SZ);
if (TSTFN(AL_MUSIC))
{ wrap_music(); FreeMem(wavmem,VOICE_SZ); FreeMem(scoremem,SCORE_SZ); }
free_chip(sprite_data,_sprite_data,88);
free_chip(nhinor,&hinor,(16*16));
free_chip(nhivar,&hivar,(16*16));
LoadView(oldview);
FreeVPortCopLists(&vp_page);
FreeVPortCopLists(&vp_text);
FreeCprList(fp_page1.savecop);
FreeCprList(fp_page2.savecop);
FreeCprList(v.SHFCprList);
if (vp_page.ColorMap) FreeColorMap(vp_page.ColorMap);
if (vp_text.ColorMap) FreeColorMap(vp_text.ColorMap);
for(i=0; i<PAGE_DEPTH; i++)
if (bm_page1->Planes[i])
FreeRaster(bm_page1->Planes[i],PHANTA_WIDTH,RAST_HEIGHT);
for(i=0; i<PAGE_DEPTH; i++)
if (bm_page2->Planes[i])
FreeRaster(bm_page2->Planes[i],PHANTA_WIDTH,RAST_HEIGHT);
if (audio_open) CloseDevice(&ioaudio->ioa_Request);
if (ioaudio) DeleteExtIO(&ioaudio->ioa_Request);
if (audioport) DeletePort(audioport);
if (TSTFN(AL_HANDLE)) wrap_device();
if (TSTFN(AL_FONT)) { UnLoadSeg(seg); CloseFont(tfont); }
#if 0
if (TSTFN(AL_TDISK)) CloseDevice((struct IORequest *)diskreq1);
if (TSTFN(AL_IOREQ)) DeleteExtIO((struct IORequest *)diskreq1);
if (TSTFN(AL_PORT)) DeletePort(diskport);
#endif
FreeDiskIO();
if (TSTFN(AL_GBASE)) { CloseLibrary((struct Library *)GfxBase); CloseLibrary(LayersBase); }
if (TSTFN(AL_BMAP)) FreeMem(bm_page1,5*BM_SIZE);
if (TSTFN(AL_BMAP)) UnMakeBitMap(&work_bm);
DisposeLayerInfo(li);
FreeSprite(0);