Subversion Repositories eduke32

Rev

Rev 879 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 879 Rev 881
1
//-------------------------------------------------------------------------
1
//-------------------------------------------------------------------------
2
/*
2
/*
3
Copyright (C) 1996, 2003 - 3D Realms Entertainment
3
Copyright (C) 1996, 2003 - 3D Realms Entertainment
4
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
4
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
5
Copyright (C) 2004, 2007 - EDuke32 developers
5
Copyright (C) 2004, 2007 - EDuke32 developers
6

6

7
This file is part of EDuke32
7
This file is part of EDuke32
8

8

9
EDuke32 is free software; you can redistribute it and/or
9
EDuke32 is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License version 2
10
modify it under the terms of the GNU General Public License version 2
11
as published by the Free Software Foundation.
11
as published by the Free Software Foundation.
12

12

13
This program is distributed in the hope that it will be useful,
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16

16

17
See the GNU General Public License for more details.
17
See the GNU General Public License for more details.
18

18

19
You should have received a copy of the GNU General Public License
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
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.
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
*/
22
*/
23
//-------------------------------------------------------------------------
23
//-------------------------------------------------------------------------
24
24
25
#include "duke3d.h"
25
#include "duke3d.h"
26
#include "types.h"
26
#include "types.h"
27
#include "develop.h"
27
#include "develop.h"
28
#include "scriplib.h"
28
#include "scriplib.h"
29
#include "file_lib.h"
29
#include "file_lib.h"
30
#include "mathutil.h"
30
#include "mathutil.h"
31
#include "gamedefs.h"
31
#include "gamedefs.h"
32
#include "keyboard.h"
32
#include "keyboard.h"
33
#include "mouse.h"  // JBF 20030809
33
#include "mouse.h"  // JBF 20030809
34
#include "function.h"
34
#include "function.h"
35
#include "control.h"
35
#include "control.h"
36
#include "fx_man.h"
36
#include "fx_man.h"
37
#include "sounds.h"
37
#include "sounds.h"
38
#include "config.h"
38
#include "config.h"
39
39
40
#include "osd.h"
40
#include "osd.h"
41
#include "osdfuncs.h"
41
#include "osdfuncs.h"
42
#include "osdcmds.h"
42
#include "osdcmds.h"
43
#include "scriptfile.h"
43
#include "scriptfile.h"
44
#include "grpscan.h"
44
#include "grpscan.h"
45
#include "gamedef.h"
45
#include "gamedef.h"
46
#include "kplib.h"
46
#include "kplib.h"
47
47
48
//#include "crc32.h"
48
//#include "crc32.h"
49
49
50
#include "util_lib.h"
50
#include "util_lib.h"
51
51
52
#ifdef _WIN32
52
#ifdef _WIN32
53
#define WIN32_LEAN_AND_MEAN
53
#define WIN32_LEAN_AND_MEAN
54
#include <windows.h>
54
#include <windows.h>
55
#include <shellapi.h>
55
#include <shellapi.h>
56
extern int getversionfromwebsite(char *buffer);
56
extern int getversionfromwebsite(char *buffer);
57
#define BUILDDATE 20080720 // this is checked against http://eduke32.com/VERSION
57
#define BUILDDATE 20080720 // this is checked against http://eduke32.com/VERSION
58
#define UPDATEINTERVAL 604800 // 1w
58
#define UPDATEINTERVAL 604800 // 1w
59
#endif
59
#endif
60
60
61
#define IDFSIZE 479985668
61
#define IDFSIZE 479985668
62
#define IDFILENAME "DUKE3D.IDF"
62
#define IDFILENAME "DUKE3D.IDF"
63
63
64
#define TIMERUPDATESIZ 32
64
#define TIMERUPDATESIZ 32
65
65
66
int cameradist = 0, cameraclock = 0;
66
int cameradist = 0, cameraclock = 0;
67
static int playerswhenstarted;
67
static int playerswhenstarted;
68
static int qe,cp;
68
static int qe,cp;
69
#if !defined(_WIN32)
69
#if !defined(_WIN32)
70
static int usecwd = 0;
70
static int usecwd = 0;
71
#endif
71
#endif
72
static int g_CommandSetup = 0;
72
static int g_CommandSetup = 0;
73
static int g_NoSetup = 0;
73
static int g_NoSetup = 0;
74
static int g_NoAutoLoad = 0;
74
static int g_NoAutoLoad = 0;
75
static int g_NoSound = 0;
75
static int g_NoSound = 0;
76
static int g_NoMusic = 0;
76
static int g_NoMusic = 0;
77
static char *CommandMap = NULL;
77
static char *CommandMap = NULL;
78
static char *CommandName = NULL;
78
static char *CommandName = NULL;
79
static char *CommandNet = NULL;
79
static char *CommandNet = NULL;
80
static int g_KeepAddr = 0;
80
static int g_KeepAddr = 0;
81
int CommandWeaponChoice = 0;
81
int CommandWeaponChoice = 0;
82
static struct strllist
82
static struct strllist
83
{
83
{
84
    struct strllist *next;
84
    struct strllist *next;
85
    char *str;
85
    char *str;
86
}
86
}
87
*CommandPaths = NULL, *CommandGrps = NULL;
87
*CommandPaths = NULL, *CommandGrps = NULL;
88
88
89
char boardfilename[BMAX_PATH] = {0};
89
char boardfilename[BMAX_PATH] = {0};
90
char waterpal[768], slimepal[768], titlepal[768], drealms[768], endingpal[768], animpal[768];
90
char waterpal[768], slimepal[768], titlepal[768], drealms[768], endingpal[768], animpal[768];
91
static char firstdemofile[80] = { '\0' };
91
static char firstdemofile[80] = { '\0' };
92
int display_bonus_screen = 1;
92
int display_bonus_screen = 1;
93
static int userconfiles = 0;
93
static int userconfiles = 0;
94
94
95
static int netparamcount = 0;
95
static int netparamcount = 0;
96
static char **netparam = NULL;
96
static char **netparam = NULL;
97
97
98
int voting = -1;
98
int voting = -1;
99
int vote_map = -1, vote_episode = -1;
99
int vote_map = -1, vote_episode = -1;
100
100
101
int recfilep,totalreccnt;
101
int recfilep,totalreccnt;
102
int debug_on = 0,actor_tog = 0;
102
int debug_on = 0,actor_tog = 0;
103
static char *rtsptr;
103
static char *rtsptr;
104
104
105
extern char syncstate;
105
extern char syncstate;
106
extern int numlumps;
106
extern int numlumps;
107
107
108
static FILE *frecfilep = (FILE *)NULL;
108
static FILE *frecfilep = (FILE *)NULL;
109
109
110
int restorepalette,screencapt;
110
int restorepalette,screencapt;
111
static int g_NoLogoAnim = 0;
111
static int g_NoLogoAnim = 0;
112
static int g_NoLogo = 0;
112
static int g_NoLogo = 0;
113
static int sendmessagecommand = -1;
113
static int sendmessagecommand = -1;
114
114
115
char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp";
115
char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp";
116
char *duke3dgrp = defaultduke3dgrp;
116
char *duke3dgrp = defaultduke3dgrp;
117
static char defaultconfilename[BMAX_PATH] = {"EDUKE.CON"};
117
static char defaultconfilename[BMAX_PATH] = {"EDUKE.CON"};
118
static char *confilename = defaultconfilename;
118
static char *confilename = defaultconfilename;
119
static char *duke3ddef = "duke3d.def";
119
static char *duke3ddef = "duke3d.def";
120
120
121
extern int lastvisinc;
121
extern int lastvisinc;
122
122
123
int g_Shareware = 0;
123
int g_Shareware = 0;
124
int g_GameType = 0;
124
int g_GameType = 0;
125
125
126
#define MAXUSERQUOTES 4
126
#define MAXUSERQUOTES 4
127
static int quotebot, quotebotgoal;
127
static int quotebot, quotebotgoal;
128
static int user_quote_time[MAXUSERQUOTES];
128
static int user_quote_time[MAXUSERQUOTES];
129
static char user_quote[MAXUSERQUOTES][178];
129
static char user_quote[MAXUSERQUOTES][178];
130
// char typebuflen,typebuf[41];
130
// char typebuflen,typebuf[41];
131
131
132
#ifdef JFAUD
132
#ifdef JFAUD
133
static int MAXCACHE1DSIZE = (16*1048576);
133
static int MAXCACHE1DSIZE = (16*1048576);
134
#else
134
#else
135
static int MAXCACHE1DSIZE = (32*1048576);
135
static int MAXCACHE1DSIZE = (32*1048576);
136
#endif
136
#endif
137
137
138
int tempwallptr;
138
int tempwallptr;
139
139
140
static int nonsharedtimer;
140
static int nonsharedtimer;
141
141
142
static void cameratext(short i);
142
static void cameratext(short i);
143
static int moveloop(void);
143
static int moveloop(void);
144
static void doorders(void);
144
static void doorders(void);
145
static void fakedomovethings(void);
145
static void fakedomovethings(void);
146
static void fakedomovethingscorrect(void);
146
static void fakedomovethingscorrect(void);
147
static int domovethings(void);
147
static int domovethings(void);
148
static int playback(void);
148
static int playback(void);
149
149
150
static char recbuf[180];
150
static char recbuf[180];
151
151
152
extern void computergetinput(int snum, input *syn);
152
extern void computergetinput(int snum, input *syn);
153
153
154
#define USERQUOTE_LEFTOFFSET 5
154
#define USERQUOTE_LEFTOFFSET 5
155
#define USERQUOTE_RIGHTOFFSET 14
155
#define USERQUOTE_RIGHTOFFSET 14
156
156
157
enum
157
enum
158
{
158
{
159
    T_EOF = -2,
159
    T_EOF = -2,
160
    T_ERROR = -1,
160
    T_ERROR = -1,
161
    T_INCLUDE = 0,
161
    T_INCLUDE = 0,
162
    T_INTERFACE = 0,
162
    T_INTERFACE = 0,
163
    T_LOADGRP = 1,
163
    T_LOADGRP = 1,
164
    T_MODE = 1,
164
    T_MODE = 1,
165
    T_CACHESIZE = 2,
165
    T_CACHESIZE = 2,
166
    T_ALLOW = 2,
166
    T_ALLOW = 2,
167
    T_NOAUTOLOAD,
167
    T_NOAUTOLOAD,
168
    T_MUSIC,
168
    T_MUSIC,
169
    T_SOUND,
169
    T_SOUND,
170
    T_FILE,
170
    T_FILE,
171
    T_ID
171
    T_ID
172
};
172
};
173
173
174
typedef struct
174
typedef struct
175
{
175
{
176
    char *text;
176
    char *text;
177
    int tokenid;
177
    int tokenid;
178
}
178
}
179
tokenlist;
179
tokenlist;
180
180
181
static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens)
181
static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens)
182
{
182
{
183
    char *tok;
183
    char *tok;
184
    int i;
184
    int i;
185
185
186
    if (!sf) return T_ERROR;
186
    if (!sf) return T_ERROR;
187
    tok = scriptfile_gettoken(sf);
187
    tok = scriptfile_gettoken(sf);
188
    if (!tok) return T_EOF;
188
    if (!tok) return T_EOF;
189
189
190
    for (i=0;i<ntokens;i++)
190
    for (i=0;i<ntokens;i++)
191
    {
191
    {
192
        if (!Bstrcasecmp(tok, tl[i].text))
192
        if (!Bstrcasecmp(tok, tl[i].text))
193
            return tl[i].tokenid;
193
            return tl[i].tokenid;
194
    }
194
    }
195
    return T_ERROR;
195
    return T_ERROR;
196
}
196
}
197
197
198
inline void setstatusbarscale(int sc)
198
inline void setstatusbarscale(int sc)
199
{
199
{
200
    ud.statusbarscale = min(100,max(10,sc));
200
    ud.statusbarscale = min(100,max(10,sc));
201
    vscrn();
201
    vscrn();
202
}
202
}
203
203
204
static inline int sbarx(int x)
204
static inline int sbarx(int x)
205
{
205
{
206
    if (ud.screen_size == 4 /*|| ud.statusbarmode == 1*/) return scale(x<<16,ud.statusbarscale,100);
206
    if (ud.screen_size == 4 /*|| ud.statusbarmode == 1*/) return scale(x<<16,ud.statusbarscale,100);
207
    return (((320l<<16) - scale(320l<<16,ud.statusbarscale,100)) >> 1) + scale(x<<16,ud.statusbarscale,100);
207
    return (((320l<<16) - scale(320l<<16,ud.statusbarscale,100)) >> 1) + scale(x<<16,ud.statusbarscale,100);
208
}
208
}
209
209
210
static inline int sbary(int y)
210
static inline int sbary(int y)
211
{
211
{
212
    return ((200l<<16) - scale(200l<<16,ud.statusbarscale,100) + scale(y<<16,ud.statusbarscale,100));
212
    return ((200l<<16) - scale(200l<<16,ud.statusbarscale,100) + scale(y<<16,ud.statusbarscale,100));
213
}
213
}
214
214
215
static inline int sbarsc(int sc)
215
static inline int sbarsc(int sc)
216
{
216
{
217
    return scale(sc,ud.statusbarscale,100);
217
    return scale(sc,ud.statusbarscale,100);
218
}
218
}
219
219
220
static void patchstatusbar(int x1, int y1, int x2, int y2)
220
static void patchstatusbar(int x1, int y1, int x2, int y2)
221
{
221
{
222
    int scl, tx, ty;
222
    int scl, tx, ty;
223
    int clx1,cly1,clx2,cly2,clofx,clofy;
223
    int clx1,cly1,clx2,cly2,clofx,clofy;
224
224
225
    scl = sbarsc(65536);
225
    scl = sbarsc(65536);
226
    tx = sbarx(0);
226
    tx = sbarx(0);
227
    ty = sbary(200-tilesizy[BOTTOMSTATUSBAR]);
227
    ty = sbary(200-tilesizy[BOTTOMSTATUSBAR]);
228
228
229
    clx1 = scale(scale(x1,xdim,320),ud.statusbarscale,100);
229
    clx1 = scale(scale(x1,xdim,320),ud.statusbarscale,100);
230
    cly1 = scale(scale(y1,ydim,200),ud.statusbarscale,100);
230
    cly1 = scale(scale(y1,ydim,200),ud.statusbarscale,100);
231
    clx2 = scale(scale(x2,xdim,320),ud.statusbarscale,100);
231
    clx2 = scale(scale(x2,xdim,320),ud.statusbarscale,100);
232
    cly2 = scale(scale(y2,ydim,200),ud.statusbarscale,100);
232
    cly2 = scale(scale(y2,ydim,200),ud.statusbarscale,100);
233
    clofx = (xdim - scale(xdim,ud.statusbarscale,100)) >> 1;
233
    clofx = (xdim - scale(xdim,ud.statusbarscale,100)) >> 1;
234
    clofy = (ydim - scale(ydim,ud.statusbarscale,100));
234
    clofy = (ydim - scale(ydim,ud.statusbarscale,100));
235
235
236
//    if (ud.statusbarmode == 0)
236
//    if (ud.statusbarmode == 0)
237
    rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1+clofx,cly1+clofy,clx2+clofx-1,cly2+clofy-1);
237
    rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1+clofx,cly1+clofy,clx2+clofx-1,cly2+clofy-1);
