1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2016 EDuke32 developers and contributors
4 Copyright (C) 2020 Nuke.YKT
5 
6 This file is part of EDuke32.
7 
8 EDuke32 is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License version 2
10 as published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22 //-------------------------------------------------------------------------
23 
24 #include "compat.h"
25 #include "baselayer.h"
26 #include "duke3d.h"
27 #include "sounds.h"
28 
29 int rrdh_randseed = 1;
30 
rrdh_random(void)31 int rrdh_random(void)
32 {
33     static int seedinit = 0;
34     if (!seedinit)
35     {
36         rrdh_randseed = (int)timerGetPerformanceCounter();
37         seedinit = 1;
38     }
39     rrdh_randseed = (rrdh_randseed*1103515245)+12345;
40     return (rrdh_randseed>>16)&0x7fff;
41 }
42 
43 
sub_5151C(short a1)44 int sub_5151C(short a1)
45 {
46     switch (a1)
47     {
48     case 26:
49     case 27:
50     case 29:
51     case 30:
52     case 31:
53     case 32:
54     case 33:
55     case 34:
56     case 35:
57     case 73:
58     case 74:
59     case 92:
60     case 93:
61     case 96:
62     case 97:
63     case 98:
64     case 103:
65     case 141:
66     case 142:
67     case 143:
68     case 144:
69     case 145:
70     case 146:
71     case 147:
72     case 148:
73     case 149:
74     case 150:
75     case 151:
76     case 152:
77     case 153:
78     case 154:
79     case 155:
80     case 156:
81     case 157:
82     case 158:
83     case 159:
84     case 160:
85     case 161:
86     case 162:
87     case 163:
88     case 164:
89     case 165:
90         return 1;
91     }
92     return 0;
93 }
94 
rrgh_isatree(short s)95 int rrgh_isatree(short s)
96 {
97     switch (sprite[s].picnum)
98     {
99     case 984:
100     case 985:
101     case 986:
102     case 988:
103     case 989:
104     case 990:
105     case 991:
106     case 1028:
107     case 1029:
108     case 1030:
109     case 1040:
110     case 1041:
111     case 1050:
112     case 1051:
113     case 1052:
114     case 1053:
115     case 1054:
116     case 1055:
117     case 1056:
118     case 1057:
119     case 1058:
120     case 1059:
121     case 1093:
122     case 1094:
123     case 1095:
124     case 1096:
125     case 1097:
126     case 1098:
127     case 1099:
128     case 1100:
129     case 1113:
130     case 1114:
131     case 1115:
132     case 1116:
133     case 1117:
134         return 1;
135     }
136     return 0;
137 }
138 
sub_51678(int a1,int a2,int a3,int a4,int a5,int a6)139 void sub_51678(int a1, int a2, int a3, int a4, int a5, int a6)
140 {
141 }
142 
ghcons_isanimalescapewall(short w)143 int ghcons_isanimalescapewall(short w)
144 {
145     walltype *wl = &wall[w];
146     switch (wall[w].picnum)
147     {
148     case 1182:
149     case 1183:
150     case 1184:
151     case 1185:
152     case 2347:
153     case 3802:
154     case 3803:
155     case 7870:
156     case 7871:
157     case 7872:
158         return 1;
159     }
160     return 0;
161 }
162 
ghcons_isanimalescapesect(short s)163 int ghcons_isanimalescapesect(short s)
164 {
165     sectortype *sc = &sector[s];
166     return sector[s].hitag == 2001;
167 }
168 
sub_517AC(int * a1,int * a2,short * a3)169 int sub_517AC(int *a1, int *a2, short *a3)
170 {
171     int i, x, y;
172     short j;
173     if (numsectors < 0 || numsectors >= MAXSECTORS)
174         return 0;
175     for (i = 0; i < 32; i++)
176     {
177         x = (((rrdh_random() & 2047) + 1) - 1024) * 100;
178         y = (((rrdh_random() & 2047) + 1) - 1024) * 100;
179 
180         for (j = 0; j < numsectors; j++)
181         {
182             if (inside(x, y, j))
183             {
184                 *a1 = x;
185                 *a2 = y;
186                 *a3 = j;
187                 return 1;
188             }
189         }
190     }
191     return 0;
192 }
193 
ghcons_findnewspot(short a1)194 int ghcons_findnewspot(short a1)
195 {
196     int v20 = 0, v24 = 0;
197     short v18 = 0;
198     spritetype *spr;
199     sectortype *sec;
200     spr = &sprite[a1];
201     if (sub_517AC(&v20, &v24, &v18))
202     {
203         sec = &sector[v18];
204         switch (DYNAMICTILEMAP(spr->picnum))
205         {
206         case PIG__STATICRR:
207         case VIXEN__STATICRR:
208         case CHEER__STATICRR:
209             if (sec->hitag)
210                 return 0;
211             break;
212         case DOGRUN__STATICRR:
213             if (sec->hitag)
214                 return 0;
215             break;
216         }
217         vec3_t pos = { v20, v24,  v18 };
218         setsprite(a1, &pos);
219         changespritesect(a1, v18);
220         if (spr->picnum == DOGRUN)
221             spr->z = -307200;
222         else
223             spr->z = sec->floorz;
224         return 1;
225     }
226     return 0;
227 }
228 
sub_519E8(int a1)229 void sub_519E8(int a1)
230 {
231     int vbx;
232     if ((rrdh_random() & 63) == 32)
233     {
234         if (sub_57A60(20))
235         {
236             vbx = rrdh_random() % 5;
237             switch (a1)
238             {
239             case 0:
240             case 4:
241                 vbx += 60;
242                 break;
243             case 1:
244             case 5:
245                 vbx += 65;
246                 break;
247             case 2:
248                 vbx += 70;
249                 break;
250             case 3:
251                 vbx += 75;
252                 break;
253             }
254             S_PlaySound(vbx);
255         }
256     }
257 }
258 
259 int dword_AA25C;
260 
ghsound_ambientlooppoll(void)261 void ghsound_ambientlooppoll(void)
262 {
263     if (dword_AA25C)
264     {
265         if (dword_AA25C < 0 || dword_AA25C >= MAXSOUNDS)
266         {
267             initprintf("ghsound_ambientlooppoll bad index\n");
268             return;
269         }
270         if (!A_CheckSoundPlaying(-1, dword_AA25C))
271         {
272             A_PlaySound(dword_AA25C, g_player[screenpeek].ps->i);
273         }
274     }
275 }
276 
ghsound_ambientloop(int a1)277 void ghsound_ambientloop(int a1)
278 {
279     switch (a1)
280     {
281     case 0:
282         A_PlaySound(83, g_player[screenpeek].ps->i);
283         dword_AA25C = 83;
284         break;
285     case 1:
286         S_PlaySound(84);
287         dword_AA25C = 84;
288         break;
289     case 2:
290         S_PlaySound(85);
291         dword_AA25C = 85;
292         break;
293     default:
294         dword_AA25C = 0;
295         break;
296     }
297 }
298 
299 
300 int dword_AA260;
301 
sub_51B68(void)302 int sub_51B68(void)
303 {
304     int r;
305     if ((int)totalclock - dword_AA260 < 200)
306         return 0;
307     if ((rrdh_random() & 127) != 64)
308         return 0;
309 
310     dword_AA260 = (int)totalclock;
311 
312     r = 60 + (rrdh_random() % 15);
313     S_PlaySound(r);
314     return r;
315 }
316 
ghsound_pmadecall(spritetype * a1,short a2)317 int ghsound_pmadecall(spritetype *a1, short a2)
318 {
319     switch (DYNAMICTILEMAP(a1->picnum))
320     {
321     case DOGRUN__STATICRR:
322         if (A_CheckSoundPlaying(-1, 41))
323             return 1;
324     case VIXEN__STATICRR:
325         if (A_CheckSoundPlaying(-1, 40))
326             return 1;
327     case PIG__STATICRR:
328         if (A_CheckSoundPlaying(-1, 42))
329             return 1;
330     case CHEER__STATICRR:
331         if (A_CheckSoundPlaying(-1, 43))
332             return 1;
333     }
334     return 0;
335 }
336 
ghsound_pmadesound(spritetype * a1,short a2)337 int ghsound_pmadesound(spritetype *a1, short a2)
338 {
339     int d = klabs(g_player[a2].ps->pos.x - a1->x) + klabs(g_player[a2].ps->pos.y - a1->y);
340     if (A_CheckSoundPlaying(-1, 1) && d < 23040)
341         return 1;
342     if (A_CheckSoundPlaying(-1, 2))
343         return 1;
344     if (A_CheckSoundPlaying(-1, 3) && d < 23040)
345         return 1;
346     if (A_CheckSoundPlaying(-1, 4))
347         return 1;
348     if (A_CheckSoundPlaying(-1, 5) && d < 23040)
349         return 1;
350     if (A_CheckSoundPlaying(-1, 6))
351         return 1;
352     if (A_CheckSoundPlaying(-1, 7) && d < 23040)
353         return 1;
354     if (A_CheckSoundPlaying(-1, 8) && d < 23040)
355         return 1;
356     if (A_CheckSoundPlaying(-1, 56) && d < 23040)
357         return 1;
358     if (A_CheckSoundPlaying(-1, 57) && d < 23040)
359         return 1;
360     if (A_CheckSoundPlaying(-1, 58) && d < 23040)
361         return 1;
362     if (A_CheckSoundPlaying(-1, 59) && d < 23040)
363         return 1;
364     if (A_CheckSoundPlaying(-1, 25) && d < 21504)
365         return 1;
366     if (A_CheckSoundPlaying(-1, 11) && d < 10752)
367         return 1;
368     if (A_CheckSoundPlaying(-1, 9) && d < 15360)
369         return 1;
370     if (A_CheckSoundPlaying(-1, 10) && d < 30720)
371         return 1;
372     if (A_CheckSoundPlaying(-1, 12) && d < 19968)
373         return 1;
374     if (A_CheckSoundPlaying(-1, 15) && d < 10752)
375         return 1;
376     if (A_CheckSoundPlaying(-1, 13) && d < 15360)
377         return 1;
378     if (A_CheckSoundPlaying(-1, 14) && d < 30720)
379         return 1;
380     if (A_CheckSoundPlaying(-1, 16) && d < 19968)
381         return 1;
382     if (A_CheckSoundPlaying(-1, 19) && d < 10752)
383         return 1;
384     if (A_CheckSoundPlaying(-1, 17) && d < 15360)
385         return 1;
386     if (A_CheckSoundPlaying(-1, 18) && d < 30720)
387         return 1;
388     if (A_CheckSoundPlaying(-1, 20) && d < 19968)
389         return 1;
390     if (A_CheckSoundPlaying(-1, 23) && d < 10752)
391         return 1;
392     if (A_CheckSoundPlaying(-1, 21) && d < 15360)
393         return 1;
394     if (A_CheckSoundPlaying(-1, 22) && d < 30720)
395         return 1;
396     if (A_CheckSoundPlaying(-1, 24) && d < 19968)
397         return 1;
398     if (A_CheckSoundPlaying(-1, 81) && d < 15360)
399         return 1;
400     if (A_CheckSoundPlaying(-1, 80) && d < 30720)
401         return 1;
402     if (A_CheckSoundPlaying(-1, 41) && d < 23040)
403         return 1;
404     if (A_CheckSoundPlaying(-1, 40) && d < 23040)
405         return 1;
406     if (A_CheckSoundPlaying(-1, 42) && d < 23040)
407         return 1;
408     if (A_CheckSoundPlaying(-1, 43) && d < 23040)
409         return 1;
410     if (A_CheckSoundPlaying(-1, 88) && d < 10752)
411         return 1;
412     if (A_CheckSoundPlaying(-1, 89) && d < 15360)
413         return 1;
414     if (A_CheckSoundPlaying(-1, 90) && d < 23040)
415         return 1;
416     if (A_CheckSoundPlaying(-1, 27) && d < 30720)
417         return 1;
418     if (A_CheckSoundPlaying(-1, 36) && d < 30720)
419         return 1;
420     if (A_CheckSoundPlaying(-1, 30) && d < 30720)
421         return 1;
422     if (A_CheckSoundPlaying(-1, 33) && d < 30720)
423         return 1;
424     return 0;
425 }
426 
ghsound_pfiredgunnear(spritetype * a1,short a2)427 int ghsound_pfiredgunnear(spritetype *a1, short a2)
428 {
429     if (A_CheckSoundPlaying(-1, 2))
430         return 1;
431     if (A_CheckSoundPlaying(-1, 4))
432         return 1;
433     if (A_CheckSoundPlaying(-1, 6))
434         return 1;
435     if (A_CheckSoundPlaying(-1, 8) && klabs(g_player[a2].ps->pos.x - a1->x) + klabs(g_player[a2].ps->pos.y - a1->y) < 23040)
436         return 1;
437     return 0;
438 }
439 
sub_5228C(short a1)440 int sub_5228C(short a1)
441 {
442     switch (a1)
443     {
444     case 998:
445     case 999:
446     case 1007:
447     case 1008:
448         return 1;
449     }
450     return 0;
451 }
452 
sub_522B8(short a1)453 int sub_522B8(short a1)
454 {
455     switch (a1)
456     {
457     case 981:
458     case 982:
459         return 1;
460     }
461     return 0;
462 }
463 
464 int dword_AA264;
465 
ghsound_footstepsound(short a1,int a2)466 void ghsound_footstepsound(short a1, int a2)
467 {
468     DukePlayer_t *p;
469     int i, nexti, d;
470     spritetype *s;
471     if (sub_535EC())
472         return;
473 
474     p = g_player[a1].ps;
475     if (sector[p->cursectnum].hitag == 2003)
476     {
477         if (a2 == 0)
478         {
479             if (sub_57A40(5) == 1)
480                 A_PlaySound(81, p->i);
481         }
482         else if (a2 == 1)
483         {
484             if (sub_57A40(5) == 1)
485                 A_PlaySound(80, p->i);
486         }
487         else
488         {
489             if (sub_57A40(5) == 1)
490                 A_PlaySound(82, p->i);
491         }
492     }
493     else
494     {
495         if (a2 == 0)
496         {
497             if (sub_57A40(5) == 1)
498             {
499                 switch (ud.level_number)
500                 {
501                 case 0:
502                     A_PlaySound(9, p->i);
503                     break;
504                 case 1:
505                     A_PlaySound(13, p->i);
506                     break;
507                 case 2:
508                     A_PlaySound(17, p->i);
509                     break;
510                 case 3:
511                     A_PlaySound(21, p->i);
512                     break;
513                 }
514             }
515         }
516         else if (a2 == 1)
517         {
518             if (sub_57A40(5) == 1)
519             {
520                 switch (ud.level_number)
521                 {
522                 case 0:
523                     A_PlaySound(10, p->i);
524                     break;
525                 case 1:
526                     A_PlaySound(14, p->i);
527                     break;
528                 case 2:
529                     A_PlaySound(18, p->i);
530                     break;
531                 case 3:
532                     A_PlaySound(22, p->i);
533                     break;
534                 }
535             }
536         }
537         else
538         {
539             if (sub_57A40(5) == 1)
540             {
541                 switch (ud.level_number)
542                 {
543                 case 0:
544                     A_PlaySound(11, p->i);
545                     break;
546                 case 1:
547                     A_PlaySound(15, p->i);
548                     break;
549                 case 2:
550                     A_PlaySound(19, p->i);
551                     break;
552                 case 3:
553                     A_PlaySound(23, p->i);
554                     break;
555                 }
556             }
557         }
558     }
559     i = headspritesect[p->cursectnum];
560     while (i >= 0)
561     {
562         nexti = nextspritesect[i];
563         s = &sprite[i];
564         if (sub_5228C(s->picnum) && klabs(p->pos.x - s->x) + klabs(p->pos.y - s->y) < s->clipdist)
565         {
566             if (i != dword_AA264)
567             {
568                 A_PlaySound(25, p->i);
569                 sub_5A250(4096);
570                 dword_AA264 = i;
571             }
572             return;
573         }
574         else if (sub_522B8(s->picnum) && klabs(p->pos.x - s->x) + klabs(p->pos.y - s->y) < 124)
575         {
576             sub_5A250(2048);
577         }
578         i = nexti;
579     }
580 }
581 
ghsound_plrtouchedsprite(short a1,short a2)582 void ghsound_plrtouchedsprite(short a1, short a2)
583 {
584     DukePlayer_t *p;
585     spritetype *s;
586     p = g_player[a2].ps;
587 
588     s = &sprite[a1];
589     if (rrgh_isatree(a1))
590     {
591         switch (ud.level_number)
592         {
593         case 0:
594             if (!A_CheckSoundPlaying(-1, 12))
595                 A_PlaySound(12, p->i);
596             break;
597         case 1:
598             if (!A_CheckSoundPlaying(-1, 16))
599                 A_PlaySound(16, p->i);
600             break;
601         case 2:
602             if (!A_CheckSoundPlaying(-1, 20))
603                 A_PlaySound(20, p->i);
604             break;
605         case 3:
606             if (!A_CheckSoundPlaying(-1, 24))
607                 A_PlaySound(24, p->i);
608             break;
609         }
610     }
611 }
612 
613 unsigned short word_AA268[] = {
614     9, 10, 11, 12, 25, 35, 36, 37, 41, 60, 61, 62, 63, 64, 80, 81, 82
615 };
616 
617 unsigned short word_AA28A[] = {
618     13, 14, 15, 16, 25, 26, 27, 28, 32, 33, 34, 40, 43, 65, 66, 67, 68, 69
619 };
620 
621 unsigned short word_AA2AE[] = {
622     17, 18, 19, 20, 25, 26, 27, 28, 29, 30, 31, 40, 42, 70, 71, 72, 73, 74
623 };
624 
625 unsigned short word_AA2D2[] = {
626     21, 22, 23, 24, 25, 26, 27, 28, 40, 75, 76, 77, 78, 79
627 };
628 
ghsound_preload(int a1)629 void ghsound_preload(int a1)
630 {
631 #if 0
632     unsigned short *vsi = NULL, snd;
633     int i, c;
634     switch (a1)
635     {
636     case 0:
637         vsi = word_AA268;
638         c = 17;
639         break;
640     case 1:
641         vsi = word_AA28A;
642         c = 18;
643         break;
644     case 2:
645         vsi = word_AA2AE;
646         c = 18;
647         break;
648     case 3:
649         vsi = word_AA2D2;
650         c = 14;
651         break;
652     }
653     if (vsi)
654     {
655         for (i = 0; i < c; i++)
656         {
657             snd = vsi[i];
658             if (snd >= MAXSOUNDS)
659             {
660                 initprintf("ERROR: ghsound_preload: sndnum out of range\n");
661                 continue;
662             }
663             if (snd > 0 && g_sounds[snd].ptr == NULL)
664             {
665                 S_LoadSound(snd);
666             }
667         }
668     }
669     switch (g_player[myconnectindex].ps->dhat61f)
670     {
671     case 0:
672         if (g_sounds[1].ptr == NULL)
673         {
674             S_LoadSound(1);
675         }
676         if (g_sounds[2].ptr == NULL)
677         {
678             S_LoadSound(2);
679         }
680         break;
681     case 1:
682     case 2:
683         if (g_sounds[5].ptr == NULL)
684         {
685             S_LoadSound(5);
686         }
687         if (g_sounds[6].ptr == NULL)
688         {
689             S_LoadSound(6);
690         }
691         break;
692     case 3:
693         if (g_sounds[3].ptr == NULL)
694         {
695             S_LoadSound(3);
696         }
697         if (g_sounds[4].ptr == NULL)
698         {
699             S_LoadSound(4);
700         }
701         break;
702     case 4:
703         if (g_sounds[7].ptr == NULL)
704         {
705             S_LoadSound(7);
706         }
707         if (g_sounds[8].ptr == NULL)
708         {
709             S_LoadSound(8);
710         }
711         break;
712     }
713     if (g_sounds[98].ptr == NULL)
714     {
715         S_LoadSound(98);
716     }
717     if (g_sounds[99].ptr == NULL)
718     {
719         S_LoadSound(99);
720     }
721     if (g_sounds[100].ptr == NULL)
722     {
723         S_LoadSound(100);
724     }
725     if (g_sounds[101].ptr == NULL)
726     {
727         S_LoadSound(101);
728     }
729 #endif
730 }
731 
ghprelvl_randkeep(short a1,unsigned int a2)732 void ghprelvl_randkeep(short a1, unsigned int a2)
733 {
734     short vbx;
735     int v18 = 0;
736     unsigned int i, vcx;
737     while (1)
738     {
739         vcx = 0;
740         for (i = 0; i < MAXSPRITES; i++)
741         {
742             if (sprite[i].picnum == a1)
743                 vcx++;
744         }
745         if (vcx <= a2)
746             return;
747         for (i = 0; i < MAXSPRITES; i++)
748         {
749             if (!v18)
750                 vbx = MAXSPRITES - 1 - i;
751             else
752                 vbx = i;
753 
754             if (a1 == sprite[vbx].picnum)
755             {
756                 if ((rrdh_random() % 256) < 32)
757                 {
758                     sprite[vbx].picnum = 0;
759                     deletesprite(vbx);
760                     vcx--;
761                     if (vcx <= a2)
762                         return;
763                 }
764             }
765         }
766         if (!v18)
767             v18 = 1;
768         else
769             v18 = 0;
770     }
771 }
772 
sub_52AB8(int a1,int a2)773 char sub_52AB8(int a1, int a2)
774 {
775     int vbx = (a1 * a2) / 100;
776     return (rrdh_random() % vbx) % 256;
777 }
778 
sub_52AF0(short a1)779 int sub_52AF0(short a1)
780 {
781     if (a1 < 0 || a1 >= MAXSPRITES)
782         return 0;
783     switch (DYNAMICTILEMAP(sprite[a1].picnum))
784     {
785     case PIG__STATICRR:
786     case DOGRUN__STATICRR:
787     case VIXEN__STATICRR:
788     case CHEER__STATICRR:
789     case RRTILE1076__STATICRR:
790         return 1;
791     }
792     return 0;
793 }
794 
sub_52B58(short a1)795 int sub_52B58(short a1)
796 {
797     if (a1 < 0 || a1 >= MAXSPRITES)
798         return 0;
799     switch (sprite[a1].picnum)
800     {
801     case 976:
802     case 977:
803     case 2603:
804     case 2990:
805         return 1;
806     }
807     return 0;
808 }
809 
sub_52BA8(void)810 void sub_52BA8(void)
811 {
812     int v1c, tl, tc;
813     int i;
814     short sect;
815     v1c = 0;
816     sub_59C20();
817     sub_54A2C();
818     for (i = 0; i < MAXSPRITES; i++)
819     {
820         sprite[i].cstat = 0;
821         sprite[i].pal = 0;
822         changespritestat(i, 0);
823         sect = sprite[i].sectnum;
824         if (sub_52AF0(i))
825         {
826             if (sect >= 0 && sect < numsectors)
827             {
828                 if (sector[sect].ceilingheinum == 0 && sector[sect].floorheinum == 0)
829                 {
830                     if (klabs(sprite[i].z - sector[sect].floorz) > 1024 && sprite[i].z < sector[sect].floorz)
831                     {
832                         initprintf("NOTICE: deleting floating sprite %i: x=%i, y=%i, z=%i, sect=%i\n", i, sprite[i].x, sprite[i].y, sprite[i].z, sect);
833                         deletesprite(i);
834                         sprite[i].picnum = 0;
835                         sprite[i].cstat = 0;
836                     }
837                 }
838             }
839         }
840         if (sub_52B58(i))
841         {
842             sprite[i].cstat = 1;
843             sprite[i].clipdist = 8;
844         }
845         if (rrgh_isatree(i))
846         {
847             sprite[i].cstat = 1;
848             sprite[i].xoffset = 0;
849             sprite[i].yoffset = 0;
850             sprite[i].clipdist = 8;
851         }
852         if (sprite[i].picnum == 998 || sprite[i].picnum == 999 || sprite[i].picnum == 1007 || sprite[i].picnum == 1008)
853         {
854             sprite[i].cstat = 32;
855             sprite[i].clipdist = 127;
856         }
857         if (sprite[i].picnum)
858         {
859             v1c++;
860         }
861     }
862     ghprelvl_randkeep(PIG, 4);
863     ghprelvl_randkeep(VIXEN, 4);
864     ghprelvl_randkeep(DOGRUN, 4);
865     ghprelvl_randkeep(CHEER, 4);
866     ghprelvl_randkeep(7065, 64);
867 
868     for (i = 0; i < MAXSPRITES; i++)
869     {
870         if (sprite[i].picnum == PIG)
871         {
872             sprite[i].cstat = 257;
873             changespritestat(i, 1);
874             sprite[i].xrepeat = 10 + sub_52AB8(5, 125);
875             sprite[i].yrepeat = 10 + sub_52AB8(5, 125);
876             sprite[i].clipdist = mulscale7(sprite[i].xrepeat, tilesiz[sprite[i].picnum].x);
877         }
878         if (sprite[i].picnum == VIXEN)
879         {
880             sprite[i].cstat = 257;
881             changespritestat(i, 1);
882             sprite[i].xrepeat = 14 + sub_52AB8(7, 100);
883             sprite[i].yrepeat = 14 + sub_52AB8(7, 100);
884             sprite[i].clipdist = mulscale7(sprite[i].xrepeat, tilesiz[sprite[i].picnum].x);
885         }
886         if (sprite[i].picnum == DOGRUN)
887         {
888             sprite[i].cstat = 257;
889             changespritestat(i, 1);
890             sprite[i].xrepeat = 8 + sub_52AB8(4, 100);
891             sprite[i].yrepeat = 8 + sub_52AB8(4, 100);
892             sprite[i].clipdist = mulscale7(sprite[i].xrepeat, tilesiz[sprite[i].picnum].x);
893         }
894         if (sprite[i].picnum == CHEER)
895         {
896             sprite[i].cstat = 257;
897             changespritestat(i, 1);
898             sprite[i].xrepeat = 8 + sub_52AB8(4, 100);
899             sprite[i].yrepeat = 8 + sub_52AB8(4, 100);
900             sprite[i].clipdist = mulscale7(sprite[i].xrepeat, tilesiz[sprite[i].picnum].x);
901         }
902         if (sprite[i].picnum == 7065)
903         {
904             sprite[i].cstat = 0;
905             sprite[i].z -= rrdh_random() << 3;
906             changespritestat(i, 801);
907         }
908     }
909 
910     for (i = 0; i < numwalls; i++)
911     {
912         if (wall[i].nextsector != -1)
913         {
914             wall[i].cstat &= ~64;
915         }
916     }
917     sub_55F8C();
918     sub_566F0();
919     sub_558F4();
920     sub_56AB8();
921     sub_573C0();
922     sub_59314();
923     ghsound_preload(ud.level_number);
924     sub_55184();
925     sub_57B24();
926     sub_58388();
927     sub_59B50();
928     sub_59F80(ud.level_number);
929     sub_299C0();
930 }
931 
sub_53154(int a1)932 void sub_53154(int a1)
933 {
934     ghsound_ambientloop(a1);
935 }
936 
937 int dword_AA2F0, dword_AA2F4, dword_AA2F8, dword_AA2FC;
938 
sub_53160(int a1)939 void sub_53160(int a1)
940 {
941     dword_AA2FC = a1;
942     dword_AA2F8 = 1;
943 }
944 
sub_53194(void)945 void sub_53194(void)
946 {
947     switch (dword_AA2F0)
948     {
949     case 0:
950         if (KB_KeyPressed(sc_S))
951         {
952             KB_ClearKeyDown(sc_S);
953             dword_AA2F0++;
954         }
955         break;
956     case 1:
957         if (KB_KeyPressed(sc_P))
958         {
959             KB_ClearKeyDown(sc_P);
960             dword_AA2F0++;
961         }
962         break;
963     case 2:
964         if (KB_KeyPressed(sc_O))
965         {
966             KB_ClearKeyDown(sc_O);
967             dword_AA2F0++;
968         }
969         break;
970     case 3:
971         if (KB_KeyPressed(sc_R))
972         {
973             KB_ClearKeyDown(sc_R);
974             dword_AA2F0++;
975         }
976         break;
977     case 4:
978         if (KB_KeyPressed(sc_K))
979         {
980             KB_ClearKeyDown(sc_K);
981             dword_AA2F0++;
982         }
983         break;
984     case 5:
985         if (KB_KeyPressed(sc_1))
986         {
987             KB_ClearKeyDown(sc_1);
988             dword_AA2F0 = 0;
989             sub_535DC();
990         }
991         if (KB_KeyPressed(sc_2))
992         {
993             KB_ClearKeyDown(sc_2);
994             dword_AA2F0 = 0;
995             sub_57AC0();
996         }
997         if (KB_KeyPressed(sc_3))
998         {
999             KB_ClearKeyDown(sc_3);
1000             dword_AA2F0 = 0;
1001             //sub_15224();
1002         }
1003         break;
1004     }
1005 }
1006 
sub_53304(void)1007 void sub_53304(void)
1008 {
1009     //ControlInfo info;
1010     //CONTROL_GetInput(&info);
1011 
1012     if (KB_KeyPressed(sc_RightAlt) || KB_KeyPressed(sc_LeftAlt) || KB_KeyPressed(sc_RightShift) || KB_KeyPressed(sc_LeftShift))
1013         return;
1014 
1015     sub_53194();
1016     if (KB_KeyPressed(sc_F1))
1017     {
1018         KB_ClearKeyDown(sc_F1);
1019         switch (g_player[myconnectindex].ps->dhat61f)
1020         {
1021         case 0:
1022             sub_566E8();
1023             break;
1024         case 1:
1025         case 2:
1026             sub_55F68();
1027             break;
1028         case 3:
1029             sub_558D0();
1030             break;
1031         case 4:
1032             sub_56AB0();
1033             break;
1034         }
1035     }
1036     if (KB_KeyPressed(sc_F2))
1037     {
1038         KB_ClearKeyDown(sc_F2);
1039         switch (g_player[myconnectindex].ps->dhat61f)
1040         {
1041         case 0:
1042             sub_56780();
1043             break;
1044         case 1:
1045         case 2:
1046             sub_56020();
1047             break;
1048         case 3:
1049             sub_55988();
1050             break;
1051         case 4:
1052             sub_56B3C();
1053             break;
1054         }
1055     }
1056     if (KB_KeyPressed(sc_F3))
1057     {
1058         KB_ClearKeyDown(sc_F3);
1059         switch (g_player[myconnectindex].ps->dhat61f)
1060         {
1061         case 0:
1062             sub_56724();
1063             break;
1064         case 1:
1065         case 2:
1066             sub_55FCC();
1067             break;
1068         case 3:
1069             sub_55934();
1070             break;
1071         case 4:
1072             sub_56AE4();
1073             break;
1074         }
1075     }
1076     if (KB_KeyPressed(sc_F4))
1077     {
1078         KB_ClearKeyDown(sc_F4);
1079         ghdeploy_drop(myconnectindex, ud.level_number);
1080     }
1081     if (KB_KeyPressed(sc_F5))
1082     {
1083         KB_ClearKeyDown(sc_F5);
1084         A_PlaySound(40, g_player[myconnectindex].ps->i);
1085     }
1086     if (KB_KeyPressed(sc_F6))
1087     {
1088         KB_ClearKeyDown(sc_F6);
1089         A_PlaySound(42, g_player[myconnectindex].ps->i);
1090     }
1091     if (KB_KeyPressed(sc_F7))
1092     {
1093         KB_ClearKeyDown(sc_F7);
1094         A_PlaySound(41, g_player[myconnectindex].ps->i);
1095     }
1096     if (KB_KeyPressed(sc_F8))
1097     {
1098         KB_ClearKeyDown(sc_F8);
1099         A_PlaySound(43, g_player[myconnectindex].ps->i);
1100     }
1101     //if (KB_KeyPressed(sc_S))
1102     //{
1103     //    KB_ClearKeyDown(sc_S);
1104     //}
1105 }
1106 
sub_535DC(void)1107 void sub_535DC(void)
1108 {
1109     dword_AA2F4 ^= 1;
1110 }
1111 
sub_535EC(void)1112 int sub_535EC(void)
1113 {
1114     return dword_AA2F4;
1115 }
1116 
1117 int dword_AA300;
1118 int dword_AA304 = 1731;
1119 int dword_AA308, dword_AA30C;
1120 
1121 struct struct2B80E0 {
1122     short f_0;
1123     short f_2;
1124     int f_4;
1125     int f_8;
1126     int f_c;
1127     int f_10;
1128 };
1129 
1130 struct2B80E0 f2B80E0[20];
1131 
1132 #pragma pack(push, 1)
1133 typedef struct _scoretype2 {
1134     int f_0;
1135     char f_4;
1136     char f_5;
1137     char f_6;
1138     int f_7;
1139     int f_b;
1140 } scoretype2;
1141 
1142 typedef struct _scoretype {
1143     int f_0;
1144     int f_4;
1145     int f_8;
1146     int f_c;
1147     scoretype2 f_10[5];
1148 } scoretype;
1149 #pragma pack(pop)
1150 
1151 
1152 scoretype bestscore = {
1153     0, 0, 0, 0,
1154     0, 65, 65, 65, 0, 0,
1155     0, 65, 65, 65, 0, 0,
1156     0, 65, 65, 65, 0, 0,
1157     0, 65, 65, 65, 0, 0,
1158     0, 65, 65, 65, 0, 0,
1159 };
1160 
1161 unsigned int dword_AA36C, dword_AA370, dword_AA374, dword_AA378, dword_AA37C, dword_AA380;
1162 int dword_AA384;
1163 char byte_AA388 = 65, byte_AA389 = 65, byte_AA38A = 65;
1164 unsigned int dword_AA38C;
1165 
1166 char dword_AA390[43] = "                                          ";
1167 
ghtrophy_savebestscores(void)1168 void ghtrophy_savebestscores(void)
1169 {
1170     FILE *handle;
1171 
1172     handle = Bfopen("scores", "rb");
1173     if (!handle)
1174     {
1175         initprintf("ghtrophy_savebestscores cant open scores\n");
1176         return;
1177     }
1178     Bfseek(handle, 0, SEEK_SET);
1179     if (dword_AA36C > bestscore.f_0)
1180         bestscore.f_0 = dword_AA36C;
1181     if (dword_AA370 > bestscore.f_4)
1182         bestscore.f_4 = dword_AA370;
1183     if (dword_AA374 > bestscore.f_8)
1184         bestscore.f_8 = dword_AA374;
1185     if (dword_AA378 > bestscore.f_c)
1186         bestscore.f_c = dword_AA378;
1187 
1188     Bfseek(handle, 0, SEEK_SET);
1189 
1190     if (Bfwrite(&bestscore, sizeof(bestscore), 1, handle) != 1)
1191     {
1192         initprintf("ghtrophy_savebestscores err write scores\n");
1193         Bfclose(handle);
1194         return;
1195     }
1196     Bfclose(handle);
1197     dword_AA380 = 0;
1198 }
1199 
ghtrophy_loadbestscores(void)1200 void ghtrophy_loadbestscores(void)
1201 {
1202     FILE *handle;
1203     handle = fopen("scores", "wb");
1204     if (!handle)
1205     {
1206         initprintf("ghtrophy_loadbestscores cant open scores\n");
1207         return;
1208     }
1209     Bfseek(handle, 0, SEEK_SET);
1210     if (Bfread(&bestscore, sizeof(bestscore), 1, handle) != 1)
1211     {
1212         initprintf("ghtrophy_loadbestscores err read scores\n");
1213         Bfclose(handle);
1214         return;
1215     }
1216     Bfclose(handle);
1217 }
1218 
ghtrophy_isakill(short a1)1219 int ghtrophy_isakill(short a1)
1220 {
1221     spritetype *spr = &sprite[a1];
1222     for (int i = 0; i < dword_AA300; i++)
1223     {
1224         if (f2B80E0[i].f_0 == a1)
1225             return 1;
1226     }
1227     return 0;
1228 }
1229 
sub_537A8(short a1,int a2)1230 int sub_537A8(short a1, int a2)
1231 {
1232     char va = rrdh_random() & 255;
1233     switch (DYNAMICTILEMAP(a1))
1234     {
1235     case PIG__STATICRR:
1236         if (a2 == 0 && va > 64)
1237             break;
1238         if (a2 == 6 && va > 80)
1239             break;
1240         if (a2 == 2 && va > 128)
1241             break;
1242         return 1;
1243     case VIXEN__STATICRR:
1244         if (a2 == 6 && va > 128)
1245             break;
1246         return 1;
1247     case CHEER__STATICRR:
1248         return 1;
1249     case DOGRUN__STATICRR:
1250         return 1;
1251     }
1252     return 0;
1253 }
1254 
sub_5381C(int a1,int a2)1255 int sub_5381C(int a1, int a2)
1256 {
1257     int vbx = (a1 * a2) / 100;
1258     return rrdh_random() % vbx;
1259 }
1260 
sub_53848(int a1)1261 void sub_53848(int a1)
1262 {
1263     dword_AA37C = a1;
1264 }
1265 
ghtrophy_addkill(int a1)1266 void ghtrophy_addkill(int a1)
1267 {
1268     int v18 = 0, vdi = 0;
1269     spritetype *spr = &sprite[a1];
1270 
1271     if (ud.level_number > 3)
1272         return;
1273 
1274     if (sprite[a1].cstat & 32768)
1275         return;
1276 
1277     switch (DYNAMICTILEMAP(sprite[a1].picnum))
1278     {
1279     default:
1280         sub_5A250(4);
1281         break;
1282     case PIG__STATICRR:
1283     case DOGRUN__STATICRR:
1284     case VIXEN__STATICRR:
1285     case CHEER__STATICRR:
1286         if (!ghtrophy_isakill(a1) && sub_537A8(sprite[a1].picnum, v18))
1287         {
1288             if (dword_AA300 < 20)
1289             {
1290                 f2B80E0[dword_AA300].f_0 = a1;
1291                 f2B80E0[dword_AA300].f_2 = sprite[a1].picnum;
1292                 switch (DYNAMICTILEMAP(sprite[a1].picnum))
1293                 {
1294                 case VIXEN__STATICRR:
1295                     f2B80E0[dword_AA300].f_4 = (sprite[a1].xrepeat * sprite[a1].yrepeat) / 40;
1296                     f2B80E0[dword_AA300].f_4 -= 2;
1297                     if (f2B80E0[dword_AA300].f_4 < 2)
1298                         f2B80E0[dword_AA300].f_4 = 2;
1299                     f2B80E0[dword_AA300].f_4 += 2;
1300                     if (f2B80E0[dword_AA300].f_4 > dword_AA36C)
1301                         dword_AA36C = f2B80E0[dword_AA300].f_4;
1302                     dword_AA308++;
1303                     vdi = dword_AA308;
1304                     break;
1305                 case PIG__STATICRR:
1306                     f2B80E0[dword_AA300].f_4 = sprite[a1].xrepeat * sprite[a1].yrepeat;
1307                     f2B80E0[dword_AA300].f_4 += sub_5381C(30, 125);
1308                     f2B80E0[dword_AA300].f_4 += sub_5381C(10, 100);
1309                     if (f2B80E0[dword_AA300].f_4 > 350)
1310                         f2B80E0[dword_AA300].f_4 = 350;
1311                     if (f2B80E0[dword_AA300].f_4 > dword_AA370)
1312                         dword_AA370 = f2B80E0[dword_AA300].f_4;
1313                     dword_AA30C++;
1314                     vdi = dword_AA30C;
1315                     break;
1316                 case DOGRUN__STATICRR:
1317                     f2B80E0[dword_AA300].f_4 = (sprite[a1].xrepeat * sprite[a1].yrepeat) / 40;
1318                     f2B80E0[dword_AA300].f_4 += sub_5381C(4, 125);
1319                     f2B80E0[dword_AA300].f_4 -= 3;
1320                     if (f2B80E0[dword_AA300].f_4 < 2)
1321                         f2B80E0[dword_AA300].f_4 = 2;
1322                     dword_AA378++;
1323                     vdi = dword_AA378;
1324                     break;
1325                 case CHEER__STATICRR:
1326                     f2B80E0[dword_AA300].f_4 = (sprite[a1].xrepeat * sprite[a1].yrepeat) / 16;
1327                     f2B80E0[dword_AA300].f_4 += sub_5381C(10, 125);
1328                     if (f2B80E0[dword_AA300].f_4 < 8)
1329                         f2B80E0[dword_AA300].f_4 = 8;
1330                     dword_AA374++;
1331                     vdi = dword_AA374;
1332                     break;
1333                 }
1334                 ghstatbr_registerkillinfo(f2B80E0[dword_AA300].f_2, f2B80E0[dword_AA300].f_4, vdi);
1335                 dword_AA300++;
1336             }
1337             sub_5A250(8);
1338         }
1339         break;
1340     }
1341 }
1342 
ghtrophy_rscopysrcdest(scoretype2 * a1,scoretype2 * a2)1343 void ghtrophy_rscopysrcdest(scoretype2 *a1, scoretype2 *a2)
1344 {
1345     if (!a1 || !a2)
1346     {
1347         initprintf("ghtrophy_rscopysrcdest null ptr\n");
1348         return;
1349     }
1350     a2->f_0 = a1->f_0;
1351     a2->f_4 = a1->f_4;
1352     a2->f_5 = a1->f_5;
1353     a2->f_6 = a1->f_6;
1354 }
1355 
sub_53C04(void)1356 void sub_53C04(void)
1357 {
1358     scoretype2 v60, v50, v40, v30, v20;
1359     dword_AA380 = 0;
1360     dword_AA384 = 0;
1361     dword_AA38C = (int)totalclock;
1362     if (dword_AA37C > bestscore.f_10[0].f_0)
1363     {
1364         v20.f_0 = dword_AA37C;
1365         ghtrophy_rscopysrcdest(&bestscore.f_10[0], &v50);
1366         ghtrophy_rscopysrcdest(&bestscore.f_10[1], &v30);
1367         ghtrophy_rscopysrcdest(&bestscore.f_10[2], &v40);
1368         ghtrophy_rscopysrcdest(&bestscore.f_10[3], &v60);
1369         dword_AA380 = 1;
1370     }
1371     else if (dword_AA37C > bestscore.f_10[1].f_0)
1372     {
1373         ghtrophy_rscopysrcdest(&bestscore.f_10[0], &v20);
1374         v50.f_0 = dword_AA37C;
1375         ghtrophy_rscopysrcdest(&bestscore.f_10[1], &v30);
1376         ghtrophy_rscopysrcdest(&bestscore.f_10[2], &v40);
1377         ghtrophy_rscopysrcdest(&bestscore.f_10[3], &v60);
1378         dword_AA380 = 2;
1379     }
1380     else if (dword_AA37C > bestscore.f_10[2].f_0)
1381     {
1382         ghtrophy_rscopysrcdest(&bestscore.f_10[0], &v20);
1383         ghtrophy_rscopysrcdest(&bestscore.f_10[1], &v50);
1384         v30.f_0 = dword_AA37C;
1385         ghtrophy_rscopysrcdest(&bestscore.f_10[2], &v40);
1386         ghtrophy_rscopysrcdest(&bestscore.f_10[3], &v60);
1387         dword_AA380 = 3;
1388     }
1389     else if (dword_AA37C > bestscore.f_10[3].f_0)
1390     {
1391         ghtrophy_rscopysrcdest(&bestscore.f_10[0], &v20);
1392         ghtrophy_rscopysrcdest(&bestscore.f_10[1], &v50);
1393         ghtrophy_rscopysrcdest(&bestscore.f_10[2], &v30);
1394         v40.f_0 = dword_AA37C;
1395         ghtrophy_rscopysrcdest(&bestscore.f_10[3], &v60);
1396         dword_AA380 = 4;
1397     }
1398     else if (dword_AA37C > bestscore.f_10[4].f_0)
1399     {
1400         ghtrophy_rscopysrcdest(&bestscore.f_10[0], &v20);
1401         ghtrophy_rscopysrcdest(&bestscore.f_10[1], &v50);
1402         ghtrophy_rscopysrcdest(&bestscore.f_10[2], &v30);
1403         ghtrophy_rscopysrcdest(&bestscore.f_10[3], &v40);
1404         v60.f_0 = dword_AA37C;
1405         dword_AA380 = 5;
1406     }
1407     if (dword_AA380)
1408     {
1409         ghtrophy_rscopysrcdest(&v20, &bestscore.f_10[0]);
1410         ghtrophy_rscopysrcdest(&v50, &bestscore.f_10[1]);
1411         ghtrophy_rscopysrcdest(&v30, &bestscore.f_10[2]);
1412         ghtrophy_rscopysrcdest(&v40, &bestscore.f_10[3]);
1413         ghtrophy_rscopysrcdest(&v60, &bestscore.f_10[4]);
1414     }
1415 }
1416 
sub_53E18(void)1417 void sub_53E18(void)
1418 {
1419     sub_53C04();
1420     if (dword_AA380)
1421     {
1422         sub_53160(300);
1423     }
1424 }
1425 
sub_53E4C(vec2_t const origin)1426 void sub_53E4C(vec2_t const origin)
1427 {
1428     int v20 = 0, v1c, v18, vsi, vdi;
1429     char val;
1430     val = sub_54B80();
1431     if (val & 32)
1432     {
1433         v20 = 1;
1434         switch (dword_AA384)
1435         {
1436         case 0:
1437             byte_AA388 = val;
1438             break;
1439         case 1:
1440             byte_AA389 = val;
1441             break;
1442         case 2:
1443             byte_AA38A = val;
1444             break;
1445         }
1446     }
1447 
1448     v1c = 0;
1449     if ((int)totalclock - dword_AA38C > 30)
1450     {
1451         v1c = 1;
1452         dword_AA38C = (int)totalclock;
1453     }
1454 
1455     v18 = 18;
1456     vsi = 100;
1457     vdi = 44;
1458 
1459     menutext_(origin.x+(160<<16), origin.y+(22<<16), 0, "TOP FIVE", 10|16, TEXT_XCENTER);
1460 
1461     if (dword_AA380)
1462     {
1463         if (!v1c || dword_AA384 != 0)
1464         {
1465             sprintf(dword_AA390, "%c", byte_AA388);
1466             gametext_simple(origin.x+(vsi<<16), origin.y+((vdi+v18*(dword_AA380-1))<<16), dword_AA390);
1467         }
1468         if (!v1c || dword_AA384 != 1)
1469         {
1470             sprintf(dword_AA390, "%c", byte_AA389);
1471             gametext_simple(origin.x+((vsi+14)<<16), origin.y+((vdi+v18*(dword_AA380-1))<<16), dword_AA390);
1472         }
1473         if (!v1c || dword_AA384 != 2)
1474         {
1475             sprintf(dword_AA390, "%c", byte_AA38A);
1476             gametext_simple(origin.x+((vsi+28)<<16), origin.y+((vdi+v18*(dword_AA380-1))<<16), dword_AA390);
1477         }
1478         switch (dword_AA380)
1479         {
1480         case 1:
1481             bestscore.f_10[0].f_4 = byte_AA388;
1482             bestscore.f_10[0].f_5 = byte_AA389;
1483             bestscore.f_10[0].f_6 = byte_AA38A;
1484             break;
1485         case 2:
1486             bestscore.f_10[1].f_4 = byte_AA388;
1487             bestscore.f_10[1].f_5 = byte_AA389;
1488             bestscore.f_10[1].f_6 = byte_AA38A;
1489             break;
1490         case 3:
1491             bestscore.f_10[2].f_4 = byte_AA388;
1492             bestscore.f_10[2].f_5 = byte_AA389;
1493             bestscore.f_10[2].f_6 = byte_AA38A;
1494             break;
1495         case 4:
1496             bestscore.f_10[3].f_4 = byte_AA388;
1497             bestscore.f_10[3].f_5 = byte_AA389;
1498             bestscore.f_10[3].f_6 = byte_AA38A;
1499             break;
1500         case 5:
1501             bestscore.f_10[4].f_4 = byte_AA388;
1502             bestscore.f_10[4].f_5 = byte_AA389;
1503             bestscore.f_10[4].f_6 = byte_AA38A;
1504             break;
1505         }
1506     }
1507     if (dword_AA380 != 1)
1508     {
1509         sprintf(dword_AA390, "%c", bestscore.f_10[0].f_4);
1510         gametext_simple(origin.x+(vsi<<16), origin.y+(vdi<<16), dword_AA390);
1511         sprintf(dword_AA390, "%c", bestscore.f_10[0].f_5);
1512         gametext_simple(origin.x+((vsi+14)<<16), origin.y+(vdi<<16), dword_AA390);
1513         sprintf(dword_AA390, "%c", bestscore.f_10[0].f_6);
1514         gametext_simple(origin.x+((vsi+28)<<16), origin.y+(vdi<<16), dword_AA390);
1515     }
1516     sprintf(dword_AA390, "%5d", bestscore.f_10[0].f_0);
1517     gametext_simple(origin.x+((vsi+74)<<16), origin.y+(vdi<<16), dword_AA390);
1518     if (dword_AA380 != 2)
1519     {
1520         sprintf(dword_AA390, "%c", bestscore.f_10[1].f_4);
1521         gametext_simple(origin.x+(vsi<<16), origin.y+((vdi+v18)<<16), dword_AA390);
1522         sprintf(dword_AA390, "%c", bestscore.f_10[1].f_5);
1523         gametext_simple(origin.x+((vsi+14)<<16), origin.y+((vdi+v18)<<16), dword_AA390);
1524         sprintf(dword_AA390, "%c", bestscore.f_10[1].f_6);
1525         gametext_simple(origin.x+((vsi+28)<<16), origin.y+((vdi+v18)<<16), dword_AA390);
1526     }
1527     sprintf(dword_AA390, "%5d", bestscore.f_10[1].f_0);
1528     gametext_simple(origin.x+((vsi+74)<<16), origin.y+((vdi+v18)<<16), dword_AA390);
1529     if (dword_AA380 != 3)
1530     {
1531         sprintf(dword_AA390, "%c", bestscore.f_10[2].f_4);
1532         gametext_simple(origin.x+(vsi<<16), origin.y+((vdi+v18*2)<<16), dword_AA390);
1533         sprintf(dword_AA390, "%c", bestscore.f_10[2].f_5);
1534         gametext_simple(origin.x+((vsi+14)<<16), origin.y+((vdi+v18*2)<<16), dword_AA390);
1535         sprintf(dword_AA390, "%c", bestscore.f_10[2].f_6);
1536         gametext_simple(origin.x+((vsi+28)<<16), origin.y+((vdi+v18*2)<<16), dword_AA390);
1537     }
1538     sprintf(dword_AA390, "%5d", bestscore.f_10[2].f_0);
1539     gametext_simple(origin.x+((vsi+74)<<16), origin.y+((vdi+v18*2)<<16), dword_AA390);
1540     if (dword_AA380 != 4)
1541     {
1542         sprintf(dword_AA390, "%c", bestscore.f_10[3].f_4);
1543         gametext_simple(origin.x+(vsi<<16), origin.y+((vdi+v18*3)<<16), dword_AA390);
1544         sprintf(dword_AA390, "%c", bestscore.f_10[3].f_5);
1545         gametext_simple(origin.x+((vsi+14)<<16), origin.y+((vdi+v18*3)<<16), dword_AA390);
1546         sprintf(dword_AA390, "%c", bestscore.f_10[3].f_6);
1547         gametext_simple(origin.x+((vsi+28)<<16), origin.y+((vdi+v18*3)<<16), dword_AA390);
1548     }
1549     sprintf(dword_AA390, "%5d", bestscore.f_10[3].f_0);
1550     gametext_simple(origin.x+((vsi+74)<<16), origin.y+((vdi+v18*3)<<16), dword_AA390);
1551     if (dword_AA380 != 5)
1552     {
1553         sprintf(dword_AA390, "%c", bestscore.f_10[4].f_4);
1554         gametext_simple(origin.x+(vsi<<16), origin.y+((vdi+v18*4)<<16), dword_AA390);
1555         sprintf(dword_AA390, "%c", bestscore.f_10[4].f_5);
1556         gametext_simple(origin.x+((vsi+14)<<16), origin.y+((vdi+v18*4)<<16), dword_AA390);
1557         sprintf(dword_AA390, "%c", bestscore.f_10[4].f_6);
1558         gametext_simple(origin.x+((vsi+28)<<16), origin.y+((vdi+v18*4)<<16), dword_AA390);
1559     }
1560     sprintf(dword_AA390, "%5d", bestscore.f_10[4].f_0);
1561     gametext_simple(origin.x+((vsi+74)<<16), origin.y+((vdi+v18*4)<<16), dword_AA390);
1562 
1563     if (KB_KeyPressed(sc_LeftArrow) || KB_KeyPressed(sc_kpad_4))
1564     {
1565         KB_ClearKeyDown(sc_LeftArrow);
1566         KB_ClearKeyDown(sc_kpad_4);
1567         dword_AA384--;
1568     }
1569     else if (v20 || KB_KeyPressed(sc_RightArrow) || KB_KeyPressed(sc_kpad_6))
1570     {
1571         KB_ClearKeyDown(sc_RightArrow);
1572         KB_ClearKeyDown(sc_kpad_6);
1573         dword_AA384++;
1574     }
1575     if (dword_AA384 < 0)
1576         dword_AA384 = 0;
1577     if (dword_AA384 > 2)
1578         dword_AA384 = 0;
1579     if (dword_AA380)
1580     {
1581         gametext_simple(origin.x+(86<<16), origin.y+(146<<16), "PRESS ESC WHEN DONE");
1582     }
1583 }
1584 
sub_5469C(vec2_t const origin,int a1)1585 void sub_5469C(vec2_t const origin, int a1)
1586 {
1587     unsigned int v20, v1c, v18, v24, vdi, t;
1588     if (a1 == 2)
1589     {
1590         sub_53E4C(origin);
1591         return;
1592     }
1593     rotatesprite_fs(origin.x+(160<<16), origin.y, 65536, 0, dword_AA304, 0, 0, 64+16+10);
1594     if (a1 == 1)
1595     {
1596         v20 = bestscore.f_0;
1597         v1c = bestscore.f_4;
1598         v18 = bestscore.f_c;
1599         v24 = bestscore.f_10[0].f_0;
1600         vdi = bestscore.f_8;
1601     }
1602     else
1603     {
1604         v20 = dword_AA36C;
1605         v1c = dword_AA370;
1606         v18 = dword_AA378;
1607         v24 = dword_AA37C;
1608         vdi = dword_AA374;
1609     }
1610     if (v20 > 0)
1611     {
1612         rotatesprite_fs(origin.x+(4<<16), origin.y, 36864, 0, 1741, 0, 0, 16+10);
1613     }
1614     if (v1c > 0)
1615     {
1616         rotatesprite_fs(origin.x+(98<<16), origin.y+(6<<16), 36864, 0, 1740, 0, 0, 16+10);
1617     }
1618     if (vdi > 0)
1619     {
1620         rotatesprite_fs(origin.x+(172<<16), origin.y+(128<<16), 28576, 0, 1743, 0, 0, 16+10);
1621     }
1622     if (v18 > 0)
1623     {
1624         rotatesprite_fs(origin.x+(232<<16), origin.y+(128<<16), 28576, 0, 1742, 0, 0, 16+10);
1625     }
1626     if (a1 == 0)
1627         gametext_simple(origin.x+(4<<16), origin.y+(104<<16), "SO FAR IN THIS HUNTIN' TRIP...");
1628     else
1629         gametext_simple(origin.x+(4<<16), origin.y+(104<<16), "YOUR BEST TOTALS TO DATE...");
1630 
1631     sprintf(dword_AA390, "BEST DEER:    %2d PTS", v20);
1632     gametext_simple(origin.x+(8<<16), origin.y+(122<<16), dword_AA390);
1633     sprintf(dword_AA390, "BEST BOAR:    %3d  LB", v1c);
1634     gametext_simple(origin.x+(8<<16), origin.y+(136<<16), dword_AA390);
1635     sprintf(dword_AA390, "MOST TURKEYS: %2d    ", vdi);
1636     gametext_simple(origin.x+(8<<16), origin.y+(150<<16), dword_AA390);
1637     sprintf(dword_AA390, "MOST DUCKS:   %2d    ", v18);
1638     gametext_simple(origin.x+(8<<16), origin.y+(164<<16), dword_AA390);
1639     if (a1 == 0)
1640     {
1641         t = dword_AA308 + dword_AA30C + v18;
1642         if (t > 6)
1643             gametext_simple(origin.x+(8<<16), origin.y+(182<<16), "YEAH BABY !");
1644         else if (t > 4)
1645             gametext_simple(origin.x+(8<<16), origin.y+(182<<16), "NICE WORK !");
1646         else if (t > 1)
1647             gametext_simple(origin.x+(8<<16), origin.y+(182<<16), "GOOD JOB !");
1648         else
1649             gametext_simple(origin.x+(8<<16), origin.y+(182<<16), "KEEP TRYIN' !");
1650     }
1651     else
1652     {
1653         sprintf(dword_AA390, "BEST RANGE SCORE: %5d", v24);
1654         gametext_simple(origin.x+(8<<16), origin.y+(182<<16), dword_AA390);
1655     }
1656 }
1657 
sub_54A2C(void)1658 void sub_54A2C(void)
1659 {
1660     int i;
1661     dword_AA300 = 0;
1662     dword_AA304 = 1731+(rrdh_random()%6);
1663     dword_AA308 = 0;
1664     dword_AA30C = 0;
1665     for (i = 0; i < 20; i++)
1666     {
1667         f2B80E0[i].f_0 = -1;
1668         f2B80E0[i].f_2 = 0;
1669         f2B80E0[i].f_4 = 0;
1670         f2B80E0[i].f_8 = 0;
1671         f2B80E0[i].f_c = 0;
1672         f2B80E0[i].f_10 = 0;
1673     }
1674     dword_AA36C = 0;
1675     dword_AA370 = 0;
1676     dword_AA374 = 0;
1677     dword_AA378 = 0;
1678     dword_AA37C = 0;
1679     dword_AA380 = 0;
1680     dword_AA384 = 0;
1681     byte_AA388 = 65;
1682     byte_AA389 = 65;
1683     byte_AA38A = 65;
1684     dword_AA38C = 0;
1685     ghtrophy_loadbestscores();
1686 }
1687 
sub_54B80(void)1688 char sub_54B80(void)
1689 {
1690     switch (KB_GetLastScanCode())
1691     {
1692     case sc_A:
1693         KB_SetLastScanCode(sc_None);
1694         return 'A';
1695     case sc_B:
1696         KB_SetLastScanCode(sc_None);
1697         return 'B';
1698     case sc_C:
1699         KB_SetLastScanCode(sc_None);
1700         return 'C';
1701     case sc_D:
1702         KB_SetLastScanCode(sc_None);
1703         return 'D';
1704     case sc_E:
1705         KB_SetLastScanCode(sc_None);
1706         return 'E';
1707     case sc_F:
1708         KB_SetLastScanCode(sc_None);
1709         return 'F';
1710     case sc_G:
1711         KB_SetLastScanCode(sc_None);
1712         return 'G';
1713     case sc_H:
1714         KB_SetLastScanCode(sc_None);
1715         return 'H';
1716     case sc_I:
1717         KB_SetLastScanCode(sc_None);
1718         return 'I';
1719     case sc_J:
1720         KB_SetLastScanCode(sc_None);
1721         return 'J';
1722     case sc_K:
1723         KB_SetLastScanCode(sc_None);
1724         return 'K';
1725     case sc_L:
1726         KB_SetLastScanCode(sc_None);
1727         return 'L';
1728     case sc_M:
1729         KB_SetLastScanCode(sc_None);
1730         return 'M';
1731     case sc_N:
1732         KB_SetLastScanCode(sc_None);
1733         return 'N';
1734     case sc_O:
1735         KB_SetLastScanCode(sc_None);
1736         return 'O';
1737     case sc_P:
1738         KB_SetLastScanCode(sc_None);
1739         return 'P';
1740     case sc_Q:
1741         KB_SetLastScanCode(sc_None);
1742         return 'Q';
1743     case sc_R:
1744         KB_SetLastScanCode(sc_None);
1745         return 'R';
1746     case sc_S:
1747         KB_SetLastScanCode(sc_None);
1748         return 'S';
1749     case sc_T:
1750         KB_SetLastScanCode(sc_None);
1751         return 'T';
1752     case sc_U:
1753         KB_SetLastScanCode(sc_None);
1754         return 'U';
1755     case sc_V:
1756         KB_SetLastScanCode(sc_None);
1757         return 'V';
1758     case sc_W:
1759         KB_SetLastScanCode(sc_None);
1760         return 'W';
1761     case sc_X:
1762         KB_SetLastScanCode(sc_None);
1763         return 'X';
1764     case sc_Y:
1765         KB_SetLastScanCode(sc_None);
1766         return 'Y';
1767     case sc_Z:
1768         KB_SetLastScanCode(sc_None);
1769         return 'Z';
1770     default:
1771         KB_SetLastScanCode(sc_None);
1772         return ' ';
1773     }
1774     return 0;
1775 }
1776 
1777 char byte_AA394[6] = { 0, 1, 2, 3, 2, 1 };
1778 
1779 int dword_AA39C, dword_AA3A0, dword_AA3A4, dword_AA3A8, dword_AA3AC, dword_AA3B0, dword_AA3B4, dword_AA3B8, dword_AA3BC, dword_AA3C0, dword_AA3C4;
1780 
sub_54D90(void)1781 void sub_54D90(void)
1782 {
1783     rotatesprite(160<<16, 100<<16, 32768, 0, 7063, -24, 0, 32+2+1, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y);
1784 }
1785 
sub_54DE0(void)1786 void sub_54DE0(void)
1787 {
1788     dword_AA3A8 = tilesiz[7050].x;
1789     dword_AA3AC = tilesiz[7050].y;
1790 
1791     if (!waloff[7050])
1792         tileCreate(7050, dword_AA3A8, dword_AA3AC);
1793 }
1794 
ghrender_preparescope(void)1795 void ghrender_preparescope(void)
1796 {
1797     int delta, i, j;
1798     char *ptr;
1799     dword_AA3A4 = 0;
1800     if (!waloff[7050])
1801         return;
1802     dword_AA3B4 = windowxy2.x - windowxy1.x + 1;
1803     dword_AA3B8 = windowxy2.y - windowxy1.y + 1;
1804     if (dword_AA3B4 <= dword_AA3A8 || dword_AA3B8 <= dword_AA3AC)
1805         return;
1806     delta = bytesperline - dword_AA3B4;
1807     if (delta < 0)
1808         G_GameExit("ghrender_preparescope: delta < 0");
1809     delta /= 2;
1810 
1811     dword_AA3B0 = (dword_AA3B8 * bytesperline) / 2;
1812     dword_AA3B0 -= (bytesperline >> 1);
1813     dword_AA3B0 -= delta;
1814     dword_AA3B0 -= (dword_AA3AC >> 1) * bytesperline;
1815     dword_AA3B0 -= (dword_AA3A8 >> 1);
1816     tileCopySection(7051, 0, 0, tilesiz[7051].x, tilesiz[7051].y, 7050, 0, 0);
1817     ptr = (char*)waloff[7050];
1818     if (ptr)
1819     {
1820         for (i = 0; i < dword_AA3A8; i++)
1821         {
1822             for (j = 0; j < dword_AA3AC; j++)
1823             {
1824                 if (*ptr == 0)
1825                     *ptr = 255;
1826                 ptr++;
1827             }
1828         }
1829         dword_AA3A4 = 1;
1830     }
1831 }
1832 
sub_54FA4(int a1,int a2)1833 void sub_54FA4(int a1, int a2)
1834 {
1835     int i, j;
1836     char *ptr1, *ptr2;
1837     if (videoGetRenderMode() >= REND_POLYMOST)
1838         return;
1839     if (!dword_AA3A4)
1840         ghrender_preparescope();
1841     ptr1 = (char*)waloff[7050];
1842     if (!ptr1)
1843         return;
1844     videoBeginDrawing();
1845     ptr2 = (char*)frameplace;
1846     if (!ptr2)
1847         return;
1848     for (i = 0; i < dword_AA3A8; i++)
1849     {
1850         for (j = 0; j < dword_AA3AC; j++)
1851         {
1852             if (*ptr1 != 255)
1853             {
1854                 *ptr1 = ptr2[i*bytesperline+dword_AA3B0+j];
1855             }
1856             ptr1++;
1857         }
1858     }
1859     videoEndDrawing();
1860     rotatesprite(a1<<16, a2<<16, 57344, 512, 7050, 0, 0, 4+2, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y);
1861     rotatesprite(a1<<16, a2<<16, 57344, 512, 7050, -8, 0, 4+2+1, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y);
1862     rotatesprite(a1<<16, a2<<16, 32768, 0, 7063, -24, 0, 32+2+1, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y);
1863 }
1864 
1865 typedef struct _struct2B8280 {
1866     short f_0;
1867     char f_2;
1868 } struct2B8280;
1869 
1870 struct2B8280 f2B8280[MAXSPRITES];
1871 
sub_550F0(void)1872 void sub_550F0(void)
1873 {
1874     int i, sect;
1875     dword_AA3A0 = 0;
1876     for (i = 0; i < MAXSPRITES; i++)
1877     {
1878         f2B8280[i].f_0 = -1;
1879         sect = sprite[i].sectnum;
1880         if (sect >= 0 && sect < numsectors)
1881         {
1882             if (sprite[i].cstat & 2)
1883             {
1884                 if (sector[sect].floorstat & 1)
1885                 {
1886                     f2B8280[dword_AA3A0].f_2 = sprite[i].xrepeat;
1887                     f2B8280[dword_AA3A0].f_0 = i;
1888                     dword_AA3A0++;
1889                 }
1890             }
1891         }
1892     }
1893     dword_AA39C = 0;
1894 }
1895 
ghrender_movewatersprites(void)1896 void ghrender_movewatersprites(void)
1897 {
1898     int i, spr;
1899     if (!sub_57AA0(2))
1900         return;
1901     for (i = 0; i < dword_AA3A0; i++)
1902     {
1903         spr = f2B8280[i].f_0;
1904         if (spr < 0 || spr >= MAXSPRITES)
1905         {
1906             initprintf("ghrender_movewatersprites: bad watersprite sprnum\n");
1907             continue;
1908         }
1909         if (dword_AA39C < 0 || dword_AA39C >= 6)
1910         {
1911             initprintf("ghrender_movewatersprites: currepeat out of range\n");
1912             continue;
1913         }
1914         sprite[spr].xrepeat = f2B8280[i].f_2 + byte_AA394[dword_AA39C];
1915     }
1916     dword_AA39C++;
1917     if (dword_AA39C >= 6)
1918         dword_AA39C = 0;
1919 }
1920 
1921 typedef struct _structAA3D0 {
1922     unsigned int f_0;
1923     int f_4;
1924     int f_8;
1925     int f_c;
1926     int f_10;
1927 } structAA3D0;
1928 
sub_55244(void)1929 void sub_55244(void)
1930 {
1931 }
1932 
sub_5524C(void)1933 void sub_5524C(void)
1934 {
1935 }
1936 
sub_55184(void)1937 void sub_55184(void)
1938 {
1939     sub_550F0();
1940 }
1941 
1942 structAA3D0 fAA3D0[15] = {
1943     1, 2860, 136, 152, 0,
1944     10, 2861, 136, 142, 2,
1945     10, 2862, 136, 142, 5,
1946     10, 2862, 136, 142, 4,
1947     10, 2861, 136, 142, 0,
1948     4, 2863, 144, 162, 5,
1949     16, 2864, 204, 160, 5,
1950     22, 2865, 136, 142, 8,
1951     22, 2869, 136, 142, 9,
1952     22, 2868, 136, 142, 10,
1953     18, 2865, 136, 142, 5,
1954     22, 2865, 136, 142, 12,
1955     22, 2866, 136, 142, 13,
1956     22, 2867, 136, 142, 14,
1957     18, 2865, 136, 142, 5
1958 };
1959 
ghshtgn_setmode(int a1)1960 int ghshtgn_setmode(int a1)
1961 {
1962     if (a1 < 0 || a1 >= 15)
1963         return -1;
1964     if (dword_AA3BC != a1)
1965     {
1966         if ((int)totalclock - dword_AA3C4 > fAA3D0[dword_AA3BC].f_0)
1967         {
1968             switch (dword_AA3BC)
1969             {
1970             case 7:
1971             case 11:
1972                 A_PlaySound(3, g_player[myconnectindex].ps->i);
1973                 break;
1974             case 10:
1975             case 14:
1976                 dword_AA3C0 = 1;
1977                 break;
1978             case 6:
1979                 dword_AA3C0 = 0;
1980                 break;
1981             }
1982             dword_AA3C4 = (int)totalclock;
1983             dword_AA3BC = a1;
1984         }
1985     }
1986     return dword_AA3BC;
1987 }
1988 
1989 int dword_2BB290[MAXSECTORS];
1990 
1991 int dword_AA3C8, dword_AA3CC;
1992 
hitscan_old(int xs,int ys,int zs,int16_t sectnum,int xv,int yv,int zv,int16_t * hitsect,int16_t * hitwall,int16_t * hitsprite,int * xh,int * yh,int * zh,int cm)1993 int hitscan_old(int xs, int ys, int zs, int16_t sectnum, int xv, int yv, int zv, int16_t *hitsect, int16_t *hitwall, int16_t *hitsprite,
1994     int *xh, int *yh, int *zh, int cm)
1995 {
1996     vec3_t s = { xs, ys, zs };
1997     hitdata_t h = { *xh, *yh, *zh, *hitsprite, *hitwall, *hitsect };
1998     int ret = hitscan(&s, sectnum, xv, yv, zv, &h, cm);
1999     *xh = h.pos.x;
2000     *yh = h.pos.y;
2001     *zh = h.pos.z;
2002     *hitsprite = h.sprite;
2003     *hitwall = h.wall;
2004     *hitsect = h.sect;
2005     return ret;
2006 }
2007 
ghshtgn_fire(short snum)2008 void ghshtgn_fire(short snum)
2009 {
2010     DukePlayer_t *p;
2011     short v20 = 0;
2012     short v1c = 0;
2013     short v18 = 0;
2014     int v44 = 0;
2015     int v48 = 0;
2016     int v4c = 0;
2017     int v34, v28, v40, v2c, v24, v38, vdx, vax, vbx, vdi, v3c, v30, i;
2018     short sect;
2019     if (!dword_AA3C0 && dword_AA3BC == 5)
2020         sub_5A250(0x10);
2021 
2022     if (dword_AA3BC == 5 && dword_AA3C0 && ghshtgn_setmode(6) == 6)
2023     {
2024         p = g_player[snum].ps;
2025         A_PlaySound(4, p->i);
2026         v34 = 9;
2027         while (v34 > 0)
2028         {
2029             v28 = p->pos.x;
2030             v40 = p->pos.y;
2031             v2c = p->pos.z + p->pyoff;
2032             if (dword_AA3C8 == 7)
2033             {
2034                 vax = 2;
2035                 vbx = 4;
2036                 v24 = 8;
2037                 vdx = 2048;
2038                 v38 = 4096;
2039             }
2040             else
2041             {
2042                 vax = 2;
2043                 vbx = 2;
2044                 v24 = 4;
2045                 vdx = 512;
2046                 v38 = 1024;
2047             }
2048             vdi = (100 - fix16_to_int(p->q16horiz)) * 2048;
2049             switch (v34)
2050             {
2051             default:
2052                 return;
2053             case 9:
2054                 v3c = sintable[(fix16_to_int(p->q16ang) + vax - vbx + 512) & 2047];
2055                 v30 = sintable[(fix16_to_int(p->q16ang) + vax - vbx) & 2047];
2056                 vdi += vdx;
2057                 break;
2058             case 8:
2059                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + vbx + 512) & 2047];
2060                 v30 = sintable[(fix16_to_int(p->q16ang) + vax + vbx) & 2047];
2061                 vdi += vdx;
2062                 break;
2063             case 7:
2064                 v3c = sintable[(fix16_to_int(p->q16ang) + vax - vbx + 512) & 2047];
2065                 v30 = sintable[(fix16_to_int(p->q16ang) + vax - vbx) & 2047];
2066                 vdi -= vdx;
2067                 break;
2068             case 6:
2069                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + vbx + 512) & 2047];
2070                 v30 = sintable[(fix16_to_int(p->q16ang) + vax + vbx) & 2047];
2071                 vdi -= vdx;
2072                 break;
2073             case 5:
2074                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + 512) & 2047];
2075                 v30 = sintable[(fix16_to_int(p->q16ang) + vax) & 2047];
2076                 vdi -= v38;
2077                 break;
2078             case 4:
2079                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + 512) & 2047];
2080                 v30 = sintable[(fix16_to_int(p->q16ang) + vax) & 2047];
2081                 vdi += v38;
2082                 break;
2083             case 3:
2084                 v3c = sintable[(fix16_to_int(p->q16ang) + vax - v24 + 512) & 2047];
2085                 v30 = sintable[(fix16_to_int(p->q16ang) + vax - v24) & 2047];
2086                 break;
2087             case 2:
2088                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + v24 + 512) & 2047];
2089                 v30 = sintable[(fix16_to_int(p->q16ang) + vax + v24) & 2047];
2090                 break;
2091             case 1:
2092                 v3c = sintable[(fix16_to_int(p->q16ang) + vax + 512) & 2047];
2093                 v30 = sintable[(fix16_to_int(p->q16ang) + vax) & 2047];
2094                 break;
2095             }
2096             for (i = 0; i < numsectors; i++)
2097             {
2098                 dword_2BB290[i] = sector[i].ceilingz;
2099                 sector[i].ceilingz = -0x64000;
2100             }
2101             hitscan_old(v28, v40, v2c, p->cursectnum, v3c, v30, vdi, &v20, &v18, &v1c, &v44, &v48, &v4c, CLIPMASK1);
2102             for (i = 0; i < numsectors; i++)
2103             {
2104                 sector[i].ceilingz = dword_2BB290[i];
2105             }
2106             v34--;
2107             if (v20 < 0)
2108             {
2109                 initprintf("WARNING: ghshtgn_fire hitsect < 0\n");
2110                 return;
2111             }
2112             sub_51678(v18, v1c, v20, v44, v48, v4c);
2113             if (v1c >= 0)
2114             {
2115                 if (sprite[v1c].cstat == (short)32768)
2116                 {
2117                     initprintf("ERROR: hit spr with cstat 32768\n");
2118                     return;
2119                 }
2120                 sect = sprite[v1c].sectnum;
2121                 if (sector[sect].hitag == 2000)
2122                 {
2123                     initprintf("ERROR: hit spr in REST_AREA sector\n");
2124                     return;
2125                 }
2126                 ghtrophy_addkill(v1c);
2127                 ghtarget_hit(v1c, dword_AA3C8);
2128             }
2129             else
2130                 sub_5A250(4);
2131         }
2132     }
2133 }
2134 
sub_558D0(void)2135 void sub_558D0(void)
2136 {
2137     if (!dword_AA3BC)
2138         ghshtgn_setmode(1);
2139     else
2140         ghshtgn_setmode(3);
2141 }
2142 
sub_558F4(void)2143 void sub_558F4(void)
2144 {
2145     dword_AA3CC = 1;
2146     ghshtgn_setmode(0);
2147     dword_AA3C8 = 6;
2148     dword_AA3C0 = 0;
2149 }
2150 
sub_55928(void)2151 int sub_55928(void)
2152 {
2153     return dword_AA3C8;
2154 }
2155 
sub_55934(void)2156 void sub_55934(void)
2157 {
2158     if (dword_AA3BC == 0 || dword_AA3BC == 5)
2159     {
2160         sub_5A250(0x4000);
2161         dword_AA3C0 = 0;
2162         sub_55988();
2163         dword_AA3C8 = 6 + (dword_AA3C8 == 6);
2164     }
2165 }
2166 
sub_55988(void)2167 void sub_55988(void)
2168 {
2169     int pframe;
2170     if (dword_AA3BC == 0 || dword_AA3BC == 5)
2171     {
2172         pframe = dword_AA3BC;
2173         if (dword_AA3CC)
2174         {
2175             if (ghshtgn_setmode(7) == 7)
2176                 fAA3D0[10].f_10 = pframe;
2177             dword_AA3CC = 0;
2178         }
2179         else
2180         {
2181             if (ghshtgn_setmode(11) == 11)
2182                 fAA3D0[14].f_10 = pframe;
2183         }
2184     }
2185 }
2186 
2187 unsigned int dword_AA53C;
2188 int dword_AA540;
2189 
2190 int dword_AA4FC[] = {
2191     0, -1, -2, -3, -4, -3, -2, -1
2192 };
2193 
2194 int dword_AA51C[] = {
2195     0, -1, -2, -2, -1, -2, -2, -1
2196 };
2197 
ghshtgn_render(short snum)2198 void ghshtgn_render(short snum)
2199 {
2200     int vdx;
2201     if (dword_AA3BC < 0 || dword_AA3BC >= 15)
2202     {
2203         initprintf("ERROR: ghshtgn_draw bad index\n");
2204         return;
2205     }
2206     if (snum < 0 || snum >= numplayers)
2207     {
2208         initprintf("ERROR: ghshtgn_render bad index\n");
2209         return;
2210     }
2211     DukePlayer_t* p = g_player[snum].ps;
2212     if (p->dhat613 || p->dhat617)
2213     {
2214         vdx = 10;
2215         if (p->dhat617)
2216             vdx = 5;
2217         if ((int)totalclock - dword_AA53C > vdx)
2218         {
2219             dword_AA540++;
2220             if (dword_AA540 >= 8)
2221                 dword_AA540 = 0;
2222             dword_AA53C = (int)totalclock;
2223         }
2224     }
2225     else
2226     {
2227         if (dword_AA540)
2228             dword_AA540++;
2229         if (dword_AA540 >= 8)
2230             dword_AA540 = 0;
2231     }
2232     if (dword_AA540 >= 8)
2233     {
2234         initprintf("ERROR: ghshtgn_render bobcnt out of bounds\n");
2235         return;
2236     }
2237     sub_54D90();
2238     rotatesprite_win((fAA3D0[dword_AA3BC].f_8+dword_AA4FC[dword_AA540])<<16,
2239         (fAA3D0[dword_AA3BC].f_c+dword_AA51C[dword_AA540]+17)<<16, 40960,
2240         0, fAA3D0[dword_AA3BC].f_4, 0, 0, 2);
2241     if (dword_AA3BC == 5 && p->dhat617)
2242         ghshtgn_setmode(3);
2243     else
2244         ghshtgn_setmode(fAA3D0[dword_AA3BC].f_10);
2245 }
2246 
2247 int dword_AA544, dword_AA548;
2248 unsigned int dword_AA54C;
2249 
2250 structAA3D0 fAA558[17] = {
2251     1, 2816, 135, 152, 0,
2252     10, 2822, 135, 132, 2,
2253     10, 2817, 135, 132, 5,
2254     10, 2817, 135, 132, 4,
2255     10, 2822, 135, 132, 0,
2256     4, 2818, 144, 130, 5,
2257     16, 2819, 144, 130, 5,
2258     28, 2817, 135, 132, 8,
2259     28, 2823, 135, 132, 9,
2260     28, 2824, 135, 132, 10,
2261     28, 2823, 135, 132, 11,
2262     28, 2817, 135, 132, 5,
2263     28, 2817, 135, 132, 13,
2264     28, 2820, 135, 132, 14,
2265     28, 2821, 135, 132, 15,
2266     28, 2823, 135, 132, 16,
2267     28, 2817, 135, 132, 5
2268 };
2269 
2270 structAA3D0 fAA6AC[17] = {
2271     1, 2830, 135, 152, 0,
2272     10, 2831, 135, 132, 2,
2273     10, 2832, 135, 132, 5,
2274     10, 2832, 135, 132, 4,
2275     10, 2831, 135, 132, 0,
2276     4, 2833, 146, 136, 5,
2277     16, 2834, 146, 136, 5,
2278     28, 2832, 135, 132, 8,
2279     28, 2837, 135, 132, 9,
2280     28, 2838, 135, 132, 10,
2281     28, 2837, 135, 132, 11,
2282     28, 2832, 135, 132, 5,
2283     28, 2832, 135, 132, 13,
2284     28, 2836, 135, 132, 14,
2285     28, 2835, 135, 132, 15,
2286     28, 2837, 135, 132, 16,
2287     28, 2832, 135, 132, 5
2288 };
2289 
ghrifle_setmode(int a1)2290 int ghrifle_setmode(int a1)
2291 {
2292     if (a1 < 0 || a1 >= 17)
2293         return -1;
2294     if (dword_AA544 != a1)
2295     {
2296         if ((int)totalclock - dword_AA54C > fAA558[dword_AA544].f_0)
2297         {
2298             switch (dword_AA544)
2299             {
2300             case 7:
2301             case 12:
2302                 A_PlaySound(5, g_player[myconnectindex].ps->i);
2303                 break;
2304             case 11:
2305             case 16:
2306                 dword_AA548 = 1;
2307                 break;
2308             case 6:
2309                 dword_AA548 = 0;
2310                 break;
2311             }
2312             dword_AA54C = (int)totalclock;
2313             dword_AA544 = a1;
2314         }
2315     }
2316     return dword_AA544;
2317 }
2318 
2319 int dword_2BC2A0[MAXSECTORS];
2320 int dword_AA550, dword_AA554;
2321 
ghrifle_fire(short snum)2322 void ghrifle_fire(short snum)
2323 {
2324     DukePlayer_t *p;
2325     short v20 = 0;
2326     short v1c = 0;
2327     short v18 = 0;
2328     int v44 = 0;
2329     int v48 = 0;
2330     int v4c = 0;
2331     int v28, v40, v2c, vdi, v3c, v30, i;
2332     short sect;
2333     if (!dword_AA548 && dword_AA544 == 5)
2334         sub_5A250(0x10);
2335 
2336     if (dword_AA548 && dword_AA544 == 5 && ghrifle_setmode(6) == 6)
2337     {
2338         p = g_player[snum].ps;
2339         A_PlaySound(6, p->i);
2340         v28 = p->pos.x;
2341         v40 = p->pos.y;
2342         v2c = p->pos.z + p->pyoff;
2343         v3c = sintable[(fix16_to_int(p->q16ang) + 512) & 2047];
2344         v30 = sintable[(fix16_to_int(p->q16ang)) & 2047];
2345         vdi = (100 - fix16_to_int(p->q16horiz)) * 2048;
2346         for (i = 0; i < numsectors; i++)
2347         {
2348             dword_2BC2A0[i] = sector[i].ceilingz;
2349             sector[i].ceilingz = -0x64000;
2350         }
2351         hitscan_old(v28, v40, v2c, p->cursectnum, v3c, v30, vdi, &v20, &v18, &v1c, &v44, &v48, &v4c, CLIPMASK1);
2352         for (i = 0; i < numsectors; i++)
2353         {
2354             sector[i].ceilingz = dword_2BC2A0[i];
2355         }
2356         if (v20 < 0)
2357         {
2358             initprintf("WARNING: ghrifle_fire hitsect < 0\n");
2359             return;
2360         }
2361         sub_51678(v18, v1c, v20, v44, v48, v4c);
2362         if (v1c >= 0)
2363         {
2364             if (sprite[v1c].cstat == (short)32768)
2365             {
2366                 initprintf("ERROR: hit spr with cstat 32768\n");
2367                 return;
2368             }
2369             sect = sprite[v1c].sectnum;
2370             if (sector[sect].hitag == 2000)
2371             {
2372                 initprintf("ERROR: hit spr in REST_AREA sector\n");
2373                 return;
2374             }
2375             ghtrophy_addkill(v1c);
2376             ghtarget_hit(v1c, dword_AA550);
2377         }
2378         else
2379             sub_5A250(4);
2380     }
2381 }
2382 
sub_55F68(void)2383 void sub_55F68(void)
2384 {
2385     if (dword_AA544 == 0)
2386         ghrifle_setmode(1);
2387     else
2388         ghrifle_setmode(3);
2389 }
2390 
sub_55F8C(void)2391 void sub_55F8C(void)
2392 {
2393     dword_AA554 = 1;
2394     ghrifle_setmode(0);
2395     dword_AA550 = 4;
2396     dword_AA548 = 0;
2397 }
2398 
sub_55FC0(void)2399 int sub_55FC0(void)
2400 {
2401     return dword_AA550;
2402 }
2403 
sub_55FCC(void)2404 void sub_55FCC(void)
2405 {
2406     if (dword_AA544 == 0 || dword_AA544 == 5)
2407     {
2408         sub_5A250(0x4000);
2409         dword_AA548 = 0;
2410         sub_56020();
2411         dword_AA550 = 4 + (dword_AA550 == 4);
2412     }
2413 }
2414 
sub_56020(void)2415 void sub_56020(void)
2416 {
2417     int pframe;
2418     if (dword_AA544 == 0 || dword_AA544 == 5)
2419     {
2420         pframe = dword_AA544;
2421         if (dword_AA554)
2422         {
2423             if (ghrifle_setmode(7) == 7)
2424                 fAA558[11].f_10 = pframe;
2425             dword_AA554 = 0;
2426         }
2427         else
2428         {
2429             if (ghrifle_setmode(12) == 12)
2430                 fAA558[16].f_10 = pframe;
2431         }
2432     }
2433 }
2434 
2435 unsigned int dword_AA840;
2436 int dword_AA844;
2437 
2438 int dword_AA800[] = {
2439     0, -1, -2, -3, -4, -3, -2, -1
2440 };
2441 
2442 int dword_AA820[] = {
2443     0, -1, -2, -2, -1, -2, -2, -1
2444 };
2445 
ghrifle_render(short snum,int a2)2446 void ghrifle_render(short snum, int a2)
2447 {
2448     int vdx, tile, x, y;
2449     if (dword_AA544 < 0 || dword_AA544 >= 17)
2450     {
2451         initprintf("ERROR: ghrifle_draw bad index\n");
2452         return;
2453     }
2454     if (snum < 0 || snum >= numplayers)
2455     {
2456         initprintf("ERROR: ghrifle_render bad index\n");
2457         return;
2458     }
2459     DukePlayer_t* p = g_player[snum].ps;
2460     if (p->dhat613 || p->dhat617)
2461     {
2462         vdx = 10;
2463         if (p->dhat617)
2464             vdx = 5;
2465         if ((int)totalclock - dword_AA840 > vdx)
2466         {
2467             dword_AA844++;
2468             if (dword_AA844 >= 8)
2469                 dword_AA844 = 0;
2470             dword_AA840 = (int)totalclock;
2471         }
2472     }
2473     else
2474     {
2475         if (dword_AA844)
2476             dword_AA844++;
2477         if (dword_AA844 >= 8)
2478             dword_AA844 = 0;
2479     }
2480     if (dword_AA844 >= 8)
2481     {
2482         initprintf("ERROR: ghrifle_render bobcnt out of bounds\n");
2483         return;
2484     }
2485 
2486     if (a2 == 1)
2487     {
2488         x = fAA558[dword_AA544].f_8 + dword_AA800[dword_AA844];
2489         y = fAA558[dword_AA544].f_c + dword_AA820[dword_AA844] + 17;
2490         tile = fAA558[dword_AA544].f_4;
2491     }
2492     else
2493     {
2494         x = fAA6AC[dword_AA544].f_8 + dword_AA800[dword_AA844];
2495         y = fAA6AC[dword_AA544].f_c + dword_AA820[dword_AA844] + 17;
2496         tile = fAA6AC[dword_AA544].f_4;
2497     }
2498 
2499     if (dword_AA544 == 5 && a2 == 1)
2500         sub_54FA4(160+dword_AA800[dword_AA844], 100+dword_AA820[dword_AA844]);
2501     else
2502         sub_54D90();
2503 
2504     rotatesprite_win(x<<16, y<<16, 32768, 0, tile, 0, 0, 2);
2505 
2506     if (a2 == 1 && dword_AA544 == 5 && (p->dhat613 || p->dhat617))
2507     {
2508         ghrifle_setmode(3);
2509     }
2510     else
2511     {
2512         if (dword_AA544 == 5 && p->dhat617)
2513             ghrifle_setmode(3);
2514         else
2515             ghrifle_setmode(fAA558[dword_AA544].f_10);
2516     }
2517 }
2518 
2519 int dword_AA848;
2520 int dword_AA84C;
2521 unsigned int dword_AA850;
2522 int dword_AA854;
2523 
2524 structAA3D0 fAA858[15] = {
2525     1, 3328, 198, 152, 0,
2526     4, 3329, 198, 132, 2,
2527     4, 3330, 198, 132, 3,
2528     4, 3331, 198, 136, 4,
2529     4, 3332, 198, 136, 5,
2530     4, 3333, 198, 132, 6,
2531     4, 3334, 198, 132, 7,
2532     4, 3333, 198, 132, 8,
2533     4, 3332, 198, 132, 9,
2534     4, 3331, 198, 132, 0,
2535     12, 3336, 198, 132, 11,
2536     12, 3337, 198, 132, 12,
2537     12, 3338, 198, 132, 13,
2538     12, 3337, 198, 132, 14,
2539     12, 3336, 198, 132, 0
2540 };
2541 
2542 int dword_AA984[] = {
2543     0, -1, -2, -3, -4, -3, -2, -1
2544 };
2545 int dword_AA9A4[] = {
2546     0, -1, -2, -2, -1, -2, -2, -1
2547 };
2548 
ghpistol_setmode(int a1)2549 int ghpistol_setmode(int a1)
2550 {
2551     if (a1 < 0 || a1 >= 15)
2552         return 0;
2553     if (a1 != dword_AA848)
2554     {
2555         if ((int)totalclock - dword_AA850 > fAA858[dword_AA848].f_0)
2556         {
2557             switch (dword_AA848)
2558             {
2559             case 10:
2560                 A_PlaySound(1, g_player[myconnectindex].ps->i);
2561                 break;
2562             case 14:
2563                 dword_AA84C = 6;
2564                 break;
2565             case 2:
2566                 if (!dword_AA84C)
2567                 {
2568                     initprintf("ghpistol_setmode: pistolloaded at 0\n");
2569                 }
2570                 else
2571                     dword_AA84C--;
2572                 break;
2573             }
2574             dword_AA850 = (int)totalclock;
2575             dword_AA848 = a1;
2576         }
2577 
2578     }
2579     return dword_AA848;
2580 }
2581 
2582 int dword_2BD2B0[MAXSECTORS];
2583 
ghpistol_fire(short snum)2584 void ghpistol_fire(short snum)
2585 {
2586     DukePlayer_t *p;
2587     short v18 = 0;
2588     short v1c = 0;
2589     short v20 = 0;
2590     int v38 = 0;
2591     int v3c = 0;
2592     int v40 = 0;
2593     int v30, v34, v2c, vdx, vbx, v28, v24, vsi, i;
2594     if (dword_AA84C == 0 && dword_AA848 == 0)
2595         sub_5A250(16);
2596     if (dword_AA84C && dword_AA848 == 0 && ghpistol_setmode(1) == 1)
2597     {
2598         p = g_player[snum].ps;
2599         A_PlaySound(2, p->i);
2600         v30 = p->pos.x;
2601         v34 = p->pos.y;
2602         v2c = p->pos.z + p->pyoff;
2603         if (dword_AA854 == 3)
2604         {
2605             vdx = 4 - (rrdh_random() & 7);
2606             vbx = 2047 - (rrdh_random() & 2047);
2607         }
2608         else
2609         {
2610             vdx = 8 - (rrdh_random() & 15);
2611             vbx = 2048 - (rrdh_random() & 2048);
2612         }
2613         vdx += 2;
2614         v24 = sintable[(fix16_to_int(p->q16ang) + vdx + 512) & 2047];
2615         v28 = sintable[(fix16_to_int(p->q16ang) + vdx) & 2047];
2616         vsi = ((100 - fix16_to_int(p->q16horiz)) << 11) + vbx;
2617 
2618         for (i = 0; i < MAXSECTORS; i++)
2619         {
2620             dword_2BD2B0[i] = sector[i].ceilingz;
2621             sector[i].ceilingz = -0x64000;
2622         }
2623         hitscan_old(v30, v34, v2c, p->cursectnum, v24, v28, vsi, &v18, &v20, &v1c, &v38, &v3c, &v40, CLIPMASK1);
2624         for (i = 0; i < MAXSECTORS; i++)
2625         {
2626             sector[i].ceilingz = dword_2BD2B0[i];
2627         }
2628         if (v18 < 0)
2629         {
2630             initprintf("WARNING: ghpistol_fire hitsect < 0\n");
2631             return;
2632         }
2633         sub_51678(v28, v1c, v18, v38, v3c, v40);
2634         if (v1c >= 0)
2635         {
2636             if (sprite[v1c].cstat == (short)32768)
2637             {
2638                 initprintf("ERROR: hit spr with cstat 32768\n");
2639                 return;
2640             }
2641             if (sector[sprite[v1c].sectnum].hitag == 2000)
2642             {
2643                 initprintf("ERROR: hit spr in REST_AREA sector\n");
2644                 return;
2645             }
2646             ghtrophy_addkill(v1c);
2647             ghtarget_hit(v1c, dword_AA854);
2648         }
2649         else
2650             sub_5A250(4);
2651     }
2652 
2653 }
2654 
sub_566E8(void)2655 void sub_566E8(void)
2656 {
2657 }
2658 
sub_566F0(void)2659 void sub_566F0(void)
2660 {
2661     ghpistol_setmode(0);
2662     dword_AA854 = 2;
2663     dword_AA84C = 0;
2664 }
2665 
sub_56718(void)2666 int sub_56718(void)
2667 {
2668     return dword_AA854;
2669 }
2670 
sub_56724(void)2671 void sub_56724(void)
2672 {
2673     if (dword_AA848 == 0)
2674     {
2675         sub_5A250(0x4000);
2676         dword_AA84C = 0;
2677         if (dword_AA848 == 0)
2678             ghpistol_setmode(10);
2679         dword_AA854 = 2 + (dword_AA854 == 2);
2680     }
2681 }
2682 
sub_56780(void)2683 void sub_56780(void)
2684 {
2685     if (dword_AA848 == 0 && dword_AA84C != 6)
2686         ghpistol_setmode(10);
2687 }
2688 
2689 unsigned int dword_AA9C4;
2690 
2691 int dword_AA9C8;
2692 
ghpistol_render(short snum)2693 void ghpistol_render(short snum)
2694 {
2695     int vdx;
2696     if (dword_AA848 < 0 || dword_AA848 >= 15)
2697     {
2698         initprintf("ERROR: ghpistol_draw bad index\n");
2699         return;
2700     }
2701     if (snum < 0 || snum >= numplayers)
2702     {
2703         initprintf("ERROR: ghpistol_render bad index\n");
2704         return;
2705     }
2706     DukePlayer_t *p = g_player[snum].ps;
2707     if (p->dhat613 || p->dhat617)
2708     {
2709         vdx = 10;
2710         if (p->dhat617)
2711             vdx = 5;
2712 
2713         if ((int)totalclock - dword_AA9C4 > vdx)
2714         {
2715             dword_AA9C8++;
2716             if (dword_AA9C8 >= 8)
2717                 dword_AA9C8 = 0;
2718             dword_AA9C4 = (int)totalclock;
2719         }
2720     }
2721     else
2722     {
2723         if (dword_AA9C8)
2724             dword_AA9C8++;
2725         if (dword_AA9C8 >= 8)
2726             dword_AA9C8 = 0;
2727     }
2728     if (dword_AA9C8 >= 8)
2729     {
2730         initprintf("ERROR: ghpistol_render bobcnt out of bounds\n");
2731         return;
2732     }
2733     sub_54D90();
2734     rotatesprite_win((fAA858[dword_AA848].f_8+dword_AA984[dword_AA9C8])<<16,
2735         (fAA858[dword_AA848].f_c+dword_AA9A4[dword_AA9C8]+17)<<16, 40960,
2736         0, fAA858[dword_AA848].f_4, 0, 0, 2);
2737     ghpistol_setmode(fAA858[dword_AA848].f_10);
2738 }
2739 
2740 int dword_AA9CC;
2741 unsigned int dword_AA9D4;
2742 
2743 structAA3D0 fAA9DC[7] = {
2744     1, 3454, 216, 158, 0,
2745     4, 3452, 216, 162, 1,
2746     4, 3453, 216, 158, 3,
2747     12, 3455, 216, 158, 0,
2748     12, 3456, 216, 132, 5,
2749     12, 3457, 216, 132, 6,
2750     12, 3458, 216, 132, 1
2751 };
2752 
2753 int dword_AAA68[] = {
2754     0, -1, -2, -3, -4, -3, -2, -1
2755 };
2756 
2757 int dword_AAA88[] = {
2758     0, -1, -2, -2, -1, -2, -2, -1
2759 };
2760 
2761 int dword_AA9D0;
2762 
ghbow_setmode(int a1)2763 int ghbow_setmode(int a1)
2764 {
2765     if (a1 < 0 || a1 >= 7)
2766     {
2767         initprintf("ERROR: ghbow_setmode %i\n", a1);
2768         return 0;
2769     }
2770     if (dword_AA9CC != a1)
2771     {
2772         if ((int)totalclock - dword_AA9D4 > fAA9DC[dword_AA9CC].f_0)
2773         {
2774             switch (dword_AA9CC)
2775             {
2776             case 4:
2777                 A_PlaySound(7, g_player[myconnectindex].ps->i);
2778                 break;
2779             case 6:
2780                 dword_AA9D0 = 1;
2781                 break;
2782             case 2:
2783                 dword_AA9D0 = 0;
2784                 break;
2785             }
2786             dword_AA9D4 = (int)totalclock;
2787             dword_AA9CC = a1;
2788         }
2789     }
2790     return dword_AA9CC;
2791 }
2792 
ghbow_fire(short snum)2793 void ghbow_fire(short snum)
2794 {
2795     struct player_struct *p;
2796     if (!dword_AA9D0)
2797     {
2798         if (dword_AA9CC == 1 || dword_AA9CC == 0)
2799             sub_5A250(0x10);
2800     }
2801     if (dword_AA9D0 && dword_AA9CC == 1 && ghbow_setmode(2) == 2)
2802     {
2803         A_PlaySound(8, g_player[myconnectindex].ps->i);
2804         gharrow_spawnarrow(snum);
2805     }
2806 }
2807 
sub_56AB0(void)2808 void sub_56AB0(void)
2809 {
2810 }
2811 
2812 int dword_AA9D8;
2813 
sub_56AB8(void)2814 void sub_56AB8(void)
2815 {
2816     ghbow_setmode(0);
2817     dword_AA9D8 = 0;
2818     dword_AA9D0 = 0;
2819 }
2820 
sub_56AD8(void)2821 int sub_56AD8(void)
2822 {
2823     return dword_AA9D8;
2824 }
2825 
sub_56AE4(void)2826 void sub_56AE4(void)
2827 {
2828     if (dword_AA9CC == 0)
2829     {
2830         sub_5A250(0x4000);
2831         dword_AA9D0 = 0;
2832         if (dword_AA9CC == 0)
2833             ghbow_setmode(4);
2834         dword_AA9D8 = (dword_AA9D8 == 0);
2835     }
2836 }
2837 
sub_56B3C(void)2838 void sub_56B3C(void)
2839 {
2840     if (dword_AA9CC == 0 && dword_AA9D0 != 1)
2841         ghbow_setmode(4);
2842 }
2843 
2844 unsigned int dword_AAAA8;
2845 int dword_AAAAC;
2846 
ghbow_render(short snum)2847 void ghbow_render(short snum)
2848 {
2849     int vdx;
2850     if (dword_AA9CC < 0 || dword_AA9CC >= 7)
2851     {
2852         initprintf("ERROR: ghbow_draw bad index\n");
2853         return;
2854     }
2855     if (snum < 0 || snum >= numplayers)
2856     {
2857         initprintf("ERROR: ghbow_render bad index\n");
2858         return;
2859     }
2860     DukePlayer_t *p = g_player[snum].ps;
2861     if (p->dhat613 || p->dhat617)
2862     {
2863         vdx = 10;
2864         if (p->dhat617)
2865             vdx = 5;
2866 
2867         if ((int)totalclock - dword_AAAA8 > vdx)
2868         {
2869             dword_AAAAC++;
2870             if (dword_AAAAC >= 8)
2871                 dword_AAAAC = 0;
2872             dword_AAAA8 = (int)totalclock;
2873         }
2874     }
2875     else
2876     {
2877         if (dword_AAAAC)
2878             dword_AAAAC++;
2879         if (dword_AAAAC >= 8)
2880             dword_AAAAC = 0;
2881     }
2882     if (dword_AAAAC >= 8)
2883     {
2884         initprintf("ERROR: ghbow_render bobcnt out of bounds\n");
2885         return;
2886     }
2887     sub_54D90();
2888     rotatesprite_win((fAA9DC[dword_AA9CC].f_8+dword_AAA68[dword_AAAAC])<<16,
2889         (fAA9DC[dword_AA9CC].f_c+dword_AAA88[dword_AAAAC]+17)<<16, 40960,
2890         0, fAA9DC[dword_AA9CC].f_4, 0, 0, 2);
2891     ghbow_setmode(fAA9DC[dword_AA9CC].f_10);
2892 }
2893 
sub_56CF0(int a1)2894 int sub_56CF0(int a1)
2895 {
2896     if (a1 < 0 || a1 >= numsectors)
2897         return 0;
2898     return 1;
2899 }
2900 
ghprecip_snowfall(void)2901 void ghprecip_snowfall(void)
2902 {
2903     DukePlayer_t *p;
2904     int i, nexti, j;
2905     spritetype *s;
2906     short sect, v18;
2907     int vdi, vsi, v28;
2908     p = g_player[screenpeek].ps;
2909 
2910     i = headspritestat[801];
2911     while (i >= 0)
2912     {
2913         nexti = nextspritestat[i];
2914         s = &sprite[i];
2915         s->z += 0x300;
2916         sect = s->sectnum;
2917         if (sect < 0 || sect >= numsectors)
2918         {
2919             initprintf("ghprecip_snowfall: bad sectnum\n");
2920             goto BOLT;
2921         }
2922         if (s->z > sector[sect].floorz)
2923         {
2924             vdi = p->pos.x + (rrdh_random() & 0x3fff) - 0x2000;
2925             vsi = p->pos.y + (rrdh_random() & 0x3fff) - 0x2000;
2926             v28 = -0x19000;
2927             v18 = -1;
2928             for (j = 0; j < numsectors; j++)
2929             {
2930                 if (inside(vdi, vsi, j))
2931                 {
2932                     if (sub_56CF0(j))
2933                     {
2934                         v18 = j;
2935                         break;
2936                     }
2937                 }
2938             }
2939             if (v18 >= 0 && v18 < numsectors)
2940             {
2941                 s->x = vdi;
2942                 s->y = vsi;
2943                 s->z = v28;
2944                 changespritestat(i, v18);
2945                 if (v18 != s->sectnum)
2946                 {
2947                     initprintf("changespritesect failed\n");
2948                 }
2949             }
2950         }
2951 BOLT:
2952         i = nexti;
2953     }
2954 }
2955 
sub_56EA8(void)2956 void sub_56EA8(void)
2957 {
2958     ghprecip_snowfall();
2959 }
2960 
2961 
sub_56EC0(void)2962 void sub_56EC0(void)
2963 {
2964     short i;
2965     i = headspritestat[802];
2966     while (i >= 0)
2967     {
2968         sprite[i].extra++;
2969         i = nextspritestat[i];
2970     }
2971 }
2972 
2973 int dword_AAAB8 = 0x180;
2974 int dword_AAAB0;
2975 
ghtrax_getoldestdeertrax(void)2976 short ghtrax_getoldestdeertrax(void)
2977 {
2978     short i, nexti, vcx, vsi;
2979     vcx = -1;
2980     vsi = 0;
2981     i = headspritestat[802];
2982     while (i >= 0)
2983     {
2984         nexti = nextspritestat[i];
2985         if (vcx < sprite[i].extra)
2986         {
2987             vcx = sprite[i].extra;
2988             vsi = i;
2989         }
2990         if (sprite[i].extra > dword_AAAB8)
2991         {
2992             initprintf("ghtrax_getoldestdeertrax: oldest trax at %i\n", sprite[i].extra);
2993         }
2994         i = nexti;
2995     }
2996     return vsi;
2997 }
2998 
ghtrax_deertrax(short a1)2999 void ghtrax_deertrax(short a1)
3000 {
3001     spritetype *s, *s2;
3002     int v24 = 0;
3003     int v28 = 0;
3004     int v2c = 0;
3005     int v30 = 0;
3006     short v18, i, nexti;
3007     s = &sprite[a1];
3008     if (dword_AAAB8 > dword_AAAB0)
3009     {
3010         v18 = insertsprite(s->sectnum, 0);
3011         if (v18 < 0 || v18 >= MAXSPRITES)
3012         {
3013             initprintf("ghtrax_deertrax: insertsprite failed\n");
3014             dword_AAAB8 = dword_AAAB0;
3015             initprintf("                 set maxtraxdeer to %i\n", dword_AAAB8);
3016         }
3017         else
3018             dword_AAAB0++;
3019     }
3020     else
3021     {
3022         v18 = ghtrax_getoldestdeertrax();
3023         if (v18 < 0 || v18 >= MAXSPRITES)
3024         {
3025             initprintf("ghtrax_deertrax: invalid oldest trax sprite\n");
3026             return;
3027         }
3028     }
3029     sub_56EC0();
3030     s2 = &sprite[v18];
3031     getzrange_old(s->x, s->y, s->z, s->sectnum, &v24, &v28, &v2c, &v30, 128, CLIPMASK0);
3032     if (v2c < sector[s->sectnum].floorz)
3033         v2c = sector[s->sectnum].floorz - 8;
3034     vec3_t pos = { s->x, s->y, v2c };
3035     setsprite(a1, &pos);
3036     changespritestat(a1, 802);
3037     s2->cstat = 0x20;
3038     s2->extra = 0;
3039     s2->ang = s->ang;
3040     s2->owner = a1;
3041     s2->pal = 0;
3042     s2->xoffset = 0;
3043     s2->yoffset = 0;
3044     s2->xvel = 0;
3045     s2->yvel = 0;
3046     s2->zvel = 0;
3047     s2->shade = -28;
3048     s2->xrepeat = 14;
3049     s2->yrepeat = 18;
3050     s2->clipdist = 32;
3051     s2->picnum = 7080 + (ud.level_number != 3);
3052 }
3053 
sub_57140(void)3054 void sub_57140(void)
3055 {
3056     short i, nexti;
3057     i = headspritestat[804];
3058     while (i >= 0)
3059     {
3060         nexti = nextspritestat[i];
3061         sprite[i].extra++;
3062         i = nexti;
3063     }
3064 }
3065 
3066 int dword_AAAC4 = 0x100;
3067 
ghtrax_getoldestboartrax(void)3068 short ghtrax_getoldestboartrax(void)
3069 {
3070     short i, nexti, vcx, vsi;
3071     vcx = -1;
3072     vsi = 0;
3073     i = headspritestat[804];
3074     while (i >= 0)
3075     {
3076         nexti = nextspritestat[i];
3077         if (vcx < sprite[i].extra)
3078         {
3079             vcx = sprite[i].extra;
3080             vsi = i;
3081         }
3082         if (sprite[i].extra > dword_AAAC4)
3083         {
3084             initprintf("ghtrax_getoldestdeertrax: oldest trax at %i\n", sprite[i].extra);
3085         }
3086         i = nexti;
3087     }
3088     return vsi;
3089 }
3090 
3091 int dword_AAABC;
3092 
ghtrax_boartrax(short a1)3093 void ghtrax_boartrax(short a1)
3094 {
3095     spritetype* s, * s2;
3096     int v24 = 0;
3097     int v28 = 0;
3098     int v2c = 0;
3099     int v30 = 0;
3100     short v18, i, nexti;
3101     s = &sprite[a1];
3102     if (dword_AAAC4 > dword_AAABC)
3103     {
3104         v18 = insertsprite(s->sectnum, 0);
3105         if (v18 < 0 || v18 >= MAXSPRITES)
3106         {
3107             initprintf("ghtrax_boartrax: insertsprite failed\n");
3108             dword_AAAC4 = dword_AAABC;
3109             initprintf("                 set maxtraxboar to\n", dword_AAAC4);
3110         }
3111         else
3112             dword_AAABC++;
3113     }
3114     else
3115     {
3116         v18 = ghtrax_getoldestboartrax();
3117         if (v18 < 0 || v18 >= MAXSPRITES)
3118         {
3119             initprintf("ghtrax_boartrax: invalid oldest trax sprite\n");
3120             return;
3121         }
3122     }
3123     sub_57140();
3124     s2 = &sprite[v18];
3125     getzrange_old(s->x, s->y, s->z, s->sectnum, &v24, &v28, &v2c, &v30, 128, CLIPMASK0);
3126     if (v2c < sector[s->sectnum].floorz)
3127         v2c = sector[s->sectnum].floorz - 8;
3128     vec3_t pos = { s->x, s->y, v2c };
3129     setsprite(a1, &pos);
3130     changespritestat(a1, 804);
3131     s2->cstat = 0x20;
3132     s2->extra = 0;
3133     s2->ang = s->ang;
3134     s2->owner = a1;
3135     s2->pal = 0;
3136     s2->xoffset = 0;
3137     s2->yoffset = 0;
3138     s2->xvel = 0;
3139     s2->yvel = 0;
3140     s2->zvel = 0;
3141     s2->shade = -28;
3142     s2->xrepeat = 14;
3143     s2->yrepeat = 18;
3144     s2->clipdist = 32;
3145     s2->picnum = 7084 + (ud.level_number != 3);
3146 }
3147 
3148 int dword_AAAB4, dword_AAAC0;
3149 
3150 short word_AAAC8;
3151 
sub_573C0(void)3152 void sub_573C0(void)
3153 {
3154     int vdx = 0;
3155     int i;
3156     for (i = 0; i < MAXSPRITES; i++)
3157         if (sprite[i].picnum)
3158             vdx++;
3159 
3160     vdx = MAXSPRITES - vdx;
3161     if (vdx <= 640)
3162         initprintf("not enuff sprites left for deer and boar trax\n");
3163     dword_AAAB0 = 0;
3164     dword_AAAB4 = 0;
3165     dword_AAAB8 = 0x180;
3166     dword_AAABC = 0;
3167     dword_AAAC0 = 0;
3168     dword_AAAC4 = 0x100;
3169     word_AAAC8 = (rrdh_random() & 2047);
3170 }
3171 
sub_5743C(void)3172 short sub_5743C(void)
3173 {
3174     return word_AAAC8;
3175 }
3176 
ghtrax_isplrupwind(short a1,short a2)3177 int ghtrax_isplrupwind(short a1, short a2)
3178 {
3179     spritetype *s;
3180     DukePlayer_t *p;
3181     s = &sprite[a1];
3182     p = g_player[a2].ps;
3183 
3184     return klabs(word_AAAC8 - (getangle(s->x -p->pos.x, s->y - p->pos.y) & 2047)) < 256;
3185 }
3186 
ghtrax_leavetrax(short a1)3187 void ghtrax_leavetrax(short a1)
3188 {
3189     spritetype *s;
3190     sectortype *sc;
3191     short sect;
3192     s = &sprite[a1];
3193     sect = s->sectnum;
3194     sc = &sector[sect];
3195 
3196     if (klabs(sector[sect].ceilingheinum - sector[sect].floorheinum) <= 576)
3197     {
3198         switch (DYNAMICTILEMAP(sprite[a1].picnum))
3199         {
3200         case VIXEN__STATICRR:
3201             if (sector[sect].hitag == 0)
3202                 ghtrax_deertrax(a1);
3203             break;
3204         case PIG__STATICRR:
3205             if (sector[sect].hitag == 0)
3206                 ghtrax_boartrax(a1);
3207             break;
3208         }
3209     }
3210 }
3211 
ghtrax_deerdroppings(short a1)3212 void ghtrax_deerdroppings(short a1)
3213 {
3214     spritetype* s, * s2;
3215     int v24 = 0;
3216     int v28 = 0;
3217     int v2c = 0;
3218     int v30 = 0;
3219     short v18, i, nexti;
3220     s = &sprite[a1];
3221     if (dword_AAAB4 >= 24)
3222         return;
3223     v18 = insertsprite(s->sectnum, 0);
3224     if (v18 < 0 || v18 >= MAXSPRITES)
3225     {
3226         initprintf("ghtrax_deerdroppings: insertsprite failed\n");
3227         return;
3228     }
3229     s2 = &sprite[v18];
3230     getzrange_old(s->x, s->y, s->z, s->sectnum, &v24, &v28, &v2c, &v30, 128, CLIPMASK0);
3231     if (v2c < sector[s->sectnum].floorz)
3232         v2c = sector[s->sectnum].floorz - 8;
3233     vec3_t pos = { s->x, s->y, v2c };
3234     setsprite(a1, &pos);
3235     changespritestat(a1, 803);
3236     s2->cstat = 0;
3237     s2->ang = s->ang;
3238     s2->owner = a1;
3239     s2->pal = 0;
3240     s2->xoffset = 0;
3241     s2->yoffset = 0;
3242     s2->xvel = 0;
3243     s2->yvel = 0;
3244     s2->zvel = 0;
3245     s2->shade = 8;
3246     s2->xrepeat = 8;
3247     s2->yrepeat = 5;
3248     s2->clipdist = 32;
3249     s2->extra = 0;
3250     s2->picnum = 981 + (ud.level_number != 3);
3251     dword_AAAB4++;
3252 }
3253 
ghtrax_boardroppings(short a1)3254 void ghtrax_boardroppings(short a1)
3255 {
3256     spritetype* s, * s2;
3257     int v24 = 0;
3258     int v28 = 0;
3259     int v2c = 0;
3260     int v30 = 0;
3261     short v18, i, nexti;
3262     s = &sprite[a1];
3263     if (dword_AAAC0 >= 24)
3264         return;
3265     v18 = insertsprite(s->sectnum, 0);
3266     if (v18 < 0 || v18 >= MAXSPRITES)
3267     {
3268         initprintf("ghtrax_boardroppings: insertsprite failed\n");
3269         return;
3270     }
3271     s2 = &sprite[v18];
3272     getzrange_old(s->x, s->y, s->z, s->sectnum, &v24, &v28, &v2c, &v30, 128, CLIPMASK0);
3273     if (v2c < sector[s->sectnum].floorz)
3274         v2c = sector[s->sectnum].floorz - 8;
3275     vec3_t pos = { s->x, s->y, v2c };
3276     setsprite(a1, &pos);
3277     changespritestat(a1, 805);
3278     s2->cstat = 0;
3279     s2->ang = s->ang;
3280     s2->owner = a1;
3281     s2->picnum = 983;
3282     s2->pal = 0;
3283     s2->xoffset = 0;
3284     s2->yoffset = 0;
3285     s2->xvel = 0;
3286     s2->yvel = 0;
3287     s2->zvel = 0;
3288     s2->shade = 8;
3289     s2->xrepeat = 8;
3290     s2->yrepeat = 5;
3291     s2->clipdist = 32;
3292     s2->extra = 0;
3293     dword_AAAC0++;
3294 }
3295 
ghtrax_leavedroppings(short a1)3296 void ghtrax_leavedroppings(short a1)
3297 {
3298     spritetype *s;
3299     sectortype *sc;
3300     short sect;
3301     s = &sprite[a1];
3302     sect = s->sectnum;
3303     sc = &sector[sect];
3304 
3305     if (klabs(sector[sect].ceilingheinum - sector[sect].floorheinum) <= 576)
3306     {
3307         switch (DYNAMICTILEMAP(sprite[a1].picnum))
3308         {
3309         case VIXEN__STATICRR:
3310             if (sector[sect].hitag == 0)
3311                 ghtrax_deerdroppings(a1);
3312             break;
3313         case PIG__STATICRR:
3314             if (sector[sect].hitag == 0)
3315                 ghtrax_boardroppings(a1);
3316             break;
3317         }
3318     }
3319 }
3320 
3321 int dword_AAAD0, dword_AAAD4, dword_AAAD8, dword_AAACC;
3322 unsigned int dword_AAADC, dword_AAAE0, dword_AAAE4, dword_AAAE8;
3323 
sub_579A0(void)3324 void sub_579A0(void)
3325 {
3326     dword_AAAD0++;
3327     dword_AAACC++;
3328     if (dword_AAAD0 == 4)
3329     {
3330         if (dword_AAADC > 0)
3331             dword_AAADC--;
3332         if (dword_AAAE0 > 0)
3333             dword_AAAE0--;
3334         if (dword_AAAE4 > 0)
3335             dword_AAAE4--;
3336         if (dword_AAAE8 > 0)
3337             dword_AAAE8--;
3338         dword_AAAD0 = 0;
3339         dword_AAAD4++;
3340         if (dword_AAAD4 == 10)
3341         {
3342             dword_AAAD8++;
3343             dword_AAAD4 = 0;
3344         }
3345     }
3346 }
3347 
sub_57A40(int a1)3348 int sub_57A40(int a1)
3349 {
3350     if (dword_AAADC)
3351         return 0;
3352     dword_AAADC = a1;
3353     return 1;
3354 }
3355 
sub_57A60(int a2)3356 int sub_57A60(int a2)
3357 {
3358     if (dword_AAAE0)
3359         return 0;
3360     dword_AAAE0 = a2;
3361     return 1;
3362 }
3363 
sub_57A80(int a2)3364 int sub_57A80(int a2)
3365 {
3366     if (dword_AAAE4)
3367         return 0;
3368     dword_AAAE4 = a2;
3369     return 1;
3370 }
3371 
sub_57AA0(int a2)3372 int sub_57AA0(int a2)
3373 {
3374     if (dword_AAAE8)
3375         return 0;
3376     dword_AAAE8 = a2;
3377     return 1;
3378 }
3379 
3380 int dword_AAAEC;
3381 
sub_57AC0(void)3382 void sub_57AC0(void)
3383 {
3384     int i;
3385     for (i = 0; i < MAXSECTORS; i++)
3386         show2dsector[i>>3] |= 1<<(i&7);
3387     for (i = 0; i < MAXWALLS; i++)
3388         show2dwall[i>>3] |= 1<<(i&7);
3389     dword_AAAEC ^= 1;
3390 }
3391 
sub_57B24(void)3392 void sub_57B24(void)
3393 {
3394     dword_AAAEC = 0;
3395 }
3396 
sub_57B38(long cposx,long cposy,long czoom,short cang)3397 void sub_57B38(long cposx, long cposy, long czoom, short cang)
3398 {
3399         long i, j, k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff;
3400         long dax, day, cosang, sinang, xspan, yspan, sprx, spry;
3401         long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang;
3402         long xvect, yvect, xvect2, yvect2, xc, yc, xc2, yc2;
3403         short p;
3404         char col;
3405         walltype *wal, *wal2;
3406         spritetype *spr;
3407 
3408         if (!dword_AAAEC)
3409             return;
3410 
3411         xvect = sintable[(-cang)&2047] * czoom;
3412         yvect = sintable[(1536-cang)&2047] * czoom;
3413         xvect2 = mulscale16(xvect,yxaspect);
3414         yvect2 = mulscale16(yvect,yxaspect);
3415         xc = windowxy2.x - windowxy1.x;
3416         yc = windowxy2.y - windowxy1.y;
3417         xc2 = 0;
3418         yc2 = 0;
3419 
3420                 //Draw white lines
3421         for(i=0;i<numsectors;i++)
3422         {
3423                 if (!(show2dsector[i>>3]&(1<<(i&7)))) continue;
3424 
3425                 startwall = sector[i].wallptr;
3426                 endwall = sector[i].wallptr + sector[i].wallnum;
3427 
3428                 k = -1;
3429                 for(j=startwall,wal=&wall[startwall];j<endwall;j++,wal++)
3430                 {
3431                         if (wal->nextwall >= 0) continue;
3432 
3433                         if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue;
3434 
3435                         if (tilesiz[wal->picnum].x == 0) continue;
3436                         if (tilesiz[wal->picnum].y == 0) continue;
3437 
3438                         if (j == k)
3439                                 { x1 = x2; y1 = y2; }
3440                         else
3441                         {
3442                                 ox = wal->x; oy = wal->y;
3443                                 x1 = dmulscale16(ox,xvect,-oy,yvect)+(xc<<11);
3444                                 y1 = dmulscale16(oy,xvect2,ox,yvect2)+(yc<<11);
3445                         }
3446 
3447                         k = wal->point2; wal2 = &wall[k];
3448                         ox = wal2->x; oy = wal2->y;
3449                         x2 = dmulscale16(ox,xvect,-oy,yvect)+(xc<<11);
3450                         y2 = dmulscale16(oy,xvect2,ox,yvect2)+(yc<<11);
3451 
3452                         renderDrawLine(x1,y1,x2,y2,74);
3453                 }
3454         }
3455 
3456          for(k=0;k<MAXSPRITES;k++)
3457          {
3458              i = 0;
3459              switch (DYNAMICTILEMAP(sprite[k].picnum))
3460              {
3461              case VIXEN__STATICRR:
3462                  i = 5665;
3463                  break;
3464              case PIG__STATICRR:
3465                  i = 4966;
3466                  break;
3467              case DOGRUN__STATICRR:
3468                  i = 4311;
3469                  break;
3470              case CHEER__STATICRR:
3471                  i = 6777;
3472                  break;
3473              }
3474              if (i == 0) continue;
3475 
3476               ox = sprite[k].x-xc2; oy = sprite[k].y-yc2;
3477               x1 = dmulscale16(ox,xvect,-oy,yvect);
3478               y1 = dmulscale16(oy,xvect2,ox,yvect2);
3479 
3480               rotatesprite_win((x1<<4)+(xc<<15), (y1<<4)+(yc<<15), 8192, 0, i, 0, 0, 0);
3481          }
3482 
3483           ox = cposx-xc2; oy = cposy-yc2;
3484           x1 = dmulscale16(ox,xvect,-oy,yvect);
3485           y1 = dmulscale16(oy,xvect2,ox,yvect2);
3486 
3487           rotatesprite_win((x1<<4)+(xc<<15), (y1<<4)+(yc<<15), 65536, (fix16_to_int(g_player[screenpeek].ps->q16ang)+512)&2047, 7060, 0, 0, 0);
3488 }
3489 
sub_57FB0(void)3490 int sub_57FB0(void)
3491 {
3492     return 64 + (rrdh_random() % 224);
3493 }
3494 
3495 unsigned int dword_AAAF0;
3496 unsigned int dword_AAAF4, dword_AAAF8;
3497 int dword_AAAFC, dword_AAB00, dword_AAB04;
3498 
ghtarget_runningclock(void)3499 void ghtarget_runningclock(void)
3500 {
3501     if (dword_AAAFC != 2)
3502     {
3503         if (dword_AAAFC == 1)
3504         {
3505             if ((int)totalclock - dword_AAB04 >= 240)
3506             {
3507                 sub_53E18();
3508                 dword_AAAFC = 2;
3509             }
3510         }
3511         else
3512         {
3513             if ((int)totalclock - dword_AAAF8 >= 120)
3514             {
3515                 if (dword_AAAF4 > 0)
3516                     dword_AAAF4--;
3517                 else if (dword_AAAF0 > 0)
3518                 {
3519                     dword_AAAF4 = 50;
3520                     dword_AAAF0--;
3521                 }
3522                 else
3523                 {
3524                     dword_AAAFC = 1;
3525                     dword_AAB04 = (int)totalclock;
3526                     P_DoQuote(145, g_player[myconnectindex].ps);
3527                 }
3528                 dword_AAAF8 = (int)totalclock;
3529             }
3530         }
3531     }
3532 }
3533 
sub_580C8(void)3534 void sub_580C8(void)
3535 {
3536     int vsi = dword_AAAF0 % 10;
3537     int vd = dword_AAAF0 / 10;
3538     rotatesprite(292<<16, 184<<16, 17408, 0, DIGITALNUM+vd, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3539     rotatesprite(296<<16, 184<<16, 17408, 0, DIGITALNUM+vsi, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3540     vsi = dword_AAAF4 % 10;
3541     vd = dword_AAAF4 / 10;
3542     rotatesprite(302<<16, 184<<16, 17408, 0, DIGITALNUM+vd, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3543     rotatesprite(306<<16, 184<<16, 17408, 0, DIGITALNUM+vsi, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3544 }
3545 
ghtarget_move(void)3546 void ghtarget_move(void)
3547 {
3548     int v2c = 0;
3549     int v28 = 0;
3550     int v24 = 0;
3551     short v18 = 0;
3552     int i, nexti;
3553     short mv;
3554     spritetype *s;
3555     i = headspritestat[808];
3556     while (i >= 0)
3557     {
3558         nexti = nextspritestat[i];
3559         s = &sprite[i];
3560         if (dword_AAAFC)
3561             mv = 0;
3562         else
3563         {
3564             v2c = s->x;
3565             v28 = s->y;
3566             v24 = s->z;
3567             v18 = s->sectnum;
3568             vec3_t vect = { (sintable[1536]*s->xvel)>>14, 0, 0 };
3569             mv = A_MoveSprite(i, &vect, CLIPMASK1);
3570         }
3571         if (mv || v18 != s->sectnum)
3572         {
3573             s->x = v2c;
3574             s->y = v28;
3575             s->z = v24;
3576             changespritesect(i, v18);
3577             s->yvel = -s->yvel;
3578             s->xvel = sub_57FB0();
3579             if (s->yvel == -1)
3580                 s->xvel = -s->xvel;
3581             s->cstat ^= 4;
3582             ghtarget_setanimal(i);
3583             if (s->extra)
3584             {
3585                 s->cstat |= 256;
3586                 s->cstat &= ~32768;
3587                 s->extra = 0;
3588                 s->xvel = sub_57FB0();
3589                 if (s->yvel == -1)
3590                     s->xvel = -s->xvel;
3591             }
3592         }
3593         i = nexti;
3594     }
3595     if (ud.level_number > 3)
3596         ghtarget_runningclock();
3597 }
3598 
sub_58364(int a1)3599 void sub_58364(int a1)
3600 {
3601     dword_AAAF0 = a1;
3602     dword_AAAF8 = 0;
3603     dword_AAAF4 = 0;
3604     dword_AAAFC = 0;
3605 }
3606 
sub_58388(void)3607 void sub_58388(void)
3608 {
3609     int i, vdx;
3610     sub_58364(0);
3611     dword_AAB00 = 0;
3612     if (ud.level_number < 4)
3613         return;
3614     for (i = 0; i < MAXSPRITES; i++)
3615     {
3616         vdx = 0;
3617         switch (sprite[i].picnum)
3618         {
3619         case 7110:
3620             sprite[i].xrepeat = 18;
3621             sprite[i].yrepeat = 24;
3622             vdx = 1;
3623             break;
3624         case 7111:
3625             sprite[i].xrepeat = 13;
3626             sprite[i].yrepeat = 14;
3627             vdx = 1;
3628             break;
3629         case 7112:
3630             sprite[i].xrepeat = 22;
3631             sprite[i].yrepeat = 16;
3632             vdx = 1;
3633             break;
3634         case 1076:
3635             sprite[i].cstat = 257;
3636             break;
3637         }
3638         if (vdx)
3639         {
3640             changespritestat(i, 808);
3641             sprite[i].cstat = 273;
3642             sprite[i].xvel = sub_57FB0();
3643             sprite[i].yvel = 1;
3644             sprite[i].extra = 0;
3645         }
3646     }
3647     sub_58364(3);
3648 }
3649 
ghtarget_setanimal(short a1)3650 void ghtarget_setanimal(short a1)
3651 {
3652     int vdx;
3653     vdx = rrdh_random() % 5;
3654     switch (vdx)
3655     {
3656     case 0:
3657         sprite[a1].picnum = 7110;
3658         sprite[a1].xrepeat = 18;
3659         sprite[a1].yrepeat = 24;
3660         break;
3661     case 1:
3662         sprite[a1].picnum = 7111;
3663         sprite[a1].xrepeat = 13;
3664         sprite[a1].yrepeat = 14;
3665         break;
3666     case 2:
3667         sprite[a1].picnum = 7112;
3668         sprite[a1].xrepeat = 22;
3669         sprite[a1].yrepeat = 16;
3670         break;
3671     }
3672 }
3673 
ghtarget_hit(short a1,int a2)3674 void ghtarget_hit(short a1, int a2)
3675 {
3676     unsigned short vc;
3677     if (dword_AAAFC)
3678         return;
3679     if (sprite[a1].picnum == 1076)
3680     {
3681         dword_AAB00++;
3682         sub_58A30(1);
3683         sub_53848(dword_AAB00);
3684     }
3685     else if (sprite[a1].statnum == 808)
3686     {
3687         vc = sprite[a1].picnum;
3688         switch (sprite[a1].picnum)
3689         {
3690         case 7110:
3691         case 7111:
3692             vc = 1;
3693             break;
3694         case 7112:
3695             vc = 4;
3696             break;
3697         }
3698         ghstatbr_registerkillinfo(sprite[a1].picnum, 0, 0);
3699         vc += klabs(sprite[a1].xvel) / 32;
3700         switch (sector[sprite[a1].sectnum].hitag)
3701         {
3702         case 2004:
3703             vc++;
3704             break;
3705         case 2005:
3706             vc += 2;
3707             break;
3708         case 2006:
3709             vc += 4;
3710             break;
3711         case 2007:
3712             vc += 8;
3713             break;
3714         case 2008:
3715             vc += 16;
3716             break;
3717         default:
3718             initprintf("WARNING: ghtarget_hit: spr not in track\n");
3719             break;
3720         }
3721         switch (g_player[myconnectindex].ps->dhat61f)
3722         {
3723         case 0:
3724             vc++;
3725             break;
3726         case 1:
3727             vc += 2;
3728             break;
3729         case 3:
3730             vc += 2;
3731             break;
3732         case 4:
3733             vc += 3;
3734             break;
3735         }
3736         sprite[a1].cstat |= 32768;
3737         sprite[a1].cstat &= ~256;
3738         A_PlaySound(87, g_player[myconnectindex].ps->i);
3739         ghtarget_setanimal(a1);
3740         sprite[a1].extra = 1;
3741         if (vc > 18)
3742             sub_5A250(0x200);
3743         dword_AAB00 += vc;
3744         sub_58A30(vc);
3745         sub_53848(dword_AAB00);
3746     }
3747 }
3748 
gharrow_move(void)3749 void gharrow_move(void)
3750 {
3751     int i, nexti;
3752     short mv;
3753     int v24, v28, v20, vdx;
3754     short v18;
3755     spritetype *s;
3756     i = headspritestat[809];
3757     while (i >= 0)
3758     {
3759         nexti = nextspritestat[i];
3760         s = &sprite[i];
3761         if (s->sectnum < 0 || s->sectnum >= numsectors)
3762         {
3763             deletesprite(i);
3764         }
3765         else
3766         {
3767             A_GetZLimits(i);
3768             v24 = s->x;
3769             v28 = s->y;
3770             v20 = s->y;
3771             v18 = s->sectnum;
3772             vec3_t vec = { s->xvel, s->yvel, s->zvel };
3773             mv = A_MoveSprite(i, &vec, CLIPMASK1);
3774             if (mv)
3775             {
3776                 s->x = v24;
3777                 s->y = v28;
3778                 s->z = v20;
3779                 changespritesect(i, v18);
3780                 if ((mv & 49152) == 49152)
3781                 {
3782                     mv &= MAXSPRITES - 1;
3783                     A_PlaySound(59, mv);
3784                     vdx = sub_56AD8();
3785                     ghtrophy_addkill(mv);
3786                     ghtarget_hit(mv, vdx);
3787                 }
3788                 else
3789                 {
3790                     if ((mv & 49152) == 32768 && ud.level_number > 3)
3791                         A_PlaySound(59, i);
3792                     sub_5A250(4);
3793                 }
3794                 deletesprite(i);
3795             }
3796         }
3797         i = nexti;
3798     }
3799 }
3800 
gharrow_spawnarrow(short snum)3801 void gharrow_spawnarrow(short snum)
3802 {
3803     short s;
3804     spritetype *spr;
3805     DukePlayer_t *p;
3806     p = g_player[snum].ps;
3807     s = insertsprite(p->cursectnum, 809);
3808     if (s < 0 || s >= MAXSPRITES)
3809     {
3810         initprintf("gharrow_spawnarrow: insertsprite failed\n");
3811         return;
3812     }
3813     spr = &sprite[s];
3814     if (!spr)
3815     {
3816         initprintf("gharrow_spawnarrow: null sprptr\n");
3817         return;
3818     }
3819     spr->x = p->pos.x;
3820     spr->y = p->pos.y;
3821     spr->z = p->pos.z;
3822     spr->ang = (fix16_to_int(p->q16ang) + 3) & 2047;
3823     spr->xvel = sintable[(spr->ang + 512) & 2047];
3824     spr->yvel = sintable[(spr->ang) & 2047];
3825     spr->picnum = 3450;
3826     spr->cstat = 1;
3827     spr->owner = 0;
3828     spr->xrepeat = 14;
3829     spr->yrepeat = 14;
3830     spr->pal = 0;
3831     spr->xoffset = 0;
3832     spr->yoffset = 0;
3833     spr->lotag = 0;
3834     spr->hitag = 0;
3835     spr->extra = 0;
3836     spr->shade = 0;
3837     spr->zvel = (100 - fix16_to_int(p->q16horiz) + 1) << 9;
3838     spr->cstat |= 0x8001;
3839 }
3840 
3841 int dword_AAB08 = 1;
3842 unsigned int dword_AAB0C;
3843 
sub_58A30(int a1)3844 void sub_58A30(int a1)
3845 {
3846     dword_AAB0C += a1;
3847     if (dword_AAB0C > 99999)
3848         dword_AAB0C = 0;
3849     dword_AAB08 = 128;
3850 }
3851 
sub_58A5C(unsigned int a1)3852 void sub_58A5C(unsigned int a1)
3853 {
3854     int t1 = a1 % 10;
3855     int t2 = (a1 % 100) / 10;
3856     int t3 = (a1 % 1000) / 100;
3857     int t4 = (a1 % 10000) / 1000;
3858     int t5 = (a1 % 100000) / 10000;
3859     rotatesprite(243<<16, 185<<16, 22528, 0, DIGITALNUM+t1, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3860     rotatesprite(235<<16, 185<<16, 22528, 0, DIGITALNUM+t2, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3861     rotatesprite(227<<16, 185<<16, 22528, 0, DIGITALNUM+t3, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3862     rotatesprite(219<<16, 185<<16, 22528, 0, DIGITALNUM+t4, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3863     rotatesprite(211<<16, 185<<16, 22528, 0, DIGITALNUM+t5, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3864 }
3865 
3866 short word_AAB10;
3867 int dword_AAB14, dword_AAB18;
3868 
ghstatbr_registerkillinfo(short a1,int a2,int a3)3869 void ghstatbr_registerkillinfo(short a1, int a2, int a3)
3870 {
3871     if (a1 < 0 || a1 >= MAXTILES)
3872     {
3873         initprintf("ERROR: ghstatbr_registerkillinfo bad pic range\n");
3874         return;
3875     }
3876     if (a2 < 0)
3877     {
3878         initprintf("ERROR: ghstatbr_registerkillinfo neg points\n");
3879         return;
3880     }
3881     switch (DYNAMICTILEMAP(a1))
3882     {
3883     case VIXEN__STATICRR:
3884         word_AAB10 = 1720;
3885         break;
3886     case RRTILE7110__STATICRR:
3887         word_AAB10 = 7114;
3888         break;
3889     case PIG__STATICRR:
3890         word_AAB10 = 1719;
3891         break;
3892     case RRTILE7111__STATICRR:
3893         word_AAB10 = 7115;
3894         break;
3895     case DOGRUN__STATICRR:
3896         word_AAB10 = 1721;
3897         break;
3898     case RRTILE7113__STATICRR:
3899         word_AAB10 = 7116;
3900         break;
3901     case CHEER__STATICRR:
3902         word_AAB10 = 1722;
3903         break;
3904     case RRTILE7112__STATICRR:
3905         word_AAB10 = 7117;
3906         break;
3907     default:
3908         word_AAB10 = 0;
3909         dword_AAB14 = 0;
3910         return;
3911     }
3912     dword_AAB14 = a2;
3913     dword_AAB18 = a3;
3914     dword_AAB08 |= 8;
3915 }
3916 
sub_58D14(void)3917 void sub_58D14(void)
3918 {
3919     if (word_AAB10 > 0 && dword_AAB14 >= 0 && dword_AAB18 >= 0)
3920     {
3921         rotatesprite(39<<16, 185<<16, 32768, 0, word_AAB10, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3922         if (ud.level_number < 4)
3923         {
3924             unsigned int t1 = dword_AAB14 % 10;
3925             unsigned int t2 = (dword_AAB14 % 100) / 10;
3926             unsigned int t3 = (dword_AAB14 % 1000) / 100;
3927             rotatesprite(64<<16, 180<<16, 18432, 0, DIGITALNUM+t1, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3928             if (t3 || t2 > 0)
3929             {
3930                 rotatesprite(58<<16, 180<<16, 18432, 0, DIGITALNUM+t2, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3931             }
3932             if (t3 > 0)
3933             {
3934                 rotatesprite(52<<16, 180<<16, 18432, 0, DIGITALNUM+t3, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3935             }
3936             t1 = dword_AAB18 % 10;
3937             t2 = (dword_AAB18 % 100) / 10;
3938             rotatesprite(64<<16, 190<<16, 18432, 0, DIGITALNUM+t1, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3939             if (t2 > 0)
3940             {
3941                 rotatesprite(58<<16, 190<<16, 18432, 0, DIGITALNUM+t2, 0, 0, 128+64+10, 0, 0, xdim-1, ydim-1);
3942             }
3943         }
3944     }
3945 }
3946 
3947 
sub_58F40(int a1)3948 void sub_58F40(int a1)
3949 {
3950     int v18 = sub_59B44();
3951     int v1c, v20, i;
3952     switch (a1)
3953     {
3954     case 0:
3955         v20 = 1723;
3956         v1c = 24576;
3957         break;
3958     case 1:
3959     case 2:
3960     case 3:
3961         v20 = 1724;
3962         v1c = 24576;
3963         break;
3964     default:
3965         return;
3966     }
3967     for (i = 0; i < v18; i++)
3968     {
3969         rotatesprite((216+13*i)<<16, 184<<16, v1c, 0, v20, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3970     }
3971 }
3972 
ghstatbr_drawammotype(void)3973 void ghstatbr_drawammotype(void)
3974 {
3975     int vbx = 0;
3976     switch (g_player[myconnectindex].ps->dhat61f)
3977     {
3978     case 0:
3979         vbx = sub_56718();
3980         break;
3981     case 1:
3982     case 2:
3983         vbx = sub_55FC0();
3984         break;
3985     case 3:
3986         vbx = sub_55928();
3987         break;
3988     case 4:
3989         vbx = sub_56AD8();
3990         break;
3991     }
3992     rotatesprite(97<<16, 187<<16, 32768, 0, 1711+vbx, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
3993 }
3994 
3995 int dword_AAB1C;
3996 
ghstatbr_render(void)3997 void ghstatbr_render(void)
3998 {
3999     int r;
4000     short v18;
4001     if (g_player[myconnectindex].ps->gm & MODE_GAME)
4002     {
4003         if (g_currentMenu == MENU_DHTROPHIES)
4004             return;
4005     }
4006     if (klabs(fix16_to_int(g_player[myconnectindex].ps->q16ang) - fix16_to_int(g_player[myconnectindex].ps->oq16ang)) > 16)
4007         dword_AAB08 = 2;
4008 
4009     v18 = sub_5743C();
4010     r = rrdh_random() & 1023;
4011     if (r < 64)
4012     {
4013         v18 += r - 32;
4014         dword_AAB08 = 4;
4015         v18 &= 2047;
4016     }
4017     if (dword_AAB08)
4018     {
4019         //sub_51028(3, dword_AAB1C++);
4020         if (ud.level_number < 4)
4021         {
4022             rotatesprite(0<<16, 166<<16, 32768, 0, 1647, 4, 0, 128+64+16+10, 0, 0, xdim-1, ydim-1);
4023         }
4024         else
4025         {
4026             rotatesprite(0<<16, 166<<16, 32768, 0, 1710, 4, 0, 128+64+16+10, 0, 0, xdim-1, ydim-1);
4027         }
4028         sub_58D14();
4029         if (ud.level_number > 0 && ud.level_number < 4)
4030         {
4031             rotatesprite(216<<16, 166<<16, 32768, 0, 1725, 4, 0, 128+64+16+10, 0, 0, xdim-1, ydim-1);
4032         }
4033         ghstatbr_drawammotype();
4034         rotatesprite(155<<16, 185<<16, 32768, v18, 1637, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
4035         if (ud.level_number < 4)
4036             rotatesprite(301<<16, 183<<16, 32768, fix16_to_int(g_player[screenpeek].ps->q16ang), 1638, 0, 0, 128+10, 0, 0, xdim-1, ydim-1);
4037         if (ud.level_number > 3)
4038             sub_580C8();
4039         sub_58F40(ud.level_number);
4040         if (ud.level_number > 3)
4041             sub_58A5C(dword_AAB0C);
4042         dword_AAB08 = 0;
4043     }
4044 }
4045 
4046 //void sub_592F0(void)
4047 //{
4048 //    dword_AAB08 = 1;
4049 //}
4050 //
4051 //void sub_59304(int a1)
4052 //{
4053 //    dword_AAB08 |= a1;
4054 //}
4055 
sub_59314(void)4056 void sub_59314(void)
4057 {
4058     dword_AAB0C = 0;
4059     dword_AAB14 = 0;
4060     dword_AAB08 = 1;
4061     word_AAB10 = 0;
4062 }
4063 
ghdeploy_isdownwind(short a1,short a2)4064 int ghdeploy_isdownwind(short a1, short a2)
4065 {
4066     short ang;
4067     ang = getangle(sprite[a1].x - sprite[a2].x, sprite[a1].y - sprite[a2].y) & 2047;
4068     return klabs(sub_5743C() - ang) < 512;
4069 }
4070 
ghdeploy_bias(short a1)4071 void ghdeploy_bias(short a1)
4072 {
4073     spritetype *s;
4074     int i, nexti, vcx, d;
4075     short v1c;
4076     s = &sprite[a1];
4077     vcx = 76800;
4078     v1c = -1;
4079     i = headspritestat[811];
4080     while (i >= 0)
4081     {
4082         nexti = nextspritestat[i];
4083         if (sprite[i].extra > 0)
4084         {
4085             if (sprite[i].picnum == 7073 && ghdeploy_isdownwind(a1, i))
4086             {
4087                 d = klabs(sprite[a1].x-sprite[i].x) + klabs(sprite[a1].y-sprite[i].y);
4088                 if (d < vcx)
4089                 {
4090                     vcx = d;
4091                     v1c = i;
4092                 }
4093             }
4094             else if (sprite[i].picnum == 7072)
4095             {
4096                 if ((rrdh_random() & 255) > 32)
4097                 {
4098                     d = klabs(sprite[a1].x-sprite[i].x) + klabs(sprite[a1].y-sprite[i].y);
4099                     if (d < vcx)
4100                     {
4101                         vcx = d;
4102                         v1c = i;
4103                     }
4104                 }
4105             }
4106             else
4107             {
4108                 d = klabs(sprite[a1].x-sprite[i].x) + klabs(sprite[a1].y-sprite[i].y);
4109                 if (d < vcx)
4110                 {
4111                     vcx = d;
4112                     v1c = i;
4113                 }
4114             }
4115         }
4116         i = nexti;
4117     }
4118     if (vcx < 76800 && v1c != -1)
4119     {
4120         sprite[a1].ang = getangle(sprite[v1c].x-sprite[a1].x,sprite[v1c].y-sprite[a1].y) & 2047;
4121     }
4122     else
4123     {
4124         sprite[a1].ang = rrdh_random() & 2047;
4125     }
4126 }
4127 
4128 int dword_AAB24[] = {
4129     0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176,
4130     192, 208, 224, 240, 256, 240, 224, 208, 192, 176, 160,
4131     144, 128, 112, 96, 80, 64, 48, 32, 16
4132 };
4133 
ghdeploy_move(void)4134 void ghdeploy_move(void)
4135 {
4136     int v1c = 0;
4137     int v20 = 0;
4138     int v24 = 0;
4139     int v28 = 0;
4140     int i, nexti;
4141     spritetype *s;
4142 
4143     i = headspritestat[811];
4144     while (i >= 0)
4145     {
4146         nexti = nextspritestat[i];
4147         s = &sprite[i];
4148         if (s->sectnum < 0 || s->sectnum >= numsectors)
4149         {
4150             initprintf("ghdeploy_move DEPLOYED bad sect %i\n", s->sectnum);
4151             deletesprite(i);
4152         }
4153         else if (sector[s->sectnum].hitag == 2003)
4154         {
4155             if (s->zvel < 0 || s->zvel >= 32)
4156                 s->zvel = 0;
4157             else
4158             {
4159                 s->z = sector[s->sectnum].floorz + 256 + dword_AAB24[s->zvel];
4160                 s->zvel++;
4161             }
4162         }
4163         if (s->picnum == 7073 && s->extra > 0)
4164         {
4165             s->extra--;
4166         }
4167         i = nexti;
4168     }
4169     i = headspritestat[810];
4170     while (i >= 0)
4171     {
4172         nexti = nextspritestat[i];
4173         s = &sprite[i];
4174         if (s->sectnum < 0 || s->sectnum >= numsectors)
4175         {
4176             initprintf("ghdeploy_move TOSS bad sect %i\n", s->sectnum);
4177             deletesprite(i);
4178         }
4179         vec3_t vec = { s->xvel, s->yvel, 0 };
4180         A_MoveSprite(i, &vec, CLIPMASK1);
4181         getzrange_old(s->x, s->y, s->z, s->sectnum, &v1c, &v20, &v24, &v28, 32, CLIPMASK0);
4182         if (v24 - 2048 < sprite[i].z)
4183         {
4184             changespritestat(i, 811);
4185             s->extra = 9600;
4186             s->z = v24;
4187             s->zvel = 0;
4188             if (s->picnum == 7072)
4189             {
4190                 s->cstat = 1;
4191                 if (sector[s->sectnum].hitag == 2003)
4192                     A_PlaySound(90, g_player[myconnectindex].ps->i);
4193                 if (sector[s->sectnum].hitag == 2003)
4194                     A_PlaySound(89, g_player[myconnectindex].ps->i);
4195             }
4196         }
4197         else
4198         {
4199             sprite[i].z += sprite[i].zvel;
4200             sprite[i].zvel += 0x200;
4201         }
4202         i = nexti;
4203     }
4204 }
4205 
4206 unsigned int dword_AAB20;
4207 int dword_AABA4 = 4;
4208 
ghdeploy_drop(int a1,int a2)4209 void ghdeploy_drop(int a1, int a2)
4210 {
4211     DukePlayer_t *p;
4212     short va;
4213     spritetype *s;
4214     if ((int)totalclock - dword_AAB20 < 120)
4215         return;
4216     if (!dword_AABA4)
4217     {
4218         P_DoQuote(149, g_player[a1].ps);
4219         return;
4220     }
4221     if (a2 > 3)
4222         return;
4223     p = g_player[a1].ps;
4224     if (p->cursectnum < 0 || p->cursectnum >= numsectors)
4225     {
4226         initprintf("ERROR: ghdeploy_drop bad plrsectr %i\n", p->cursectnum);
4227         return;
4228     }
4229     va = insertsprite(p->cursectnum, 810);
4230     if (va < 0 || va >= MAXSPRITES)
4231     {
4232         initprintf("ghdeploy_drop: insertsprite failed\n");
4233         return;
4234     }
4235     s = &sprite[va];
4236     if (!s)
4237     {
4238         initprintf("ghdeploy_drop: null sprptr\n");
4239         return;
4240     }
4241     s->x = p->pos.x + (sintable[(fix16_to_int(p->q16ang) + 512) & 2047] >> 7);
4242     s->y = p->pos.y + (sintable[(fix16_to_int(p->q16ang)) & 2047] >> 7);
4243     s->z = p->pos.z + 0x1000;
4244     s->ang = fix16_to_int(fix16_to_int(p->q16ang)) & 2047;
4245     s->xvel = (sintable[(fix16_to_int(p->q16ang) + 512) & 2047] * 5) >> 8;
4246     s->yvel = (sintable[(fix16_to_int(p->q16ang)) & 2047] * 5) >> 8;
4247     s->zvel = (80 - fix16_to_int(p->q16horiz)) << 6;
4248     if (a2 == 0)
4249     {
4250         s->picnum = 7072;
4251         s->cstat = 0;
4252         P_DoQuote(146, p);
4253     }
4254     else
4255     {
4256         s->cstat = 0;
4257         s->cstat |= 32768;
4258         s->picnum = 7073;
4259         P_DoQuote(148, p);
4260         A_PlaySound(88, p->i);
4261     }
4262     s->owner = 0;
4263     s->clipdist = 4;
4264     s->xrepeat = 10;
4265     s->yrepeat = 10;
4266     s->pal = 0;
4267     s->xoffset = 0;
4268     s->yoffset = 0;
4269     s->lotag = 0;
4270     s->hitag = 0;
4271     s->extra = 0;
4272     s->shade = 0;
4273     dword_AABA4--;
4274     //sub_592F0();
4275     dword_AAB20 = (int)totalclock;
4276 }
4277 
sub_59B44(void)4278 int sub_59B44(void)
4279 {
4280     return dword_AABA4;
4281 }
4282 
sub_59B50(void)4283 void sub_59B50(void)
4284 {
4285     dword_AABA4 = 4;
4286     dword_AAB20 = 0;
4287 }
4288 
ghdeploy_plrtouchedsprite(short a1,short a2)4289 void ghdeploy_plrtouchedsprite(short a1, short a2)
4290 {
4291     DukePlayer_t *p;
4292     spritetype *s;
4293     p = g_player[a2].ps;
4294     s = &sprite[a1];
4295 
4296     if (sprite[a1].statnum == 811 && sprite[a1].picnum != 7073)
4297     {
4298         deletesprite(a1);
4299         dword_AABA4++;
4300         P_DoQuote(147, p);
4301     }
4302 }
4303 
4304 short word_2BE990[68];
4305 short word_2BEA18;
4306 char byte_2BE350[256];
4307 
sub_59C20(void)4308 void sub_59C20(void)
4309 {
4310     int i;
4311     word_2BEA18 = 0;
4312     tilesiz[7059].x = 0;
4313     tilesiz[7059].y = 0;
4314     for (i = 0; i < numsectors; i++)
4315     {
4316         sector[i].extra = 256;
4317         if (sector[i].floorpicnum == 7059)
4318             word_2BE990[word_2BEA18++] = i;
4319     }
4320     for (i = 0; i < 256; i++)
4321         byte_2BE350[i] = i;
4322     paletteMakeLookupTable(2, byte_2BE350, 10*4, 10*4, 24*4, 0);
4323 }
4324 
4325 int dword_2BEA20, dword_2BEA24;
4326 int dword_AABA8, dword_AABAC, dword_AABB0;
4327 
sub_59F80(int a1)4328 void sub_59F80(int a1)
4329 {
4330     dword_2BEA20 = 0;
4331     dword_AABA8 = (int)totalclock;
4332     dword_AABAC = (int)totalclock;
4333     dword_2BEA24 = a1;
4334     dword_AABB0 = 0;
4335 }
4336 
ghmumble_randomsayit(int a1,int a2)4337 void ghmumble_randomsayit(int a1, int a2)
4338 {
4339     if (a1 < 0 || a1 >= MAXSOUNDS)
4340     {
4341         initprintf("ghmumble_randomsayit bad sndnum\n");
4342         return;
4343     }
4344     if (g_player[myconnectindex].ps->gm == MODE_GAME)
4345     {
4346         if ((rrdh_random() & 255) <= a2)
4347         {
4348             S_PlaySound(a1);
4349             dword_AABB0 = (int)totalclock;
4350         }
4351     }
4352 }
4353 
sub_5A02C(void)4354 void sub_5A02C(void)
4355 {
4356     int t;
4357     if (dword_2BEA24 > 3)
4358     {
4359         if (dword_2BEA20 == 512)
4360         {
4361             ghmumble_randomsayit(105+(rrdh_random()%2), 164);
4362         }
4363         dword_2BEA20 = 0;
4364         return;
4365     }
4366     if ((int)totalclock - dword_AABB0 < 480)
4367     {
4368         dword_2BEA20 = 0;
4369         return;
4370     }
4371     if (dword_2BEA20 == 0)
4372     {
4373         if ((int)totalclock - dword_AABA8 > 2400)
4374         {
4375             ghmumble_randomsayit(91 + (rrdh_random() % 4), 200);
4376             dword_AABA8 = (int)totalclock;
4377             dword_AABAC = (int)totalclock;
4378         }
4379     }
4380     else if (dword_2BEA20 & 8)
4381     {
4382         ghmumble_randomsayit(100 + (rrdh_random() % 2), 200);
4383         dword_AABA8 = (int)totalclock;
4384         dword_AABAC = (int)totalclock;
4385     }
4386     else if (dword_2BEA20 & 4)
4387     {
4388         if (dword_2BEA20 & 32)
4389             ghmumble_randomsayit(98 + (rrdh_random() % 2), 216);
4390         dword_AABA8 = (int)totalclock;
4391         dword_AABAC = (int)totalclock;
4392     }
4393     else if (dword_2BEA20 & 16)
4394     {
4395         if (dword_2BEA20 & 32)
4396             ghmumble_randomsayit(102, 216);
4397         dword_AABA8 = (int)totalclock;
4398         dword_AABAC = (int)totalclock;
4399     }
4400     else if (dword_2BEA20 & 2048)
4401     {
4402         ghmumble_randomsayit(108, 250);
4403         dword_AABA8 = (int)totalclock;
4404     }
4405     else if (dword_2BEA20 & 4096)
4406     {
4407         ghmumble_randomsayit(109, 80);
4408         dword_AABA8 = (int)totalclock;
4409     }
4410     else if (dword_2BEA20 & 16384)
4411     {
4412         ghmumble_randomsayit(107, 255);
4413         dword_AABA8 = (int)totalclock;
4414     }
4415     else if (dword_2BEA20 & 256)
4416     {
4417         if ((dword_2BEA20 & 64) == 0)
4418         {
4419             if ((int)totalclock - dword_AABAC > 7200)
4420             {
4421                 initprintf("nosightings mumble\n");
4422                 t = rrdh_random() % 3;
4423                 if (t == 2 && dword_2BEA24 != 3)
4424                     t = 1;
4425                 ghmumble_randomsayit(95+t, 200);
4426                 dword_AABA8 = (int)totalclock;
4427                 dword_AABAC = (int)totalclock;
4428             }
4429         }
4430     }
4431     dword_2BEA20 = 0;
4432 }
4433 
sub_5A250(int a1)4434 void sub_5A250(int a1)
4435 {
4436     if (a1 >= 0x10000)
4437         return;
4438     switch (a1)
4439     {
4440     case 1:
4441         dword_2BEA20 = 0;
4442         return;
4443     case 2:
4444         dword_AABA8 = (int)totalclock;
4445         dword_AABAC = (int)totalclock;
4446         dword_2BEA20 = 0;
4447         return;
4448     case 0x100:
4449         dword_AABA8 = (int)totalclock;
4450         break;
4451     case 0x10:
4452         break;
4453     case 0x20:
4454     case 0x40:
4455         dword_AABAC = (int)totalclock;
4456         break;
4457     }
4458     dword_2BEA20 |= a1;
4459 }
4460