Subversion Repositories eduke32

Rev

Rev 793 | Rev 855 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 793 Rev 841
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 "osd.h"
26
#include "osd.h"
27
27
28
#ifdef RENDERTYPEWIN
28
#ifdef RENDERTYPEWIN
29
#define WIN32_LEAN_AND_MEAN
29
#define WIN32_LEAN_AND_MEAN
30
#include <windows.h>
30
#include <windows.h>
31
#endif
31
#endif
32
32
33
extern char pow2char[];
33
extern char pow2char[];
34
34
35
extern int everyothertime;
35
extern int everyothertime;
36
static int which_palookup = 9;
36
static int which_palookup = 9;
37
int g_NumPalettes;
37
int g_NumPalettes;
38
short spritecache[MAXTILES][3];
38
short spritecache[MAXTILES][3];
39
39
40
static char precachehightile[2][MAXTILES>>3];
40
static char precachehightile[2][MAXTILES>>3];
41
static int  precachecount;
41
static int  precachecount;
42
42
43
static void tloadtile(int tilenume, int type)
43
static void tloadtile(int tilenume, int type)
44
{
44
{
45
    if ((picanm[tilenume]&63) < 1)
45
    if ((picanm[tilenume]&63) < 1)
46
    {
46
    {
47
        if (!(gotpic[tilenume>>3] & pow2char[tilenume&7])) precachecount++;
47
        if (!(gotpic[tilenume>>3] & pow2char[tilenume&7])) precachecount++;
48
        gotpic[tilenume>>3] |= pow2char[tilenume&7];
48
        gotpic[tilenume>>3] |= pow2char[tilenume&7];
49
        precachehightile[(unsigned char)type][tilenume>>3] |= pow2char[tilenume&7];
49
        precachehightile[(unsigned char)type][tilenume>>3] |= pow2char[tilenume&7];
50
        return;
50
        return;
51
    }
51
    }
52
52
53
    {
53
    {
54
        int i,j;
54
        int i,j;
55
55
56
        if ((picanm[tilenume]&192)==192)
56
        if ((picanm[tilenume]&192)==192)
57
        {
57
        {
58
            i = tilenume - (picanm[tilenume]&63);
58
            i = tilenume - (picanm[tilenume]&63);
59
            j = tilenume;
59
            j = tilenume;
60
        }
60
        }
61
        else
61
        else
62
        {
62
        {
63
            i = tilenume;
63
            i = tilenume;
64
            j = tilenume + (picanm[tilenume]&63);
64
            j = tilenume + (picanm[tilenume]&63);
65
        }
65
        }
66
        for (;i<=j;i++)
66
        for (;i<=j;i++)
67
        {
67
        {
68
            if (!(gotpic[i>>3] & pow2char[i&7])) precachecount++;
68
            if (!(gotpic[i>>3] & pow2char[i&7])) precachecount++;
69
            gotpic[i>>3] |= pow2char[i&7];
69
            gotpic[i>>3] |= pow2char[i&7];
70
            precachehightile[(unsigned char)type][i>>3] |= pow2char[i&7];
70
            precachehightile[(unsigned char)type][i>>3] |= pow2char[i&7];
71
        }
71
        }
72
    }
72
    }
73
}
73
}
74
74
75
static void cachespritenum(int i)
75
static void cachespritenum(int i)
76
{
76
{
77
    char maxc;
77
    char maxc;
78
    int j;
78
    int j;
79
79
80
    if (ud.monsters_off && badguy(&sprite[i])) return;
80
    if (ud.monsters_off && badguy(&sprite[i])) return;
81
81
82
    maxc = 1;
82
    maxc = 1;
83
83
84
    if (spritecache[PN][0] == PN)
84
    if (spritecache[PN][0] == PN)
85
        for (j = PN; j <= spritecache[PN][1]; j++)
85
        for (j = PN; j <= spritecache[PN][1]; j++)
86
            tloadtile(j,1);
86
            tloadtile(j,1);
87
87
88
    switch (dynamictostatic[PN])
88
    switch (dynamictostatic[PN])
89
    {
89
    {
90
    case HYDRENT__STATIC:
90
    case HYDRENT__STATIC:
91
        tloadtile(BROKEFIREHYDRENT,1);
91
        tloadtile(BROKEFIREHYDRENT,1);
92
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
92
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
93
        break;
93
        break;
94
    case TOILET__STATIC:
94
    case TOILET__STATIC:
95
        tloadtile(TOILETBROKE,1);
95
        tloadtile(TOILETBROKE,1);
96
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
96
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
97
        break;
97
        break;
98
    case STALL__STATIC:
98
    case STALL__STATIC:
99
        tloadtile(STALLBROKE,1);
99
        tloadtile(STALLBROKE,1);
100
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
100
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
101
        break;
101
        break;
102
    case RUBBERCAN__STATIC:
102
    case RUBBERCAN__STATIC:
103
        maxc = 2;
103
        maxc = 2;
104
        break;
104
        break;
105
    case TOILETWATER__STATIC:
105
    case TOILETWATER__STATIC:
106
        maxc = 4;
106
        maxc = 4;
107
        break;
107
        break;
108
    case FEMPIC1__STATIC:
108
    case FEMPIC1__STATIC:
109
        maxc = 44;
109
        maxc = 44;
110
        break;
110
        break;
111
    case LIZTROOP__STATIC:
111
    case LIZTROOP__STATIC:
112
    case LIZTROOPRUNNING__STATIC:
112
    case LIZTROOPRUNNING__STATIC:
113
    case LIZTROOPSHOOT__STATIC:
113
    case LIZTROOPSHOOT__STATIC:
114
    case LIZTROOPJETPACK__STATIC:
114
    case LIZTROOPJETPACK__STATIC:
115
    case LIZTROOPONTOILET__STATIC:
115
    case LIZTROOPONTOILET__STATIC:
116
    case LIZTROOPDUCKING__STATIC:
116
    case LIZTROOPDUCKING__STATIC:
117
        for (j = LIZTROOP; j < (LIZTROOP+72); j++) tloadtile(j,1);
117
        for (j = LIZTROOP; j < (LIZTROOP+72); j++) tloadtile(j,1);
118
        for (j=HEADJIB1;j<LEGJIB1+3;j++) tloadtile(j,1);
118
        for (j=HEADJIB1;j<LEGJIB1+3;j++) tloadtile(j,1);
119
        maxc = 0;
119
        maxc = 0;
120
        break;
120
        break;
121
    case WOODENHORSE__STATIC:
121
    case WOODENHORSE__STATIC:
122
        maxc = 5;
122
        maxc = 5;
123
        for (j = HORSEONSIDE; j < (HORSEONSIDE+4); j++) tloadtile(j,1);
123
        for (j = HORSEONSIDE; j < (HORSEONSIDE+4); j++) tloadtile(j,1);
124
        break;
124
        break;
125
    case NEWBEAST__STATIC:
125
    case NEWBEAST__STATIC:
126
    case NEWBEASTSTAYPUT__STATIC:
126
    case NEWBEASTSTAYPUT__STATIC:
127
        maxc = 90;
127
        maxc = 90;
128
        break;
128
        break;
129
    case BOSS1__STATIC:
129
    case BOSS1__STATIC:
130
    case BOSS2__STATIC:
130
    case BOSS2__STATIC:
131
    case BOSS3__STATIC:
131
    case BOSS3__STATIC:
132
        maxc = 30;
132
        maxc = 30;
133
        break;
133
        break;
134
    case OCTABRAIN__STATIC:
134
    case OCTABRAIN__STATIC:
135
    case OCTABRAINSTAYPUT__STATIC:
135
    case OCTABRAINSTAYPUT__STATIC:
136
    case COMMANDER__STATIC:
136
    case COMMANDER__STATIC:
137
    case COMMANDERSTAYPUT__STATIC:
137
    case COMMANDERSTAYPUT__STATIC:
138
        maxc = 38;
138
        maxc = 38;
139
        break;
139
        break;
140
    case RECON__STATIC:
140
    case RECON__STATIC:
141
        maxc = 13;
141
        maxc = 13;
142
        break;
142
        break;
143
    case PIGCOP__STATIC:
143
    case PIGCOP__STATIC:
144
    case PIGCOPDIVE__STATIC:
144
    case PIGCOPDIVE__STATIC:
145
        maxc = 61;
145
        maxc = 61;
146
        break;
146
        break;
147
    case SHARK__STATIC:
147
    case SHARK__STATIC:
148
        maxc = 30;
148
        maxc = 30;
149
        break;
149
        break;
150
    case LIZMAN__STATIC:
150
    case LIZMAN__STATIC:
151
    case LIZMANSPITTING__STATIC:
151
    case LIZMANSPITTING__STATIC:
152
    case LIZMANFEEDING__STATIC:
152
    case LIZMANFEEDING__STATIC:
153
    case LIZMANJUMP__STATIC:
153
    case LIZMANJUMP__STATIC:
154
        for (j=LIZMANHEAD1;j<LIZMANLEG1+3;j++) tloadtile(j,1);
154
        for (j=LIZMANHEAD1;j<LIZMANLEG1+3;j++) tloadtile(j,1);
155
        maxc = 80;
155
        maxc = 80;
156
        break;
156
        break;
157
    case APLAYER__STATIC:
157
    case APLAYER__STATIC:
158
        maxc = 0;
158
        maxc = 0;
159
        if (ud.multimode > 1)
159
        if (ud.multimode > 1)
160
        {
160
        {
161
            maxc = 5;
161
            maxc = 5;
162
            for (j = 1420;j < 1420+106; j++) tloadtile(j,1);
162
            for (j = 1420;j < 1420+106; j++) tloadtile(j,1);
163
        }
163
        }
164
        break;
164
        break;
165
    case ATOMICHEALTH__STATIC:
165
    case ATOMICHEALTH__STATIC:
166
        maxc = 14;
166
        maxc = 14;
167
        break;
167
        break;
168
    case DRONE__STATIC:
168
    case DRONE__STATIC:
169
        maxc = 10;
169
        maxc = 10;
170
        break;
170
        break;
171
    case EXPLODINGBARREL__STATIC:
171
    case EXPLODINGBARREL__STATIC:
172
    case SEENINE__STATIC:
172
    case SEENINE__STATIC:
173
    case OOZFILTER__STATIC:
173
    case OOZFILTER__STATIC:
174
        maxc = 3;
174
        maxc = 3;
175
        break;
175
        break;
176
    case NUKEBARREL__STATIC:
176
    case NUKEBARREL__STATIC:
177
    case CAMERA1__STATIC:
177
    case CAMERA1__STATIC:
178
        maxc = 5;
178
        maxc = 5;
179
        break;
179
        break;
180
        // caching of HUD sprites for weapons that may be in the level
180
        // caching of HUD sprites for weapons that may be in the level
181
    case CHAINGUNSPRITE__STATIC:
181
    case CHAINGUNSPRITE__STATIC:
182
        for (j=CHAINGUN; j<=CHAINGUN+7; j++) tloadtile(j,1);
182
        for (j=CHAINGUN; j<=CHAINGUN+7; j++) tloadtile(j,1);
183
        break;
183
        break;
184
    case RPGSPRITE__STATIC:
184
    case RPGSPRITE__STATIC:
185
        for (j=RPGGUN; j<=RPGGUN+2; j++) tloadtile(j,1);
185
        for (j=RPGGUN; j<=RPGGUN+2; j++) tloadtile(j,1);
186
        break;
186
        break;
187
    case FREEZESPRITE__STATIC:
187
    case FREEZESPRITE__STATIC:
188
        for (j=FREEZE; j<=FREEZE+5; j++) tloadtile(j,1);
188
        for (j=FREEZE; j<=FREEZE+5; j++) tloadtile(j,1);
189
        break;
189
        break;
190
    case GROWSPRITEICON__STATIC:
190
    case GROWSPRITEICON__STATIC:
191
    case SHRINKERSPRITE__STATIC:
191
    case SHRINKERSPRITE__STATIC:
192
        for (j=SHRINKER-2; j<=SHRINKER+5; j++) tloadtile(j,1);
192
        for (j=SHRINKER-2; j<=SHRINKER+5; j++) tloadtile(j,1);
193
        break;
193
        break;
194
    case HBOMBAMMO__STATIC:
194
    case HBOMBAMMO__STATIC:
195
    case HEAVYHBOMB__STATIC:
195
    case HEAVYHBOMB__STATIC:
196
        for (j=HANDREMOTE; j<=HANDREMOTE+5; j++) tloadtile(j,1);
196
        for (j=HANDREMOTE; j<=HANDREMOTE+5; j++) tloadtile(j,1);
197
        break;
197
        break;
198
    case TRIPBOMBSPRITE__STATIC:
198
    case TRIPBOMBSPRITE__STATIC:
199
        for (j=HANDHOLDINGLASER; j<=HANDHOLDINGLASER+4; j++) tloadtile(j,1);
199
        for (j=HANDHOLDINGLASER; j<=HANDHOLDINGLASER+4; j++) tloadtile(j,1);
200
        break;
200
        break;
201
    case SHOTGUNSPRITE__STATIC:
201
    case SHOTGUNSPRITE__STATIC:
202
        tloadtile(SHOTGUNSHELL,1);
202
        tloadtile(SHOTGUNSHELL,1);
203
        for (j=SHOTGUN; j<=SHOTGUN+6; j++) tloadtile(j,1);
203
        for (j=SHOTGUN; j<=SHOTGUN+6; j++) tloadtile(j,1);
204
        break;
204
        break;
205
    case DEVISTATORSPRITE__STATIC:
205
    case DEVISTATORSPRITE__STATIC:
206
        for (j=DEVISTATOR; j<=DEVISTATOR+1; j++) tloadtile(j,1);
206
        for (j=DEVISTATOR; j<=DEVISTATOR+1; j++) tloadtile(j,1);
207
        break;
207
        break;
208
208
209
    }
209
    }
210
210
211
    for (j = PN; j < (PN+maxc); j++) tloadtile(j,1);
211
    for (j = PN; j < (PN+maxc); j++) tloadtile(j,1);
212
}
212
}
213
213
214
static void cachegoodsprites(void)
214
static void cachegoodsprites(void)
215
{
215
{
216
    int i,j;
216
    int i,j;
217
217
218
    for (i=0;i<MAXTILES;i++)
218
    for (i=0;i<MAXTILES;i++)
219
    {
219
    {
220
        if (spriteflags[i] & SPRITE_FLAG_PROJECTILE)
220
        if (spriteflags[i] & SPRITE_FLAG_PROJECTILE)
221
            tloadtile(i,1);
221
            tloadtile(i,1);
222
        if (spritecache[i][0] == i && spritecache[i][2])
222
        if (spritecache[i][0] == i && spritecache[i][2])
223
            for (j = i; j <= spritecache[i][1]; j++)
223
            for (j = i; j <= spritecache[i][1]; j++)
224
                tloadtile(j,1);
224
                tloadtile(j,1);
225
    }
225
    }
226
    tloadtile(BOTTOMSTATUSBAR,1);
226
    tloadtile(BOTTOMSTATUSBAR,1);
227
    if (ud.multimode > 1)
227
    if (ud.multimode > 1)
228
        tloadtile(FRAGBAR,1);
228
        tloadtile(FRAGBAR,1);
229
229
230
    tloadtile(VIEWSCREEN,1);
230
    tloadtile(VIEWSCREEN,1);
231
231
232
    for (i=STARTALPHANUM;i<ENDALPHANUM+1;i++) tloadtile(i,1);
232
    for (i=STARTALPHANUM;i<ENDALPHANUM+1;i++) tloadtile(i,1);
233
    for (i=BIGALPHANUM; i<BIGALPHANUM+82; i++) tloadtile(i,1);
233
    for (i=BIGALPHANUM; i<BIGALPHANUM+82; i++) tloadtile(i,1);
234
    for (i=MINIFONT;i<MINIFONT+63;i++) tloadtile(i,1);
234
    for (i=MINIFONT;i<MINIFONT+63;i++) tloadtile(i,1);
235
235
236
    for (i=FOOTPRINTS;i<FOOTPRINTS+3;i++) tloadtile(i,1);
236
    for (i=FOOTPRINTS;i<FOOTPRINTS+3;i++) tloadtile(i,1);
237
237
238
    for (i = BURNING; i < BURNING+14; i++) tloadtile(i,1);
238
    for (i = BURNING; i < BURNING+14; i++) tloadtile(i,1);
239
    for (i = BURNING2; i < BURNING2+14; i++) tloadtile(i,1);
239
    for (i = BURNING2; i < BURNING2+14; i++) tloadtile(i,1);
240
240
241
    for (i = CRACKKNUCKLES; i < CRACKKNUCKLES+4; i++) tloadtile(i,1);
241
    for (i = CRACKKNUCKLES; i < CRACKKNUCKLES+4; i++) tloadtile(i,1);
242
242
243
    for (i = FIRSTGUN; i < FIRSTGUN+3 ; i++) tloadtile(i,1);
243
    for (i = FIRSTGUN; i < FIRSTGUN+3 ; i++) tloadtile(i,1);
244
    for (i = FIRSTGUNRELOAD; i < FIRSTGUNRELOAD+8 ; i++) tloadtile(i,1);
244
    for (i = FIRSTGUNRELOAD; i < FIRSTGUNRELOAD+8 ; i++) tloadtile(i,1);
245
245
246
    for (i = EXPLOSION2; i < EXPLOSION2+21 ; i++) tloadtile(i,1);
246
    for (i = EXPLOSION2; i < EXPLOSION2+21 ; i++) tloadtile(i,1);
247
247
248
    for (i = COOLEXPLOSION1; i < COOLEXPLOSION1+21 ; i++) tloadtile(i,1);
248
    for (i = COOLEXPLOSION1; i < COOLEXPLOSION1+21 ; i++) tloadtile(i,1);
249
249
250
    tloadtile(BULLETHOLE,1);
250
    tloadtile(BULLETHOLE,1);
251
    tloadtile(BLOODPOOL,1);
251
    tloadtile(BLOODPOOL,1);
252
    for (i = TRANSPORTERBEAM; i < (TRANSPORTERBEAM+6); i++) tloadtile(i,1);
252
    for (i = TRANSPORTERBEAM; i < (TRANSPORTERBEAM+6); i++) tloadtile(i,1);
253
253
254
    for (i = SMALLSMOKE; i < (SMALLSMOKE+4); i++) tloadtile(i,1);
254
    for (i = SMALLSMOKE; i < (SMALLSMOKE+4); i++) tloadtile(i,1);
255
    for (i = SHOTSPARK1; i < (SHOTSPARK1+4); i++) tloadtile(i,1);
255
    for (i = SHOTSPARK1; i < (SHOTSPARK1+4); i++) tloadtile(i,1);
256
256
257
    for (i = BLOOD; i < (BLOOD+4); i++) tloadtile(i,1);
257
    for (i = BLOOD; i < (BLOOD+4); i++) tloadtile(i,1);
258
    for (i = JIBS1; i < (JIBS5+5); i++) tloadtile(i,1);
258
    for (i = JIBS1; i < (JIBS5+5); i++) tloadtile(i,1);
259
    for (i = JIBS6; i < (JIBS6+8); i++) tloadtile(i,1);
259
    for (i = JIBS6; i < (JIBS6+8); i++) tloadtile(i,1);
260
260
261
    for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
261
    for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
262
262
263
    tloadtile(FIRELASER,1);
263
    tloadtile(FIRELASER,1);
264
    for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
264
    for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
265
265
266
    for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
266
    for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
267
267
268
    for (i=RPG; i<RPG+7; i++) tloadtile(i,1);
268
    for (i=RPG; i<RPG+7; i++) tloadtile(i,1);
269
    for (i=FREEZEBLAST; i<FREEZEBLAST+3; i++) tloadtile(i,1);
269
    for (i=FREEZEBLAST; i<FREEZEBLAST+3; i++) tloadtile(i,1);
270
    for (i=SHRINKSPARK; i<SHRINKSPARK+4; i++) tloadtile(i,1);
270
    for (i=SHRINKSPARK; i<SHRINKSPARK+4; i++) tloadtile(i,1);
271
    for (i=GROWSPARK; i<GROWSPARK+4; i++) tloadtile(i,1);
271
    for (i=GROWSPARK; i<GROWSPARK+4; i++) tloadtile(i,1);
272
    for (i=SHRINKEREXPLOSION; i<SHRINKEREXPLOSION+4; i++) tloadtile(i,1);
272
    for (i=SHRINKEREXPLOSION; i<SHRINKEREXPLOSION+4; i++) tloadtile(i,1);
273
    for (i=MORTER; i<MORTER+4; i++) tloadtile(i,4);
273
    for (i=MORTER; i<MORTER+4; i++) tloadtile(i,4);
274
}
274
}
275
275
276
static int getsound(unsigned int num)
276
static int getsound(unsigned int num)
277
{
277
{
278
    short fp = -1;
278
    short fp = -1;
279
    int   l;
279
    int   l;
280
280
281
    if (num >= MAXSOUNDS || ud.config.SoundToggle == 0) return 0;
281
    if (num >= MAXSOUNDS || ud.config.SoundToggle == 0) return 0;
282
    if (ud.config.FXDevice < 0) return 0;
282
    if (ud.config.FXDevice < 0) return 0;
283
283
284
    if (!g_sounds[num].filename) return 0;
284
    if (!g_sounds[num].filename) return 0;
285
    if (g_sounds[num].filename1)fp = kopen4load(g_sounds[num].filename1,loadfromgrouponly);
285
    if (g_sounds[num].filename1)fp = kopen4load(g_sounds[num].filename1,loadfromgrouponly);
286
    if (fp == -1)fp = kopen4load(g_sounds[num].filename,loadfromgrouponly);
286
    if (fp == -1)fp = kopen4load(g_sounds[num].filename,loadfromgrouponly);
287
    if (fp == -1) return 0;
287
    if (fp == -1) return 0;
288
288
289
    l = kfilelength(fp);
289
    l = kfilelength(fp);
290
    g_sounds[num].soundsiz = l;
290
    g_sounds[num].soundsiz = l;
291
291
292
    if ((ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17)) ||
292
    if ((ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17)) ||
293
            (l < 12288))
293
            (l < 12288))