238
//    else rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1,cly1,clx2+clofx-1,cly2+clofy-1);
238
//    else rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1,cly1,clx2+clofx-1,cly2+clofy-1);
239
}
239
}
240
240
241
void setgamepalette(player_struct *player, char *pal, int set)
241
void setgamepalette(player_struct *player, char *pal, int set)
242
{
242
{
243
    if (player != g_player[screenpeek].ps)
243
    if (player != g_player[screenpeek].ps)
244
    {
244
    {
245
        // another head
245
        // another head
246
        player->palette = pal;
246
        player->palette = pal;
247
        return;
247
        return;
248
    }
248
    }
249
249
250
#if 0
250
#if 0
251
    if (getrendermode() < 3)
251
    if (getrendermode() < 3)
252
    {
252
    {
253
        // 8-bit mode
253
        // 8-bit mode
254
        player->palette = pal;
254
        player->palette = pal;
255
        setbrightness(ud.brightness>>2, pal, set);
255
        setbrightness(ud.brightness>>2, pal, set);
256
        //pub = pus = NUMPAGES;
256
        //pub = pus = NUMPAGES;
257
        return;
257
        return;
258
    }
258
    }
259
259
260
    if (pal == palette || pal == waterpal || pal == slimepal)
260
    if (pal == palette || pal == waterpal || pal == slimepal)
261
    {
261
    {
262
        if (player->palette != palette && player->palette != waterpal && player->palette != slimepal)
262
        if (player->palette != palette && player->palette != waterpal && player->palette != slimepal)
263
            setbrightness(ud.brightness>>2, palette, set);
263
            setbrightness(ud.brightness>>2, palette, set);
264
        else setpalettefade(0,0,0,0);
264
        else setpalettefade(0,0,0,0);
265
    }
265
    }
266
    else
266
    else
267
    {
267
    {
268
        if (pal != titlepal && pal != drealms && pal != endingpal && pal != animpal)
268
        if (pal != titlepal && pal != drealms && pal != endingpal && pal != animpal)
269
            pal = palette;
269
            pal = palette;
270
        setbrightness(ud.brightness>>2, pal, set);
270
        setbrightness(ud.brightness>>2, pal, set);
271
    }
271
    }
272
#else
272
#else
273
    if (!(pal == palette || pal == waterpal || pal == slimepal || pal == drealms || pal == titlepal || pal == endingpal || pal == animpal))
273
    if (!(pal == palette || pal == waterpal || pal == slimepal || pal == drealms || pal == titlepal || pal == endingpal || pal == animpal))
274
        pal = palette;
274
        pal = palette;
275
275
276
    setbrightness(ud.brightness>>2, pal, set);
276
    setbrightness(ud.brightness>>2, pal, set);
277
#endif
277
#endif
278
    player->palette = pal;
278
    player->palette = pal;
279
}
279
}
280
280
281
int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,int orientation,int x1, int y1, int x2, int y2, int z)
281
int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,int orientation,int x1, int y1, int x2, int y2, int z)
282
{
282
{
283
    int ac,newx,oldx=x;
283
    int ac,newx,oldx=x;
284
    char centre, *oldt;
284
    char centre, *oldt;
285
285
286
    centre = (x == (320>>1));
286
    centre = (x == (320>>1));
287
    newx = 0;
287
    newx = 0;
288
    oldt = (char *)t;
288
    oldt = (char *)t;
289
289
290
    if (t == NULL)
290
    if (t == NULL)
291
        return -1;
291
        return -1;
292
292
293
    if (centre)
293
    if (centre)
294
    {
294
    {
295
        while (*t)
295
        while (*t)
296
        {
296
        {
297
            if (*t == '^' && isdigit(*(t+1)))
297
            if (*t == '^' && isdigit(*(t+1)))
298
            {
298
            {
299
                t += 2;
299
                t += 2;
300
                if (isdigit(*t)) t++;
300
                if (isdigit(*t)) t++;
301
                continue;
301
                continue;
302
            }
302
            }
303
            if (*t == 32)
303
            if (*t == 32)
304
            {
304
            {
305
                newx+=5*z/65536;
305
                newx+=5*z/65536;
306
                t++;
306
                t++;
307
                continue;
307
                continue;
308
            }
308
            }
309
            else ac = *t - '!' + starttile;
309
            else ac = *t - '!' + starttile;
310
310
311
            if (ac < starttile || ac > (starttile + 93)) break;
311
            if (ac < starttile || ac > (starttile + 93)) break;
312
312
313
            if (*t >= '0' && *t <= '9')
313
            if (*t >= '0' && *t <= '9')
314
                newx += 8*z/65536;
314
                newx += 8*z/65536;
315
            else newx += tilesizx[ac]*z/65536;
315
            else newx += tilesizx[ac]*z/65536;
316
            t++;
316
            t++;
317
        }
317
        }
318
318
319
        t = oldt;
319
        t = oldt;
320
        x = (320>>1)-(newx>>1);
320
        x = (320>>1)-(newx>>1);
321
    }
321
    }
322
322
323
    while (*t)
323
    while (*t)
324
    {
324
    {
325
        if (*t == '^' && isdigit(*(t+1)))
325
        if (*t == '^' && isdigit(*(t+1)))
326
        {
326
        {
327
            char smallbuf[4];
327
            char smallbuf[4];
328
            t++;
328
            t++;
329
            if (isdigit(*(t+1)))
329
            if (isdigit(*(t+1)))
330
            {
330
            {
331
                smallbuf[0] = *(t++);
331
                smallbuf[0] = *(t++);
332
                smallbuf[1] = *(t++);
332
                smallbuf[1] = *(t++);
333
                smallbuf[2] = '\0';
333
                smallbuf[2] = '\0';
334
                p = atol(smallbuf);
334
                p = atol(smallbuf);
335
            }
335
            }
336
            else
336
            else
337
            {
337
            {
338
                smallbuf[0] = *(t++);
338
                smallbuf[0] = *(t++);
339
                smallbuf[1] = '\0';
339
                smallbuf[1] = '\0';
340
                p = atol(smallbuf);
340
                p = atol(smallbuf);
341
            }
341
            }
342
            continue;
342
            continue;
343
        }
343
        }
344
        if (*t == 32)
344
        if (*t == 32)
345
        {
345
        {
346
            x+=5*z/65536;
346
            x+=5*z/65536;
347
            t++;
347
            t++;
348
            continue;
348
            continue;
349
        }
349
        }
350
        else ac = *t - '!' + starttile;
350
        else ac = *t - '!' + starttile;
351
351
352
        if (ac < starttile || ac > (starttile + 93))
352
        if (ac < starttile || ac > (starttile + 93))
353
            break;
353
            break;
354
354
355
        rotatesprite(x<<16,(y<<16)+(small?ud.config.ScreenHeight<<15:0),z,0,ac,s,p,small?(8|16):(2|orientation),x1,y1,x2,y2);
355
        rotatesprite(x<<16,(y<<16)+(small?ud.config.ScreenHeight<<15:0),z,0,ac,s,p,small?(8|16):(2|orientation),x1,y1,x2,y2);
356
356
357
        if ((*t >= '0' && *t <= '9'))
357
        if ((*t >= '0' && *t <= '9'))
358
            x += 8*z/65536;
358
            x += 8*z/65536;
359
        else x += tilesizx[ac]*z/65536;//(tilesizx[ac]>>small);
359
        else x += tilesizx[ac]*z/65536;//(tilesizx[ac]>>small);
360
        if (x > (ud.config.ScreenWidth - 14)) oldt = (char *)t, x = oldx, y+=8*z/65536;
360
        if (x > (ud.config.ScreenWidth - 14)) oldt = (char *)t, x = oldx, y+=8*z/65536;
361
        t++;
361
        t++;
362
    }
362
    }
363
363
364
    return (x);
364
    return (x);
365
}
365
}
366
366
367
int gametextlen(int x,const char *t)
367
int gametextlen(int x,const char *t)
368
{
368
{
369
    int ac;
369
    int ac;
370
370
371
    if (t == NULL)
371
    if (t == NULL)
372
        return -1;
372
        return -1;
373
373
374
    while (*t)
374
    while (*t)
375
    {
375
    {
376
        if (*t == 32)
376
        if (*t == 32)
377
        {
377
        {
378
            x+=5;
378
            x+=5;
379
            t++;
379
            t++;
380
            continue;
380
            continue;
381
        }
381
        }
382
        else ac = *t - '!' + STARTALPHANUM;
382
        else ac = *t - '!' + STARTALPHANUM;
383
383
384
        if (ac < STARTALPHANUM || ac > (STARTALPHANUM + 93))
384
        if (ac < STARTALPHANUM || ac > (STARTALPHANUM + 93))
385
            break;
385
            break;
386
386
387
        if ((*t >= '0' && *t <= '9'))
387
        if ((*t >= '0' && *t <= '9'))
388
            x += 8;
388
            x += 8;
389
        else x += tilesizx[ac];
389
        else x += tilesizx[ac];
390
        t++;
390
        t++;
391
    }
391
    }
392
392
393
    return (x);
393
    return (x);
394
}
394
}
395
395
396
inline int gametext(int x,int y,const char *t,int s,int dabits)
396
inline int gametext(int x,int y,const char *t,int s,int dabits)
397
{
397
{
398
    return(gametext_z(0,STARTALPHANUM, x,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
398
    return(gametext_z(0,STARTALPHANUM, x,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
399
}
399
}
400
400
401
inline int gametextpal(int x,int y,const char *t,int s,int p)
401
inline int gametextpal(int x,int y,const char *t,int s,int p)
402
{
402
{
403
    return(gametext_z(0,STARTALPHANUM, x,y,t,s,p,26,0, 0, xdim-1, ydim-1, 65536));
403
    return(gametext_z(0,STARTALPHANUM, x,y,t,s,p,26,0, 0, xdim-1, ydim-1, 65536));
404
}
404
}
405
405
406
static inline int mpgametext(int y,const char *t,int s,int dabits)
406
static inline int mpgametext(int y,const char *t,int s,int dabits)
407
{
407
{
408
    if (xdim >= 640 && ydim >= 480)
408
    if (xdim >= 640 && ydim >= 480)
409
        return(gametext_z(1,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
409
        return(gametext_z(1,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
410
    return(gametext_z(0,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
410
    return(gametext_z(0,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
411
}
411
}
412
412
413
static int minitext_(int x,int y,const char *t,int s,int p,int sb)
413
static int minitext_(int x,int y,const char *t,int s,int p,int sb)
414
{
414
{
415
    int ac;
415
    int ac;
416
    char ch,cmode;
416
    char ch,cmode;
417
417
418
    cmode = (sb&256)!=0;
418
    cmode = (sb&256)!=0;
419
    sb &= 255;
419
    sb &= 255;
420
420
421
    while (*t)
421
    while (*t)
422
    {
422
    {
423
        ch = Btoupper(*t);
423
        ch = Btoupper(*t);
424
        if (ch == 32)
424
        if (ch == 32)
425
        {
425
        {
426
            x+=5;
426
            x+=5;
427
            t++;
427
            t++;
428
            continue;
428
            continue;
429
        }
429
        }
430
        else ac = ch - '!' + MINIFONT;
430
        else ac = ch - '!' + MINIFONT;
431
431
432
        if (cmode) rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,ac,s,p,sb,0,0,xdim-1,ydim-1);
432
        if (cmode) rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,ac,s,p,sb,0,0,xdim-1,ydim-1);
433
        else rotatesprite(x<<16,y<<16,65536L,0,ac,s,p,sb,0,0,xdim-1,ydim-1);
433
        else rotatesprite(x<<16,y<<16,65536L,0,ac,s,p,sb,0,0,xdim-1,ydim-1);
434
        x += 4; // tilesizx[ac]+1;
434
        x += 4; // tilesizx[ac]+1;
435
435
436
        t++;
436
        t++;
437
    }
437
    }
438
    return (x);
438
    return (x);
439
}
439
}
440
440
441
inline int minitextshade(int x,int y,const char *t,int s,int p,int sb)
441
inline int minitextshade(int x,int y,const char *t,int s,int p,int sb)
442
{
442
{
443
    return (minitext_(x,y,(char *)stripcolorcodes(t),s,p,sb));
443
    return (minitext_(x,y,(char *)stripcolorcodes(t),s,p,sb));
444
}
444
}
445
445
446
inline int minitext(int x,int y,const char *t,int p,int sb)
446
inline int minitext(int x,int y,const char *t,int p,int sb)
447
{
447
{
448
    return (minitext_(x,y,(char *)stripcolorcodes(t),0,p,sb));
448
    return (minitext_(x,y,(char *)stripcolorcodes(t),0,p,sb));
449
}
449
}
450
450
451
#if 0
451
#if 0
452
static void gamenumber(int x,int y,int n,char s)
452
static void gamenumber(int x,int y,int n,char s)
453
{
453
{
454
    char b[10];
454
    char b[10];
455
    //ltoa(n,b,10);
455
    //ltoa(n,b,10);
456
    Bsnprintf(b,10,"%d",n);
456
    Bsnprintf(b,10,"%d",n);
457
    gametext(x,y,b,s,2+8+16);
457
    gametext(x,y,b,s,2+8+16);
458
}
458
}
459
#endif
459
#endif
460
460
461
static void allowtimetocorrecterrorswhenquitting(void)
461
static void allowtimetocorrecterrorswhenquitting(void)
462
{
462
{
463
    int i, j, oldtotalclock;
463
    int i, j, oldtotalclock;
464
464
465
    ready2send = 0;
465
    ready2send = 0;
466
466
467
    for (j=0;j<8;j++)
467
    for (j=0;j<8;j++)
468
    {
468
    {
469
        oldtotalclock = totalclock;
469
        oldtotalclock = totalclock;
470
470
471
        while (totalclock < oldtotalclock+TICSPERFRAME)
471
        while (totalclock < oldtotalclock+TICSPERFRAME)
472
        {
472
        {
473
            handleevents();
473
            handleevents();
474
            getpackets();
474
            getpackets();
475
        }
475
        }
476
        if (KB_KeyPressed(sc_Escape)) return;
476
        if (KB_KeyPressed(sc_Escape)) return;
477
477
478
        packbuf[0] = 127;
478
        packbuf[0] = 127;
479
        for (i=connecthead;i>=0;i=connectpoint2[i])
479
        for (i=connecthead;i>=0;i=connectpoint2[i])
480
        {
480
        {
481
            if (i != myconnectindex) sendpacket(i,packbuf,1);
481
            if (i != myconnectindex) sendpacket(i,packbuf,1);
482
            if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
482
            if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
483
        }
483
        }
484
    }
484
    }
485
}
485
}
486
486
487
void adduserquote(const char *daquote)
487
void adduserquote(const char *daquote)
488
{
488
{
489
    int i;
489
    int i;
490
490
491
    for (i=MAXUSERQUOTES-1;i>0;i--)
491
    for (i=MAXUSERQUOTES-1;i>0;i--)
492
    {
492
    {
493
        Bstrcpy(user_quote[i],user_quote[i-1]);
493
        Bstrcpy(user_quote[i],user_quote[i-1]);
494
        user_quote_time[i] = user_quote_time[i-1];
494
        user_quote_time[i] = user_quote_time[i-1];
495
    }
495
    }
496
    Bstrcpy(user_quote[0],daquote);
496
    Bstrcpy(user_quote[0],daquote);
497
    OSD_Printf("%s\n",daquote);
497
    OSD_Printf("%s\n",daquote);
498
498
499
    user_quote_time[0] = ud.msgdisptime;
499
    user_quote_time[0] = ud.msgdisptime;
500
    pub = NUMPAGES;
500
    pub = NUMPAGES;
501
}
501
}
502
502
503
int lastpackettime = 0;
503
int lastpackettime = 0;
504
504
505
void getpackets(void)
505
void getpackets(void)
506
{
506
{
507
    int i, j, k, l;
507
    int i, j, k, l;
508
    int other, packbufleng;
508
    int other, packbufleng;
509
    input *osyn, *nsyn;
509
    input *osyn, *nsyn;
510
510
511
    sampletimer();
511
    sampletimer();
512
    AudioUpdate();
512
    AudioUpdate();
513
513
514
    CONTROL_ProcessBinds();
514
    CONTROL_ProcessBinds();
515
515
516
    if (ALT_IS_PRESSED && KB_KeyPressed(sc_Enter))
516
    if (ALT_IS_PRESSED && KB_KeyPressed(sc_Enter))
517
    {
517
    {
518
        if (setgamemode(!ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP))
518
        if (setgamemode(!ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP))
519
        {
519
        {
520
            OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "Failed setting fullscreen video mode.\n");
520
            OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "Failed setting fullscreen video mode.\n");
521
            if (setgamemode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP))
521
            if (setgamemode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP))
522
                gameexit("Failed to recover from failure to set fullscreen video mode.\n");
522
                gameexit("Failed to recover from failure to set fullscreen video mode.\n");
523
        }
523
        }
524
        else ud.config.ScreenMode = !ud.config.ScreenMode;
524
        else ud.config.ScreenMode = !ud.config.ScreenMode;
525
        KB_ClearKeyDown(sc_Enter);
525
        KB_ClearKeyDown(sc_Enter);
526
        restorepalette = 1;
526
        restorepalette = 1;
527
        vscrn();
527
        vscrn();
528
    }
528
    }
529
529
530
    if (KB_UnBoundKeyPressed(sc_F12))
530
    if (KB_UnBoundKeyPressed(sc_F12))
531
    {
531
    {
532
        KB_ClearKeyDown(sc_F12);
532
        KB_ClearKeyDown(sc_F12);
533
        screencapture("duke0000.tga",0);
533
        screencapture("duke0000.tga",0);
534
        FTA(103,g_player[myconnectindex].ps);
534
        FTA(103,g_player[myconnectindex].ps);
535
    }
535
    }
536
536
537
    // only dispatch commands here when not in a game
537
    // only dispatch commands here when not in a game
538
    if (!(g_player[myconnectindex].ps->gm&MODE_GAME))
538
    if (!(g_player[myconnectindex].ps->gm&MODE_GAME))
539
    {
539
    {
540
        OSD_DispatchQueued();
540
        OSD_DispatchQueued();
541
    }
541
    }
542
542
543
    if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && (KB_KeyPressed(sc_Delete)||KB_KeyPressed(sc_End)))
543
    if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && (KB_KeyPressed(sc_Delete)||KB_KeyPressed(sc_End)))
544
    {
544
    {
545
        qe = 1;
545
        qe = 1;
546
        gameexit("Quick Exit.");
546
        gameexit("Quick Exit.");
547
    }
547
    }
548
548
549
    if (numplayers < 2) return;
549
    if (numplayers < 2) return;
550
    while ((packbufleng = getpacket(&other,packbuf)) > 0)
550
    while ((packbufleng = getpacket(&other,packbuf)) > 0)
551
    {
551
    {
552
        lastpackettime = totalclock;
552
        lastpackettime = totalclock;
553
#if 0
553
#if 0
554
        initprintf("RECEIVED PACKET: type: %d : len %d\n", packbuf[0], packbufleng);
554
        initprintf("RECEIVED PACKET: type: %d : len %d\n", packbuf[0], packbufleng);
555
#endif
555
#endif
556
        switch (packbuf[0])
556
        switch (packbuf[0])
557
        {
557
        {
558
        case 0:  //[0] (receive master sync buffer)
558
        case 0:  //[0] (receive master sync buffer)
559
            j = 1;
559
            j = 1;
560
560
561
            if ((g_player[other].movefifoend&(TIMERUPDATESIZ-1)) == 0)
561
            if ((g_player[other].movefifoend&(TIMERUPDATESIZ-1)) == 0)
562
                for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
562
                for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
563
                {
563
                {
564
                    if (g_player[i].playerquitflag == 0) continue;
564
                    if (g_player[i].playerquitflag == 0) continue;
565
                    if (i == myconnectindex)
565
                    if (i == myconnectindex)
566
                        otherminlag = (int)((signed char)packbuf[j]);
566
                        otherminlag = (int)((signed char)packbuf[j]);
567
                    j++;
567
                    j++;
568
                }
568
                }
569
569
570
            osyn = (input *)&inputfifo[(g_player[connecthead].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
570
            osyn = (input *)&inputfifo[(g_player[connecthead].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
571
            nsyn = (input *)&inputfifo[(g_player[connecthead].movefifoend)&(MOVEFIFOSIZ-1)][0];
571
            nsyn = (input *)&inputfifo[(g_player[connecthead].movefifoend)&(MOVEFIFOSIZ-1)][0];
572
572
573
            k = j;
573
            k = j;
574
            for (i=connecthead;i>=0;i=connectpoint2[i])
574
            for (i=connecthead;i>=0;i=connectpoint2[i])
575
                j += g_player[i].playerquitflag+g_player[i].playerquitflag;
575
                j += g_player[i].playerquitflag+g_player[i].playerquitflag;
576
            for (i=connecthead;i>=0;i=connectpoint2[i])
576
            for (i=connecthead;i>=0;i=connectpoint2[i])
577
            {
577
            {
578
                if (g_player[i].playerquitflag == 0) continue;
578
                if (g_player[i].playerquitflag == 0) continue;
579
579
580
                l = packbuf[k++];
580
                l = packbuf[k++];
581
                l += (int)(packbuf[k++]<<8);
581
                l += (int)(packbuf[k++]<<8);
582
582
583
                if (i == myconnectindex)
583
                if (i == myconnectindex)
584
                {
584
                {
585
                    j += ((l&1)<<1)+(l&2)+((l&4)>>2)+((l&8)>>3)+((l&16)>>4)+((l&32)>>5)+((l&64)>>6)+((l&128)>>7)+((l&256)>>8)+((l&512)>>9)+((l&1024)>>10)+((l&2048)>>11);
585
                    j += ((l&1)<<1)+(l&2)+((l&4)>>2)+((l&8)>>3)+((l&16)>>4)+((l&32)>>5)+((l&64)>>6)+((l&128)>>7)+((l&256)>>8)+((l&512)>>9)+((l&1024)>>10)+((l&2048)>>11);
586
                    continue;
586
                    continue;
587
                }
587
                }
588
588
589
                copybufbyte(&osyn[i],&nsyn[i],sizeof(input));
589
                copybufbyte(&osyn[i],&nsyn[i],sizeof(input));
590
                if (l&1)   nsyn[i].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
590
                if (l&1)   nsyn[i].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
591
                if (l&2)   nsyn[i].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
591
                if (l&2)   nsyn[i].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
592
                if (l&4)   nsyn[i].avel = (signed char)packbuf[j++];
592
                if (l&4)   nsyn[i].avel = (signed char)packbuf[j++];
593
                if (l&8)   nsyn[i].bits = ((nsyn[i].bits&0xffffff00)|((int)packbuf[j++]));
593
                if (l&8)   nsyn[i].bits = ((nsyn[i].bits&0xffffff00)|((int)packbuf[j++]));
594
                if (l&16)  nsyn[i].bits = ((nsyn[i].bits&0xffff00ff)|((int)packbuf[j++])<<8);
594
                if (l&16)  nsyn[i].bits = ((nsyn[i].bits&0xffff00ff)|((int)packbuf[j++])<<8);
595
                if (l&32)  nsyn[i].bits = ((nsyn[i].bits&0xff00ffff)|((int)packbuf[j++])<<16);
595
                if (l&32)  nsyn[i].bits = ((nsyn[i].bits&0xff00ffff)|((int)packbuf[j++])<<16);
596
                if (l&64)  nsyn[i].bits = ((nsyn[i].bits&0x00ffffff)|((int)packbuf[j++])<<24);
596
                if (l&64)  nsyn[i].bits = ((nsyn[i].bits&0x00ffffff)|((int)packbuf[j++])<<24);
597
                if (l&128) nsyn[i].horz = (signed char)packbuf[j++];
597
                if (l&128) nsyn[i].horz = (signed char)packbuf[j++];
598
                if (l&256)  nsyn[i].extbits = ((nsyn[i].extbits&0xffffff00)|((int)packbuf[j++]));
598
                if (l&256)  nsyn[i].extbits = ((nsyn[i].extbits&0xffffff00)|((int)packbuf[j++]));
599
                if (l&512)  nsyn[i].extbits = ((nsyn[i].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
599
                if (l&512)  nsyn[i].extbits = ((nsyn[i].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
600
                if (l&1024) nsyn[i].extbits = ((nsyn[i].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
600
                if (l&1024) nsyn[i].extbits = ((nsyn[i].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
601
                if (l&2048) nsyn[i].extbits = ((nsyn[i].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
601
                if (l&2048) nsyn[i].extbits = ((nsyn[i].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
602
602
603
                if (nsyn[i].bits&(1<<26)) g_player[i].playerquitflag = 0;
603
                if (nsyn[i].bits&(1<<26)) g_player[i].playerquitflag = 0;
604
                g_player[i].movefifoend++;
604
                g_player[i].movefifoend++;
605
            }
605
            }
606
606
607
            while (j != packbufleng)
607
            while (j != packbufleng)
608
            {
608
            {
609
                for (i=connecthead;i>=0;i=connectpoint2[i])
609
                for (i=connecthead;i>=0;i=connectpoint2[i])
610
                    if (i != myconnectindex)
610
                    if (i != myconnectindex)
611
                    {
611
                    {
612
                        g_player[i].syncval[g_player[i].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j];
612
                        g_player[i].syncval[g_player[i].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j];
613
                        g_player[i].syncvalhead++;
613
                        g_player[i].syncvalhead++;
614
                    }
614
                    }
615
                j++;
615
                j++;
616
            }
616
            }
617
617
618
            for (i=connecthead;i>=0;i=connectpoint2[i])
618
            for (i=connecthead;i>=0;i=connectpoint2[i])
619
                if (i != myconnectindex)
619
                if (i != myconnectindex)
620
                    for (j=1;j<movesperpacket;j++)
620
                    for (j=1;j<movesperpacket;j++)
621
                    {
621
                    {
622
                        copybufbyte(&nsyn[i],&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input));
622
                        copybufbyte(&nsyn[i],&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input));
623
                        g_player[i].movefifoend++;
623
                        g_player[i].movefifoend++;
624
                    }
624
                    }
625
625
626
            movefifosendplc += movesperpacket;
626
            movefifosendplc += movesperpacket;
627
627
628
            break;
628
            break;
629
        case 1:  //[1] (receive slave sync buffer)
629
        case 1:  //[1] (receive slave sync buffer)
630
            j = 3;
630
            j = 3;
631
            k = packbuf[1] + (int)(packbuf[2]<<8);
631
            k = packbuf[1] + (int)(packbuf[2]<<8);
632
632
633
            osyn = (input *)&inputfifo[(g_player[other].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
633
            osyn = (input *)&inputfifo[(g_player[other].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
634
            nsyn = (input *)&inputfifo[(g_player[other].movefifoend)&(MOVEFIFOSIZ-1)][0];
634
            nsyn = (input *)&inputfifo[(g_player[other].movefifoend)&(MOVEFIFOSIZ-1)][0];
635
635
636
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
636
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
637
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
637
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
638
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
638
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
639
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
639
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
640
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int)packbuf[j++]));
640
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int)packbuf[j++]));
641
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int)packbuf[j++])<<8);
641
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int)packbuf[j++])<<8);
642
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int)packbuf[j++])<<16);
642
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int)packbuf[j++])<<16);
643
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int)packbuf[j++])<<24);
643
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int)packbuf[j++])<<24);
644
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
644
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
645
            if (k&256)  nsyn[other].extbits = ((nsyn[other].extbits&0xffffff00)|((int)packbuf[j++]));
645
            if (k&256)  nsyn[other].extbits = ((nsyn[other].extbits&0xffffff00)|((int)packbuf[j++]));
646
            if (k&512)  nsyn[other].extbits = ((nsyn[other].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
646
            if (k&512)  nsyn[other].extbits = ((nsyn[other].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
647
            if (k&1024) nsyn[other].extbits = ((nsyn[other].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
647
            if (k&1024) nsyn[other].extbits = ((nsyn[other].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
648
            if (k&2048) nsyn[other].extbits = ((nsyn[other].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
648
            if (k&2048) nsyn[other].extbits = ((nsyn[other].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
649
            g_player[other].movefifoend++;
649
            g_player[other].movefifoend++;
650
650
651
            while (j != packbufleng)
651
            while (j != packbufleng)
652
            {
652
            {
653
                g_player[other].syncval[g_player[other].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j++];
653
                g_player[other].syncval[g_player[other].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j++];
654
                g_player[other].syncvalhead++;
654
                g_player[other].syncvalhead++;
655
            }
655
            }
656
656
657
            for (i=1;i<movesperpacket;i++)
657
            for (i=1;i<movesperpacket;i++)
658
            {
658
            {
659
                copybufbyte(&nsyn[other],&inputfifo[g_player[other].movefifoend&(MOVEFIFOSIZ-1)][other],sizeof(input));
659
                copybufbyte(&nsyn[other],&inputfifo[g_player[other].movefifoend&(MOVEFIFOSIZ-1)][other],sizeof(input));
660
                g_player[other].movefifoend++;
660
                g_player[other].movefifoend++;
661
            }
661
            }
662
662
663
            break;
663
            break;
664
664
665
        case 16:
665
        case 16:
666
            g_player[other].movefifoend = movefifoplc = movefifosendplc = fakemovefifoplc = 0;
666
            g_player[other].movefifoend = movefifoplc = movefifosendplc = fakemovefifoplc = 0;
667
            g_player[other].syncvalhead = syncvaltottail = 0L;
667
            g_player[other].syncvalhead = syncvaltottail = 0L;
668
        case 17:
668
        case 17:
669
            j = 1;
669
            j = 1;
670
670
671
            if ((g_player[other].movefifoend&(TIMERUPDATESIZ-1)) == 0)
671
            if ((g_player[other].movefifoend&(TIMERUPDATESIZ-1)) == 0)
672
                if (other == connecthead)
672
                if (other == connecthead)
673
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
673
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
674
                    {
674
                    {
675
                        if (i == myconnectindex)
675
                        if (i == myconnectindex)
676
                            otherminlag = (int)((signed char)packbuf[j]);
676
                            otherminlag = (int)((signed char)packbuf[j]);
677
                        j++;
677
                        j++;
678
                    }
678
                    }
679
679
680
            osyn = (input *)&inputfifo[(g_player[other].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
680
            osyn = (input *)&inputfifo[(g_player[other].movefifoend-1)&(MOVEFIFOSIZ-1)][0];
681
            nsyn = (input *)&inputfifo[(g_player[other].movefifoend)&(MOVEFIFOSIZ-1)][0];
681
            nsyn = (input *)&inputfifo[(g_player[other].movefifoend)&(MOVEFIFOSIZ-1)][0];
682
682
683
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
683
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
684
            k = packbuf[j++];
684
            k = packbuf[j++];
685
            k += (int)(packbuf[j++]<<8);
685
            k += (int)(packbuf[j++]<<8);
686
686
687
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
687
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
688
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
688
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
689
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
689
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
690
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int)packbuf[j++]));
690
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((int)packbuf[j++]));
691
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int)packbuf[j++])<<8);
691
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((int)packbuf[j++])<<8);
692
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int)packbuf[j++])<<16);
692
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((int)packbuf[j++])<<16);
693
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int)packbuf[j++])<<24);
693
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((int)packbuf[j++])<<24);
694
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
694
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
695
            if (k&256)  nsyn[other].extbits = ((nsyn[other].extbits&0xffffff00)|((int)packbuf[j++]));
695
            if (k&256)  nsyn[other].extbits = ((nsyn[other].extbits&0xffffff00)|((int)packbuf[j++]));
696
            if (k&512)  nsyn[other].extbits = ((nsyn[other].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
696
            if (k&512)  nsyn[other].extbits = ((nsyn[other].extbits&0xffff00ff)|((int)packbuf[j++])<<8);
697
            if (k&1024) nsyn[other].extbits = ((nsyn[other].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
697
            if (k&1024) nsyn[other].extbits = ((nsyn[other].extbits&0xff00ffff)|((int)packbuf[j++])<<16);
698
            if (k&2048) nsyn[other].extbits = ((nsyn[other].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
698
            if (k&2048) nsyn[other].extbits = ((nsyn[other].extbits&0x00ffffff)|((int)packbuf[j++])<<24);
699
            g_player[other].movefifoend++;
699
            g_player[other].movefifoend++;
700
700
701
            for (i=1;i<movesperpacket;i++)
701
            for (i=1;i<movesperpacket;i++)
702
            {
702
            {
703
                copybufbyte(&nsyn[other],&inputfifo[g_player[other].movefifoend&(MOVEFIFOSIZ-1)][other],sizeof(input));
703
                copybufbyte(&nsyn[other],&inputfifo[g_player[other].movefifoend&(MOVEFIFOSIZ-1)][other],sizeof(input));
704
                g_player[other].movefifoend++;
704
                g_player[other].movefifoend++;
705
            }
705
            }
706
706
707
            if (j > packbufleng)
707
            if (j > packbufleng)
708
                initprintf("INVALID GAME PACKET!!! (packet %d, %d too many bytes (%d %d))\n",packbuf[0],j-packbufleng,packbufleng,k);
708
                initprintf("INVALID GAME PACKET!!! (packet %d, %d too many bytes (%d %d))\n",packbuf[0],j-packbufleng,packbufleng,k);
709
709
710
            while (j < packbufleng)
710
            while (j < packbufleng)
711
            {
711
            {
712
                g_player[other].syncval[g_player[other].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j++];
712
                g_player[other].syncval[g_player[other].syncvalhead&(MOVEFIFOSIZ-1)] = packbuf[j++];
713
                g_player[other].syncvalhead++;
713
                g_player[other].syncvalhead++;
714
            }
714
            }
715
715
716
            break;
716
            break;
717
        case 127:
717
        case 127:
718
            break;
718
            break;
719
719
720
        case 250:
720
        case 250:
721
            if (g_player[other].playerreadyflag == 0)
721
            if (g_player[other].playerreadyflag == 0)
722
                initprintf("Player %d is ready\n", other);
722
                initprintf("Player %d is ready\n", other);
723
            g_player[other].playerreadyflag++;
723
            g_player[other].playerreadyflag++;
724
            break;
724
            break;
725
        case 255:
725
        case 255:
726
            gameexit(" ");
726
            gameexit(" ");
727
            break;
727
            break;
728
        default:
728
        default:
729
            switch (packbuf[0])
729
            switch (packbuf[0])
730
            {
730
            {
731
            case 4:
731
            case 4:
732
                //slaves in M/S mode only send to master
732
                //slaves in M/S mode only send to master
733
                if ((!networkmode) && (myconnectindex == connecthead))
733
                if ((!networkmode) && (myconnectindex == connecthead))
734
                {
734
                {
735
                    if (packbuf[1] == 255)
735
                    if (packbuf[1] == 255)
736
                    {
736
                    {
737
                        //Master re-transmits message to all others
737
                        //Master re-transmits message to all others
738
                        for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
738
                        for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
739
                            if (i != other)
739
                            if (i != other)
740
                                sendpacket(i,packbuf,packbufleng);
740
                                sendpacket(i,packbuf,packbufleng);
741
                    }
741
                    }
742
                    else if (((int)packbuf[1]) != myconnectindex)
742
                    else if (((int)packbuf[1]) != myconnectindex)
743
                    {
743
                    {
744
                        //Master re-transmits message not intended for master
744
                        //Master re-transmits message not intended for master
745
                        sendpacket((int)packbuf[1],packbuf,packbufleng);
745
                        sendpacket((int)packbuf[1],packbuf,packbufleng);
746
                        break;
746
                        break;
747
                    }
747
                    }
748
                }
748
                }
749
749
750
                Bstrcpy(recbuf,packbuf+2);
750
                Bstrcpy(recbuf,packbuf+2);
751
                recbuf[packbufleng-2] = 0;
751
                recbuf[packbufleng-2] = 0;
752
752
753
                adduserquote(recbuf);
753
                adduserquote(recbuf);
754
                sound(EXITMENUSOUND);
754
                sound(EXITMENUSOUND);
755
755
756
                pus = NUMPAGES;
756
                pus = NUMPAGES;
757
                pub = NUMPAGES;
757
                pub = NUMPAGES;
758
758
759
                break;
759
                break;
760
760
761
            case 5:
761
            case 5:
762
                //Slaves in M/S mode only send to master
762
                //Slaves in M/S mode only send to master
763
                //Master re-transmits message to all others
763
                //Master re-transmits message to all others
764
                if ((!networkmode) && (myconnectindex == connecthead))
764
                if ((!networkmode) && (myconnectindex == connecthead))
765
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
765
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
766
                        if (i != other) sendpacket(i,packbuf,packbufleng);
766
                        if (i != other) sendpacket(i,packbuf,packbufleng);
767
767
768
                if (vote_map != -1 || vote_episode != -1 || voting != -1)
768
                if (vote_map != -1 || vote_episode != -1 || voting != -1)
769
                    adduserquote("VOTE SUCCEEDED");
769
                    adduserquote("VOTE SUCCEEDED");
770
770
771
                ud.m_level_number = ud.level_number = packbuf[1];
771
                ud.m_level_number = ud.level_number = packbuf[1];
772
                ud.m_volume_number = ud.volume_number = packbuf[2];
772
                ud.m_volume_number = ud.volume_number = packbuf[2];
773
                ud.m_player_skill = ud.player_skill = packbuf[3];
773
                ud.m_player_skill = ud.player_skill = packbuf[3];
774
                ud.m_monsters_off = ud.monsters_off = packbuf[4];
774
                ud.m_monsters_off = ud.monsters_off = packbuf[4];
775
                ud.m_respawn_monsters = ud.respawn_monsters = packbuf[5];
775
                ud.m_respawn_monsters = ud.respawn_monsters = packbuf[5];
776
                ud.m_respawn_items = ud.respawn_items = packbuf[6];
776
                ud.m_respawn_items = ud.respawn_items = packbuf[6];
777
                ud.m_respawn_inventory = ud.respawn_inventory = packbuf[7];
777
                ud.m_respawn_inventory = ud.respawn_inventory = packbuf[7];
778
                ud.m_coop = packbuf[8];
778
                ud.m_coop = packbuf[8];
779
                ud.m_marker = ud.marker = packbuf[9];
779
                ud.m_marker = ud.marker = packbuf[9];
780
                ud.m_ffire = ud.ffire = packbuf[10];
780
                ud.m_ffire = ud.ffire = packbuf[10];
781
                ud.m_noexits = ud.noexits = packbuf[11];
781
                ud.m_noexits = ud.noexits = packbuf[11];
782
782
783
                for (i=connecthead;i>=0;i=connectpoint2[i])
783
                for (i=connecthead;i>=0;i=connectpoint2[i])
784
                {
784
                {
785
                    resetweapons(i);
785
                    resetweapons(i);
786
                    resetinventory(i);
786
                    resetinventory(i);
787
                }
787
                }
788
788
789
                newgame(ud.volume_number,ud.level_number,ud.player_skill);
789
                newgame(ud.volume_number,ud.level_number,ud.player_skill);
790
                ud.coop = ud.m_coop;
790
                ud.coop = ud.m_coop;
791
791
792
                if (enterlevel(MODE_GAME)) backtomenu();
792
                if (enterlevel(MODE_GAME)) backtomenu();
793
793
794
                break;
794
                break;
795
            case 6:
795
            case 6:
796
                //slaves in M/S mode only send to master
796
                //slaves in M/S mode only send to master
797
                //Master re-transmits message to all others
797
                //Master re-transmits message to all others
798
                if ((!networkmode) && (myconnectindex == connecthead))
798
                if ((!networkmode) && (myconnectindex == connecthead))
799
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
799
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
800
                        if (i != other) sendpacket(i,packbuf,packbufleng);
800
                        if (i != other) sendpacket(i,packbuf,packbufleng);
801
801
802
                if (packbuf[2] != BYTEVERSION)
802
                if (packbuf[2] != BYTEVERSION)
803
                    gameexit("\nYou cannot play Duke with different versions.");
803
                    gameexit("\nYou cannot play Duke with different versions.");
804
804
805
                other = packbuf[1];
805
                other = packbuf[1];
806
806
807
                for (i=3;packbuf[i];i++)
807
                for (i=3;packbuf[i];i++)
808
                    g_player[other].user_name[i-3] = packbuf[i];
808
                    g_player[other].user_name[i-3] = packbuf[i];
809
                g_player[other].user_name[i-3] = 0;
809
                g_player[other].user_name[i-3] = 0;
810
                i++;
810
                i++;
811
811
812
                g_player[other].ps->aim_mode = packbuf[i++];
812
                g_player[other].ps->aim_mode = packbuf[i++];
813
                g_player[other].ps->auto_aim = packbuf[i++];
813
                g_player[other].ps->auto_aim = packbuf[i++];
814
                g_player[other].ps->weaponswitch = packbuf[i++];
814
                g_player[other].ps->weaponswitch = packbuf[i++];
815
                g_player[other].ps->palookup = g_player[other].pcolor = packbuf[i++];
815
                g_player[other].ps->palookup = g_player[other].pcolor = packbuf[i++];
816
                g_player[other].pteam = packbuf[i++];
816
                g_player[other].pteam = packbuf[i++];
817
817
818
                /*            if(g_player[other].ps->team != j && sprite[g_player[other].ps->i].picnum == APLAYER)
818
                /*            if(g_player[other].ps->team != j && sprite[g_player[other].ps->i].picnum == APLAYER)
819
                            {
819
                            {
820
                                hittype[g_player[other].ps->i].extra = 1000;
820
                                hittype[g_player[other].ps->i].extra = 1000;
821
                                hittype[g_player[other].ps->i].picnum = APLAYERTOP;
821
                                hittype[g_player[other].ps->i].picnum = APLAYERTOP;
822
                            } */
822
                            } */
823
823
824
                break;
824
                break;
825
            case 10:
825
            case 10:
826
                //slaves in M/S mode only send to master
826
                //slaves in M/S mode only send to master
827
                //Master re-transmits message to all others
827
                //Master re-transmits message to all others
828
                if ((!networkmode) && (myconnectindex == connecthead))
828
                if ((!networkmode) && (myconnectindex == connecthead))
829
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
829
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
830
                        if (i != other) sendpacket(i,packbuf,packbufleng);
830
                        if (i != other) sendpacket(i,packbuf,packbufleng);
831
831
832
                other = packbuf[1];
832
                other = packbuf[1];
833
833
834
                i = 2;
834
                i = 2;
835
835
836
                j = i; //This used to be Duke packet #9... now concatenated with Duke packet #6
836
                j = i; //This used to be Duke packet #9... now concatenated with Duke packet #6
837
                for (;i-j<10;i++) g_player[other].wchoice[i-j] = packbuf[i];
837
                for (;i-j<10;i++) g_player[other].wchoice[i-j] = packbuf[i];
838
838
839
                break;
839
                break;
840
            case 7:
840
            case 7:
841
                //slaves in M/S mode only send to master
841
                //slaves in M/S mode only send to master
842
                //Master re-transmits message to all others
842
                //Master re-transmits message to all others
843
                if ((!networkmode) && (myconnectindex == connecthead))
843
                if ((!networkmode) && (myconnectindex == connecthead))
844
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
844
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
845
                        if (i != other) sendpacket(i,packbuf,packbufleng);
845
                        if (i != other) sendpacket(i,packbuf,packbufleng);
846
846
847
                if (numlumps == 0) break;
847
                if (numlumps == 0) break;
848
848
849
                if (ud.config.SoundToggle == 0 || ud.lockout == 1 || ud.config.FXDevice < 0)
849
                if (ud.config.SoundToggle == 0 || ud.lockout == 1 || ud.config.FXDevice < 0)
850
                    break;
850
                    break;
851
                rtsptr = (char *)RTS_GetSound(packbuf[1]-1);
851
                rtsptr = (char *)RTS_GetSound(packbuf[1]-1);
852
                if (*rtsptr == 'C')
852
                if (*rtsptr == 'C')
853
                    FX_PlayVOC3D(rtsptr,0,0,0,255,-packbuf[1]);
853
                    FX_PlayVOC3D(rtsptr,0,0,0,255,-packbuf[1]);
854
                else
854
                else
855
                    FX_PlayWAV3D(rtsptr,0,0,0,255,-packbuf[1]);
855
                    FX_PlayWAV3D(rtsptr,0,0,0,255,-packbuf[1]);
856
                rtsplaying = 7;
856
                rtsplaying = 7;
857
                break;
857
                break;
858
858
859
            case 254:
859
            case 254:
860
                //slaves in M/S mode only send to master
860
                //slaves in M/S mode only send to master
861
                if (myconnectindex == connecthead)
861
                if (myconnectindex == connecthead)
862
                {
862
                {
863
                    //Master re-transmits message to all others
863
                    //Master re-transmits message to all others
864
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
864
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
865
                        if (i != other)
865
                        if (i != other)
866
                            sendpacket(i,packbuf,packbufleng);
866
                            sendpacket(i,packbuf,packbufleng);
867
                }
867
                }
868
                /*
868
                /*
869
                            j = packbuf[1];
869
                            j = packbuf[1];
870
                            playerquitflag[j] = 0;
870
                            playerquitflag[j] = 0;
871

871

872
                            j = -1;
872
                            j = -1;
873
                            for(i=connecthead;i>=0;i=connectpoint2[i])
873
                            for(i=connecthead;i>=0;i=connectpoint2[i])
874
                            {
874
                            {
875
                                if (g_player[i].playerquitflag) { j = i; continue; }
875
                                if (g_player[i].playerquitflag) { j = i; continue; }
876

876

877
                                if (i == connecthead) connecthead = connectpoint2[connecthead];
877
                                if (i == connecthead) connecthead = connectpoint2[connecthead];
878
                                else connectpoint2[j] = connectpoint2[i];
878
                                else connectpoint2[j] = connectpoint2[i];
879

879

880
                                numplayers--;
880
                                numplayers--;
881
                                ud.multimode--;
881
                                ud.multimode--;
882

882

883
                                Bsprintf(buf,"%s is history!",g_player[i].user_name);
883
                                Bsprintf(buf,"%s is history!",g_player[i].user_name);
884
                                adduserquote(buf);
884
                                adduserquote(buf);
885

885

886
                                if (numplayers < 2)
886
                                if (numplayers < 2)
887
                                    sound(GENERIC_AMBIENCE17);
887
                                    sound(GENERIC_AMBIENCE17);
888

888

889
                                if(i == 0 && networkmode == 0) */
889
                                if(i == 0 && networkmode == 0) */
890
                gameexit("Game aborted from menu; disconnected.");
890
                gameexit("Game aborted from menu; disconnected.");
891
                //            }
891
                //            }
892
892
893
                break;
893
                break;
894
894
895
            case 9:
895
            case 9:
896
                //slaves in M/S mode only send to master
896
                //slaves in M/S mode only send to master
897
                if (myconnectindex == connecthead)
897
                if (myconnectindex == connecthead)
898
                {
898
                {
899
                    //Master re-transmits message to all others
899
                    //Master re-transmits message to all others
900
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
900
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
901
                        if (i != other)
901
                        if (i != other)
902
                            sendpacket(i,packbuf,packbufleng);
902
                            sendpacket(i,packbuf,packbufleng);
903
                }
903
                }
904
904
905
                Bstrcpy(boardfilename,packbuf+1);
905
                Bstrcpy(boardfilename,packbuf+1);
906
                boardfilename[packbufleng-1] = 0;
906
                boardfilename[packbufleng-1] = 0;
907
                Bcorrectfilename(boardfilename,0);
907
                Bcorrectfilename(boardfilename,0);
908
                if (boardfilename[0] != 0)
908
                if (boardfilename[0] != 0)
909
                {
909
                {
910
                    if ((i = kopen4load(boardfilename,0)) < 0)
910
                    if ((i = kopen4load(boardfilename,0)) < 0)
911
                    {
911
                    {
912
                        Bmemset(boardfilename,0,sizeof(boardfilename));
912
                        Bmemset(boardfilename,0,sizeof(boardfilename));
913
                        sendboardname();
913
                        sendboardname();
914
                    }
914
                    }
915
                    else kclose(i);
915
                    else kclose(i);
916
                }
916
                }
917
917
918
                if (ud.m_level_number == 7 && ud.m_volume_number == 0 && boardfilename[0] == 0)
918
                if (ud.m_level_number == 7 && ud.m_volume_number == 0 && boardfilename[0] == 0)
919
                    ud.m_level_number = 0;
919
                    ud.m_level_number = 0;
920
920
921
                break;
921
                break;
922
922
923
            case 18: // map vote
923
            case 18: // map vote
924
924
925
                if (myconnectindex == connecthead)
925
                if (myconnectindex == connecthead)
926
                {
926
                {
927
                    //Master re-transmits message to all others
927
                    //Master re-transmits message to all others
928
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
928
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
929
                        if (i != other)
929
                        if (i != other)
930
                            sendpacket(i,packbuf,packbufleng);
930
                            sendpacket(i,packbuf,packbufleng);
931
                }
931
                }
932
932
933
                switch (packbuf[1])
933
                switch (packbuf[1])
934
                {
934
                {
935
                case 0:
935
                case 0:
936
                    if (voting == myconnectindex && g_player[(unsigned char)packbuf[2]].gotvote == 0)
936
                    if (voting == myconnectindex && g_player[(unsigned char)packbuf[2]].gotvote == 0)
937
                    {
937
                    {
938
                        g_player[(unsigned char)packbuf[2]].gotvote = 1;
938
                        g_player[(unsigned char)packbuf[2]].gotvote = 1;
939
                        g_player[(unsigned char)packbuf[2]].vote = packbuf[3];
939
                        g_player[(unsigned char)packbuf[2]].vote = packbuf[3];
940
                        Bsprintf(tempbuf,"GOT VOTE FROM %s",g_player[(unsigned char)packbuf[2]].user_name);
940
                        Bsprintf(tempbuf,"GOT VOTE FROM %s",g_player[(unsigned char)packbuf[2]].user_name);
941
                        adduserquote(tempbuf);
941
                        adduserquote(tempbuf);
942
                    }
942
                    }
943
                    break;
943
                    break;
944
944
945
                case 1: // call map vote
945
                case 1: // call map vote
946
                    voting = packbuf[2];
946
                    voting = packbuf[2];
947
                    vote_episode = packbuf[3];
947
                    vote_episode = packbuf[3];
948
                    vote_map = packbuf[4];
948
                    vote_map = packbuf[4];
949
                    Bsprintf(tempbuf,"%s^00 HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)",g_player[(unsigned char)packbuf[2]].user_name,map[(unsigned char)(packbuf[3]*MAXLEVELS + packbuf[4])].name,packbuf[3]+1,packbuf[4]+1);
949
                    Bsprintf(tempbuf,"%s^00 HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)",g_player[(unsigned char)packbuf[2]].user_name,map[(unsigned char)(packbuf[3]*MAXLEVELS + packbuf[4])].name,packbuf[3]+1,packbuf[4]+1);
950
                    adduserquote(tempbuf);
950
                    adduserquote(tempbuf);
951
                    Bsprintf(tempbuf,"PRESS F1 TO VOTE YES, F2 TO VOTE NO");
951
                    Bsprintf(tempbuf,"PRESS F1 TO VOTE YES, F2 TO VOTE NO");
952
                    adduserquote(tempbuf);
952
                    adduserquote(tempbuf);
953
                    for (i=0;i<MAXPLAYERS;i++)
953
                    for (i=0;i<MAXPLAYERS;i++)
954
                    {
954
                    {
955
                        g_player[i].vote = 0;
955
                        g_player[i].vote = 0;
956
                        g_player[i].gotvote = 0;
956
                        g_player[i].gotvote = 0;
957
                    }
957
                    }
958
                    g_player[voting].gotvote = g_player[voting].vote = 1;
958
                    g_player[voting].gotvote = g_player[voting].vote = 1;
959
                    break;
959
                    break;
960
960
961
                case 2: // cancel map vote
961
                case 2: // cancel map vote
962
                    if (voting == packbuf[2])
962
                    if (voting == packbuf[2])
963
                    {
963
                    {
964
                        voting = -1;
964
                        voting = -1;
965
                        i = 0;
965
                        i = 0;
966
                        for (j=0;j<MAXPLAYERS;j++)
966
                        for (j=0;j<MAXPLAYERS;j++)
967
                            i += g_player[j].gotvote;
967
                            i += g_player[j].gotvote;
968
968
969
                        if (i != numplayers)
969
                        if (i != numplayers)
970
                            Bsprintf(tempbuf,"%s^00 HAS CANCELED THE VOTE",g_player[(unsigned char)packbuf[2]].user_name);
970
                            Bsprintf(tempbuf,"%s^00 HAS CANCELED THE VOTE",g_player[(unsigned char)packbuf[2]].user_name);
971
                        else Bsprintf(tempbuf,"VOTE FAILED");
971
                        else Bsprintf(tempbuf,"VOTE FAILED");
972
                        for (i=0;i<MAXPLAYERS;i++)
972
                        for (i=0;i<MAXPLAYERS;i++)
973
                        {
973
                        {
974
                            g_player[i].vote = 0;
974
                            g_player[i].vote = 0;
975
                            g_player[i].gotvote = 0;
975
                            g_player[i].gotvote = 0;
976
                        }
976
                        }
977
                        adduserquote(tempbuf);
977
                        adduserquote(tempbuf);
978
                    }
978
                    }
979
                    break;
979
                    break;
980
                }
980
                }
981
                break;
981
                break;
982
982
983
            case 126:
983
            case 126:
984
                //Slaves in M/S mode only send to master
984
                //Slaves in M/S mode only send to master
985
                //Master re-transmits message to all others
985
                //Master re-transmits message to all others
986
                if ((!networkmode) && (myconnectindex == connecthead))
986
                if ((!networkmode) && (myconnectindex == connecthead))
987
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
987
                    for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
988
                        if (i != other) sendpacket(i,packbuf,packbufleng);
988
                        if (i != other) sendpacket(i,packbuf,packbufleng);
989
989
990
                multiflag = 2;
990
                multiflag = 2;
991
                multiwhat = 0;
991
                multiwhat = 0;
992
                multiwho = packbuf[2]; //other: need to send in m/s mode because of possible re-transmit
992
                multiwho = packbuf[2]; //other: need to send in m/s mode because of possible re-transmit
993
                multipos = packbuf[1];
993
                multipos = packbuf[1];
994
                loadplayer(multipos);
994
                loadplayer(multipos);
995
                multiflag = 0;
995
                multiflag = 0;
996
                break;
996
                break;
997
            }
997
            }
998
            break;
998
            break;
999
        }
999
        }
1000
    }
1000
    }
1001
}
1001
}
1002
1002
1003
void faketimerhandler(void)
1003
void faketimerhandler(void)
1004
{
1004
{
1005
    int i, j, k;
1005
    int i, j, k;
1006
    //    short who;
1006
    //    short who;
1007
    input *osyn, *nsyn;
1007
    input *osyn, *nsyn;
1008
1008
1009
    if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
1009
    if (qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
1010
    {
1010
    {
1011
        qe = 1;
1011
        qe = 1;
1012
        gameexit("Quick Exit.");
1012
        gameexit("Quick Exit.");
1013
    }
1013
    }
1014
1014
1015
    sampletimer();
1015
    sampletimer();
1016
    AudioUpdate();
1016
    AudioUpdate();
1017
    if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return;
1017
    if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return;
1018
    ototalclock += TICSPERFRAME;
1018
    ototalclock += TICSPERFRAME;
1019
1019
1020
    getpackets();
1020
    getpackets();
1021
    if (getoutputcirclesize() >= 16) return;
1021
    if (getoutputcirclesize() >= 16) return;
1022
1022
1023
    for (i=connecthead;i>=0;i=connectpoint2[i])
1023
    for (i=connecthead;i>=0;i=connectpoint2[i])
1024
        if (i != myconnectindex)
1024
        if (i != myconnectindex)
1025
            if (g_player[i].movefifoend < g_player[myconnectindex].movefifoend-200) return;
1025
            if (g_player[i].movefifoend < g_player[myconnectindex].movefifoend-200) return;
1026
1026
1027
    getinput(myconnectindex);
1027
    getinput(myconnectindex);
1028
1028
1029
    avgfvel += loc.fvel;
1029
    avgfvel += loc.fvel;
1030
    avgsvel += loc.svel;
1030
    avgsvel += loc.svel;
1031
    avgavel += loc.avel;
1031
    avgavel += loc.avel;
1032
    avghorz += loc.horz;
1032
    avghorz += loc.horz;
1033
    avgbits |= loc.bits;
1033
    avgbits |= loc.bits;
1034
    avgextbits |= loc.extbits;
1034
    avgextbits |= loc.extbits;
1035
    if (g_player[myconnectindex].movefifoend&(movesperpacket-1))
1035
    if (g_player[myconnectindex].movefifoend&(movesperpacket-1))
1036
    {
1036
    {
1037
        copybufbyte(&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex],
1037
        copybufbyte(&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex],
1038
                    &inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex],sizeof(input));
1038
                    &inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex],sizeof(input));
1039
        g_player[myconnectindex].movefifoend++;
1039
        g_player[myconnectindex].movefifoend++;
1040
        return;
1040
        return;
1041
    }
1041
    }
