| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 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-2002 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Teleportation. |
| 31 |
* |
| 32 |
*-----------------------------------------------------------------------------*/ |
| 33 |
|
| 34 |
#include "doomdef.h" |
| 35 |
#include "doomstat.h" |
| 36 |
#include "p_spec.h" |
| 37 |
#include "p_maputl.h" |
| 38 |
#include "p_map.h" |
| 39 |
#include "r_main.h" |
| 40 |
#include "p_tick.h" |
| 41 |
#include "s_sound.h" |
| 42 |
#include "sounds.h" |
| 43 |
#include "p_user.h" |
| 44 |
#include "smooth.h" |
| 45 |
#include "m_random.h" |
| 46 |
|
| 47 |
#include "dsda/id_list.h" |
| 48 |
#include "dsda/thing_id.h" |
| 49 |
|
| 50 |
// More will be added |
| 51 |
static dboolean P_IsTeleportDestination(mobj_t *mo) |
| 52 |
{ |
| 53 |
return mo->type == MT_TELEPORTMAN || |
| 54 |
mo->type == ZMT_TELEPORTDEST2 || mo->type == ZMT_TELEPORTDEST3; |
| 55 |
} |
| 56 |
|
| 57 |
static dboolean P_UseTeleportDestinationHeight(mobj_t *mo) |
| 58 |
{ |
| 59 |
return mo->type == ZMT_TELEPORTDEST2 || mo->type == ZMT_TELEPORTDEST3; |
| 60 |
} |
| 61 |
|
| 62 |
static dboolean P_IsMapSpot(mobj_t *mo) |
| 63 |
{ |
| 64 |
return mo->type == ZMT_MAPSPOT || mo->type == ZMT_MAPSPOT_GRAVITY; |
| 65 |
} |
| 66 |
|
| 67 |
static mobj_t* P_TeleportDestination(short thing_id, int tag) |
| 68 |
{ |
| 69 |
const int *id_p; |
| 70 |
|
| 71 |
if (thing_id) |
| 72 |
{ |
| 73 |
int count = 0; |
| 74 |
mobj_t *target; |
| 75 |
thing_id_search_t search; |
| 76 |
|
| 77 |
dsda_ResetThingIDSearch(&search); |
| 78 |
while ((target = dsda_FindMobjFromThingID(thing_id, &search))) |
| 79 |
{ |
| 80 |
if (P_IsTeleportDestination(target)) |
| 81 |
{ |
| 82 |
if (!tag || target->subsector->sector->tag == tag) |
| 83 |
{ |
| 84 |
++count; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if (!count) |
| 90 |
{ |
| 91 |
if (!tag) |
| 92 |
{ |
| 93 |
// Fall back on map spots |
| 94 |
dsda_ResetThingIDSearch(&search); |
| 95 |
while ((target = dsda_FindMobjFromThingID(thing_id, &search))) |
| 96 |
{ |
| 97 |
if (P_IsMapSpot(target)) |
| 98 |
{ |
| 99 |
break; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
// Fall back on any nonblocking thing |
| 104 |
if (!target) |
| 105 |
{ |
| 106 |
dsda_ResetThingIDSearch(&search); |
| 107 |
while ((target = dsda_FindMobjFromThingID(thing_id, &search))) |
| 108 |
{ |
| 109 |
if (!(target->flags & MF_SOLID)) |
| 110 |
{ |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
return target; |
| 117 |
} |
| 118 |
} |
| 119 |
else |
| 120 |
{ |
| 121 |
if (count > 1) |
| 122 |
{ |
| 123 |
count = 1 + (P_Random(pr_hexen) % count); |
| 124 |
} |
| 125 |
|
| 126 |
dsda_ResetThingIDSearch(&search); |
| 127 |
while ((target = dsda_FindMobjFromThingID(thing_id, &search))) |
| 128 |
{ |
| 129 |
if (P_IsTeleportDestination(target)) |
| 130 |
{ |
| 131 |
if (!tag || target->subsector->sector->tag == tag) |
| 132 |
{ |
| 133 |
if (!--count) |
| 134 |
{ |
| 135 |
return target; |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
return NULL; |
| 143 |
} |
| 144 |
|
| 145 |
FIND_SECTORS(id_p, tag) |
| 146 |
{ |
| 147 |
register thinker_t* th = NULL; |
| 148 |
while ((th = P_NextThinker(th,th_misc)) != NULL) |
| 149 |
if (th->function == P_MobjThinker) { |
| 150 |
register mobj_t* m = (mobj_t*)th; |
| 151 |
if (m->type == MT_TELEPORTMAN && |
| 152 |
m->subsector->sector->iSectorID == *id_p) |
| 153 |
return m; |
| 154 |
} |
| 155 |
} |
| 156 |
return NULL; |
| 157 |
} |
| 158 |
// |
| 159 |
// TELEPORTATION |
| 160 |
// |
| 161 |
// killough 5/3/98: reformatted, cleaned up |
| 162 |
|
| 163 |
static int P_TeleportToDestination(mobj_t *destination, line_t *line, mobj_t *thing, int flags) |
| 164 |
{ |
| 165 |
fixed_t oldx = thing->x; |
| 166 |
fixed_t oldy = thing->y; |
| 167 |
fixed_t oldz = thing->z; |
| 168 |
fixed_t momx = thing->momx; |
| 169 |
fixed_t momy = thing->momy; |
| 170 |
fixed_t z = thing->z - thing->floorz; |
| 171 |
player_t *player = thing->player; |
| 172 |
angle_t angle = 0; |
| 173 |
fixed_t c = 0, s = 0; |
| 174 |
|
| 175 |
// Get the angle between the exit thing and source linedef. |
| 176 |
// Rotate 90 degrees, so that walking perpendicularly across |
| 177 |
// teleporter linedef causes thing to exit in the direction |
| 178 |
// indicated by the exit thing. |
| 179 |
if (flags & (TELF_ROTATEBOOM | TELF_ROTATEBOOMINVERSE) && line) |
| 180 |
{ |
| 181 |
angle = R_PointToAngle2(0, 0, line->dx, line->dy) - destination->angle + ANG90; |
| 182 |
|
| 183 |
if (flags & TELF_ROTATEBOOMINVERSE) |
| 184 |
angle = angle + ANG180; |
| 185 |
|
| 186 |
s = finesine[angle >> ANGLETOFINESHIFT]; |
| 187 |
c = finecosine[angle >> ANGLETOFINESHIFT]; |
| 188 |
} |
| 189 |
|
| 190 |
// killough 5/12/98: exclude voodoo dolls: |
| 191 |
if (player && player->mo != thing) |
| 192 |
player = NULL; |
| 193 |
|
| 194 |
if (!P_TeleportMove(thing, destination->x, destination->y, false)) /* killough 8/9/98 */ |
| 195 |
return 0; |
| 196 |
|
| 197 |
if (flags & (TELF_ROTATEBOOM | TELF_ROTATEBOOMINVERSE)) |
| 198 |
{ |
| 199 |
if (line) |
| 200 |
{ |
| 201 |
// Rotate thing according to difference in angles |
| 202 |
thing->angle += angle; |
| 203 |
|
| 204 |
// Rotate thing's momentum to come out of exit just like it entered |
| 205 |
thing->momx = FixedMul(momx, c) - FixedMul(momy, s); |
| 206 |
thing->momy = FixedMul(momy, c) + FixedMul(momx, s); |
| 207 |
} |
| 208 |
} |
| 209 |
else if (!(flags & TELF_KEEPORIENTATION)) |
| 210 |
{ |
| 211 |
thing->angle = destination->angle; |
| 212 |
} |
| 213 |
|
| 214 |
if (P_UseTeleportDestinationHeight(destination)) |
| 215 |
thing->z = destination->z; |
| 216 |
else if (flags & TELF_KEEPHEIGHT) |
| 217 |
thing->z = thing->floorz + z; |
| 218 |
else if (compatibility_level != finaldoom_compatibility) |
| 219 |
thing->z = thing->floorz; |
| 220 |
thing->PrevZ = thing->z; |
| 221 |
|
| 222 |
if (flags & TELF_SOURCEFOG) |
| 223 |
{ |
| 224 |
// spawn teleport fog and emit sound at source |
| 225 |
S_StartMobjSound(P_SpawnMobj(oldx, oldy, oldz, MT_TFOG), sfx_telept); |
| 226 |
} |
| 227 |
|
| 228 |
if (flags & TELF_DESTFOG) |
| 229 |
{ |
| 230 |
// spawn teleport fog and emit sound at destination |
| 231 |
S_StartMobjSound( |
| 232 |
P_SpawnMobj( |
| 233 |
destination->x + 20 * finecosine[destination->angle >> ANGLETOFINESHIFT], |
| 234 |
destination->y + 20 * finesine[destination->angle >> ANGLETOFINESHIFT], |
| 235 |
thing->z, MT_TFOG |
| 236 |
), |
| 237 |
sfx_telept |
| 238 |
); |
| 239 |
} |
| 240 |
|
| 241 |
/* don't move for a bit |
| 242 |
* cph - DEMOSYNC - BOOM had (player) here? */ |
| 243 |
if ( |
| 244 |
thing->player && |
| 245 |
((flags & TELF_DESTFOG) || !(flags & TELF_KEEPORIENTATION)) && |
| 246 |
!(flags & TELF_KEEPVELOCITY) |
| 247 |
) |
| 248 |
thing->reactiontime = 18; |
| 249 |
|
| 250 |
if (!(flags & TELF_KEEPORIENTATION) && !(flags & TELF_KEEPVELOCITY)) |
| 251 |
{ |
| 252 |
thing->momx = thing->momy = thing->momz = 0; |
| 253 |
|
| 254 |
/* killough 10/98: kill all bobbing momentum too */ |
| 255 |
if (player) |
| 256 |
player->momx = player->momy = 0; |
| 257 |
} |
| 258 |
|
| 259 |
if (player) |
| 260 |
{ |
| 261 |
// This code was different between silent and non-silent functions. |
| 262 |
if (flags & TELF_KEEPORIENTATION) |
| 263 |
{ |
| 264 |
// Adjust player's view, in case there has been a height change |
| 265 |
if (player) |
| 266 |
{ |
| 267 |
// Save the current deltaviewheight, used in stepping |
| 268 |
fixed_t deltaviewheight = player->deltaviewheight; |
| 269 |
|
| 270 |
// Clear deltaviewheight, since we don't want any changes |
| 271 |
player->deltaviewheight = 0; |
| 272 |
|
| 273 |
// Set player's view according to the newly set parameters |
| 274 |
P_CalcHeight(player); |
| 275 |
|
| 276 |
// Reset the delta to have the same dynamics as before |
| 277 |
player->deltaviewheight = deltaviewheight; |
| 278 |
} |
| 279 |
} |
| 280 |
else |
| 281 |
{ |
| 282 |
player->viewz = thing->z + player->viewheight; |
| 283 |
} |
| 284 |
|
| 285 |
// e6y |
| 286 |
R_ResetAfterTeleport(player); |
| 287 |
} |
| 288 |
|
| 289 |
return 1; |
| 290 |
} |
| 291 |
|
| 292 |
int EV_TeleportGroup(short group_tid, mobj_t *thing, short source_tid, short dest_tid, |
| 293 |
dboolean move_source, dboolean fog) |
| 294 |
{ |
| 295 |
int result = 0; |
| 296 |
mobj_t *source; |
| 297 |
mobj_t *dest; |
| 298 |
mobj_t *target; |
| 299 |
thing_id_search_t search; |
| 300 |
|
| 301 |
dsda_ResetThingIDSearch(&search); |
| 302 |
source = dsda_FindMobjFromThingID(source_tid, &search); |
| 303 |
|
| 304 |
dest = P_TeleportDestination(dest_tid, 0); |
| 305 |
|
| 306 |
if (source && dest) |
| 307 |
{ |
| 308 |
int flags; |
| 309 |
angle_t an; |
| 310 |
fixed_t dcos, dsin; |
| 311 |
|
| 312 |
flags = fog ? (TELF_DESTFOG | TELF_SOURCEFOG) : TELF_KEEPORIENTATION; |
| 313 |
|
| 314 |
an = dest->angle - source->angle; |
| 315 |
dcos = finecosine[an >> ANGLETOFINESHIFT]; |
| 316 |
dsin = finesine[an >> ANGLETOFINESHIFT]; |
| 317 |
|
| 318 |
dsda_ResetThingIDSearch(&search); |
| 319 |
while ((target = dsda_FindMobjFromThingIDOrMobj(group_tid, thing, &search))) |
| 320 |
{ |
| 321 |
fixed_t dx, dy; |
| 322 |
mobj_t target_dest; |
| 323 |
|
| 324 |
memset(&target_dest, 0, sizeof(target_dest)); |
| 325 |
|
| 326 |
dx = target->x - source->x; |
| 327 |
dy = target->y - source->y; |
| 328 |
target_dest.x = dest->x + FixedMul(dx, dcos) - FixedMul(dy, dsin); |
| 329 |
target_dest.y = dest->y + FixedMul(dx, dsin) + FixedMul(dy, dcos); |
| 330 |
target_dest.angle = target->angle; |
| 331 |
target_dest.type = dest->type; |
| 332 |
|
| 333 |
result |= P_TeleportToDestination(&target_dest, NULL, target, flags); |
| 334 |
} |
| 335 |
|
| 336 |
if (result && move_source) |
| 337 |
{ |
| 338 |
P_TeleportToDestination(dest, NULL, source, TELF_KEEPORIENTATION); |
| 339 |
source->angle = dest->angle; |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
return result; |
| 344 |
} |
| 345 |
|
| 346 |
int EV_TeleportInSector(int tag, short source_tid, short dest_tid, |
| 347 |
dboolean fog, short group_tid) |
| 348 |
{ |
| 349 |
int result = 0; |
| 350 |
mobj_t *source; |
| 351 |
mobj_t *dest; |
| 352 |
mobj_t *target; |
| 353 |
thing_id_search_t search; |
| 354 |
|
| 355 |
dsda_ResetThingIDSearch(&search); |
| 356 |
source = dsda_FindMobjFromThingID(source_tid, &search); |
| 357 |
|
| 358 |
dest = P_TeleportDestination(dest_tid, 0); |
| 359 |
|
| 360 |
if (source && dest) |
| 361 |
{ |
| 362 |
const int *id_p; |
| 363 |
int flags; |
| 364 |
angle_t an; |
| 365 |
fixed_t dcos, dsin; |
| 366 |
|
| 367 |
flags = fog ? (TELF_DESTFOG | TELF_SOURCEFOG) : TELF_KEEPORIENTATION; |
| 368 |
|
| 369 |
an = dest->angle - source->angle; |
| 370 |
dcos = finecosine[an >> ANGLETOFINESHIFT]; |
| 371 |
dsin = finesine[an >> ANGLETOFINESHIFT]; |
| 372 |
|
| 373 |
FIND_SECTORS(id_p, tag) |
| 374 |
{ |
| 375 |
mobj_in_sector_t mis; |
| 376 |
|
| 377 |
P_InitSectorSearch(&mis, §ors[*id_p]); |
| 378 |
while ((target = P_FindMobjInSector(&mis))) |
| 379 |
{ |
| 380 |
fixed_t dx, dy; |
| 381 |
mobj_t target_dest; |
| 382 |
|
| 383 |
if (group_tid && target->tid != group_tid) |
| 384 |
continue; |
| 385 |
|
| 386 |
memset(&target_dest, 0, sizeof(target_dest)); |
| 387 |
|
| 388 |
dx = target->x - source->x; |
| 389 |
dy = target->y - source->y; |
| 390 |
target_dest.x = dest->x + FixedMul(dx, dcos) - FixedMul(dy, dsin); |
| 391 |
target_dest.y = dest->y + FixedMul(dx, dsin) + FixedMul(dy, dcos); |
| 392 |
target_dest.angle = target->angle; |
| 393 |
target_dest.type = dest->type; |
| 394 |
|
| 395 |
result |= P_TeleportToDestination(&target_dest, NULL, target, flags); |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
return result; |
| 401 |
} |
| 402 |
|
| 403 |
int EV_CompatibleTeleport(short thing_id, int tag, line_t *line, int side, mobj_t *thing, int flags) |
| 404 |
{ |
| 405 |
mobj_t *m; |
| 406 |
|
| 407 |
// don't teleport missiles |
| 408 |
// Don't teleport if hit back of line, |
| 409 |
// so you can get out of teleporter. |
| 410 |
if (side || thing->flags & MF_MISSILE) |
| 411 |
return 0; |
| 412 |
|
| 413 |
if ((m = P_TeleportDestination(thing_id, tag)) != NULL) |
| 414 |
{ |
| 415 |
return P_TeleportToDestination(m, line, thing, flags); |
| 416 |
} |
| 417 |
|
| 418 |
return 0; |
| 419 |
} |
| 420 |
|
| 421 |
// |
| 422 |
// Silent linedef-based TELEPORTATION, by Lee Killough |
| 423 |
// Primarily for rooms-over-rooms etc. |
| 424 |
// This is the complete player-preserving kind of teleporter. |
| 425 |
// It has advantages over the teleporter with thing exits. |
| 426 |
// |
| 427 |
|
| 428 |
// maximum fixed_t units to move object to avoid hiccups |
| 429 |
#define FUDGEFACTOR 10 |
| 430 |
|
| 431 |
int EV_SilentLineTeleport(line_t *line, int side, mobj_t *thing, |
| 432 |
int tag, dboolean reverse) |
| 433 |
{ |
| 434 |
const int *i; |
| 435 |
line_t *l; |
| 436 |
|
| 437 |
if (side || thing->flags & MF_MISSILE) |
| 438 |
return 0; |
| 439 |
|
| 440 |
for (i = dsda_FindLinesFromID(tag); *i >= 0; i++) |
| 441 |
if ((l = lines + *i) != line && l->backsector) |
| 442 |
{ |
| 443 |
// Get the thing's position along the source linedef |
| 444 |
fixed_t pos = D_abs(line->dx) > D_abs(line->dy) ? |
| 445 |
FixedDiv(thing->x - line->v1->x, line->dx) : |
| 446 |
FixedDiv(thing->y - line->v1->y, line->dy) ; |
| 447 |
|
| 448 |
// Get the angle between the two linedefs, for rotating |
| 449 |
// orientation and momentum. Rotate 180 degrees, and flip |
| 450 |
// the position across the exit linedef, if reversed. |
| 451 |
angle_t angle = (reverse ? pos = FRACUNIT-pos, 0 : ANG180) + |
| 452 |
R_PointToAngle2(0, 0, l->dx, l->dy) - |
| 453 |
R_PointToAngle2(0, 0, line->dx, line->dy); |
| 454 |
|
| 455 |
// Interpolate position across the exit linedef |
| 456 |
fixed_t x = l->v2->x - FixedMul(pos, l->dx); |
| 457 |
fixed_t y = l->v2->y - FixedMul(pos, l->dy); |
| 458 |
|
| 459 |
// Sine, cosine of angle adjustment |
| 460 |
fixed_t s = finesine[angle>>ANGLETOFINESHIFT]; |
| 461 |
fixed_t c = finecosine[angle>>ANGLETOFINESHIFT]; |
| 462 |
|
| 463 |
// Maximum distance thing can be moved away from interpolated |
| 464 |
// exit, to ensure that it is on the correct side of exit linedef |
| 465 |
int fudge = FUDGEFACTOR; |
| 466 |
|
| 467 |
// Whether this is a player, and if so, a pointer to its player_t. |
| 468 |
// Voodoo dolls are excluded by making sure thing->player->mo==thing. |
| 469 |
player_t *player = thing->player && thing->player->mo == thing ? |
| 470 |
thing->player : NULL; |
| 471 |
|
| 472 |
// Whether walking towards first side of exit linedef steps down |
| 473 |
int stepdown = |
| 474 |
l->frontsector->floorheight < l->backsector->floorheight; |
| 475 |
|
| 476 |
// Height of thing above ground |
| 477 |
fixed_t z = thing->z - thing->floorz; |
| 478 |
|
| 479 |
// Side to exit the linedef on positionally. |
| 480 |
// |
| 481 |
// Notes: |
| 482 |
// |
| 483 |
// This flag concerns exit position, not momentum. Due to |
| 484 |
// roundoff error, the thing can land on either the left or |
| 485 |
// the right side of the exit linedef, and steps must be |
| 486 |
// taken to make sure it does not end up on the wrong side. |
| 487 |
// |
| 488 |
// Exit momentum is always towards side 1 in a reversed |
| 489 |
// teleporter, and always towards side 0 otherwise. |
| 490 |
// |
| 491 |
// Exiting positionally on side 1 is always safe, as far |
| 492 |
// as avoiding oscillations and stuck-in-wall problems, |
| 493 |
// but may not be optimum for non-reversed teleporters. |
| 494 |
// |
| 495 |
// Exiting on side 0 can cause oscillations if momentum |
| 496 |
// is towards side 1, as it is with reversed teleporters. |
| 497 |
// |
| 498 |
// Exiting on side 1 slightly improves player viewing |
| 499 |
// when going down a step on a non-reversed teleporter. |
| 500 |
|
| 501 |
int side = reverse || (player && stepdown); |
| 502 |
|
| 503 |
// Make sure we are on correct side of exit linedef. |
| 504 |
while (P_PointOnLineSide(x, y, l) != side && --fudge>=0) |
| 505 |
if (D_abs(l->dx) > D_abs(l->dy)) |
| 506 |
y -= (l->dx < 0) != side ? -1 : 1; |
| 507 |
else |
| 508 |
x += (l->dy < 0) != side ? -1 : 1; |
| 509 |
|
| 510 |
// Attempt to teleport, aborting if blocked |
| 511 |
if (!P_TeleportMove(thing, x, y, false)) /* killough 8/9/98 */ |
| 512 |
return 0; |
| 513 |
|
| 514 |
// e6y |
| 515 |
if (player && player->mo == thing) |
| 516 |
R_ResetAfterTeleport(player); |
| 517 |
|
| 518 |
// Adjust z position to be same height above ground as before. |
| 519 |
// Ground level at the exit is measured as the higher of the |
| 520 |
// two floor heights at the exit linedef. |
| 521 |
thing->z = z + sides[l->sidenum[stepdown]].sector->floorheight; |
| 522 |
thing->PrevZ = thing->z; |
| 523 |
|
| 524 |
// Rotate thing's orientation according to difference in linedef angles |
| 525 |
thing->angle += angle; |
| 526 |
|
| 527 |
// Momentum of thing crossing teleporter linedef |
| 528 |
x = thing->momx; |
| 529 |
y = thing->momy; |
| 530 |
|
| 531 |
// Rotate thing's momentum to come out of exit just like it entered |
| 532 |
thing->momx = FixedMul(x, c) - FixedMul(y, s); |
| 533 |
thing->momy = FixedMul(y, c) + FixedMul(x, s); |
| 534 |
|
| 535 |
// Adjust a player's view, in case there has been a height change |
| 536 |
if (player) |
| 537 |
{ |
| 538 |
// Save the current deltaviewheight, used in stepping |
| 539 |
fixed_t deltaviewheight = player->deltaviewheight; |
| 540 |
|
| 541 |
// Clear deltaviewheight, since we don't want any changes now |
| 542 |
player->deltaviewheight = 0; |
| 543 |
|
| 544 |
// Set player's view according to the newly set parameters |
| 545 |
P_CalcHeight(player); |
| 546 |
|
| 547 |
// Reset the delta to have the same dynamics as before |
| 548 |
player->deltaviewheight = deltaviewheight; |
| 549 |
} |
| 550 |
|
| 551 |
// e6y |
| 552 |
if (player && player->mo == thing) |
| 553 |
R_ResetAfterTeleport(player); |
| 554 |
|
| 555 |
return 1; |
| 556 |
} |
| 557 |
return 0; |
| 558 |
} |
| 559 |
|
| 560 |
// heretic |
| 561 |
|
| 562 |
#include "heretic/def.h" |
| 563 |
|
| 564 |
dboolean P_Teleport(mobj_t * thing, fixed_t x, fixed_t y, angle_t angle, dboolean useFog) |
| 565 |
{ |
| 566 |
fixed_t oldx; |
| 567 |
fixed_t oldy; |
| 568 |
fixed_t oldz; |
| 569 |
fixed_t aboveFloor; |
| 570 |
fixed_t fogDelta; |
| 571 |
player_t *player; |
| 572 |
unsigned an; |
| 573 |
mobj_t *fog; |
| 574 |
|
| 575 |
oldx = thing->x; |
| 576 |
oldy = thing->y; |
| 577 |
oldz = thing->z; |
| 578 |
aboveFloor = thing->z - thing->floorz; |
| 579 |
if (!P_TeleportMove(thing, x, y, false)) |
| 580 |
{ |
| 581 |
return (false); |
| 582 |
} |
| 583 |
if (thing->player) |
| 584 |
{ |
| 585 |
player = thing->player; |
| 586 |
if (player->powers[pw_flight] && aboveFloor) |
| 587 |
{ |
| 588 |
thing->z = thing->floorz + aboveFloor; |
| 589 |
if (thing->z + thing->height > thing->ceilingz) |
| 590 |
{ |
| 591 |
thing->z = thing->ceilingz - thing->height; |
| 592 |
} |
| 593 |
player->viewz = thing->z + player->viewheight; |
| 594 |
} |
| 595 |
else |
| 596 |
{ |
| 597 |
thing->z = thing->floorz; |
| 598 |
player->viewz = thing->z + player->viewheight; |
| 599 |
if (useFog) |
| 600 |
{ |
| 601 |
player->lookdir = 0; |
| 602 |
} |
| 603 |
} |
| 604 |
} |
| 605 |
else if (thing->flags & MF_MISSILE) |
| 606 |
{ |
| 607 |
thing->z = thing->floorz + aboveFloor; |
| 608 |
if (thing->z + thing->height > thing->ceilingz) |
| 609 |
{ |
| 610 |
thing->z = thing->ceilingz - thing->height; |
| 611 |
} |
| 612 |
} |
| 613 |
else |
| 614 |
{ |
| 615 |
thing->z = thing->floorz; |
| 616 |
} |
| 617 |
// Spawn teleport fog at source and destination |
| 618 |
if (useFog) |
| 619 |
{ |
| 620 |
fogDelta = thing->flags & MF_MISSILE ? 0 : TELEFOGHEIGHT; |
| 621 |
fog = P_SpawnMobj(oldx, oldy, oldz + fogDelta, g_mt_tfog); |
| 622 |
S_StartMobjSound(fog, g_sfx_telept); |
| 623 |
an = angle >> ANGLETOFINESHIFT; |
| 624 |
fog = P_SpawnMobj(x + 20 * finecosine[an], |
| 625 |
y + 20 * finesine[an], thing->z + fogDelta, g_mt_tfog); |
| 626 |
S_StartMobjSound(fog, g_sfx_telept); |
| 627 |
if (thing->player && |
| 628 |
!thing->player->powers[pw_weaponlevel2] && |
| 629 |
!thing->player->powers[pw_speed]) |
| 630 |
{ // Freeze player for about .5 sec |
| 631 |
thing->reactiontime = 18; |
| 632 |
} |
| 633 |
thing->angle = angle; |
| 634 |
} |
| 635 |
|
| 636 |
if (hexen) |
| 637 |
{ |
| 638 |
if (thing->flags2 & MF2_FOOTCLIP) |
| 639 |
{ |
| 640 |
if (thing->z == thing->subsector->sector->floorheight |
| 641 |
&& P_GetThingFloorType(thing) > FLOOR_SOLID) |
| 642 |
{ |
| 643 |
thing->floorclip = 10 * FRACUNIT; |
| 644 |
} |
| 645 |
else |
| 646 |
{ |
| 647 |
thing->floorclip = 0; |
| 648 |
} |
| 649 |
} |
| 650 |
} |
| 651 |
else |
| 652 |
{ |
| 653 |
if (thing->flags2 & MF2_FOOTCLIP |
| 654 |
&& P_GetThingFloorType(thing) != FLOOR_SOLID) |
| 655 |
{ |
| 656 |
thing->flags2 |= MF2_FEETARECLIPPED; |
| 657 |
} |
| 658 |
else if (thing->flags2 & MF2_FEETARECLIPPED) |
| 659 |
{ |
| 660 |
thing->flags2 &= ~MF2_FEETARECLIPPED; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
if (thing->flags & MF_MISSILE) |
| 665 |
{ |
| 666 |
angle >>= ANGLETOFINESHIFT; |
| 667 |
thing->momx = FixedMul(thing->info->speed, finecosine[angle]); |
| 668 |
thing->momy = FixedMul(thing->info->speed, finesine[angle]); |
| 669 |
} |
| 670 |
else if (useFog) |
| 671 |
{ |
| 672 |
thing->momx = thing->momy = thing->momz = 0; |
| 673 |
} |
| 674 |
|
| 675 |
if (thing->player) |
| 676 |
{ |
| 677 |
R_ResetAfterTeleport(thing->player); |
| 678 |
} |
| 679 |
|
| 680 |
return (true); |
| 681 |
} |
| 682 |
|
| 683 |
int EV_HereticTeleport(short thing_id, int tag, line_t * line, int side, mobj_t * thing, int flags) |
| 684 |
{ |
| 685 |
int i; |
| 686 |
mobj_t *m; |
| 687 |
thinker_t *thinker; |
| 688 |
sector_t *sector; |
| 689 |
|
| 690 |
if (thing->flags2 & MF2_NOTELEPORT) |
| 691 |
{ |
| 692 |
return (false); |
| 693 |
} |
| 694 |
if (side == 1) |
| 695 |
{ // Don't teleport when crossing back side |
| 696 |
return (false); |
| 697 |
} |
| 698 |
for (i = 0; i < numsectors; i++) |
| 699 |
{ |
| 700 |
if (sectors[i].tag == tag) |
| 701 |
{ |
| 702 |
for (thinker = thinkercap.next; thinker != &thinkercap; |
| 703 |
thinker = thinker->next) |
| 704 |
{ |
| 705 |
if (thinker->function != P_MobjThinker) |
| 706 |
{ // Not a mobj |
| 707 |
continue; |
| 708 |
} |
| 709 |
m = (mobj_t *) thinker; |
| 710 |
if (m->type != HERETIC_MT_TELEPORTMAN) |
| 711 |
{ // Not a teleportman |
| 712 |
continue; |
| 713 |
} |
| 714 |
sector = m->subsector->sector; |
| 715 |
if (sector - sectors != i) |
| 716 |
{ // Wrong sector |
| 717 |
continue; |
| 718 |
} |
| 719 |
return (P_Teleport(thing, m->x, m->y, m->angle, true)); |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
return (false); |
| 724 |
} |
| 725 |
|
| 726 |
// hexen |
| 727 |
|
| 728 |
#include "m_random.h" |
| 729 |
#include "lprintf.h" |
| 730 |
|
| 731 |
dboolean EV_HexenTeleport(int tid, mobj_t * thing, dboolean fog) |
| 732 |
{ |
| 733 |
int i; |
| 734 |
int count; |
| 735 |
mobj_t *mo; |
| 736 |
int searcher; |
| 737 |
|
| 738 |
if (!thing) |
| 739 |
{ // Teleport function called with an invalid mobj |
| 740 |
return false; |
| 741 |
} |
| 742 |
if (thing->flags2 & MF2_NOTELEPORT) |
| 743 |
{ |
| 744 |
return false; |
| 745 |
} |
| 746 |
count = 0; |
| 747 |
searcher = -1; |
| 748 |
while (P_FindMobjFromTID(tid, &searcher) != NULL) |
| 749 |
{ |
| 750 |
count++; |
| 751 |
} |
| 752 |
if (count == 0) |
| 753 |
{ |
| 754 |
return false; |
| 755 |
} |
| 756 |
count = 1 + (P_Random(pr_hexen) % count); |
| 757 |
searcher = -1; |
| 758 |
mo = NULL; |
| 759 |
|
| 760 |
for (i = 0; i < count; i++) |
| 761 |
{ |
| 762 |
mo = P_FindMobjFromTID(tid, &searcher); |
| 763 |
} |
| 764 |
if (mo == NULL) |
| 765 |
{ |
| 766 |
I_Error("Can't find teleport mapspot\n"); |
| 767 |
} |
| 768 |
return P_Teleport(thing, mo->x, mo->y, mo->angle, fog); |
| 769 |
} |