File: p_ceilng.c

package info (click to toggle)
doomlegacy 1.32beta4-3
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 6,768 kB
  • ctags: 13,999
  • sloc: ansic: 110,665; asm: 1,413; makefile: 915; pascal: 63
file content (435 lines) | stat: -rw-r--r-- 12,008 bytes parent folder | download
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// Emacs style mode select   -*- C++ -*- 
//-----------------------------------------------------------------------------
//
// $Id: p_ceilng.c,v 1.8 2001/01/25 22:15:43 bpereira Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
// Portions Copyright (C) 1998-2000 by DooM Legacy Team.
//
// 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.
//
//
// $Log: p_ceilng.c,v $
// Revision 1.8  2001/01/25 22:15:43  bpereira
// added heretic support
//
// Revision 1.7  2000/10/21 08:43:30  bpereira
// no message
//
// Revision 1.6  2000/09/28 20:57:16  bpereira
// no message
//
// Revision 1.5  2000/04/11 19:07:24  stroggonmeth
// Finished my logs, fixed a crashing bug.
//
// Revision 1.4  2000/04/08 17:29:24  stroggonmeth
// no message
//
// Revision 1.3  2000/04/04 00:32:46  stroggonmeth
// Initial Boom compatability plus few misc changes all around.
//
// Revision 1.2  2000/02/27 00:42:10  hurdler
// fix CR+LF problem
//
// Revision 1.1.1.1  2000/02/22 20:32:32  hurdler
// Initial import into CVS (v1.29 pr3)
//
//
// DESCRIPTION:  
//      Ceiling aninmation (lowering, crushing, raising)
//
//-----------------------------------------------------------------------------


#include "doomdef.h"
#include "p_local.h"
#include "r_state.h"
#include "s_sound.h"
#include "z_zone.h"

// ==========================================================================
//                              CEILINGS
// ==========================================================================


// SoM: 3/6/2000: the list of ceilings moving currently, including crushers
ceilinglist_t *activeceilings;
//ceiling_t*      activeceilings[MAXCEILINGS];
int ceilmovesound = sfx_stnmov;

//
// T_MoveCeiling
//

void T_MoveCeiling (ceiling_t* ceiling)
{
    result_e    res;

    switch(ceiling->direction)
    {
      case 0:
        // IN STASIS
        break;
      case 1:
        // UP
        res = T_MovePlane(ceiling->sector,
                          ceiling->speed,
                          ceiling->topheight,
                          false,1,ceiling->direction);

        if (!(leveltime % (8*NEWTICRATERATIO)))
        {
            switch(ceiling->type)
            {
              case silentCrushAndRaise:
              case genSilentCrusher:
                break;
              default:
                S_StartSound((mobj_t *)&ceiling->sector->soundorg,
                             ceilmovesound);
                // ?
                break;
            }
        }

        if (res == pastdest)
        {
            switch(ceiling->type)
            {

              case raiseToHighest:
              case genCeiling: //SoM: 3/6/2000
                P_RemoveActiveCeiling(ceiling);
                break;

              // SoM: 3/6/2000: movers with texture change, change the texture then get removed
              case genCeilingChgT:
              case genCeilingChg0:
                ceiling->sector->special = ceiling->newspecial;
                ceiling->sector->oldspecial = ceiling->oldspecial;
              case genCeilingChg:
                ceiling->sector->ceilingpic = ceiling->texture;
                P_RemoveActiveCeiling(ceiling);
                break;

              case silentCrushAndRaise:
                S_StartSound((mobj_t *)&ceiling->sector->soundorg,
                             sfx_pstop);
              case fastCrushAndRaise:
              case genCrusher: // SoM: 3/6/2000
              case genSilentCrusher:
              case crushAndRaise:
                ceiling->direction = -1;
                break;

              default:
                break;
            }
        }
        break;

      case -1:
        // DOWN
        res = T_MovePlane(ceiling->sector,
                          ceiling->speed,
                          ceiling->bottomheight,
                          ceiling->crush,1,ceiling->direction);

        if (!(leveltime % (8*NEWTICRATERATIO)))
        {
            switch(ceiling->type)
            {
              case silentCrushAndRaise:
              case genSilentCrusher:
                break;
              default:
                S_StartSound((mobj_t *)&ceiling->sector->soundorg,
                             ceilmovesound);
            }
        }

        if (res == pastdest)
        {
            switch(ceiling->type) //SoM: 3/6/2000: Use boom code
            {
              case genSilentCrusher:
              case genCrusher:
                if (ceiling->oldspeed<CEILSPEED*3)
                  ceiling->speed = ceiling->oldspeed;
                ceiling->direction = 1;
                break;
    
              // make platform stop at bottom of all crusher strokes
              // except generalized ones, reset speed, start back up
              case silentCrushAndRaise:
                S_StartSound((mobj_t *)&ceiling->sector->soundorg,sfx_pstop);
              case crushAndRaise: 
                ceiling->speed = CEILSPEED;
              case fastCrushAndRaise:
                ceiling->direction = 1;
                break;
              
              // in the case of ceiling mover/changer, change the texture
              // then remove the active ceiling
              case genCeilingChgT:
              case genCeilingChg0:
                ceiling->sector->special = ceiling->newspecial;
                //jff add to fix bug in special transfers from changes
                ceiling->sector->oldspecial = ceiling->oldspecial;
              case genCeilingChg:
                ceiling->sector->ceilingpic = ceiling->texture;
                P_RemoveActiveCeiling(ceiling);
                break;
    
              // all other case, just remove the active ceiling
              case lowerAndCrush:
              case lowerToFloor:
              case lowerToLowest:
              case lowerToMaxFloor:
              case genCeiling:
                P_RemoveActiveCeiling(ceiling);
                break;
    
              default:
                break;
            }
        }
        else // ( res != pastdest )
        {
            if (res == crushed)
            {
                switch(ceiling->type)
                {
                  //SoM: 2/6/2000
                  // slow down slow crushers on obstacle
                  case genCrusher:  
                  case genSilentCrusher:
                    if (ceiling->oldspeed < CEILSPEED*3)
                      ceiling->speed = CEILSPEED / 8;
                    break;

                  case silentCrushAndRaise:
                  case crushAndRaise:
                  case lowerAndCrush:
                    ceiling->speed = CEILSPEED / 8;
                    break;

                  default:
                    break;
                }
            }
        }
        break;
    }
}