1042
    nsyn = &inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex];
1042
    nsyn = &inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex];
1043
    nsyn[0].fvel = avgfvel/movesperpacket;
1043
    nsyn[0].fvel = avgfvel/movesperpacket;
1044
    nsyn[0].svel = avgsvel/movesperpacket;
1044
    nsyn[0].svel = avgsvel/movesperpacket;
1045
    nsyn[0].avel = avgavel/movesperpacket;
1045
    nsyn[0].avel = avgavel/movesperpacket;
1046
    nsyn[0].horz = avghorz/movesperpacket;
1046
    nsyn[0].horz = avghorz/movesperpacket;
1047
    nsyn[0].bits = avgbits;
1047
    nsyn[0].bits = avgbits;
1048
    nsyn[0].extbits = avgextbits;
1048
    nsyn[0].extbits = avgextbits;
1049
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
1049
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
1050
    g_player[myconnectindex].movefifoend++;
1050
    g_player[myconnectindex].movefifoend++;
1051
1051
1052
    if (numplayers < 2)
1052
    if (numplayers < 2)
1053
    {
1053
    {
1054
        if (ud.multimode > 1) for (i=connecthead;i>=0;i=connectpoint2[i])
1054
        if (ud.multimode > 1) for (i=connecthead;i>=0;i=connectpoint2[i])
1055
                if (i != myconnectindex)
1055
                if (i != myconnectindex)
1056
                {
1056
                {
1057
                    //clearbufbyte(&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input),0L);
1057
                    //clearbufbyte(&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i],sizeof(input),0L);
1058
                    if (ud.playerai)
1058
                    if (ud.playerai)
1059
                        computergetinput(i,&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i]);
1059
                        computergetinput(i,&inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i]);
1060
                    inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i].svel++;
1060
                    inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i].svel++;
