Subversion Repositories eduke32

Rev

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

Rev 4986 Rev 4987
1
//-------------------------------------------------------------------------
1
//-------------------------------------------------------------------------
2
/*
2
/*
3
Copyright (C) 2010 EDuke32 developers and contributors
3
Copyright (C) 2010 EDuke32 developers and contributors
4

4

5
This file is part of EDuke32.
5
This file is part of EDuke32.
6

6

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

10

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

14

15
See the GNU General Public License for more details.
15
See the GNU General Public License for more details.
16

16

17
You should have received a copy of the GNU General Public License
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
*/
20
*/
21
//-------------------------------------------------------------------------
21
//-------------------------------------------------------------------------
22
22
23
#include "duke3d.h"
23
#include "duke3d.h"
24
#include "game.h"
24
#include "game.h"
25
#include "common_game.h"
25
#include "common_game.h"
26
#include "osd.h"
26
#include "osd.h"
27
#include "gamedef.h"
27
#include "gamedef.h"
28
#include "premap.h"
28
#include "premap.h"
29
#include "sounds.h"
29
#include "sounds.h"
30
#include "fx_man.h"
30
#include "fx_man.h"
31
#include "gameexec.h"
31
#include "gameexec.h"
32
#include "anim.h"
32
#include "anim.h"
33
#include "menus.h"
33
#include "menus.h"
34
#include "demo.h"
34
#include "demo.h"
35
35
36
#ifdef LUNATIC
36
#ifdef LUNATIC
37
# include "lunatic_game.h"
37
# include "lunatic_game.h"
38
#endif
38
#endif
39
39
40
halfdimen_t g_halfScreen;
40
halfdimen_t g_halfScreen;
41
int32_t g_halveScreenArea = 0;
41
int32_t g_halveScreenArea = 0;
42
42
43
static int32_t g_whichPalForPlayer = 9;
43
static int32_t g_whichPalForPlayer = 9;
44
44
45
static uint8_t precachehightile[2][MAXTILES>>3];
45
static uint8_t precachehightile[2][MAXTILES>>3];
46
static int32_t  g_precacheCount;
46
static int32_t  g_precacheCount;
47
47
48
extern int32_t g_levelTextTime;
48
extern int32_t g_levelTextTime;
49
49
50
static void flag_precache(int32_t tile, int32_t type)
50
static void flag_precache(int32_t tile, int32_t type)
51
{
51
{
52
    if (!(gotpic[tile>>3] & pow2char[tile&7]))
52
    if (!(gotpic[tile>>3] & pow2char[tile&7]))
53
        g_precacheCount++;
53
        g_precacheCount++;
54
    gotpic[tile>>3] |= pow2char[tile&7];
54
    gotpic[tile>>3] |= pow2char[tile&7];
55
    precachehightile[type][tile>>3] |= pow2char[tile&7];
55
    precachehightile[type][tile>>3] |= pow2char[tile&7];
56
}
56
}
57
57
58
static void tloadtile(int32_t tilenume, int32_t type)
58
static void tloadtile(int32_t tilenume, int32_t type)
59
{
59
{
60
    int32_t i,j;
60
    int32_t i,j;
61
61
62
    if ((picanm[tilenume].sf&PICANM_ANIMTYPE_MASK)==PICANM_ANIMTYPE_BACK)
62
    if ((picanm[tilenume].sf&PICANM_ANIMTYPE_MASK)==PICANM_ANIMTYPE_BACK)
63
    {
63
    {
64
        i = tilenume - picanm[tilenume].num;
64
        i = tilenume - picanm[tilenume].num;
65
        j = tilenume;
65
        j = tilenume;
66
    }
66
    }
67
    else
67
    else
68
    {
68
    {
69
        i = tilenume;
69
        i = tilenume;
70
        j = tilenume + picanm[tilenume].num;
70
        j = tilenume + picanm[tilenume].num;
71
    }
71
    }
72
72
73
    for (; i<=j; i++)
73
    for (; i<=j; i++)
74
        flag_precache(i, type);
74
        flag_precache(i, type);
75
}
75
}
76
76
77
static void G_CacheSpriteNum(int32_t i)
77
static void G_CacheSpriteNum(int32_t i)
78
{
78
{
79
    char maxc;
79
    char maxc;
80
    int32_t j;
80
    int32_t j;
81
81
82
    if (ud.monsters_off && A_CheckEnemySprite(&sprite[i])) return;
82
    if (ud.monsters_off && A_CheckEnemySprite(&sprite[i])) return;
83
83
84
    maxc = 1;
84
    maxc = 1;
85
85
86
    for (j = PN; j <= g_tile[PN].cacherange; j++)
86
    for (j = PN; j <= g_tile[PN].cacherange; j++)
87
        tloadtile(j,1);
87
        tloadtile(j,1);
88
88
89
    switch (DYNAMICTILEMAP(PN))
89
    switch (DYNAMICTILEMAP(PN))
90
    {
90
    {
91
    case HYDRENT__STATIC:
91
    case HYDRENT__STATIC:
92
        tloadtile(BROKEFIREHYDRENT,1);
92
        tloadtile(BROKEFIREHYDRENT,1);
93
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
93
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
94
        break;
94
        break;
95
    case TOILET__STATIC:
95
    case TOILET__STATIC:
96
        tloadtile(TOILETBROKE,1);
96
        tloadtile(TOILETBROKE,1);
97
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
97
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
98
        break;
98
        break;
99
    case STALL__STATIC:
99
    case STALL__STATIC:
100
        tloadtile(STALLBROKE,1);
100
        tloadtile(STALLBROKE,1);
101
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
101
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
102
        break;
102
        break;
103
    case RUBBERCAN__STATIC:
103
    case RUBBERCAN__STATIC:
104
        maxc = 2;
104
        maxc = 2;
105
        break;
105
        break;
106
    case TOILETWATER__STATIC:
106
    case TOILETWATER__STATIC:
107
        maxc = 4;
107
        maxc = 4;
108
        break;
108
        break;
109
    case FEMPIC1__STATIC:
109
    case FEMPIC1__STATIC:
110
        maxc = 44;
110
        maxc = 44;
111
        break;
111
        break;
112
    case LIZTROOP__STATIC:
112
    case LIZTROOP__STATIC:
113
    case LIZTROOPRUNNING__STATIC:
113
    case LIZTROOPRUNNING__STATIC:
114
    case LIZTROOPSHOOT__STATIC:
114
    case LIZTROOPSHOOT__STATIC:
115
    case LIZTROOPJETPACK__STATIC:
115
    case LIZTROOPJETPACK__STATIC:
116
    case LIZTROOPONTOILET__STATIC:
116
    case LIZTROOPONTOILET__STATIC:
117
    case LIZTROOPDUCKING__STATIC:
117
    case LIZTROOPDUCKING__STATIC:
118
        for (j = LIZTROOP; j < (LIZTROOP+72); j++) tloadtile(j,1);
118
        for (j = LIZTROOP; j < (LIZTROOP+72); j++) tloadtile(j,1);
119
        for (j=HEADJIB1; j<LEGJIB1+3; j++) tloadtile(j,1);
119
        for (j=HEADJIB1; j<LEGJIB1+3; j++) tloadtile(j,1);
120
        maxc = 0;
120
        maxc = 0;
121
        break;
121
        break;
122
    case WOODENHORSE__STATIC:
122
    case WOODENHORSE__STATIC:
123
        maxc = 5;
123
        maxc = 5;
124
        for (j = HORSEONSIDE; j < (HORSEONSIDE+4); j++) tloadtile(j,1);
124
        for (j = HORSEONSIDE; j < (HORSEONSIDE+4); j++) tloadtile(j,1);
125
        break;
125
        break;
126
    case NEWBEAST__STATIC:
126
    case NEWBEAST__STATIC:
127
    case NEWBEASTSTAYPUT__STATIC:
127
    case NEWBEASTSTAYPUT__STATIC:
128
        maxc = 90;
128
        maxc = 90;
129
        break;
129
        break;
130
    case BOSS1__STATIC:
130
    case BOSS1__STATIC:
131
    case BOSS2__STATIC:
131
    case BOSS2__STATIC:
132
    case BOSS3__STATIC:
132
    case BOSS3__STATIC:
133
        maxc = 30;
133
        maxc = 30;
134
        break;
134
        break;
135
    case OCTABRAIN__STATIC:
135
    case OCTABRAIN__STATIC:
136
    case OCTABRAINSTAYPUT__STATIC:
136
    case OCTABRAINSTAYPUT__STATIC:
137
    case COMMANDER__STATIC:
137
    case COMMANDER__STATIC:
138
    case COMMANDERSTAYPUT__STATIC:
138
    case COMMANDERSTAYPUT__STATIC:
139
        maxc = 38;
139
        maxc = 38;
140
        break;
140
        break;
141
    case RECON__STATIC:
141
    case RECON__STATIC:
142
        maxc = 13;
142
        maxc = 13;
143
        break;
143
        break;
144
    case PIGCOP__STATIC:
144
    case PIGCOP__STATIC:
145
    case PIGCOPDIVE__STATIC:
145
    case PIGCOPDIVE__STATIC:
146
        maxc = 61;
146
        maxc = 61;
147
        break;
147
        break;
148
    case SHARK__STATIC:
148
    case SHARK__STATIC:
149
        maxc = 30;
149
        maxc = 30;
150
        break;
150
        break;
151
    case LIZMAN__STATIC:
151
    case LIZMAN__STATIC:
152
    case LIZMANSPITTING__STATIC:
152
    case LIZMANSPITTING__STATIC:
153
    case LIZMANFEEDING__STATIC:
153
    case LIZMANFEEDING__STATIC:
154
    case LIZMANJUMP__STATIC:
154
    case LIZMANJUMP__STATIC:
155
        for (j=LIZMANHEAD1; j<LIZMANLEG1+3; j++) tloadtile(j,1);
155
        for (j=LIZMANHEAD1; j<LIZMANLEG1+3; j++) tloadtile(j,1);
156
        maxc = 80;
156
        maxc = 80;
157
        break;
157
        break;
158
    case APLAYER__STATIC:
158
    case APLAYER__STATIC:
159
        maxc = 0;
159
        maxc = 0;
160
        if ((g_netServer || ud.multimode > 1))
160
        if ((g_netServer || ud.multimode > 1))
161
        {
161
        {
162
            maxc = 5;
162
            maxc = 5;
163
            for (j = 1420; j < 1420+106; j++) tloadtile(j,1);
163
            for (j = 1420; j < 1420+106; j++) tloadtile(j,1);
164
        }
164
        }
165
        break;
165
        break;
166
    case ATOMICHEALTH__STATIC:
166
    case ATOMICHEALTH__STATIC:
167
        maxc = 14;
167
        maxc = 14;
168
        break;
168
        break;
169
    case DRONE__STATIC:
169
    case DRONE__STATIC:
170
        maxc = 10;
170
        maxc = 10;
171
        break;
171
        break;
172
    case EXPLODINGBARREL__STATIC:
172
    case EXPLODINGBARREL__STATIC:
173
    case SEENINE__STATIC:
173
    case SEENINE__STATIC:
174
    case OOZFILTER__STATIC:
174
    case OOZFILTER__STATIC:
175
        maxc = 3;
175
        maxc = 3;
176
        break;
176
        break;
177
    case NUKEBARREL__STATIC:
177
    case NUKEBARREL__STATIC:
178
    case CAMERA1__STATIC:
178
    case CAMERA1__STATIC:
179
        maxc = 5;
179
        maxc = 5;
180
        break;
180
        break;
181
        // caching of HUD sprites for weapons that may be in the level
181
        // caching of HUD sprites for weapons that may be in the level
182
    case CHAINGUNSPRITE__STATIC:
182
    case CHAINGUNSPRITE__STATIC:
183
        for (j=CHAINGUN; j<=CHAINGUN+7; j++) tloadtile(j,1);
183
        for (j=CHAINGUN; j<=CHAINGUN+7; j++) tloadtile(j,1);
184
        break;
184
        break;
185
    case RPGSPRITE__STATIC:
185
    case RPGSPRITE__STATIC:
186
        for (j=RPGGUN; j<=RPGGUN+2; j++) tloadtile(j,1);
186
        for (j=RPGGUN; j<=RPGGUN+2; j++) tloadtile(j,1);
187
        break;
187
        break;
188
    case FREEZESPRITE__STATIC:
188
    case FREEZESPRITE__STATIC:
189
        for (j=FREEZE; j<=FREEZE+5; j++) tloadtile(j,1);
189
        for (j=FREEZE; j<=FREEZE+5; j++) tloadtile(j,1);
190
        break;
190
        break;
191
    case GROWSPRITEICON__STATIC:
191
    case GROWSPRITEICON__STATIC:
192
    case SHRINKERSPRITE__STATIC:
192
    case SHRINKERSPRITE__STATIC:
193
        for (j=SHRINKER-2; j<=SHRINKER+5; j++) tloadtile(j,1);
193
        for (j=SHRINKER-2; j<=SHRINKER+5; j++) tloadtile(j,1);
194
        break;
194
        break;
195
    case HBOMBAMMO__STATIC:
195
    case HBOMBAMMO__STATIC:
196
    case HEAVYHBOMB__STATIC:
196
    case HEAVYHBOMB__STATIC:
197
        for (j=HANDREMOTE; j<=HANDREMOTE+5; j++) tloadtile(j,1);
197
        for (j=HANDREMOTE; j<=HANDREMOTE+5; j++) tloadtile(j,1);
198
        break;
198
        break;
199
    case TRIPBOMBSPRITE__STATIC:
199
    case TRIPBOMBSPRITE__STATIC:
200
        for (j=HANDHOLDINGLASER; j<=HANDHOLDINGLASER+4; j++) tloadtile(j,1);
200
        for (j=HANDHOLDINGLASER; j<=HANDHOLDINGLASER+4; j++) tloadtile(j,1);
201
        break;
201
        break;
202
    case SHOTGUNSPRITE__STATIC:
202
    case SHOTGUNSPRITE__STATIC:
203
        tloadtile(SHOTGUNSHELL,1);
203
        tloadtile(SHOTGUNSHELL,1);
204
        for (j=SHOTGUN; j<=SHOTGUN+6; j++) tloadtile(j,1);
204
        for (j=SHOTGUN; j<=SHOTGUN+6; j++) tloadtile(j,1);
205
        break;
205
        break;
206
    case DEVISTATORSPRITE__STATIC:
206
    case DEVISTATORSPRITE__STATIC:
207
        for (j=DEVISTATOR; j<=DEVISTATOR+1; j++) tloadtile(j,1);
207
        for (j=DEVISTATOR; j<=DEVISTATOR+1; j++) tloadtile(j,1);
208
        break;
208
        break;
209
209
210
    }
210
    }
211
211
212
    for (j = PN; j < (PN+maxc); j++) tloadtile(j,1);
212
    for (j = PN; j < (PN+maxc); j++) tloadtile(j,1);
213
}
213
}
214
214
215
static void G_PrecacheSprites(void)
215
static void G_PrecacheSprites(void)
216
{
216
{
217
    int32_t i,j;
217
    int32_t i,j;
218
218
219
    for (i=0; i<MAXTILES; i++)
219
    for (i=0; i<MAXTILES; i++)
220
    {
220
    {
221
        if (g_tile[i].flags & SFLAG_PROJECTILE)
221
        if (g_tile[i].flags & SFLAG_PROJECTILE)
222
            tloadtile(i,1);
222
            tloadtile(i,1);
223
223
224
        if (A_CheckSpriteTileFlags(i, SFLAG_CACHE))
224
        if (A_CheckSpriteTileFlags(i, SFLAG_CACHE))
225
            for (j = i; j <= g_tile[i].cacherange; j++)
225
            for (j = i; j <= g_tile[i].cacherange; j++)
226
                tloadtile(j,1);
226
                tloadtile(j,1);
227
    }
227
    }
228
    tloadtile(BOTTOMSTATUSBAR,1);
228
    tloadtile(BOTTOMSTATUSBAR,1);
229
    if ((g_netServer || ud.multimode > 1))
229
    if ((g_netServer || ud.multimode > 1))
230
        tloadtile(FRAGBAR,1);
230
        tloadtile(FRAGBAR,1);
231
231
232
    tloadtile(VIEWSCREEN,1);
232
    tloadtile(VIEWSCREEN,1);
233
233
234
    for (i=STARTALPHANUM; i<ENDALPHANUM+1; i++) tloadtile(i,1);
234
    for (i=STARTALPHANUM; i<ENDALPHANUM+1; i++) tloadtile(i,1);
235
    for (i=BIGALPHANUM-11; i<BIGALPHANUM+82; i++) tloadtile(i,1);
235
    for (i=BIGALPHANUM-11; i<BIGALPHANUM+82; i++) tloadtile(i,1);
236
    for (i=MINIFONT; i<MINIFONT+93; i++) tloadtile(i,1);
236
    for (i=MINIFONT; i<MINIFONT+93; i++) tloadtile(i,1);
237
237
238
    for (i=FOOTPRINTS; i<FOOTPRINTS+3; i++) tloadtile(i,1);
238
    for (i=FOOTPRINTS; i<FOOTPRINTS+3; i++) tloadtile(i,1);
239
239
240
    for (i = BURNING; i < BURNING+14; i++) tloadtile(i,1);
240
    for (i = BURNING; i < BURNING+14; i++) tloadtile(i,1);
241
    for (i = BURNING2; i < BURNING2+14; i++) tloadtile(i,1);
241
    for (i = BURNING2; i < BURNING2+14; i++) tloadtile(i,1);
242
242
243
    for (i = CRACKKNUCKLES; i < CRACKKNUCKLES+4; i++) tloadtile(i,1);
243
    for (i = CRACKKNUCKLES; i < CRACKKNUCKLES+4; i++) tloadtile(i,1);
244
244
245
    for (i = FIRSTGUN; i < FIRSTGUN+3 ; i++) tloadtile(i,1);
245
    for (i = FIRSTGUN; i < FIRSTGUN+3 ; i++) tloadtile(i,1);
246
    for (i = FIRSTGUNRELOAD; i < FIRSTGUNRELOAD+8 ; i++) tloadtile(i,1);
246
    for (i = FIRSTGUNRELOAD; i < FIRSTGUNRELOAD+8 ; i++) tloadtile(i,1);
247
247
248
    for (i = EXPLOSION2; i < EXPLOSION2+21 ; i++) tloadtile(i,1);
248
    for (i = EXPLOSION2; i < EXPLOSION2+21 ; i++) tloadtile(i,1);
249
249
250
    for (i = COOLEXPLOSION1; i < COOLEXPLOSION1+21 ; i++) tloadtile(i,1);
250
    for (i = COOLEXPLOSION1; i < COOLEXPLOSION1+21 ; i++) tloadtile(i,1);
251
251
252
    tloadtile(BULLETHOLE,1);
252
    tloadtile(BULLETHOLE,1);
253
    tloadtile(BLOODPOOL,1);
253
    tloadtile(BLOODPOOL,1);
254
    for (i = TRANSPORTERBEAM; i < (TRANSPORTERBEAM+6); i++) tloadtile(i,1);
254
    for (i = TRANSPORTERBEAM; i < (TRANSPORTERBEAM+6); i++) tloadtile(i,1);
255
255
256
    for (i = SMALLSMOKE; i < (SMALLSMOKE+4); i++) tloadtile(i,1);
256
    for (i = SMALLSMOKE; i < (SMALLSMOKE+4); i++) tloadtile(i,1);
257
    for (i = SHOTSPARK1; i < (SHOTSPARK1+4); i++) tloadtile(i,1);
257
    for (i = SHOTSPARK1; i < (SHOTSPARK1+4); i++) tloadtile(i,1);
258
258
259
    for (i = BLOOD; i < (BLOOD+4); i++) tloadtile(i,1);
259
    for (i = BLOOD; i < (BLOOD+4); i++) tloadtile(i,1);
260
    for (i = JIBS1; i < (JIBS5+5); i++) tloadtile(i,1);
260
    for (i = JIBS1; i < (JIBS5+5); i++) tloadtile(i,1);
261
    for (i = JIBS6; i < (JIBS6+8); i++) tloadtile(i,1);
261
    for (i = JIBS6; i < (JIBS6+8); i++) tloadtile(i,1);
262
262
263
    for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
263
    for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
264
264
265
    tloadtile(FIRELASER,1);
265
    tloadtile(FIRELASER,1);
266
    for (i=TRANSPORTERSTAR; i<TRANSPORTERSTAR+6; i++) tloadtile(i,1);
266
    for (i=TRANSPORTERSTAR; i<TRANSPORTERSTAR+6; i++) tloadtile(i,1);
267
    for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
267
    for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
268
268
269
    for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
269
    for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
270
270
271
    for (i=RPG; i<RPG+7; i++) tloadtile(i,1);
271
    for (i=RPG; i<RPG+7; i++) tloadtile(i,1);
272
    for (i=FREEZEBLAST; i<FREEZEBLAST+3; i++) tloadtile(i,1);
272
    for (i=FREEZEBLAST; i<FREEZEBLAST+3; i++) tloadtile(i,1);
273
    for (i=SHRINKSPARK; i<SHRINKSPARK+4; i++) tloadtile(i,1);
273
    for (i=SHRINKSPARK; i<SHRINKSPARK+4; i++) tloadtile(i,1);
274
    for (i=GROWSPARK; i<GROWSPARK+4; i++) tloadtile(i,1);
274
    for (i=GROWSPARK; i<GROWSPARK+4; i++) tloadtile(i,1);
275
    for (i=SHRINKEREXPLOSION; i<SHRINKEREXPLOSION+4; i++) tloadtile(i,1);
275
    for (i=SHRINKEREXPLOSION; i<SHRINKEREXPLOSION+4; i++) tloadtile(i,1);
276
    for (i=MORTER; i<MORTER+4; i++) tloadtile(i,1);
276
    for (i=MORTER; i<MORTER+4; i++) tloadtile(i,1);
277
    for (i=0; i<=60; i++) tloadtile(i,1);
277
    for (i=0; i<=60; i++) tloadtile(i,1);
278
}
278
}
279
279
280
// FIXME: this function is a piece of shit, needs specific sounds listed
280
// FIXME: this function is a piece of shit, needs specific sounds listed
281
static int32_t G_CacheSound(uint32_t num)
281
static int32_t G_CacheSound(uint32_t num)
282
{
282
{
283
    int16_t fp = -1;
283
    int16_t fp = -1;
284
    int32_t   l;
284
    int32_t   l;
285
285
286
    if (num >= MAXSOUNDS || !ud.config.SoundToggle) return 0;
286
    if (num >= MAXSOUNDS || !ud.config.SoundToggle) return 0;
287
287
288
    if (EDUKE32_PREDICT_FALSE(!g_sounds[num].filename)) return 0;
288
    if (EDUKE32_PREDICT_FALSE(!g_sounds[num].filename)) return 0;
289
289
290
#if defined HAVE_FLAC || defined HAVE_VORBIS
290
#if defined HAVE_FLAC || defined HAVE_VORBIS
291
    fp = S_UpgradeFormat(g_sounds[num].filename, g_loadFromGroupOnly);
291
    fp = S_UpgradeFormat(g_sounds[num].filename, g_loadFromGroupOnly);
292
    if (fp == -1)
292
    if (fp == -1)
293
#endif
293
#endif
294
        fp = kopen4loadfrommod(g_sounds[num].filename,g_loadFromGroupOnly);
294
        fp = kopen4loadfrommod(g_sounds[num].filename,g_loadFromGroupOnly);
295
    if (fp == -1)
295
    if (fp == -1)
296
    {
296
    {
297
//        OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
297
//        OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
298
        return 0;
298
        return 0;
299
    }
299
    }
300
300
301
    l = kfilelength(fp);
301
    l = kfilelength(fp);
302
    g_sounds[num].soundsiz = l;
302
    g_sounds[num].soundsiz = l;
303
303
304
    if ((ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17)) ||
304
    if ((ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17)) ||
305
            (l < 12288))
305
            (l < 12288))