//
// EV_DoCeiling
// Move a ceiling up/down and all around!
//
int
EV_DoCeiling
( line_t*       line,
  ceiling_e     type )
{
    int         secnum;
    int         rtn;
    sector_t*   sec;
    ceiling_t*  ceiling;

    secnum = -1;
    rtn = 0;

    //  Reactivate in-stasis ceilings...for certain types.
    // This restarts a crusher after it has been stopped
    switch(type)
    {
      case fastCrushAndRaise:
      case silentCrushAndRaise:
      case crushAndRaise:
        rtn = P_ActivateInStasisCeiling(line); //SoM: Return true if the crusher is activated
      default:
        break;
    }

    while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
    {
        sec = &sectors[secnum];


        if (P_SectorActive(ceiling_special,sec))  //SoM: 3/6/2000
            continue;

        // new door thinker
        rtn = 1;
        ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
        P_AddThinker (&ceiling->thinker);
        sec->ceilingdata = ceiling;
        ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling;
        ceiling->sector = sec;
        ceiling->crush = false;

        switch(type)
        {
          case fastCrushAndRaise:
            ceiling->crush = true;
            ceiling->topheight = sec->ceilingheight;
            ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
            ceiling->direction = -1;
            ceiling->speed = CEILSPEED * 2;
            break;

          case silentCrushAndRaise:
          case crushAndRaise:
            ceiling->crush = true;
            ceiling->topheight = sec->ceilingheight;
          case lowerAndCrush:
          case lowerToFloor:
            ceiling->bottomheight = sec->floorheight;
            if (type != lowerToFloor)
                ceiling->bottomheight += 8*FRACUNIT;
            ceiling->direction = -1;
            ceiling->speed = CEILSPEED;
            break;

          case raiseToHighest:
            ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
            ceiling->direction = 1;
            ceiling->speed = CEILSPEED;
            break;

          //SoM: 3/6/2000: Added Boom types
          case lowerToLowest:
            ceiling->bottomheight = P_FindLowestCeilingSurrounding(sec);
            ceiling->direction = -1;
            ceiling->speed = CEILSPEED;
            break;

          case lowerToMaxFloor:
            ceiling->bottomheight = P_FindHighestFloorSurrounding(sec);
            ceiling->direction = -1;
            ceiling->speed = CEILSPEED;
            break;

          default:
            break;

        }

        ceiling->tag = sec->tag;
        ceiling->type = type;
        P_AddActiveCeiling(ceiling);
    }
    return rtn;
}


//
// Add an active ceiling
//
//SoM: 3/6/2000: Take advantage of the new Boom method for active ceilings.
void P_AddActiveCeiling(ceiling_t* ceiling)
{
  ceilinglist_t *list = malloc(sizeof *list);
  list->ceiling = ceiling;
  ceiling->list = list;
  if ((list->next = activeceilings))
    list->next->prev = &list->next;
  list->prev = &activeceilings;
  activeceilings = list;
}



//
// Remove a ceiling's thinker
//
// SoM: 3/6/2000 :Use improved Boom code.
void P_RemoveActiveCeiling(ceiling_t* ceiling)
{
  ceilinglist_t *list = ceiling->list;
  ceiling->sector->ceilingdata = NULL;  //jff 2/22/98
  P_RemoveThinker(&ceiling->thinker);
  if ((*list->prev = list->next))
    list->next->prev = list->prev;
  free(list);
}



//
// Restart a ceiling that's in-stasis
//
//SoM: 3/6/2000: Use improved boom code
int P_ActivateInStasisCeiling(line_t *line)
{
  ceilinglist_t *cl;
  int rtn=0;

  for (cl=activeceilings; cl; cl=cl->next)
  {
    ceiling_t *ceiling = cl->ceiling;
    if (ceiling->tag == line->tag && ceiling->direction == 0)
    {
      ceiling->direction = ceiling->olddirection;
      ceiling->thinker.function.acp1 = (actionf_p1) T_MoveCeiling;
      rtn=1;
    }
  }
  return rtn;
}



//
// EV_CeilingCrushStop
// Stop a ceiling from crushing!
//
//SoM: 3/6/2000: use improved Boom code
int EV_CeilingCrushStop(line_t* line)
{
  int rtn=0;

  ceilinglist_t *cl;
  for (cl=activeceilings; cl; cl=cl->next)
  {
    ceiling_t *ceiling = cl->ceiling;
    if (ceiling->direction != 0 && ceiling->tag == line->tag)
    {
      ceiling->olddirection = ceiling->direction;
      ceiling->direction = 0;
      ceiling->thinker.function.acv = (actionf_v)NULL;
      rtn=1;
    }
  }
  return rtn;
}



// SoM: 3/6/2000: Extra, boom only function.
//
// P_RemoveAllActiveCeilings()
//
// Removes all ceilings from the active ceiling list
//
// Passed nothing, returns nothing
//
void P_RemoveAllActiveCeilings(void)
{
  while (activeceilings)
  {  
    ceilinglist_t *next = activeceilings->next;
    free(activeceilings);
    activeceilings = next;
  }
}