1061
                    inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i].fvel++;
1061
                    inputfifo[g_player[i].movefifoend&(MOVEFIFOSIZ-1)][i].fvel++;
1062
                    g_player[i].movefifoend++;
1062
                    g_player[i].movefifoend++;
1063
                }
1063
                }
1064
        return;
1064
        return;
1065
    }
1065
    }
1066
1066
1067
    for (i=connecthead;i>=0;i=connectpoint2[i])
1067
    for (i=connecthead;i>=0;i=connectpoint2[i])
1068
        if (i != myconnectindex)
1068
        if (i != myconnectindex)
1069
        {
1069
        {
1070
            k = (g_player[myconnectindex].movefifoend-1)-g_player[i].movefifoend;
1070
            k = (g_player[myconnectindex].movefifoend-1)-g_player[i].movefifoend;
1071
            g_player[i].myminlag = min(g_player[i].myminlag,k);
1071
            g_player[i].myminlag = min(g_player[i].myminlag,k);
1072
            mymaxlag = max(mymaxlag,k);
1072
            mymaxlag = max(mymaxlag,k);
1073
        }
1073
        }
1074
1074
1075
    if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1075
    if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1076
    {
1076
    {
1077
        i = mymaxlag-bufferjitter;
1077
        i = mymaxlag-bufferjitter;
1078
        mymaxlag = 0;
1078
        mymaxlag = 0;
1079
        if (i > 0) bufferjitter += ((3+i)>>2);
1079
        if (i > 0) bufferjitter += ((3+i)>>2);
1080
        else if (i < 0) bufferjitter -= ((1-i)>>2);
1080
        else if (i < 0) bufferjitter -= ((1-i)>>2);
1081
    }
1081
    }
