Subversion Repositories eduke32

Rev

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

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

872

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

877

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

880

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

883

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

886

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

889

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