forked from viridia/faery-tale-amiga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmain2.c
1723 lines (1485 loc) · 41.5 KB
/
fmain2.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 "exec/types.h"
#include "exec/memory.h"
#include "graphics/gfxbase.h"
#include "graphics/rastport.h"
#include "graphics/clip.h"
#include "graphics/layers.h"
#include "graphics/view.h"
#include "libraries/dos.h"
#include "libraries/dosextens.h"
#include "devices/trackdisk.h"
#include "ftale.h"
#define NO_PROTECT
extern unsigned short xreg, yreg; /* where the region is */
#asm
; shape structure - anim_list
abs_x equ 0 ; short
abs_y equ 2
rel_x equ 4
rel_y equ 6
type equ 8
race equ 9
index equ 10
visible equ 11
weapon equ 12
environ equ 13
goal equ 14
tactic equ 15
state equ 16
facing equ 17
vitality equ 18
vel_x equ 20
vel_y equ 21
l_shape equ 22
#endasm
extern struct shape anim_list[20];
extern short anix, anix2;
extern USHORT hero_x, hero_y, map_x, map_y;
/* motion states */
#define WALKING 12
#define STILL 13
#define FIGHTING 0
#define DYING 14
#define DEAD 15
/* asm */
char com2[9] = { 0,1,2,7,9,3,6,5,4 };
/*set_course(object,target_x,target_y,mode)
unsigned short object, target_x, target_y, mode;
{ short xdif, ydif, deviation, j;
register long xabs, yabs, xdir, ydir;
; */
#asm
com2 dc.b 0,1,2,7,9,3,6,5,4,0
public _set_course
_set_course
movem.l d0-d7/a0-a1,-(sp)
move.l 40+4(sp),d2 ; object #
move.l 40+8(sp),d0 ; target x
move.l 40+12(sp),d1 ; target_y
move.l 40+16(sp),d3 ; mode
lea _anim_list,a1 ; start of anim_list
mulu.w #l_shape,d2 ; object # times length of struct
add.l d2,a1 ; a1 = start of anim_list[object]
; if (mode == 6) { xdif = target_x; ydif = target_y; }
cmp.b #6,d3 ; if mode != 6
beq.s 1$ ; calculate offset normally
; else
; { xdif = anim_list[object].abs_x - target_x;
; ydif = anim_list[object].abs_y - target_y;
; }
neg.w d0 ; d0 = -target_x
neg.w d1 ; d1 = -target_y
add.w abs_x(a1),d0 ; d0 = x difference
add.w abs_y(a1),d1 ; d1 = y difference
1$
; xabs = yabs = xdir = ydir = 0;
clr.l d6 ; xdir = 0;
clr.l d7 ; ydir = 0;
; if (xdif > 0) { xabs = xdif; xdir = 1; }
tst.w d0 ; if (xdif > 0)
beq 3$ ; if xdif = 0, do nothing
bmi 2$ ; if xdif < 0
moveq #1,d6 ; xdir = 1; xabs = xdif
bra 3$
; if (xdif < 0) { xabs = -xdif; xdir = -1; }
2$ neg.w d0 ; xabs = -xdif
moveq #-1,d6 ; xdir = -1;
3$
; if (ydif > 0) { yabs = ydif; ydir = 1; }
tst.w d1 ; if (ydif > 0)
beq 5$ ; if ydif = 0, do nothing
bmi 4$ ; if ydif < 0
moveq #1,d7 ; ydir = 1; yabs = ydif
bra 5$
; if (ydif < 0) { yabs = -ydif; ydir = -1; }
4$ neg.w d1 ; yabs = -ydif
moveq #-1,d7 ; ydir = -1;
5$
; if (mode != 4)
cmp.b #4,d3 ; if mode 4
beq 6$ ; then don't do
; { if ((xabs>>1) > yabs) ydir = 0; /* if SMART_SEEK */
move.w d0,d4 ; copy xabs
lsr.w #1,d4 ; d4 = xabs >> 1
cmp.w d4,d1 ; if (xabs>>1) > yabs
bge.s 55$
clr.l d7
55$
; if ((yabs>>1) > xabs) xdir = 0;
move.w d1,d4 ; copy yabs
lsr.w #1,d4 ; d4 = yabs >> 1
cmp.w d4,d0 ; if (yabs>>1) > xabs
bge.s 6$
clr.l d6 ; xdir = 0
6$
; }
; deviation = 0;
clr.l d4 ; d4 = deviation = 0
; if (mode==1 && (xabs+yabs) < 40) deviation = 1;
move.w d0,d5 ; d5 = xabs
add.w d1,d5 ; d5 = xabs + yabs
cmp.b #1,d3 ; if (mode == 1)
bne.s 7$
cmp.w #40,d5 ; and (dist < 40)
bge.s 7$
moveq #1,d4 ; deviation = 1;
7$
; else if (mode==2 && (xabs+yabs) < 30) deviation = 2;
cmp.b #2,d3 ; if (mode == 2)
bne.s 8$
cmp.w #30,d5 ; and (dist < 30)
bge.s 8$
moveq #1,d4 ; deviation = 1;
8$
; else if (mode==3) { xdir = -xdir; ydir = -ydir; }
cmp.b #3,d3
bne.s 81$
neg.b d6 ; xdir = -xdir;
neg.b d7 ; ydir = -ydir
; j = com2[4 - ydir - ydir - ydir - xdir];
81$
moveq #4,d5 ; d4 = 4
sub.b d7,d5
sub.b d7,d5
sub.b d7,d5
sub.b d6,d5 ; d4 - 4 - ydir - ydir - ydir - xdir
lea com2(pc),a0
move.b (a0,d5.w),d5 ; d5 = j = com2[d5]
****
; if (j == 9) anim_list[object].state = STILL;
cmp.b #9,d5
bne.s 9$
move.b #13,state(a1) ; #STILL -> anim_list[object].state
bra 99$
9$
; else
; { if (rand()&1) j += deviation; else j -= deviation;
jsr _rand ; go left or right
btst #1,d0 ; test a bit
beq 10$
add.b d4,d5 ; j += deviation
bra 11$
10$ sub.b d4,d5 ; j -= deviation
; anim_list[object].facing = j & 7;
11$ and.b #7,d5 ; and j with 7
move.b d5,facing(a1) ; move to facing
; if (mode != 5) anim_list[object].state = WALKING;
cmp.b #5,d3 ; if mode != 5
beq 99$ ; move #WALKING to state
move.b #12,state(a1)
99$ movem.l (sp)+,d0-d7/a0-a1
rts
#endasm
/* a hit, a palpable hit! */
#define FLEE 5 /* run directly away */
extern char *stuff;
dohit(i,j,fc,wt) short wt; register long j,i,fc;
{ if (anim_list[0].weapon < 4 &&
(anim_list[j].race == 9 ||
(anim_list[j].race == 0x89 && stuff[7] == 0) ))
{ speak(58); return; }
if (anim_list[j].race == 0x8a || anim_list[j].race == 0x8b) return;
anim_list[j].vitality -= wt; /* Ow, that hurt! */
if (anim_list[j].vitality < 0) anim_list[j].vitality = 0;
if (i==-1) effect(2,500+rand64());
else if (i==-2) effect(5,3200+bitrand(511));
else if (j==0) effect(0,800+bitrand(511));
else effect(3,400+rand256());
/* push back the foe!! Yar! */
if (anim_list[j].type != DRAGON && anim_list[j].type != SETFIG
&& move_figure(j,fc,2) && (i >= 0))
move_figure(i,fc,2);
checkdead(j,5);
}
extern short nearest;
extern short xtype;
char turtle_eggs;
aftermath()
{ register long dead, flee, i, j;
dead = flee = 0;
for (i=3; i<anix; i++)
{ if (anim_list[i].type != ENEMY) ;
else if (anim_list[i].state == DEAD) dead++;
else if (anim_list[i].goal == FLEE) flee++;
}
if (anim_list[0].vitality < 1) ; /* if dead, no message */
else if (anim_list[0].vitality < 5 && dead) print("Bravely done!");
else if (xtype < 50)
{ if (dead) /* foes??? what are their names?? */
{ print(""); prdec(dead,1);
print_cont("foes were defeated in battle.");
}
if (flee)
{ print(""); prdec(flee,1);
print_cont("foes fled in retreat.");
}
}
/* check for presence of turtle eggs */
if (turtle_eggs) get_turtle();
}
proxcheck(x,y,i) short x,y,i;
{ register long x1, y1;
register long j;
if (anim_list[i].type != ENEMY || anim_list[i].race != 2) /* wraith */
{ x1=prox(x,y);
if (i==0 && (x1 == 8 || x1 == 9)) x1 = 0;
if (x1) return x1;
}
for (j=0; j<anix; j++)
{ if (i != j && j != 1 && anim_list[j].type != 5
&& anim_list[j].state != DEAD) /* can walk over dead and rafts */
{ x1 = x - anim_list[j].abs_x;
y1 = y - anim_list[j].abs_y;
if (x1 < 11 && x1 > -11 && y1 < 9 && y1 > -9) return 16;
}
}
return 0;
}
nearest_fig(constraint,dist) char constraint; short dist;
{ register long d,i;
nearest = 0;
for (i=1; i<anix2; i++)
{ if (anim_list[i].type == OBJECTS &&
(constraint || anim_list[i].index == 0x1d)) continue;
d = calc_dist(i,0);
if (d<dist) { nearest = i; dist = d; }
}
return dist;
}
/* asm */
calc_dist(a,b) register long a,b;
{ register long x,y; short dist;
x = anim_list[a].abs_x - anim_list[b].abs_x; if (x<0) x = -x;
y = anim_list[a].abs_y - anim_list[b].abs_y; if (y<0) y = -y;
if (x>(y+y)) return x;
if (y>(x+x)) return y;
return (x+y)*5/7;
}
/* asm */
move_figure(fig,dir,dist) short fig,dir,dist;
{ register unsigned short xtest,ytest;
xtest = newx(anim_list[fig].abs_x,dir,dist);
ytest = newy(anim_list[fig].abs_y,dir,dist);
if (proxcheck(xtest,ytest,fig)) return FALSE;
anim_list[fig].abs_x = xtest;
anim_list[fig].abs_y = ytest;
return TRUE;
}
struct compvars {
UBYTE xrect, yrect;
UBYTE xsize, ysize;
} comptable[10] = {
{ 0, 0, 16,8 },
{ 16, 0, 16,9 },
{ 32, 0, 16,8 },
{ 30, 8, 18,8 },
{ 32,16, 16,8 },
{ 16,13, 16,11 },
{ 0,16, 16,8 },
{ 0, 8, 18,8 },
{ 0, 0, 1,1 },
{ 0, 0, 1,1 }
};
extern UBYTE *nhinor, *nhivar;
extern struct BitMap *bm_text, *bm_source;
drawcompass(dir) short dir;
{ register long xr, yr, xs, ys;
xr = comptable[dir].xrect;
yr = comptable[dir].yrect;
xs = comptable[dir].xsize;
ys = comptable[dir].ysize;
bm_source->Planes[2] = nhinor;
BltBitMap(bm_source,0,0,bm_text,567,15,48,24,0xC0,4,NULL);
if (dir < 9)
{ bm_source->Planes[2] = nhivar;
BltBitMap(bm_source,xr,yr,bm_text,567+xr,15+yr,xs,ys,0xC0,4,NULL);
}
}
USHORT fader[32];
USHORT pagecolors [] = {
0x0000,0x0FFF,0x0E96,0x0B63,0x0631,0x07BF,0x0333,0x0DB8,
0x0223,0x0445,0x0889,0x0BBC,0x0521,0x0941,0x0F82,0x0FC7,
0x0040,0x0070,0x00B0,0x06F6,0x0005,0x0009,0x000D,0x037F,
0x0C00,0x0F50,0x0FA0,0x0FF6,0x0EB6,0x0EA5,0x000F,0x0BDF };
extern short secret_timer, light_timer, freeze_timer;
struct ViewPort vp_page;
extern UWORD region_num, new_region;
fade_page(r,g,b,limit,colors) short r,g,b,limit; USHORT *colors;
{ register long r1,b1,g1,g2;
short i;
if (region_num == 4) pagecolors[31] = 0x0980;
else if (region_num == 9)
{ if (secret_timer) pagecolors[31] = 0x00f0;
else pagecolors[31] = 0x0445;
}
else pagecolors[31] = 0x0bdf;
if (r>100) r = 100;
if (g>100) g = 100;
if (b>100) b = 100;
if (limit)
{ if (r<10) r=10; /* night limits */
if (g<25) g=25;
if (b<60) b=60;
g2 = (100-g)/3;
}
else
{ if (r<0) r = 0;
if (g<0) g = 0;
if (b<0) b = 0;
g2 = 0;
}
for (i=0; i<32; i++)
{ r1 = (colors[i] & 0x0f00)>>4;
g1 = colors[i] & 0x00f0;
b1 = colors[i] & 0x000f;
if (light_timer && (r1 < g1)) r1 = g1;
r1 = (r * r1)/1600;
g1 = (g * g1)/1600;
b1 = (b * b1 + (g2*g1))/100;
if (limit)
{ if (i>= 16 && i<= 24 && g > 20)
{ if (g < 50) b1+=2; else if (g < 75) b1++; }
if (b1 > 15) b1 = 15;
}
fader[i]=(r1<<8)+(g1<<4)+b1;
}
LoadRGB4(&vp_page,fader,32);
}
extern struct RastPort *rp;
/* asm */
colorplay() /* teleport effect */
{ register long i,j;
for (j=0; j<32; j++)
{ for (i=1; i<32; i++) fader[i]=bitrand(0xfff);
LoadRGB4(&vp_page,fader,32);
Delay(1);
}
}
char print_que[32];
short prec=0, pplay=0;
extern short brave, luck, kind, wealth, hero_sector;
SHORT sg1, sg2;
short db1, db2;
ppick()
{ register long p;
if (prec == pplay) Delay(1);
else
{ p = print_que[pplay];
pplay = (pplay + 1) & 31;
switch (p) {
case 2: print("Coords = "); prdec(hero_x,6); prdec(hero_y,6);
print("Memory Available: "); prdec(AvailMem(0),6);
break;
case 3: print("You are at: ");
prdec(hero_x/256,3); prdec(hero_y/256,3);
print("H/Sector = "); prdec(hero_sector,3);
text(" Extent = ",10); prdec(xtype,2);
break;
case 4: move(245,52);
text("Vit:",4); prdec(anim_list[0].vitality,3);
break;
case 5: print_options(); break;
case 7: if (luck < 0) luck = 0;
move(14,52); text("Brv:",4);prdec(brave,3);
move(90,52); text("Lck:",4);prdec(luck,3);
move(168,52); text("Knd:",4);prdec(kind,3);
move(321,52); text("Wlth:",5);prdec(wealth,3);
break;
case 10: print("Take What?"); break;
}
}
}
#asm
public _prec,_pplay,_print_que,_prq
_prq
movem.l d0/d1/a1,-(sp)
move.w _prec,d0
move.w _pplay,d1
addq #1,d0
and.w #31,d0
cmp.w d0,d1
beq.s prqx
move.w _prec,d1
move.w d0,_prec
lea _print_que,a1
move.b 3+4+12(sp),(a1,d1)
prqx movem.l (sp)+,d0/d1/a1
rts
#endasm
#define TXMIN 16
#define TXMAX 400
#define TYMIN 5
#define TYMAX 44
print(str) register char *str;
{ register long l;
l = 0; while (str[l]) l++;
ScrollRaster(rp,0,10,TXMIN,TYMIN,TXMAX,TYMAX);
move(TXMIN,42);
text(str,l);
}
print_cont(str) register char *str;
{ register long l = 0;
while (str[l]) l++;
text(str,l);
}
#define MLEN 35
char *mbuf, mesbuf[200];
extern char *datanames[];
extern short brother;
extract(start) register char *start;
{ register char *ss, *lbreak;
char *lstart, c; short i;
lstart = mbuf = mesbuf;
i = 0;
while (TRUE)
{ lbreak = 0; /* end of current line */
for ( ; i<37; i++)
{ c = *start++;
if (c == ' ') lbreak = mbuf;
if (c == 0) { lbreak = mbuf; *lbreak = 0; i=1000; }
if (c == 13) { lbreak = mbuf; *lbreak = 0; break; }
if (c == '%')
{ ss = datanames[brother-1];
while (*ss) { *mbuf++ = *ss++; i++; }
}
else *mbuf++ = c;
}
if (lbreak) /* found wrap point */
{ *lbreak++ = 0; /* end the line */
print(lstart); /* print it */
if (i > 38) break;
i = mbuf - lbreak;
lstart = lbreak;
}
else
{ *mbuf++ = 0; /* no wrap point so just print it */
if (i > 38) break;
print (lstart);
i = 0;
lstart = mbuf;
}
}
}
#asm
;msg(start,num) register char *start; register long num;
;{ while (num) if (*start++ == 0) num--;
; extract(start);
;}
public _event,_speak,_msg,_event_msg,_speeches
_event
lea _event_msg,a0
move.l 4(sp),d0
bra msg1
_speak
lea _speeches,a0
move.l 4(sp),d0
bra msg1
_msg
move.l 4(sp),a0
move.l 8(sp),d0
msg1 beq msgx
1$ tst.b (a0)+
bne.s 1$
subq.w #1,d0
bne.s 1$
msgx move.l a0,4(sp)
bra _extract
#endasm
announce_container(s) char *s;
{ print(datanames[brother-1]);
print_cont(" found ");
print_cont(s);
print_cont(" containing ");
}
announce_treasure(s) char *s;
{ print(datanames[brother-1]);
print_cont(" found ");
print_cont(s);
}
name()
{ print_cont(datanames[brother-1]); }
extern struct RastPort rp_map, rp_text;
extern struct ViewPort vp_page, vp_text;
extern struct BitMap *bm_draw;
extern struct fpage *fp_drawing, *fp_viewing;
extern char viewstatus;
map_message()
{ fade_down();
rp = &rp_map;
rp_map.BitMap = fp_drawing->ri_page->BitMap;
SetDrMd(rp,JAM1);
SetAPen(rp,24);
SetRast(rp,0);
vp_text.Modes = HIRES | SPRITES | VP_HIDE;
stillscreen();
LoadRGB4(&vp_page,pagecolors,32);
viewstatus = 2;
}
message_off()
{ fade_down();
rp = &rp_text;
vp_text.Modes = HIRES | SPRITES;
pagechange();
viewstatus = 3;
}
fade_down()
{ register long i;
for (i=100; i>=0; i-=5) { fade_page(i,i,i,FALSE,pagecolors); Delay(1); } }
fade_normal()
{ register long i;
for (i=0; i<=100; i+=5) { fade_page(i,i,i,FALSE,pagecolors); Delay(1); } }
stillscreen()
{ fp_drawing->ri_page->RxOffset = fp_drawing->ri_page->RyOffset = 0;
pagechange();
}
extern struct seq_info seq_list[];
struct cfile_info {
UBYTE width, height, count; /* size of character set */
UBYTE numblocks; /* number of block to load in */
UBYTE seq_num; /* which seq_list slot to load into */
USHORT file_id;
} cfiles[] = {
{ 1,32,67, 42, PHIL, 1376 }, /* julian */
{ 1,32,67, 42, PHIL, 1418 }, /* phillip */
{ 1,32,67, 42, PHIL, 1460 }, /* kevin */
{ 1,16,116,36,OBJECTS,1312 }, /* objects */
{ 2,32, 2, 3, RAFT, 1348 }, /* raft */
{ 2,32,16, 20,CARRIER,1351 }, /* turtle */
{ 1,32,64, 40, ENEMY, 960 }, /* ogre file */
{ 1,32,64, 40, ENEMY, 1080 }, /* ghost file */
{ 1,32,64, 40, ENEMY, 1000 }, /* dknight file (spiders) */
{ 1,32,64, 40, ENEMY, 1040 }, /* necromancer (farmer / loraii) */
{ 3,40, 5, 12, DRAGON,1160 }, /* dragon */
{ 4,64, 8, 40,CARRIER,1120 }, /* bird */
{ 1,32,64, 40, ENEMY, 1376 }, /* snake and salamander */
{ 1,32, 8, 5,SETFIG, 936 }, /* wizard/priest */
{ 1,32, 8, 5,SETFIG, 931 }, /* royal set */
{ 1,32, 8, 5,SETFIG, 941 }, /* bartender */
{ 1,32, 8, 5,SETFIG, 946 }, /* witch */
{ 1,32, 8, 5,SETFIG, 951 }, /* ranger/begger */
};
#define SHAPE_SZ (78000) /* 73K for now */
extern unsigned char *shape_mem, *nextshape;
extern unsigned short safe_r;
extern short actor_file, set_file;
shape_read()
{ nextshape = shape_mem;
read_shapes(3); prep(OBJECTS);
read_shapes(brother-1); prep(PHIL);
read_shapes(4); prep(RAFT);
seq_list[ENEMY].location = nextshape;
read_shapes(actor_file); prep(cfiles[actor_file].seq_num);
read_shapes(set_file); prep(SETFIG);
new_region = region_num; load_all();
motor_off();
}
read_shapes(num) register long num;
{ long size; register long slot;
slot = cfiles[num].seq_num;
seq_list[slot].bytes = cfiles[num].height * cfiles[num].width * 2;
size = seq_list[slot].bytes * cfiles[num].count;
seq_list[slot].location = nextshape;
seq_list[slot].width = cfiles[num].width;
seq_list[slot].height = cfiles[num].height;
seq_list[slot].count = cfiles[num].count;
if ((nextshape + (size*6)) <= (shape_mem + SHAPE_SZ))
{ load_track_range(cfiles[num].file_id,
cfiles[num].numblocks,nextshape,8);
nextshape += size*5;
seq_list[slot].maskloc = nextshape;
nextshape += size;
}
}
#if 0
extern struct IOExtTD *lastreq, diskreqs[10], *diskreq1;
load_track_range(f_block,b_count,buffer,dr)
short f_block, b_count, dr; APTR buffer;
{ short error;
lastreq = &(diskreqs[dr]);
if (lastreq->iotd_Req.io_Command == CMD_READ) WaitIO((struct IORequest *)lastreq);
*lastreq = *diskreq1;
lastreq->iotd_Req.io_Length = b_count * 512;
lastreq->iotd_Req.io_Data = buffer;
lastreq->iotd_Req.io_Command = CMD_READ;
lastreq->iotd_Req.io_Offset = f_block * 512;
SendIO((struct IORequest *)lastreq);
}
motor_off()
{ diskreqs[9] = *diskreq1;
diskreqs[9].iotd_Req.io_Length = 0;
diskreqs[9].iotd_Req.io_Command = TD_MOTOR;
DoIO((struct IORequest *)&diskreqs[9]);
}
#endif
seekn()
{ cpytest();
/* diskreqs[9] = *diskreq1 */ ;
/* diskreqs[9].iotd_Req.io_Length = 512;
diskreqs[9].iotd_Req.io_Data = (APTR)shape_mem;
diskreqs[9].iotd_Req.io_Offset = 0;
diskreqs[9].iotd_Req.io_Command = CMD_READ;
DoIO(&(diskreqs[9]));
prot2();
motor_off(); */
}
prep(slot) short slot;
{
WaitDiskIO(8); /* WaitIO((struct IORequest *)&diskreqs[8]); */
InvalidDiskIO(8); /* diskreqs[8].iotd_Req.io_Command = CMD_INVALID; */
make_mask(seq_list[slot].location,seq_list[slot].maskloc,
seq_list[slot].width,seq_list[slot].height,seq_list[slot].count);
}
load_next()
{ if (!IsReadLastDiskIO() || CheckLastDiskIO())
/* if (lastreq->iotd_Req.io_Command != CMD_READ || CheckIO((struct IORequest *)lastreq)) */
load_new_region();
}
extern unsigned char *(track[32]), *scoremem;
read_score()
{ long file;
long packlen, sc_load, sc_count;
register long i;
sc_load = sc_count = 0;
if (file = Open("songs",1005))
{ for (i=0; i<(4*7); i++)
{ Read(file,&packlen,4);
if ((packlen*2 + sc_load) > 5900) break;
track[sc_count] = scoremem + sc_load;
sc_count++;
Read(file,scoremem+sc_load,packlen*2);
sc_load += (packlen*2);
}
Close(file);
}
}
char skipp;
extern struct BitMap pagea, pageb;
copypage(br1,br2,x,y) char *br1, *br2; short x,y;
{ if (skipp) return;
Delay(350);
BltBitMap(&pageb,0,0,&pagea,0,0,320,200,0xC0,0x1f,0);
unpackbrush(br1,&pageb,4,24);
unpackbrush(br2,&pageb,x,y);
if (skipint()) return;
flipscan();
skipint();
}
char flip1[] = { 8,6,5,4,3,2,3,5,13,0,0, 13,5,3,2,3,4,5,6,8,0,0 };
char flip2[] = { 7,5,4,3,2,1,1,1, 1,0,0, 1,1,1,1,2,3,4,5,7,0,0 };
char flip3[] = {12,9,6,3,0,0,0,0, 0,0,0, 0,0,0,0,0,0,3,6,9,0,0 };
flipscan()
{ short i, scol, h; register long bcol, dcol, rate, wide;
struct BitMap *temp;
for (i=0; i<22; i++)
{ temp = fp_drawing->ri_page->BitMap;
dcol = 0;
rate = flip1[i];
wide = flip2[i];
if (i<11)
{ bcol = 161-wide;
BltBitMap(&pageb,160,0,temp,160,0,135,200,0xC0,0x1f,0);
if (rate == 0) goto lab1;
for (scol=wide; scol<136; scol+=rate)
{ h = page_det(scol);
BltBitMap(&pagea,bcol+scol,h,temp,161+dcol,h,wide,200-h-h,0xC0,0x1f,0);
dcol+=wide;
}
BltBitMap(&pagea,296,7,temp,161+dcol,h,1,186,0xC0,0x1f,0);
}
else
{ bcol = 160;
if (rate == 0)
{ BltBitMap(&pageb,24,0,temp,24,0,135,200,0xC0,0x1f,0);
goto lab1;
}
BltBitMap(&pagea,24,0,temp,24,0,135,200,0xC0,0x1f,0);
for (scol=wide; scol<136; scol+=rate)
{ h = page_det(scol);
dcol+=wide;
BltBitMap(&pageb,bcol-scol,h,temp,bcol-dcol,h,wide,200-h-h,0xC0,0x1f,0);
}
scol = 135; h = 7;
BltBitMap(&pageb,24,h,temp,159-dcol,h,1,200-h-h,0xC0,0x1f,0);
}
lab1: pagechange();
if (flip3[i]) Delay(flip3[i]);
}
}
skipint()
{ return skipp = (getkey()==' ');}
/* UBYTE *AllocMem(); */
UBYTE *into_chip(oldpointer,size) register UBYTE *oldpointer; long size;
{ register UBYTE *newpointer; register long i;
if (TypeOfMem(oldpointer) & MEMF_CHIP) return oldpointer;
newpointer = AllocMem(size,MEMF_CHIP);
for (i=0; i<size; i++) newpointer[i] = *oldpointer++;
return newpointer;
}
char jtrans[] = { 0,3, 8,10, 11,15, 1,30, 2,45, 3,75, 13,20 };
char treasure_probs[] = {
0, 0, 0, 0, 0, 0, 0, 0, /* no treasure */
9,11,13,31,31,17,17,32, /* stone,vial,totem,gold,keys */
12,14,20,20,20,31,33,31, /* keys,skull,gold,nothing */
10,10,16,16,11,17,18,19, /* magic and keys */
15,21,0,0,0,0,0,0 /* jade skull and white key */
};
char weapon_probs[] = {
0,0,0,0, /* no weapons */
1,1,1,1, /* dirks only */
1,2,1,2, /* dirks and maces */
1,2,3,2, /* mostly maces */
4,4,3,2, /* swords and bows */
5,5,5,5, /* magic wand */
8,8,8,8, /* touch attack! */
3,3,3,3, /* swords only */
};
UBYTE fallstates[] = {
0,0,0,0,0,0,
0x20,0x22,0x3a,0x6f,0x70,0x71,
0x24,0x27,0x3c,0x6f,0x70,0x71,
0x37,0x38,0x3d,0x6f,0x70,0x71 };
char bow_x[32] = {
1,2,3,4,3,2,1,0, 3,2,0,-2,-3,-2,0,2,
-3,-3,-3,-3,-3,-3,-3,-2, 0,1,1,1,0,-2,-3,-2 };
char bow_y[32] = {
8,8,8,7,8,8,8,8, 11,12,13,13,13,13,13,12,
8,7,6,5,6,7,8,9, 12,12,12,12,12,12,11,12 };
/* 0 1 2 3 4 5 6 7 */
char bowshotx[8] = { 0, 0, 3, 6,-3,-3,-3,-6 };
char bowshoty[8] = { -6,-6,-1, 0, 6, 8, 0,-1 };
char gunshoty[8] = { 2, 0, 4, 7, 9, 4, 7, 8 };
BYTE witchpoints[] = { /* 64 points - 256 entries */
0,100,0,10, 9,99,0,9, 19,98,1,9, 29,95,2,9,
38,92,3,9, 47,88,4,8, 55,83,5,8, 63,77,6,7,
70,70,7,7, 77,63,7,6, 83,55,8,5, 88,47,8,4,
92,38,9,3, 95,29,9,2, 98,19,9,1, 99,9,9,0,
100,0,10,0, 99,-10,9,-1, 98,-20,9,-2, 95,-30,9,-3,
92,-39,9,-4, 88,-48,8,-5, 83,-56,8,-6, 77,-64,7,-7,
70,-71,7,-8, 63,-78,6,-8, 55,-84,5,-9, 47,-89,4,-9,
38,-93,3,-10, 29,-96,2,-10, 19,-99,1,-10, 9,-100,0,-10,
0,-100,0,-10, -10,-100,-1,-10,-20,-99,-2,-10, -30,-96,-3,-10,
-39,-93,-4,-10, -48,-89,-5,-9, -56,-84,-6,-9, -64,-78,-7,-8,
-71,-71,-8,-8, -78,-64,-8,-7, -84,-56,-9,-6, -89,-48,-9,-5,
-93,-39,-10,-4, -96,-30,-10,-3, -99,-20,-10,-2, -100,-10,-10,-1,
-100,-1,-10,-1, -100,9,-10,0, -99,19,-10,1, -96,29,-10,2,
-93,38,-10,3, -89,47,-9,4, -84,55,-9,5, -78,63,-8,6,
-71,70,-8,7, -64,77,-7,7, -56,83,-6,8, -48,88,-5,8,
-39,92,-4,9, -30,95,-3,9, -20,98,-2,9, -10,99,-1,9,
};
struct TmpRas mytmp, *InitTmpRas();
struct AreaInfo myAreaInfo;
WORD areabuffer[20];
PLANEPTR myras, AllocRaster();
struct Layer *layer, templayer, *oldlayer /*, *CreateUpfrontLayer() */ ;
extern struct Layer_Info *li;
SHORT s1,s2;
witch_fx(fp) register struct fpage *fp;
{ UBYTE w1; register BYTE *w;
register struct RastPort *r;
SHORT x1,y1,x2,y2,x3,y3,x4,y4;
SHORT xh, yh, dx, dy, dx1, dy1;
xh = hero_x - (map_x & 0xfff0);
yh = hero_y - (map_y & 0xffe0);
layer = CreateUpfrontLayer(li,rp_map.BitMap,0,0,16*19,6*32,
LAYERSIMPLE,NULL);
r = &rp_map; oldlayer = r->Layer; r->Layer = layer;
w1 = ((fp->witchdir+63) * 4); w = witchpoints + w1;
x1 = w[0] + fp->witchx; y1 = w[1] + fp->witchy;
x2 = w[2] + fp->witchx; y2 = w[3] + fp->witchy;
w1 = ((fp->witchdir+1) * 4); w = witchpoints + w1;
x3 = w[0] + fp->witchx; y3 = w[1] + fp->witchy;
x4 = w[2] + fp->witchx; y4 = w[3] + fp->witchy;
dx = x2 - x1; dy = y2 - y1;
dx1 = xh - x1; dy1 = yh - y1;
s1 = (dx*dy1-dy*dx1);
sg1 = 0; if (s1 >= 0) sg1 = 1;
dx = x4 - x3; dy = y4 - y3;
dx1 = xh - x3; dy1 = yh - y3;
s2 = (dx*dy1-dy*dx1);
sg2 = 0; if (s2 >= 0) sg2 = 1;
SetDrMd(r,COMPLEMENT);
if (myras = AllocRaster(100,100))
{ struct TmpRas *oldtmp; struct AreaInfo *oldarea;
oldtmp = r->TmpRas;
oldarea = r->AreaInfo;
r->TmpRas = InitTmpRas(&mytmp,myras,RASSIZE(100,100));
InitArea(&myAreaInfo,areabuffer,9);
r->AreaInfo = &myAreaInfo;
AreaMove(r,x1,y1);
AreaDraw(r,x2,y2);
AreaDraw(r,x4,y4);
AreaDraw(r,x3,y3);
AreaEnd(r);
FreeRaster(myras,100,100);
r->TmpRas = oldtmp;
r->AreaInfo = oldarea;
}
r->Layer = oldlayer;
DeleteLayer(NULL,layer);
}
enum obytes {
QUIVER=11,
MONEY=13, URN, CHEST, SACKS, G_RING, B_STONE, G_JEWEL,
SCRAP, C_ORB, VIAL, B_TOTEM, J_SKULL,
GOLD_KEY=25, GREY_KEY=26,
FOOTSTOOL=31,
TURTLE=102,
BLUE_KEY=114,
M_WAND=145, MEAL, ROSE, FRUIT, STATUE, BOOK, SHELL,
GREEN_KEY=153, WHITE_KEY=154, RED_KEY=242,
};
UBYTE itrans[] = {
QUIVER,35,
B_STONE,9,G_JEWEL,10,VIAL,11,C_ORB,12,B_TOTEM,13,G_RING,14,J_SKULL,15,
M_WAND,4, 27,5, 8,2, 9,1, 12,0, 10,3, ROSE,23, FRUIT,24, STATUE,25,
BOOK,26, SHELL,6, 155,7, 136,27, 137,28, 138,29, 139,22, 140,30,
GOLD_KEY,16,GREEN_KEY,17,BLUE_KEY,18,RED_KEY,19,GREY_KEY,20,WHITE_KEY,21,
0,0 };
UBYTE rand_treasure[] = {
SACKS, SACKS, SACKS, SACKS,
CHEST, MONEY, GOLD_KEY, QUIVER,
GREY_KEY, GREY_KEY, GREY_KEY, RED_KEY,
B_TOTEM, VIAL, WHITE_KEY, CHEST
};
#define TENBLANKS {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}
/* divide object list up by region number */
/* 0=nonexist, 1=ground, 2=inventory, 3=setfig, 4=dead setfig, 5=hidden object */
/* 6 = cabinet items */
struct object /* 250 objects, for a start */