1082
1082
1083
    if (networkmode == 1)
1083
    if (networkmode == 1)
1084
    {
1084
    {
1085
        packbuf[0] = 17;
1085
        packbuf[0] = 17;
1086
        if ((g_player[myconnectindex].movefifoend-1) == 0) packbuf[0] = 16;
1086
        if ((g_player[myconnectindex].movefifoend-1) == 0) packbuf[0] = 16;
1087
        j = 1;
1087
        j = 1;
1088
1088
1089
        //Fix timers and buffer/jitter value
1089
        //Fix timers and buffer/jitter value
1090
        if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1090
        if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1091
        {
1091
        {
1092
            if (myconnectindex != connecthead)
1092
            if (myconnectindex != connecthead)
1093
            {
1093
            {
1094
                i = g_player[connecthead].myminlag-otherminlag;
1094
                i = g_player[connecthead].myminlag-otherminlag;
1095
                if (klabs(i) > 8) i >>= 1;
1095
                if (klabs(i) > 8) i >>= 1;
1096
                else if (klabs(i) > 2) i = ksgn(i);
1096
                else if (klabs(i) > 2) i = ksgn(i);
1097
                else i = 0;
1097
                else i = 0;
1098
1098
1099
                totalclock -= TICSPERFRAME*i;
1099
                totalclock -= TICSPERFRAME*i;
1100
                g_player[connecthead].myminlag -= i;
1100
                g_player[connecthead].myminlag -= i;
1101
                otherminlag += i;
1101
                otherminlag += i;
1102
            }
1102
            }
1103
1103
1104
            if (myconnectindex == connecthead)
1104
            if (myconnectindex == connecthead)
1105
                for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1105
                for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1106
                    packbuf[j++] = min(max(g_player[i].myminlag,-128),127);
1106
                    packbuf[j++] = min(max(g_player[i].myminlag,-128),127);
1107
1107
1108
            for (i=connecthead;i>=0;i=connectpoint2[i])
1108
            for (i=connecthead;i>=0;i=connectpoint2[i])
1109
                g_player[i].myminlag = 0x7fffffff;
1109
                g_player[i].myminlag = 0x7fffffff;
1110
        }
1110
        }
1111
1111
1112
        osyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-2)&(MOVEFIFOSIZ-1)][myconnectindex];
