blob: 8b2c0e959fb6c82cecd8531a49406d172bc0d2c6 [file] [log] [blame]
Franklin Weia855d622017-01-21 15:18:31 -05001//-------------------------------------------------------------------------
2/*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4
5 This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
6
7 Duke Nukem 3D is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
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 aint32_t with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 Original Source: 1996 - Todd Replogle
23 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
24*/
25//-------------------------------------------------------------------------
26
Franklin Weia855d622017-01-21 15:18:31 -050027#include "SDL.h"
Franklin Weia855d622017-01-21 15:18:31 -050028
29#include "types.h"
30
31#include "develop.h"
32#include "scriplib.h"
33#include "file_lib.h"
34#include "gamedefs.h"
35#include "keyboard.h"
36#include "util_lib.h"
37#include "function.h"
38#include "control.h"
39#include "sounds.h"
40#include "config.h"
41#include "audiolib/sndcards.h"
42
43#include "duke3d.h"
44
45#include "console.h"
46#include "cvars.h"
47#include "cvar_defs.h"
48
49#include "global.h"
50
51
52#define MINITEXT_BLUE 0
53#define MINITEXT_RED 2
54#define MINITEXT_YELLOW 23
55#define MINITEXT_GRAY 17
56
57#define COLOR_ON MINITEXT_YELLOW
58#define COLOR_OFF MINITEXT_BLUE
59
60#define IDFSIZE 479985668
61// #define IDFSIZE 9961476
62// #define IDFSIZE 16384
63#define IDFILENAME "DUKE3D.IDF"
64
65#define TIMERUPDATESIZ 32
66
67int32_t cameradist = 0, cameraclock = 0;
68uint8_t eightytwofifty = 0;
69uint8_t playerswhenstarted;
70uint8_t qe,cp;
71
72uint8_t nHostForceDisableAutoaim = 0;
73
74// Game play speed
75int g_iTickRate = 120;
76int g_iTicksPerFrame = 26;
77
78int32 CommandSoundToggleOff = 0;
79int32 CommandMusicToggleOff = 0;
80
81// For addfaz's stun server. use /stun to activate
82uint16_t g_bStun = 0;
83
84char confilename[128] = {"GAME.CON"};
85char boardfilename[128] = {0};
86uint8_t waterpal[768], slimepal[768], titlepal[768], drealms[768], endingpal[768];
87char firstdemofile[80] = { '\0' };
88
89#define patchstatusbar(x1,y1,x2,y2) \
90 { \
91 rotatesprite(0,(200-34)<<16,65536L,0,BOTTOMSTATUSBAR,4,0,10+16+64+128, \
92 scale(x1,xdim,320),scale(y1,ydim,200), \
93 scale(x2,xdim,320)-1,scale(y2,ydim,200)-1); \
94 }
95
96void newint24( int errval, int ax, int bp, int si );
97
98int recfilep,totalreccnt;
99uint8_t debug_on = 0,actor_tog = 0,memorycheckoveride=0;
100uint8_t *rtsptr;
101
102
103extern uint8_t syncstate;
104extern int32 numlumps;
105
106FILE *frecfilep = (FILE *)NULL;
107void pitch_test( void );
108
109uint8_t restorepalette,screencapt,nomorelogohack;
110int sendmessagecommand = -1;
111
Franklin Weia855d622017-01-21 15:18:31 -0500112extern int32_t lastvisinc;
113
Franklin Weia855d622017-01-21 15:18:31 -0500114void timerhandler(void)
115{
116 totalclock++;
117}
Franklin Weia855d622017-01-21 15:18:31 -0500118
119int gametext(int x,int y,char *t,uint8_t s,short dabits)
120{
121 short ac,newx;
122 char* oldt;
123 uint8_t centre;
124
125 centre = ( x == (320>>1) );
126 newx = 0;
127 oldt = t;
128
129 if(centre)
130 {
131 while(*t)
132 {
133 if(*t == 32) {newx+=5;t++;continue;}
134 else ac = *t - '!' + STARTALPHANUM;
135
136 if( ac < STARTALPHANUM || ac > ENDALPHANUM ) break;
137
138 if(*t >= '0' && *t <= '9')
139 newx += 8;
140 else newx += tiles[ac].dim.width;
141 t++;
142 }
143
144 t = oldt;
145 x = (320>>1)-(newx>>1);
146 }
147
148 while(*t)
149 {
150 if(*t == 32) {x+=5;t++;continue;}
151 else ac = *t - '!' + STARTALPHANUM;
152
153 if( ac < STARTALPHANUM || ac > ENDALPHANUM )
154 break;
155
156 rotatesprite(x<<16,y<<16,65536L,0,ac,s,0,dabits,0,0,xdim-1,ydim-1);
157
158 if(*t >= '0' && *t <= '9')
159 x += 8;
160 else x += tiles[ac].dim.width;
161
162 t++;
163 }
164
165 return (x);
166}
167
168int gametextpal(int x,int y,char *t,uint8_t s,uint8_t p)
169{
170 short ac,newx;
171 uint8_t centre;
172 char* oldt;
173
174 centre = ( x == (320>>1) );
175 newx = 0;
176 oldt = t;
177
178 if(centre)
179 {
180 while(*t)
181 {
182 if(*t == 32) {newx+=5;t++;continue;}
183 else ac = *t - '!' + STARTALPHANUM;
184
185 if( ac < STARTALPHANUM || ac > ENDALPHANUM ) break;
186
187 if(*t >= '0' && *t <= '9')
188 newx += 8;
189 else newx += tiles[ac].dim.width;
190 t++;
191 }
192
193 t = oldt;
194 x = (320>>1)-(newx>>1);
195 }
196
197 while(*t)
198 {
199 if(*t == 32) {x+=5;t++;continue;}
200 else ac = *t - '!' + STARTALPHANUM;
201
202 if( ac < STARTALPHANUM || ac > ENDALPHANUM )
203 break;
204
205 rotatesprite(x<<16,y<<16,65536L,0,ac,s,p,2+8+16,0,0,xdim-1,ydim-1);
206 if(*t >= '0' && *t <= '9')
207 x += 8;
208 else x += tiles[ac].dim.width;
209
210 t++;
211 }
212
213 return (x);
214}
215
216int gametextpart(int x,int y,char *t,uint8_t s,short p)
217{
218 short ac,newx, cnt;
219 uint8_t centre;
220 char * oldt;
221
222 centre = ( x == (320>>1) );
223 newx = 0;
224 oldt = t;
225 cnt = 0;
226
227 if(centre)
228 {
229 while(*t)
230 {
231 if(cnt == p) break;
232
233 if(*t == 32) {newx+=5;t++;continue;}
234 else ac = *t - '!' + STARTALPHANUM;
235
236 if( ac < STARTALPHANUM || ac > ENDALPHANUM ) break;
237
238 newx += tiles[ac].dim.width;
239 t++;
240 cnt++;
241
242 }
243
244 t = oldt;
245 x = (320>>1)-(newx>>1);
246 }
247
248 cnt = 0;
249 while(*t)
250 {
251 if(*t == 32) {x+=5;t++;continue;}
252 else ac = *t - '!' + STARTALPHANUM;
253
254 if( ac < STARTALPHANUM || ac > ENDALPHANUM ) break;
255
256 if(cnt == p)
257 {
258 rotatesprite(x<<16,y<<16,65536L,0,ac,s,1,2+8+16,0,0,xdim-1,ydim-1);
259 break;
260 }
261 else
262 rotatesprite(x<<16,y<<16,65536L,0,ac,s,0,2+8+16,0,0,xdim-1,ydim-1);
263
264 x += tiles[ac].dim.width;
265
266 t++;
267 cnt++;
268 }
269
270 return (x);
271}
272
273int minitext(int x,int y,char *str,uint8_t p,uint8_t sb)
274{
275 short ac;
276 char buf[128];
277 char *t;
278
279 strncpy (buf, str, 128);
280 buf[127] = 0;
281 t = buf;
282
283 while(*t)
284 {
285 *t = toupper(*t);
286 if(*t == 32) {x+=5;t++;continue;}
287 else ac = *t - '!' + MINIFONT;
288
289 rotatesprite(x<<16,y<<16,65536L,0,ac,0,p,sb,0,0,xdim-1,ydim-1);
290 x += 4; // tilesizx[ac]+1;
291
292 t++;
293 }
294 return (x);
295}
296
297int minitextshade(int x,int y,char *str,uint8_t s,uint8_t p,uint8_t sb)
298{
299 short ac;
300 char buf[128];
301 char *t;
302
303 strncpy (buf, str, 128);
304 buf[127] = 0;
305 t = buf;
306
307 while(*t)
308 {
309 *t = toupper(*t);
310 if(*t == 32) {x+=5;t++;continue;}
311 else ac = *t - '!' + MINIFONT;
312
313 rotatesprite(x<<16,y<<16,65536L,0,ac,s,p,sb,0,0,xdim-1,ydim-1);
314 x += 4; // tilesizx[ac]+1;
315
316 t++;
317 }
318 return (x);
319}
320
321void gamenumber(int32_t x,int32_t y,int32_t n,uint8_t s)
322{
323 char b[10];
324
325
326 //
327 // uint8_t * ltoa(int32_t l, uint8_t * buffer, int radix);
328 // is NON-STANDARD and equivalent to STANDARD
329 // (void) sprintf(buffer, "%ld", l);
330 //ltoa(n,b,10);
331 sprintf(b,"%d",n);
332 gametext(x,y,b,s,2+8+16);
333}
334
335
336char recbuf[80];
337void allowtimetocorrecterrorswhenquitting(void)
338{
339 int32_t i, j, oldtotalclock;
340
341 ready2send = 0;
342
343 for(j=0;j<8;j++)
344 {
345 oldtotalclock = totalclock;
346
347 while (totalclock < oldtotalclock+TICSPERFRAME)
348 getpackets();
349
350 if(KB_KeyPressed(sc_Escape)) return;
351
352 packbuf[0] = 127;
353 for(i=connecthead;i>=0;i=connectpoint2[i])
354 if (i != myconnectindex)
355 sendpacket(i,packbuf,1);
356 }
357}
358
359#define MAXUSERQUOTES 4
360int32_t quotebot, quotebotgoal;
361short user_quote_time[MAXUSERQUOTES];
362char user_quote[MAXUSERQUOTES][128];
363// uint8_t typebuflen,typebuf[41];
364
365static void adduserquote(char *daquote)
366{
367 int32_t i;
368
369 for(i=MAXUSERQUOTES-1;i>0;i--)
370 {
371 strcpy(user_quote[i],user_quote[i-1]);
372 user_quote_time[i] = user_quote_time[i-1];
373 }
374 strcpy(user_quote[0],daquote);
375 user_quote_time[0] = 180;
376 pub = NUMPAGES;
377}
378
379char *grpVersion2char_from_crc(unsigned int crc32_grp_to_identify)
380{
381 char *id;
382 int i=0;
383
384 id = crc32lookup[MAX_KNOWN_GRP].name; // unknown version
385
386 for(i=0; i<MAX_KNOWN_GRP; i++)
387 {
388 if(crc32lookup[i].crc32==crc32_grp_to_identify)
389 id = crc32lookup[i].name;
390 }
391
392 return(id);
393}
394
395char *grpVersion2char(uint8_t grp_to_identify)
396{
397 char *id;
398
399 switch(grp_to_identify)
400 {
401 case DUKEITOUTINDC_GRP:
402 id = "v1.5 DC PACK";
403 break;
404 case SHAREWARE_GRP13:
405 id = "v1.3 SHAREW.";
406 break;
407 case ATOMIC_GRP14_15:
408 id = "v1.5 ATOMIC";
409 break;
410 case REGULAR_GRP13D:
411 id = "v1.3D FULL";
412 break;
413 case UNKNOWN_GRP:
414 id = "vX.X UNKNOWN";
415 break;
416 default:
417 Error(EXIT_FAILURE,"Failed the GRP Identification\n");
418 break;
419 }
420
421 return(id);
422}
423
424//This is a function from the Engine module, used in getpackets.
425void sampletimer(void);
426
427void getpackets(void)
428{
429 int32_t i, j, k, l;
430 short other, packbufleng;
431 input *osyn, *nsyn;
432
433 sampletimer();
434 if(qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
435 {
436 qe = 1;
437 gameexit("Quick Exit.");
438 }
439
440 // not a net game
441 if (numplayers < 2)
442 {
443 //printf("getpackets() numplayers < 2");
444 return;
445 }
446
447 while ((packbufleng = getpacket(&other,packbuf)) > 0)
448 {
449#ifdef _DEBUG_NETWORKING_
450 printf("RECEIVED PACKET: type: %d : len %d\n", packbuf[0], packbufleng);
451#endif
452
453 switch(packbuf[0])
454 {
455 case 253:
456 // This should have already been handled by mmulti.cpp so ignore it
457 printf("Invalid Packet: %d", packbuf[0]);
458 break;
459
460 case 125:
461 cp = 0;
462 break;
463
464 case 126:
465 multiflag = 2;
466 multiwhat = 0;
467 multiwho = other;
468 multipos = packbuf[1];
469 loadplayer( multipos );
470 multiflag = 0;
471 break;
472 case 0: //[0] (receive master sync buffer)
473 j = 1;
474
475 if ((movefifoend[other]&(TIMERUPDATESIZ-1)) == 0)
476 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
477 {
478 if (playerquitflag[i] == 0) continue;
479 if (i == myconnectindex)
480 otherminlag = (int32_t)((int8_t )packbuf[j]);
481 j++;
482 }
483
484 osyn = (input *)&inputfifo[(movefifoend[connecthead]-1)&(MOVEFIFOSIZ-1)][0];
485 nsyn = (input *)&inputfifo[(movefifoend[connecthead])&(MOVEFIFOSIZ-1)][0];
486
487 k = j;
488 for(i=connecthead;i>=0;i=connectpoint2[i])
489 j += playerquitflag[i];
490 for(i=connecthead;i>=0;i=connectpoint2[i])
491 {
492 if (playerquitflag[i] == 0) continue;
493
494 l = packbuf[k++];
495 if (i == myconnectindex)
496 { j += ((l&1)<<1)+(l&2)+((l&4)>>2)+((l&8)>>3)+((l&16)>>4)+((l&32)>>5)+((l&64)>>6)+((l&128)>>7); continue; }
497
498 copybufbyte(&osyn[i],&nsyn[i],sizeof(input));
499 if (l&1) nsyn[i].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
500 if (l&2) nsyn[i].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
501 if (l&4) nsyn[i].avel = (int8_t )packbuf[j++];
502 if (l&8) nsyn[i].bits = ((nsyn[i].bits&0xffffff00)|((int32_t)packbuf[j++]));
503 if (l&16) nsyn[i].bits = ((nsyn[i].bits&0xffff00ff)|((int32_t)packbuf[j++])<<8);
504 if (l&32) nsyn[i].bits = ((nsyn[i].bits&0xff00ffff)|((int32_t)packbuf[j++])<<16);
505 if (l&64) nsyn[i].bits = ((nsyn[i].bits&0x00ffffff)|((int32_t)packbuf[j++])<<24);
506 if (l&128) nsyn[i].horz = (int8_t )packbuf[j++];
507
508 if (nsyn[i].bits&(1<<26)) playerquitflag[i] = 0;
509 movefifoend[i]++;
510 }
511
512 while (j != packbufleng)
513 {
514 for(i=connecthead;i>=0;i=connectpoint2[i])
515 if(i != myconnectindex)
516 {
517 syncval[i][syncvalhead[i]&(MOVEFIFOSIZ-1)] = packbuf[j];
518 syncvalhead[i]++;
519 }
520 j++;
521 }
522
523 for(i=connecthead;i>=0;i=connectpoint2[i])
524 if (i != myconnectindex)
525 for(j=1;j<movesperpacket;j++)
526 {
527 copybufbyte(&nsyn[i],&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i],sizeof(input));
528 movefifoend[i]++;
529 }
530
531 movefifosendplc += movesperpacket;
532
533 break;
534 case 1: //[1] (receive slave sync buffer)
535 j = 2; k = packbuf[1];
536
537 osyn = (input *)&inputfifo[(movefifoend[other]-1)&(MOVEFIFOSIZ-1)][0];
538 nsyn = (input *)&inputfifo[(movefifoend[other])&(MOVEFIFOSIZ-1)][0];
539
540 copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
541 if (k&1) nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
542 if (k&2) nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
543 if (k&4) nsyn[other].avel = (int8_t )packbuf[j++];
544 if (k&8) nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int32_t)packbuf[j++]));
545 if (k&16) nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int32_t)packbuf[j++])<<8);
546 if (k&32) nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int32_t)packbuf[j++])<<16);
547 if (k&64) nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int32_t)packbuf[j++])<<24);
548 if (k&128) nsyn[other].horz = (int8_t )packbuf[j++];
549 movefifoend[other]++;
550
551 while (j != packbufleng)
552 {
553 syncval[other][syncvalhead[other]&(MOVEFIFOSIZ-1)] = packbuf[j++];
554 syncvalhead[other]++;
555 }
556
557 for(i=1;i<movesperpacket;i++)
558 {
559 copybufbyte(&nsyn[other],&inputfifo[movefifoend[other]&(MOVEFIFOSIZ-1)][other],sizeof(input));
560 movefifoend[other]++;
561 }
562
563 break;
564
565 case 4: // message talk T
566 strcpy(recbuf,(char*)packbuf+1);
567 recbuf[packbufleng-1] = 0;
568
569 adduserquote(recbuf);
570 sound(EXITMENUSOUND);
571
572 pus = NUMPAGES;
573 pub = NUMPAGES;
574
575 break;
576
577 case 5:
578 ud.m_level_number = ud.level_number = packbuf[1];
579 ud.m_volume_number = ud.volume_number = packbuf[2];
580 ud.m_player_skill = ud.player_skill = packbuf[3];
581 ud.m_monsters_off = ud.monsters_off = packbuf[4];
582 ud.m_respawn_monsters = ud.respawn_monsters = packbuf[5];
583 ud.m_respawn_items = ud.respawn_items = packbuf[6];
584 ud.m_respawn_inventory = ud.respawn_inventory = packbuf[7];
585 ud.m_coop = packbuf[8];
586 ud.m_marker = ud.marker = packbuf[9];
587 ud.m_ffire = ud.ffire = packbuf[10];
588
589 for(i=connecthead;i>=0;i=connectpoint2[i])
590 {
591 resetweapons(i);
592 resetinventory(i);
593 }
594
595 newgame(ud.volume_number,ud.level_number,ud.player_skill);
596 ud.coop = ud.m_coop;
597
598 enterlevel(MODE_GAME);
599
600 break;
601
602 case 6: // get names
603 for (i=2;packbuf[i] && i<=11;i++) // limit size of name
604 ud.user_name[other][i-2] = packbuf[i];
605 ud.user_name[other][i-2] = 0;
606
607 // we allow the old rancidmeat 19.1 to connect, using the old grpVersion system w/ BYTEVERSION
608 if(packbuf[1] == BYTEVERSION_27 || packbuf[1] == BYTEVERSION_117)
609 {
610 // Old rancid was using either BYTEVERSION_27 or BYTEVERSION_117
611 Error(EXIT_SUCCESS, "STOP: Your opponent is using an obsolete version\n"
612 "Please ask him to update to xDuke v%d.%d!\n", CHOCOLATE_DUKE_REV_X, CHOCOLATE_DUKE_REV_DOT_Y);
613 }
614 break;
615
616 case 9:
617 for (i=1;i<packbufleng;i++)
618 ud.wchoice[other][i-1] = packbuf[i];
619 break;
620
621 case 7:
622
623 if(numlumps == 0) break;
624
625 if (SoundToggle == 0 || ud.lockout == 1 || FXDevice == NumSoundCards)
626 break;
627 rtsptr = RTS_GetSound(packbuf[1]-1);
628 if (*rtsptr == 'C')
629 FX_PlayVOC3D(rtsptr,0,0,0,255,-packbuf[1]);
630 else
631 FX_PlayWAV3D(rtsptr,0,0,0,255,-packbuf[1]);
632 rtsplaying = 7;
633 break;
634 case 8:
635 ud.m_level_number = ud.level_number = packbuf[1];
636 ud.m_volume_number = ud.volume_number = packbuf[2];
637 ud.m_player_skill = ud.player_skill = packbuf[3];
638 ud.m_monsters_off = ud.monsters_off = packbuf[4];
639 ud.m_respawn_monsters = ud.respawn_monsters = packbuf[5];
640 ud.m_respawn_items = ud.respawn_items = packbuf[6];
641 ud.m_respawn_inventory = ud.respawn_inventory = packbuf[7];
642 ud.m_coop = ud.coop = packbuf[8];
643 ud.m_marker = ud.marker = packbuf[9];
644 ud.m_ffire = ud.ffire = packbuf[10];
645
646 copybufbyte(packbuf+10,boardfilename,packbufleng-11);
647 boardfilename[packbufleng-11] = 0;
648
649 for(i=connecthead;i>=0;i=connectpoint2[i])
650 {
651 resetweapons(i);
652 resetinventory(i);
653 }
654
655 newgame(ud.volume_number,ud.level_number,ud.player_skill);
656 enterlevel(MODE_GAME);
657 break;
658
659 case 16:
660 movefifoend[other] = movefifoplc = movefifosendplc = fakemovefifoplc = 0;
661 syncvalhead[other] = syncvaltottail = 0L;
662
663 case 17:
664 j = 1;
665
666 if ((movefifoend[other]&(TIMERUPDATESIZ-1)) == 0)
667 if (other == connecthead)
668 for(i=connectpoint2[connecthead]; i>=0; i=connectpoint2[i])
669 {
670 if (i == myconnectindex)
671 {
672 otherminlag = (int32_t)((int8_t )packbuf[j]);
673 }
674
675 j++;
676 }
677
678 osyn = (input *)&inputfifo[(movefifoend[other]-1)&(MOVEFIFOSIZ-1)][0];
679 nsyn = (input *)&inputfifo[(movefifoend[other])&(MOVEFIFOSIZ-1)][0];
680
681 copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
682 k = packbuf[j++];
683 if (k&1) nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
684 if (k&2) nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
685 if (k&4) nsyn[other].avel = (int8_t )packbuf[j++];
686 if (k&8) nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int32_t)packbuf[j++]));
687 if (k&16) nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int32_t)packbuf[j++])<<8);
688 if (k&32) nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int32_t)packbuf[j++])<<16);
689 if (k&64) nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int32_t)packbuf[j++])<<24);
690 if (k&128) nsyn[other].horz = (int8_t )packbuf[j++];
691 movefifoend[other]++;
692
693 for(i=1;i<movesperpacket;i++)
694 {
695 copybufbyte(&nsyn[other],&inputfifo[movefifoend[other]&(MOVEFIFOSIZ-1)][other],sizeof(input));
696 movefifoend[other]++;
697 }
698
699 if (j > packbufleng)
700 {
701 printf("INVALID GAME PACKET!!! (%d too many bytes) (j= %d, packbuflen= %d, type: %d)\n",j-packbufleng, j, packbufleng, packbuf[0]);
702 }
703
704 while (j != packbufleng)
705 {
706 syncval[other][syncvalhead[other]&(MOVEFIFOSIZ-1)] = packbuf[j++];
707 syncvalhead[other]++;
708 }
709
710 break;
711 case 127:
712 break;
713
714#ifdef CHECK_XDUKE_REV
715 case 131: // xDuke Rev ID
716 memcpy(ud.rev[other], packbuf, 10);
717 break;
718#endif
719
720 case 132: // get map CRC of opponents (to debug out of synch)
721 ud.mapCRC[other] = (uint16_t)packbuf[1] + (uint16_t)(packbuf[2]<<8);
722 break;
723
724 case 133: // client refused to disable the autoaim by host
725
726 Error(EXIT_SUCCESS, "One or more players refused to play with AutoAim OFF because this breaks\n"
727 "the official Duke's gameplay. Please restart without this option...\n");
728
729 break;
730
731 case 134: // Get GRP CRC32 + Con size + exeCRC + conCRC
732 memcpy(ud.groupefil_crc32[other], packbuf+1, sizeof(groupefil_crc32));
733 memcpy(ud.conSize+other, packbuf+1+sizeof(groupefil_crc32), sizeof(ud.conSize[0]));
734 memcpy(ud.conCRC+other, packbuf+1+sizeof(groupefil_crc32)+sizeof(ud.conSize[0]), sizeof(ud.conCRC[0]));
735 memcpy(ud.exeCRC+other, packbuf+1+sizeof(groupefil_crc32)+sizeof(ud.conSize[0])+sizeof(ud.conCRC[0]), sizeof(ud.exeCRC[0]));
736 break;
737
738 case 250:
739 {
740 playerreadyflag[other]++;
741 printf("Player %d '%s' is ready...\n", other, ud.user_name[other]);
742 }
743 break;
744 case 255:
745 gameexitanycase();
746 break;
747 }
748 }
749 rb->yield();
750}
751
752//From player.c
753void computergetinput(int32_t snum, input *syn);
754void faketimerhandler()
755{
756 int32_t i, j, k;
757 input *osyn, *nsyn;
758
759 //Check if we should quit the game.
760 if ((qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete)) ||
761 (qe == 0 && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_F4)))
762 {
763 qe = 1;
764 gameexit("Quick Exit.");
765 }
766
767 //Has it been 120ticks ?
768 if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0))
769 return; // Returns here when playing a demo.
770
771 //YES : Add 120tick
772 ototalclock += TICSPERFRAME;
773
774 //Check network stuff.
775 getpackets();
776 if (getoutputcirclesize() >= 16)
777 return;
778
779
780 for(i=connecthead;i>=0;i=connectpoint2[i])
781 if (i != myconnectindex)
782 if (movefifoend[i] < movefifoend[myconnectindex]-200)
783 return;
784
785 if( !CONSOLE_IsActive())
786 {
787 getinput(myconnectindex);
788 }
789
790 avgfvel += loc.fvel; // x
791 avgsvel += loc.svel; // y
792 avgavel += loc.avel;
793 avghorz += loc.horz;
794 avgbits |= loc.bits;
795 if (movefifoend[myconnectindex]&(movesperpacket-1))
796 {
797 copybufbyte(&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex],
798 &inputfifo[movefifoend[myconnectindex]&(MOVEFIFOSIZ-1)][myconnectindex],sizeof(input));
799 movefifoend[myconnectindex]++;
800 return;
801 }
802
803 nsyn = &inputfifo[movefifoend[myconnectindex]&(MOVEFIFOSIZ-1)][myconnectindex];
804 nsyn[0].fvel = avgfvel/movesperpacket;
805 nsyn[0].svel = avgsvel/movesperpacket;
806 nsyn[0].avel = avgavel/movesperpacket;
807 nsyn[0].horz = avghorz/movesperpacket;
808 nsyn[0].bits = avgbits;
809 avgfvel = avgsvel = avgavel = avghorz = avgbits = 0;
810 movefifoend[myconnectindex]++;
811
812 if (numplayers < 2)
813 {
814 if (ud.multimode > 1) for(i=connecthead;i>=0;i=connectpoint2[i])
815 if(i != myconnectindex)
816 {
817 //clearbufbyte(&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i],sizeof(input),0L);
818 if(ud.playerai)
819 computergetinput(i,&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i]);
820 movefifoend[i]++;
821 }
822 return;
823 }
824
825 for(i=connecthead;i>=0;i=connectpoint2[i])
826 if (i != myconnectindex)
827 {
828 k = (movefifoend[myconnectindex]-1)-movefifoend[i];
829 myminlag[i] = min(myminlag[i],k);
830 mymaxlag = max(mymaxlag,k);
831 }
832
833 if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
834 {
835 i = mymaxlag-bufferjitter; mymaxlag = 0;
836 if (i > 0) bufferjitter += ((3+i)>>2);
837 else if (i < 0) bufferjitter -= ((1-i)>>2);
838 }
839
840 if (networkmode == 1)
841 {
842 packbuf[0] = 17;
843
844 if ((movefifoend[myconnectindex]-1) == 0)
845 {
846 packbuf[0] = 16;
847 }
848
849 j = 1;
850
851 //Fix timers and buffer/jitter value
852 if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
853 {
854 if (myconnectindex != connecthead)
855 {
856 i = myminlag[connecthead]-otherminlag;
857 if (klabs(i) > 8)
858 {
859 i >>= 1;
860 }
861 else
862 if (klabs(i) > 2)
863 {
864 i = ksgn(i);
865 }
866 else
867 {
868 i = 0;
869 }
870
871 totalclock -= TICSPERFRAME*i;
872 myminlag[connecthead] -= i; otherminlag += i;
873 }
874
875 if (myconnectindex == connecthead)
876 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
877 packbuf[j++] = min(max(myminlag[i],-128),127);
878
879 for(i=connecthead;i>=0;i=connectpoint2[i])
880 myminlag[i] = 0x7fffffff;
881 }
882
883 osyn = (input *)&inputfifo[(movefifoend[myconnectindex]-2)&(MOVEFIFOSIZ-1)][myconnectindex];
884 nsyn = (input *)&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex];
885
886 k = j;
887 packbuf[j++] = 0;
888
889 if (nsyn[0].fvel != osyn[0].fvel)
890 {
891 packbuf[j++] = (uint8_t )nsyn[0].fvel;
892 packbuf[j++] = (uint8_t )(nsyn[0].fvel>>8);
893 packbuf[k] |= 1;
894 }
895 if (nsyn[0].svel != osyn[0].svel)
896 {
897 packbuf[j++] = (uint8_t )nsyn[0].svel;
898 packbuf[j++] = (uint8_t )(nsyn[0].svel>>8);
899 packbuf[k] |= 2;
900 }
901 if (nsyn[0].avel != osyn[0].avel)
902 {
903 packbuf[j++] = (int8_t )nsyn[0].avel;
904 packbuf[k] |= 4;
905 }
906 if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[k] |= 8;
907 if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[k] |= 16;
908 if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[k] |= 32;
909 if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[k] |= 64;
910 if (nsyn[0].horz != osyn[0].horz)
911 {
912 packbuf[j++] = (uint8_t )nsyn[0].horz;
913 packbuf[k] |= 128;
914 }
915
916 while (syncvalhead[myconnectindex] != syncvaltail)
917 {
918 packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
919 syncvaltail++;
920 }
921
922 for(i=connecthead;i>=0;i=connectpoint2[i])
923 if (i != myconnectindex)
924 sendpacket(i,packbuf,j);
925
926 return;
927 }
928 if (myconnectindex != connecthead) //Slave
929 {
930 //Fix timers and buffer/jitter value
931 if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
932 {
933 i = myminlag[connecthead]-otherminlag;
934 if (klabs(i) > 8) i >>= 1;
935 else if (klabs(i) > 2) i = ksgn(i);
936 else i = 0;
937
938 totalclock -= TICSPERFRAME*i;
939 myminlag[connecthead] -= i; otherminlag += i;
940
941 for(i=connecthead;i>=0;i=connectpoint2[i])
942 myminlag[i] = 0x7fffffff;
943 }
944
945 packbuf[0] = 1; packbuf[1] = 0; j = 2;
946
947 osyn = (input *)&inputfifo[(movefifoend[myconnectindex]-2)&(MOVEFIFOSIZ-1)][myconnectindex];
948 nsyn = (input *)&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex];
949
950 if (nsyn[0].fvel != osyn[0].fvel)
951 {
952 packbuf[j++] = (uint8_t )nsyn[0].fvel;
953 packbuf[j++] = (uint8_t )(nsyn[0].fvel>>8);
954 packbuf[1] |= 1;
955 }
956 if (nsyn[0].svel != osyn[0].svel)
957 {
958 packbuf[j++] = (uint8_t )nsyn[0].svel;
959 packbuf[j++] = (uint8_t )(nsyn[0].svel>>8);
960 packbuf[1] |= 2;
961 }
962 if (nsyn[0].avel != osyn[0].avel)
963 {
964 packbuf[j++] = (int8_t )nsyn[0].avel;
965 packbuf[1] |= 4;
966 }
967 if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[1] |= 8;
968 if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[1] |= 16;
969 if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[1] |= 32;
970 if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[1] |= 64;
971 if (nsyn[0].horz != osyn[0].horz)
972 {
973 packbuf[j++] = (uint8_t )nsyn[0].horz;
974 packbuf[1] |= 128;
975 }
976
977 while (syncvalhead[myconnectindex] != syncvaltail)
978 {
979 packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
980 syncvaltail++;
981 }
982
983 sendpacket(connecthead,packbuf,j);
984 return;
985 }
986
987 //This allows allow packet-resends
988 for(i=connecthead;i>=0;i=connectpoint2[i])
989 if (movefifoend[i] <= movefifosendplc)
990 {
991 packbuf[0] = 127;
992 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
993 sendpacket(i,packbuf,1);
994 return;
995 }
996
997 while (1) //Master
998 {
999 for(i=connecthead;i>=0;i=connectpoint2[i])
1000 if (playerquitflag[i] && (movefifoend[i] <= movefifosendplc)) return;
1001
1002 osyn = (input *)&inputfifo[(movefifosendplc-1)&(MOVEFIFOSIZ-1)][0];
1003 nsyn = (input *)&inputfifo[(movefifosendplc )&(MOVEFIFOSIZ-1)][0];
1004
1005 //MASTER -> SLAVE packet
1006 packbuf[0] = 0; j = 1;
1007
1008 //Fix timers and buffer/jitter value
1009 if ((movefifosendplc&(TIMERUPDATESIZ-1)) == 0)
1010 {
1011 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1012 if (playerquitflag[i])
1013 packbuf[j++] = min(max(myminlag[i],-128),127);
1014
1015 for(i=connecthead;i>=0;i=connectpoint2[i])
1016 myminlag[i] = 0x7fffffff;
1017 }
1018
1019 k = j;
1020 for(i=connecthead;i>=0;i=connectpoint2[i])
1021 j += playerquitflag[i];
1022 for(i=connecthead;i>=0;i=connectpoint2[i])
1023 {
1024 if (playerquitflag[i] == 0) continue;
1025
1026 packbuf[k] = 0;
1027 if (nsyn[i].fvel != osyn[i].fvel)
1028 {
1029 packbuf[j++] = (uint8_t )nsyn[i].fvel;
1030 packbuf[j++] = (uint8_t )(nsyn[i].fvel>>8);
1031 packbuf[k] |= 1;
1032 }
1033 if (nsyn[i].svel != osyn[i].svel)
1034 {
1035 packbuf[j++] = (uint8_t )nsyn[i].svel;
1036 packbuf[j++] = (uint8_t )(nsyn[i].svel>>8);
1037 packbuf[k] |= 2;
1038 }
1039 if (nsyn[i].avel != osyn[i].avel)
1040 {
1041 packbuf[j++] = (int8_t )nsyn[i].avel;
1042 packbuf[k] |= 4;
1043 }
1044 if ((nsyn[i].bits^osyn[i].bits)&0x000000ff) packbuf[j++] = (nsyn[i].bits&255), packbuf[k] |= 8;
1045 if ((nsyn[i].bits^osyn[i].bits)&0x0000ff00) packbuf[j++] = ((nsyn[i].bits>>8)&255), packbuf[k] |= 16;
1046 if ((nsyn[i].bits^osyn[i].bits)&0x00ff0000) packbuf[j++] = ((nsyn[i].bits>>16)&255), packbuf[k] |= 32;
1047 if ((nsyn[i].bits^osyn[i].bits)&0xff000000) packbuf[j++] = ((nsyn[i].bits>>24)&255), packbuf[k] |= 64;
1048 if (nsyn[i].horz != osyn[i].horz)
1049 {
1050 packbuf[j++] = (uint8_t )nsyn[i].horz;
1051 packbuf[k] |= 128;
1052 }
1053 k++;
1054 }
1055
1056 while (syncvalhead[myconnectindex] != syncvaltail)
1057 {
1058 packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
1059 syncvaltail++;
1060 }
1061
1062 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1063 if (playerquitflag[i])
1064 {
1065 sendpacket(i,packbuf,j);
1066 if (nsyn[i].bits&(1<<26))
1067 playerquitflag[i] = 0;
1068 }
1069
1070 movefifosendplc += movesperpacket;
1071 }
1072}
1073
1074extern int32_t cacnum;
1075
1076typedef struct {
1077 uint8_t *hand;
1078 int32_t leng;
1079 uint8_t *lock; }
1080 cactype;
1081extern cactype cac[];
1082
1083void caches(void)
1084{
1085 short i,k;
1086 char text[512];
1087
1088 k = 0;
1089 for(i=0;i<cacnum;i++)
1090 if ((*cac[i].lock) >= 200)
1091 {
1092 sprintf(text,"Locked- %d: Leng:%d, Lock:%d",i,cac[i].leng,*cac[i].lock);
1093 printext256(0L,k,31,-1,text,1); k += 6;
1094 }
1095
1096 k += 6;
1097
1098 for(i=1;i<11;i++)
1099 if (lumplockbyte[i] >= 200)
1100 {
1101 sprintf(text,"RTS Locked %hd:",i);
1102 printext256(0L,k,31,-1,text,1); k += 6;
1103 }
1104
1105
1106}
1107
1108// FIX_00024: A key can be assigned to the new SHOW_INFO function. Display map CRC when
1109// in deathmatch. Usefull to identify who loaded a wrong map in multiplayer.
1110void dispVersion(void)
1111{
1112 int i;
1113 int offx, offy, stepx, stepy;
1114 char text[512];
1115
1116 offx = 21; offy = 30;
1117 stepx = 73; stepy = 20;
1118
1119 // black translucent background underneath lists
1120 rotatesprite(0<<16, 0<<16, 65536l<<5, 0, BLANK, 8, 0, 1+2+8+16+64,
1121 scale(0,xdim,320),scale(26,ydim,200),
1122 scale(320-0,xdim,320)-1,scale(200-((ud.multimode>4)?(161-1*7)-stepy:(161-1*7)),ydim,200)-1);
1123
1124 // FIX_00009: Show map CRC and GRP file version of each player in case of Out Of Synch
1125 for(i=connecthead;i>=0;i=connectpoint2[i])
1126 {
1127 // Disp name
1128 sprintf(text,"%s", ud.user_name[i]);
1129 minitext(offx+(stepx*(i&3)),offy+0+((i&4)>>2)*stepy, text, sprite[ps[i].i].pal, 2+8+16);
1130
1131 // Disp MAP CRC
1132 if(ps[i].fakeplayer)
1133 sprintf(text,"MAP CRC: (bot)");
1134 else
1135 sprintf(text,"MAP CRC: %X", ud.mapCRC[i]);
1136 minitext(offx+(stepx*(i&3)),offy+7+((i&4)>>2)*stepy, text, COLOR_ON,2+8+16);
1137
1138 }
1139}
1140
1141void checksync(void)
1142{
1143 int32_t i;
1144
1145 for(i=connecthead;i>=0;i=connectpoint2[i])
1146 if (syncvalhead[i] == syncvaltottail) break;
1147 if (i < 0)
1148 {
1149 syncstat = 0;
1150 do
1151 {
1152 for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1153 {
1154 if (syncval[i][syncvaltottail&(MOVEFIFOSIZ-1)] != syncval[connecthead][syncvaltottail&(MOVEFIFOSIZ-1)])
1155 {
1156 syncstat = 1;
1157 }
1158 }
1159
1160 syncvaltottail++;
1161 for(i=connecthead;i>=0;i=connectpoint2[i])
1162 {
1163 if (syncvalhead[i] == syncvaltottail)
1164 {
1165 break;
1166 }
1167 }
1168 } while (i < 0);
1169 }
1170
1171 if (connectpoint2[connecthead] < 0)
1172 {
1173 syncstat = 0;
1174 }
1175
1176 if (syncstat)
1177 {
1178 minitext(21,30+35+30, "Out Of Sync - Please restart game", COLOR_ON,2+8+16);
1179 // FIX_00090: Removed info key. FPS were shown after CRC msg. CRC not always removed. (Turrican)
1180 for(i=connecthead;i>=0;i=connectpoint2[i])
1181 {
1182 if (ud.mapCRC[connecthead]!=ud.mapCRC[i])
1183 {
1184 minitext(21,30+42+30, "Map CRC mismatching. Please use exactly the same map.", COLOR_ON,2+8+16);
1185 dispVersion();
1186 }
1187 else
1188 minitext(21,30+42+30, "Verify the con files. Close your P2P if any", COLOR_ON,2+8+16);
1189
1190 }
1191 }
1192
1193 if (syncstate)
1194 {
1195 //printext256(4L,160L,31,0,"Missed Network packet!",0);
1196 //printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0);
1197 minitext(21,30+35+30, "Missed Network packet!", COLOR_ON,2+8+16);
1198 }
1199
1200}
1201
1202
1203void check_fta_sounds(short i)
1204{
1205 if(sprite[i].extra > 0) switch(PN)
1206 {
1207 case LIZTROOPONTOILET:
1208 case LIZTROOPJUSTSIT:
1209 case LIZTROOPSHOOT:
1210 case LIZTROOPJETPACK:
1211 case LIZTROOPDUCKING:
1212 case LIZTROOPRUNNING:
1213 case LIZTROOP:
1214 spritesound(PRED_RECOG,i);
1215 break;
1216 case LIZMAN:
1217 case LIZMANSPITTING:
1218 case LIZMANFEEDING:
1219 case LIZMANJUMP:
1220 spritesound(CAPT_RECOG,i);
1221 break;
1222 case PIGCOP:
1223 case PIGCOPDIVE:
1224 spritesound(PIG_RECOG,i);
1225 break;
1226 case RECON:
1227 spritesound(RECO_RECOG,i);
1228 break;
1229 case DRONE:
1230 spritesound(DRON_RECOG,i);
1231 break;
1232 case COMMANDER:
1233 case COMMANDERSTAYPUT:
1234 spritesound(COMM_RECOG,i);
1235 break;
1236 case ORGANTIC:
1237 spritesound(TURR_RECOG,i);
1238 break;
1239 case OCTABRAIN:
1240 case OCTABRAINSTAYPUT:
1241 spritesound(OCTA_RECOG,i);
1242 break;
1243 case BOSS1:
1244 sound(BOS1_RECOG);
1245 break;
1246 case BOSS2:
1247 if(sprite[i].pal == 1)
1248 sound(BOS2_RECOG);
1249 else sound(WHIPYOURASS);
1250 break;
1251 case BOSS3:
1252 if(sprite[i].pal == 1)
1253 sound(BOS3_RECOG);
1254 else sound(RIPHEADNECK);
1255 break;
1256 case BOSS4:
1257 case BOSS4STAYPUT:
1258 if(sprite[i].pal == 1)
1259 sound(BOS4_RECOG);
1260 sound(BOSS4_FIRSTSEE);
1261 break;
1262 case GREENSLIME:
1263 spritesound(SLIM_RECOG,i);
1264 break;
1265 }
1266}
1267
1268short inventory(spritetype *s)
1269{
1270 switch(s->picnum)
1271 {
1272 case FIRSTAID:
1273 case STEROIDS:
1274 case HEATSENSOR:
1275 case BOOTS:
1276 case JETPACK:
1277 case HOLODUKE:
1278 case AIRTANK:
1279 return 1;
1280 }
1281 return 0;
1282}
1283
1284
1285short badguy(spritetype *s)
1286{
1287
1288 switch(s->picnum)
1289 {
1290 case SHARK:
1291 case RECON:
1292 case DRONE:
1293 case LIZTROOPONTOILET:
1294 case LIZTROOPJUSTSIT:
1295 case LIZTROOPSTAYPUT:
1296 case LIZTROOPSHOOT:
1297 case LIZTROOPJETPACK:
1298 case LIZTROOPDUCKING:
1299 case LIZTROOPRUNNING:
1300 case LIZTROOP:
1301 case OCTABRAIN:
1302 case COMMANDER:
1303 case COMMANDERSTAYPUT:
1304 case PIGCOP:
1305 case EGG:
1306 case PIGCOPSTAYPUT:
1307 case PIGCOPDIVE:
1308 case LIZMAN:
1309 case LIZMANSPITTING:
1310 case LIZMANFEEDING:
1311 case LIZMANJUMP:
1312 case ORGANTIC:
1313 case BOSS1:
1314 case BOSS2:
1315 case BOSS3:
1316 case BOSS4:
1317 case GREENSLIME:
1318 case GREENSLIME+1:
1319 case GREENSLIME+2:
1320 case GREENSLIME+3:
1321 case GREENSLIME+4:
1322 case GREENSLIME+5:
1323 case GREENSLIME+6:
1324 case GREENSLIME+7:
1325 case RAT:
1326 case ROTATEGUN:
1327 return 1;
1328 }
1329 if( actortype[s->picnum] ) return 1;
1330
1331 return 0;
1332}
1333
1334
1335short badguypic(short pn)
1336{
1337
1338 switch(pn)
1339 {
1340 case SHARK:
1341 case RECON:
1342 case DRONE:
1343 case LIZTROOPONTOILET:
1344 case LIZTROOPJUSTSIT:
1345 case LIZTROOPSTAYPUT:
1346 case LIZTROOPSHOOT:
1347 case LIZTROOPJETPACK:
1348 case LIZTROOPDUCKING:
1349 case LIZTROOPRUNNING:
1350 case LIZTROOP:
1351 case OCTABRAIN:
1352 case COMMANDER:
1353 case COMMANDERSTAYPUT:
1354 case PIGCOP:
1355 case EGG:
1356 case PIGCOPSTAYPUT:
1357 case PIGCOPDIVE:
1358 case LIZMAN:
1359 case LIZMANSPITTING:
1360 case LIZMANFEEDING:
1361 case LIZMANJUMP:
1362 case ORGANTIC:
1363 case BOSS1:
1364 case BOSS2:
1365 case BOSS3:
1366 case BOSS4:
1367 case GREENSLIME:
1368 case GREENSLIME+1:
1369 case GREENSLIME+2:
1370 case GREENSLIME+3:
1371 case GREENSLIME+4:
1372 case GREENSLIME+5:
1373 case GREENSLIME+6:
1374 case GREENSLIME+7:
1375 case RAT:
1376 case ROTATEGUN:
1377 return 1;
1378 }
1379
1380 if( actortype[pn] ) return 1;
1381
1382 return 0;
1383}
1384
1385
1386
1387void myos(int32_t x, int32_t y, short tilenum, int8_t shade, uint8_t orientation)
1388{
1389 uint8_t p;
1390 short a;
1391
1392 if(orientation&4)
1393 a = 1024;
1394 else a = 0;
1395
1396 p = sector[ps[screenpeek].cursectnum].floorpal;
1397 rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1398}
1399
1400void myospal(int32_t x, int32_t y, short tilenum, int8_t shade, uint8_t orientation, uint8_t p)
1401{
1402// uint8_t fp;
1403 short a;
1404
1405 if(orientation&4)
1406 a = 1024;
1407 else a = 0;
1408
1409// fp = sector[ps[screenpeek].cursectnum].floorpal;
1410
1411 rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1412
1413}
1414
1415void invennum(int32_t x,int32_t y,uint8_t num1,uint8_t ha,uint8_t sbits)
1416{
1417 char dabuf[80] = {0};
1418 sprintf(dabuf,"%d",num1);
1419 if(num1 > 99)
1420 {
1421 rotatesprite((x-4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1422 rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1423 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1424 }
1425 else if(num1 > 9)
1426 {
1427 rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1428 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1429 }
1430 else
1431 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1432}
1433
1434void orderweaponnum(short ind,int32_t x,int32_t y,int32_t num1, int32_t num2,uint8_t ha)
1435{
1436 rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
1437 rotatesprite((x-3)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
1438
1439 minitextshade(x+1,y-4,"ORDER",26,6,2+8+16+128);
1440}
1441
1442void weaponnum(short ind,int32_t x,int32_t y,int32_t num1, int32_t num2,uint8_t ha)
1443{
1444 char dabuf[80] = {0};
1445
1446 rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
1447 rotatesprite((x-3)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
1448 rotatesprite((x+9)<<16,y<<16,65536L,0,THREEBYFIVE+11,ha,0,10+128,0,0,xdim-1,ydim-1);
1449
1450 if(num1 > 99) num1 = 99;
1451 if(num2 > 99) num2 = 99;
1452
1453 sprintf(dabuf,"%d",num1);
1454 if(num1 > 9)
1455 {
1456 rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1457 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1458 }
1459 else rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1460
1461 sprintf(dabuf,"%d",num2);
1462 if(num2 > 9)
1463 {
1464 rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1465 rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1466 }
1467 else rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1468}
1469
1470void weaponnum999(uint8_t ind,int32_t x,int32_t y,int32_t num1, int32_t num2,uint8_t ha)
1471{
1472 char dabuf[80] = {0};
1473
1474 rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
1475 rotatesprite((x-4)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
1476 rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+11,ha,0,10+128,0,0,xdim-1,ydim-1);
1477
1478 sprintf(dabuf,"%d",num1);
1479 if(num1 > 99)
1480 {
1481 rotatesprite((x)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1482 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1483 rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1484 }
1485 else if(num1 > 9)
1486 {
1487 rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1488 rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1489 }
1490 else rotatesprite((x+8)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1491
1492 sprintf(dabuf,"%d",num2);
1493 if(num2 > 99)
1494 {
1495 rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1496 rotatesprite((x+21)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1497 rotatesprite((x+25)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[2]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1498 }
1499 else if(num2 > 9)
1500 {
1501 rotatesprite((x+17)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1502 rotatesprite((x+21)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[1]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1503 }
1504 else rotatesprite((x+25)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
1505}
1506
1507
1508//REPLACE FULLY
1509void weapon_amounts(struct player_struct *p,int32_t x,int32_t y,int32_t u)
1510{
1511 int cw;
1512
1513 cw = p->curr_weapon;
1514
1515 if (u&4)
1516 {
1517 if (u != 0xffffffff) patchstatusbar(96,178,96+12,178+6);
1518 weaponnum999(PISTOL_WEAPON,x,y,
1519 p->ammo_amount[PISTOL_WEAPON],max_ammo_amount[PISTOL_WEAPON],
1520 12-20*(cw == PISTOL_WEAPON) );
1521 }
1522 if (u&8)
1523 {
1524 if (u != 0xffffffff) patchstatusbar(96,184,96+12,184+6);
1525 weaponnum999(SHOTGUN_WEAPON,x,y+6,
1526 p->ammo_amount[SHOTGUN_WEAPON],max_ammo_amount[SHOTGUN_WEAPON],
1527 (!p->gotweapon[SHOTGUN_WEAPON]*9)+12-18*
1528 (cw == SHOTGUN_WEAPON) );
1529 }
1530 if (u&16)
1531 {
1532 if (u != 0xffffffff) patchstatusbar(96,190,96+12,190+6);
1533 weaponnum999(CHAINGUN_WEAPON,x,y+12,
1534 p->ammo_amount[CHAINGUN_WEAPON],max_ammo_amount[CHAINGUN_WEAPON],
1535 (!p->gotweapon[CHAINGUN_WEAPON]*9)+12-18*
1536 (cw == CHAINGUN_WEAPON) );
1537 }
1538 if (u&32)
1539 {
1540 if (u != 0xffffffff) patchstatusbar(135,178,135+8,178+6);
1541 weaponnum(RPG_WEAPON,x+39,y,
1542 p->ammo_amount[RPG_WEAPON],max_ammo_amount[RPG_WEAPON],
1543 (!p->gotweapon[RPG_WEAPON]*9)+12-19*
1544 (cw == RPG_WEAPON) );
1545 }
1546 if (u&64)
1547 {
1548 if (u != 0xffffffff) patchstatusbar(135,184,135+8,184+6);
1549 weaponnum(HANDBOMB_WEAPON,x+39,y+6,
1550 p->ammo_amount[HANDBOMB_WEAPON],max_ammo_amount[HANDBOMB_WEAPON],
1551 (((!p->ammo_amount[HANDBOMB_WEAPON])|(!p->gotweapon[HANDBOMB_WEAPON]))*9)+12-19*
1552 ((cw == HANDBOMB_WEAPON) || (cw == HANDREMOTE_WEAPON)));
1553 }
1554 if (u&128)
1555 {
1556 if (u != 0xffffffff) patchstatusbar(135,190,135+8,190+6);
1557
1558 if(VOLUMEONE)
1559 {
1560 orderweaponnum(SHRINKER_WEAPON,x+39,y+12,
1561 p->ammo_amount[SHRINKER_WEAPON],max_ammo_amount[SHRINKER_WEAPON],
1562 (!p->gotweapon[SHRINKER_WEAPON]*9)+12-18*
1563 (cw == SHRINKER_WEAPON) );
1564 }
1565 else
1566 {
1567 if(p->subweapon&(1<<GROW_WEAPON))
1568 weaponnum(SHRINKER_WEAPON,x+39,y+12,
1569 p->ammo_amount[GROW_WEAPON],max_ammo_amount[GROW_WEAPON],
1570 (!p->gotweapon[GROW_WEAPON]*9)+12-18*
1571 (cw == GROW_WEAPON) );
1572 else
1573 weaponnum(SHRINKER_WEAPON,x+39,y+12,
1574 p->ammo_amount[SHRINKER_WEAPON],max_ammo_amount[SHRINKER_WEAPON],
1575 (!p->gotweapon[SHRINKER_WEAPON]*9)+12-18*
1576 (cw == SHRINKER_WEAPON) );
1577 }
1578 }
1579 if (u&256)
1580 {
1581 if (u != 0xffffffff) patchstatusbar(166,178,166+8,178+6);
1582
1583 if(VOLUMEONE)
1584 {
1585 orderweaponnum(DEVISTATOR_WEAPON,x+70,y,
1586 p->ammo_amount[DEVISTATOR_WEAPON],max_ammo_amount[DEVISTATOR_WEAPON],
1587 (!p->gotweapon[DEVISTATOR_WEAPON]*9)+12-18*
1588 (cw == DEVISTATOR_WEAPON) );
1589 }
1590 else
1591 {
1592 weaponnum(DEVISTATOR_WEAPON,x+70,y,
1593 p->ammo_amount[DEVISTATOR_WEAPON],max_ammo_amount[DEVISTATOR_WEAPON],
1594 (!p->gotweapon[DEVISTATOR_WEAPON]*9)+12-18*
1595 (cw == DEVISTATOR_WEAPON) );
1596 }
1597 }
1598 if (u&512)
1599 {
1600 if (u != 0xffffffff) patchstatusbar(166,184,166+8,184+6);
1601 if(VOLUMEONE)
1602 {
1603 orderweaponnum(TRIPBOMB_WEAPON,x+70,y+6,
1604 p->ammo_amount[TRIPBOMB_WEAPON],max_ammo_amount[TRIPBOMB_WEAPON],
1605 (!p->gotweapon[TRIPBOMB_WEAPON]*9)+12-18*
1606 (cw == TRIPBOMB_WEAPON) );
1607 }
1608 else
1609 {
1610 weaponnum(TRIPBOMB_WEAPON,x+70,y+6,
1611 p->ammo_amount[TRIPBOMB_WEAPON],max_ammo_amount[TRIPBOMB_WEAPON],
1612 (!p->gotweapon[TRIPBOMB_WEAPON]*9)+12-18*
1613 (cw == TRIPBOMB_WEAPON) );
1614 }
1615 }
1616
1617 if (u&65536L)
1618 {
1619 if (u != 0xffffffff) patchstatusbar(166,190,166+8,190+6);
1620 if(VOLUMEONE)
1621 {
1622 orderweaponnum(-1,x+70,y+12,
1623 p->ammo_amount[FREEZE_WEAPON],max_ammo_amount[FREEZE_WEAPON],
1624 (!p->gotweapon[FREEZE_WEAPON]*9)+12-18*
1625 (cw == FREEZE_WEAPON) );
1626 }
1627 else
1628 {
1629 weaponnum(-1,x+70,y+12,
1630 p->ammo_amount[FREEZE_WEAPON],max_ammo_amount[FREEZE_WEAPON],
1631 (!p->gotweapon[FREEZE_WEAPON]*9)+12-18*
1632 (cw == FREEZE_WEAPON) );
1633 }
1634 }
1635}
1636
1637void digitalnumber(int32_t x,int32_t y,int32_t n,uint8_t s,uint8_t cs)
1638{
1639 short i, j, k, p, c;
1640 char b[10];
1641
1642 //
1643 // uint8_t * ltoa(int32_t l, uint8_t * buffer, int radix);
1644 // is NON-STANDARD and equivalent to STANDARD
1645 // (void) sprintf(buffer, "%ld", l);
1646 //ltoa(n,b,10);
1647 sprintf(b,"%d",n);
1648
1649 i = strlen(b);
1650 j = 0;
1651
1652 for(k=0;k<i;k++)
1653 {
1654 p = DIGITALNUM+*(b+k)-'0';
1655 j += tiles[p].dim.width+1;
1656 }
1657 c = x-(j>>1);
1658
1659 j = 0;
1660 for(k=0;k<i;k++)
1661 {
1662 p = DIGITALNUM+*(b+k)-'0';
1663 rotatesprite((c+j)<<16,y<<16,65536L,0,p,s,0,cs,0,0,xdim-1,ydim-1);
1664 j += tiles[p].dim.width+1;
1665 }
1666}
1667
1668/*
1669
1670 void scratchmarks(int32_t x,int32_t y,int32_t n,uint8_t s,uint8_t p)
1671 {
1672 int32_t i, ni;
1673
1674 ni = n/5;
1675 for(i=ni;i >= 0;i--)
1676 {
1677 overwritesprite(x-2,y,SCRATCH+4,s,0,0);
1678 x += tilesizx[SCRATCH+4]-1;
1679 }
1680
1681 ni = n%5;
1682 if(ni) overwritesprite(x,y,SCRATCH+ni-1,s,p,0);
1683 }
1684*/
1685void displayinventory(struct player_struct *p)
1686{
1687 short n, j, xoff, y;
1688
1689 j = xoff = 0;
1690
1691 n = (p->jetpack_amount > 0)<<3; if(n&8) j++;
1692 n |= ( p->scuba_amount > 0 )<<5; if(n&32) j++;
1693 n |= (p->steroids_amount > 0)<<1; if(n&2) j++;
1694 n |= ( p->holoduke_amount > 0)<<2; if(n&4) j++;
1695 n |= (p->firstaid_amount > 0); if(n&1) j++;
1696 n |= (p->heat_amount > 0)<<4; if(n&16) j++;
1697 n |= (p->boot_amount > 0)<<6; if(n&64) j++;
1698
1699 xoff = 160-(j*11);
1700
1701 j = 0;
1702
1703 if(ud.screen_size > 4)
1704 y = 154;
1705 else y = 172;
1706
1707 if(ud.screen_size == 4)
1708 {
1709 if(ud.multimode > 1)
1710 xoff += 56;
1711 else xoff += 65;
1712 }
1713
1714 while( j <= 9 )
1715 {
1716 if( n&(1<<j) )
1717 {
1718 switch( n&(1<<j) )
1719 {
1720 case 1:
1721 rotatesprite(xoff<<16,y<<16,65536L,0,FIRSTAID_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1722 case 2:
1723 rotatesprite((xoff+1)<<16,y<<16,65536L,0,STEROIDS_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1724 case 4:
1725 rotatesprite((xoff+2)<<16,y<<16,65536L,0,HOLODUKE_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1726 case 8:
1727 rotatesprite(xoff<<16,y<<16,65536L,0,JETPACK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1728 case 16:
1729 rotatesprite(xoff<<16,y<<16,65536L,0,HEAT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1730 case 32:
1731 rotatesprite(xoff<<16,y<<16,65536L,0,AIRTANK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1732 case 64:
1733 rotatesprite(xoff<<16,(y-1)<<16,65536L,0,BOOT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1734 }
1735
1736 xoff += 22;
1737
1738 if(p->inven_icon == j+1)
1739 rotatesprite((xoff-2)<<16,(y+19)<<16,65536L,1024,ARROW,-32,0,2+16,windowx1,windowy1,windowx2,windowy2);
1740 }
1741
1742 j++;
1743 }
1744}
1745
1746
1747
1748void displayfragbar(void)
1749{
1750 short i, j;
1751 char text[512];
1752
1753 j = 0;
1754
1755 for(i=connecthead;i>=0;i=connectpoint2[i])
1756 if(i > j) j = i;
1757
1758 rotatesprite(0,0,65600L,0,FRAGBAR,0,0,2+8+16+64+128,0,0,xdim-1,ydim-1);
1759 if(j >= 4) rotatesprite(319,(8)<<16,65600L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
1760 if(j >= 8) rotatesprite(319,(16)<<16,65600L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
1761 if(j >= 12) rotatesprite(319,(24)<<16,65600L,0,FRAGBAR,0,0,10+16+64+128,0,0,xdim-1,ydim-1);
1762
1763 for(i=connecthead;i>=0;i=connectpoint2[i])
1764 {
1765 minitext(21+(73*(i&3)),2+((i&28)<<1),&ud.user_name[i][0],sprite[ps[i].i].pal,2+8+16+128);
1766 sprintf(text,"%d",ps[i].frag-ps[i].fraggedself);
1767 minitext(17+50+(73*(i&3)),2+((i&28)<<1),text,sprite[ps[i].i].pal,2+8+16+128);
1768 }
1769}
1770
1771void display_boardfilename_FPS_weapon(short *offx, short *offy, short *stepx, short *stepy)
1772{
1773
1774 short i;
1775
1776 // FIX_00025: Can toggle FPS and map name during a game (use dnrate OR toggle
1777 // from menu when in deathmatch).
1778
1779 // Display boardfilename and FPS
1780 if(ud.tickrate&1)
1781 {
1782 duke_tics(*offx, *offy, COLOR_ON);
1783 *offy += *stepy;
1784 }
1785 if(ud.tickrate&2)
1786 dispVersion();
1787
1788 // We display the weapons here instead of changing the function
1789 // displayweapon() because the display will be much faster
1790 for(i=connecthead;i>=0;i=connectpoint2[i])
1791 {
1792 if (ud.hideweapon && i==screenpeek)
1793 drawsmallweapon(ps[i].curr_weapon, 1, 130, (ud.screen_size<=4)?170:140);
1794 }
1795}
1796
1797
1798// FIX_00026: Weapon can now be hidden (on your screen only).
1799void drawsmallweapon(short weapon, float scale, short x, short y)
1800{
1801 float t = 60000;
1802 int s;
1803 float offsetx, offsety;
1804
1805
1806 switch(weapon)
1807 {
1808 case KNEE_WEAPON : s=0; break;
1809 case PISTOL_WEAPON : s=FIRSTGUNSPRITE;
1810 offsetx = 8;
1811 offsety = 7;
1812 break;
1813 case SHOTGUN_WEAPON : s=SHOTGUNSPRITE;
1814 t = 45000;
1815 offsetx = -1;
1816 offsety = 9;
1817 break;
1818 case CHAINGUN_WEAPON : s=CHAINGUNSPRITE;
1819 t = 45000;
1820 offsetx = -1;
1821 offsety = 9;
1822 break;
1823 case RPG_WEAPON : s=RPGSPRITE;
1824 t = 45000;
1825 offsetx = 4;
1826 offsety = 9;
1827 break;
1828 case HANDBOMB_WEAPON : s=HEAVYHBOMB;
1829 t=20000;
1830 offsetx = 16;
1831 offsety = 13;
1832 break;
1833 case SHRINKER_WEAPON : s=SHRINKERSPRITE;
1834 t = 30000;
1835 offsetx = 6;
1836 offsety = 14;
1837 break;
1838 case DEVISTATOR_WEAPON : s=DEVISTATORSPRITE;
1839 t = 45000;
1840 offsetx = 3;
1841 offsety = 9;
1842 break;
1843 case TRIPBOMB_WEAPON : s=TRIPBOMBSPRITE;
1844 t = 75000;
1845 offsetx = 10;
1846 offsety = 12;
1847 break;
1848 case FREEZE_WEAPON : s=FREEZESPRITE;
1849 t = 45000;
1850 offsetx = 1;
1851 offsety = 6;
1852 break;
1853 case HANDREMOTE_WEAPON : s=0;
1854 break;
1855 case GROW_WEAPON : s=GROWSPRITEICON;
1856 t = 30000;
1857 offsetx = 6;
1858 offsety = 4;
1859 break;
1860 default : s=0;
1861 }
1862
1863 if(s)
1864 rotatesprite((x+(short)(offsetx*scale))<<16,(y+(short)(offsety*scale))<<16,(int)(t*scale),0,s,0,0,2+8+16,0,0,xdim-1,ydim-1);
1865
1866 return;
1867}
1868
1869void coolgaugetext(short snum)
1870{
1871 struct player_struct *p;
1872 int32_t i, j, o, ss, u;
1873 uint8_t permbit;
1874 short offx = 3, offy = 3, stepx=60, stepy=6;
1875 char text[512];
1876
1877 p = &ps[snum];
1878
1879 if (p->invdisptime > 0)
1880 {
1881 displayinventory(p);
1882 }
1883
1884
1885 if(ps[snum].gm&MODE_MENU)
1886 if( (current_menu >= 400 && current_menu <= 405) )
1887 return;
1888
1889 offy += countfragbars(); //add fragbars
1890 display_boardfilename_FPS_weapon(&offx, &offy, &stepx, &stepy);
1891
1892
1893 ss = ud.screen_size; if (ss < 4) return;
1894
1895 // Draw the multi player frag status bar
1896 if ( ud.multimode > 1 && ud.coop != 1 )
1897 {
1898 if (pus)
1899 {
1900 displayfragbar();
1901 }
1902 else
1903 {
1904 for(i=connecthead;i>=0;i=connectpoint2[i])
1905 {
1906 if (ps[i].frag != sbar.frag[i])
1907 {
1908 displayfragbar();
1909 break;
1910 }
1911 }
1912 }
1913 for(i=connecthead;i>=0;i=connectpoint2[i])
1914 if (i != myconnectindex)
1915 sbar.frag[i] = ps[i].frag;
1916 }
1917
1918 if (ss == 4) //DRAW MINI STATUS BAR:
1919 {
1920 // FIX_00027: Added an extra small statusbar (HUD)
1921 if(ud.extended_screen_size>0)
1922 {
1923 offx = 5; offy = 160;
1924
1925 sprintf(text,"%d", ps[screenpeek].ammo_amount[ps[screenpeek].curr_weapon]);
1926 minitext(offx+26,offy+21,text,COLOR_ON,2+8+16); //minitext: 2 red light, 23 yellow
1927 sprintf(text,"%d", ps[screenpeek].last_extra);
1928 gametext(offx,offy+20,text,ps[screenpeek].last_extra<=50?15:0,2+8+16); //minitext: 2 red light, 23 yellow
1929 rotatesprite((offx+0*10)<<16,(offy+28)<<16,20000,0,SHIELD,ps[screenpeek].shield_amount?25:100,0,2+8+16,0,0,xdim-1,ydim-1);
1930 rotatesprite((offx+0*10)<<16,(offy+28)<<16,ksqrt(ps[screenpeek].shield_amount)*20000/10,0,SHIELD,0,0,2+8+16,0,0,xdim-1,ydim-1);
1931 rotatesprite((offx+1*10)<<16,(offy+28)<<16,35000,0,JETPACK_ICON,ps[screenpeek].jetpack_amount?25:100,0,2+8+16,0,0,xdim-1,ydim-1);
1932 rotatesprite((offx+1*10)<<16,(offy+28)<<16,ksqrt(ps[screenpeek].jetpack_amount)*35000/40,0,JETPACK_ICON,0,0,2+8+16,0,0,xdim-1,ydim-1);
1933 rotatesprite((offx+2*10-1)<<16,(offy+28)<<16,35000,0,STEROIDS_ICON,ps[screenpeek].steroids_amount?25:100,0,2+8+16,0,0,xdim-1,ydim-1);
1934 rotatesprite((offx+2*10-1)<<16,(offy+28)<<16,ksqrt(ps[screenpeek].steroids_amount)*35000/20,0,STEROIDS_ICON,5,0,2+8+16,0,0,xdim-1,ydim-1);
1935 rotatesprite((offx+3*10-3)<<16,(offy+28)<<16,40000,0,FIRSTAID_ICON,ps[screenpeek].firstaid_amount?25:100,0,2+8+16,0,0,xdim-1,ydim-1);
1936 rotatesprite((offx+3*10-3)<<16,(offy+28)<<16,ksqrt(ps[screenpeek].firstaid_amount)*40000/10,0,FIRSTAID_ICON,0,0,2+8+16,0,0,xdim-1,ydim-1);
1937 }
1938 else
1939 {
1940 if (p->inven_icon)
1941 rotatesprite(69<<16,(200-30)<<16,65536L,0,INVENTORYBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1942 rotatesprite(5<<16,(200-28)<<16,65536L,0,HEALTHBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1943
1944 if(sprite[p->i].pal == 1 && p->last_extra < 2)
1945 digitalnumber(20,200-17,1,-16,10+16);
1946 else digitalnumber(20,200-17,p->last_extra,-16,10+16);
1947
1948 rotatesprite(37<<16,(200-28)<<16,65536L,0,AMMOBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1949
1950 if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
1951 digitalnumber(53,200-17,p->ammo_amount[i],-16,10+16);
1952
1953 o = 158; permbit = 0;
1954 if (p->inven_icon)
1955 {
1956 switch(p->inven_icon)
1957 {
1958 case 1: i = FIRSTAID_ICON; break;
1959 case 2: i = STEROIDS_ICON; break;
1960 case 3: i = HOLODUKE_ICON; break;
1961 case 4: i = JETPACK_ICON; break;
1962 case 5: i = HEAT_ICON; break;
1963 case 6: i = AIRTANK_ICON; break;
1964 case 7: i = BOOT_ICON; break;
1965 default: i = -1;
1966 }
1967 if (i >= 0) rotatesprite((231-o)<<16,(200-21)<<16,65536L,0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1968
1969 minitext(292-30-o,190,"%",6,10+16+permbit);
1970
1971 j = 0x80000000;
1972 switch(p->inven_icon)
1973 {
1974 case 1: i = p->firstaid_amount; break;
1975 case 2: i = ((p->steroids_amount+3)>>2); break;
1976 case 3: i = ((p->holoduke_amount+15)/24); j = p->holoduke_on; break;
1977 case 4: i = ((p->jetpack_amount+15)>>4); j = p->jetpack_on; break;
1978 case 5: i = p->heat_amount/12; j = p->heat_on; break;
1979 case 6: i = ((p->scuba_amount+63)>>6); break;
1980 case 7: i = (p->boot_amount>>1); break;
1981 }
1982 invennum(284-30-o,200-6,(uint8_t )i,0,10+permbit);
1983 if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit);
1984 else if (j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit);
1985 if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit);
1986 }
1987 }
1988 return;
1989 }
1990
1991 //DRAW/UPDATE FULL STATUS BAR:
1992
1993 if (pus) { pus = 0; u = 0xffffffff; } else u = 0;
1994
1995 if (sbar.frag[myconnectindex] != p->frag) { sbar.frag[myconnectindex] = p->frag; u |= 32768; }
1996 if (sbar.got_access != p->got_access) { sbar.got_access = p->got_access; u |= 16384; }
1997 if (sbar.last_extra != p->last_extra) { sbar.last_extra = p->last_extra; u |= 1; }
1998 if (sbar.shield_amount != p->shield_amount) { sbar.shield_amount = p->shield_amount; u |= 2; }
1999 if (sbar.curr_weapon != p->curr_weapon) { sbar.curr_weapon = p->curr_weapon; u |= (4+8+16+32+64+128+256+512+1024+65536L); }
2000 for(i=1;i < 10;i++)
2001 {
2002 if (sbar.ammo_amount[i] != p->ammo_amount[i]) {
2003 sbar.ammo_amount[i] = p->ammo_amount[i]; if(i < 9) u |= ((2<<i)+1024); else u |= 65536L+1024; }
2004 if (sbar.gotweapon[i] != p->gotweapon[i]) { sbar.gotweapon[i] =
2005 p->gotweapon[i]; if(i < 9 ) u |= ((2<<i)+1024); else u |= 65536L+1024; }
2006 }
2007 if (sbar.inven_icon != p->inven_icon) { sbar.inven_icon = p->inven_icon; u |= (2048+4096+8192); }
2008 if (sbar.holoduke_on != p->holoduke_on) { sbar.holoduke_on = p->holoduke_on; u |= (4096+8192); }
2009 if (sbar.jetpack_on != p->jetpack_on) { sbar.jetpack_on = p->jetpack_on; u |= (4096+8192); }
2010 if (sbar.heat_on != p->heat_on) { sbar.heat_on = p->heat_on; u |= (4096+8192); }
2011 if (sbar.firstaid_amount != p->firstaid_amount) { sbar.firstaid_amount = p->firstaid_amount; u |= 8192; }
2012 if (sbar.steroids_amount != p->steroids_amount) { sbar.steroids_amount = p->steroids_amount; u |= 8192; }
2013 if (sbar.holoduke_amount != p->holoduke_amount) { sbar.holoduke_amount = p->holoduke_amount; u |= 8192; }
2014 if (sbar.jetpack_amount != p->jetpack_amount) { sbar.jetpack_amount = p->jetpack_amount; u |= 8192; }
2015 if (sbar.heat_amount != p->heat_amount) { sbar.heat_amount = p->heat_amount; u |= 8192; }
2016 if (sbar.scuba_amount != p->scuba_amount) { sbar.scuba_amount = p->scuba_amount; u |= 8192; }
2017 if (sbar.boot_amount != p->boot_amount) { sbar.boot_amount = p->boot_amount; u |= 8192; }
2018 if (u == 0) return;
2019
2020 //0 - update health
2021 //1 - update armor
2022 //2 - update PISTOL_WEAPON ammo
2023 //3 - update SHOTGUN_WEAPON ammo
2024 //4 - update CHAINGUN_WEAPON ammo
2025 //5 - update RPG_WEAPON ammo
2026 //6 - update HANDBOMB_WEAPON ammo
2027 //7 - update SHRINKER_WEAPON ammo
2028 //8 - update DEVISTATOR_WEAPON ammo
2029 //9 - update TRIPBOMB_WEAPON ammo
2030 //10 - update ammo display
2031 //11 - update inventory icon
2032 //12 - update inventory on/off
2033 //13 - update inventory %
2034 //14 - update keys
2035 //15 - update kills
2036 //16 - update FREEZE_WEAPON ammo
2037
2038 if (u == 0xffffffff)
2039 {
2040 patchstatusbar(0,0,320,200);
2041 if (ud.multimode > 1 && ud.coop != 1)
2042 rotatesprite(277<<16,(200-27)<<16,65536L,0,KILLSICON,0,0,10+16+128,0,0,xdim-1,ydim-1);
2043 }
2044 if (ud.multimode > 1 && ud.coop != 1)
2045 {
2046 if (u&32768)
2047 {
2048 if (u != 0xffffffff) patchstatusbar(276,183,299,193);
2049 digitalnumber(287,200-17,max(p->frag-p->fraggedself,0),-16,10+16+128);
2050 }
2051 }
2052 else
2053 {
2054 if (u&16384)
2055 {
2056 if (u != 0xffffffff) patchstatusbar(275,182,299,194);
2057 if (p->got_access&4) rotatesprite(275<<16,182<<16,65536L,0,ACCESS_ICON,0,23,10+16+128,0,0,xdim-1,ydim-1);
2058 if (p->got_access&2) rotatesprite(288<<16,182<<16,65536L,0,ACCESS_ICON,0,21,10+16+128,0,0,xdim-1,ydim-1);
2059 if (p->got_access&1) rotatesprite(281<<16,189<<16,65536L,0,ACCESS_ICON,0,0,10+16+128,0,0,xdim-1,ydim-1);
2060 }
2061 }
2062 if (u&(4+8+16+32+64+128+256+512+65536L)) weapon_amounts(p,96,182,u);
2063
2064 if (u&1)
2065 {
2066 if (u != 0xffffffff) patchstatusbar(20,183,43,193);
2067 if(sprite[p->i].pal == 1 && p->last_extra < 2)
2068 digitalnumber(32,200-17,1,-16,10+16+128);
2069 else digitalnumber(32,200-17,p->last_extra,-16,10+16+128);
2070 }
2071 if (u&2)
2072 {
2073 if (u != 0xffffffff) patchstatusbar(52,183,75,193);
2074 digitalnumber(64,200-17,p->shield_amount,-16,10+16+128);
2075 }
2076
2077 if (u&1024)
2078 {
2079 if (u != 0xffffffff) patchstatusbar(196,183,219,193);
2080 if (p->curr_weapon != KNEE_WEAPON)
2081 {
2082 if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
2083 digitalnumber(230-22,200-17,p->ammo_amount[i],-16,10+16+128);
2084 }
2085 }
2086
2087 if (u&(2048+4096+8192))
2088 {
2089 if (u != 0xffffffff)
2090 {
2091 if (u&(2048+4096)) { patchstatusbar(231,179,265,197); }
2092 else { patchstatusbar(250,190,261,195); }
2093 }
2094 if (p->inven_icon)
2095 {
2096 o = 0; permbit = 128;
2097
2098 if (u&(2048+4096))
2099 {
2100 switch(p->inven_icon)
2101 {
2102 case 1: i = FIRSTAID_ICON; break;
2103 case 2: i = STEROIDS_ICON; break;
2104 case 3: i = HOLODUKE_ICON; break;
2105 case 4: i = JETPACK_ICON; break;
2106 case 5: i = HEAT_ICON; break;
2107 case 6: i = AIRTANK_ICON; break;
2108 case 7: i = BOOT_ICON; break;
2109 }
2110 rotatesprite((231-o)<<16,(200-21)<<16,65536L,0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
2111 minitext(292-30-o,190,"%",6,10+16+permbit);
2112 if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit);
2113 }
2114 if (u&(2048+4096))
2115 {
2116 switch(p->inven_icon)
2117 {
2118 case 3: j = p->holoduke_on; break;
2119 case 4: j = p->jetpack_on; break;
2120 case 5: j = p->heat_on; break;
2121 default: j = 0x80000000;
2122 }
2123 if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit);
2124 else if (j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit);
2125 }
2126 if (u&8192)
2127 {
2128 switch(p->inven_icon)
2129 {
2130 case 1: i = p->firstaid_amount; break;
2131 case 2: i = ((p->steroids_amount+3)>>2); break;
2132 case 3: i = ((p->holoduke_amount+15)/24); break;
2133 case 4: i = ((p->jetpack_amount+15)>>4); break;
2134 case 5: i = p->heat_amount/12; break;
2135 case 6: i = ((p->scuba_amount+63)>>6); break;
2136 case 7: i = (p->boot_amount>>1); break;
2137 }
2138 invennum(284-30-o,200-6,(uint8_t )i,0,10+permbit);
2139 }
2140 }
2141 }
2142}
2143
2144
2145#define AVERAGEFRAMES 16
2146static int32_t frameval[AVERAGEFRAMES], framecnt = 0;
2147
2148void duke_tics(short offx, short offy, short color)
2149{
2150 int32_t i;
2151 char fps[512], mapname[512];
2152 int32_t currentFps;
2153 static int32_t fpsAvg = 0, savedFps = 0;
2154 static boolean toggle = true;
2155 char text[512];
2156
2157 strcpy(mapname,boardfilename);
2158 for(i=0;i<512;i++)
2159 if(mapname[i]=='.')
2160 mapname[i]=0;
2161
2162 if( mapname[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0 )
2163 sprintf(text, "%s", mapname);
2164 else
2165 //sprintf(tempbuf, "%s", level_names[ud.volume_number*11 + ud.level_number]);
2166 sprintf(text, "e%dl%d", ud.volume_number+1, ud.level_number+1);
2167
2168
2169 i = totalclock;
2170
2171 if (i != frameval[framecnt])
2172 {
2173 currentFps = (TICRATE*AVERAGEFRAMES)/(i-frameval[framecnt]);
2174 fpsAvg = ((fpsAvg<<3)+(fpsAvg<<2) + (currentFps<<2))>>4;
2175
2176 frameval[framecnt] = i;
2177 }
2178
2179 framecnt = ((framecnt+1)&(AVERAGEFRAMES-1));
2180
2181 // refresh screen and update visible FPS. This is to allow a refresh
2182 // of the screen when the screensize > 4 w/o compromising the FPS.
2183 if(ud.screen_size>8)
2184 if ((totalclock%64) < 32)
2185 {
2186 if(toggle)
2187 {
2188 vscrn();
2189 savedFps = fpsAvg;
2190 }
2191 toggle = false;
2192 }
2193 else
2194 {
2195 toggle = true;
2196 }
2197 else
2198 savedFps = fpsAvg;
2199
Franklin Wei9f6ce042017-12-25 14:53:11 -05002200 extern int rbaud_underruns, fp_calls[4];
2201 sprintf(fps," %d %d %d %d %d %d", savedFps, rbaud_underruns, fp_calls[0],
2202 fp_calls[1], fp_calls[2], fp_calls[3]);
Franklin Weia855d622017-01-21 15:18:31 -05002203 strcat(text, fps);
2204
2205 minitext(offx,offy,text,color,2+8+16+128);
2206}
2207
2208void coords(short snum)
2209{
2210 short x = 200, y = 0;
2211 char text[512];
2212 // x = 250 is too much on the right and
2213 // will make the text going out of the screen
2214 // if screen <= (320x200)
2215 // This will also *write beyond the video
2216 // buffer limit* and will crash the game.
2217
2218 if(ud.coop != 1)
2219 {
2220 if(ud.multimode > 1 && ud.multimode < 5)
2221 y = 8;
2222 else if(ud.multimode > 4)
2223 y = 16;
2224 }
2225
2226 sprintf(text,"X= %d",ps[snum].posx);
2227 printext256(x,y,31,-1,text,1);
2228 sprintf(text,"Y= %d",ps[snum].posy);
2229 printext256(x,y+7L,31,-1,text,1);
2230 sprintf(text,"Z= %d",ps[snum].posz);
2231 printext256(x,y+14L,31,-1,text,1);
2232 sprintf(text,"A= %d",ps[snum].ang);
2233 printext256(x,y+21L,31,-1,text,1);
2234 sprintf(text,"ZV= %d",ps[snum].poszv);
2235 printext256(x,y+28L,31,-1,text,1);
2236 sprintf(text,"OG= %d",ps[snum].on_ground);
2237 printext256(x,y+35L,31,-1,text,1);
2238 sprintf(text,"AM= %d",ps[snum].ammo_amount[GROW_WEAPON]);
2239 printext256(x,y+43L,31,-1,text,1);
2240 sprintf(text,"LFW= %d",ps[snum].last_full_weapon);
2241 printext256(x,y+50L,31,-1,text,1);
2242 sprintf(text,"SECTL= %d",sector[ps[snum].cursectnum].lotag);
2243 printext256(x,y+57L,31,-1,text,1);
2244 sprintf(text,"SEED= %d",randomseed);
2245 printext256(x,y+64L,31,-1,text,1);
2246 sprintf(text,"THOLD= %d",ps[snum].transporter_hold);
2247 printext256(x,y+64L+7,31,-1,text,1);
2248}
2249
2250void operatefta(void)
2251{
2252 int32_t i, j, k;
2253
2254 if(ud.screen_size > 0) j = 200-45; else j = 200-8;
2255 quotebot = min(quotebot,j);
2256 quotebotgoal = min(quotebotgoal,j);
2257 if(ps[myconnectindex].gm&MODE_TYPE) j -= 8;
2258 quotebotgoal = j; j = quotebot;
2259 for(i=0;i<MAXUSERQUOTES;i++)
2260 {
2261 k = user_quote_time[i]; if (k <= 0) break;
2262
2263 if (k > 4)
2264 gametext(320>>1,j,user_quote[i],0,2+8+16);
2265 else if (k > 2) gametext(320>>1,j,user_quote[i],0,2+8+16+1);
2266 else gametext(320>>1,j,user_quote[i],0,2+8+16+1+32);
2267 j -= 8;
2268 }
2269
2270 if (ps[screenpeek].fta <= 1) return;
2271
2272 if (ud.coop != 1 && ud.screen_size > 0 && ud.multimode > 1)
2273 {
2274 j = 0; k = 8;
2275 for(i=connecthead;i>=0;i=connectpoint2[i])
2276 if (i > j) j = i;
2277
2278 if (j >= 4 && j <= 8) k += 8;
2279 else if (j > 8 && j <= 12) k += 16;
2280 else if (j > 12) k += 24;
2281 }
2282 else k = 0;
2283
2284 if (ps[screenpeek].ftq == 115 || ps[screenpeek].ftq == 116)
2285 {
2286 k = quotebot;
2287 for(i=0;i<MAXUSERQUOTES;i++)
2288 {
2289 if (user_quote_time[i] <= 0) break;
2290 k -= 8;
2291 }
2292 k -= 4;
2293 }
2294
2295 j = ps[screenpeek].fta;
2296 if (j