Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
298 serge 1
// Emacs style mode select   -*- C++ -*-
2
//-----------------------------------------------------------------------------
3
//
4
// $Id:$
5
//
6
// Copyright (C) 1993-1996 by id Software, Inc.
7
//
8
// This source is available for distribution and/or modification
9
// only under the terms of the DOOM Source Code License as
10
// published by id Software. All rights reserved.
11
//
12
// The source is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15
// for more details.
16
//
17
// $Log:$
18
//
19
// DESCRIPTION:  Ceiling aninmation (lowering, crushing, raising)
20
//
21
//-----------------------------------------------------------------------------
22
 
23
static const char
24
rcsid[] = "$Id: p_ceilng.c,v 1.4 1997/02/03 16:47:53 b1 Exp $";
25
 
26
 
27
#include "z_zone.h"
28
#include "doomdef.h"
29
#include "p_local.h"
30
 
31
#include "s_sound.h"
32
 
33
// State.
34
#include "doomstat.h"
35
#include "r_state.h"
36
 
37
// Data.
38
#include "sounds.h"
39
 
40
//
41
// CEILINGS
42
//
43
 
44
 
45
ceiling_t*	activeceilings[MAXCEILINGS];
46
 
47
 
48
//
49
// T_MoveCeiling
50
//
51
 
52
void T_MoveCeiling (ceiling_t* ceiling)
53
{
54
    result_e	res;
55
 
56
    switch(ceiling->direction)
57
    {
58
      case 0:
59
	// IN STASIS
60
	break;
61
      case 1:
62
	// UP
63
	res = T_MovePlane(ceiling->sector,
64
			  ceiling->speed,
65
			  ceiling->topheight,
66
			  false,1,ceiling->direction);
67
 
68
	if (!(leveltime&7))
69
	{
70
	    switch(ceiling->type)
71
	    {
72
	      case silentCrushAndRaise:
73
		break;
74
	      default:
75
		S_StartSound((mobj_t *)&ceiling->sector->soundorg,
76
			     sfx_stnmov);
77
		// ?
78
		break;
79
	    }
80
	}
81
 
82
	if (res == pastdest)
83
	{
84
	    switch(ceiling->type)
85
	    {
86
	      case raiseToHighest:
87
		P_RemoveActiveCeiling(ceiling);
88
		break;
89
 
90
	      case silentCrushAndRaise:
91
		S_StartSound((mobj_t *)&ceiling->sector->soundorg,
92
			     sfx_pstop);
93
	      case fastCrushAndRaise:
94
	      case crushAndRaise:
95
		ceiling->direction = -1;
96
		break;
97
 
98
	      default:
99
		break;
100
	    }
101
 
102
	}
103
	break;
104
 
105
      case -1:
106
	// DOWN
107
	res = T_MovePlane(ceiling->sector,
108
			  ceiling->speed,
109
			  ceiling->bottomheight,
110
			  ceiling->crush,1,ceiling->direction);
111
 
112
	if (!(leveltime&7))
113
	{
114
	    switch(ceiling->type)
115
	    {
116
	      case silentCrushAndRaise: break;
117
	      default:
118
		S_StartSound((mobj_t *)&ceiling->sector->soundorg,
119
			     sfx_stnmov);
120
	    }
121
	}
122
 
123
	if (res == pastdest)
124
	{
125
	    switch(ceiling->type)
126
	    {
127
	      case silentCrushAndRaise:
128
		S_StartSound((mobj_t *)&ceiling->sector->soundorg,
129
			     sfx_pstop);
130
	      case crushAndRaise:
131
		ceiling->speed = CEILSPEED;
132
	      case fastCrushAndRaise:
133
		ceiling->direction = 1;
134
		break;
135
 
136
	      case lowerAndCrush:
137
	      case lowerToFloor:
138
		P_RemoveActiveCeiling(ceiling);
139
		break;
140
 
141
	      default:
142
		break;
143
	    }
144
	}
145
	else // ( res != pastdest )
146
	{
147
	    if (res == crushed)
148
	    {
149
		switch(ceiling->type)
150
		{
151
		  case silentCrushAndRaise:
152
		  case crushAndRaise:
153
		  case lowerAndCrush:
154
		    ceiling->speed = CEILSPEED / 8;
155
		    break;
156
 
157
		  default:
158
		    break;
159
		}
160
	    }
161
	}
162
	break;
163
    }
164
}
165
 
166
 
167
//
168
// EV_DoCeiling
169
// Move a ceiling up/down and all around!
170
//
171
int
172
EV_DoCeiling
173
( line_t*	line,
174
  ceiling_e	type )