1112
        osyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-2)&(MOVEFIFOSIZ-1)][myconnectindex];
1113
        nsyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex];
1113
        nsyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex];
1114
1114
1115
        k = j;
1115
        k = j;
1116
        packbuf[j++] = 0;
1116
        packbuf[j++] = 0;
1117
        packbuf[j++] = 0;
1117
        packbuf[j++] = 0;
1118
1118
1119
        if (nsyn[0].fvel != osyn[0].fvel)
1119
        if (nsyn[0].fvel != osyn[0].fvel)
1120
        {
1120
        {
1121
            packbuf[j++] = (char)nsyn[0].fvel;
1121
            packbuf[j++] = (char)nsyn[0].fvel;
1122
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
1122
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
1123
            packbuf[k] |= 1;
1123
            packbuf[k] |= 1;
1124
        }
1124
        }
1125
        if (nsyn[0].svel != osyn[0].svel)
1125
        if (nsyn[0].svel != osyn[0].svel)
1126
        {
1126
        {
1127
            packbuf[j++] = (char)nsyn[0].svel;
1127
            packbuf[j++] = (char)nsyn[0].svel;
1128
            packbuf[j++] = (char)(nsyn[0].svel>>8);
1128
            packbuf[j++] = (char)(nsyn[0].svel>>8);
1129
            packbuf[k] |= 2;
1129
            packbuf[k] |= 2;
1130
        }
1130
        }