306
    {
306
    {
307
        g_soundlocks[num] = 199;
307
        g_soundlocks[num] = 199;
308
        allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_soundlocks[num]);
308
        allocache((intptr_t *)&g_sounds[num].ptr,l,(char *)&g_soundlocks[num]);
309
        if (g_sounds[num].ptr != NULL)
309
        if (g_sounds[num].ptr != NULL)
310
            kread(fp, g_sounds[num].ptr , l);
310
            kread(fp, g_sounds[num].ptr , l);
311
    }
311
    }
312
    kclose(fp);
312
    kclose(fp);
313
    return 1;
313
    return 1;
314
}
314
}
315
315
316
static void G_PrecacheSounds(void)
316
static void G_PrecacheSounds(void)
317
{
317
{
318
    int32_t i, j = 0;
318
    int32_t i, j = 0;
319
319
320
    for (i=MAXSOUNDS-1; i>=0; i--)
320
    for (i=MAXSOUNDS-1; i>=0; i--)
321
        if (g_sounds[i].ptr == 0)
321
        if (g_sounds[i].ptr == 0)
322
        {
322
        {
323
            j++;
323
            j++;
324
            if ((j&7) == 0)
324
            if ((j&7) == 0)
325
                G_HandleAsync();
325
                G_HandleAsync();
326
326
327
            G_CacheSound(i);
327
            G_CacheSound(i);
328
        }
328
        }
329
}
329
}
330
330
331
static void G_DoLoadScreen(const char *statustext, int32_t percent)
331
static void G_DoLoadScreen(const char *statustext, int32_t percent)
332
{
332
{
333
    int32_t i=0,j;
333
    int32_t i=0,j;
334
334
335
    if (ud.recstat != 2)
335
    if (ud.recstat != 2)
336
    {
336
    {
337
        j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN);
337
        j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN);
338
338
339
        //g_player[myconnectindex].ps->palette = palette;
339
        //g_player[myconnectindex].ps->palette = palette;
340
        P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 1);    // JBF 20040308
340
        P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 1);    // JBF 20040308
341
341
342
        if (!statustext)
342
        if (!statustext)
343
        {
343
        {
344
            i = ud.screen_size;
344
            i = ud.screen_size;
345
            ud.screen_size = 0;
345
            ud.screen_size = 0;
346
            G_UpdateScreenArea();
346
            G_UpdateScreenArea();
347
            clearallviews(0L);
347
            clearallviews(0L);
348
        }
348
        }
349
349
350
        if ((uint32_t)j < 2*MAXTILES)
350
        if ((uint32_t)j < 2*MAXTILES)
351
        {
351
        {
352
            clearallviews(0);
352
            clearallviews(0);
353
353
354
            rotatesprite_fs(320<<15,200<<15,65536L,0, j > MAXTILES-1?j-MAXTILES:j,0,0,
354
            rotatesprite_fs(320<<15,200<<15,65536L,0, j > MAXTILES-1?j-MAXTILES:j,0,0,
355
                            2+8+64+BGSTRETCH);
355
                            2+8+64+BGSTRETCH);
356
        }
356
        }
357
        else
357
        else
358
        {
358
        {
359
            nextpage();
359
            nextpage();
360
            return;
360
            return;
361
        }
361
        }
362
362
363
        if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
363
        if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
364
        {
364
        {
365
            menutext(160,90,0,0,"Loading User Map");
365
            menutext(160,90,0,0,"Loading User Map");
366
            gametextpal(160,90+10,boardfilename,14,2);
366
            gametextpal(160,90+10,boardfilename,14,2);
367
        }
367
        }
368
        else
368
        else
369
        {
369
        {
370
            menutext(160,90,0,0,"Loading");
370
            menutext(160,90,0,0,"Loading");
371
            if (MapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
371
            if (MapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
372
                menutext(160,90+16+8,0,0,MapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
372
                menutext(160,90+16+8,0,0,MapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
373
        }
373
        }
374
374
375
        if (statustext) gametext(160,180,statustext,0,2+8+16);
375
        if (statustext) gametext(160,180,statustext,0,2+8+16);
376
376
377
        if (percent != -1)
377
        if (percent != -1)
378
        {
378
        {
379
            int32_t ii = scale(scale(xdim-1,288,320),percent,100);
379
            int32_t ii = scale(scale(xdim-1,288,320),percent,100);
380
            rotatesprite(31<<16,145<<16,65536,0,929,15,0,2+8+16,0,0,ii,ydim-1);
380
            rotatesprite(31<<16,145<<16,65536,0,929,15,0,2+8+16,0,0,ii,ydim-1);
381
            rotatesprite(159<<16,145<<16,65536,0,929,15,0,2+8+16,0,0,ii,ydim-1);
381
            rotatesprite(159<<16,145<<16,65536,0,929,15,0,2+8+16,0,0,ii,ydim-1);
382
            rotatesprite(30<<16,144<<16,65536,0,929,0,0,2+8+16,0,0,ii,ydim-1);
382
            rotatesprite(30<<16,144<<16,65536,0,929,0,0,2+8+16,0,0,ii,ydim-1);
383
            rotatesprite(158<<16,144<<16,65536,0,929,0,0,2+8+16,0,0,ii,ydim-1);
383
            rotatesprite(158<<16,144<<16,65536,0,929,0,0,2+8+16,0,0,ii,ydim-1);
384
        }
384
        }
385
385
386
        VM_OnEventWithReturn(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, percent);
386
        VM_OnEventWithReturn(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, percent);
387
        nextpage();
387
        nextpage();
388
388
389
        if (!statustext)
389
        if (!statustext)
390
        {
390
        {
391
            KB_FlushKeyboardQueue();
391
            KB_FlushKeyboardQueue();
392
            ud.screen_size = i;
392
            ud.screen_size = i;
393
        }
393
        }
394
    }
394
    }
395
    else
395
    else
396
    {
396
    {
397
        if (!statustext)
397
        if (!statustext)
398
        {
398
        {
399
            clearallviews(0L);
399
            clearallviews(0L);
400
            //g_player[myconnectindex].ps->palette = palette;
400
            //g_player[myconnectindex].ps->palette = palette;
401
            //G_FadePalette(0,0,0,0);
401
            //G_FadePalette(0,0,0,0);
402
            P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0);    // JBF 20040308
402
            P_SetGamePalette(g_player[myconnectindex].ps, BASEPAL, 0);    // JBF 20040308
403
        }
403
        }
404
        /*Gv_SetVar(g_iReturnVarID,LOADSCREEN, -1, -1);*/
404
        /*Gv_SetVar(g_iReturnVarID,LOADSCREEN, -1, -1);*/
405
405
406
        j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN);
406
        j = VM_OnEventWithReturn(EVENT_GETLOADTILE, -1, myconnectindex, LOADSCREEN);
407
407
408
        if ((uint32_t)j < 2*MAXTILES)
408
        if ((uint32_t)j < 2*MAXTILES)
409
        {
409
        {
410
            rotatesprite_fs(320<<15,200<<15,65536L, 0,j > MAXTILES-1?j-MAXTILES:j,0,0,
410
            rotatesprite_fs(320<<15,200<<15,65536L, 0,j > MAXTILES-1?j-MAXTILES:j,0,0,
411
                            2+8+64+BGSTRETCH);
411
                            2+8+64+BGSTRETCH);
412
        }
412
        }
413
        else
413
        else
414
        {
414
        {
415
            nextpage();
415
            nextpage();
416
            return;
416
            return;
417
        }
417
        }
418
418
419
        menutext(160,105,0,0,"Loading...");
419
        menutext(160,105,0,0,"Loading...");
420
        if (statustext) gametext(160,180,statustext,0,2+8+16);
420
        if (statustext) gametext(160,180,statustext,0,2+8+16);
421
        VM_OnEventWithReturn(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, percent);
421
        VM_OnEventWithReturn(EVENT_DISPLAYLOADINGSCREEN, g_player[screenpeek].ps->i, screenpeek, percent);
422
        nextpage();
422
        nextpage();
423
    }
423
    }
