]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/doom/p_telept.c
games/doom: fix unterminated comment causing sound bugs (from qu7uux)
[plan9front.git] / sys / src / games / doom / p_telept.c
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:
20 //      Teleportation.
21 //
22 //-----------------------------------------------------------------------------
23
24 static const char
25 rcsid[] = "$Id: p_telept.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
26
27
28
29 #include "doomdef.h"
30
31 #include "s_sound.h"
32
33 #include "p_local.h"
34
35
36 // Data.
37 #include "sounds.h"
38
39 // State.
40 #include "r_state.h"
41
42
43
44 //
45 // TELEPORTATION
46 //
47 int
48 EV_Teleport
49 ( line_t*       line,
50   int           side,
51   mobj_t*       thing )
52 {
53     int         i;
54     int         tag;
55     mobj_t*     m;
56     mobj_t*     fog;
57     unsigned    an;
58     thinker_t*  thinker;
59     sector_t*   sector;
60     fixed_t     oldx;
61     fixed_t     oldy;
62     fixed_t     oldz;
63
64     // don't teleport missiles
65     if (thing->flags & MF_MISSILE)
66         return 0;               
67
68     // Don't teleport if hit back of line,
69     //  so you can get out of teleporter.
70     if (side == 1)              
71         return 0;       
72
73     
74     tag = line->tag;
75     for (i = 0; i < numsectors; i++)
76     {
77         if (sectors[ i ].tag == tag )
78         {
79             for (thinker = thinkercap.next;
80                  thinker != &thinkercap;
81                  thinker = thinker->next)
82             {
83                 // not a mobj
84                 if (thinker->function != P_MobjThinker)
85                     continue;   
86
87                 m = (mobj_t *)thinker;
88                 
89                 // not a teleportman
90                 if (m->type != MT_TELEPORTMAN )
91                     continue;           
92
93                 sector = m->subsector->sector;
94                 // wrong sector
95                 if (sector-sectors != i )
96                     continue;   
97
98                 oldx = thing->x;
99                 oldy = thing->y;
100                 oldz = thing->z;
101                                 
102                 if (!P_TeleportMove (thing, m->x, m->y))
103                     return 0;
104
105                 if(!noztele)
106                         thing->z = thing->floorz;
107                 if (thing->player)
108                     thing->player->viewz = thing->z+thing->player->viewheight;
109                                 
110                 // spawn teleport fog at source and destination
111                 fog = P_SpawnMobj (oldx, oldy, oldz, MT_TFOG);
112                 S_StartSound (fog, sfx_telept);
113                 an = m->angle >> ANGLETOFINESHIFT;
114                 fog = P_SpawnMobj (m->x+20*finecosine[an], m->y+20*finesine[an]
115                                    , thing->z, MT_TFOG);
116
117                 // emit sound, where?
118                 S_StartSound (fog, sfx_telept);
119                 
120                 // don't move for a bit
121                 if (thing->player)
122                     thing->reactiontime = 18;   
123
124                 thing->angle = m->angle;
125                 thing->momx = thing->momy = thing->momz = 0;
126                 return 1;
127             }   
128         }
129     }
130     return 0;
131 }
132