294
    {
294
    {
295
        g_sounds[num].lock = 199;
295
        g_sounds[num].lock = 199;
296
        allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_sounds[num].lock);
296
        allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_sounds[num].lock);
297
        if (g_sounds[num].ptr != NULL)
297
        if (g_sounds[num].ptr != NULL)
298
            kread(fp, g_sounds[num].ptr , l);
298
            kread(fp, g_sounds[num].ptr , l);
299
    }
299
    }
300
    kclose(fp);
300
    kclose(fp);
301
    return 1;
301
    return 1;
302
}
302
}
303
303
304
static void precachenecessarysounds(void)
304
static void precachenecessarysounds(void)
305
{
305
{
306
    int i, j;
306
    int i, j;
307
307
308
    if (ud.config.FXDevice < 0) return;
308
    if (ud.config.FXDevice < 0) return;
309
    j = 0;
309
    j = 0;
310
310
311
    for (i=0;i<MAXSOUNDS;i++)
311
    for (i=0;i<MAXSOUNDS;i++)
312
        if (g_sounds[i].ptr == 0)
312
        if (g_sounds[i].ptr == 0)
313
        {
313
        {
314
            j++;
314
            j++;
315
            if ((j&7) == 0)
315
            if ((j&7) == 0)
316
            {
316
            {
317
                handleevents();
317
                handleevents();
318
                getpackets();
318
                getpackets();
319
            }
319
            }
320
            getsound(i);
320
            getsound(i);
321
        }
321
        }
322
}
322
}
323
323
324
static void dofrontscreens(char *statustext)
324
static void dofrontscreens(char *statustext)
325
{
325
{
326
    int i=0,j;
326
    int i=0,j;
327
327
328
    if (ud.recstat != 2)
328
    if (ud.recstat != 2)
329
    {
329
    {
330
        if (!statustext)
330
        if (!statustext)
331
        {
331
        {
332
            //g_player[myconnectindex].ps->palette = palette;
332
            //g_player[myconnectindex].ps->palette = palette;
333
            setgamepalette(g_player[myconnectindex].ps, palette, 1);    // JBF 20040308
333
            setgamepalette(g_player[myconnectindex].ps, palette, 1);    // JBF 20040308
334
            fadepal(0,0,0, 0,64,7);
334
            fadepal(0,0,0, 0,64,7);
335
            i = ud.screen_size;
335
            i = ud.screen_size;
336
            ud.screen_size = 0;
336
            ud.screen_size = 0;
337
            vscrn();
337
            vscrn();
338
            clearview(0L);
338
            clearview(0L);
339
        }
339
        }
340
340
341
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
341
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
342
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
342
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
343
        j = GetGameVarID(g_iReturnVarID, -1, -1);
343
        j = GetGameVarID(g_iReturnVarID, -1, -1);
344
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
344
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
345
        if (j > MAXTILES-1)
345
        if (j > MAXTILES-1)
346
        {
346
        {
347
            nextpage();
347
            nextpage();
348
            return;
348
            return;
349
        }
349
        }
350
        if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
350
        if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
351
        {
351
        {
352
            menutext(160,90,0,0,"ENTERING USER MAP");
352
            menutext(160,90,0,0,"ENTERING USER MAP");
353
            gametextpal(160,90+10,boardfilename,14,2);
353
            gametextpal(160,90+10,boardfilename,14,2);
354
        }
354
        }
355
        else
355
        else
356
        {
356
        {
357
            menutext(160,90,0,0,"ENTERING");
357
            menutext(160,90,0,0,"ENTERING");
358
            if (map[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
358
            if (map[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
359
                menutext(160,90+16+8,0,0,map[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
359
                menutext(160,90+16+8,0,0,map[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
360
        }
360
        }
361
361
362
        if (statustext) gametext(160,180,statustext,0,2+8+16);
362
        if (statustext) gametext(160,180,statustext,0,2+8+16);
363
363
364
        OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1);
364
        OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1);
365
        nextpage();
365
        nextpage();
366
366
367
        if (!statustext)
367
        if (!statustext)
368
        {
368
        {
369
            fadepal(0,0,0, 63,0,-7);
369
            fadepal(0,0,0, 63,0,-7);
370
370
371
            KB_FlushKeyboardQueue();
371
            KB_FlushKeyboardQueue();
372
            ud.screen_size = i;
372
            ud.screen_size = i;
373
        }
373
        }
374
    }
374
    }
375
    else
375
    else
376
    {
376
    {
377
        if (!statustext)
377
        if (!statustext)
378
        {
378
        {
379
            clearview(0L);
379
            clearview(0L);
380
            //g_player[myconnectindex].ps->palette = palette;
380
            //g_player[myconnectindex].ps->palette = palette;
381
            //palto(0,0,0,0);
381
            //palto(0,0,0,0);
382
            setgamepalette(g_player[myconnectindex].ps, palette, 0);    // JBF 20040308
382
            setgamepalette(g_player[myconnectindex].ps, palette, 0);    // JBF 20040308
383
        }
383
        }
384
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
384
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
385
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
385
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
386
        j = GetGameVarID(g_iReturnVarID, -1, -1);
386
        j = GetGameVarID(g_iReturnVarID, -1, -1);
387
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
387
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
388
        if (j > MAXTILES-1)
388
        if (j > MAXTILES-1)
389
        {
389
        {
390
            nextpage();
390
            nextpage();
391
            return;
391
            return;
392
        }
392
        }
393
        menutext(160,105,0,0,"LOADING...");
393
        menutext(160,105,0,0,"LOADING...");
394
        if (statustext) gametext(160,180,statustext,0,2+8+16);
394
        if (statustext) gametext(160,180,statustext,0,2+8+16);
395
        OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1);
395
        OnEvent(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, -1);
396
        nextpage();
396
        nextpage();
397
    }
397
    }
398
}
398
}
399
399
400
void cacheit(void)
400
void cacheit(void)
401
{
401
{
402
    int i,j,k, pc=0;
402
    int i,j,k, pc=0;
403
    int tc;
403
    int tc;
404
    unsigned int starttime, endtime;
404
    unsigned int starttime, endtime;
405
405
406
    if (ud.recstat == 2)
406
    if (ud.recstat == 2)
407
        return;
407
        return;
408
408
409
    MUSIC_Pause();
409
    MUSIC_Pause();
410
    if (map[MAXVOLUMES*MAXLEVELS+2].musicfn1)
410
    if (map[MAXVOLUMES*MAXLEVELS+2].musicfn1)
411
    {
411
    {
412
        MUSIC_StopSong();
412
        MUSIC_StopSong();
413
        playmusic(&env_music_fn[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus
413
        playmusic(&env_music_fn[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus
414
    }
414
    }
415
415
416
    starttime = getticks();
416
    starttime = getticks();
417
417
418
    precachenecessarysounds();
418
    precachenecessarysounds();
419
419
420
    cachegoodsprites();
420
    cachegoodsprites();
421
421
422
    for (i=0;i<numwalls;i++)
422
    for (i=0;i<numwalls;i++)
423
    {
423
    {
424
        tloadtile(wall[i].picnum, 0);
424
        tloadtile(wall[i].picnum, 0);
425
425
426
        if (wall[i].overpicnum >= 0)
426
        if (wall[i].overpicnum >= 0)
427
        {
427
        {
428
            tloadtile(wall[i].overpicnum, 0);
428
            tloadtile(wall[i].overpicnum, 0);
429
        }
429
        }
430
    }
430
    }
431
431
432
    for (i=0;i<numsectors;i++)
432
    for (i=0;i<numsectors;i++)
433
    {
433
    {
434
        tloadtile(sector[i].floorpicnum, 0);
434
        tloadtile(sector[i].floorpicnum, 0);
435
        tloadtile(sector[i].ceilingpicnum, 0);
435
        tloadtile(sector[i].ceilingpicnum, 0);
436
        if (sector[i].ceilingpicnum == LA)  // JBF 20040509: if( waloff[sector[i].ceilingpicnum] == LA) WTF??!??!?!?
436
        if (sector[i].ceilingpicnum == LA)  // JBF 20040509: if( waloff[sector[i].ceilingpicnum] == LA) WTF??!??!?!?
437
        {
437
        {
438
            tloadtile(LA+1, 0);
438
            tloadtile(LA+1, 0);
439
            tloadtile(LA+2, 0);
439
            tloadtile(LA+2, 0);
440
        }
440
        }
441
441
442
        j = headspritesect[i];
442
        j = headspritesect[i];
443
        while (j >= 0)
443
        while (j >= 0)
444
        {
444
        {
445
            if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
445
            if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
446
                cachespritenum(j);
446
                cachespritenum(j);
447
            j = nextspritesect[j];
447
            j = nextspritesect[j];
448
        }
448
        }
449
    }
449
    }
450
450
451
    tc = totalclock;
451
    tc = totalclock;
452
    j = 0;
452
    j = 0;
453
453
454
    for (i=0;i<MAXTILES;i++)
454
    for (i=0;i<MAXTILES;i++)
455
    {
455
    {
456
        if (!(i&7) && !gotpic[i>>3])
456
        if (!(i&7) && !gotpic[i>>3])
457
        {
457
        {
458
            i+=7;
458
            i+=7;
459
            continue;
459
            continue;
460
        }
460
        }
461
        if (gotpic[i>>3] & pow2char[i&7])
461
        if (gotpic[i>>3] & pow2char[i&7])
462
        {
462
        {
463
            if (waloff[i] == 0)
463
            if (waloff[i] == 0)
464
                loadtile((short)i);
464
                loadtile((short)i);
465
465
466
#if defined(POLYMOST) && defined(USE_OPENGL)
466
#if defined(POLYMOST) && defined(USE_OPENGL)
467
            if (ud.config.useprecache)
467
            if (ud.config.useprecache)
468
            {
468
            {
469
                if (precachehightile[0][i>>3] & pow2char[i&7])
469
                if (precachehightile[0][i>>3] & pow2char[i&7])
470
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
470
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
471
                        polymost_precache(i,k,0);
471
                        polymost_precache(i,k,0);
472
472
473
                if (precachehightile[1][i>>3] & pow2char[i&7])
473
                if (precachehightile[1][i>>3] & pow2char[i&7])
474
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
474
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
475
                        polymost_precache(i,k,1);
475
                        polymost_precache(i,k,1);
476
            }
476
            }
477
#endif
477
#endif
478
            j++;
478
            j++;
479
            pc++;
479
            pc++;
480
        }
480
        }
481
        else continue;
481
        else continue;
482
482
483
        if ((j&7) == 0)
483
        if ((j&7) == 0)
484
        {
484
        {
485
            handleevents();
485
            handleevents();
486
            getpackets();
486
            getpackets();
487
        }
487
        }
488
        if (totalclock - tc > TICRATE/4)
488
        if (totalclock - tc > TICRATE/4)
489
        {
489
        {
490
            sprintf(tempbuf,"Loading resources... %d%%\n",min(100,100*pc/precachecount));
490
            sprintf(tempbuf,"Loading resources... %d%%\n",min(100,100*pc/precachecount));
491
            dofrontscreens(tempbuf);
491
            dofrontscreens(tempbuf);
492
            tc = totalclock;
492
            tc = totalclock;
493
        }
493
        }
494
    }
494
    }
495
495
496
    clearbufbyte(gotpic,sizeof(gotpic),0L);
496
    clearbufbyte(gotpic,sizeof(gotpic),0L);
497
497
498
    endtime = getticks();
498
    endtime = getticks();
499
    OSD_Printf("Cache time: %dms\n", endtime-starttime);
499
    OSD_Printf("Cache time: %dms\n", endtime-starttime);
500
}
500
}
501
501
502
void xyzmirror(int i,int wn)
502
void xyzmirror(int i,int wn)
503
{
503
{
504
    //if (waloff[wn] == 0) loadtile(wn);
504
    //if (waloff[wn] == 0) loadtile(wn);
505
    setviewtotile(wn,tilesizy[wn],tilesizx[wn]);
505
    setviewtotile(wn,tilesizy[wn],tilesizx[wn]);
506
506
507
    drawrooms(SX,SY,SZ,SA,100+sprite[i].shade,SECT);
507
    drawrooms(SX,SY,SZ,SA,100+sprite[i].shade,SECT);
508
    display_mirror = 1;
508
    display_mirror = 1;
509
    animatesprites(SX,SY,SA,65536L);
509
    animatesprites(SX,SY,SA,65536L);
510
    display_mirror = 0;
510
    display_mirror = 0;
511
    drawmasks();
511
    drawmasks();
512
512
513
    setviewback();
513
    setviewback();
514
    squarerotatetile(wn);
514
    squarerotatetile(wn);
515
    invalidatetile(wn,-1,255);
515
    invalidatetile(wn,-1,255);
516
}
516
}
517
517
518
void vscrn(void)
518
void vscrn(void)
519
{
519
{
520
    int i, j, ss, x1, x2, y1, y2;
520
    int i, j, ss, x1, x2, y1, y2;
521
521
522
    if (ud.screen_size < 0) ud.screen_size = 0;
522
    if (ud.screen_size < 0) ud.screen_size = 0;
523
    if (ud.screen_size > 64) ud.screen_size = 64;
523
    if (ud.screen_size > 64) ud.screen_size = 64;
524
    if (ud.screen_size == 0) flushperms();
524
    if (ud.screen_size == 0) flushperms();
525
525
526
    ss = max(ud.screen_size-8,0);
526
    ss = max(ud.screen_size-8,0);
527
527
528
    x1 = scale(ss,xdim,160);
528
    x1 = scale(ss,xdim,160);
529
    x2 = xdim-x1;
529
    x2 = xdim-x1;
530
530
531
    y1 = ss;
531
    y1 = ss;
532
    y2 = 200;
532
    y2 = 200;
533
    if (ud.screen_size > 0 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_FRAGBAR) && ud.multimode > 1)
533
    if (ud.screen_size > 0 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_FRAGBAR) && ud.multimode > 1)
534
    {
534
    {
535
        j = 0;
535
        j = 0;
536
        for (i=connecthead;i>=0;i=connectpoint2[i])
536
        for (i=connecthead;i>=0;i=connectpoint2[i])
537
            if (i > j) j = i;
537
            if (i > j) j = i;
538
538
539
        if (j >= 1) y1 += 8;
539
        if (j >= 1) y1 += 8;
540
        if (j >= 4) y1 += 8;
540
        if (j >= 4) y1 += 8;
541
        if (j >= 8) y1 += 8;
541
        if (j >= 8) y1 += 8;
542
        if (j >= 12) y1 += 8;
542
        if (j >= 12) y1 += 8;
543
    }
543
    }
544
544
545
    if (ud.screen_size >= 8 && !(ud.screen_size == 8 && ud.statusbarmode && bpp > 8))
545
    if (ud.screen_size >= 8 && !(ud.screen_size == 8 && ud.statusbarmode && bpp > 8))
546
        y2 -= (ss+scale(tilesizy[BOTTOMSTATUSBAR],ud.statusbarscale,100));
546
        y2 -= (ss+scale(tilesizy[BOTTOMSTATUSBAR],ud.statusbarscale,100));
547
547
548
    y1 = scale(y1,ydim,200);
548
    y1 = scale(y1,ydim,200);
549
    y2 = scale(y2,ydim,200);
549
    y2 = scale(y2,ydim,200);
550
550
551
    setview(x1,y1,x2-1,y2-1);
551
    setview(x1,y1,x2-1,y2-1);
552
552
553
    pub = NUMPAGES;
553
    pub = NUMPAGES;
554
    pus = NUMPAGES;
554
    pus = NUMPAGES;
555
}
555
}
556
556
557
void pickrandomspot(int snum)
557
void pickrandomspot(int snum)
558
{
558
{
559
    player_struct *p = g_player[snum].ps;
559
    player_struct *p = g_player[snum].ps;
560
    int i=snum,j,k;
560
    int i=snum,j,k;
561
    unsigned int dist,pdist = -1;
561
    unsigned int dist,pdist = -1;
562
562
563
    if (ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_FIXEDRESPAWN))
563
    if (ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_FIXEDRESPAWN))
564
    {
564
    {
565
        i = TRAND%numplayersprites;
565
        i = TRAND%numplayersprites;
566
        if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDMSPAWN)
566
        if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDMSPAWN)
567
        {
567
        {
568
            for (j=0;j<ud.multimode;j++)
568
            for (j=0;j<ud.multimode;j++)
569
            {
569
            {
570
                if (j != snum && g_player[j].ps->team == g_player[snum].ps->team && sprite[g_player[j].ps->i].extra > 0)
570
                if (j != snum && g_player[j].ps->team == g_player[snum].ps->team && sprite[g_player[j].ps->i].extra > 0)
571
                {
571
                {
572
                    for (k=0;k<numplayersprites;k++)
572
                    for (k=0;k<numplayersprites;k++)
573
                    {
573
                    {
574
                        dist = FindDistance2D(g_player[j].ps->posx-g_PlayerSpawnPoints[k].ox,g_player[j].ps->posy-g_PlayerSpawnPoints[k].oy);
574
                        dist = FindDistance2D(g_player[j].ps->posx-g_PlayerSpawnPoints[k].ox,g_player[j].ps->posy-g_PlayerSpawnPoints[k].oy);
575
                        if (dist < pdist)
575
                        if (dist < pdist)
576
                            i = k, pdist = dist;
576
                            i = k, pdist = dist;
577
                    }
577
                    }
578
                    break;
578
                    break;
579
                }
579
                }
580
            }
580
            }
581
        }
581
        }
582
    }
582
    }
583
583
584
    p->bobposx = p->oposx = p->posx = g_PlayerSpawnPoints[i].ox;
584
    p->bobposx = p->oposx = p->posx = g_PlayerSpawnPoints[i].ox;
585
    p->bobposy = p->oposy = p->posy = g_PlayerSpawnPoints[i].oy;
585
    p->bobposy = p->oposy = p->posy = g_PlayerSpawnPoints[i].oy;
586
    p->oposz = p->posz = g_PlayerSpawnPoints[i].oz;
586
    p->oposz = p->posz = g_PlayerSpawnPoints[i].oz;
587
    p->ang = g_PlayerSpawnPoints[i].oa;
587
    p->ang = g_PlayerSpawnPoints[i].oa;
588
    p->cursectnum = g_PlayerSpawnPoints[i].os;
588
    p->cursectnum = g_PlayerSpawnPoints[i].os;
589
}
589
}
590
590
591
static void resetplayerstats(int snum)
591
static void resetplayerstats(int snum)
592
{
592
{
593
    player_struct *p = g_player[snum].ps;
593
    player_struct *p = g_player[snum].ps;
594
594
595
    ud.show_help        = 0;
595
    ud.show_help        = 0;
596
    ud.showallmap       = 0;
596
    ud.showallmap       = 0;
597
    p->dead_flag        = 0;
597
    p->dead_flag        = 0;
598
    p->wackedbyactor    = -1;
598
    p->wackedbyactor    = -1;
599
    p->falling_counter  = 0;
599
    p->falling_counter  = 0;
600
    p->quick_kick       = 0;
600
    p->quick_kick       = 0;
601
    p->subweapon        = 0;
601
    p->subweapon        = 0;
602
    p->last_full_weapon = 0;
602
    p->last_full_weapon = 0;
603
    p->ftq              = 0;
603
    p->ftq              = 0;
604
    p->fta              = 0;
604
    p->fta              = 0;
605
    p->tipincs          = 0;
605
    p->tipincs          = 0;
606
    p->buttonpalette    = 0;
606
    p->buttonpalette    = 0;
607
    p->actorsqu         =-1;
607
    p->actorsqu         =-1;
608
    p->invdisptime      = 0;
608
    p->invdisptime      = 0;
609
    p->refresh_inventory= 0;
609
    p->refresh_inventory= 0;
610
    p->last_pissed_time = 0;
610
    p->last_pissed_time = 0;
611
    p->holster_weapon   = 0;
611
    p->holster_weapon   = 0;
612
    p->pycount          = 0;
612
    p->pycount          = 0;
613
    p->pyoff            = 0;
613
    p->pyoff            = 0;
614
    p->opyoff           = 0;
614
    p->opyoff           = 0;
615
    p->loogcnt          = 0;
615
    p->loogcnt          = 0;
616
    p->angvel           = 0;
616
    p->angvel           = 0;
617
    p->weapon_sway      = 0;
617
    p->weapon_sway      = 0;
618
    //    p->select_dir       = 0;
618
    //    p->select_dir       = 0;
619
    p->extra_extra8     = 0;
619
    p->extra_extra8     = 0;
620
    p->show_empty_weapon= 0;
620
    p->show_empty_weapon= 0;
621
    p->dummyplayersprite=-1;
621
    p->dummyplayersprite=-1;
622
    p->crack_time       = 0;
622
    p->crack_time       = 0;
623
    p->hbomb_hold_delay = 0;
623
    p->hbomb_hold_delay = 0;
624
    p->transporter_hold = 0;
624
    p->transporter_hold = 0;
625
    p->wantweaponfire  = -1;
625
    p->wantweaponfire  = -1;
626
    p->hurt_delay       = 0;
626
    p->hurt_delay       = 0;
627
    p->footprintcount   = 0;
627
    p->footprintcount   = 0;
628
    p->footprintpal     = 0;
628
    p->footprintpal     = 0;
629
    p->footprintshade   = 0;
629
    p->footprintshade   = 0;
630
    p->jumping_toggle   = 0;
630
    p->jumping_toggle   = 0;
631
    p->ohoriz = p->horiz= 140;
631
    p->ohoriz = p->horiz= 140;
632
    p->horizoff         = 0;
632
    p->horizoff         = 0;
633
    p->bobcounter       = 0;
633
    p->bobcounter       = 0;
634
    p->on_ground        = 0;
634
    p->on_ground        = 0;
635
    p->player_par       = 0;
635
    p->player_par       = 0;
636
    p->return_to_center = 9;
636
    p->return_to_center = 9;
637
    p->airleft          = 15*26;
637
    p->airleft          = 15*26;
638
    p->rapid_fire_hold  = 0;
638
    p->rapid_fire_hold  = 0;
639
    p->toggle_key_flag  = 0;
639
    p->toggle_key_flag  = 0;
640
    p->access_spritenum = -1;
640
    p->access_spritenum = -1;
641
    if (ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_ACCESSATSTART))
641
    if (ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_ACCESSATSTART))
642
        p->got_access = 7;
642
        p->got_access = 7;
643
    else p->got_access      = 0;
643
    else p->got_access      = 0;
644
    p->random_club_frame= 0;
644
    p->random_club_frame= 0;
645
    pus = 1;
645
    pus = 1;
646
    p->on_warping_sector = 0;
646
    p->on_warping_sector = 0;
647
    p->spritebridge      = 0;
647
    p->spritebridge      = 0;
648
    p->sbs          = 0;
648
    p->sbs          = 0;
649
    p->palette = (char *) &palette[0];
649
    p->palette = (char *) &palette[0];
650
650
651
    if (p->steroids_amount < 400)
651
    if (p->steroids_amount < 400)
652
    {
652
    {
653
        p->steroids_amount = 0;
653
        p->steroids_amount = 0;
654
        p->inven_icon = 0;
654
        p->inven_icon = 0;
655
    }
655
    }
656
    p->heat_on =            0;
656
    p->heat_on =            0;
657
    p->jetpack_on =         0;
657
    p->jetpack_on =         0;
658
    p->holoduke_on =       -1;
658
    p->holoduke_on =       -1;
659
659
660
    p->look_ang          = 512 - ((ud.level_number&1)<<10);
660
    p->look_ang          = 512 - ((ud.level_number&1)<<10);
661
661
662
    p->rotscrnang        = 0;
662
    p->rotscrnang        = 0;
663
    p->orotscrnang       = 1;   // JBF 20031220
663
    p->orotscrnang       = 1;   // JBF 20031220
664
    p->newowner          =-1;
664
    p->newowner          =-1;
665
    p->jumping_counter   = 0;
665
    p->jumping_counter   = 0;
666
    p->hard_landing      = 0;
666
    p->hard_landing      = 0;
667
    p->posxv             = 0;
667
    p->posxv             = 0;
668
    p->posyv             = 0;
668
    p->posyv             = 0;
669
    p->poszv             = 0;
669
    p->poszv             = 0;
670
    fricxv            = 0;
670
    fricxv            = 0;
671
    fricyv            = 0;
671
    fricyv            = 0;
672
    p->somethingonplayer =-1;
672
    p->somethingonplayer =-1;
673
    p->one_eighty_count  = 0;
673
    p->one_eighty_count  = 0;
674
    p->cheat_phase       = 0;
674
    p->cheat_phase       = 0;
675
675
676
    p->on_crane          = -1;
676
    p->on_crane          = -1;
677
677
678
    if ((aplWeaponWorksLike[p->curr_weapon][snum] == PISTOL_WEAPON) &&
678
    if ((aplWeaponWorksLike[p->curr_weapon][snum] == PISTOL_WEAPON) &&
679
            (aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum]))
679
            (aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum]))
680
        p->kickback_pic  = aplWeaponTotalTime[p->curr_weapon][snum]+1;
680
        p->kickback_pic  = aplWeaponTotalTime[p->curr_weapon][snum]+1;
681
    else p->kickback_pic = 0;
681
    else p->kickback_pic = 0;
682
682
683
    p->weapon_pos        = 6;
683
    p->weapon_pos        = 6;
684
    p->walking_snd_toggle= 0;
684
    p->walking_snd_toggle= 0;
685
    p->weapon_ang        = 0;
685
    p->weapon_ang        = 0;
686
686
687
    p->knuckle_incs      = 1;
687
    p->knuckle_incs      = 1;
688
    p->fist_incs = 0;
688
    p->fist_incs = 0;
689
    p->knee_incs         = 0;
689
    p->knee_incs         = 0;
690
    p->jetpack_on        = 0;
690
    p->jetpack_on        = 0;
691
    p->reloading        = 0;
691
    p->reloading        = 0;
692
692
693
    p->movement_lock     = 0;
693
    p->movement_lock     = 0;
694
694
695
    setpal(p);
695
    setpal(p);
696
    OnEvent(EVENT_RESETPLAYER, p->i, snum, -1);
696
    OnEvent(EVENT_RESETPLAYER, p->i, snum, -1);
697
}
697
}
698
698
699
void resetweapons(int snum)
699
void resetweapons(int snum)
700
{
700
{
701
    int weapon;
701
    int weapon;
702
    player_struct *p = g_player[snum].ps;
702
    player_struct *p = g_player[snum].ps;
703
703
704
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
704
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
705
        p->gotweapon[weapon] = 0;
705
        p->gotweapon[weapon] = 0;
706
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
706
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
707
        p->ammo_amount[weapon] = 0;
707
        p->ammo_amount[weapon] = 0;
708
708
709
    p->weapon_pos = 6;
709
    p->weapon_pos = 6;
710
    p->kickback_pic = 5;
710
    p->kickback_pic = 5;
711
    p->curr_weapon = PISTOL_WEAPON;
711
    p->curr_weapon = PISTOL_WEAPON;
712
    p->gotweapon[PISTOL_WEAPON] = 1;
712
    p->gotweapon[PISTOL_WEAPON] = 1;
713
    p->gotweapon[KNEE_WEAPON] = 1;
713
    p->gotweapon[KNEE_WEAPON] = 1;
714
    p->ammo_amount[PISTOL_WEAPON] = 48;
714
    p->ammo_amount[PISTOL_WEAPON] = 48;
715
    p->gotweapon[HANDREMOTE_WEAPON] = 1;
715
    p->gotweapon[HANDREMOTE_WEAPON] = 1;
716
    p->last_weapon = -1;
716
    p->last_weapon = -1;
717
717
718
    p->show_empty_weapon= 0;
718
    p->show_empty_weapon= 0;
719
    p->last_pissed_time = 0;
719
    p->last_pissed_time = 0;
720
    p->holster_weapon = 0;
720
    p->holster_weapon = 0;
721
    OnEvent(EVENT_RESETWEAPONS, p->i, snum, -1);
721
    OnEvent(EVENT_RESETWEAPONS, p->i, snum, -1);
722
}
722
}
723
723
724
void resetinventory(int snum)
724
void resetinventory(int snum)
725
{
725
{
726
    player_struct *p = g_player[snum].ps;
726
    player_struct *p = g_player[snum].ps;
727
727
728
    p->inven_icon       = 0;
728
    p->inven_icon       = 0;
729
    p->boot_amount = 0;
729
    p->boot_amount = 0;
730
    p->scuba_on =           0;
730
    p->scuba_on =           0;
731
    p->scuba_amount =         0;
731
    p->scuba_amount =         0;
732
    p->heat_amount        = 0;
732
    p->heat_amount        = 0;
733
    p->heat_on = 0;
733
    p->heat_on = 0;
734
    p->jetpack_on =         0;
734
    p->jetpack_on =         0;
735
    p->jetpack_amount =       0;
735
    p->jetpack_amount =       0;
736
    p->shield_amount =      start_armour_amount;
736
    p->shield_amount =      start_armour_amount;
737
    p->holoduke_on = -1;
737
    p->holoduke_on = -1;
738
    p->holoduke_amount =    0;
738
    p->holoduke_amount =    0;
739
    p->firstaid_amount = 0;
739
    p->firstaid_amount = 0;
740
    p->steroids_amount = 0;
740
    p->steroids_amount = 0;
741
    p->inven_icon = 0;
741
    p->inven_icon = 0;
742
    OnEvent(EVENT_RESETINVENTORY, p->i, snum, -1);
742
    OnEvent(EVENT_RESETINVENTORY, p->i, snum, -1);
743
}
743
}
744
744
745
static void resetprestat(int snum,int g)
745
static void resetprestat(int snum,int g)
746
{
746
{
747
    player_struct *p = g_player[snum].ps;
747
    player_struct *p = g_player[snum].ps;
748
    int i;
748
    int i;
749
749
750
    spriteqloc = 0;
750
    spriteqloc = 0;
751
    for (i=0;i<spriteqamount;i++) spriteq[i] = -1;
751
    for (i=0;i<spriteqamount;i++) spriteq[i] = -1;
752
752
753
    p->hbomb_on          = 0;
753
    p->hbomb_on          = 0;
754
    p->cheat_phase       = 0;
754
    p->cheat_phase       = 0;
755
    p->pals_time         = 0;
755
    p->pals_time         = 0;
756
    p->toggle_key_flag   = 0;
756
    p->toggle_key_flag   = 0;
757
    p->secret_rooms      = 0;
757
    p->secret_rooms      = 0;
758
    p->max_secret_rooms  = 0;
758
    p->max_secret_rooms  = 0;
759
    p->actors_killed     = 0;
759
    p->actors_killed     = 0;
760
    p->max_actors_killed = 0;
760
    p->max_actors_killed = 0;
761
    p->lastrandomspot = 0;
761
    p->lastrandomspot = 0;
762
    p->weapon_pos = 6;
762
    p->weapon_pos = 6;
763
    p->kickback_pic = 5;
763
    p->kickback_pic = 5;
764
    p->last_weapon = -1;
764
    p->last_weapon = -1;
765
    p->weapreccnt = 0;
765
    p->weapreccnt = 0;
766
    p->interface_toggle_flag = 0;
766
    p->interface_toggle_flag = 0;
767
    p->show_empty_weapon= 0;
767
    p->show_empty_weapon= 0;
768
    p->holster_weapon = 0;
768
    p->holster_weapon = 0;
769
    p->last_pissed_time = 0;
769
    p->last_pissed_time = 0;
770
770
771
    p->one_parallax_sectnum = -1;
771
    p->one_parallax_sectnum = -1;
772
    p->visibility = ud.const_visibility;
772
    p->visibility = ud.const_visibility;
773
773
774
    screenpeek              = myconnectindex;
774
    screenpeek              = myconnectindex;
775
    numanimwalls            = 0;
775
    numanimwalls            = 0;
776
    numcyclers              = 0;
776
    numcyclers              = 0;
777
    animatecnt              = 0;
777
    animatecnt              = 0;
778
    parallaxtype            = 0;
778
    parallaxtype            = 0;
779
    randomseed              = 17L;
779
    randomseed              = 17L;
780
    ud.pause_on             = 0;
780
    ud.pause_on             = 0;
781
    ud.camerasprite         =-1;
781
    ud.camerasprite         =-1;
782
    ud.eog                  = 0;
782
    ud.eog                  = 0;
783
    tempwallptr             = 0;
783
    tempwallptr             = 0;
784
    camsprite               =-1;
784
    camsprite               =-1;
785
    earthquaketime          = 0;
785
    earthquaketime          = 0;
786
786
787
    numinterpolations = 0;
787
    numinterpolations = 0;
788
    startofdynamicinterpolations = 0;
788
    startofdynamicinterpolations = 0;
789
789
790
    if (((g&MODE_EOL) != MODE_EOL && numplayers < 2) || (!(gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && numplayers > 1))
790
    if (((g&MODE_EOL) != MODE_EOL && numplayers < 2) || (!(gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && numplayers > 1))
791
    {
791
    {
792
        resetweapons(snum);
792
        resetweapons(snum);
793
        resetinventory(snum);
793
        resetinventory(snum);
794
    }
794
    }
795
    else if (p->curr_weapon == HANDREMOTE_WEAPON)
795
    else if (p->curr_weapon == HANDREMOTE_WEAPON)
796
    {
796
    {
797
        p->ammo_amount[HANDBOMB_WEAPON]++;
797
        p->ammo_amount[HANDBOMB_WEAPON]++;
798
        p->curr_weapon = HANDBOMB_WEAPON;
798
        p->curr_weapon = HANDBOMB_WEAPON;
799
    }
799
    }
800
800
801
    p->timebeforeexit   = 0;
801
    p->timebeforeexit   = 0;
802
    p->customexitsound  = 0;
802
    p->customexitsound  = 0;
803
803
804
}
804
}
805
805
806
static void setupbackdrop(short sky)
806
static void setupbackdrop(short sky)
807
{
807
{
808
    short i;
808
    short i;
809
809
810
    for (i=0;i<MAXPSKYTILES;i++) pskyoff[i]=0;
810
    for (i=0;i<MAXPSKYTILES;i++) pskyoff[i]=0;
811
811
812
    if (parallaxyscale != 65536L)
812
    if (parallaxyscale != 65536L)
813
        parallaxyscale = 32768;
813
        parallaxyscale = 32768;
814
814
815
    switch (dynamictostatic[sky])
815
    switch (dynamictostatic[sky])
816
    {
816
    {
817
    case CLOUDYOCEAN__STATIC:
817
    case CLOUDYOCEAN__STATIC:
818
        parallaxyscale = 65536L;
818
        parallaxyscale = 65536L;
819
        break;
819
        break;
820
    case MOONSKY1__STATIC :
820
    case MOONSKY1__STATIC :
821
        pskyoff[6]=1;
821
        pskyoff[6]=1;
822
        pskyoff[1]=2;
822
        pskyoff[1]=2;
823
        pskyoff[4]=2;
823
        pskyoff[4]=2;
824
        pskyoff[2]=3;
824
        pskyoff[2]=3;
825
        break;
825
        break;
826
    case BIGORBIT1__STATIC: // orbit
826
    case BIGORBIT1__STATIC: // orbit
827
        pskyoff[5]=1;
827
        pskyoff[5]=1;
828
        pskyoff[6]=2;
828
        pskyoff[6]=2;
829
        pskyoff[7]=3;
829
        pskyoff[7]=3;
830
        pskyoff[2]=4;
830
        pskyoff[2]=4;
831
        break;
831
        break;
832
    case LA__STATIC:
832
    case LA__STATIC:
833
        parallaxyscale = 16384+1024;
833
        parallaxyscale = 16384+1024;
834
        pskyoff[0]=1;
834
        pskyoff[0]=1;
835
        pskyoff[1]=2;
835
        pskyoff[1]=2;
836
        pskyoff[2]=1;
836
        pskyoff[2]=1;
837
        pskyoff[3]=3;
837
        pskyoff[3]=3;
838
        pskyoff[4]=4;
838
        pskyoff[4]=4;
839
        pskyoff[5]=0;
839
        pskyoff[5]=0;
840
        pskyoff[6]=2;
840
        pskyoff[6]=2;
841
        pskyoff[7]=3;
841
        pskyoff[7]=3;
842
        break;
842
        break;
843
    }
843
    }
844
844
845
    pskybits=3;
845
    pskybits=3;
846
}
846
}
847
847
848
static void prelevel(char g)
848
static void prelevel(char g)
849
{
849
{
850
    int i, nexti, j, startwall, endwall, lotaglist;
850
    int i, nexti, j, startwall, endwall, lotaglist;
851
    int lotags[MAXSPRITES];
851
    int lotags[MAXSPRITES];
852
    int switchpicnum;
852
    int switchpicnum;
853
853
854
854
855
    clearbufbyte(show2dsector,sizeof(show2dsector),0L);
855
    clearbufbyte(show2dsector,sizeof(show2dsector),0L);
856
    clearbufbyte(show2dwall,sizeof(show2dwall),0L);
856
    clearbufbyte(show2dwall,sizeof(show2dwall),0L);
857
    clearbufbyte(show2dsprite,sizeof(show2dsprite),0L);
857
    clearbufbyte(show2dsprite,sizeof(show2dsprite),0L);
858
858
859
    resetprestat(0,g);
859
    resetprestat(0,g);
860
    numclouds = 0;
860
    numclouds = 0;
861
861
862
    for (i=0;i<numsectors;i++)
862
    for (i=0;i<numsectors;i++)
863
    {
863
    {
864
        sector[i].extra = 256;
864
        sector[i].extra = 256;
865
865
866
        switch (sector[i].lotag)
866
        switch (sector[i].lotag)
867
        {
867
        {
868
        case 20:
868
        case 20:
869
        case 22:
869
        case 22:
870
            if (sector[i].floorz > sector[i].ceilingz)
870
            if (sector[i].floorz > sector[i].ceilingz)
871
                sector[i].lotag |= 32768;
871
                sector[i].lotag |= 32768;
872
            continue;
872
            continue;
873
        }
873
        }
874
874
875
        if (sector[i].ceilingstat&1)
875
        if (sector[i].ceilingstat&1)
876
        {
876
        {
877
            if (waloff[sector[i].ceilingpicnum] == 0)
877
            if (waloff[sector[i].ceilingpicnum] == 0)
878
            {
878
            {
879
                if (sector[i].ceilingpicnum == LA)
879
                if (sector[i].ceilingpicnum == LA)
880
                    for (j=0;j<5;j++)
880
                    for (j=0;j<5;j++)
881
                        tloadtile(sector[i].ceilingpicnum+j, 0);
881
                        tloadtile(sector[i].ceilingpicnum+j, 0);
882
            }
882
            }
883
            setupbackdrop(sector[i].ceilingpicnum);
883
            setupbackdrop(sector[i].ceilingpicnum);
884
884
885
            if (sector[i].ceilingpicnum == CLOUDYSKIES && numclouds < 127)
885
            if (sector[i].ceilingpicnum == CLOUDYSKIES && numclouds < 127)
886
                clouds[numclouds++] = i;
886
                clouds[numclouds++] = i;
887
887
888
            if (g_player[0].ps->one_parallax_sectnum == -1)
888
            if (g_player[0].ps->one_parallax_sectnum == -1)
889
                g_player[0].ps->one_parallax_sectnum = i;
889
                g_player[0].ps->one_parallax_sectnum = i;
890
        }
890
        }
891
891
892
        if (sector[i].lotag == 32767) //Found a secret room
892
        if (sector[i].lotag == 32767) //Found a secret room
893
        {
893
        {
894
            g_player[0].ps->max_secret_rooms++;
894
            g_player[0].ps->max_secret_rooms++;
895
            continue;
895
            continue;
896
        }
896
        }
897
897
898
        if (sector[i].lotag == -1)
898
        if (sector[i].lotag == -1)
899
        {
899
        {
900
            g_player[0].ps->exitx = wall[sector[i].wallptr].x;
900
            g_player[0].ps->exitx = wall[sector[i].wallptr].x;
901
            g_player[0].ps->exity = wall[sector[i].wallptr].y;
901
            g_player[0].ps->exity = wall[sector[i].wallptr].y;
902
            continue;
902
            continue;
903
        }
903
        }
904
    }
904
    }
905
905
906
    i = headspritestat[0];
906
    i = headspritestat[0];
907
    while (i >= 0)
907
    while (i >= 0)
908
    {
908
    {
909
        nexti = nextspritestat[i];
909
        nexti = nextspritestat[i];
910
        ResetActorGameVars(i);
910
        ResetActorGameVars(i);
911
        LoadActor(i);
911
        LoadActor(i);
912
        OnEvent(EVENT_LOADACTOR, i, -1, -1);
912
        OnEvent(EVENT_LOADACTOR, i, -1, -1);
913
        if (sprite[i].lotag == -1 && (sprite[i].cstat&16))
913
        if (sprite[i].lotag == -1 && (sprite[i].cstat&16))
914
        {
914
        {
915
            g_player[0].ps->exitx = SX;
915
            g_player[0].ps->exitx = SX;
916
            g_player[0].ps->exity = SY;
916
            g_player[0].ps->exity = SY;
917
        }
917
        }
918
        else switch (dynamictostatic[PN])
918
        else switch (dynamictostatic[PN])
919
            {
919
            {
920
            case GPSPEED__STATIC:
920
            case GPSPEED__STATIC:
921
                sector[SECT].extra = SLT;
921
                sector[SECT].extra = SLT;
922
                deletesprite(i);
922
                deletesprite(i);
923
                break;
923
                break;
924
924
925
            case CYCLER__STATIC:
925
            case CYCLER__STATIC:
926
                if (numcyclers >= MAXCYCLERS)
926
                if (numcyclers >= MAXCYCLERS)
927
                {
927
                {
928
                    Bsprintf(tempbuf,"\nToo many cycling sectors (%d max).",MAXCYCLERS);
928
                    Bsprintf(tempbuf,"\nToo many cycling sectors (%d max).",MAXCYCLERS);
929
                    gameexit(tempbuf);
929
                    gameexit(tempbuf);
930
                }
930
                }
931
                cyclers[numcyclers][0] = SECT;
931
                cyclers[numcyclers][0] = SECT;
932
                cyclers[numcyclers][1] = SLT;
932
                cyclers[numcyclers][1] = SLT;
933
                cyclers[numcyclers][2] = SS;
933
                cyclers[numcyclers][2] = SS;
934
                cyclers[numcyclers][3] = sector[SECT].floorshade;
934
                cyclers[numcyclers][3] = sector[SECT].floorshade;
935
                cyclers[numcyclers][4] = SHT;
935
                cyclers[numcyclers][4] = SHT;
936
                cyclers[numcyclers][5] = (SA == 1536);
936
                cyclers[numcyclers][5] = (SA == 1536);
937
                numcyclers++;
937
                numcyclers++;
938
                deletesprite(i);
938
                deletesprite(i);
939
                break;
939
                break;
940
940
941
            case SECTOREFFECTOR__STATIC:
941
            case SECTOREFFECTOR__STATIC:
942
            case ACTIVATOR__STATIC:
942
            case ACTIVATOR__STATIC:
943
            case TOUCHPLATE__STATIC:
943
            case TOUCHPLATE__STATIC:
944
            case ACTIVATORLOCKED__STATIC:
944
            case ACTIVATORLOCKED__STATIC:
945
            case MUSICANDSFX__STATIC:
945
            case MUSICANDSFX__STATIC:
946
            case LOCATORS__STATIC:
946
            case LOCATORS__STATIC:
947
            case MASTERSWITCH__STATIC:
947
            case MASTERSWITCH__STATIC:
948
            case RESPAWN__STATIC:
948
            case RESPAWN__STATIC:
949
                sprite[i].cstat = 0;
949
                sprite[i].cstat = 0;
950
                break;
950
                break;
951
            }
951
            }
952
        i = nexti;
952
        i = nexti;
953
    }
953
    }
954
954
955
    for (i=0;i < MAXSPRITES;i++)
955
    for (i=0;i < MAXSPRITES;i++)
956
    {
956
    {
957
        if (sprite[i].statnum < MAXSTATUS)
957
        if (sprite[i].statnum < MAXSTATUS)
958
        {
958
        {
959
            if (PN == SECTOREFFECTOR && SLT == 14)
959
            if (PN == SECTOREFFECTOR && SLT == 14)
960
                continue;
960
                continue;
961
            spawn(-1,i);
961
            spawn(-1,i);
962
        }
962
        }
963
    }
963
    }
964
964
965
    for (i=0;i < MAXSPRITES;i++)
965
    for (i=0;i < MAXSPRITES;i++)
966
        if (sprite[i].statnum < MAXSTATUS)
966
        if (sprite[i].statnum < MAXSTATUS)
967
        {
967
        {
968
            if (PN == SECTOREFFECTOR && SLT == 14)
968
            if (PN == SECTOREFFECTOR && SLT == 14)
969
                spawn(-1,i);
969
                spawn(-1,i);
970
        }
970
        }
971
971
972
    lotaglist = 0;
972
    lotaglist = 0;
973
973
974
    i = headspritestat[0];
974
    i = headspritestat[0];
975
    while (i >= 0)
975
    while (i >= 0)
976
    {
976
    {
977
        switch (dynamictostatic[PN-1])
977
        switch (dynamictostatic[PN-1])
978
        {
978
        {
979
        case DIPSWITCH__STATIC:
979
        case DIPSWITCH__STATIC:
980
        case DIPSWITCH2__STATIC:
980
        case DIPSWITCH2__STATIC:
981
        case PULLSWITCH__STATIC:
981
        case PULLSWITCH__STATIC:
982
        case HANDSWITCH__STATIC:
982
        case HANDSWITCH__STATIC:
983
        case SLOTDOOR__STATIC:
983
        case SLOTDOOR__STATIC:
984
        case LIGHTSWITCH__STATIC:
984
        case LIGHTSWITCH__STATIC:
985
        case SPACELIGHTSWITCH__STATIC:
985
        case SPACELIGHTSWITCH__STATIC:
986
        case SPACEDOORSWITCH__STATIC:
986
        case SPACEDOORSWITCH__STATIC:
987
        case FRANKENSTINESWITCH__STATIC:
987
        case FRANKENSTINESWITCH__STATIC:
988
        case LIGHTSWITCH2__STATIC:
988
        case LIGHTSWITCH2__STATIC:
989
        case POWERSWITCH1__STATIC:
989
        case POWERSWITCH1__STATIC:
990
        case LOCKSWITCH1__STATIC:
990
        case LOCKSWITCH1__STATIC:
991
        case POWERSWITCH2__STATIC:
991
        case POWERSWITCH2__STATIC:
992
            for (j=0;j<lotaglist;j++)
992
            for (j=0;j<lotaglist;j++)
993
                if (SLT == lotags[j])
993
                if (SLT == lotags[j])
994
                    break;
994
                    break;
995
995
996
            if (j == lotaglist)
996
            if (j == lotaglist)
997
            {
997
            {
998
                lotags[lotaglist] = SLT;
998
                lotags[lotaglist] = SLT;
999
                lotaglist++;
999
                lotaglist++;
1000
                if (lotaglist > MAXSPRITES-1)
1000
                if (lotaglist > MAXSPRITES-1)
1001
                    gameexit("\nToo many switches.");
1001
                    gameexit("\nToo many switches.");
1002
1002
1003
                j = headspritestat[3];
1003
                j = headspritestat[3];
1004
                while (j >= 0)
1004
                while (j >= 0)
1005
                {
1005
                {
1006
                    if (sprite[j].lotag == 12 && sprite[j].hitag == SLT)
1006
                    if (sprite[j].lotag == 12 && sprite[j].hitag == SLT)
1007
                        hittype[j].temp_data[0] = 1;
1007
                        hittype[j].temp_data[0] = 1;
1008
                    j = nextspritestat[j];
1008
                    j = nextspritestat[j];
1009
                }
1009
                }
1010
            }
1010
            }
1011
            break;
1011
            break;
1012
        }
1012
        }
1013
        i = nextspritestat[i];
1013
        i = nextspritestat[i];
1014
    }
1014
    }
1015
1015
1016
    mirrorcnt = 0;
1016
    mirrorcnt = 0;
1017
1017
1018
    for (i = 0; i < numwalls; i++)
1018
    for (i = 0; i < numwalls; i++)
1019
    {
1019
    {
1020
        walltype *wal;
1020
        walltype *wal;
1021
        wal = &wall[i];
1021
        wal = &wall[i];
1022
1022
1023
        if (wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
1023
        if (wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
1024
        {
1024
        {
1025
            j = wal->nextsector;
1025
            j = wal->nextsector;
1026
1026
1027
            if (mirrorcnt > 63)
1027
            if (mirrorcnt > 63)
1028
                gameexit("\nToo many mirrors (64 max.)");
1028
                gameexit("\nToo many mirrors (64 max.)");
1029
            if ((j >= 0) && sector[j].ceilingpicnum != MIRROR)
1029
            if ((j >= 0) && sector[j].ceilingpicnum != MIRROR)
1030
            {
1030
            {
1031
                sector[j].ceilingpicnum = MIRROR;
1031
                sector[j].ceilingpicnum = MIRROR;
1032
                sector[j].floorpicnum = MIRROR;
1032
                sector[j].floorpicnum = MIRROR;
1033
                mirrorwall[mirrorcnt] = i;
1033
                mirrorwall[mirrorcnt] = i;
1034
                mirrorsector[mirrorcnt] = j;
1034
                mirrorsector[mirrorcnt] = j;
1035
                mirrorcnt++;
1035
                mirrorcnt++;
1036
                continue;
1036
                continue;
1037
            }
1037
            }
1038
        }
1038
        }
1039
1039
1040
        if (numanimwalls >= MAXANIMWALLS)
1040
        if (numanimwalls >= MAXANIMWALLS)
1041
        {
1041
        {
1042
            Bsprintf(tempbuf,"\nToo many 'anim' walls (%d max).",MAXANIMWALLS);
1042
            Bsprintf(tempbuf,"\nToo many 'anim' walls (%d max).",MAXANIMWALLS);
1043
            gameexit(tempbuf);
1043
            gameexit(tempbuf);
1044
        }
1044
        }
1045
1045
1046
        animwall[numanimwalls].tag = 0;
1046
        animwall[numanimwalls].tag = 0;
1047
        animwall[numanimwalls].wallnum = 0;
1047
        animwall[numanimwalls].wallnum = 0;
1048
        switchpicnum = wal->overpicnum;
1048
        switchpicnum = wal->overpicnum;
1049
        if ((wal->overpicnum > W_FORCEFIELD)&&(wal->overpicnum <= W_FORCEFIELD+2))
1049
        if ((wal->overpicnum > W_FORCEFIELD)&&(wal->overpicnum <= W_FORCEFIELD+2))
1050
        {
1050
        {
1051
            switchpicnum = W_FORCEFIELD;
1051
            switchpicnum = W_FORCEFIELD;
1052
        }
1052
        }
1053
        switch (dynamictostatic[switchpicnum])
1053
        switch (dynamictostatic[switchpicnum])
1054
        {
1054
        {
1055
        case FANSHADOW__STATIC:
1055
        case FANSHADOW__STATIC:
1056
        case FANSPRITE__STATIC:
1056
        case FANSPRITE__STATIC:
1057
            wall->cstat |= 65;
1057
            wall->cstat |= 65;
1058
            animwall[numanimwalls].wallnum = i;
1058
            animwall[numanimwalls].wallnum = i;
1059
            numanimwalls++;
1059
            numanimwalls++;
1060
            break;
1060
            break;
1061
1061
1062
        case W_FORCEFIELD__STATIC:
1062
        case W_FORCEFIELD__STATIC:
1063
            if (wal->overpicnum==W_FORCEFIELD__STATIC)
1063
            if (wal->overpicnum==W_FORCEFIELD__STATIC)
1064
                for (j=0;j<3;j++)
1064
                for (j=0;j<3;j++)
1065
                    tloadtile(W_FORCEFIELD+j, 0);
1065
                    tloadtile(W_FORCEFIELD+j, 0);
1066
            if (wal->shade > 31)
1066
            if (wal->shade > 31)
1067
                wal->cstat = 0;
1067
                wal->cstat = 0;
1068
            else wal->cstat |= 85+256;
1068
            else wal->cstat |= 85+256;
1069
1069
1070
1070
1071
            if (wal->lotag && wal->nextwall >= 0)
1071
            if (wal->lotag && wal->nextwall >= 0)
1072
                wall[wal->nextwall].lotag =
1072
                wall[wal->nextwall].lotag =
1073
                    wal->lotag;
1073
                    wal->lotag;
1074
1074
1075
        case BIGFORCE__STATIC:
1075
        case BIGFORCE__STATIC:
1076
1076
1077
            animwall[numanimwalls].wallnum = i;
1077
            animwall[numanimwalls].wallnum = i;
1078
            numanimwalls++;
1078
            numanimwalls++;
1079
1079
1080
            continue;
1080
            continue;
1081
        }
1081
        }
1082
1082
1083
        wal->extra = -1;
1083
        wal->extra = -1;
1084
1084
1085
        switch (dynamictostatic[wal->picnum])
1085
        switch (dynamictostatic[wal->picnum])
1086
        {
1086
        {
1087
        case WATERTILE2__STATIC:
1087
        case WATERTILE2__STATIC:
1088
            for (j=0;j<3;j++)
1088
            for (j=0;j<3;j++)
1089
                tloadtile(wal->picnum+j, 0);
1089
                tloadtile(wal->picnum+j, 0);
1090
            break;
1090
            break;
1091
1091
1092
        case TECHLIGHT2__STATIC:
1092
        case TECHLIGHT2__STATIC:
1093
        case TECHLIGHT4__STATIC:
1093
        case TECHLIGHT4__STATIC:
1094
            tloadtile(wal->picnum, 0);
1094
            tloadtile(wal->picnum, 0);
1095
            break;
1095
            break;
1096
        case W_TECHWALL1__STATIC:
1096
        case W_TECHWALL1__STATIC:
1097
        case W_TECHWALL2__STATIC:
1097
        case W_TECHWALL2__STATIC:
1098
        case W_TECHWALL3__STATIC:
1098
        case W_TECHWALL3__STATIC:
1099
        case W_TECHWALL4__STATIC:
1099
        case W_TECHWALL4__STATIC:
1100
            animwall[numanimwalls].wallnum = i;
1100
            animwall[numanimwalls].wallnum = i;
1101
            //                animwall[numanimwalls].tag = -1;
1101
            //                animwall[numanimwalls].tag = -1;
1102
            numanimwalls++;
1102
            numanimwalls++;
1103
            break;
1103
            break;
1104
        case SCREENBREAK6__STATIC:
1104
        case SCREENBREAK6__STATIC:
1105
        case SCREENBREAK7__STATIC:
1105
        case SCREENBREAK7__STATIC:
1106
        case SCREENBREAK8__STATIC:
1106
        case SCREENBREAK8__STATIC:
1107
            for (j=SCREENBREAK6;j<SCREENBREAK9;j++)
1107
            for (j=SCREENBREAK6;j<SCREENBREAK9;j++)
1108
                tloadtile(j, 0);
1108
                tloadtile(j, 0);
1109
            animwall[numanimwalls].wallnum = i;
1109
            animwall[numanimwalls].wallnum = i;
1110
            animwall[numanimwalls].tag = -1;
1110
            animwall[numanimwalls].tag = -1;
1111
            numanimwalls++;
1111
            numanimwalls++;
1112
            break;
1112
            break;
1113
1113
1114
        case FEMPIC1__STATIC:
1114
        case FEMPIC1__STATIC:
1115
        case FEMPIC2__STATIC:
1115
        case FEMPIC2__STATIC:
1116
        case FEMPIC3__STATIC:
1116
        case FEMPIC3__STATIC:
1117
1117
1118
            wal->extra = wal->picnum;
1118
            wal->extra = wal->picnum;
1119
            animwall[numanimwalls].tag = -1;
1119
            animwall[numanimwalls].tag = -1;
1120
            if (ud.lockout)
1120
            if (ud.lockout)
1121
            {
1121
            {
1122
                if (wal->picnum == FEMPIC1)
1122
                if (wal->picnum == FEMPIC1)
1123
                    wal->picnum = BLANKSCREEN;
1123
                    wal->picnum = BLANKSCREEN;
1124
                else wal->picnum = SCREENBREAK6;
1124
                else wal->picnum = SCREENBREAK6;
1125
            }
1125
            }
1126
1126
1127
            animwall[numanimwalls].wallnum = i;
1127
            animwall[numanimwalls].wallnum = i;
1128
            animwall[numanimwalls].tag = wal->picnum;
1128
            animwall[numanimwalls].tag = wal->picnum;
1129
            numanimwalls++;
1129
            numanimwalls++;
1130
            break;
1130
            break;
1131
1131
1132
        case SCREENBREAK1__STATIC:
1132
        case SCREENBREAK1__STATIC:
1133
        case SCREENBREAK2__STATIC:
1133
        case SCREENBREAK2__STATIC:
1134
        case SCREENBREAK3__STATIC:
1134
        case SCREENBREAK3__STATIC:
1135
        case SCREENBREAK4__STATIC:
1135
        case SCREENBREAK4__STATIC:
1136
        case SCREENBREAK5__STATIC:
1136
        case SCREENBREAK5__STATIC:
1137
1137
1138
        case SCREENBREAK9__STATIC:
1138
        case SCREENBREAK9__STATIC:
1139
        case SCREENBREAK10__STATIC:
1139
        case SCREENBREAK10__STATIC:
1140
        case SCREENBREAK11__STATIC:
1140
        case SCREENBREAK11__STATIC:
1141
        case SCREENBREAK12__STATIC:
1141
        case SCREENBREAK12__STATIC:
1142
        case SCREENBREAK13__STATIC:
1142
        case SCREENBREAK13__STATIC:
1143
        case SCREENBREAK14__STATIC:
1143
        case SCREENBREAK14__STATIC:
1144
        case SCREENBREAK15__STATIC:
1144
        case SCREENBREAK15__STATIC:
1145
        case SCREENBREAK16__STATIC:
1145
        case SCREENBREAK16__STATIC:
1146
        case SCREENBREAK17__STATIC:
1146
        case SCREENBREAK17__STATIC:
1147
        case SCREENBREAK18__STATIC:
1147
        case SCREENBREAK18__STATIC:
1148
        case SCREENBREAK19__STATIC:
1148
        case SCREENBREAK19__STATIC:
1149
1149
1150
            animwall[numanimwalls].wallnum = i;
1150
            animwall[numanimwalls].wallnum = i;
1151
            animwall[numanimwalls].tag = wal->picnum;
1151
            animwall[numanimwalls].tag = wal->picnum;
1152
            numanimwalls++;
1152
            numanimwalls++;
1153
            break;
1153
            break;
1154
        }
1154
        }
1155
    }
1155
    }
1156
1156
1157
    //Invalidate textures in sector behind mirror
1157
    //Invalidate textures in sector behind mirror
1158
    for (i=0;i<mirrorcnt;i++)
1158
    for (i=0;i<mirrorcnt;i++)
1159
    {
1159
    {
1160
        startwall = sector[mirrorsector[i]].wallptr;
1160
        startwall = sector[mirrorsector[i]].wallptr;
1161
        endwall = startwall + sector[mirrorsector[i]].wallnum;
1161
        endwall = startwall + sector[mirrorsector[i]].wallnum;
1162
        for (j=startwall;j<endwall;j++)
1162
        for (j=startwall;j<endwall;j++)
1163
        {
1163
        {
1164
            wall[j].picnum = MIRROR;
1164
            wall[j].picnum = MIRROR;
1165
            wall[j].overpicnum = MIRROR;
1165
            wall[j].overpicnum = MIRROR;
1166
        }
1166
        }
1167
    }
1167
    }
1168
}
1168
}
1169
1169
1170
void newgame(int vn,int ln,int sk)
1170
void newgame(int vn,int ln,int sk)
1171
{
1171
{
1172
    player_struct *p = g_player[0].ps;
1172
    player_struct *p = g_player[0].ps;
1173
    int i;
1173
    int i;
1174
1174
1175
    handleevents();
1175
    handleevents();
1176
    getpackets();
1176
    getpackets();
1177
1177
1178
    if (globalskillsound >= 0 && ud.config.FXDevice >= 0 && ud.config.SoundToggle)
1178
    if (globalskillsound >= 0 && ud.config.FXDevice >= 0 && ud.config.SoundToggle)
1179
    {
1179
    {
1180
        while (issoundplaying(-1,globalskillsound))
1180
        while (issoundplaying(-1,globalskillsound))
1181
        {
1181
        {
1182
            handleevents();
1182
            handleevents();
1183
            getpackets();
1183
            getpackets();
1184
        }
1184
        }
1185
    }
1185
    }
1186
1186
1187
    globalskillsound = -1;
1187
    globalskillsound = -1;
1188
1188
1189
    waitforeverybody();
1189
    waitforeverybody();
1190
    ready2send = 0;
1190
    ready2send = 0;
1191
1191
1192
    if (ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && (ud.coop&GAMETYPE_FLAG_SCORESHEET))
1192
    if (ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && (ud.coop&GAMETYPE_FLAG_SCORESHEET))
1193
        dobonus(1);
1193
        dobonus(1);
1194
1194
1195
    if (ln == 0 && vn == 3 && ud.multimode < 2 && ud.lockout == 0)
1195
    if (ln == 0 && vn == 3 && ud.multimode < 2 && ud.lockout == 0)
1196
    {
1196
    {
1197
        playmusic(&env_music_fn[1][0],MAXVOLUMES*MAXLEVELS+1);
1197
        playmusic(&env_music_fn[1][0],MAXVOLUMES*MAXLEVELS+1);
1198
1198
1199
        flushperms();
1199
        flushperms();
1200
        setview(0,0,xdim-1,ydim-1);
1200
        setview(0,0,xdim-1,ydim-1);
1201
        clearview(0L);
1201
        clearview(0L);
1202
        nextpage();
1202
        nextpage();
1203
1203
1204
        playanm("vol41a.anm",6);
1204
        playanm("vol41a.anm",6);
1205
        clearview(0L);
1205
        clearview(0L);
1206
        nextpage();
1206
        nextpage();
1207
1207
1208
        playanm("vol42a.anm",7);
1208
        playanm("vol42a.anm",7);
1209
        playanm("vol43a.anm",9);
1209
        playanm("vol43a.anm",9);
1210
        clearview(0L);
1210
        clearview(0L);
1211
        nextpage();
1211
        nextpage();
1212
1212
1213
        FX_StopAllSounds();
1213
        FX_StopAllSounds();
1214
    }
1214
    }
1215
1215
1216
    show_shareware = 26*34;
1216
    show_shareware = 26*34;
1217
1217
1218
    ud.level_number =   ln;
1218
    ud.level_number =   ln;
1219
    ud.volume_number =  vn;
1219
    ud.volume_number =  vn;
1220
    ud.player_skill =   sk;
1220
    ud.player_skill =   sk;
1221
    ud.secretlevel =    0;
1221
    ud.secretlevel =    0;
1222
    ud.from_bonus = 0;
1222
    ud.from_bonus = 0;
1223
    parallaxyscale = 0;
1223
    parallaxyscale = 0;
1224
1224
1225
    ud.last_level = -1;
1225
    ud.last_level = -1;
1226
    lastsavedpos = -1;
1226
    lastsavedpos = -1;
1227
    p->zoom            = 768;
1227
    p->zoom            = 768;
1228
    p->gm              = 0;
1228
    p->gm              = 0;
1229
1229
1230
    //AddLog("Newgame");
1230
    //AddLog("Newgame");
1231
    ResetGameVars();
1231
    ResetGameVars();
1232
1232
1233
    InitGameVarPointers();
1233
    InitGameVarPointers();
1234
1234
1235
    ResetSystemDefaults();
1235
    ResetSystemDefaults();
1236
1236
1237
    if (ud.m_coop != 1)
1237
    if (ud.m_coop != 1)
1238
    {
1238
    {
1239
        for (i=0;i<MAX_WEAPONS;i++)
1239
        for (i=0;i<MAX_WEAPONS;i++)
1240
        {
1240
        {
1241
            if (aplWeaponWorksLike[i][0]==PISTOL_WEAPON)
1241
            if (aplWeaponWorksLike[i][0]==PISTOL_WEAPON)
1242
            {
1242
            {
1243
                p->curr_weapon = i;
1243
                p->curr_weapon = i;
1244
                p->gotweapon[i] = 1;
1244
                p->gotweapon[i] = 1;
1245
                p->ammo_amount[i] = 48;
1245
                p->ammo_amount[i] = 48;
1246
            }
1246
            }
1247
            else if (aplWeaponWorksLike[i][0]==KNEE_WEAPON)
1247
            else if (aplWeaponWorksLike[i][0]==KNEE_WEAPON)
1248
                p->gotweapon[i] = 1;
1248
                p->gotweapon[i] = 1;
1249
            else if (aplWeaponWorksLike[i][0]==HANDREMOTE_WEAPON)
1249
            else if (aplWeaponWorksLike[i][0]==HANDREMOTE_WEAPON)
1250
                p->gotweapon[i] = 1;
1250
                p->gotweapon[i] = 1;
1251
        }
1251
        }
1252
        p->last_weapon = -1;
1252
        p->last_weapon = -1;
1253
    }
1253
    }
1254
1254
1255
    display_mirror =        0;
1255
    display_mirror =        0;
1256
1256
1257
    if (ud.multimode > 1)
1257
    if (ud.multimode > 1)
1258
    {
1258
    {
1259
        if (numplayers < 2)
1259
        if (numplayers < 2)
1260
        {
1260
        {
1261
            connecthead = 0;
1261
            connecthead = 0;
1262
            for (i=0;i<MAXPLAYERS;i++) connectpoint2[i] = i+1;
1262
            for (i=0;i<MAXPLAYERS;i++) connectpoint2[i] = i+1;
1263
            connectpoint2[ud.multimode-1] = -1;
1263
            connectpoint2[ud.multimode-1] = -1;
1264
        }
1264
        }
1265
    }
1265
    }
1266
    else
1266
    else
1267
    {
1267
    {
1268
        connecthead = 0;
1268
        connecthead = 0;
1269
        connectpoint2[0] = -1;
1269
        connectpoint2[0] = -1;
1270
    }
1270
    }
1271
}
1271
}
1272
1272
1273
int getteampal(int team)
1273
int getteampal(int team)
1274
{
1274
{
1275
    switch (team)
1275
    switch (team)
1276
    {
1276
    {
1277
    case 0:
1277
    case 0:
1278
        return 3;
1278
        return 3;
1279
    case 1:
1279
    case 1:
1280
        return 10;
1280
        return 10;
1281
    case 2:
1281
    case 2:
1282
        return 11;
1282
        return 11;
1283
    case 3:
1283
    case 3:
1284
        return 12;
1284
        return 12;
1285
    }
1285
    }
1286
    return 0;
1286
    return 0;
1287
}
1287
}
1288
1288
1289
static void resetpspritevars(char g)
1289
static void resetpspritevars(char g)
1290
{
1290
{
1291
    short i, j, nexti,circ;
1291
    short i, j, nexti,circ;
1292
    int firstx,firsty;
1292
    int firstx,firsty;
1293
    spritetype *s;
1293
    spritetype *s;
1294
    char aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
1294
    char aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
1295
    STATUSBARTYPE tsbar[MAXPLAYERS];
1295
    STATUSBARTYPE tsbar[MAXPLAYERS];
1296
1296
1297
    EGS(g_player[0].ps->cursectnum,g_player[0].ps->posx,g_player[0].ps->posy,g_player[0].ps->posz,
1297
    EGS(g_player[0].ps->cursectnum,g_player[0].ps->posx,g_player[0].ps->posy,g_player[0].ps->posz,
1298
        APLAYER,0,0,0,g_player[0].ps->ang,0,0,0,10);
1298
        APLAYER,0,0,0,g_player[0].ps->ang,0,0,0,10);
1299
1299
1300
    if (ud.recstat != 2) for (i=0;i<ud.multimode;i++)
1300
    if (ud.recstat != 2) for (i=0;i<ud.multimode;i++)
1301
        {
1301
        {
1302
            aimmode[i] = g_player[i].ps->aim_mode;
1302
            aimmode[i] = g_player[i].ps->aim_mode;
1303
            autoaim[i] = g_player[i].ps->auto_aim;
1303
            autoaim[i] = g_player[i].ps->auto_aim;
1304
            weaponswitch[i] = g_player[i].ps->weaponswitch;
1304
            weaponswitch[i] = g_player[i].ps->weaponswitch;
1305
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1305
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1306
            {
1306
            {
1307
                for (j=0;j<MAX_WEAPONS;j++)
1307
                for (j=0;j<MAX_WEAPONS;j++)
1308
                {
1308
                {
1309
                    tsbar[i].ammo_amount[j] = g_player[i].ps->ammo_amount[j];
1309
                    tsbar[i].ammo_amount[j] = g_player[i].ps->ammo_amount[j];
1310
                    tsbar[i].gotweapon[j] = g_player[i].ps->gotweapon[j];
1310
                    tsbar[i].gotweapon[j] = g_player[i].ps->gotweapon[j];
1311
                }
1311
                }
1312
1312
1313
                tsbar[i].shield_amount = g_player[i].ps->shield_amount;
1313
                tsbar[i].shield_amount = g_player[i].ps->shield_amount;
1314
                tsbar[i].curr_weapon = g_player[i].ps->curr_weapon;
1314
                tsbar[i].curr_weapon = g_player[i].ps->curr_weapon;
1315
                tsbar[i].inven_icon = g_player[i].ps->inven_icon;
1315
                tsbar[i].inven_icon = g_player[i].ps->inven_icon;
1316
1316
1317
                tsbar[i].firstaid_amount = g_player[i].ps->firstaid_amount;
1317
                tsbar[i].firstaid_amount = g_player[i].ps->firstaid_amount;
1318
                tsbar[i].steroids_amount = g_player[i].ps->steroids_amount;
1318
                tsbar[i].steroids_amount = g_player[i].ps->steroids_amount;
1319
                tsbar[i].holoduke_amount = g_player[i].ps->holoduke_amount;
1319
                tsbar[i].holoduke_amount = g_player[i].ps->holoduke_amount;
1320
                tsbar[i].jetpack_amount = g_player[i].ps->jetpack_amount;
1320
                tsbar[i].jetpack_amount = g_player[i].ps->jetpack_amount;
1321
                tsbar[i].heat_amount = g_player[i].ps->heat_amount;
1321
                tsbar[i].heat_amount = g_player[i].ps->heat_amount;
1322
                tsbar[i].scuba_amount = g_player[i].ps->scuba_amount;
1322
                tsbar[i].scuba_amount = g_player[i].ps->scuba_amount;
1323
                tsbar[i].boot_amount = g_player[i].ps->boot_amount;
1323
                tsbar[i].boot_amount = g_player[i].ps->boot_amount;
1324
            }
1324
            }
1325
        }
1325
        }
1326
1326
1327
    resetplayerstats(0);
1327
    resetplayerstats(0);
1328
1328
1329
    for (i=1;i<ud.multimode;i++)
1329
    for (i=1;i<ud.multimode;i++)
1330
        memcpy(g_player[i].ps,g_player[0].ps,sizeof(player_struct));
1330
        memcpy(g_player[i].ps,g_player[0].ps,sizeof(player_struct));
1331
1331
1332
    if (ud.recstat != 2)
1332
    if (ud.recstat != 2)
1333
        for (i=0;i<ud.multimode;i++)
1333
        for (i=0;i<ud.multimode;i++)
1334
        {
1334
        {
1335
            g_player[i].ps->aim_mode = aimmode[i];
1335
            g_player[i].ps->aim_mode = aimmode[i];
1336
            g_player[i].ps->auto_aim = autoaim[i];
1336
            g_player[i].ps->auto_aim = autoaim[i];
1337
            g_player[i].ps->weaponswitch = weaponswitch[i];
1337
            g_player[i].ps->weaponswitch = weaponswitch[i];
1338
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1338
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1339
            {
1339
            {
1340
                for (j=0;j<MAX_WEAPONS;j++)
1340
                for (j=0;j<MAX_WEAPONS;j++)
1341
                {
1341
                {
1342
                    g_player[i].ps->ammo_amount[j] = tsbar[i].ammo_amount[j];
1342
                    g_player[i].ps->ammo_amount[j] = tsbar[i].ammo_amount[j];
1343
                    g_player[i].ps->gotweapon[j] = tsbar[i].gotweapon[j];
1343
                    g_player[i].ps->gotweapon[j] = tsbar[i].gotweapon[j];
1344
                }
1344
                }
1345
                g_player[i].ps->shield_amount = tsbar[i].shield_amount;
1345
                g_player[i].ps->shield_amount = tsbar[i].shield_amount;
1346
                g_player[i].ps->curr_weapon = tsbar[i].curr_weapon;
1346
                g_player[i].ps->curr_weapon = tsbar[i].curr_weapon;
1347
                g_player[i].ps->inven_icon = tsbar[i].inven_icon;
1347
                g_player[i].ps->inven_icon = tsbar[i].inven_icon;
1348
1348
1349
                g_player[i].ps->firstaid_amount = tsbar[i].firstaid_amount;
1349
                g_player[i].ps->firstaid_amount = tsbar[i].firstaid_amount;
1350
                g_player[i].ps->steroids_amount= tsbar[i].steroids_amount;
1350
                g_player[i].ps->steroids_amount= tsbar[i].steroids_amount;
1351
                g_player[i].ps->holoduke_amount = tsbar[i].holoduke_amount;
1351
                g_player[i].ps->holoduke_amount = tsbar[i].holoduke_amount;
1352
                g_player[i].ps->jetpack_amount = tsbar[i].jetpack_amount;
1352
                g_player[i].ps->jetpack_amount = tsbar[i].jetpack_amount;
1353
                g_player[i].ps->heat_amount = tsbar[i].heat_amount;
1353
                g_player[i].ps->heat_amount = tsbar[i].heat_amount;
1354
                g_player[i].ps->scuba_amount= tsbar[i].scuba_amount;
1354
                g_player[i].ps->scuba_amount= tsbar[i].scuba_amount;
1355
                g_player[i].ps->boot_amount = tsbar[i].boot_amount;
1355
                g_player[i].ps->boot_amount = tsbar[i].boot_amount;
1356
            }
1356
            }
1357
        }
1357
        }
1358
1358
1359
    numplayersprites = 0;
1359
    numplayersprites = 0;
1360
    circ = 2048/ud.multimode;
1360
    circ = 2048/ud.multimode;
1361
1361
1362
    which_palookup = 9;
1362
    which_palookup = 9;
1363
    j = connecthead;
1363
    j = connecthead;
1364
    i = headspritestat[10];
1364
    i = headspritestat[10];
1365
    while (i >= 0)
1365
    while (i >= 0)
1366
    {
1366
    {
1367
        nexti = nextspritestat[i];
1367
        nexti = nextspritestat[i];
1368
        s = &sprite[i];
1368
        s = &sprite[i];
1369
1369
1370
        if (numplayersprites == MAXPLAYERS)
1370
        if (numplayersprites == MAXPLAYERS)
1371
            gameexit("\nToo many player sprites (max 16.)");
1371
            gameexit("\nToo many player sprites (max 16.)");
1372
1372
1373
        if (numplayersprites == 0)
1373
        if (numplayersprites == 0)
1374
        {
1374
        {
1375
            firstx = g_player[0].ps->posx;
1375
            firstx = g_player[0].ps->posx;
1376
            firsty = g_player[0].ps->posy;
1376
            firsty = g_player[0].ps->posy;
1377
        }
1377
        }
1378
1378
1379
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].ox = s->x;
1379
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].ox = s->x;
1380
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oy = s->y;
1380
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oy = s->y;
1381
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oz = s->z;
1381
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oz = s->z;
1382
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oa = s->ang;
1382
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oa = s->ang;
1383
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].os = s->sectnum;
1383
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].os = s->sectnum;
1384
1384
1385
        numplayersprites++;
1385
        numplayersprites++;
1386
        if (j >= 0)
1386
        if (j >= 0)
1387
        {
1387
        {
1388
            s->owner = i;
1388
            s->owner = i;
1389
            s->shade = 0;
1389
            s->shade = 0;
1390
            s->xrepeat = 42;
1390
            s->xrepeat = 42;
1391
            s->yrepeat = 36;
1391
            s->yrepeat = 36;
1392
            s->cstat = 1+256;
1392
            s->cstat = 1+256;
1393
            s->xoffset = 0;
1393
            s->xoffset = 0;
1394
            s->clipdist = 64;
1394
            s->clipdist = 64;
1395
1395
1396
            if ((g&MODE_EOL) != MODE_EOL || g_player[j].ps->last_extra == 0)
1396
            if ((g&MODE_EOL) != MODE_EOL || g_player[j].ps->last_extra == 0)
1397
            {
1397
            {
1398
                g_player[j].ps->last_extra = g_player[j].ps->max_player_health;
1398
                g_player[j].ps->last_extra = g_player[j].ps->max_player_health;
1399
                s->extra = g_player[j].ps->max_player_health;
1399
                s->extra = g_player[j].ps->max_player_health;
1400
                g_player[j].ps->runspeed = dukefriction;
1400
                g_player[j].ps->runspeed = dukefriction;
1401
            }
1401
            }
1402
            else s->extra = g_player[j].ps->last_extra;
1402
            else s->extra = g_player[j].ps->last_extra;
1403
1403
1404
            s->yvel = j;
1404
            s->yvel = j;
1405
1405
1406
            if (!g_player[j].pcolor && ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM))
1406
            if (!g_player[j].pcolor && ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM))
1407
            {
1407
            {
1408
                if (s->pal == 0)
1408
                if (s->pal == 0)
1409
                {
1409
                {
1410
                    int k = 0;
1410
                    int k = 0;
1411
1411
1412
                    for (;k<ud.multimode;k++)
1412
                    for (;k<ud.multimode;k++)
1413
                    {
1413
                    {
1414
                        if (which_palookup == g_player[k].ps->palookup)
1414
                        if (which_palookup == g_player[k].ps->palookup)
1415
                        {
1415
                        {
1416
                            which_palookup++;
1416
                            which_palookup++;
1417
                            if (which_palookup >= 17)
1417
                            if (which_palookup >= 17)
1418
                                which_palookup = 9;
1418
                                which_palookup = 9;
1419
                            k=0;
1419
                            k=0;
1420
                        }
1420
                        }
1421
                    }
1421
                    }
1422
                    g_player[j].pcolor = s->pal = g_player[j].ps->palookup = which_palookup++;
1422
                    g_player[j].pcolor = s->pal = g_player[j].ps->palookup = which_palookup++;
1423
                    if (which_palookup >= 17)
1423
                    if (which_palookup >= 17)
1424
                        which_palookup = 9;
1424
                        which_palookup = 9;
1425
                }
1425
                }
1426
                else g_player[j].pcolor = g_player[j].ps->palookup = s->pal;
1426
                else g_player[j].pcolor = g_player[j].ps->palookup = s->pal;
1427
            }
1427
            }
1428
            else
1428
            else
1429
            {
1429
            {
1430
                int k = g_player[j].pcolor;
1430
                int k = g_player[j].pcolor;
1431
1431
1432
                if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM)
1432
                if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM)
1433
                {
1433
                {
1434
                    k = getteampal(g_player[j].pteam);
1434
                    k = getteampal(g_player[j].pteam);
1435
                    g_player[j].ps->team = g_player[j].pteam;
1435
                    g_player[j].ps->team = g_player[j].pteam;
1436
                }
1436
                }
1437
                s->pal = g_player[j].ps->palookup = k;
1437
                s->pal = g_player[j].ps->palookup = k;
1438
            }
1438
            }
1439
1439
1440
            g_player[j].ps->i = i;
1440
            g_player[j].ps->i = i;
1441
            g_player[j].ps->frag_ps = j;
1441
            g_player[j].ps->frag_ps = j;
1442
            hittype[i].owner = i;
1442
            hittype[i].owner = i;
1443
1443
1444
            hittype[i].bposx = g_player[j].ps->bobposx = g_player[j].ps->oposx = g_player[j].ps->posx =        s->x;
1444
            hittype[i].bposx = g_player[j].ps->bobposx = g_player[j].ps->oposx = g_player[j].ps->posx =        s->x;
1445
            hittype[i].bposy = g_player[j].ps->bobposy = g_player[j].ps->oposy = g_player[j].ps->posy =        s->y;
1445
            hittype[i].bposy = g_player[j].ps->bobposy = g_player[j].ps->oposy = g_player[j].ps->posy =        s->y;
1446
            hittype[i].bposz = g_player[j].ps->oposz = g_player[j].ps->posz =        s->z;
1446
            hittype[i].bposz = g_player[j].ps->oposz = g_player[j].ps->posz =        s->z;
1447
            g_player[j].ps->oang  = g_player[j].ps->ang  =        s->ang;
1447
            g_player[j].ps->oang  = g_player[j].ps->ang  =        s->ang;
1448
1448
1449
            updatesector(s->x,s->y,&g_player[j].ps->cursectnum);
1449
            updatesector(s->x,s->y,&g_player[j].ps->cursectnum);
1450
1450
1451
            j = connectpoint2[j];
1451
            j = connectpoint2[j];
1452
1452
1453
        }
1453
        }