175
{
176
    int		secnum;
177
    int		rtn;
178
    sector_t*	sec;
179
    ceiling_t*	ceiling;
180
 
181
    secnum = -1;
182
    rtn = 0;
183
 
184
    //	Reactivate in-stasis ceilings...for certain types.
185
    switch(type)
186
    {
187
      case fastCrushAndRaise:
188
      case silentCrushAndRaise:
189
      case crushAndRaise:
190
	P_ActivateInStasisCeiling(line);
191
      default:
192
	break;
193
    }
194
 
195
    while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
196
    {
197
	sec = §ors[secnum];
198
	if (sec->specialdata)
199
	    continue;
200
 
201
	// new door thinker
202
	rtn = 1;
203
	ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
204
	P_AddThinker (&ceiling->thinker);
205
	sec->specialdata = ceiling;
206
	ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling;
207
	ceiling->sector = sec;
208
	ceiling->crush = false;
209
 
210
	switch(type)
211
	{
212
	  case fastCrushAndRaise:
213
	    ceiling->crush = true;
214
	    ceiling->topheight = sec->ceilingheight;
215
	    ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
216
	    ceiling->direction = -1;
217
	    ceiling->speed = CEILSPEED * 2;
218
	    break;
219
 
220
	  case silentCrushAndRaise:
221
	  case crushAndRaise:
222
	    ceiling->crush = true;
223
	    ceiling->topheight = sec->ceilingheight;
224
	  case lowerAndCrush:
225
	  case lowerToFloor:
226
	    ceiling->bottomheight = sec->floorheight;
227
	    if (type != lowerToFloor)
228
		ceiling->bottomheight += 8*FRACUNIT;
229
	    ceiling->direction = -1;
230
	    ceiling->speed = CEILSPEED;
231
	    break;
232
 
233
	  case raiseToHighest:
234
	    ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
235
	    ceiling->direction = 1;
236
	    ceiling->speed = CEILSPEED;
237
	    break;
238
	}
239
 
240
	ceiling->tag = sec->tag;
241
	ceiling->type = type;
242
	P_AddActiveCeiling(ceiling);
243
    }
244
    return rtn;
245
}
246
 
247
 
248
//
249
// Add an active ceiling
250
//
251
void P_AddActiveCeiling(ceiling_t* c)
252
{
253
    int		i;
254
 
255
    for (i = 0; i < MAXCEILINGS;i++)
256
    {
257
	if (activeceilings[i] == NULL)
258
	{
259
	    activeceilings[i] = c;
260
	    return;
261
	}
262
    }
263
}
264
 
265
 
266
 
267
//
268
// Remove a ceiling's thinker
269
//
270
void P_RemoveActiveCeiling(ceiling_t* c)
271
{
272
    int		i;
273
 
274
    for (i = 0;i < MAXCEILINGS;i++)
275
    {
276
	if (activeceilings[i] == c)
277
	{
278
	    activeceilings[i]->sector->specialdata = NULL;
279
	    P_RemoveThinker (&activeceilings[i]->thinker);
280
	    activeceilings[i] = NULL;
281
	    break;
282
	}
283
    }
284
}
285
 
286
 
287
 
288
//
289
// Restart a ceiling that's in-stasis
290
//
291
void P_ActivateInStasisCeiling(line_t* line)
292
{
293
    int		i;
294
 
295
    for (i = 0;i < MAXCEILINGS;i++)
296
    {
297
	if (activeceilings[i]
298
	    && (activeceilings[i]->tag == line->tag)
299
	    && (activeceilings[i]->direction == 0))
300
	{
301
	    activeceilings[i]->direction = activeceilings[i]->olddirection;
302
	    activeceilings[i]->thinker.function.acp1
303
	      = (actionf_p1)T_MoveCeiling;
304
	}
305
    }
306
}
307
 
308
 
309
 
310
//
311
// EV_CeilingCrushStop
312
// Stop a ceiling from crushing!
313
//
314
int	EV_CeilingCrushStop(line_t	*line)
315
{
316
    int		i;
317
    int		rtn;
318
 
319
    rtn = 0;
320
    for (i = 0;i < MAXCEILINGS;i++)
321
    {
322
	if (activeceilings[i]
323
	    && (activeceilings[i]->tag == line->tag)
324
	    && (activeceilings[i]->direction != 0))
325
	{
326
	    activeceilings[i]->olddirection = activeceilings[i]->direction;
327
	    activeceilings[i]->thinker.function.acv = (actionf_v)NULL;
328
	    activeceilings[i]->direction = 0;		// in-stasis
329
	    rtn = 1;
330
	}
331
    }
332
 
333
 
334
    return rtn;
335
}