424
}
424
}
425
425
426
extern void G_SetCrosshairColor(int32_t r, int32_t g, int32_t b);
426
extern void G_SetCrosshairColor(int32_t r, int32_t g, int32_t b);
427
extern palette_t CrosshairColors;
427
extern palette_t CrosshairColors;
428
428
429
void G_CacheMapData(void)
429
void G_CacheMapData(void)
430
{
430
{
431
    int32_t i,j,pc=0;
431
    int32_t i,j,pc=0;
432
    int32_t tc;
432
    int32_t tc;
433
    uint32_t starttime, endtime;
433
    uint32_t starttime, endtime;
434
434
435
    if (ud.recstat == 2)
435
    if (ud.recstat == 2)
436
        return;
436
        return;
437
437
438
    S_PauseMusic(1);
438
    S_PauseMusic(1);
439
    if (MapInfo[MUS_LOADING].musicfn)
439
    if (MapInfo[MUS_LOADING].musicfn)
440
    {
440
    {
441
        S_StopMusic();
441
        S_StopMusic();
442
        S_PlayMusic(MapInfo[MUS_LOADING].musicfn);
442
        S_PlayMusic(MapInfo[MUS_LOADING].musicfn);
443
    }
443
    }
444
444
445
    starttime = getticks();
445
    starttime = getticks();
446
446
447
    G_PrecacheSounds();
447
    G_PrecacheSounds();
448
    G_PrecacheSprites();
448
    G_PrecacheSprites();
449
449
450
    for (i=0; i<numwalls; i++)
450
    for (i=0; i<numwalls; i++)
451
    {
451
    {
452
        tloadtile(wall[i].picnum, 0);
452
        tloadtile(wall[i].picnum, 0);
453
453
454
        if (wall[i].overpicnum >= 0)
454
        if (wall[i].overpicnum >= 0)
455
        {
455
        {
456
            tloadtile(wall[i].overpicnum, 0);
456
            tloadtile(wall[i].overpicnum, 0);
457
        }
457
        }
458
    }
458
    }
459
459
460
    for (i=0; i<numsectors; i++)
460
    for (i=0; i<numsectors; i++)
461
    {
461
    {
462
        tloadtile(sector[i].floorpicnum, 0);
462
        tloadtile(sector[i].floorpicnum, 0);
463
        tloadtile(sector[i].ceilingpicnum, 0);
463
        tloadtile(sector[i].ceilingpicnum, 0);
464
        if (sector[i].ceilingpicnum == LA)  // JBF 20040509: if( waloff[sector[i].ceilingpicnum] == LA) WTF?!?!?!?
464
        if (sector[i].ceilingpicnum == LA)  // JBF 20040509: if( waloff[sector[i].ceilingpicnum] == LA) WTF?!?!?!?
465
        {
465
        {
466
            tloadtile(LA+1, 0);
466
            tloadtile(LA+1, 0);
467
            tloadtile(LA+2, 0);
467
            tloadtile(LA+2, 0);
468
        }
468
        }
469
469
470
        for (SPRITES_OF_SECT(i, j))
470
        for (SPRITES_OF_SECT(i, j))
471
            if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
471
            if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
472
                G_CacheSpriteNum(j);
472
                G_CacheSpriteNum(j);
473
    }
473
    }
474
474
475
    tc = totalclock;
475
    tc = totalclock;
476
    j = 0;
476
    j = 0;
477
477
478
    for (i=0; i<MAXTILES; i++)
478
    for (i=0; i<MAXTILES; i++)
479
    {
479
    {
480
        if (!(i&7) && !gotpic[i>>3])
480
        if (!(i&7) && !gotpic[i>>3])
481
        {
481
        {
482
            i+=7;
482
            i+=7;
483
            continue;
483
            continue;
484
        }
484
        }
485
        if (gotpic[i>>3] & pow2char[i&7])
485
        if (gotpic[i>>3] & pow2char[i&7])
486
        {
486
        {
487
            if (waloff[i] == 0)
487
            if (waloff[i] == 0)
488
                loadtile((int16_t)i);
488
                loadtile((int16_t)i);
489
489
490
#ifdef USE_OPENGL
490
#ifdef USE_OPENGL
491
// PRECACHE
491
// PRECACHE
492
            if (ud.config.useprecache && bpp > 8)
492
            if (ud.config.useprecache && bpp > 8)
493
            {
493
            {
494
                int32_t k,type;
494
                int32_t k,type;
495
495
496
                for (type=0; type<=1; type++)
496
                for (type=0; type<=1; type++)
497
                    if (precachehightile[type][i>>3] & pow2char[i&7])
497
                    if (precachehightile[type][i>>3] & pow2char[i&7])
498
                    {
498
                    {
499
                        k = 0;
499
                        k = 0;
500
                        for (k=0; k<MAXPALOOKUPS-RESERVEDPALS && !KB_KeyPressed(sc_Space); k++)
500
                        for (k=0; k<MAXPALOOKUPS-RESERVEDPALS && !KB_KeyPressed(sc_Space); k++)
501
                        {
501
                        {
502
                            // this is the CROSSHAIR_PAL, see comment in game.c
502
                            // this is the CROSSHAIR_PAL, see comment in game.c
503
                            if (k == MAXPALOOKUPS-RESERVEDPALS-1)
503
                            if (k == MAXPALOOKUPS-RESERVEDPALS-1)
504
                                break;
504
                                break;
505
#ifdef POLYMER
505
#ifdef POLYMER
506
                            if (getrendermode() != REND_POLYMER || !polymer_havehighpalookup(0, k))
506
                            if (getrendermode() != REND_POLYMER || !polymer_havehighpalookup(0, k))
507
#endif
507
#endif
508
                                polymost_precache(i,k,type);
508
                                polymost_precache(i,k,type);
509
                        }
509
                        }
510
510
511
                        if (r_detailmapping && !KB_KeyPressed(sc_Space))
511
                        if (r_detailmapping && !KB_KeyPressed(sc_Space))
512
                            polymost_precache(i,DETAILPAL,type);
512
                            polymost_precache(i,DETAILPAL,type);
513
                        if (r_glowmapping && !KB_KeyPressed(sc_Space))
513
                        if (r_glowmapping && !KB_KeyPressed(sc_Space))
514
                            polymost_precache(i,GLOWPAL,type);
514
                            polymost_precache(i,GLOWPAL,type);
515
#ifdef POLYMER
515
#ifdef POLYMER
516
                        if (getrendermode() == REND_POLYMER)
516
                        if (getrendermode() == REND_POLYMER)
517
                        {
517
                        {
518
                            if (pr_specularmapping && !KB_KeyPressed(sc_Space))
518
                            if (pr_specularmapping && !KB_KeyPressed(sc_Space))
519
                                polymost_precache(i,SPECULARPAL,type);
519
                                polymost_precache(i,SPECULARPAL,type);
520
                            if (pr_normalmapping && !KB_KeyPressed(sc_Space))
520
                            if (pr_normalmapping && !KB_KeyPressed(sc_Space))
521
                                polymost_precache(i,NORMALPAL,type);
521
                                polymost_precache(i,NORMALPAL,type);
522
                        }
522
                        }
523
#endif
523
#endif
524
                    }
524
                    }
525
            }
525
            }
526
#endif
526
#endif
527
            j++;
527
            j++;
528
            pc++;
528
            pc++;
529
        }
529
        }
530
        else continue;
530
        else continue;
531
531
532
        MUSIC_Update();
532
        MUSIC_Update();
533
533
534
        if ((j&7) == 0)
534
        if ((j&7) == 0)
535
            G_HandleAsync();
535
            G_HandleAsync();
536
536
537
        if (bpp > 8 && totalclock - tc > TICRATE/4)
537
        if (bpp > 8 && totalclock - tc > TICRATE/4)
538
        {
538
        {
539
            /*Bsprintf(tempbuf,"%d resources remaining\n",g_precacheCount-pc+1);*/
539
            /*Bsprintf(tempbuf,"%d resources remaining\n",g_precacheCount-pc+1);*/
540
            tc = min(100, tabledivide32_noinline(100 * pc, g_precacheCount));
540
            tc = min(100, tabledivide32_noinline(100 * pc, g_precacheCount));
541
            Bsprintf(tempbuf,"Loaded %d%% (%d/%d textures)\n",tc,pc,g_precacheCount);
541
            Bsprintf(tempbuf,"Loaded %d%% (%d/%d textures)\n",tc,pc,g_precacheCount);
542
            G_DoLoadScreen(tempbuf, tc);
542
            G_DoLoadScreen(tempbuf, tc);
543
            tc = totalclock;
543
            tc = totalclock;
544
        }
544
        }
545
    }
545
    }
546
546
547
    Bmemset(gotpic, 0, sizeof(gotpic));
547
    Bmemset(gotpic, 0, sizeof(gotpic));
548
548
549
    endtime = getticks();
549
    endtime = getticks();
550
    OSD_Printf("Cache time: %dms\n", endtime-starttime);
550
    OSD_Printf("Cache time: %dms\n", endtime-starttime);
551
}
551
}
552
552
553
void G_UpdateScreenArea(void)
553
void G_UpdateScreenArea(void)
554
{
554
{
555
    if (!in3dmode())
555
    if (!in3dmode())
556
        return;
556
        return;
557
557
558
    ud.screen_size = clamp(ud.screen_size, 0, 64);
558
    ud.screen_size = clamp(ud.screen_size, 0, 64);
559
    if (ud.screen_size == 0)
559
    if (ud.screen_size == 0)
560
        flushperms();
560
        flushperms();
561
561
562
    {
562
    {
563
        const int32_t ss = max(ud.screen_size-8,0);
563
        const int32_t ss = max(ud.screen_size-8,0);
564
564
565
        const int32_t x1 = scale(ss,xdim,160);
565
        const int32_t x1 = scale(ss,xdim,160);
566
        int32_t x2 = xdim-x1;
566
        int32_t x2 = xdim-x1;
567
567
568
        int32_t y1 = ss;
568
        int32_t y1 = ss;
569
        int32_t y2 = 200;
569
        int32_t y2 = 200;
570
570
571
        if (ud.screen_size > 0 && (GametypeFlags[ud.coop]&GAMETYPE_FRAGBAR) && (g_netServer || ud.multimode > 1))
571
        if (ud.screen_size > 0 && (GametypeFlags[ud.coop]&GAMETYPE_FRAGBAR) && (g_netServer || ud.multimode > 1))
572
        {
572
        {
573
            int32_t i, j = 0;
573
            int32_t i, j = 0;
574
574
575
            for (TRAVERSE_CONNECT(i))
575
            for (TRAVERSE_CONNECT(i))
576
                if (i > j) j = i;
576
                if (i > j) j = i;
577
577
578
            if (j >= 1) y1 += 8;
578
            if (j >= 1) y1 += 8;
579
            if (j >= 4) y1 += 8;
579
            if (j >= 4) y1 += 8;
580
            if (j >= 8) y1 += 8;
580
            if (j >= 8) y1 += 8;
581
            if (j >= 12) y1 += 8;
581
            if (j >= 12) y1 += 8;
582
        }
582
        }
583
583
584
        if (ud.screen_size >= 8 && ud.statusbarmode==0)
584
        if (ud.screen_size >= 8 && ud.statusbarmode==0)
585
            y2 -= (ss+scale(tilesiz[BOTTOMSTATUSBAR].y,ud.statusbarscale,100));
585
            y2 -= (ss+scale(tilesiz[BOTTOMSTATUSBAR].y,ud.statusbarscale,100));
586
586
587
        y1 = scale(y1,ydim,200);
587
        y1 = scale(y1,ydim,200);
588
        y2 = scale(y2,ydim,200)+(getrendermode() != REND_CLASSIC);
588
        y2 = scale(y2,ydim,200)+(getrendermode() != REND_CLASSIC);
589
589
590
        if (g_halveScreenArea)
590
        if (g_halveScreenArea)
591
        {
591
        {
592
            int32_t ourxdimen=x2-x1, ourydimen=y2-y1;
592
            int32_t ourxdimen=x2-x1, ourydimen=y2-y1;
593
593
594
            g_halfScreen.x1 = x1;
594
            g_halfScreen.x1 = x1;
595
            g_halfScreen.y1 = y1;
595
            g_halfScreen.y1 = y1;
596
            g_halfScreen.xdimen = (ourxdimen>>1);
596
            g_halfScreen.xdimen = (ourxdimen>>1);
597
            g_halfScreen.ydimen = (ourydimen>>1);
597
            g_halfScreen.ydimen = (ourydimen>>1);
598
598
599
            x2 = x1 + (ourxdimen>>1);
599
            x2 = x1 + (ourxdimen>>1);
600
            y2 = y1 + (ourydimen>>1);
600
            y2 = y1 + (ourydimen>>1);
601
        }
601
        }
602
602
603
        setview(x1,y1,x2-1,y2-1);
603
        setview(x1,y1,x2-1,y2-1);
604
    }
604
    }
605
605
606
    G_GetCrosshairColor();
606
    G_GetCrosshairColor();
607
    G_SetCrosshairColor(CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
607
    G_SetCrosshairColor(CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
608
608
609
    pub = NUMPAGES;
609
    pub = NUMPAGES;
610
    pus = NUMPAGES;
610
    pus = NUMPAGES;
611
}
611
}
612
612
613
void P_RandomSpawnPoint(int32_t snum)
613
void P_RandomSpawnPoint(int32_t snum)
614
{
614
{
615
    DukePlayer_t *p = g_player[snum].ps;
615
    DukePlayer_t *p = g_player[snum].ps;
616
    int32_t i=snum,j,k;
616
    int32_t i=snum,j,k;
617
    uint32_t dist,pdist = -1;
617
    uint32_t dist,pdist = -1;
618
618
619
    if ((g_netServer || ud.multimode > 1) && !(GametypeFlags[ud.coop] & GAMETYPE_FIXEDRESPAWN))
619
    if ((g_netServer || ud.multimode > 1) && !(GametypeFlags[ud.coop] & GAMETYPE_FIXEDRESPAWN))
620
    {
620
    {
621
        i = krand()%g_numPlayerSprites;
621
        i = krand()%g_numPlayerSprites;
622
        if (GametypeFlags[ud.coop] & GAMETYPE_TDMSPAWN)
622
        if (GametypeFlags[ud.coop] & GAMETYPE_TDMSPAWN)
623
        {
623
        {
624
            for (j=0; j<ud.multimode; j++)
624
            for (j=0; j<ud.multimode; j++)
625
            {
625
            {
626
                if (j != snum && g_player[j].ps->team == p->team && sprite[g_player[j].ps->i].extra > 0)
626
                if (j != snum && g_player[j].ps->team == p->team && sprite[g_player[j].ps->i].extra > 0)
627
                {
627
                {
628
                    for (k=0; k<g_numPlayerSprites; k++)
628
                    for (k=0; k<g_numPlayerSprites; k++)
629
                    {
629
                    {
630
                        dist = FindDistance2D(g_player[j].ps->pos.x-g_playerSpawnPoints[k].pos.x,g_player[j].ps->pos.y-g_playerSpawnPoints[k].pos.y);
630
                        dist = FindDistance2D(g_player[j].ps->pos.x-g_playerSpawnPoints[k].pos.x,g_player[j].ps->pos.y-g_playerSpawnPoints[k].pos.y);
631
                        if (dist < pdist)
631
                        if (dist < pdist)
632
                            i = k, pdist = dist;
632
                            i = k, pdist = dist;
633
                    }
633
                    }
634
                    break;
634
                    break;
635
                }
635
                }
636
            }
636
            }
637
        }
637
        }
638
    }
638
    }
639
639
640
    p->bobpos.x = p->opos.x = p->pos.x = g_playerSpawnPoints[i].pos.x;
640
    p->bobpos.x = p->opos.x = p->pos.x = g_playerSpawnPoints[i].pos.x;
641
    p->bobpos.y = p->opos.y = p->pos.y = g_playerSpawnPoints[i].pos.y;
641
    p->bobpos.y = p->opos.y = p->pos.y = g_playerSpawnPoints[i].pos.y;
642
    p->opos.z = p->pos.z = g_playerSpawnPoints[i].pos.z;
642
    p->opos.z = p->pos.z = g_playerSpawnPoints[i].pos.z;
643
    p->ang = g_playerSpawnPoints[i].ang;
643
    p->ang = g_playerSpawnPoints[i].ang;
644
    p->cursectnum = g_playerSpawnPoints[i].sect;
644
    p->cursectnum = g_playerSpawnPoints[i].sect;
645
    sprite[p->i].cstat = 1+256;
645
    sprite[p->i].cstat = 1+256;
646
}
646
}
647
647
648
static inline void P_ResetTintFade(DukePlayer_t *ps)
648
static inline void P_ResetTintFade(DukePlayer_t *ps)
649
{
649
{
650
    ps->pals.f = 0;
650
    ps->pals.f = 0;
651
#ifdef LUNATIC
651
#ifdef LUNATIC
652
    ps->palsfadeprio = 0;
652
    ps->palsfadeprio = 0;
653
#endif
653
#endif
654
}
654
}
655
655
656
void P_ResetPlayer(int32_t snum)
656
void P_ResetPlayer(int32_t snum)
657
{
657
{
658
    vec3_t tmpvect;
658
    vec3_t tmpvect;
659
    DukePlayer_t *const pl = g_player[snum].ps;
659
    DukePlayer_t *const pl = g_player[snum].ps;
660
    spritetype *const sp = &sprite[pl->i];
660
    spritetype *const sp = &sprite[pl->i];
661
661
662
    tmpvect.x = pl->pos.x;
662
    tmpvect.x = pl->pos.x;
663
    tmpvect.y = pl->pos.y;
663
    tmpvect.y = pl->pos.y;
664
    tmpvect.z = pl->pos.z+PHEIGHT;
664
    tmpvect.z = pl->pos.z+PHEIGHT;
665
    P_RandomSpawnPoint(snum);
665
    P_RandomSpawnPoint(snum);
666
    sp->x = actor[pl->i].bpos.x = pl->bobpos.x = pl->opos.x = pl->pos.x;
666
    sp->x = actor[pl->i].bpos.x = pl->bobpos.x = pl->opos.x = pl->pos.x;
667
    sp->y = actor[pl->i].bpos.y = pl->bobpos.y = pl->opos.y = pl->pos.y;
667
    sp->y = actor[pl->i].bpos.y = pl->bobpos.y = pl->opos.y = pl->pos.y;
668
    sp->z = actor[pl->i].bpos.y = pl->opos.z =pl->pos.z;
668
    sp->z = actor[pl->i].bpos.y = pl->opos.z =pl->pos.z;
669
    updatesector(pl->pos.x,pl->pos.y,&pl->cursectnum);
669
    updatesector(pl->pos.x,pl->pos.y,&pl->cursectnum);
670
    setsprite(pl->i,&tmpvect);
670
    setsprite(pl->i,&tmpvect);
671
    sp->cstat = 257;
671
    sp->cstat = 257;
672
672
673
    sp->shade = -12;
673
    sp->shade = -12;
674
    sp->clipdist = 64;
674
    sp->clipdist = 64;
675
    sp->xrepeat = 42;
675
    sp->xrepeat = 42;
676
    sp->yrepeat = 36;
676
    sp->yrepeat = 36;
677
    sp->owner = pl->i;
677
    sp->owner = pl->i;
678
    sp->xoffset = 0;
678
    sp->xoffset = 0;
679
    sp->pal = pl->palookup;
679
    sp->pal = pl->palookup;
680
680
681
    pl->last_extra = sp->extra = pl->max_player_health;
681
    pl->last_extra = sp->extra = pl->max_player_health;
682
    pl->wantweaponfire = -1;
682
    pl->wantweaponfire = -1;
683
    pl->horiz = 100;
683
    pl->horiz = 100;
684
    pl->on_crane = -1;
684
    pl->on_crane = -1;
685
    pl->frag_ps = snum;
685
    pl->frag_ps = snum;
686
    pl->horizoff = 0;
686
    pl->horizoff = 0;
687
    pl->opyoff = 0;
687
    pl->opyoff = 0;
688
    pl->wackedbyactor = -1;
688
    pl->wackedbyactor = -1;
689
    pl->inv_amount[GET_SHIELD] = g_startArmorAmount;
689
    pl->inv_amount[GET_SHIELD] = g_startArmorAmount;
690
    pl->dead_flag = 0;
690
    pl->dead_flag = 0;
691
    pl->footprintcount = 0;
691
    pl->footprintcount = 0;
692
    pl->weapreccnt = 0;
692
    pl->weapreccnt = 0;
693
    pl->fta = 0;
693
    pl->fta = 0;
694
    pl->ftq = 0;
694
    pl->ftq = 0;
695
    pl->vel.x = pl->vel.y = 0;
695
    pl->vel.x = pl->vel.y = 0;
696
    pl->rotscrnang = 0;
696
    pl->rotscrnang = 0;
697
    pl->runspeed = g_playerFriction;
697
    pl->runspeed = g_playerFriction;
698
    pl->falling_counter = 0;
698
    pl->falling_counter = 0;
699
699
700
    P_ResetTintFade(pl);
700
    P_ResetTintFade(pl);
701
701
702
    actor[pl->i].extra = -1;
702
    actor[pl->i].extra = -1;
703
    actor[pl->i].owner = pl->i;
703
    actor[pl->i].owner = pl->i;
704
704
705
    actor[pl->i].cgg = 0;
705
    actor[pl->i].cgg = 0;
706
    actor[pl->i].movflag = 0;
706
    actor[pl->i].movflag = 0;
707
    actor[pl->i].tempang = 0;
707
    actor[pl->i].tempang = 0;
708
    actor[pl->i].actorstayput = -1;
708
    actor[pl->i].actorstayput = -1;
709
    actor[pl->i].dispicnum = 0;
709
    actor[pl->i].dispicnum = 0;
710
    actor[pl->i].owner = pl->i;
710
    actor[pl->i].owner = pl->i;
711
711
712
    actor[pl->i].t_data[4] = 0;
712
    actor[pl->i].t_data[4] = 0;
713
713
714
    P_ResetInventory(snum);
714
    P_ResetInventory(snum);
715
    P_ResetWeapons(snum);
715
    P_ResetWeapons(snum);
716
716
717
    pl->reloading = 0;
717
    pl->reloading = 0;
718
718
719
    pl->movement_lock = 0;
719
    pl->movement_lock = 0;
720
720
721
    VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum);
721
    VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum);
722
}
722
}
723
723
724
void P_ResetStatus(int32_t snum)
724
void P_ResetStatus(int32_t snum)
725
{
725
{
726
    DukePlayer_t *p = g_player[snum].ps;
726
    DukePlayer_t *p = g_player[snum].ps;
727
727
728
    ud.show_help        = 0;
728
    ud.show_help        = 0;
729
    ud.showallmap       = 0;
729
    ud.showallmap       = 0;
730
    p->dead_flag        = 0;
730
    p->dead_flag        = 0;
731
    p->wackedbyactor    = -1;
731
    p->wackedbyactor    = -1;
732
    p->falling_counter  = 0;
732
    p->falling_counter  = 0;
733
    p->quick_kick       = 0;
733
    p->quick_kick       = 0;
734
    p->subweapon        = 0;
734
    p->subweapon        = 0;
735
    p->last_full_weapon = 0;
735
    p->last_full_weapon = 0;
736
    p->ftq              = 0;
736
    p->ftq              = 0;
737
    p->fta              = 0;
737
    p->fta              = 0;
738
    p->tipincs          = 0;
738
    p->tipincs          = 0;
739
    p->buttonpalette    = 0;
739
    p->buttonpalette    = 0;
740
    p->actorsqu         =-1;
740
    p->actorsqu         =-1;
741
    p->invdisptime      = 0;
741
    p->invdisptime      = 0;
742
    p->refresh_inventory= 0;
742
    p->refresh_inventory= 0;
743
    p->last_pissed_time = 0;
743
    p->last_pissed_time = 0;
744
    p->holster_weapon   = 0;
744
    p->holster_weapon   = 0;
745
    p->pycount          = 0;
745
    p->pycount          = 0;
746
    p->pyoff            = 0;
746
    p->pyoff            = 0;
747
    p->opyoff           = 0;
747
    p->opyoff           = 0;
748
    p->loogcnt          = 0;
748
    p->loogcnt          = 0;
749
    p->angvel           = 0;
749
    p->angvel           = 0;
750
    p->weapon_sway      = 0;
750
    p->weapon_sway      = 0;
751
    p->extra_extra8     = 0;
751
    p->extra_extra8     = 0;
752
    p->show_empty_weapon= 0;
752
    p->show_empty_weapon= 0;
753
    p->dummyplayersprite=-1;
753
    p->dummyplayersprite=-1;
754
    p->crack_time       = 0;
754
    p->crack_time       = 0;
755
    p->hbomb_hold_delay = 0;
755
    p->hbomb_hold_delay = 0;
756
    p->transporter_hold = 0;
756
    p->transporter_hold = 0;
757
    p->wantweaponfire  = -1;
757
    p->wantweaponfire  = -1;
758
    p->hurt_delay       = 0;
758
    p->hurt_delay       = 0;
759
    p->footprintcount   = 0;
759
    p->footprintcount   = 0;
760
    p->footprintpal     = 0;
760
    p->footprintpal     = 0;
761
    p->footprintshade   = 0;
761
    p->footprintshade   = 0;
762
    p->jumping_toggle   = 0;
762
    p->jumping_toggle   = 0;
763
    p->ohoriz = p->horiz= 140;
763
    p->ohoriz = p->horiz= 140;
764
    p->horizoff         = 0;
764
    p->horizoff         = 0;
765
    p->bobcounter       = 0;
765
    p->bobcounter       = 0;
766
    p->on_ground        = 0;
766
    p->on_ground        = 0;
767
    p->player_par       = 0;
767
    p->player_par       = 0;
768
    p->return_to_center = 9;
768
    p->return_to_center = 9;
769
    p->airleft          = 15*GAMETICSPERSEC;
769
    p->airleft          = 15*GAMETICSPERSEC;
770
    p->rapid_fire_hold  = 0;
770
    p->rapid_fire_hold  = 0;
771
    p->toggle_key_flag  = 0;
771
    p->toggle_key_flag  = 0;
772
    p->access_spritenum = -1;
772
    p->access_spritenum = -1;
773
    if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop] & GAMETYPE_ACCESSATSTART))
