1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4 Copyright (C) 2017-2019 Nuke.YKT
5 
6 This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
7 
8 Duke Nukem 3D is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 
23 Original Source: 1996 - Todd Replogle
24 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
25 */
26 //-------------------------------------------------------------------------
27 
28 #include "types.h"
29 #include "develop.h"
30 #include "scriplib.h"
31 #include "file_lib.h"
32 #include "gamedefs.h"
33 #include "keyboard.h"
34 #include "util_lib.h"
35 #include "function.h"
36 #include "control.h"
37 #include "fx_man.h"
38 #include "sounds.h"
39 #include "config.h"
40 #include "sndcards.h"
41 
42 #include "duke3d.h"
43 
44 extern FILE *frecfilep;
45 
46 #define patchstatusbar(x1,y1,x2,y2)                                        \
47 {                                                                          \
48     rotatesprite(0,(200-34)<<16,32768L,0,BOTTOMSTATUSBAR,4,0,10+16+64+128, \
49         scale(x1,xdim,320),scale(y1,ydim,200),                             \
50         scale(x2,xdim,320)-1,scale(y2,ydim,200)-1);                        \
51 }
52 
53 #define patchstatusbar2(x1,y1,x2,y2)                                       \
54 {                                                                          \
55     rotatesprite(0,158<<16,32768L,0,WEAPONBAR,4,0,10+16+64+128,            \
56         scale(x1,xdim,320),scale(y1,ydim,200),                             \
57         scale(x2,xdim,320)-1,scale(y2,ydim,200)-1);                        \
58 }
59 
actorfella(spritetype * s)60 short actorfella(spritetype *s)
61 {
62     switch (s->picnum)
63     {
64         case BOULDER:
65         case BOULDER1:
66         case EGG:
67         case RAT:
68         case TORNADO:
69         case BILLYCOCK:
70         case BILLYRAY:
71         case BILLYRAYSTAYPUT:
72         case BRAYSNIPER:
73         case DOGRUN:
74         case LTH:
75         case HULKJUMP:
76         case BUBBASTAND:
77         case HULK:
78         case HULKSTAYPUT:
79         case DRONE:
80         case PIG:
81         case RECON:
82         case MINION:
83         case MINIONSTAYPUT:
84         case UFO1:
85         case COOT:
86         case COOTSTAYPUT:
87         case SHARK:
88         case VIXEN:
89 #ifdef RRRA
90         case SBSWIPE:
91         case BIKERB:
92         case BIKERBV2:
93         case BIKER:
94         case MAKEOUT:
95         case CHEERB:
96         case CHEER:
97         case CHEERSTAYPUT:
98         case COOTPLAY:
99         case BILLYPLAY:
100         case MINIONBOAT:
101         case HULKBOAT:
102         case CHEERBOAT:
103         case RABBIT:
104         case ROCK:
105         case ROCK2:
106         case MAMA:
107 #else
108         case SBMOVE:
109         case UFO2:
110         case UFO3:
111         case UFO4:
112         case UFO5:
113 #endif
114             return 1;
115     }
116     return 0;
117 }
118 
119 
badguy(spritetype * s)120 short badguy(spritetype *s)
121 {
122 
123     switch(s->picnum)
124     {
125             case BOULDER:
126             case BOULDER1:
127             case EGG:
128             case RAT:
129             case TORNADO:
130             case BILLYCOCK:
131             case BILLYRAY:
132             case BILLYRAYSTAYPUT:
133             case BRAYSNIPER:
134             case DOGRUN:
135             case LTH:
136             case HULKJUMP:
137             case BUBBASTAND:
138             case HULK:
139             case HULKSTAYPUT:
140             case HEN:
141             case DRONE:
142             case PIG:
143             case RECON:
144             case MINION:
145             case MINIONSTAYPUT:
146             case UFO1:
147             case COOT:
148             case COOTSTAYPUT:
149             case SHARK:
150             case VIXEN:
151 #ifdef RRRA
152             case SBSWIPE:
153             case BIKERB:
154             case BIKERBV2:
155             case BIKER:
156             case MAKEOUT:
157             case CHEERB:
158             case CHEER:
159             case CHEERSTAYPUT:
160             case COOTPLAY:
161             case BILLYPLAY:
162             case MINIONBOAT:
163             case HULKBOAT:
164             case CHEERBOAT:
165             case RABBIT:
166             case MAMA:
167 #else
168             case SBMOVE:
169             case UFO2:
170             case UFO3:
171             case UFO4:
172             case UFO5:
173 #endif
174                 return 1;
175     }
176     if( actortype[s->picnum] ) return 1;
177 
178     return 0;
179 }
180 
181 
badguypic(short pn)182 short badguypic(short pn)
183 {
184 
185     switch(pn)
186     {
187             case BOULDER:
188             case BOULDER1:
189             case EGG:
190             case RAT:
191             case TORNADO:
192             case BILLYCOCK:
193             case BILLYRAY:
194             case BILLYRAYSTAYPUT:
195             case BRAYSNIPER:
196             case DOGRUN:
197             case LTH:
198             case HULKJUMP:
199             case BUBBASTAND:
200             case HULK:
201             case HULKSTAYPUT:
202             case DRONE:
203             case PIG:
204             case RECON:
205             case MINION:
206             case MINIONSTAYPUT:
207             case UFO1:
208             case COOT:
209             case COOTSTAYPUT:
210             case SHARK:
211             case VIXEN:
212 #ifdef RRRA
213             case SBSWIPE:
214             case BIKERB:
215             case BIKERBV2:
216             case BIKER:
217             case MAKEOUT:
218             case CHEERB:
219             case CHEER:
220             case CHEERSTAYPUT:
221             case COOTPLAY:
222             case BILLYPLAY:
223             case MINIONBOAT:
224             case HULKBOAT:
225             case CHEERBOAT:
226             case RABBIT:
227             case MAMA:
228 #else
229             case SBMOVE:
230             case UFO2:
231             case UFO3:
232             case UFO4:
233             case UFO5:
234 #endif
235                 return 1;
236     }
237 
238     if( actortype[pn] ) return 1;
239 
240     return 0;
241 }
242 
243 #ifdef RRRA
ShowMotorcycle(long x,long y,short tilenum,signed char shade,char orientation,char p,short a)244 void ShowMotorcycle(long x, long y, short tilenum, signed char shade, char orientation, char p, short a)
245 {
246     char fp;
247 
248     fp = sector[ps[screenpeek].cursectnum].floorpal;
249     rotatesprite(x<<16,y<<16,34816L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
250 }
251 
OnMotorcycle(struct player_struct * p,int unk)252 void OnMotorcycle(struct player_struct *p, int unk)
253 {
254     if (!p->OnMotorcycle && !(sector[p->cursectnum].lotag == 2))
255     {
256         if (unk)
257         {
258             p->posx = sprite[unk].x;
259             p->posy = sprite[unk].y;
260             p->ang = sprite[unk].ang;
261             p->ammo_amount[RA13_WEAPON] = sprite[unk].owner;
262             deletesprite(unk);
263         }
264         p->over_shoulder_on = 0;
265         p->OnMotorcycle = 1;
266         p->last_full_weapon = p->curr_weapon;
267         p->curr_weapon = RA13_WEAPON;
268         p->gotweapon[RA13_WEAPON] = 1;
269         p->posxv = 0;
270         p->posyv = 0;
271         p->horiz = 100;
272     }
273     if (!Sound[186].num)
274         spritesound(186, p->i);
275 }
276 
OffMotorcycle(struct player_struct * p)277 void OffMotorcycle(struct player_struct *p)
278 {
279     short j;
280     if (p->OnMotorcycle)
281     {
282         if (Sound[188].num > 0)
283             stopsound(Sound[188].num);
284         if (Sound[187].num > 0)
285             stopsound(Sound[187].num);
286         if (Sound[186].num > 0)
287             stopsound(Sound[186].num);
288         if (Sound[214].num > 0)
289             stopsound(Sound[214].num);
290         if (Sound[42].num == 0)
291             spritesound(42, p->i);
292         p->OnMotorcycle = 0;
293         p->gotweapon[RA13_WEAPON] = 0;
294         p->curr_weapon = p->last_full_weapon;
295         checkavailweapon(p);
296         p->horiz = 100;
297         p->raat5b5 = 0;
298         p->MotoSpeed = 0;
299         p->TiltStatus = 0;
300         p->raat5c1 = 0;
301         p->VBumpTarget = 0;
302         p->VBumpNow = 0;
303         p->TurbCount = 0;
304         p->posxv = 0;
305         p->posyv = 0;
306         p->posxv -= sintable[(p->ang+512)&2047]<<7;
307         p->posyv -= sintable[p->ang&2047]<<7;
308         p->raat5b9 = 0;
309         j = spawn(p->i, EMPTYBIKE);
310         sprite[j].ang = p->ang;
311         sprite[j].xvel += sintable[(p->ang+512)&2047]<<7;
312         sprite[j].yvel += sintable[p->ang&2047]<<7;
313         sprite[j].owner = p->ammo_amount[RA13_WEAPON];
314     }
315 }
316 
ShowBoat(long x,long y,short tilenum,signed char shade,char orientation,char p,short a)317 void ShowBoat(long x, long y, short tilenum, signed char shade, char orientation, char p, short a)
318 {
319     char fp;
320 
321     fp = sector[ps[screenpeek].cursectnum].floorpal;
322     rotatesprite(x<<16,y<<16,66048L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
323 }
324 
OnBoat(struct player_struct * p,int unk)325 void OnBoat(struct player_struct *p, int unk)
326 {
327     if (!p->OnBoat)
328     {
329         if (unk)
330         {
331             p->posx = sprite[unk].x;
332             p->posy = sprite[unk].y;
333             p->ang = sprite[unk].ang;
334             p->ammo_amount[RA14_WEAPON] = sprite[unk].owner;
335             deletesprite(unk);
336         }
337         p->over_shoulder_on = 0;
338         p->OnBoat = 1;
339         p->last_full_weapon = p->curr_weapon;
340         p->curr_weapon = RA14_WEAPON;
341         p->gotweapon[RA14_WEAPON] = 1;
342         p->posxv = 0;
343         p->posyv = 0;
344         p->horiz = 100;
345     }
346 }
347 
OffBoat(struct player_struct * p)348 void OffBoat(struct player_struct *p)
349 {
350     short j;
351     if (p->OnBoat)
352     {
353         p->OnBoat = 0;
354         p->gotweapon[RA14_WEAPON] = 0;
355         p->curr_weapon = p->last_full_weapon;
356         checkavailweapon(p);
357         p->horiz = 100;
358         p->raat5b5 = 0;
359         p->MotoSpeed = 0;
360         p->TiltStatus = 0;
361         p->raat5c1 = 0;
362         p->VBumpTarget = 0;
363         p->VBumpNow = 0;
364         p->TurbCount = 0;
365         p->posxv = 0;
366         p->posyv = 0;
367         p->posxv -= sintable[(p->ang+512)&2047]<<7;
368         p->posyv -= sintable[p->ang&2047]<<7;
369         p->raat5b9 = 0;
370         j = spawn(p->i, EMPTYBOAT);
371         sprite[j].ang = p->ang;
372         sprite[j].xvel += sintable[(p->ang+512)&2047]<<7;
373         sprite[j].yvel += sintable[p->ang&2047]<<7;
374         sprite[j].owner = p->ammo_amount[RA14_WEAPON];
375     }
376 }
377 
378 #endif
379 
myos(long x,long y,short tilenum,signed char shade,char orientation)380 void myos(long x, long y, short tilenum, signed char shade, char orientation)
381 {
382     char p;
383     short a;
384 
385     if(orientation&4)
386         a = 1024;
387     else a = 0;
388 
389     p = sector[ps[screenpeek].cursectnum].floorpal;
390     rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
391 }
392 
myospal(long x,long y,short tilenum,signed char shade,char orientation,char p)393 void myospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
394 {
395     char fp;
396     short a;
397 
398     if(orientation&4)
399         a = 1024;
400     else a = 0;
401 
402     fp = sector[ps[screenpeek].cursectnum].floorpal;
403 
404     rotatesprite(x<<16,y<<16,32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
405 
406 }
407 
408 #ifdef RRRA
myospalsb(long x,long y,short tilenum,signed char shade,char orientation,char p)409 void myospalsb(long x, long y, short tilenum, signed char shade, char orientation, char p)
410 {
411     char fp;
412     short a;
413 
414     if(orientation&4)
415         a = 1024;
416     else a = 0;
417 
418     fp = sector[ps[screenpeek].cursectnum].floorpal;
419 
420     rotatesprite(x<<16,y<<16,32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
421 
422 }
423 #endif
424 
rdmyospal(long x,long y,short tilenum,signed char shade,char orientation,char p)425 void rdmyospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
426 {
427     char fp;
428     short a;
429 
430     if(orientation&4)
431         a = 1024;
432     else a = 0;
433 
434     fp = sector[ps[screenpeek].cursectnum].floorpal;
435 
436     rotatesprite(x<<16,y<<16,36700L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
437 
438 }
rd2myospal(long x,long y,short tilenum,signed char shade,char orientation,char p)439 void rd2myospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
440 {
441     char fp;
442     short a;
443 
444     if(orientation&4)
445         a = 1024;
446     else a = 0;
447 
448     fp = sector[ps[screenpeek].cursectnum].floorpal;
449 
450     rotatesprite(x<<16,y<<16,44040L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
451 
452 }
453 
rd3myospal(long x,long y,short tilenum,signed char shade,char orientation,char p)454 void rd3myospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
455 {
456     char fp;
457     short a;
458 
459     if(orientation&4)
460         a = 1024;
461     else a = 0;
462 
463     fp = sector[ps[screenpeek].cursectnum].floorpal;
464 
465     rotatesprite(x<<16,y<<16,47040L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
466 
467 }
468 
invennum(long x,long y,char num1,char ha,char sbits)469 void invennum(long x,long y,char num1,char ha,char sbits)
470 {
471     char dabuf[80] = {0};
472     sprintf(dabuf,"%ld",num1);
473     if(num1 > 99)
474     {
475         rotatesprite((x-4)<<16,(y-1)<<16,32768L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
476         rotatesprite((x)<<16,y<<16,32768L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
477         rotatesprite((x+4)<<16,y<<16,32768L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
478     }
479     else if(num1 > 9)
480     {
481         rotatesprite((x)<<16,y<<16,32768L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
482         rotatesprite((x+4)<<16,y<<16,32768L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
483     }
484     else
485         rotatesprite((x+4)<<16,y<<16,32768L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
486 }
487 
488 
weaponnum(short ind,long x,long y,long num1,long num2,char ha)489 void weaponnum(short ind,long x,long y,long num1, long num2,char ha)
490 {
491     char dabuf[80] = {0};
492 
493     rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
494     rotatesprite((x-3)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
495     rotatesprite((x+9)<<16,y<<16,65536L,0,THREEBYFIVE+11,ha,0,10+128,0,0,xdim-1,ydim-1);
496 
497     if(num1 > 99) num1 = 99;
498     if(num2 > 99) num2 = 99;
499 
500     sprintf(dabuf,"%ld",num1);
501     if(num1 > 9)
502     {
503         rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
504         rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
505     }
506     else rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
507 
508     sprintf(dabuf,"%ld",num2);
509     if(num2 > 9)
510     {
511         rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
512         rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
513     }
514     else rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
515 }
516 
weaponnum999(char ind,long x,long y,long num1,long num2,char ha)517 void weaponnum999(char ind,long x,long y,long num1, long num2,char ha)
518 {
519     char dabuf[80] = {0};
520 
521     rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
522     rotatesprite((x-4)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
523     rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+11,ha,0,10+128,0,0,xdim-1,ydim-1);
524 
525     sprintf(dabuf,"%ld",num1);
526     if(num1 > 99)
527     {
528         rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
529         rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
530         rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
531     }
532     else if(num1 > 9)
533     {
534         rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
535         rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
536     }
537     else rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
538 
539     sprintf(dabuf,"%ld",num2);
540     if(num2 > 99)
541     {
542         rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
543         rotatesprite((x+21)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
544         rotatesprite((x+25)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
545     }
546     else if(num2 > 9)
547     {
548         rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
549         rotatesprite((x+21)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
550     }
551     else rotatesprite((x+25)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
552 }
553 
554 
555     //REPLACE FULLY
weapon_amounts(struct player_struct * p,long x,long y,long u)556 void weapon_amounts(struct player_struct *p,long x,long y,long u)
557 {
558      int cw;
559 
560      cw = p->curr_weapon;
561 
562      if (u&4)
563      {
564          if (u != 0xffffffff) patchstatusbar(96,178,96+12,178+6);
565          weaponnum999(PISTOL_WEAPON,x,y,
566                      p->ammo_amount[PISTOL_WEAPON],max_ammo_amount[PISTOL_WEAPON],
567                      12-20*(cw == PISTOL_WEAPON) );
568      }
569      if (u&8)
570      {
571          if (u != 0xffffffff) patchstatusbar(96,184,96+12,184+6);
572          weaponnum999(SHOTGUN_WEAPON,x,y+6,
573                      p->ammo_amount[SHOTGUN_WEAPON],max_ammo_amount[SHOTGUN_WEAPON],
574                      (!p->gotweapon[SHOTGUN_WEAPON]*9)+12-18*
575                      (cw == SHOTGUN_WEAPON) );
576      }
577      if (u&16)
578      {
579          if (u != 0xffffffff) patchstatusbar(96,190,96+12,190+6);
580          weaponnum999(CHAINGUN_WEAPON,x,y+12,
581                       p->ammo_amount[CHAINGUN_WEAPON],max_ammo_amount[CHAINGUN_WEAPON],
582                       (!p->gotweapon[CHAINGUN_WEAPON]*9)+12-18*
583                       (cw == CHAINGUN_WEAPON) );
584      }
585      if (u&32)
586      {
587          if (u != 0xffffffff) patchstatusbar(135,178,135+8,178+6);
588          weaponnum(RPG_WEAPON,x+39,y,
589                   p->ammo_amount[RPG_WEAPON],max_ammo_amount[RPG_WEAPON],
590                   (!p->gotweapon[RPG_WEAPON]*9)+12-19*
591                   (cw == RPG_WEAPON) );
592      }
593      if (u&64)
594      {
595          if (u != 0xffffffff) patchstatusbar(135,184,135+8,184+6);
596          weaponnum(HANDBOMB_WEAPON,x+39,y+6,
597                      p->ammo_amount[HANDBOMB_WEAPON],max_ammo_amount[HANDBOMB_WEAPON],
598                      (((!p->ammo_amount[HANDBOMB_WEAPON])|(!p->gotweapon[HANDBOMB_WEAPON]))*9)+12-19*
599                      ((cw == HANDBOMB_WEAPON) || (cw == HANDREMOTE_WEAPON)));
600      }
601      if (u&128)
602      {
603          if (u != 0xffffffff) patchstatusbar(135,190,135+8,190+6);
604          if(!p->ammo_amount[SHRINKER_WEAPON] || cw == GROW_WEAPON)
605              weaponnum(SHRINKER_WEAPON,x+39,y+12,
606                  p->ammo_amount[GROW_WEAPON],max_ammo_amount[GROW_WEAPON],
607                  (!p->gotweapon[GROW_WEAPON]*9)+12-18*
608                  (cw == GROW_WEAPON) );
609          else
610              weaponnum(SHRINKER_WEAPON,x+39,y+12,
611                  p->ammo_amount[SHRINKER_WEAPON],max_ammo_amount[SHRINKER_WEAPON],
612                  (!p->gotweapon[SHRINKER_WEAPON]*9)+12-18*
613                  (cw == SHRINKER_WEAPON) );
614      }
615      if (u&256)
616      {
617          if (u != 0xffffffff) patchstatusbar(166,178,166+8,178+6);
618          weaponnum(DEVISTATOR_WEAPON,x+70,y,
619                      p->ammo_amount[DEVISTATOR_WEAPON],max_ammo_amount[DEVISTATOR_WEAPON],
620                      (!p->gotweapon[DEVISTATOR_WEAPON]*9)+12-18*
621                      (cw == DEVISTATOR_WEAPON) );
622      }
623      if (u&512)
624      {
625          if (u != 0xffffffff) patchstatusbar(166,184,166+8,184+6);
626          weaponnum(TRIPBOMB_WEAPON,x+70,y+6,
627                      p->ammo_amount[TRIPBOMB_WEAPON],max_ammo_amount[TRIPBOMB_WEAPON],
628                      (!p->gotweapon[TRIPBOMB_WEAPON]*9)+12-18*
629                      (cw == TRIPBOMB_WEAPON) );
630      }
631 
632      if (u&65536L)
633      {
634          if (u != 0xffffffff) patchstatusbar(166,190,166+8,190+6);
635          weaponnum(-1,x+70,y+12,
636                      p->ammo_amount[FREEZE_WEAPON],max_ammo_amount[FREEZE_WEAPON],
637                      (!p->gotweapon[FREEZE_WEAPON]*9)+12-18*
638                      (cw == FREEZE_WEAPON) );
639      }
640 }
641 
digitalnumber(long x,long y,long n,char s,char cs)642 void digitalnumber(long x,long y,long n,char s,char cs)
643 {
644     short i, j, k, p, c;
645     char b[10];
646 
647     ltoa(n,b,10);
648     i = strlen(b);
649     j = 0;
650 
651     for(k=0;k<i;k++)
652     {
653         p = DIGITALNUM+*(b+k)-'0';
654         j += (tilesizx[p]>>1)+1;
655     }
656     c = x-(j>>1);
657 
658     j = 0;
659     for(k=0;k<i;k++)
660     {
661         p = DIGITALNUM+*(b+k)-'0';
662         rotatesprite((c+j)<<16,y<<16,32768L,0,p,s,0,cs,0,0,xdim-1,ydim-1);
663         j += (tilesizx[p]>>1)+1;
664     }
665 }
666 
667 /*
668 
669 void scratchmarks(long x,long y,long n,char s,char p)
670 {
671     long i, ni;
672 
673     ni = n/5;
674     for(i=ni;i >= 0;i--)
675     {
676         overwritesprite(x-2,y,SCRATCH+4,s,0,0);
677         x += tilesizx[SCRATCH+4]-1;
678     }
679 
680     ni = n%5;
681     if(ni) overwritesprite(x,y,SCRATCH+ni-1,s,p,0);
682 }
683   */
displayinventory(struct player_struct * p)684 void displayinventory(struct player_struct *p)
685 {
686     short n, j, xoff, y;
687 
688     j = xoff = 0;
689 
690     n = (p->jetpack_amount > 0)<<3; if(n&8) j++;
691     n |= ( p->scuba_amount > 0 )<<5; if(n&32) j++;
692     n |= (p->steroids_amount > 0)<<1; if(n&2) j++;
693     n |= ( p->holoduke_amount > 0)<<2; if(n&4) j++;
694     n |= (p->firstaid_amount > 0); if(n&1) j++;
695     n |= (p->heat_amount > 0)<<4; if(n&16) j++;
696     n |= (p->boot_amount > 0)<<6; if(n&64) j++;
697 
698     xoff = 160-(j*11);
699 
700     j = 0;
701 
702     if(ud.screen_size > 4)
703     {
704         y = 160;
705         if(ud.multimode > 1)
706             y -= 4;
707         if(ud.multimode > 4)
708             y -= 4;
709     }
710     else y = 180;
711 
712     if(ud.screen_size == 4)
713         xoff += 56;
714 
715     while( j <= 9 )
716     {
717         if( n&(1<<j) )
718         {
719             switch( n&(1<<j) )
720             {
721                 case   1:
722                 rotatesprite(xoff<<16,y<<16,32768L,0,FIRSTAID_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
723                 case   2:
724                 rotatesprite((xoff+1)<<16,y<<16,32768L,0,STEROIDS_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
725                 case   4:
726                 rotatesprite((xoff+2)<<16,y<<16,32768L,0,HOLODUKE_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
727                 case   8:
728                 rotatesprite(xoff<<16,y<<16,32768L,0,JETPACK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
729                 case  16:
730                 rotatesprite(xoff<<16,y<<16,32768L,0,HEAT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
731                 case  32:
732                 rotatesprite(xoff<<16,y<<16,32768L,0,AIRTANK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
733                 case 64:
734                 rotatesprite(xoff<<16,(y-1)<<16,32768L,0,BOOT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
735             }
736 
737             xoff += 22;
738 
739             if(p->inven_icon == j+1)
740                 rotatesprite((xoff-2)<<16,(y+19)<<16,32768L,1024,ARROW,-32,0,2+16,windowx1,windowy1,windowx2,windowy2);
741         }
742 
743         j++;
744     }
745 }
746 
747 
748 
displayfragbar(void)749 void displayfragbar(void)
750 {
751     short i, j;
752 
753     j = 0;
754 
755     for(i=connecthead;i>=0;i=connectpoint2[i])
756         if(i > j) j = i;
757 
758     rotatesprite(0,0,32800L,0,FRAGBAR,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1);
759     if(j >= 4) rotatesprite(319,(8)<<16,32800L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
760     if(j >= 8) rotatesprite(319,(16)<<16,32800L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
761     if(j >= 12) rotatesprite(319,(24)<<16,32800L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
762 
763     for(i=connecthead;i>=0;i=connectpoint2[i])
764     {
765         minitext(21+(73*(i&3)),2+((i&28)<<1),&ud.user_name[i][0],9+(i&7),2+8+16+128);
766         sprintf(tempbuf,"%d",ps[i].frag-ps[i].fraggedself);
767         minitext(17+50+(73*(i&3)),2+((i&28)<<1),tempbuf,9+(i&7),2+8+16+128);
768     }
769 }
770 
weaponbar(short snum)771 void weaponbar(short snum)
772 {
773     struct player_struct *p;
774     short i, icon, amount;
775 
776     p = &ps[snum];
777     rotatesprite(0,158<<16,32800L,0,WEAPONBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
778     for(i=0;i<10;i++)
779     {
780 #ifdef RRRA
781         if (i == 4 && p->curr_weapon == RA16_WEAPON)
782         {
783             icon = AMMO_ICON + 10;
784             rotatesprite((18+i*32)<<16,160<<16,32800L,0,icon,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
785             amount = p->ammo_amount[RA16_WEAPON];
786             invennum(38+i*32,162,(char)amount,0,10+128);
787         }
788         else
789         {
790 #endif
791         icon = AMMO_ICON + i;
792         if(p->gotweapon[i+1])
793             rotatesprite((18+i*32)<<16,160<<16,32800L,0,icon,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
794         amount = p->ammo_amount[i + 1];
795         invennum(38+i*32,162,(char)amount,0,10+128);
796 #ifdef RRRA
797         }
798 #endif
799     }
800 }
801 
coolgaugetext(short snum)802 void coolgaugetext(short snum)
803 {
804     struct player_struct *p;
805     long i, j, o, ss, u;
806     char c, permbit;
807 
808     p = &ps[snum];
809 
810     if (p->invdisptime > 0) displayinventory(p);
811 
812 
813     if(ps[snum].gm&MODE_MENU)
814         if( (current_menu >= 400  && current_menu <= 405) )
815             return;
816 
817     ss = ud.screen_size; if (ss < 4) return;
818 
819     if ( ud.multimode > 1 && ud.coop != 1 )
820     {
821         if (pus)
822             { displayfragbar(); }
823         else
824         {
825             for(i=connecthead;i>=0;i=connectpoint2[i])
826                 if (ps[i].frag != sbar.frag[i]) { displayfragbar(); break; }
827         }
828         for(i=connecthead;i>=0;i=connectpoint2[i])
829             if (i != myconnectindex)
830                 sbar.frag[i] = ps[i].frag;
831     }
832 
833     if (ss == 4)   //DRAW MINI STATUS BAR:
834     {
835         rotatesprite(2<<16,(200-28)<<16,32768L,0,HEALTHBOX,0,21,10+16,0,0,xdim-1,ydim-1);
836         if (p->inven_icon)
837             rotatesprite(77<<16,(200-30)<<16,32768L,0,INVENTORYBOX,0,21,10+16,0,0,xdim-1,ydim-1);
838 
839         if(sprite[p->i].pal == 1 && p->last_extra < 2)
840             digitalnumber(20,200-17,1,-16,10+16);
841         else digitalnumber(20,200-17,p->last_extra,-16,10+16);
842 
843         rotatesprite(41<<16,(200-28)<<16,32768L,0,AMMOBOX,0,21,10+16,0,0,xdim-1,ydim-1);
844 
845         if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
846         digitalnumber(59,200-17,p->ammo_amount[i],-16,10+16);
847 
848         o = 158; permbit = 0;
849         if (p->inven_icon)
850         {
851             switch(p->inven_icon)
852             {
853                 case 1: i = FIRSTAID_ICON; minitext(262-o+10,190,"%",0,permbit+10+16); break;
854                 case 2: i = STEROIDS_ICON; minitext(262-o+10,190,"%",0,permbit+10+16); break;
855                 case 3: i = HOLODUKE_ICON; break;
856                 case 4: i = JETPACK_ICON; break;
857                 case 5: i = HEAT_ICON; break;
858                 case 6: i = AIRTANK_ICON; break;
859                 case 7: i = BOOT_ICON; break;
860                 default: i = -1;
861             }
862             if (i >= 0) rotatesprite((231-o+10)<<16,(200-21)<<16,32768L,0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
863 
864             j = 0x80000000;
865             switch(p->inven_icon)
866             {
867                 case 1: i = p->firstaid_amount; break;
868                 case 2: i = ((p->steroids_amount+3)>>2); break;
869                 case 3: i = p->holoduke_amount/400; j = p->holoduke_on; break;
870                 case 4: i = p->jetpack_amount/100; j = p->jetpack_on; break;
871                 case 5: i = p->heat_amount/12; j = p->heat_on; break;
872                 case 6: i = ((p->scuba_amount+63)>>6); break;
873                 case 7: i = ((p->boot_amount/10)>>2); break;
874             }
875             invennum(254-o+8,200-6,(char)i,0,10+permbit);
876         }
877         return;
878     }
879 
880         //DRAW/UPDATE FULL STATUS BAR:
881 
882     if (pus) { pus = 0; u = 0xffffffff; } else u = 0;
883 
884     if (sbar.frag[myconnectindex] != p->frag) { sbar.frag[myconnectindex] = p->frag; u |= 32768; }
885     if (sbar.got_access != p->got_access) { sbar.got_access = p->got_access; u |= 16384; }
886     if (sbar.last_extra != p->last_extra) { sbar.last_extra = p->last_extra; u |= 1; }
887     if (sbar.shield_amount != p->shield_amount) { sbar.shield_amount = p->shield_amount; u |= 2; }
888     if (sbar.curr_weapon != p->curr_weapon) { sbar.curr_weapon = p->curr_weapon; u |= (4+8+16+32+64+128+256+512+1024+65536L); }
889     for(i=1;i < 10;i++)
890     {
891         if (sbar.ammo_amount[i] != p->ammo_amount[i]) {
892         sbar.ammo_amount[i] = p->ammo_amount[i]; if(i < 9) u |= ((2<<i)+1024); else u |= 65536L+1024; }
893         if (sbar.gotweapon[i] != p->gotweapon[i]) { sbar.gotweapon[i] =
894         p->gotweapon[i]; if(i < 9 ) u |= ((2<<i)+1024); else u |= 65536L+1024; }
895     }
896 #ifdef RRRA
897     if (p->OnMotorcycle || p->OnBoat || p->curr_weapon == RA16_WEAPON)
898         u |= 1024;
899 #endif
900     if (sbar.inven_icon != p->inven_icon) { sbar.inven_icon = p->inven_icon; u |= (2048+4096+8192); }
901     if (sbar.holoduke_on != p->holoduke_on) { sbar.holoduke_on = p->holoduke_on; u |= (4096+8192); }
902     if (sbar.jetpack_on != p->jetpack_on) { sbar.jetpack_on = p->jetpack_on; u |= (4096+8192); }
903     if (sbar.heat_on != p->heat_on) { sbar.heat_on = p->heat_on; u |= (4096+8192); }
904     if (sbar.firstaid_amount != p->firstaid_amount) { sbar.firstaid_amount = p->firstaid_amount; u |= 8192; }
905     if (sbar.steroids_amount != p->steroids_amount) { sbar.steroids_amount = p->steroids_amount; u |= 8192; }
906     if (sbar.holoduke_amount != p->holoduke_amount) { sbar.holoduke_amount = p->holoduke_amount; u |= 8192; }
907     if (sbar.jetpack_amount != p->jetpack_amount) { sbar.jetpack_amount = p->jetpack_amount; u |= 8192; }
908     if (sbar.heat_amount != p->heat_amount) { sbar.heat_amount = p->heat_amount; u |= 8192; }
909     if (sbar.scuba_amount != p->scuba_amount) { sbar.scuba_amount = p->scuba_amount; u |= 8192; }
910     if (sbar.boot_amount != p->boot_amount) { sbar.boot_amount = p->boot_amount; u |= 8192; }
911     if (u == 0) return;
912 
913     //0 - update health
914     //1 - update armor
915     //2 - update PISTOL_WEAPON ammo
916     //3 - update SHOTGUN_WEAPON ammo
917     //4 - update CHAINGUN_WEAPON ammo
918     //5 - update RPG_WEAPON ammo
919     //6 - update HANDBOMB_WEAPON ammo
920     //7 - update SHRINKER_WEAPON ammo
921     //8 - update DEVISTATOR_WEAPON ammo
922     //9 - update TRIPBOMB_WEAPON ammo
923     //10 - update ammo display
924     //11 - update inventory icon
925     //12 - update inventory on/off
926     //13 - update inventory %
927     //14 - update keys
928     //15 - update kills
929     //16 - update FREEZE_WEAPON ammo
930 
931     if (u == 0xffffffff)
932     {
933         patchstatusbar(0,0,320,200);
934         if (ud.multimode > 1 && ud.coop != 1)
935             rotatesprite(277<<16,(200-27)<<16,65536L,0,KILLSICON,0,0,10+16+128,0,0,xdim-1,ydim-1);
936         if (ud.screen_size > 8)
937             weaponbar(snum);
938     }
939     if (ud.multimode > 1 && ud.coop != 1)
940     {
941         if (u&32768)
942         {
943             if (u != 0xffffffff) patchstatusbar(276,183,299,193);
944             digitalnumber(287,200-17,max(p->frag-p->fraggedself,0),-16,10+16+128);
945         }
946     }
947     else
948     {
949         if (u != 0xffffffff) patchstatusbar(136,182,164,194);
950         if (p->keys[3]) rotatesprite(140<<16,182<<16,32768L,0,ACCESS_ICON,0,23,10+16+128,0,0,xdim-1,ydim-1);
951         if (p->keys[2]) rotatesprite(153<<16,182<<16,32768L,0,ACCESS_ICON,0,21,10+16+128,0,0,xdim-1,ydim-1);
952         if (p->keys[1]) rotatesprite(146<<16,189<<16,32768L,0,ACCESS_ICON,0,0,10+16+128,0,0,xdim-1,ydim-1);
953     }
954 
955     if (u&1)
956     {
957         if (u != 0xffffffff) patchstatusbar(52,183,77,193);
958         if(sprite[p->i].pal == 1 && p->last_extra < 2)
959             digitalnumber(64,200-17,1,-16,10+16+128);
960         else digitalnumber(64,200-17,p->last_extra,-16,10+16+128);
961     }
962 
963     if (u&1024)
964     {
965         if (u != 0xffffffff) patchstatusbar(95,183,120,193);
966 #ifdef RRRA
967         if (p->curr_weapon != KNEE_WEAPON && p->curr_weapon != RA15_WEAPON)
968 #else
969         if (p->curr_weapon != KNEE_WEAPON)
970 #endif
971         {
972             if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
973             digitalnumber(107,200-17,p->ammo_amount[i],-16,10+16+128);
974             if (ud.screen_size > 8)
975             {
976                 if (p->curr_weapon == RPG_WEAPON || p->curr_weapon == HANDBOMB_WEAPON)
977                 {
978                     patchstatusbar2(126,158,142,174);
979                     invennum(134,162,p->ammo_amount[HANDBOMB_WEAPON],0,10+128);
980                     patchstatusbar2(158,158,174,174);
981                     invennum(166,162,p->ammo_amount[RPG_WEAPON],0,10+128);
982                 }
983 #ifdef RRRA
984                 if (p->curr_weapon == RA16_WEAPON)
985                 {
986                     patchstatusbar2(158,158,174,174);
987                     invennum(166,162,p->ammo_amount[RA16_WEAPON],0,10+128);
988                 }
989 #endif
990                 else
991                 {
992                     patchstatusbar2(p->curr_weapon*32-2,158,p->curr_weapon*32+14,174);
993                     invennum(p->curr_weapon*32+6,162,p->ammo_amount[p->curr_weapon],0,10+128);
994                 }
995                 for (i=1;i<=10;i++)
996                 {
997 #ifdef RRRA
998                     if (i == 4 && p->curr_weapon == RA16_WEAPON)
999                     {
1000                         if (!p->ammo_amount[RA16_WEAPON-1])
1001                             if (p->gotweapon[RA16_WEAPON-1])
1002                         {
1003                             patchstatusbar2(i*32-2,158,i*32+14,174);
1004                             invennum(i*32+6,162,p->ammo_amount[RA16_WEAPON-1],0,10+128);
1005                         }
1006                     }
1007                     else
1008 #endif
1009                     if (!p->ammo_amount[i])
1010                         if (p->gotweapon[i])
1011                     {
1012                         patchstatusbar2(i*32-2,158,i*32+14,174);
1013                         invennum(i*32+6,162,p->ammo_amount[i],0,10+128);
1014                     }
1015                 }
1016             }
1017         }
1018     }
1019 
1020     if (u&(2048+4096+8192))
1021     {
1022         if (u != 0xffffffff)
1023         {
1024             if (u&(2048+4096)) { patchstatusbar(177,176,222,197); }
1025                               else { patchstatusbar(201,190,216,200); }
1026         }
1027         if (p->inven_icon)
1028         {
1029             o = 0; permbit = 128;
1030 
1031             if (u&(2048+4096))
1032             {
1033                 switch(p->inven_icon)
1034                 {
1035                     case 1: i = FIRSTAID_ICON; minitext(214-o+2,190,"%",0,10+16+permbit); break;
1036                     case 2: i = STEROIDS_ICON; minitext(214-o+2,190,"%",0,10+16+permbit); break;
1037                     case 3: i = HOLODUKE_ICON; break;
1038                     case 4: i = JETPACK_ICON; break;
1039                     case 5: i = HEAT_ICON; break;
1040                     case 6: i = AIRTANK_ICON; break;
1041                     case 7: i = BOOT_ICON; break;
1042                 }
1043                 if (i == AIRTANK_ICON)
1044                     rotatesprite((183-o)<<16,(200-24)<<16,32768L,0,AIRTANK_ICON,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1045                 else if (i == FIRSTAID_ICON || i == BOOT_ICON || i == STEROIDS_ICON)
1046                     rotatesprite((183-o)<<16,(200-22)<<16,32768L,0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1047                 else
1048                     rotatesprite((183-o)<<16,(200-21)<<16,32768L,0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1049                 if (p->inven_icon == 6 || p->inven_icon == 7) minitext(201-o,180,"AUTO",2,10+16+permbit);
1050             }
1051             if (u&(2048+4096))
1052             {
1053                 switch(p->inven_icon)
1054                 {
1055                     case 3: j = p->holoduke_on; break;
1056                     case 4: j = p->jetpack_on; break;
1057                     case 5: j = p->heat_on; break;
1058                     default: j = 0x80000000;
1059                 }
1060             }
1061             if (u&8192)
1062             {
1063                 switch(p->inven_icon)
1064                 {
1065                     case 1: i = p->firstaid_amount; break;
1066                     case 2: i = ((p->steroids_amount+3)>>2); break;
1067                     case 3: i = p->holoduke_amount/400; break;
1068                     case 4: i = p->jetpack_amount/100; break;
1069                     case 5: i = p->heat_amount/12; break;
1070                     case 6: i = ((p->scuba_amount+63)>>6); break;
1071                     case 7: i = ((p->boot_amount/10)>>1); break;
1072                 }
1073                 invennum(206-o,200-6,(char)i,0,10+permbit);
1074             }
1075         }
1076     }
1077 }
1078 
gutmeter(short player)1079 void gutmeter(short player)
1080 {
1081     long o, ss;
1082     struct player_struct *p;
1083 
1084     p = &ps[player];
1085     ss = ud.screen_size;
1086 
1087     if (ss <= 4)
1088         return;
1089 
1090     patchstatusbar(240,168,310,199);
1091     p->drunkang = ((p->drink_amt * 8) + 1647) & 0x7ff;
1092     if (p->drink_amt >= 100)
1093     {
1094         p->drink_amt = 100;
1095         p->drunkang = 400;
1096     }
1097     rotatesprite(257<<16,181<<16,32768L,p->drunkang,GUTMETER,0,0,10+128,0,0,xdim-1,ydim-1);
1098     rotatesprite(293<<16,181<<16,32768L,p->eatang,GUTMETER,0,0,10+128,0,0,xdim-1,ydim-1);
1099     o = 9;
1100     if (p->drink_amt >= 0 && p->drink_amt <= 30)
1101     {
1102         rotatesprite(239<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT1,0,0,10+128+16,0,0,xdim-1,ydim-1);
1103     }
1104     else if (p->drink_amt >= 31 && p->drink_amt <= 65)
1105     {
1106         rotatesprite(248<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT2,0,0,10+128+16,0,0,xdim-1,ydim-1);
1107     }
1108     else if (p->drink_amt >= 66 && p->drink_amt <= 87)
1109     {
1110         rotatesprite(256<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT3,0,0,10+128+16,0,0,xdim-1,ydim-1);
1111     }
1112     else
1113     {
1114         rotatesprite(265<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT4,0,0,10+128+16,0,0,xdim-1,ydim-1);
1115     }
1116 
1117     if (p->eat >= 0 && p->eat <= 30)
1118     {
1119         rotatesprite(276<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT1,0,0,10+128+16,0,0,xdim-1,ydim-1);
1120     }
1121     else if (p->eat >= 31 && p->eat <= 65)
1122     {
1123         rotatesprite(285<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT2,0,0,10+128+16,0,0,xdim-1,ydim-1);
1124     }
1125     else if (p->eat >= 66 && p->eat <= 87)
1126     {
1127         rotatesprite(294<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT3,0,0,10+128+16,0,0,xdim-1,ydim-1);
1128     }
1129     else
1130     {
1131         rotatesprite(302<<16,(181+o)<<16,32768L,0,GUTMETER_LIGHT4,0,0,10+128+16,0,0,xdim-1,ydim-1);
1132     }
1133 }
1134 
1135 
1136 #define AVERAGEFRAMES 16
1137 static long frameval[AVERAGEFRAMES], framecnt = 0;
1138 
tics(void)1139 void tics(void)
1140 {
1141     long i;
1142     char b[10];
1143 
1144     i = totalclock;
1145     if (i != frameval[framecnt])
1146     {
1147         sprintf(b,"%ld",(TICRATE*AVERAGEFRAMES)/(i-frameval[framecnt]));
1148         printext256(windowx1,windowy1,31,-21,b,1);
1149         frameval[framecnt] = i;
1150     }
1151 
1152     framecnt = ((framecnt+1)&(AVERAGEFRAMES-1));
1153 }
1154 
coords(short snum)1155 void coords(short snum)
1156 {
1157     short y = 0;
1158 
1159     if(ud.multimode > 1 && ud.multimode < 5)
1160         y = 8;
1161     else if(ud.multimode > 4)
1162         y = 16;
1163 
1164     sprintf(tempbuf,"X= %ld",ps[snum].posx);
1165     printext256(274L,y,31,-1,tempbuf,1);
1166     sprintf(tempbuf,"Y= %ld",ps[snum].posy);
1167     printext256(274L,y+7L,31,-1,tempbuf,1);
1168     sprintf(tempbuf,"Z= %ld",ps[snum].posz);
1169     printext256(274L,y+14L,31,-1,tempbuf,1);
1170     sprintf(tempbuf,"A= %ld",ps[snum].ang);
1171     printext256(274L,y+21L,31,-1,tempbuf,1);
1172     sprintf(tempbuf,"ZV= %ld",ps[snum].poszv);
1173     printext256(274L,y+28L,31,-1,tempbuf,1);
1174     sprintf(tempbuf,"OG= %ld",ps[snum].on_ground);
1175     printext256(274L,y+35L,31,-1,tempbuf,1);
1176     sprintf(tempbuf,"AM= %ld",ps[snum].ammo_amount[GROW_WEAPON]);
1177     printext256(274L,y+43L,31,-1,tempbuf,1);
1178 }
1179 
operatefta(void)1180 void operatefta(void)
1181 {
1182     short i, j, k;
1183 
1184     if (user_quote_time > 0)
1185     {
1186         if(ud.screen_size > 0)
1187             gametext( (320>>1),200-41,user_quote,0);
1188         else gametext( (320>>1),200-8,user_quote,0);
1189         if(user_quote_time == 1)
1190         {
1191             pub = NUMPAGES;
1192             pus = NUMPAGES;
1193         }
1194     }
1195 
1196     j = ps[screenpeek].fta;
1197 
1198     if(j > 1)
1199     {
1200         if( ud.coop != 1 && ud.screen_size > 0 && ud.multimode > 1)
1201         {
1202             j = 0;
1203             k = 8;
1204 
1205             for(i=connecthead;i>=0;i=connectpoint2[i])
1206                 if(i > j) j = i;
1207 
1208             if(j >= 4 && j <= 8)
1209                 k += 8;
1210             else if(j > 8 && j <= 12)
1211                 k += 16;
1212             else if(j > 12)
1213                 k += 24;
1214         }
1215         else k = 0;
1216 
1217         gametext(320>>1,k,fta_quotes[ps[screenpeek].ftq],0);
1218     }
1219 }
1220 
FTA(short q,struct player_struct * p)1221 void FTA(short q,struct player_struct *p)
1222 {
1223     if( ud.fta_on == 1)
1224     {
1225         if( p->fta > 0 && q != 115 && q != 116 )
1226             if( p->ftq == 115 || p->ftq == 116 ) return;
1227 
1228         p->fta = 100;
1229 
1230         if( p->ftq != q )
1231         {
1232             pub = NUMPAGES;
1233             pus = NUMPAGES;
1234             p->ftq = q;
1235         }
1236     }
1237 }
1238 
showtwoscreens(void)1239 void showtwoscreens(void)
1240 {
1241     short i;
1242 #ifdef RRRA
1243     return;
1244 #endif
1245     if (!KB_KeyWaiting())
1246     {
1247         getpackets();
1248         if (ready2send != 0)
1249             return;
1250         playanm("in_03.anm", 5, 3);
1251         totalclock = 0;
1252         while (!KB_KeyWaiting());
1253         KB_FlushKeyboardQueue();
1254     }
1255     if (!KB_KeyWaiting())
1256     {
1257         getpackets();
1258         if (ready2send != 0)
1259             return;
1260         playanm("in_04.anm", 5, 3);
1261         totalclock = 0;
1262         while (!KB_KeyWaiting());
1263         KB_FlushKeyboardQueue();
1264     }
1265     return;
1266     for(i=0;i<64;i+=7) palto(0,0,0,i);
1267     KB_FlushKeyboardQueue();
1268     clearview(0L);
1269     rotatesprite(0,0,65536L,0,TENSCREEN,0,0,2+8+16+64, 0,0,xdim-1,ydim-1);
1270     nextpage(); for(i=63;i>0;i-=7) palto(0,0,0,i);
1271     totalclock = 0;
1272     while( !KB_KeyWaiting() && totalclock < 2400);
1273 }
1274 
binscreen(void)1275 void binscreen(void)
1276 {
1277     long fil;
1278     fil = kopen4load("redneck.bin",loadfromgrouponly);
1279     if(fil == -1) return;
1280     kread(fil,(char *)0xb8000,4000);
1281     kclose(fil);
1282 }
1283 
1284 
gameexit(char * t)1285 void gameexit(char *t)
1286 {
1287     short i;
1288 
1289     if(*t != 0) ps[myconnectindex].palette = (char *) &palette[0];
1290 
1291     if(numplayers > 1)
1292     {
1293         allowtimetocorrecterrorswhenquitting();
1294         uninitmultiplayers();
1295     }
1296 
1297     if(ud.recstat == 1) closedemowrite();
1298     else if(ud.recstat == 2) { fclose(frecfilep); }
1299 
1300     if(playerswhenstarted > 1 && ud.coop != 1 && *t == ' ')
1301     {
1302         dobonus(1);
1303         setgamemode(ScreenMode,ScreenWidth,ScreenHeight);
1304     }
1305 
1306     if( *t != 0 && *(t+1) != 'V' && *(t+1) != 'Y' && playonten == 0 )
1307         showtwoscreens();
1308 
1309     Shutdown();
1310 #ifdef RRRA
1311     if (numplayers < 2)
1312 #endif
1313     shutdowncdrom();
1314 
1315     if(*t != 0)
1316     {
1317         setvmode(0x3);
1318         if(playonten == 0)
1319         {
1320             printf("Y'all come back now, ya' hear...\n");
1321 #ifdef RRRA
1322             if (*t != 0)
1323                 printf("%s%s","\n",t);
1324 #endif
1325         }
1326     }
1327 
1328     uninitgroupfile();
1329 
1330     unlink("redneck.tmp");
1331 
1332     exit(0);
1333 }
1334 
1335 
1336 
1337 
1338 short inputloc = 0;
strget(short x,short y,char * t,short dalen,short c)1339 short strget(short x,short y,char *t,short dalen,short c)
1340 {
1341     short ch,sc;
1342 
1343     while(KB_KeyWaiting())
1344     {
1345         sc = 0;
1346         ch = KB_Getch();
1347 
1348         if (ch == 0)
1349         {
1350 
1351             sc = KB_Getch();
1352             if( sc == 104) return(1);
1353 
1354             continue;
1355         }
1356         else
1357         {
1358             if(ch == 8)
1359             {
1360                 if( inputloc > 0 )
1361                 {
1362                     inputloc--;
1363                     *(t+inputloc) = 0;
1364                 }
1365             }
1366             else
1367             {
1368                 if(ch == asc_Enter || sc == 104)
1369                 {
1370                     KB_ClearKeyDown(sc_Enter);
1371                     KB_ClearKeyDown(sc_kpad_Enter);
1372                     return (1);
1373                 }
1374                 else if(ch == asc_Escape)
1375                 {
1376                     KB_ClearKeyDown(sc_Escape);
1377                     return (-1);
1378                 }
1379                 else if ( ch >= 32 && inputloc < dalen && ch < 127)
1380                 {
1381                     ch = toupper(ch);
1382                     *(t+inputloc) = ch;
1383                     *(t+inputloc+1) = 0;
1384                     inputloc++;
1385                 }
1386             }
1387         }
1388     }
1389 
1390     if( c == 999 ) return(0);
1391     if( c == 998 )
1392     {
1393         char b[41],ii;
1394         for(ii=0;ii<inputloc;ii++)
1395             b[ii] = '*';
1396         b[ii] = 0;
1397         x = gametext(x,y,b,c);
1398     }
1399     else x = gametext(x,y,t,c);
1400     c = 4-(sintable[(totalclock<<4)&2047]>>11);
1401 
1402     return (0);
1403 }
1404