1454
        else deletesprite(i);
1454
        else deletesprite(i);
1455
        i = nexti;
1455
        i = nexti;
1456
    }
1456
    }
1457
}
1457
}
1458
1458
1459
static inline void clearfrags(void)
1459
static inline void clearfrags(void)
1460
{
1460
{
1461
    int i = 0;
1461
    int i = 0;
1462
1462
1463
    while (i<ud.multimode)
1463
    while (i<ud.multimode)
1464
    {
1464
    {
1465
        g_player[i].ps->frag = g_player[i].ps->fraggedself = 0, i++;
1465
        g_player[i].ps->frag = g_player[i].ps->fraggedself = 0, i++;
1466
        clearbufbyte(&g_player[i].frags[0],MAXPLAYERS<<1,0L);
1466
        clearbufbyte(&g_player[i].frags[0],MAXPLAYERS<<1,0L);
1467
    }
1467
    }
1468
}
1468
}
1469
1469
1470
void resettimevars(void)
1470
void resettimevars(void)
1471
{
1471
{
1472
    vel = svel = angvel = horiz = 0;
1472
    vel = svel = angvel = horiz = 0;
1473
1473
1474
    totalclock = 0L;
1474
    totalclock = 0L;
1475
    cloudtotalclock = 0L;
1475
    cloudtotalclock = 0L;
1476
    ototalclock = 0L;
1476
    ototalclock = 0L;
1477
    lockclock = 0L;
1477
    lockclock = 0L;
1478
    ready2send = 1;
1478
    ready2send = 1;
1479
}
1479
}
1480
1480
1481
void waitforeverybody()
1481
void waitforeverybody()
1482
{
1482
{
1483
    int i;
1483
    int i;
1484
1484
1485
    if (numplayers < 2) return;
1485
    if (numplayers < 2) return;
1486
    packbuf[0] = 250;
1486
    packbuf[0] = 250;
1487
    for (i=connecthead;i>=0;i=connectpoint2[i])
1487
    for (i=connecthead;i>=0;i=connectpoint2[i])
1488
    {
1488
    {
1489
        if (i != myconnectindex) sendpacket(i,packbuf,1);
1489
        if (i != myconnectindex) sendpacket(i,packbuf,1);
1490
        if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
1490
        if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
1491
    }
1491
    }
1492
    g_player[myconnectindex].playerreadyflag++;
1492
    g_player[myconnectindex].playerreadyflag++;
1493
1493
1494
    while (1)
1494
    while (1)
1495
    {
1495
    {
1496
#ifdef _WIN32
1496
#ifdef _WIN32
1497
        Sleep(10);
1497
        Sleep(10);
1498
#else
1498
#else
1499
        usleep(10);
1499
        usleep(10);
1500
#endif
1500
#endif
1501
        sampletimer();
1501
        sampletimer();
1502
        handleevents();
1502
        handleevents();
1503
        AudioUpdate();
1503
        AudioUpdate();
1504
1504
1505
        if (quitevent || keystatus[1]) gameexit("");
1505
        if (quitevent || keystatus[1]) gameexit("");
1506
1506
1507
        getpackets();
1507
        getpackets();
1508
1508
1509
        for (i=connecthead;i>=0;i=connectpoint2[i])
1509
        for (i=connecthead;i>=0;i=connectpoint2[i])
1510
        {
1510
        {
1511
            if (g_player[i].playerreadyflag < g_player[myconnectindex].playerreadyflag) break;
1511
            if (g_player[i].playerreadyflag < g_player[myconnectindex].playerreadyflag) break;
1512
            if ((!networkmode) && (myconnectindex != connecthead))
1512
            if ((!networkmode) && (myconnectindex != connecthead))
1513
            {
1513
            {
1514
                i = -1;
1514
                i = -1;
1515
                break;
1515
                break;
1516
            } //slaves in M/S mode only wait for master
1516
            } //slaves in M/S mode only wait for master
1517
1517
1518
        }
1518
        }
1519
        if (i < 0) return;
1519
        if (i < 0) return;
1520
    }
1520
    }
1521
}
1521
}
1522
1522
1523
extern int jump_input;
1523
extern int jump_input;
1524
1524
1525
void clearfifo(void)
1525
void clearfifo(void)
1526
{
1526
{
1527
    int i = 0;
1527
    int i = 0;
1528
1528
1529
    syncvaltail = 0L;
1529
    syncvaltail = 0L;
1530
    syncvaltottail = 0L;
1530
    syncvaltottail = 0L;
1531
    syncstat = 0;
1531
    syncstat = 0;
1532
    bufferjitter = 1;
1532
    bufferjitter = 1;
1533
    mymaxlag = otherminlag = 0;
1533
    mymaxlag = otherminlag = 0;
1534
    jump_input = 0;
1534
    jump_input = 0;
1535
1535
1536
    movefifoplc = movefifosendplc = fakemovefifoplc = 0;
1536
    movefifoplc = movefifosendplc = fakemovefifoplc = 0;
1537
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
1537
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
1538
    otherminlag = mymaxlag = 0;
1538
    otherminlag = mymaxlag = 0;
1539
1539
1540
    clearbufbyte(&loc,sizeof(input),0L);
1540
    clearbufbyte(&loc,sizeof(input),0L);
1541
    clearbufbyte(&inputfifo,sizeof(input)*MOVEFIFOSIZ*MAXPLAYERS,0L);
1541
    clearbufbyte(&inputfifo,sizeof(input)*MOVEFIFOSIZ*MAXPLAYERS,0L);
1542
    for (;i<MAXPLAYERS;i++)
1542
    for (;i<MAXPLAYERS;i++)
1543
    {
1543
    {
1544
//              Bmemset(g_player[i].inputfifo,0,sizeof(g_player[i].inputfifo));
1544
//              Bmemset(g_player[i].inputfifo,0,sizeof(g_player[i].inputfifo));
1545
        if (g_player[i].sync != NULL)
1545
        if (g_player[i].sync != NULL)
1546
            Bmemset(g_player[i].sync,0,sizeof(input));
1546
            Bmemset(g_player[i].sync,0,sizeof(input));
1547
        Bmemset(&g_player[i].movefifoend,0,sizeof(g_player[i].movefifoend));
1547
        Bmemset(&g_player[i].movefifoend,0,sizeof(g_player[i].movefifoend));
1548
        Bmemset(&g_player[i].syncvalhead,0,sizeof(g_player[i].syncvalhead));
1548
        Bmemset(&g_player[i].syncvalhead,0,sizeof(g_player[i].syncvalhead));
1549
        Bmemset(&g_player[i].myminlag,0,sizeof(g_player[i].myminlag));
1549
        Bmemset(&g_player[i].myminlag,0,sizeof(g_player[i].myminlag));
1550
        g_player[i].vote = 0;
1550
        g_player[i].vote = 0;
1551
        g_player[i].gotvote = 0;
1551
        g_player[i].gotvote = 0;
1552
    }
1552
    }
1553
    //    clearbufbyte(playerquitflag,MAXPLAYERS,0x01);
1553
    //    clearbufbyte(playerquitflag,MAXPLAYERS,0x01);
1554
}
1554
}
1555
1555
1556
void resetmys(void)
1556
void resetmys(void)
1557
{
1557
{
1558
    myx = omyx = g_player[myconnectindex].ps->posx;
1558
    myx = omyx = g_player[myconnectindex].ps->posx;
1559
    myy = omyy = g_player[myconnectindex].ps->posy;
1559
    myy = omyy = g_player[myconnectindex].ps->posy;
1560
    myz = omyz = g_player[myconnectindex].ps->posz;
1560
    myz = omyz = g_player[myconnectindex].ps->posz;
1561
    myxvel = myyvel = myzvel = 0;
1561
    myxvel = myyvel = myzvel = 0;
1562
    myang = omyang = g_player[myconnectindex].ps->ang;
1562
    myang = omyang = g_player[myconnectindex].ps->ang;
1563
    myhoriz = omyhoriz = g_player[myconnectindex].ps->horiz;
1563
    myhoriz = omyhoriz = g_player[myconnectindex].ps->horiz;
1564
    myhorizoff = omyhorizoff = g_player[myconnectindex].ps->horizoff;
1564
    myhorizoff = omyhorizoff = g_player[myconnectindex].ps->horizoff;
1565
    mycursectnum = g_player[myconnectindex].ps->cursectnum;
1565
    mycursectnum = g_player[myconnectindex].ps->cursectnum;
1566
    myjumpingcounter = g_player[myconnectindex].ps->jumping_counter;
1566
    myjumpingcounter = g_player[myconnectindex].ps->jumping_counter;
1567
    myjumpingtoggle = g_player[myconnectindex].ps->jumping_toggle;
1567
    myjumpingtoggle = g_player[myconnectindex].ps->jumping_toggle;
1568
    myonground = g_player[myconnectindex].ps->on_ground;
1568
    myonground = g_player[myconnectindex].ps->on_ground;
1569
    myhardlanding = g_player[myconnectindex].ps->hard_landing;
1569
    myhardlanding = g_player[myconnectindex].ps->hard_landing;
1570
    myreturntocenter = g_player[myconnectindex].ps->return_to_center;
1570
    myreturntocenter = g_player[myconnectindex].ps->return_to_center;
1571
}
1571
}
1572
1572
1573
extern int voting, vote_map, vote_episode;
1573
extern int voting, vote_map, vote_episode;
1574
1574
1575
static void getlevelfromfilename(const char *fn, char *volume, char *level)
1575
static void getlevelfromfilename(const char *fn, char *volume, char *level)
1576
{
1576
{
1577
    for (*volume=0;*volume<MAXVOLUMES;(*volume)++)
1577
    for (*volume=0;*volume<MAXVOLUMES;(*volume)++)
1578
    {
1578
    {
1579
        for (*level=0;*level<MAXLEVELS;(*level)++)
1579
        for (*level=0;*level<MAXLEVELS;(*level)++)
1580
        {
1580
        {
1581
            if (map[(*volume*MAXLEVELS)+*level].filename != NULL)
1581
            if (map[(*volume*MAXLEVELS)+*level].filename != NULL)
1582
                if (!Bstrcasecmp(fn, map[(*volume*MAXLEVELS)+*level].filename))
1582
                if (!Bstrcasecmp(fn, map[(*volume*MAXLEVELS)+*level].filename))
1583
                    break;
1583
                    break;
1584
        }
1584
        }
1585
        if (*level != MAXLEVELS)
1585
        if (*level != MAXLEVELS)
1586
            break;
1586
            break;
1587
    }
1587
    }
1588
}
1588
}
1589
1589
1590
int enterlevel(int g)
1590
int enterlevel(int g)
1591
{
1591
{
1592
    int i;
1592
    int i;
1593
    char levname[BMAX_PATH];
1593
    char levname[BMAX_PATH];
1594
1594
1595
    ready2send = 1; // HACK: fetch any leftover p2p sync packets
1595
    ready2send = 1; // HACK: fetch any leftover p2p sync packets
1596
    KB_ClearKeysDown();
1596
    KB_ClearKeysDown();
1597
    handleevents();
1597
    handleevents();
1598
    getpackets();
1598
    getpackets();
1599
    waitforeverybody();
1599
    waitforeverybody();
1600
    ready2send = 0;
1600
    ready2send = 0;
1601
1601
1602
    vote_map = vote_episode = voting = -1;
1602
    vote_map = vote_episode = voting = -1;
1603
1603
1604
    if ((g&MODE_DEMO) != MODE_DEMO) ud.recstat = ud.m_recstat;
1604
    if ((g&MODE_DEMO) != MODE_DEMO) ud.recstat = ud.m_recstat;
1605
    ud.respawn_monsters = ud.m_respawn_monsters;
1605
    ud.respawn_monsters = ud.m_respawn_monsters;
1606
    ud.respawn_items    = ud.m_respawn_items;
1606
    ud.respawn_items    = ud.m_respawn_items;
1607
    ud.respawn_inventory    = ud.m_respawn_inventory;
1607
    ud.respawn_inventory    = ud.m_respawn_inventory;
1608
    ud.monsters_off = ud.m_monsters_off;
1608
    ud.monsters_off = ud.m_monsters_off;
1609
    ud.coop = ud.m_coop;
1609
    ud.coop = ud.m_coop;
1610
    ud.marker = ud.m_marker;
1610
    ud.marker = ud.m_marker;
1611
    ud.ffire = ud.m_ffire;
1611
    ud.ffire = ud.m_ffire;
1612
    ud.noexits = ud.m_noexits;
1612
    ud.noexits = ud.m_noexits;
1613
1613
1614
    if ((g&MODE_DEMO) == 0 && ud.recstat == 2)
1614
    if ((g&MODE_DEMO) == 0 && ud.recstat == 2)
1615
        ud.recstat = 0;
1615
        ud.recstat = 0;
1616
1616
1617
    FX_StopAllSounds();
1617
    FX_StopAllSounds();
1618
    clearsoundlocks();
1618
    clearsoundlocks();
1619
    FX_SetReverb(0);
1619
    FX_SetReverb(0);
1620
1620
1621
    if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1621
    if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1622
    {
1622
    {
1623
        char volume, level;
1623
        char volume, level;
1624
1624
1625
        Bcorrectfilename(boardfilename,0);
1625
        Bcorrectfilename(boardfilename,0);
1626
1626
1627
        getlevelfromfilename(boardfilename,&volume,&level);
1627
        getlevelfromfilename(boardfilename,&volume,&level);
1628
1628
1629
        if (level != MAXLEVELS)
1629
        if (level != MAXLEVELS)
1630
        {
1630
        {
1631
            ud.level_number = ud.m_level_number = level;
1631
            ud.level_number = ud.m_level_number = level;
1632
            ud.volume_number = ud.m_volume_number = volume;
1632
            ud.volume_number = ud.m_volume_number = volume;
1633
            boardfilename[0] = 0;
1633
            boardfilename[0] = 0;
1634
        }
1634
        }
1635
    }
1635
    }
1636
1636
1637
    if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL || map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
1637
    if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL || map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
1638
    {
1638
    {
1639
        if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1639
        if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1640
        {
1640
        {
1641
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
1641
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
1642
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename = Bcalloc(BMAX_PATH,sizeof(char));
1642
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename = Bcalloc(BMAX_PATH,sizeof(char));
1643
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL)
1643
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL)
1644
            {
1644
            {
1645
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].name = Bcalloc(9,sizeof(char));
1645
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].name = Bcalloc(16,sizeof(char));
1646
                Bsprintf(map[(ud.volume_number*MAXLEVELS)+ud.level_number].name,"USER MAP");
1646
                Bsprintf(map[(ud.volume_number*MAXLEVELS)+ud.level_number].name,"USER MAP");
1647
            }
1647
            }
1648
        }
1648
        }
1649
        else
1649
        else
1650
        {
1650
        {
1651
            initprintf("Map E%dL%d not defined!\n",ud.volume_number