773
    if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop] & GAMETYPE_ACCESSATSTART))
774
        p->got_access = 7;
774
        p->got_access = 7;
775
    else p->got_access      = 0;
775
    else p->got_access      = 0;
776
    p->random_club_frame= 0;
776
    p->random_club_frame= 0;
777
    pus = 1;
777
    pus = 1;
778
    p->on_warping_sector = 0;
778
    p->on_warping_sector = 0;
779
    p->spritebridge      = 0;
779
    p->spritebridge      = 0;
780
    p->sbs          = 0;
780
    p->sbs          = 0;
781
    p->palette = BASEPAL;
781
    p->palette = BASEPAL;
782
782
783
    if (p->inv_amount[GET_STEROIDS] < 400)
783
    if (p->inv_amount[GET_STEROIDS] < 400)
784
    {
784
    {
785
        p->inv_amount[GET_STEROIDS] = 0;
785
        p->inv_amount[GET_STEROIDS] = 0;
786
        p->inven_icon = ICON_NONE;
786
        p->inven_icon = ICON_NONE;
787
    }
787
    }
788
    p->heat_on =            0;
788
    p->heat_on =            0;
789
    p->jetpack_on =         0;
789
    p->jetpack_on =         0;
790
    p->holoduke_on =       -1;
790
    p->holoduke_on =       -1;
791
791
792
    p->look_ang          = 512 - ((ud.level_number&1)<<10);
792
    p->look_ang          = 512 - ((ud.level_number&1)<<10);
793
793
794
    p->rotscrnang        = 0;
794
    p->rotscrnang        = 0;
795
    p->orotscrnang       = 1;   // JBF 20031220
795
    p->orotscrnang       = 1;   // JBF 20031220
796
    p->newowner          =-1;
796
    p->newowner          =-1;
797
    p->jumping_counter   = 0;
797
    p->jumping_counter   = 0;
798
    p->hard_landing      = 0;
798
    p->hard_landing      = 0;
799
    p->vel.x             = 0;
799
    p->vel.x             = 0;
800
    p->vel.y             = 0;
800
    p->vel.y             = 0;
801
    p->vel.z             = 0;
801
    p->vel.z             = 0;
802
    p->fric.x        = 0;
802
    p->fric.x        = 0;
803
    p->fric.y        = 0;
803
    p->fric.y        = 0;
804
    p->somethingonplayer =-1;
804
    p->somethingonplayer =-1;
805
    p->one_eighty_count  = 0;
805
    p->one_eighty_count  = 0;
806
    p->cheat_phase       = 0;
806
    p->cheat_phase       = 0;
807
807
808
    p->on_crane          = -1;
808
    p->on_crane          = -1;
809
809
810
    if ((PWEAPON(snum, p->curr_weapon, WorksLike) == PISTOL_WEAPON) &&
810
    if ((PWEAPON(snum, p->curr_weapon, WorksLike) == PISTOL_WEAPON) &&
811
            (PWEAPON(snum, p->curr_weapon, Reload) > PWEAPON(snum, p->curr_weapon, TotalTime)))
811
            (PWEAPON(snum, p->curr_weapon, Reload) > PWEAPON(snum, p->curr_weapon, TotalTime)))
812
        p->kickback_pic  = PWEAPON(snum, p->curr_weapon, TotalTime);
812
        p->kickback_pic  = PWEAPON(snum, p->curr_weapon, TotalTime);
813
    else p->kickback_pic = 0;
813
    else p->kickback_pic = 0;
814
814
815
    p->weapon_pos        = WEAPON_POS_START;
815
    p->weapon_pos        = WEAPON_POS_START;
816
    p->walking_snd_toggle= 0;
816
    p->walking_snd_toggle= 0;
817
    p->weapon_ang        = 0;
817
    p->weapon_ang        = 0;
818
818
819
    p->knuckle_incs      = 1;
819
    p->knuckle_incs      = 1;
820
    p->fist_incs = 0;
820
    p->fist_incs = 0;
821
    p->knee_incs         = 0;
821
    p->knee_incs         = 0;
822
    p->jetpack_on        = 0;
822
    p->jetpack_on        = 0;
823
    p->reloading        = 0;
823
    p->reloading        = 0;
824
824
825
    p->movement_lock     = 0;
825
    p->movement_lock     = 0;
826
826
827
    p->frag_ps          = snum;
827
    p->frag_ps          = snum;
828
828
829
    P_UpdateScreenPal(p);
829
    P_UpdateScreenPal(p);
830
    VM_OnEvent(EVENT_RESETPLAYER, p->i, snum);
830
    VM_OnEvent(EVENT_RESETPLAYER, p->i, snum);
