-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp_spec.c
353 lines (299 loc) · 8.59 KB
/
p_spec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* -Implements utility functions for all linedef/sector special handlers
* -Dispatches walkover and gun line triggers
* -Initializes and implements special sector types
* -Implements donut linedef triggers
* -Initializes and implements BOOM linedef triggers for
* Scrollers/Conveyors
* Friction
* Wind/Current
*
*-----------------------------------------------------------------------------*/
#include "d_player.h"
#include "p_spec.h"
#include "p_tick.h"
#include "p_setup.h"
#include "m_random.h"
#include "d_englsh.h"
#include "w_wad.h"
#include "r_main.h"
#include "r_data.h"
#include "p_maputl.h"
#include "p_map.h"
#include "g_game.h"
#include "p_inter.h"
#include "p_user.h"
#include "sounds.h"
#include "i_system.h"
#include "globdata.h"
///////////////////////////////////////////////////////////////
//
// Linedef and Sector Special Implementation Utility Functions
//
///////////////////////////////////////////////////////////////
//
// getNextSector()
//
// Return sector_t * of sector next to current across line.
//
// Note: returns NULL if not two-sided line, or both sides refer to sector
//
sector_t __far* getNextSector(const line_t __far* line, sector_t __far* sec)
{
if (LN_FRONTSECTOR(line) == sec)
{
if (LN_BACKSECTOR(line)!=sec)
return LN_BACKSECTOR(line); //jff 5/3/98 don't retn sec unless compatibility
else // fixes an intra-sector line breaking functions
return NULL; // like floor->highest floor
}
return LN_FRONTSECTOR(line);
}
//
// P_FindLowestFloorSurrounding()
//
// Returns the fixed point value of the lowest floor height
// in the sector passed or its surrounding sectors.
//
fixed_t P_FindLowestFloorSurrounding(sector_t __far* sec)
{
int16_t i;
const line_t __far* check;
sector_t __far* other;
fixed_t floor = sec->floorheight;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (other->floorheight < floor)
floor = other->floorheight;
}
return floor;
}
//
// P_FindHighestFloorSurrounding()
//
// Passed a sector, returns the fixed point value of the largest
// floor height in the surrounding sectors, not including that passed
//
fixed_t P_FindHighestFloorSurrounding(sector_t __far* sec)
{
int16_t i;
const line_t __far* check;
sector_t __far* other;
fixed_t floor = -32000*FRACUNIT;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (other->floorheight > floor)
floor = other->floorheight;
}
return floor;
}
//
// P_FindLowestCeilingSurrounding()
//
// Passed a sector, returns the fixed point value of the smallest
// ceiling height in the surrounding sectors, not including that passed
//
fixed_t P_FindLowestCeilingSurrounding(sector_t __far* sec)
{
int16_t i;
const line_t __far* check;
sector_t __far* other;
fixed_t height = 32000*FRACUNIT;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (other->ceilingheight < height)
height = other->ceilingheight;
}
return height;
}
//
// RETURN NEXT SECTOR # THAT LINE TAG REFERS TO
//
int16_t P_FindSectorFromLineTag(const line_t __far* line, int16_t start)
{
int16_t i;
for (i=start+1; i<_g_numsectors; i++)
{
if (_g_sectors[i].tag == line->tag)
return i;
}
return -1;
}
//
// P_CheckTag()
//
// Passed a line, returns true if the tag is non-zero or the line special
// allows no tag without harm. If compatibility, all linedef specials are
// allowed to have zero tag.
//
// Note: Only line specials activated by walkover, pushing, or shooting are
// checked by this routine.
//
// jff 2/27/98 Added to check for zero tag allowed for regular special types
//
boolean P_CheckTag(const line_t __far* line)
{
/* tag not zero, allowed, or
* killough 11/98: compatibility option */
if (line->tag)
return true;
switch(LN_SPECIAL(line))
{
case 1: // Manual door specials
case 26:
case 27:
case 28:
case 31:
case 34:
case 11: // Exits
case 48: // Scrolling walls
return true; // zero tag allowed
default:
break;
}
return false; // zero tag not allowed
}
//////////////////////////////////////////////////////////////////////////
//
// Events
//
// Events are operations triggered by using, crossing,
// or shooting special lines, or by timed thinkers.
//
/////////////////////////////////////////////////////////////////////////
//
// P_UpdateSpecials()
//
// Check level timer, frag counter,
// scroll walls,
// change button textures
//
// Reads and modifies globals:
// levelTimer, levelTimeCount,
// levelFragLimit, levelFragLimitCount
//
void P_UpdateSpecials (void)
{
// Check buttons (retriggerable switches) and change texture on timeout
for (int8_t i = 0; i < MAXBUTTONS; i++)
{
if (_g_buttonlist[i].btimer)
{
_g_buttonlist[i].btimer--;
if (!_g_buttonlist[i].btimer)
{
switch(_g_buttonlist[i].where)
{
case top:
_g_sides[_g_buttonlist[i].line->sidenum[0]].toptexture =
_g_buttonlist[i].btexture;
break;
case middle:
_g_sides[_g_buttonlist[i].line->sidenum[0]].midtexture =
_g_buttonlist[i].btexture;
break;
case bottom:
_g_sides[_g_buttonlist[i].line->sidenum[0]].bottomtexture =
_g_buttonlist[i].btexture;
break;
}
memset(&_g_buttonlist[i],0,sizeof(button_t));
}
}
}
}
//////////////////////////////////////////////////////////////////////
//
// Sector and Line special thinker spawning at level startup
//
//////////////////////////////////////////////////////////////////////
void P_SpawnScrollers(void);
//
// P_SpawnSpecials
// After the map has been loaded,
// scan for specials that spawn thinkers
//
void P_SpawnSpecials (void)
{
sector_t __far* sector;
int16_t i;
// Init special sectors.
sector = _g_sectors;
for (i=0 ; i<_g_numsectors ; i++, sector++)
{
if (!sector->special)
continue;
switch (sector->special)
{
case 1:
// random off
P_SpawnLightFlash (sector);
break;
case 2:
// strobe fast
P_SpawnStrobeFlash(sector,FASTDARK,false);
break;
case 3:
// strobe slow
P_SpawnStrobeFlash(sector,SLOWDARK,false);
break;
case 8:
// glowing light
P_SpawnGlowingLight(sector);
break;
//case 9:
// secret sector
//break;
case 12:
// sync strobe slow
P_SpawnStrobeFlash (sector, SLOWDARK, true);
break;
}
}
P_RemoveAllActivePlats();
for (i = 0;i < MAXBUTTONS;i++)
memset(&_g_buttonlist[i],0,sizeof(button_t));
P_SpawnScrollers();
}