1131
        if (nsyn[0].avel != osyn[0].avel)
1131
        if (nsyn[0].avel != osyn[0].avel)
1132
        {
1132
        {
1133
            packbuf[j++] = (signed char)nsyn[0].avel;
1133
            packbuf[j++] = (signed char)nsyn[0].avel;
1134
            packbuf[k] |= 4;
1134
            packbuf[k] |= 4;
1135
        }
1135
        }
1136
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[k] |= 8;
1136
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[k] |= 8;
1137
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[k] |= 16;
1137
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[k] |= 16;
1138
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[k] |= 32;
1138
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[k] |= 32;
1139
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[k] |= 64;
1139
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[k] |= 64;
1140
        if (nsyn[0].horz != osyn[0].horz)
1140
        if (nsyn[0].horz != osyn[0].horz)
1141
        {
1141
        {
1142
            packbuf[j++] = (char)nsyn[0].horz;
1142
            packbuf[j++] = (char)nsyn[0].horz;
1143
            packbuf[k] |= 128;
1143
            packbuf[k] |= 128;
1144
        }
1144
        }
1145
//        k++;
1145
//        k++;
1146
        packbuf[++k] = 0;
1146
        packbuf[++k] = 0;
1147
        if ((nsyn[0].extbits^osyn[0].extbits)&0x000000ff) packbuf[j++] = (nsyn[0].extbits&255), packbuf[k] |= 1;
1147
        if ((nsyn[0].extbits^osyn[0].extbits)&0x000000ff) packbuf[j++] = (nsyn[0].extbits&255), packbuf[k] |= 1;
1148
        if ((nsyn[0].extbits^osyn[0].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[0].extbits>>8)&255), packbuf[k] |= 2;
1148
        if ((nsyn[0].extbits^osyn[0].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[0].extbits>>8)&255), packbuf[k] |= 2;
1149
        if ((nsyn[0].extbits^osyn[0].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[0].extbits>>16)&255), packbuf[k] |= 4;
1149
        if ((nsyn[0].extbits^osyn[0].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[0].extbits>>16)&255), packbuf[k] |= 4;
1150
        if ((nsyn[0].extbits^osyn[0].extbits)&0xff000000) packbuf[j++] = ((nsyn[0].extbits>>24)&255), packbuf[k] |= 8;
1150
        if ((nsyn[0].extbits^osyn[0].extbits)&0xff000000) packbuf[j++] = ((nsyn[0].extbits>>24)&255), packbuf[k] |= 8;
1151
1151
1152
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1152
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1153
        {
1153
        {
1154
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1154
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1155
            syncvaltail++;
1155
            syncvaltail++;
1156
        }
1156
        }
1157
1157
1158
        for (i=connecthead;i>=0;i=connectpoint2[i])
1158
        for (i=connecthead;i>=0;i=connectpoint2[i])
1159
            if (i != myconnectindex)
1159
            if (i != myconnectindex)
1160
                sendpacket(i,packbuf,j);
1160
                sendpacket(i,packbuf,j);
1161
1161
1162
        return;
1162
        return;
1163
    }
1163
    }
1164
    if (myconnectindex != connecthead)   //Slave
1164
    if (myconnectindex != connecthead)   //Slave
1165
    {
1165
    {
1166
        //Fix timers and buffer/jitter value
1166
        //Fix timers and buffer/jitter value
1167
        if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1167
        if (((g_player[myconnectindex].movefifoend-1)&(TIMERUPDATESIZ-1)) == 0)
1168
        {
1168
        {
1169
            i = g_player[connecthead].myminlag-otherminlag;
1169
            i = g_player[connecthead].myminlag-otherminlag;
1170
            if (klabs(i) > 8) i >>= 1;
1170
            if (klabs(i) > 8) i >>= 1;
1171
            else if (klabs(i) > 2) i = ksgn(i);
1171
            else if (klabs(i) > 2) i = ksgn(i);
1172
            else i = 0;
1172
            else i = 0;
1173
1173
1174
            totalclock -= TICSPERFRAME*i;
1174
            totalclock -= TICSPERFRAME*i;
1175
            g_player[connecthead].myminlag -= i;
1175
            g_player[connecthead].myminlag -= i;
1176
            otherminlag += i;
1176
            otherminlag += i;
1177
1177
1178
            for (i=connecthead;i>=0;i=connectpoint2[i])
1178
            for (i=connecthead;i>=0;i=connectpoint2[i])
1179
                g_player[i].myminlag = 0x7fffffff;
1179
                g_player[i].myminlag = 0x7fffffff;
1180
        }
1180
        }
1181
1181
1182
        packbuf[0] = 1;
1182
        packbuf[0] = 1;
1183
        packbuf[1] = 0;
1183
        packbuf[1] = 0;
1184
        packbuf[2] = 0;
1184
        packbuf[2] = 0;
1185
        j = 3;
1185
        j = 3;
1186
1186
1187
        osyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-2)&(MOVEFIFOSIZ-1)][myconnectindex];
1187
        osyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-2)&(MOVEFIFOSIZ-1)][myconnectindex];
1188
        nsyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex];
1188
        nsyn = (input *)&inputfifo[(g_player[myconnectindex].movefifoend-1)&(MOVEFIFOSIZ-1)][myconnectindex];
1189
1189
1190
        if (nsyn[0].fvel != osyn[0].fvel)
1190
        if (nsyn[0].fvel != osyn[0].fvel)
1191
        {
1191
        {
1192
            packbuf[j++] = (char)nsyn[0].fvel;
1192
            packbuf[j++] = (char)nsyn[0].fvel;
1193
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
1193
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
1194
            packbuf[1] |= 1;
1194
            packbuf[1] |= 1;
1195
        }
1195
        }
1196
        if (nsyn[0].svel != osyn[0].svel)
1196
        if (nsyn[0].svel != osyn[0].svel)
1197
        {
1197
        {
1198
            packbuf[j++] = (char)nsyn[0].svel;
1198
            packbuf[j++] = (char)nsyn[0].svel;
1199
            packbuf[j++] = (char)(nsyn[0].svel>>8);
1199
            packbuf[j++] = (char)(nsyn[0].svel>>8);
1200
            packbuf[1] |= 2;
1200
            packbuf[1] |= 2;
1201
        }
1201
        }
1202
        if (nsyn[0].avel != osyn[0].avel)
1202
        if (nsyn[0].avel != osyn[0].avel)
1203
        {
1203
        {
1204
            packbuf[j++] = (signed char)nsyn[0].avel;
1204
            packbuf[j++] = (signed char)nsyn[0].avel;
1205
            packbuf[1] |= 4;
1205
            packbuf[1] |= 4;
1206
        }
1206
        }
1207
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[1] |= 8;
1207
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[1] |= 8;
1208
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[1] |= 16;
1208
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[1] |= 16;
1209
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[1] |= 32;
1209
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[1] |= 32;
1210
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[1] |= 64;
1210
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[1] |= 64;
1211
        if (nsyn[0].horz != osyn[0].horz)
1211
        if (nsyn[0].horz != osyn[0].horz)
1212
        {
1212
        {
1213
            packbuf[j++] = (char)nsyn[0].horz;
1213
            packbuf[j++] = (char)nsyn[0].horz;
1214
            packbuf[1] |= 128;
1214
            packbuf[1] |= 128;
1215
        }
1215
        }