831
}
831
}
832
832
833
void P_ResetWeapons(int32_t snum)
833
void P_ResetWeapons(int32_t snum)
834
{
834
{
835
    int32_t weapon;
835
    int32_t weapon;
836
    DukePlayer_t *p = g_player[snum].ps;
836
    DukePlayer_t *p = g_player[snum].ps;
837
837
838
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
838
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
839
        p->ammo_amount[weapon] = 0;
839
        p->ammo_amount[weapon] = 0;
840
840
841
    p->weapon_pos = WEAPON_POS_START;
841
    p->weapon_pos = WEAPON_POS_START;
842
    p->curr_weapon = PISTOL_WEAPON;
842
    p->curr_weapon = PISTOL_WEAPON;
843
    p->kickback_pic = PWEAPON(snum, p->curr_weapon, TotalTime);
843
    p->kickback_pic = PWEAPON(snum, p->curr_weapon, TotalTime);
844
    p->gotweapon = ((1<<PISTOL_WEAPON) | (1<<KNEE_WEAPON) | (1<<HANDREMOTE_WEAPON));
844
    p->gotweapon = ((1<<PISTOL_WEAPON) | (1<<KNEE_WEAPON) | (1<<HANDREMOTE_WEAPON));
845
    p->ammo_amount[PISTOL_WEAPON] = min(p->max_ammo_amount[PISTOL_WEAPON], 48);
845
    p->ammo_amount[PISTOL_WEAPON] = min(p->max_ammo_amount[PISTOL_WEAPON], 48);
846
    p->last_weapon = -1;
846
    p->last_weapon = -1;
847
847
848
    p->show_empty_weapon= 0;
848
    p->show_empty_weapon= 0;
849
    p->last_pissed_time = 0;
849
    p->last_pissed_time = 0;
850
    p->holster_weapon = 0;
850
    p->holster_weapon = 0;
851
    VM_OnEvent(EVENT_RESETWEAPONS, p->i, snum);
851
    VM_OnEvent(EVENT_RESETWEAPONS, p->i, snum);
852
}
852
}
853
853
854
void P_ResetInventory(int32_t snum)
854
void P_ResetInventory(int32_t snum)
855
{
855
{
856
    DukePlayer_t *p = g_player[snum].ps;
856
    DukePlayer_t *p = g_player[snum].ps;
857
857
858
    Bmemset(p->inv_amount, 0, sizeof(p->inv_amount));
858
    Bmemset(p->inv_amount, 0, sizeof(p->inv_amount));
859
859
860
    p->scuba_on =           0;
860
    p->scuba_on =           0;
861
    p->heat_on = 0;
861
    p->heat_on = 0;
862
    p->jetpack_on =         0;
862
    p->jetpack_on =         0;
863
    p->holoduke_on = -1;
863
    p->holoduke_on = -1;
864
    p->inv_amount[GET_SHIELD] =      g_startArmorAmount;
864
    p->inv_amount[GET_SHIELD] =      g_startArmorAmount;
865
    p->inven_icon = ICON_NONE;
865
    p->inven_icon = ICON_NONE;
866
    VM_OnEvent(EVENT_RESETINVENTORY, p->i, snum);
866
    VM_OnEvent(EVENT_RESETINVENTORY, p->i, snum);
867
}
867
}
868
868
869
static void resetprestat(int32_t snum,int32_t g)
869
static void resetprestat(int32_t snum,int32_t g)
870
{
870
{
871
    DukePlayer_t *p = g_player[snum].ps;
871
    DukePlayer_t *p = g_player[snum].ps;
872
    int32_t i;
872
    int32_t i;
873
873
874
    g_spriteDeleteQueuePos = 0;
874
    g_spriteDeleteQueuePos = 0;
875
    for (i=0; i<g_spriteDeleteQueueSize; i++) SpriteDeletionQueue[i] = -1;
875
    for (i=0; i<g_spriteDeleteQueueSize; i++) SpriteDeletionQueue[i] = -1;
876
876
877
    p->hbomb_on          = 0;
877
    p->hbomb_on          = 0;
878
    p->cheat_phase       = 0;
878
    p->cheat_phase       = 0;
879
    p->toggle_key_flag   = 0;
879
    p->toggle_key_flag   = 0;
880
    p->secret_rooms      = 0;
880
    p->secret_rooms      = 0;
881
    p->max_secret_rooms  = 0;
881
    p->max_secret_rooms  = 0;
882
    p->actors_killed     = 0;
882
    p->actors_killed     = 0;
883
    p->max_actors_killed = 0;
883
    p->max_actors_killed = 0;
884
    p->lastrandomspot    = 0;
884
    p->lastrandomspot    = 0;
885
    p->weapon_pos = WEAPON_POS_START;
885
    p->weapon_pos = WEAPON_POS_START;
886
886
887
    P_ResetTintFade(p);
887
    P_ResetTintFade(p);
888
888
889
    if ((PWEAPON(snum, p->curr_weapon, WorksLike) == PISTOL_WEAPON) &&
889
    if ((PWEAPON(snum, p->curr_weapon, WorksLike) == PISTOL_WEAPON) &&
890
            (PWEAPON(snum, p->curr_weapon, Reload) > PWEAPON(snum, p->curr_weapon, TotalTime)))
890
            (PWEAPON(snum, p->curr_weapon, Reload) > PWEAPON(snum, p->curr_weapon, TotalTime)))
891
        p->kickback_pic  = PWEAPON(snum, p->curr_weapon, TotalTime);
891
        p->kickback_pic  = PWEAPON(snum, p->curr_weapon, TotalTime);
892
    else p->kickback_pic = 0;
892
    else p->kickback_pic = 0;
893
893
894
    p->last_weapon = -1;
894
    p->last_weapon = -1;
895
    p->weapreccnt = 0;
895
    p->weapreccnt = 0;
896
    p->interface_toggle_flag = 0;
896
    p->interface_toggle_flag = 0;
897
    p->show_empty_weapon= 0;
897
    p->show_empty_weapon= 0;
898
    p->holster_weapon = 0;
898
    p->holster_weapon = 0;
899
    p->last_pissed_time = 0;
899
    p->last_pissed_time = 0;
900
900
901
    p->one_parallax_sectnum = -1;
901
    p->one_parallax_sectnum = -1;
902
    p->visibility = ud.const_visibility;
902
    p->visibility = ud.const_visibility;
903
903
904
    screenpeek              = myconnectindex;
904
    screenpeek              = myconnectindex;
905
    g_numAnimWalls            = 0;
905
    g_numAnimWalls            = 0;
906
    g_numCyclers              = 0;
906
    g_numCyclers              = 0;
907
    g_animateCount              = 0;
907
    g_animateCount              = 0;
908
    parallaxtype            = 0;
908
    parallaxtype            = 0;
909
    randomseed              = 1996;
909
    randomseed              = 1996;
910
    ud.pause_on             = 0;
910
    ud.pause_on             = 0;
911
    ud.camerasprite         =-1;
911
    ud.camerasprite         =-1;
912
    ud.eog                  = 0;
912
    ud.eog                  = 0;
913
    tempwallptr             = 0;
913
    tempwallptr             = 0;
914
    g_curViewscreen               =-1;
914
    g_curViewscreen               =-1;
915
    g_earthquakeTime          = 0;
915
    g_earthquakeTime          = 0;
916
916
917
    g_numInterpolations = 0;
917
    g_numInterpolations = 0;
918
    startofdynamicinterpolations = 0;
918
    startofdynamicinterpolations = 0;
919
919
920
    if (((g&MODE_EOL) != MODE_EOL && numplayers < 2 && !g_netServer) ||
920
    if (((g&MODE_EOL) != MODE_EOL && numplayers < 2 && !g_netServer) ||
921
            (!(GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && numplayers > 1))
921
            (!(GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && numplayers > 1))
922
    {
922
    {
923
        P_ResetWeapons(snum);
923
        P_ResetWeapons(snum);
924
        P_ResetInventory(snum);
924
        P_ResetInventory(snum);
925
    }
925
    }
926
    else if (PWEAPON(snum, p->curr_weapon, WorksLike) == HANDREMOTE_WEAPON)
926
    else if (PWEAPON(snum, p->curr_weapon, WorksLike) == HANDREMOTE_WEAPON)
927
    {
927
    {
928
        p->ammo_amount[HANDBOMB_WEAPON]++;
928
        p->ammo_amount[HANDBOMB_WEAPON]++;
929
        p->curr_weapon = HANDBOMB_WEAPON;
929
        p->curr_weapon = HANDBOMB_WEAPON;
930
    }
930
    }
931
931
932
    p->timebeforeexit   = 0;
932
    p->timebeforeexit   = 0;
933
    p->customexitsound  = 0;
933
    p->customexitsound  = 0;
934
}
934
}
935
935
936
// Tweak sprites contained in moving sectors with these SE lotags.
936
// Tweak sprites contained in moving sectors with these SE lotags.
937
#define FIXSPR_SELOTAGP(k) \
937
#define FIXSPR_SELOTAGP(k) \
938
    ((k)==SE_0_ROTATING_SECTOR \
938
    ((k)==SE_0_ROTATING_SECTOR \
939
     || (k)==SE_6_SUBWAY \
939
     || (k)==SE_6_SUBWAY \
940
     || (k)==SE_14_SUBWAY_CAR)
940
     || (k)==SE_14_SUBWAY_CAR)
941
941
942
// Set up sprites in moving sectors that are to be fixed wrt a certain pivot
942
// Set up sprites in moving sectors that are to be fixed wrt a certain pivot
943
// position and should not diverge from it due to roundoff error in the future.
943
// position and should not diverge from it due to roundoff error in the future.
944
// Has to be after the spawning stuff.
944
// Has to be after the spawning stuff.
945
static void G_SetupRotfixedSprites(void)
945
static void G_SetupRotfixedSprites(void)
946
{
946
{
947
    int32_t i;
947
    int32_t i;
948
948
949
    for (i=headspritestat[STAT_EFFECTOR]; i>=0; i=nextspritestat[i])
949
    for (i=headspritestat[STAT_EFFECTOR]; i>=0; i=nextspritestat[i])
950
    {
950
    {
951
        if (FIXSPR_SELOTAGP(sprite[i].lotag))
951
        if (FIXSPR_SELOTAGP(sprite[i].lotag))
952
        {
952
        {
953
#ifdef YAX_ENABLE
953
#ifdef YAX_ENABLE
954
            int32_t firstrun = 1;
954
            int32_t firstrun = 1;
955
#endif
955
#endif
956
            int32_t j = headspritesect[sprite[i].sectnum];
956
            int32_t j = headspritesect[sprite[i].sectnum];
957
957
958
            while (j>=0)
958
            while (j>=0)
959
            {
959
            {
960
                const spritetype *const spr = &sprite[j];
960
                const spritetype *const spr = &sprite[j];
961
961
962
                // TRIPBOMB uses t_data[7] for its own purposes. Wouldn't be
962
                // TRIPBOMB uses t_data[7] for its own purposes. Wouldn't be
963
                // too useful with moving sectors anyway
963
                // too useful with moving sectors anyway
964
                if ((ROTFIXSPR_STATNUMP(spr->statnum) && spr->picnum!=TRIPBOMB) ||
964
                if ((ROTFIXSPR_STATNUMP(spr->statnum) && spr->picnum!=TRIPBOMB) ||
965
                    ((spr->statnum==STAT_ACTOR || spr->statnum==STAT_ZOMBIEACTOR) &&
965
                    ((spr->statnum==STAT_ACTOR || spr->statnum==STAT_ZOMBIEACTOR) &&
966
                     A_CheckSpriteTileFlags(spr->picnum, SFLAG_ROTFIXED)))
966
                     A_CheckSpriteTileFlags(spr->picnum, SFLAG_ROTFIXED)))
967
                {
967
                {
968
                    int32_t pivot = i;
968
                    int32_t pivot = i;
969
969
970
                    if (sprite[i].lotag==0)
970
                    if (sprite[i].lotag==0)
971
                        pivot = sprite[i].owner;
971
                        pivot = sprite[i].owner;
972
                    if (j!=i && j!=pivot && pivot>=0 && pivot<MAXSPRITES)
972
                    if (j!=i && j!=pivot && pivot>=0 && pivot<MAXSPRITES)
973
                    {
973
                    {
974
                        // let's hope we don't step on anyone's toes here
974
                        // let's hope we don't step on anyone's toes here
975
                        actor[j].t_data[7] = ROTFIXSPR_MAGIC | pivot; // 'rs' magic + pivot SE sprite index
975
                        actor[j].t_data[7] = ROTFIXSPR_MAGIC | pivot; // 'rs' magic + pivot SE sprite index
976
                        actor[j].t_data[8] = spr->x - sprite[pivot].x;
976
                        actor[j].t_data[8] = spr->x - sprite[pivot].x;
977
                        actor[j].t_data[9] = spr->y - sprite[pivot].y;
977
                        actor[j].t_data[9] = spr->y - sprite[pivot].y;
978
                    }
978
                    }
979
                }
979
                }
980
980
981
                j = nextspritesect[j];
981
                j = nextspritesect[j];
982
#ifdef YAX_ENABLE
982
#ifdef YAX_ENABLE
983
                if (j<0 && firstrun)
983
                if (j<0 && firstrun)
984
                    if (sprite[i].lotag==SE_6_SUBWAY || sprite[i].lotag==SE_14_SUBWAY_CAR)
984
                    if (sprite[i].lotag==SE_6_SUBWAY || sprite[i].lotag==SE_14_SUBWAY_CAR)
985
                    {
985
                    {
986
                        firstrun = 0;
986
                        firstrun = 0;
987
                        j = actor[i].t_data[9];
987
                        j = actor[i].t_data[9];
988
                        if (j >= 0)
988
                        if (j >= 0)
989
                            j = headspritesect[j];
989
                            j = headspritesect[j];
990
                    }
990
                    }
991
#endif
991
#endif
992
            }
992
            }
993
        }
993
        }
994
    }
994
    }
995
}
995
}
996
996
997
static inline int32_t G_CheckExitSprite(int32_t i)
997
static inline int32_t G_CheckExitSprite(int32_t i)
998
{
998
{
999
    return (sprite[i].lotag == UINT16_MAX && (sprite[i].cstat&16));
999
    return (sprite[i].lotag == UINT16_MAX && (sprite[i].cstat&16));
1000
}
1000
}
1001
1001
1002
static void prelevel(char g)
1002
static void prelevel(char g)
1003
{
1003
{
1004
    int32_t i, nexti, j, startwall, endwall;
1004
    int32_t i, nexti, j, startwall, endwall;
1005
    int32_t switchpicnum;
1005
    int32_t switchpicnum;
1006
    uint8_t *tagbitmap = (uint8_t *)Xcalloc(65536>>3, 1);
1006
    uint8_t *tagbitmap = (uint8_t *)Xcalloc(65536>>3, 1);
1007
1007
1008
    Bmemset(show2dsector, 0, sizeof(show2dsector));
1008
    Bmemset(show2dsector, 0, sizeof(show2dsector));
1009
#ifdef LEGACY_ROR
1009
#ifdef LEGACY_ROR
1010
    Bmemset(ror_protectedsectors, 0, MAXSECTORS);
1010
    Bmemset(ror_protectedsectors, 0, MAXSECTORS);
1011
#endif
1011
#endif
1012
    resetprestat(0,g);
1012
    resetprestat(0,g);
1013
    g_numClouds = 0;
1013
    g_numClouds = 0;
1014
1014
1015
    G_SetupGlobalPsky();
1015
    G_SetupGlobalPsky();
1016
1016
1017
    for (i=0; i<numsectors; i++)
1017
    for (i=0; i<numsectors; i++)
1018
    {
1018
    {
1019
        sector[i].extra = 256;
1019
        sector[i].extra = 256;
1020
1020
1021
        switch (sector[i].lotag)
1021
        switch (sector[i].lotag)
1022
        {
1022
        {
1023
        case ST_20_CEILING_DOOR:
1023
        case ST_20_CEILING_DOOR:
1024
        case ST_22_SPLITTING_DOOR:
1024
        case ST_22_SPLITTING_DOOR:
1025
            if (sector[i].floorz > sector[i].ceilingz)
1025
            if (sector[i].floorz > sector[i].ceilingz)
1026
                sector[i].lotag |= 32768;
1026
                sector[i].lotag |= 32768;
1027
            continue;
1027
            continue;
1028
        }
1028
        }
1029
1029
1030
        if (sector[i].ceilingstat&1)
1030
        if (sector[i].ceilingstat&1)
1031
        {
1031
        {
1032
            if (waloff[sector[i].ceilingpicnum] == 0)
1032
            if (waloff[sector[i].ceilingpicnum] == 0)
1033
            {
1033
            {
1034
                if (sector[i].ceilingpicnum == LA)
1034
                if (sector[i].ceilingpicnum == LA)
1035
                    for (j=0; j<5; j++)
1035
                    for (j=0; j<5; j++)
1036
                        tloadtile(sector[i].ceilingpicnum+j, 0);
1036
                        tloadtile(sector[i].ceilingpicnum+j, 0);
1037
            }
1037
            }
1038
1038
1039
            if (sector[i].ceilingpicnum == CLOUDYSKIES && g_numClouds < 127)
1039
            if (sector[i].ceilingpicnum == CLOUDYSKIES && g_numClouds < 127)
1040
                clouds[g_numClouds++] = i;
1040
                clouds[g_numClouds++] = i;
1041
1041
1042
            if (g_player[0].ps->one_parallax_sectnum == -1)
1042
            if (g_player[0].ps->one_parallax_sectnum == -1)
1043
                g_player[0].ps->one_parallax_sectnum = i;
1043
                g_player[0].ps->one_parallax_sectnum = i;
1044
        }
1044
        }
1045
1045
1046
        if (sector[i].lotag == 32767) //Found a secret room
1046
        if (sector[i].lotag == 32767) //Found a secret room
1047
        {
1047
        {
1048
            g_player[0].ps->max_secret_rooms++;
1048
            g_player[0].ps->max_secret_rooms++;
1049
            continue;
1049
            continue;
1050
        }
1050
        }
1051
1051
1052
        if (sector[i].lotag == UINT16_MAX)
1052
        if (sector[i].lotag == UINT16_MAX)
1053
        {
1053
        {
1054
            g_player[0].ps->exitx = wall[sector[i].wallptr].x;
1054
            g_player[0].ps->exitx = wall[sector[i].wallptr].x;
1055
            g_player[0].ps->exity = wall[sector[i].wallptr].y;
1055
            g_player[0].ps->exity = wall[sector[i].wallptr].y;
1056
            continue;
1056
            continue;
1057
        }
1057
        }
1058
    }
1058
    }
1059
1059
1060
    // NOTE: must be safe loop because callbacks could delete sprites.
1060
    // NOTE: must be safe loop because callbacks could delete sprites.
1061
    for (SPRITES_OF_STAT_SAFE(STAT_DEFAULT, i, nexti))
1061
    for (SPRITES_OF_STAT_SAFE(STAT_DEFAULT, i, nexti))
1062
    {
1062
    {
1063
        A_ResetVars(i);
1063
        A_ResetVars(i);
1064
#if !defined LUNATIC
1064
#if !defined LUNATIC
1065
        A_LoadActor(i);
1065
        A_LoadActor(i);
1066
#endif
1066
#endif
1067
        VM_OnEvent(EVENT_LOADACTOR, i, -1);
1067
        VM_OnEvent(EVENT_LOADACTOR, i, -1);
1068
        if (G_CheckExitSprite(i))
1068
        if (G_CheckExitSprite(i))
1069
        {
1069
        {
1070
            g_player[0].ps->exitx = SX;
1070
            g_player[0].ps->exitx = SX;
1071
            g_player[0].ps->exity = SY;
1071
            g_player[0].ps->exity = SY;
1072
        }
1072
        }
1073
        else switch (DYNAMICTILEMAP(PN))
1073
        else switch (DYNAMICTILEMAP(PN))
1074
            {
1074
            {
1075
            case GPSPEED__STATIC:
1075
            case GPSPEED__STATIC:
1076
                // DELETE_AFTER_LOADACTOR. Must not change statnum.
1076
                // DELETE_AFTER_LOADACTOR. Must not change statnum.
1077
                sector[SECT].extra = SLT;
1077
                sector[SECT].extra = SLT;
1078
                break;
1078
                break;
1079
1079
1080
            case CYCLER__STATIC:
1080
            case CYCLER__STATIC:
1081
                // DELETE_AFTER_LOADACTOR. Must not change statnum.
1081
                // DELETE_AFTER_LOADACTOR. Must not change statnum.
1082
                if (g_numCyclers >= MAXCYCLERS)
1082
                if (g_numCyclers >= MAXCYCLERS)
1083
                {
1083
                {
1084
                    Bsprintf(tempbuf,"\nToo many cycling sectors (%d max).",MAXCYCLERS);
1084
                    Bsprintf(tempbuf,"\nToo many cycling sectors (%d max).",MAXCYCLERS);
1085
                    G_GameExit(tempbuf);
1085
                    G_GameExit(tempbuf);
1086
                }
1086
                }
1087
                cyclers[g_numCyclers][0] = SECT;
1087
                cyclers[g_numCyclers][0] = SECT;
1088
                cyclers[g_numCyclers][1] = SLT;
1088
                cyclers[g_numCyclers][1] = SLT;
1089
                cyclers[g_numCyclers][2] = SS;
1089
                cyclers[g_numCyclers][2] = SS;
1090
                cyclers[g_numCyclers][3] = sector[SECT].floorshade;
1090
                cyclers[g_numCyclers][3] = sector[SECT].floorshade;
1091
                cyclers[g_numCyclers][4] = SHT;
1091
                cyclers[g_numCyclers][4] = SHT;
1092
                cyclers[g_numCyclers][5] = (SA == 1536);
1092
                cyclers[g_numCyclers][5] = (SA == 1536);
1093
                g_numCyclers++;
1093
                g_numCyclers++;
1094
                break;
1094
                break;
1095
1095
1096
            case SECTOREFFECTOR__STATIC:
1096
            case SECTOREFFECTOR__STATIC:
1097
            case ACTIVATOR__STATIC:
1097
            case ACTIVATOR__STATIC:
1098
            case TOUCHPLATE__STATIC:
1098
            case TOUCHPLATE__STATIC:
1099
            case ACTIVATORLOCKED__STATIC:
1099
            case ACTIVATORLOCKED__STATIC:
1100
            case MUSICANDSFX__STATIC:
1100
            case MUSICANDSFX__STATIC:
1101
            case LOCATORS__STATIC:
1101
            case LOCATORS__STATIC:
1102
            case MASTERSWITCH__STATIC:
1102
            case MASTERSWITCH__STATIC:
1103
            case RESPAWN__STATIC:
1103
            case RESPAWN__STATIC:
1104
                sprite[i].cstat &= ~(1|256);
1104
                sprite[i].cstat &= ~(1|256);
1105
                break;
1105
                break;
1106
            }
1106
            }
1107
    }
1107
    }
1108
1108
1109
    // Delete some effector / effector modifier sprites AFTER the loop running
1109
    // Delete some effector / effector modifier sprites AFTER the loop running
1110
    // the LOADACTOR events. DELETE_AFTER_LOADACTOR.
1110
    // the LOADACTOR events. DELETE_AFTER_LOADACTOR.
1111
    for (SPRITES_OF_STAT_SAFE(STAT_DEFAULT, i, nexti))
1111
    for (SPRITES_OF_STAT_SAFE(STAT_DEFAULT, i, nexti))
1112
        if (!G_CheckExitSprite(i))
1112
        if (!G_CheckExitSprite(i))
1113
            switch (DYNAMICTILEMAP(PN))
1113
            switch (DYNAMICTILEMAP(PN))
1114
            {
1114
            {
1115
            case GPSPEED__STATIC:
1115
            case GPSPEED__STATIC:
1116
            case CYCLER__STATIC:
1116
            case CYCLER__STATIC:
1117
                A_DeleteSprite(i);
1117
                A_DeleteSprite(i);
1118
                break;
1118
                break;
1119
            }
1119
            }
1120
1120
1121
    for (i = 0; i < MAXSPRITES; i++)
1121
    for (i = 0; i < MAXSPRITES; i++)
1122
    {
1122
    {
1123
        if (sprite[i].statnum < MAXSTATUS && (PN != SECTOREFFECTOR || SLT != SE_14_SUBWAY_CAR))
1123
        if (sprite[i].statnum < MAXSTATUS && (PN != SECTOREFFECTOR || SLT != SE_14_SUBWAY_CAR))
1124
            A_Spawn(-1, i);
1124
            A_Spawn(-1, i);
1125
    }
1125
    }
1126
1126
1127
    for (i = 0; i < MAXSPRITES; i++)
1127
    for (i = 0; i < MAXSPRITES; i++)
1128
    {
1128
    {
1129
        if (sprite[i].statnum < MAXSTATUS && PN == SECTOREFFECTOR && SLT == SE_14_SUBWAY_CAR)
1129
        if (sprite[i].statnum < MAXSTATUS && PN == SECTOREFFECTOR && SLT == SE_14_SUBWAY_CAR)
1130
            A_Spawn(-1, i);
1130
            A_Spawn(-1, i);
1131
    }
1131
    }
1132
1132
1133
    G_SetupRotfixedSprites();
1133
    G_SetupRotfixedSprites();
1134
1134
1135
    for (i=headspritestat[STAT_DEFAULT]; i>=0; i=nextspritestat[i])
1135
    for (i=headspritestat[STAT_DEFAULT]; i>=0; i=nextspritestat[i])
1136
    {
1136
    {
1137
        int32_t ii;
1137
        int32_t ii;
1138
1138
1139
        if (PN <= 0)  // oob safety for switch below
1139
        if (PN <= 0)  // oob safety for switch below
1140
            continue;
1140
            continue;
1141
1141
1142
        for (ii=0; ii<2; ii++)
1142
        for (ii=0; ii<2; ii++)
1143
            switch (DYNAMICTILEMAP(PN-1+ii))
1143
            switch (DYNAMICTILEMAP(PN-1+ii))
1144
            {
1144
            {
1145
            case DIPSWITCH__STATIC:
1145
            case DIPSWITCH__STATIC:
1146
            case DIPSWITCH2__STATIC:
1146
            case DIPSWITCH2__STATIC:
1147
            case PULLSWITCH__STATIC:
1147
            case PULLSWITCH__STATIC:
1148
            case HANDSWITCH__STATIC:
1148
            case HANDSWITCH__STATIC:
1149
            case SLOTDOOR__STATIC:
1149
            case SLOTDOOR__STATIC:
1150
            case LIGHTSWITCH__STATIC:
1150
            case LIGHTSWITCH__STATIC:
1151
            case SPACELIGHTSWITCH__STATIC:
1151
            case SPACELIGHTSWITCH__STATIC:
1152
            case SPACEDOORSWITCH__STATIC:
1152
            case SPACEDOORSWITCH__STATIC:
1153
            case FRANKENSTINESWITCH__STATIC:
1153
            case FRANKENSTINESWITCH__STATIC:
1154
            case LIGHTSWITCH2__STATIC:
1154
            case LIGHTSWITCH2__STATIC:
1155
            case POWERSWITCH1__STATIC:
1155
            case POWERSWITCH1__STATIC:
1156
            case LOCKSWITCH1__STATIC:
1156
            case LOCKSWITCH1__STATIC:
1157
            case POWERSWITCH2__STATIC:
1157
            case POWERSWITCH2__STATIC:
1158
                // the lower code only for the 'on' state (*)
1158
                // the lower code only for the 'on' state (*)
1159
                if (ii==0)
1159
                if (ii==0)
1160
                {
1160
                {
1161
                    j = sprite[i].lotag;
1161
                    j = sprite[i].lotag;
1162
                    tagbitmap[j>>3] |= 1<<(j&7);
1162
                    tagbitmap[j>>3] |= 1<<(j&7);
1163
                }
1163
                }
1164
1164
1165
                break;
1165
                break;
1166
            }
1166
            }
1167
    }
1167
    }
1168
1168
1169
    // initially 'on' SE 12 light (*)
1169
    // initially 'on' SE 12 light (*)
1170
    for (j=headspritestat[STAT_EFFECTOR]; j>=0; j=nextspritestat[j])
1170
    for (j=headspritestat[STAT_EFFECTOR]; j>=0; j=nextspritestat[j])
1171
    {
1171
    {
1172
        int32_t t = sprite[j].hitag;
1172
        int32_t t = sprite[j].hitag;
1173
1173
1174
        if (sprite[j].lotag == SE_12_LIGHT_SWITCH && tagbitmap[t>>3]&(1<<(t&7)))
1174
        if (sprite[j].lotag == SE_12_LIGHT_SWITCH && tagbitmap[t>>3]&(1<<(t&7)))
1175
            actor[j].t_data[0] = 1;
1175
            actor[j].t_data[0] = 1;
1176
    }
1176
    }
1177
1177
1178
    Bfree(tagbitmap);
1178
    Bfree(tagbitmap);
1179
1179
1180
    g_mirrorCount = 0;
1180
    g_mirrorCount = 0;
1181
1181
1182
    for (i = 0; i < numwalls; i++)
1182
    for (i = 0; i < numwalls; i++)
1183
    {
1183
    {
1184
        walltype *wal;
1184
        walltype *wal;
1185
        wal = &wall[i];
1185
        wal = &wall[i];
1186
1186
1187
        if (wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
1187
        if (wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
1188
        {
1188
        {
1189
            j = wal->nextsector;
1189
            j = wal->nextsector;
1190
1190
1191
            if ((j >= 0) && sector[j].ceilingpicnum != MIRROR)
1191
            if ((j >= 0) && sector[j].ceilingpicnum != MIRROR)
1192
            {
1192
            {
1193
                if (g_mirrorCount > 63)
1193
                if (g_mirrorCount > 63)
1194
                    G_GameExit("\nToo many mirrors (64 max.)");
1194
                    G_GameExit("\nToo many mirrors (64 max.)");
1195
1195
1196
                sector[j].ceilingpicnum = MIRROR;
1196
                sector[j].ceilingpicnum = MIRROR;
1197
                sector[j].floorpicnum = MIRROR;
1197
                sector[j].floorpicnum = MIRROR;
1198
                g_mirrorWall[g_mirrorCount] = i;
1198
                g_mirrorWall[g_mirrorCount] = i;
1199
                g_mirrorSector[g_mirrorCount] = j;
1199
                g_mirrorSector[g_mirrorCount] = j;
1200
                g_mirrorCount++;
1200
                g_mirrorCount++;
1201
                continue;
1201
                continue;
1202
            }
1202
            }
1203
        }
1203
        }
1204
1204
1205
        if (g_numAnimWalls >= MAXANIMWALLS)
1205
        if (g_numAnimWalls >= MAXANIMWALLS)
1206
        {
1206
        {
1207
            Bsprintf(tempbuf,"\nToo many 'anim' walls (%d max).",MAXANIMWALLS);
1207
            Bsprintf(tempbuf,"\nToo many 'anim' walls (%d max).",MAXANIMWALLS);
1208
            G_GameExit(tempbuf);
1208
            G_GameExit(tempbuf);
1209
        }
1209
        }
1210
1210
1211
        animwall[g_numAnimWalls].tag = 0;
1211
        animwall[g_numAnimWalls].tag = 0;
1212
        animwall[g_numAnimWalls].wallnum = 0;
1212
        animwall[g_numAnimWalls].wallnum = 0;
1213
1213
1214
        switchpicnum = G_GetForcefieldPicnum(i);
1214
        switchpicnum = G_GetForcefieldPicnum(i);
1215
1215
1216
        if (switchpicnum >= 0)
1216
        if (switchpicnum >= 0)
1217
        {
1217
        {
1218
            switch (DYNAMICTILEMAP(switchpicnum))
1218
            switch (DYNAMICTILEMAP(switchpicnum))
1219
            {
1219
            {
1220
            case FANSHADOW__STATIC:
1220
            case FANSHADOW__STATIC:
1221
            case FANSPRITE__STATIC:
1221
            case FANSPRITE__STATIC:
1222
                wall->cstat |= 65;
1222
                wall->cstat |= 65;
1223
                animwall[g_numAnimWalls].wallnum = i;
1223
                animwall[g_numAnimWalls].wallnum = i;
1224
                g_numAnimWalls++;
1224
                g_numAnimWalls++;
1225
                break;
1225
                break;
1226
1226
1227
            case W_FORCEFIELD__STATIC:
1227
            case W_FORCEFIELD__STATIC:
1228
                if (wal->overpicnum==W_FORCEFIELD__STATIC)
1228
                if (wal->overpicnum==W_FORCEFIELD__STATIC)
1229
                    for (j=0; j<3; j++)
1229
                    for (j=0; j<3; j++)
1230
                        tloadtile(W_FORCEFIELD+j, 0);
1230
                        tloadtile(W_FORCEFIELD+j, 0);
1231
                if (wal->shade > 31)
1231
                if (wal->shade > 31)
1232
                    wal->cstat = 0;
1232
                    wal->cstat = 0;
1233
                else wal->cstat |= FORCEFIELD_CSTAT|256;
1233
                else wal->cstat |= FORCEFIELD_CSTAT|256;
1234
1234
1235
1235
1236
                if (wal->lotag && wal->nextwall >= 0)
1236
                if (wal->lotag && wal->nextwall >= 0)
1237
                    wall[wal->nextwall].lotag =
1237
                    wall[wal->nextwall].lotag =
1238
                        wal->lotag;
1238
                        wal->lotag;
1239
1239
1240
            case BIGFORCE__STATIC:
1240
            case BIGFORCE__STATIC:
1241
                animwall[g_numAnimWalls].wallnum = i;
1241
                animwall[g_numAnimWalls].wallnum = i;
1242
                g_numAnimWalls++;
1242
                g_numAnimWalls++;
1243
1243
1244
                continue;
1244
                continue;
1245
            }
1245
            }
1246
        }
1246
        }
1247
1247
1248
        wal->extra = -1;
1248
        wal->extra = -1;
1249
1249
1250
        switch (DYNAMICTILEMAP(wal->picnum))
1250
        switch (DYNAMICTILEMAP(wal->picnum))
1251
        {
1251
        {
1252
        case WATERTILE2__STATIC:
1252
        case WATERTILE2__STATIC:
1253
            for (j=0; j<3; j++)
1253
            for (j=0; j<3; j++)
1254
                tloadtile(wal->picnum+j, 0);
1254
                tloadtile(wal->picnum+j, 0);
1255
            break;
1255
            break;
1256
1256
1257
        case TECHLIGHT2__STATIC:
1257
        case TECHLIGHT2__STATIC:
1258
        case TECHLIGHT4__STATIC:
1258
        case TECHLIGHT4__STATIC:
1259
            tloadtile(wal->picnum, 0);
1259
            tloadtile(wal->picnum, 0);
1260
            break;
1260
            break;
1261
        case W_TECHWALL1__STATIC:
1261
        case W_TECHWALL1__STATIC:
1262
        case W_TECHWALL2__STATIC:
1262
        case W_TECHWALL2__STATIC:
1263
        case W_TECHWALL3__STATIC:
1263
        case W_TECHWALL3__STATIC:
1264
        case W_TECHWALL4__STATIC:
1264
        case W_TECHWALL4__STATIC:
1265
            animwall[g_numAnimWalls].wallnum = i;
1265
            animwall[g_numAnimWalls].wallnum = i;
1266
            //                animwall[g_numAnimWalls].tag = -1;
1266
            //                animwall[g_numAnimWalls].tag = -1;
1267
            g_numAnimWalls++;
1267
            g_numAnimWalls++;
1268
            break;
1268
            break;
1269
        case SCREENBREAK6__STATIC:
1269
        case SCREENBREAK6__STATIC:
1270
        case SCREENBREAK7__STATIC:
1270
        case SCREENBREAK7__STATIC:
1271
        case SCREENBREAK8__STATIC:
1271
        case SCREENBREAK8__STATIC:
1272
            for (j=SCREENBREAK6; j<SCREENBREAK9; j++)
1272
            for (j=SCREENBREAK6; j<SCREENBREAK9; j++)
1273
                tloadtile(j, 0);
1273
                tloadtile(j, 0);
1274
            animwall[g_numAnimWalls].wallnum = i;
1274
            animwall[g_numAnimWalls].wallnum = i;
1275
            animwall[g_numAnimWalls].tag = -1;
1275
            animwall[g_numAnimWalls].tag = -1;
1276
            g_numAnimWalls++;
1276
            g_numAnimWalls++;
1277
            break;
1277
            break;
1278
1278
1279
        case FEMPIC1__STATIC:
1279
        case FEMPIC1__STATIC:
1280
        case FEMPIC2__STATIC:
1280
        case FEMPIC2__STATIC:
1281
        case FEMPIC3__STATIC:
1281
        case FEMPIC3__STATIC:
1282
            wal->extra = wal->picnum;
1282
            wal->extra = wal->picnum;
1283
            animwall[g_numAnimWalls].tag = -1;
1283
            animwall[g_numAnimWalls].tag = -1;
1284
            if (ud.lockout)
1284
            if (ud.lockout)
1285
            {
1285
            {
1286
                if (wal->picnum == FEMPIC1)
1286
                if (wal->picnum == FEMPIC1)
1287
                    wal->picnum = BLANKSCREEN;
1287
                    wal->picnum = BLANKSCREEN;
1288
                else wal->picnum = SCREENBREAK6;
1288
                else wal->picnum = SCREENBREAK6;
1289
            }
1289
            }
1290
1290
1291
            animwall[g_numAnimWalls].wallnum = i;
1291
            animwall[g_numAnimWalls].wallnum = i;
1292
            animwall[g_numAnimWalls].tag = wal->picnum;
1292
            animwall[g_numAnimWalls].tag = wal->picnum;
1293
            g_numAnimWalls++;
1293
            g_numAnimWalls++;
1294
            break;
1294
            break;
1295
1295
1296
        case SCREENBREAK1__STATIC:
1296
        case SCREENBREAK1__STATIC:
1297
        case SCREENBREAK2__STATIC:
1297
        case SCREENBREAK2__STATIC:
1298
        case SCREENBREAK3__STATIC:
1298
        case SCREENBREAK3__STATIC:
1299
        case SCREENBREAK4__STATIC:
1299
        case SCREENBREAK4__STATIC:
1300
        case SCREENBREAK5__STATIC:
1300
        case SCREENBREAK5__STATIC:
1301
            //
1301
            //
1302
        case SCREENBREAK9__STATIC:
1302
        case SCREENBREAK9__STATIC:
1303
        case SCREENBREAK10__STATIC:
1303
        case SCREENBREAK10__STATIC:
1304
        case SCREENBREAK11__STATIC:
1304
        case SCREENBREAK11__STATIC:
1305
        case SCREENBREAK12__STATIC:
1305
        case SCREENBREAK12__STATIC:
1306
        case SCREENBREAK13__STATIC:
1306
        case SCREENBREAK13__STATIC:
1307
        case SCREENBREAK14__STATIC:
1307
        case SCREENBREAK14__STATIC:
1308
        case SCREENBREAK15__STATIC:
1308
        case SCREENBREAK15__STATIC:
1309
        case SCREENBREAK16__STATIC:
1309
        case SCREENBREAK16__STATIC:
1310
        case SCREENBREAK17__STATIC:
1310
        case SCREENBREAK17__STATIC:
1311
        case SCREENBREAK18__STATIC:
1311
        case SCREENBREAK18__STATIC:
1312
        case SCREENBREAK19__STATIC:
1312
        case SCREENBREAK19__STATIC:
1313
            animwall[g_numAnimWalls].wallnum = i;
1313
            animwall[g_numAnimWalls].wallnum = i;
1314
            animwall[g_numAnimWalls].tag = wal->picnum;
1314
            animwall[g_numAnimWalls].tag = wal->picnum;
1315
            g_numAnimWalls++;
1315
            g_numAnimWalls++;
1316
            break;
1316
            break;
1317
        }
1317
        }
1318
    }
1318
    }
1319
1319
1320
    //Invalidate textures in sector behind mirror
1320
    //Invalidate textures in sector behind mirror
1321
    for (i=0; i<g_mirrorCount; i++)
1321
    for (i=0; i<g_mirrorCount; i++)
1322
    {
1322
    {
1323
        startwall = sector[g_mirrorSector[i]].wallptr;
1323
        startwall = sector[g_mirrorSector[i]].wallptr;
1324
        endwall = startwall + sector[g_mirrorSector[i]].wallnum;
1324
        endwall = startwall + sector[g_mirrorSector[i]].wallnum;
1325
        for (j=startwall; j<endwall; j++)
1325
        for (j=startwall; j<endwall; j++)
1326
        {
1326
        {
1327
            wall[j].picnum = MIRROR;
1327
            wall[j].picnum = MIRROR;
1328
            wall[j].overpicnum = MIRROR;
1328
            wall[j].overpicnum = MIRROR;
1329
            if (wall[g_mirrorWall[i]].pal == 4)
1329
            if (wall[g_mirrorWall[i]].pal == 4)
1330
                wall[j].pal = 4;
1330
                wall[j].pal = 4;
1331
        }
1331
        }
1332
    }
1332
    }
1333
}
1333
}
1334
1334
1335
1335
1336
void G_NewGame(int32_t vn, int32_t ln, int32_t sk)
1336
void G_NewGame(int32_t vn, int32_t ln, int32_t sk)
1337
{
1337
{
1338
    DukePlayer_t *p = g_player[0].ps;
1338
    DukePlayer_t *p = g_player[0].ps;
1339
    int32_t i;
1339
    int32_t i;
1340
1340
1341
    G_HandleAsync();
1341
    G_HandleAsync();
1342
1342
1343
    if (g_skillSoundVoice >= 0 && ud.config.SoundToggle)
1343
    if (g_skillSoundVoice >= 0 && ud.config.SoundToggle)
1344
    {
1344
    {
1345
        while (FX_SoundActive(g_skillSoundVoice))
1345
        while (FX_SoundActive(g_skillSoundVoice))
1346
            G_HandleAsync();
1346
            G_HandleAsync();
1347
    }
1347
    }
1348
1348
1349
    g_skillSoundVoice = -1;
1349
    g_skillSoundVoice = -1;
1350
1350
1351
    ready2send = 0;
1351
    ready2send = 0;
1352
1352
1353
    if (ud.m_recstat != 2 && ud.last_level >= 0 && (g_netServer || ud.multimode > 1) && (ud.coop&GAMETYPE_SCORESHEET))
1353
    if (ud.m_recstat != 2 && ud.last_level >= 0 && (g_netServer || ud.multimode > 1) && (ud.coop&GAMETYPE_SCORESHEET))
1354
        G_BonusScreen(1);
1354
        G_BonusScreen(1);
1355
1355
1356
    if (ln == 0 && vn == 3 && (!g_netServer && ud.multimode < 2) && ud.lockout == 0
1356
    if (ln == 0 && vn == 3 && (!g_netServer && ud.multimode < 2) && ud.lockout == 0
1357
            && (G_GetLogoFlags() & LOGO_NOE4CUTSCENE)==0)
1357
            && (G_GetLogoFlags() & LOGO_NOE4CUTSCENE)==0)
1358
    {
1358
    {
1359
        S_PlayMusic(MapInfo[MUS_BRIEFING].musicfn);
1359
        S_PlayMusic(MapInfo[MUS_BRIEFING].musicfn);
1360
1360
1361
        flushperms();
1361
        flushperms();
1362
        setview(0,0,xdim-1,ydim-1);
1362
        setview(0,0,xdim-1,ydim-1);
1363
        clearview(0L);
1363
        clearview(0L);
1364
        nextpage();
1364
        nextpage();
1365
1365
1366
        i = G_PlayAnim("vol41a.anm",6);
1366
        i = G_PlayAnim("vol41a.anm");
1367
        clearview(0L);
1367
        clearview(0L);
1368
        nextpage();
1368
        nextpage();
1369
        if (i)
1369
        if (i)
1370
            goto end_vol4a;
1370
            goto end_vol4a;
1371
1371
1372
        i = G_PlayAnim("vol42a.anm",7);
1372
        i = G_PlayAnim("vol42a.anm");
1373
        clearview(0L);
1373
        clearview(0L);
1374
        nextpage();
1374
        nextpage();
1375
        if (i)
1375
        if (i)
1376
            goto end_vol4a;
1376
            goto end_vol4a;
1377
1377
1378
        G_PlayAnim("vol43a.anm",9);
1378
        G_PlayAnim("vol43a.anm");
1379
        clearview(0L);
1379
        clearview(0L);
1380
        nextpage();
1380
        nextpage();
1381
1381
1382
end_vol4a:
1382
end_vol4a:
1383
        FX_StopAllSounds();
1383
        FX_StopAllSounds();
1384
    }
1384
    }
1385
1385
1386
    g_showShareware = GAMETICSPERSEC*34;
1386
    g_showShareware = GAMETICSPERSEC*34;
1387
1387
1388
    ud.level_number = ln;
1388
    ud.level_number = ln;
1389
    ud.volume_number = vn;
1389
    ud.volume_number = vn;
1390
    ud.player_skill = sk;
1390
    ud.player_skill = sk;
1391
    ud.secretlevel = 0;
1391
    ud.secretlevel = 0;
1392
    ud.from_bonus = 0;
1392
    ud.from_bonus = 0;
1393
1393
1394
    ud.last_level = -1;
1394
    ud.last_level = -1;
1395
    g_lastSaveSlot = -1;
1395
    g_lastSaveSlot = -1;
1396
1396
1397
#ifdef EDUKE32_TOUCH_DEVICES
1397
#ifdef EDUKE32_TOUCH_DEVICES
1398
    p->zoom = 360;
1398
    p->zoom = 360;
1399
#else
1399
#else
1400
    p->zoom = 768;
1400
    p->zoom = 768;
1401
#endif
1401
#endif
1402
    p->gm = 0;
1402
    p->gm = 0;
1403
    M_CloseMenu(0);
1403
    M_CloseMenu(0);
1404
1404
1405
#if !defined LUNATIC
1405
#if !defined LUNATIC
1406
    //AddLog("Newgame");
1406
    //AddLog("Newgame");
1407
    Gv_ResetVars();
1407
    Gv_ResetVars();
1408
1408
1409
    Gv_InitWeaponPointers();
1409
    Gv_InitWeaponPointers();
1410
1410
1411
    // PK: Gv_ResetVars() might trip up the system (pointer) gamevars,
1411
    // PK: Gv_ResetVars() might trip up the system (pointer) gamevars,
1412
    // e.g. if some earlier-version CON code had been loaded before
1412
    // e.g. if some earlier-version CON code had been loaded before
1413
    Gv_RefreshPointers();
1413
    Gv_RefreshPointers();
1414
#endif
1414
#endif
1415
    Gv_ResetSystemDefaults();
1415
    Gv_ResetSystemDefaults();
1416
1416
1417
    for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
1417
    for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
1418
        if (MapInfo[i].savedstate)
1418
        if (MapInfo[i].savedstate)
1419
        {
1419
        {
1420
            Baligned_free(MapInfo[i].savedstate);
1420
            Baligned_free(MapInfo[i].savedstate);
1421
            MapInfo[i].savedstate = NULL;
1421
            MapInfo[i].savedstate = NULL;
1422
        }
1422
        }
1423
1423
1424
    if (ud.m_coop != 1)
1424
    if (ud.m_coop != 1)
1425
    {
1425
    {
1426
        for (i=0; i<MAX_WEAPONS; i++)
1426
        for (i=0; i<MAX_WEAPONS; i++)
1427
        {
1427
        {
1428
            if (PWEAPON(0, i, WorksLike)==PISTOL_WEAPON)
1428
            if (PWEAPON(0, i, WorksLike)==PISTOL_WEAPON)
1429
            {
1429
            {
1430
                p->curr_weapon = i;
1430
                p->curr_weapon = i;
1431
                p->gotweapon |= (1<<i);
1431
                p->gotweapon |= (1<<i);
1432
                p->ammo_amount[i] = min(p->max_ammo_amount[i], 48);
1432
                p->ammo_amount[i] = min(p->max_ammo_amount[i], 48);
1433
            }
1433
            }
1434
            else if (PWEAPON(0, i, WorksLike)==KNEE_WEAPON)
1434
            else if (PWEAPON(0, i, WorksLike)==KNEE_WEAPON)
1435
                p->gotweapon |= (1<<i);
1435
                p->gotweapon |= (1<<i);
1436
            else if (PWEAPON(0, i, WorksLike)==HANDREMOTE_WEAPON)
1436
            else if (PWEAPON(0, i, WorksLike)==HANDREMOTE_WEAPON)
1437
                p->gotweapon |= (1<<i);
1437
                p->gotweapon |= (1<<i);
1438
        }
1438
        }
1439
        p->last_weapon = -1;
1439
        p->last_weapon = -1;
1440
    }
1440
    }
1441
1441
1442
    display_mirror = 0;
1442
    display_mirror = 0;
1443
1443
1444
#ifdef LUNATIC
1444
#ifdef LUNATIC
1445
    // NOTE: Lunatic state creation is relatively early. No map has yet been loaded.
1445
    // NOTE: Lunatic state creation is relatively early. No map has yet been loaded.
1446
    // XXX: What about the cases where G_EnterLevel() is called without a preceding G_NewGame()?
1446
    // XXX: What about the cases where G_EnterLevel() is called without a preceding G_NewGame()?
1447
    El_CreateGameState();
1447
    El_CreateGameState();
1448
    G_PostCreateGameState();
1448
    G_PostCreateGameState();
1449
#endif
1449
#endif
1450
    VM_OnEvent(EVENT_NEWGAME, g_player[myconnectindex].ps->i, myconnectindex);
1450
    VM_OnEvent(EVENT_NEWGAME, g_player[myconnectindex].ps->i, myconnectindex);
1451
}
1451
}
1452
1452
1453
static void resetpspritevars(char g)
1453
static void resetpspritevars(char g)
1454
{
1454
{
1455
    int16_t i, j; //circ;
1455
    int16_t i, j; //circ;
1456
1456
1457
    uint8_t aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
1457
    uint8_t aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
1458
    DukeStatus_t tsbar[MAXPLAYERS];
1458
    DukeStatus_t tsbar[MAXPLAYERS];
1459
1459
1460
    if (g_player[0].ps->cursectnum >= 0)  // < 0 may happen if we start a map in void space (e.g. testing it)
1460
    if (g_player[0].ps->cursectnum >= 0)  // < 0 may happen if we start a map in void space (e.g. testing it)
1461
    {
1461
    {
1462
        A_InsertSprite(g_player[0].ps->cursectnum,g_player[0].ps->pos.x,g_player[0].ps->pos.y,g_player[0].ps->pos.z,
1462
        A_InsertSprite(g_player[0].ps->cursectnum,g_player[0].ps->pos.x,g_player[0].ps->pos.y,g_player[0].ps->pos.z,
1463
                       APLAYER,0,0,0,g_player[0].ps->ang,0,0,0,10);
1463
                       APLAYER,0,0,0,g_player[0].ps->ang,0,0,0,10);
1464
    }
1464
    }
1465
1465
1466
    if (ud.recstat != 2)
1466
    if (ud.recstat != 2)
1467
        for (TRAVERSE_CONNECT(i))
1467
        for (TRAVERSE_CONNECT(i))
1468
        {
1468
        {
1469
            aimmode[i] = g_player[i].ps->aim_mode;
1469
            aimmode[i] = g_player[i].ps->aim_mode;
1470
            autoaim[i] = g_player[i].ps->auto_aim;
1470
            autoaim[i] = g_player[i].ps->auto_aim;
1471
            weaponswitch[i] = g_player[i].ps->weaponswitch;
1471
            weaponswitch[i] = g_player[i].ps->weaponswitch;
1472
            if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1472
            if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1473
            {
1473
            {
1474
                for (j=0; j<MAX_WEAPONS; j++)
1474
                for (j=0; j<MAX_WEAPONS; j++)
1475
                    tsbar[i].ammo_amount[j] = g_player[i].ps->ammo_amount[j];
1475
                    tsbar[i].ammo_amount[j] = g_player[i].ps->ammo_amount[j];
1476
1476
1477
                tsbar[i].gotweapon = g_player[i].ps->gotweapon;
1477
                tsbar[i].gotweapon = g_player[i].ps->gotweapon;
1478
                Bmemcpy(tsbar[i].inv_amount, g_player[i].ps->inv_amount, sizeof(tsbar[i].inv_amount));
1478
                Bmemcpy(tsbar[i].inv_amount, g_player[i].ps->inv_amount, sizeof(tsbar[i].inv_amount));
1479
                tsbar[i].curr_weapon = g_player[i].ps->curr_weapon;
1479
                tsbar[i].curr_weapon = g_player[i].ps->curr_weapon;
1480
                tsbar[i].inven_icon = g_player[i].ps->inven_icon;
1480
                tsbar[i].inven_icon = g_player[i].ps->inven_icon;
1481
            }
1481
            }
1482
        }
1482
        }
1483
1483
1484
    P_ResetStatus(0);
1484
    P_ResetStatus(0);
1485
1485
1486
    for (TRAVERSE_CONNECT(i))
1486
    for (TRAVERSE_CONNECT(i))
1487
        if (i) Bmemcpy(g_player[i].ps,g_player[0].ps,sizeof(DukePlayer_t));
1487
        if (i) Bmemcpy(g_player[i].ps,g_player[0].ps,sizeof(DukePlayer_t));
1488
1488
1489
    if (ud.recstat != 2)
1489
    if (ud.recstat != 2)
1490
        for (TRAVERSE_CONNECT(i))
1490
        for (TRAVERSE_CONNECT(i))
1491
        {
1491
        {
1492
            g_player[i].ps->aim_mode = aimmode[i];
1492
            g_player[i].ps->aim_mode = aimmode[i];
1493
            g_player[i].ps->auto_aim = autoaim[i];
1493
            g_player[i].ps->auto_aim = autoaim[i];
1494
            g_player[i].ps->weaponswitch = weaponswitch[i];
1494
            g_player[i].ps->weaponswitch = weaponswitch[i];
1495
            if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1495
            if ((g_netServer || ud.multimode > 1) && (GametypeFlags[ud.coop]&GAMETYPE_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
1496
            {
1496
            {
1497
                for (j=0; j<MAX_WEAPONS; j++)
1497
                for (j=0; j<MAX_WEAPONS; j++)
1498
                    g_player[i].ps->ammo_amount[j] = tsbar[i].ammo_amount[j];
1498
                    g_player[i].ps->ammo_amount[j] = tsbar[i].ammo_amount[j];
1499
1499
1500
                g_player[i].ps->gotweapon = tsbar[i].gotweapon;
1500
                g_player[i].ps->gotweapon = tsbar[i].gotweapon;
1501
                g_player[i].ps->curr_weapon = tsbar[i].curr_weapon;
1501
                g_player[i].ps->curr_weapon = tsbar[i].curr_weapon;
1502
                g_player[i].ps->inven_icon = tsbar[i].inven_icon;
1502
                g_player[i].ps->inven_icon = tsbar[i].inven_icon;
1503
                Bmemcpy(g_player[i].ps->inv_amount, tsbar[i].inv_amount, sizeof(tsbar[i].inv_amount));
1503
                Bmemcpy(g_player[i].ps->inv_amount, tsbar[i].inv_amount, sizeof(tsbar[i].inv_amount));
1504
            }
1504
            }
1505
        }
1505
        }
1506
1506
1507
    g_numPlayerSprites = 0;
1507
    g_numPlayerSprites = 0;
1508
//    circ = 2048/ud.multimode;
1508
//    circ = 2048/ud.multimode;
1509
1509
1510
    g_whichPalForPlayer = 9;
1510
    g_whichPalForPlayer = 9;
1511
    j = 0;
1511
    j = 0;
1512
    i = headspritestat[STAT_PLAYER];
1512
    i = headspritestat[STAT_PLAYER];
1513
    while (i >= 0)
1513
    while (i >= 0)
1514
    {
1514
    {
1515
        const int32_t nexti = nextspritestat[i];
1515
        const int32_t nexti = nextspritestat[i];
1516
        spritetype *const s = &sprite[i];
1516
        spritetype *const s = &sprite[i];
1517
1517
1518
        if (g_numPlayerSprites == MAXPLAYERS)
1518
        if (g_numPlayerSprites == MAXPLAYERS)
1519
            G_GameExit("\nToo many player sprites (max 16.)");
1519
            G_GameExit("\nToo many player sprites (max 16.)");
1520
1520
1521
        g_playerSpawnPoints[g_numPlayerSprites].pos.x = s->x;
1521
        g_playerSpawnPoints[g_numPlayerSprites].pos.x = s->x;
1522
        g_playerSpawnPoints[g_numPlayerSprites].pos.y = s->y;
1522
        g_playerSpawnPoints[g_numPlayerSprites].pos.y = s->y;
1523
        g_playerSpawnPoints[g_numPlayerSprites].pos.z = s->z;
1523
        g_playerSpawnPoints[g_numPlayerSprites].pos.z = s->z;
1524
        g_playerSpawnPoints[g_numPlayerSprites].ang = s->ang;
1524
        g_playerSpawnPoints[g_numPlayerSprites].ang = s->ang;
1525
        g_playerSpawnPoints[g_numPlayerSprites].sect = s->sectnum;
1525
        g_playerSpawnPoints[g_numPlayerSprites].sect = s->sectnum;
1526
1526
1527
        g_numPlayerSprites++;
1527
        g_numPlayerSprites++;
1528
1528
1529
        if (j < MAXPLAYERS)
1529
        if (j < MAXPLAYERS)
1530
        {
1530
        {
1531
            s->owner = i;
1531
            s->owner = i;
1532
            s->shade = 0;
1532
            s->shade = 0;
1533
            s->xrepeat = 42;
1533
            s->xrepeat = 42;
1534
            s->yrepeat = 36;
1534
            s->yrepeat = 36;
1535
            if (!g_fakeMultiMode)
1535
            if (!g_fakeMultiMode)
1536
                s->cstat = j < numplayers ? 1+256 : 32768;
1536
                s->cstat = j < numplayers ? 1+256 : 32768;
1537
            else
1537
            else
1538
                s->cstat = j < ud.multimode ? 1+256 : 32768;
1538
                s->cstat = j < ud.multimode ? 1+256 : 32768;
1539
            s->xoffset = 0;
1539
            s->xoffset = 0;
1540
            s->clipdist = 64;
1540
            s->clipdist = 64;
1541
1541
1542
//            if (j < playerswhenstarted)
1542
//            if (j < playerswhenstarted)
1543
            {
1543
            {
1544
                if ((g&MODE_EOL) != MODE_EOL || g_player[j].ps->last_extra == 0)
1544
                if ((g&MODE_EOL) != MODE_EOL || g_player[j].ps->last_extra == 0)
1545
                {
1545
                {
1546
                    g_player[j].ps->last_extra = g_player[j].ps->max_player_health;
1546
                    g_player[j].ps->last_extra = g_player[j].ps->max_player_health;
1547
                    s->extra = g_player[j].ps->max_player_health;
1547
                    s->extra = g_player[j].ps->max_player_health;
1548
                    g_player[j].ps->runspeed = g_playerFriction;
1548
                    g_player[j].ps->runspeed = g_playerFriction;
1549
                }
1549
                }
1550
                else s->extra = g_player[j].ps->last_extra;
1550
                else s->extra = g_player[j].ps->last_extra;
1551
1551
1552
                s->yvel = j;
1552
                s->yvel = j;
1553
1553
1554
                if (!g_player[j].pcolor && (g_netServer || ud.multimode > 1) && !(GametypeFlags[ud.coop] & GAMETYPE_TDM))
1554
                if (!g_player[j].pcolor && (g_netServer || ud.multimode > 1) && !(GametypeFlags[ud.coop] & GAMETYPE_TDM))
1555
                {
1555
                {
1556
                    if (s->pal == 0)
1556
                    if (s->pal == 0)
1557
                    {
1557
                    {
1558
                        int32_t k = 0;
1558
                        int32_t k = 0;
1559
1559
1560
                        for (; k<ud.multimode; k++)
1560
                        for (; k<ud.multimode; k++)
1561
                        {
1561
                        {
1562
                            if (g_whichPalForPlayer == g_player[k].ps->palookup)
1562
                            if (g_whichPalForPlayer == g_player[k].ps->palookup)
1563
                            {
1563
                            {
1564
                                g_whichPalForPlayer++;
1564
                                g_whichPalForPlayer++;
1565
                                if (g_whichPalForPlayer >= 17)
1565
                                if (g_whichPalForPlayer >= 17)
1566
                                    g_whichPalForPlayer = 9;
1566
                                    g_whichPalForPlayer = 9;
1567
                                k=0;
1567
                                k=0;
1568
                            }
1568
                            }
1569
                        }
1569
                        }
1570
                        g_player[j].pcolor = s->pal = g_player[j].ps->palookup = g_whichPalForPlayer++;
1570
                        g_player[j].pcolor = s->pal = g_player[j].ps->palookup = g_whichPalForPlayer++;
1571
                        if (g_whichPalForPlayer >= 17)
1571
                        if (g_whichPalForPlayer >= 17)
1572
                            g_whichPalForPlayer = 9;
1572
                            g_whichPalForPlayer = 9;
1573
                    }
1573
                    }
1574
                    else g_player[j].pcolor = g_player[j].ps->palookup = s->pal;
1574
                    else g_player[j].pcolor = g_player[j].ps->palookup = s->pal;
1575
                }
1575
                }
1576
                else
1576
                else
1577
                {
1577
                {
1578
                    int32_t k = g_player[j].pcolor;
1578
                    int32_t k = g_player[j].pcolor;
1579
1579
1580
                    if (GametypeFlags[ud.coop] & GAMETYPE_TDM)
1580
                    if (GametypeFlags[ud.coop] & GAMETYPE_TDM)
1581
                    {
1581
                    {
1582
                        k = G_GetTeamPalette(g_player[j].pteam);
1582
                        k = G_GetTeamPalette(g_player[j].pteam);
1583
                        g_player[j].ps->team = g_player[j].pteam;
1583
                        g_player[j].ps->team = g_player[j].pteam;
1584
                    }
1584
                    }
1585
                    s->pal = g_player[j].ps->palookup = k;
1585
                    s->pal = g_player[j].ps->palookup = k;
1586
                }
1586
                }
1587
1587
1588
                g_player[j].ps->i = i;
1588
                g_player[j].ps->i = i;
1589
                g_player[j].ps->frag_ps = j;
1589
                g_player[j].ps->frag_ps = j;
1590
                actor[i].owner = i;
1590
                actor[i].owner = i;
1591
1591
1592
                g_player[j].ps->autostep = (20L<<8);
1592
                g_player[j].ps->autostep = (20L<<8);
1593
                g_player[j].ps->autostep_sbw = (4L<<8);
1593
                g_player[j].ps->autostep_sbw = (4L<<8);
1594
1594
1595
                actor[i].bpos.x = g_player[j].ps->bobpos.x = g_player[j].ps->opos.x = g_player[j].ps->pos.x =        s->x;
1595
                actor[i].bpos.x = g_player[j].ps->bobpos.x = g_player[j].ps->opos.x = g_player[j].ps->pos.x =        s->x;
1596
                actor[i].bpos.y = g_player[j].ps->bobpos.y = g_player[j].ps->opos.y = g_player[j].ps->pos.y =        s->y;
1596
                actor[i].bpos.y = g_player[j].ps->bobpos.y = g_player[j].ps->opos.y = g_player[j].ps->pos.y =        s->y;
1597
                actor[i].bpos.z = g_player[j].ps->opos.z = g_player[j].ps->pos.z =        s->z;
1597
                actor[i].bpos.z = g_player[j].ps->opos.z = g_player[j].ps->pos.z =        s->z;
1598
                g_player[j].ps->oang  = g_player[j].ps->ang  =        s->ang;
1598
                g_player[j].ps->oang  = g_player[j].ps->ang  =        s->ang;
1599
1599
1600
                updatesector(s->x,s->y,&g_player[j].ps->cursectnum);
1600
                updatesector(s->x,s->y,&g_player[j].ps->cursectnum);
1601
            }
1601
            }
1602
1602
1603
            j++;
1603
            j++;
1604
        }
1604
        }
1605
        else A_DeleteSprite(i);
1605
        else A_DeleteSprite(i);
1606
1606
1607
        i = nexti;
1607
        i = nexti;
1608
    }
1608
    }
1609
}
1609
}
1610
1610
1611
static inline void clearfrags(void)
1611
static inline void clearfrags(void)
1612
{
1612
{
1613
    int32_t i;
1613
    int32_t i;
1614
1614
1615
    for (i=0; i<ud.multimode; i++)
1615
    for (i=0; i<ud.multimode; i++)
1616
    {
1616
    {
1617
        playerdata_t *p = &g_player[i];
1617
        playerdata_t *p = &g_player[i];
1618
1618
1619
        p->ps->frag = p->ps->fraggedself = 0;
1619
        p->ps->frag = p->ps->fraggedself = 0;
1620
        Bmemset(p->frags, 0, sizeof(p->frags));
1620
        Bmemset(p->frags, 0, sizeof(p->frags));
1621
    }
1621
    }
1622
}
1622
}
1623
1623
1624
void G_ResetTimers(uint8_t keepgtics)
1624
void G_ResetTimers(uint8_t keepgtics)
1625
{
1625
{
1626
    totalclock = cloudtotalclock = ototalclock = lockclock = 0;
1626
    totalclock = cloudtotalclock = ototalclock = lockclock = 0;
1627
    ready2send = 1;
1627
    ready2send = 1;
1628
    g_levelTextTime = 85;
1628
    g_levelTextTime = 85;
1629
1629
1630
    if (!keepgtics)
1630
    if (!keepgtics)
1631
        g_moveThingsCount = 0;
1631
        g_moveThingsCount = 0;
1632
1632
1633
    if (g_curViewscreen >= 0)
1633
    if (g_curViewscreen >= 0)
1634
        actor[g_curViewscreen].t_data[0] = 0;
1634
        actor[g_curViewscreen].t_data[0] = 0;
1635
}
1635
}
1636
1636
1637
void G_ClearFIFO(void)
1637
void G_ClearFIFO(void)
1638
{
1638
{
1639
    int32_t i = MAXPLAYERS-1;
1639
    int32_t i = MAXPLAYERS-1;
1640
   
1640
   
1641
    g_emuJumpTics = 0;
1641
    g_emuJumpTics = 0;
1642
1642
1643
    Bmemset(&avg, 0, sizeof(input_t));
1643
    Bmemset(&avg, 0, sizeof(input_t));
1644
1644
1645
    clearbufbyte(&loc,sizeof(input_t),0L);
1645
    clearbufbyte(&loc,sizeof(input_t),0L);
1646
    clearbufbyte(&inputfifo,sizeof(input_t)*MOVEFIFOSIZ*MAXPLAYERS,0L);
1646
    clearbufbyte(&inputfifo,sizeof(input_t)*MOVEFIFOSIZ*MAXPLAYERS,0L);
1647
1647
1648
    for (; i >= 0; i--)
1648
    for (; i >= 0; i--)
1649
    {
1649
    {
1650
        if (g_player[i].sync != NULL)
1650
        if (g_player[i].sync != NULL)
1651
            Bmemset(g_player[i].sync, 0, sizeof(input_t));
1651
            Bmemset(g_player[i].sync, 0, sizeof(input_t));
1652
        g_player[i].vote = g_player[i].gotvote = 0;
1652
        g_player[i].vote = g_player[i].gotvote = 0;
1653
    }
1653
    }
1654
}
1654
}
1655
1655
1656
int32_t G_FindLevelByFile(const char *fn)
1656
int32_t G_FindLevelByFile(const char *fn)
1657
{
1657
{
1658
    for (int volume = 0; volume < MAXVOLUMES; volume++)
1658
    for (int volume = 0; volume < MAXVOLUMES; volume++)
1659
    {
1659
    {
1660
        const int voloff = volume * MAXLEVELS;
1660
        const int voloff = volume * MAXLEVELS;
1661
        for (int level = 0; level < MAXLEVELS; level++)
1661
        for (int level = 0; level < MAXLEVELS; level++)
1662
        {
1662
        {
1663
            if (MapInfo[voloff + level].filename == NULL)
1663
            if (MapInfo[voloff + level].filename == NULL)
1664
                continue;
1664
                continue;
1665
1665
1666
            if (!Bstrcasecmp(fn, MapInfo[voloff + level].filename))
1666
            if (!Bstrcasecmp(fn, MapInfo[voloff + level].filename))
1667
                return voloff + level;
1667
                return voloff + level;
1668
        }
1668
        }
1669
    }
1669
    }
1670
1670
1671
    return MAXLEVELS * MAXVOLUMES;
1671
    return MAXLEVELS * MAXVOLUMES;
1672
}
1672
}
1673
1673
1674
static void G_FadeLoad(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int32_t step, int32_t ticwait, int32_t tc)
1674
static void G_FadeLoad(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int32_t step, int32_t ticwait, int32_t tc)
1675
{
1675
{
1676