1 /* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
5 * PrBoom a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 *-----------------------------------------------------------------------------*/
42 #include "rockmacros.h"
46 // killough 5/3/98: reformatted, cleaned up
48 int EV_Teleport(line_t
*line
, int side
, mobj_t
*thing
)
54 // don't teleport missiles
55 // Don't teleport if hit back of line,
56 // so you can get out of teleporter.
57 if (side
|| thing
->flags
& MF_MISSILE
)
60 // killough 1/31/98: improve performance by using
61 // P_FindSectorFromLineTag instead of simple linear search.
63 for (i
= -1; (i
= P_FindSectorFromLineTag(line
, i
)) >= 0;)
64 for (thinker
=thinkercap
.next
; thinker
!=&thinkercap
; thinker
=thinker
->next
)
65 if (thinker
->function
== P_MobjThinker
&&
66 (m
= (mobj_t
*) thinker
)->type
== MT_TELEPORTMAN
&&
67 m
->subsector
->sector
-sectors
== i
)
69 fixed_t oldx
= thing
->x
, oldy
= thing
->y
, oldz
= thing
->z
;
70 player_t
*player
= thing
->player
;
72 // killough 5/12/98: exclude voodoo dolls:
73 if (player
&& player
->mo
!= thing
)
76 if (!P_TeleportMove(thing
, m
->x
, m
->y
, false)) /* killough 8/9/98 */
79 if (!(demo_compatibility
&& gamemission
>= pack_tnt
))
80 thing
->z
= thing
->floorz
;
83 player
->viewz
= thing
->z
+ player
->viewheight
;
85 // spawn teleport fog and emit sound at source
86 S_StartSound(P_SpawnMobj(oldx
, oldy
, oldz
, MT_TFOG
), sfx_telept
);
88 // spawn teleport fog and emit sound at destination
89 S_StartSound(P_SpawnMobj(m
->x
+
90 20*finecosine
[m
->angle
>>ANGLETOFINESHIFT
],
92 20*finesine
[m
->angle
>>ANGLETOFINESHIFT
],
96 /* don't move for a bit
97 * cph - DEMOSYNC - BOOM had (player) here? */
99 thing
->reactiontime
= 18;
101 thing
->angle
= m
->angle
;
103 thing
->momx
= thing
->momy
= thing
->momz
= 0;
105 /* killough 10/98: kill all bobbing momentum too */
107 player
->momx
= player
->momy
= 0;
115 // Silent TELEPORTATION, by Lee Killough
116 // Primarily for rooms-over-rooms etc.
119 int EV_SilentTeleport(line_t
*line
, int side
, mobj_t
*thing
)
125 // don't teleport missiles
126 // Don't teleport if hit back of line,
127 // so you can get out of teleporter.
129 if (side
|| thing
->flags
& MF_MISSILE
)
132 for (i
= -1; (i
= P_FindSectorFromLineTag(line
, i
)) >= 0;)
133 for (th
= thinkercap
.next
; th
!= &thinkercap
; th
= th
->next
)
134 if (th
->function
== P_MobjThinker
&&
135 (m
= (mobj_t
*) th
)->type
== MT_TELEPORTMAN
&&
136 m
->subsector
->sector
-sectors
== i
)
138 // Height of thing above ground, in case of mid-air teleports:
139 fixed_t z
= thing
->z
- thing
->floorz
;
141 // Get the angle between the exit thing and source linedef.
142 // Rotate 90 degrees, so that walking perpendicularly across
143 // teleporter linedef causes thing to exit in the direction
144 // indicated by the exit thing.
146 R_PointToAngle2(0, 0, line
->dx
, line
->dy
) - m
->angle
+ ANG90
;
148 // Sine, cosine of angle adjustment
149 fixed_t s
= finesine
[angle
>>ANGLETOFINESHIFT
];
150 fixed_t c
= finecosine
[angle
>>ANGLETOFINESHIFT
];
152 // Momentum of thing crossing teleporter linedef
153 fixed_t momx
= thing
->momx
;
154 fixed_t momy
= thing
->momy
;
156 // Whether this is a player, and if so, a pointer to its player_t
157 player_t
*player
= thing
->player
;
159 // Attempt to teleport, aborting if blocked
160 if (!P_TeleportMove(thing
, m
->x
, m
->y
, false)) /* killough 8/9/98 */
163 // Rotate thing according to difference in angles
164 thing
->angle
+= angle
;
166 // Adjust z position to be same height above ground as before
167 thing
->z
= z
+ thing
->floorz
;
169 // Rotate thing's momentum to come out of exit just like it entered
170 thing
->momx
= FixedMul(momx
, c
) - FixedMul(momy
, s
);
171 thing
->momy
= FixedMul(momy
, c
) + FixedMul(momx
, s
);
173 // Adjust player's view, in case there has been a height change
174 // Voodoo dolls are excluded by making sure player->mo == thing.
175 if (player
&& player
->mo
== thing
)
177 // Save the current deltaviewheight, used in stepping
178 fixed_t deltaviewheight
= player
->deltaviewheight
;
180 // Clear deltaviewheight, since we don't want any changes
181 player
->deltaviewheight
= 0;
183 // Set player's view according to the newly set parameters
184 P_CalcHeight(player
);
186 // Reset the delta to have the same dynamics as before
187 player
->deltaviewheight
= deltaviewheight
;
195 // Silent linedef-based TELEPORTATION, by Lee Killough
196 // Primarily for rooms-over-rooms etc.
197 // This is the complete player-preserving kind of teleporter.
198 // It has advantages over the teleporter with thing exits.
201 // maximum fixed_t units to move object to avoid hiccups
202 #define FUDGEFACTOR 10
204 int EV_SilentLineTeleport(line_t
*line
, int side
, mobj_t
*thing
,
210 if (side
|| thing
->flags
& MF_MISSILE
)
213 for (i
= -1; (i
= P_FindLineFromLineTag(line
, i
)) >= 0;)
214 if ((l
=lines
+i
) != line
&& l
->backsector
)
216 // Get the thing's position along the source linedef
217 fixed_t pos
= D_abs(line
->dx
) > D_abs(line
->dy
) ?
218 FixedDiv(thing
->x
- line
->v1
->x
, line
->dx
) :
219 FixedDiv(thing
->y
- line
->v1
->y
, line
->dy
) ;
221 // Get the angle between the two linedefs, for rotating
222 // orientation and momentum. Rotate 180 degrees, and flip
223 // the position across the exit linedef, if reversed.
224 angle_t angle
= (reverse
? pos
= FRACUNIT
-pos
, 0 : ANG180
) +
225 R_PointToAngle2(0, 0, l
->dx
, l
->dy
) -
226 R_PointToAngle2(0, 0, line
->dx
, line
->dy
);
228 // Interpolate position across the exit linedef
229 fixed_t x
= l
->v2
->x
- FixedMul(pos
, l
->dx
);
230 fixed_t y
= l
->v2
->y
- FixedMul(pos
, l
->dy
);
232 // Sine, cosine of angle adjustment
233 fixed_t s
= finesine
[angle
>>ANGLETOFINESHIFT
];
234 fixed_t c
= finecosine
[angle
>>ANGLETOFINESHIFT
];
236 // Maximum distance thing can be moved away from interpolated
237 // exit, to ensure that it is on the correct side of exit linedef
238 int fudge
= FUDGEFACTOR
;
240 // Whether this is a player, and if so, a pointer to its player_t.
241 // Voodoo dolls are excluded by making sure thing->player->mo==thing.
242 player_t
*player
= thing
->player
&& thing
->player
->mo
== thing
?
243 thing
->player
: NULL
;
245 // Whether walking towards first side of exit linedef steps down
247 l
->frontsector
->floorheight
< l
->backsector
->floorheight
;
249 // Height of thing above ground
250 fixed_t z
= thing
->z
- thing
->floorz
;
252 // Side to exit the linedef on positionally.
256 // This flag concerns exit position, not momentum. Due to
257 // roundoff error, the thing can land on either the left or
258 // the right side of the exit linedef, and steps must be
259 // taken to make sure it does not end up on the wrong side.
261 // Exit momentum is always towards side 1 in a reversed
262 // teleporter, and always towards side 0 otherwise.
264 // Exiting positionally on side 1 is always safe, as far
265 // as avoiding oscillations and stuck-in-wall problems,
266 // but may not be optimum for non-reversed teleporters.
268 // Exiting on side 0 can cause oscillations if momentum
269 // is towards side 1, as it is with reversed teleporters.
271 // Exiting on side 1 slightly improves player viewing
272 // when going down a step on a non-reversed teleporter.
274 int side
= reverse
|| (player
&& stepdown
);
276 // Make sure we are on correct side of exit linedef.
277 while (P_PointOnLineSide(x
, y
, l
) != side
&& --fudge
>=0)
278 if (D_abs(l
->dx
) > D_abs(l
->dy
))
279 y
-= (l
->dx
< 0) != side
? -1 : 1;
281 x
+= (l
->dy
< 0) != side
? -1 : 1;
283 // Attempt to teleport, aborting if blocked
284 if (!P_TeleportMove(thing
, x
, y
, false)) /* killough 8/9/98 */
287 // Adjust z position to be same height above ground as before.
288 // Ground level at the exit is measured as the higher of the
289 // two floor heights at the exit linedef.
290 thing
->z
= z
+ sides
[l
->sidenum
[stepdown
]].sector
->floorheight
;
292 // Rotate thing's orientation according to difference in linedef angles
293 thing
->angle
+= angle
;
295 // Momentum of thing crossing teleporter linedef
299 // Rotate thing's momentum to come out of exit just like it entered
300 thing
->momx
= FixedMul(x
, c
) - FixedMul(y
, s
);
301 thing
->momy
= FixedMul(y
, c
) + FixedMul(x
, s
);
303 // Adjust a player's view, in case there has been a height change
306 // Save the current deltaviewheight, used in stepping
307 fixed_t deltaviewheight
= player
->deltaviewheight
;
309 // Clear deltaviewheight, since we don't want any changes now
310 player
->deltaviewheight
= 0;
312 // Set player's view according to the newly set parameters
313 P_CalcHeight(player
);
315 // Reset the delta to have the same dynamics as before
316 player
->deltaviewheight
= deltaviewheight
;