1216
        packbuf[2] = 0;
1216
        packbuf[2] = 0;
1217
        if ((nsyn[0].extbits^osyn[0].extbits)&0x000000ff) packbuf[j++] = (nsyn[0].extbits&255), packbuf[2] |= 1;
1217
        if ((nsyn[0].extbits^osyn[0].extbits)&0x000000ff) packbuf[j++] = (nsyn[0].extbits&255), packbuf[2] |= 1;
1218
        if ((nsyn[0].extbits^osyn[0].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[0].extbits>>8)&255), packbuf[2] |= 2;
1218
        if ((nsyn[0].extbits^osyn[0].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[0].extbits>>8)&255), packbuf[2] |= 2;
1219
        if ((nsyn[0].extbits^osyn[0].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[0].extbits>>16)&255), packbuf[2] |= 4;
1219
        if ((nsyn[0].extbits^osyn[0].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[0].extbits>>16)&255), packbuf[2] |= 4;
1220
        if ((nsyn[0].extbits^osyn[0].extbits)&0xff000000) packbuf[j++] = ((nsyn[0].extbits>>24)&255), packbuf[2] |= 8;
1220
        if ((nsyn[0].extbits^osyn[0].extbits)&0xff000000) packbuf[j++] = ((nsyn[0].extbits>>24)&255), packbuf[2] |= 8;
1221
1221
1222
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1222
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1223
        {
1223
        {
1224
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1224
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1225
            syncvaltail++;
1225
            syncvaltail++;
1226
        }
1226
        }
1227
1227
1228
        sendpacket(connecthead,packbuf,j);
1228
        sendpacket(connecthead,packbuf,j);
1229
        return;
1229
        return;
1230
    }
1230
    }
1231
1231
1232
    //This allows allow packet resends
1232
    //This allows allow packet resends
1233
    for (i=connecthead;i>=0;i=connectpoint2[i])
1233
    for (i=connecthead;i>=0;i=connectpoint2[i])
1234
        if (g_player[i].movefifoend <= movefifosendplc)
1234
        if (g_player[i].movefifoend <= movefifosendplc)
1235
        {
1235
        {
1236
            packbuf[0] = 127;
1236
            packbuf[0] = 127;
1237
            for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1237
            for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1238
                sendpacket(i,packbuf,1);
1238
                sendpacket(i,packbuf,1);
1239
            return;
1239
            return;
1240
        }
1240
        }
1241
1241
1242
    while (1)  //Master
1242
    while (1)  //Master
1243
    {
1243
    {
1244
        for (i=connecthead;i>=0;i=connectpoint2[i])
1244
        for (i=connecthead;i>=0;i=connectpoint2[i])
1245
            if (g_player[i].playerquitflag && (g_player[i].movefifoend <= movefifosendplc)) return;
1245
            if (g_player[i].playerquitflag && (g_player[i].movefifoend <= movefifosendplc)) return;
1246
1246
1247
        osyn = (input *)&inputfifo[(movefifosendplc-1)&(MOVEFIFOSIZ-1)][0];
1247
        osyn = (input *)&inputfifo[(movefifosendplc-1)&(MOVEFIFOSIZ-1)][0];
1248
        nsyn = (input *)&inputfifo[(movefifosendplc)&(MOVEFIFOSIZ-1)][0];
1248
        nsyn = (input *)&inputfifo[(movefifosendplc)&(MOVEFIFOSIZ-1)][0];
1249
1249
1250
        //MASTER -> SLAVE packet
1250
        //MASTER -> SLAVE packet
1251
        packbuf[0] = 0;
1251
        packbuf[0] = 0;
1252
        j = 1;
1252
        j = 1;
1253
1253
1254
        //Fix timers and buffer/jitter value
1254
        //Fix timers and buffer/jitter value
1255
        if ((movefifosendplc&(TIMERUPDATESIZ-1)) == 0)
1255
        if ((movefifosendplc&(TIMERUPDATESIZ-1)) == 0)
1256
        {
1256
        {
1257
            for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1257
            for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1258
                if (g_player[i].playerquitflag)
1258
                if (g_player[i].playerquitflag)
1259
                    packbuf[j++] = min(max(g_player[i].myminlag,-128),127);
1259
                    packbuf[j++] = min(max(g_player[i].myminlag,-128),127);
1260
1260
1261
            for (i=connecthead;i>=0;i=connectpoint2[i])
1261
            for (i=connecthead;i>=0;i=connectpoint2[i])
1262
                g_player[i].myminlag = 0x7fffffff;
1262
                g_player[i].myminlag = 0x7fffffff;
1263
        }
1263
        }
1264
1264
1265
        k = j;
1265
        k = j;
1266
        for (i=connecthead;i>=0;i=connectpoint2[i])
1266
        for (i=connecthead;i>=0;i=connectpoint2[i])
1267
            j += g_player[i].playerquitflag + g_player[i].playerquitflag;
1267
            j += g_player[i].playerquitflag + g_player[i].playerquitflag;
1268
        for (i=connecthead;i>=0;i=connectpoint2[i])
1268
        for (i=connecthead;i>=0;i=connectpoint2[i])
1269
        {
1269
        {
1270
            if (g_player[i].playerquitflag == 0) continue;
1270
            if (g_player[i].playerquitflag == 0) continue;
1271
1271
1272
            packbuf[k] = 0;
1272
            packbuf[k] = 0;
1273
            if (nsyn[i].fvel != osyn[i].fvel)
1273
            if (nsyn[i].fvel != osyn[i].fvel)
1274
            {
1274
            {
1275
                packbuf[j++] = (char)nsyn[i].fvel;
1275
                packbuf[j++] = (char)nsyn[i].fvel;
1276
                packbuf[j++] = (char)(nsyn[i].fvel>>8);
1276
                packbuf[j++] = (char)(nsyn[i].fvel>>8);
1277
                packbuf[k] |= 1;
1277
                packbuf[k] |= 1;
1278
            }
1278
            }
1279
            if (nsyn[i].svel != osyn[i].svel)
1279
            if (nsyn[i].svel != osyn[i].svel)
1280
            {
1280
            {
1281
                packbuf[j++] = (char)nsyn[i].svel;
1281
                packbuf[j++] = (char)nsyn[i].svel;
1282
                packbuf[j++] = (char)(nsyn[i].svel>>8);
1282
                packbuf[j++] = (char)(nsyn[i].svel>>8);
1283
                packbuf[k] |= 2;
1283
                packbuf[k] |= 2;
1284
            }
1284
            }
1285
            if (nsyn[i].avel != osyn[i].avel)
1285
            if (nsyn[i].avel != osyn[i].avel)
1286
            {
1286
            {
1287
                packbuf[j++] = (signed char)nsyn[i].avel;
1287
                packbuf[j++] = (signed char)nsyn[i].avel;
1288
                packbuf[k] |= 4;
1288
                packbuf[k] |= 4;
1289
            }
1289
            }
1290
            if ((nsyn[i].bits^osyn[i].bits)&0x000000ff) packbuf[j++] = (nsyn[i].bits&255), packbuf[k] |= 8;
1290
            if ((nsyn[i].bits^osyn[i].bits)&0x000000ff) packbuf[j++] = (nsyn[i].bits&255), packbuf[k] |= 8;
1291
            if ((nsyn[i].bits^osyn[i].bits)&0x0000ff00) packbuf[j++] = ((nsyn[i].bits>>8)&255), packbuf[k] |= 16;
1291
            if ((nsyn[i].bits^osyn[i].bits)&0x0000ff00) packbuf[j++] = ((nsyn[i].bits>>8)&255), packbuf[k] |= 16;
1292
            if ((nsyn[i].bits^osyn[i].bits)&0x00ff0000) packbuf[j++] = ((nsyn[i].bits>>16)&255), packbuf[k] |= 32;
1292
            if ((nsyn[i].bits^osyn[i].bits)&0x00ff0000) packbuf[j++] = ((nsyn[i].bits>>16)&255), packbuf[k] |= 32;
1293
            if ((nsyn[i].bits^osyn[i].bits)&0xff000000) packbuf[j++] = ((nsyn[i].bits>>24)&255), packbuf[k] |= 64;
1293
            if ((nsyn[i].bits^osyn[i].bits)&0xff000000) packbuf[j++] = ((nsyn[i].bits>>24)&255), packbuf[k] |= 64;
1294
            if (nsyn[i].horz != osyn[i].horz)
1294
            if (nsyn[i].horz != osyn[i].horz)
1295
            {
1295
            {
1296
                packbuf[j++] = (char)nsyn[i].horz;
1296
                packbuf[j++] = (char)nsyn[i].horz;
1297
                packbuf[k] |= 128;
1297
                packbuf[k] |= 128;
1298
            }
1298
            }
1299
            k++;
1299
            k++;
1300
            packbuf[k] = 0;
1300
            packbuf[k] = 0;
1301
            if ((nsyn[i].extbits^osyn[i].extbits)&0x000000ff) packbuf[j++] = (nsyn[i].extbits&255), packbuf[k] |= 1;
1301
            if ((nsyn[i].extbits^osyn[i].extbits)&0x000000ff) packbuf[j++] = (nsyn[i].extbits&255), packbuf[k] |= 1;
1302
            if ((nsyn[i].extbits^osyn[i].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[i].extbits>>8)&255), packbuf[k] |= 2;
1302
            if ((nsyn[i].extbits^osyn[i].extbits)&0x0000ff00) packbuf[j++] = ((nsyn[i].extbits>>8)&255), packbuf[k] |= 2;
1303
            if ((nsyn[i].extbits^osyn[i].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[i].extbits>>16)&255), packbuf[k] |= 4;
1303
            if ((nsyn[i].extbits^osyn[i].extbits)&0x00ff0000) packbuf[j++] = ((nsyn[i].extbits>>16)&255), packbuf[k] |= 4;
1304
            if ((nsyn[i].extbits^osyn[i].extbits)&0xff000000) packbuf[j++] = ((nsyn[i].extbits>>24)&255), packbuf[k] |= 8;
1304
            if ((nsyn[i].extbits^osyn[i].extbits)&0xff000000) packbuf[j++] = ((nsyn[i].extbits>>24)&255), packbuf[k] |= 8;
1305
            k++;
1305
            k++;
1306
        }
1306
        }
1307
1307
1308
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1308
        while (g_player[myconnectindex].syncvalhead != syncvaltail)
1309
        {
1309
        {
1310
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1310
            packbuf[j++] = g_player[myconnectindex].syncval[syncvaltail&(MOVEFIFOSIZ-1)];
1311
            syncvaltail++;
1311
            syncvaltail++;
1312
        }
1312
        }
1313
1313
1314
        for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1314
        for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1315
            if (g_player[i].playerquitflag)
1315
            if (g_player[i].playerquitflag)
1316
            {
1316
            {
1317
                sendpacket(i,packbuf,j);
1317
                sendpacket(i,packbuf,j);
1318
                if (nsyn[i].bits&(1<<26))
1318
                if (nsyn[i].bits&(1<<26))
1319
                    g_player[i].playerquitflag = 0;
1319
                    g_player[i].playerquitflag = 0;
1320
            }
1320
            }
1321
1321
1322
        movefifosendplc += movesperpacket;
1322
        movefifosendplc += movesperpacket;
1323
    }
1323
    }
1324
}
1324
}
1325
1325
1326
extern int cacnum;
1326
extern int cacnum;
1327
typedef struct
1327
typedef struct
1328
{
1328
{
1329
    int *hand, leng;
1329
    int *hand, leng;
1330
    char *lock ;
1330
    char *lock ;
1331
}
1331
}
1332
cactype;
1332
cactype;
1333
extern cactype cac[];
1333
extern cactype cac[];
1334
1334
1335
static void caches(void)
1335
static void caches(void)
1336
{
1336
{
1337
    short i,k;
1337
    short i,k;
1338
1338
1339
    k = 0;
1339
    k = 0;
1340
    for (i=0;i<cacnum;i++)
1340
    for (i=0;i<cacnum;i++)
1341
        if ((*cac[i].lock) >= 200)
1341
        if ((*cac[i].lock) >= 200)
1342
        {
1342
        {
1343
            Bsprintf(tempbuf,"Locked- %d: Leng:%d, Lock:%d",i,cac[i].leng,*cac[i].lock);
1343
            Bsprintf(tempbuf,"Locked- %d: Leng:%d, Lock:%d",i,cac[i].leng,*cac[i].lock);
1344
            printext256(0L,k,31,-1,tempbuf,1);
1344
            printext256(0L,k,31,-1,tempbuf,1);
1345
            k +=