2016-03-01 15:47:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1994-1996 Raven Software
|
|
|
|
// Copyright 1998-1998 Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2002-2016 Christoph Oelckers
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// 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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2016-03-01 15:47:10 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 11:33:19 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// Teleportation.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_terrain.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "p_maputl.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "p_spec.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2017-04-12 23:12:04 +00:00
|
|
|
#include "vm.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
#define FUDGEFACTOR 10
|
|
|
|
|
|
|
|
static FRandom pr_teleport ("Teleport");
|
|
|
|
|
|
|
|
CVAR (Bool, telezoom, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_SpawnTeleportFog
|
|
|
|
//
|
|
|
|
// The beginning of customizable teleport fog
|
|
|
|
// (not active yet)
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-23 09:42:41 +00:00
|
|
|
void P_SpawnTeleportFog(AActor *mobj, const DVector3 &pos, bool beforeTele, bool setTarget)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
AActor *mo;
|
|
|
|
if ((beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType) == NULL)
|
|
|
|
{
|
|
|
|
//Do nothing.
|
|
|
|
mo = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-06 08:48:40 +00:00
|
|
|
double fogDelta = mobj->flags & MF_MISSILE ? 0 : TELEFOGHEIGHT;
|
|
|
|
mo = Spawn((beforeTele ? mobj->TeleFogSourceType : mobj->TeleFogDestType), DVector3(pos, pos.Z + fogDelta), ALLOW_REPLACE);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mo != NULL && setTarget)
|
|
|
|
mo->target = mobj;
|
|
|
|
}
|
|
|
|
|
2016-11-24 00:23:35 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, SpawnTeleportFog)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_FLOAT(x);
|
|
|
|
PARAM_FLOAT(y);
|
|
|
|
PARAM_FLOAT(z);
|
|
|
|
PARAM_BOOL(before);
|
|
|
|
PARAM_BOOL(settarget);
|
|
|
|
P_SpawnTeleportFog(self, DVector3(x, y, z), before, settarget);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// TELEPORTATION
|
|
|
|
//
|
|
|
|
|
2016-03-28 22:31:59 +00:00
|
|
|
bool P_Teleport (AActor *thing, DVector3 pos, DAngle angle, int flags)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
bool predicting = (thing->player && (thing->player->cheats & CF_PREDICTING));
|
|
|
|
|
2016-03-23 09:42:41 +00:00
|
|
|
DVector3 old;
|
2016-03-28 22:31:59 +00:00
|
|
|
double aboveFloor;
|
2016-03-01 15:47:10 +00:00
|
|
|
player_t *player;
|
|
|
|
sector_t *destsect;
|
|
|
|
bool resetpitch = false;
|
2016-03-28 22:31:59 +00:00
|
|
|
double floorheight, ceilingheight;
|
2016-03-19 23:54:18 +00:00
|
|
|
double missilespeed = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-23 09:42:41 +00:00
|
|
|
old = thing->Pos();
|
2016-03-28 22:31:59 +00:00
|
|
|
aboveFloor = thing->Z() - thing->floorz;
|
|
|
|
destsect = P_PointInSector (pos);
|
2016-03-01 15:47:10 +00:00
|
|
|
// killough 5/12/98: exclude voodoo dolls:
|
|
|
|
player = thing->player;
|
|
|
|
if (player && player->mo != thing)
|
|
|
|
player = NULL;
|
2016-03-28 22:31:59 +00:00
|
|
|
floorheight = destsect->floorplane.ZatPoint (pos);
|
|
|
|
ceilingheight = destsect->ceilingplane.ZatPoint (pos);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (thing->flags & MF_MISSILE)
|
|
|
|
{ // We don't measure z velocity, because it doesn't change.
|
2016-03-19 23:54:18 +00:00
|
|
|
missilespeed = thing->VelXYToSpeed();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
if (flags & TELF_KEEPHEIGHT)
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = floorheight + aboveFloor;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-28 22:31:59 +00:00
|
|
|
else if (pos.Z == ONFLOORZ)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
{
|
|
|
|
if (thing->flags & MF_NOGRAVITY && aboveFloor)
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = floorheight + aboveFloor;
|
|
|
|
if (pos.Z + thing->Height > ceilingheight)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = ceilingheight - thing->Height;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = floorheight;
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!(flags & TELF_KEEPORIENTATION))
|
|
|
|
{
|
|
|
|
resetpitch = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (thing->flags & MF_MISSILE)
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = floorheight + aboveFloor;
|
|
|
|
if (pos.Z + thing->Height > ceilingheight)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = ceilingheight - thing->Height;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
pos.Z = floorheight;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-28 22:31:59 +00:00
|
|
|
if (!P_TeleportMove (thing, pos, false))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (player)
|
|
|
|
{
|
2016-03-22 17:06:08 +00:00
|
|
|
player->viewz = thing->Z() + player->viewheight;
|
2016-03-01 15:47:10 +00:00
|
|
|
if (resetpitch)
|
|
|
|
{
|
2016-03-16 21:29:35 +00:00
|
|
|
player->mo->Angles.Pitch = 0.;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(flags & TELF_KEEPORIENTATION))
|
|
|
|
{
|
2016-03-16 11:41:26 +00:00
|
|
|
thing->Angles.Yaw = angle;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-16 11:41:26 +00:00
|
|
|
angle = thing->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
// Spawn teleport fog at source and destination
|
|
|
|
if ((flags & TELF_SOURCEFOG) && !predicting)
|
|
|
|
{
|
|
|
|
P_SpawnTeleportFog(thing, old, true, true); //Passes the actor through which then pulls the TeleFog metadata types based on properties.
|
|
|
|
}
|
|
|
|
if (flags & TELF_DESTFOG)
|
|
|
|
{
|
|
|
|
if (!predicting)
|
|
|
|
{
|
2016-03-22 11:42:27 +00:00
|
|
|
DVector2 vector = angle.ToVector(20);
|
2016-03-28 22:31:59 +00:00
|
|
|
DVector2 fogpos = P_GetOffsetPosition(pos.X, pos.Y, vector.X, vector.Y);
|
2016-06-06 08:48:40 +00:00
|
|
|
P_SpawnTeleportFog(thing, DVector3(fogpos, thing->Z()), false, true);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if (thing->player)
|
|
|
|
{
|
|
|
|
// [RH] Zoom player's field of vision
|
|
|
|
// [BC] && bHaltVelocity.
|
|
|
|
if (telezoom && thing->player->mo == thing && !(flags & TELF_KEEPVELOCITY))
|
|
|
|
thing->player->FOV = MIN (175.f, thing->player->DesiredFOV + 45.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// [BC] && bHaltVelocity.
|
|
|
|
if (thing->player && ((flags & TELF_DESTFOG) || !(flags & TELF_KEEPORIENTATION)) && !(flags & TELF_KEEPVELOCITY))
|
|
|
|
{
|
2018-11-24 20:37:00 +00:00
|
|
|
int time = 18;
|
2019-01-03 21:05:49 +00:00
|
|
|
IFVIRTUALPTRNAME(thing, NAME_PlayerPawn, GetTeleportFreezeTime)
|
2018-11-24 20:37:00 +00:00
|
|
|
{
|
|
|
|
VMValue param = thing;
|
|
|
|
VMReturn ret(&time);
|
|
|
|
VMCall(func, ¶m, 1, &ret, 1);
|
|
|
|
}
|
|
|
|
thing->reactiontime = time;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
if (thing->flags & MF_MISSILE)
|
|
|
|
{
|
2016-03-16 11:41:26 +00:00
|
|
|
thing->VelFromAngle(missilespeed);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
// [BC] && bHaltVelocity.
|
|
|
|
else if (!(flags & TELF_KEEPORIENTATION) && !(flags & TELF_KEEPVELOCITY))
|
|
|
|
{ // no fog doesn't alter the player's momentum
|
2016-03-19 23:54:18 +00:00
|
|
|
thing->Vel.Zero();
|
2016-03-01 15:47:10 +00:00
|
|
|
// killough 10/98: kill all bobbing velocity too
|
2016-03-19 23:54:18 +00:00
|
|
|
if (player) player->Vel.Zero();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-25 18:52:35 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, Teleport)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_FLOAT(x);
|
|
|
|
PARAM_FLOAT(y);
|
|
|
|
PARAM_FLOAT(z);
|
|
|
|
PARAM_ANGLE(an);
|
|
|
|
PARAM_INT(flags);
|
|
|
|
ACTION_RETURN_BOOL(P_Teleport(self, DVector3(x, y, z), an, flags));
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
static AActor *SelectTeleDest (int tid, int tag, bool norandom)
|
|
|
|
{
|
|
|
|
AActor *searcher;
|
|
|
|
|
|
|
|
// If tid is non-zero, select a destination from a matching actor at random.
|
|
|
|
// If tag is also non-zero, the selection is restricted to actors in sectors
|
|
|
|
// with a matching tag. If tid is zero and tag is non-zero, then the old Doom
|
|
|
|
// behavior is used instead (return the first teleport dest found in a tagged
|
|
|
|
// sector).
|
|
|
|
|
|
|
|
// Compatibility hack for some maps that fell victim to a bug in the teleport code in 2.0.9x
|
|
|
|
if (ib_compatflags & BCOMPATF_BADTELEPORTERS) tag = 0;
|
|
|
|
|
|
|
|
if (tid != 0)
|
|
|
|
{
|
|
|
|
NActorIterator iterator (NAME_TeleportDest, tid);
|
|
|
|
int count = 0;
|
|
|
|
while ( (searcher = iterator.Next ()) )
|
|
|
|
{
|
|
|
|
if (tag == 0 || tagManager.SectorHasTag(searcher->Sector, tag))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If teleport dests were not found, the sector tag is ignored for the
|
|
|
|
// following compatibility searches.
|
|
|
|
// Do this only when tag is 0 because this is the only case that was defined in Hexen.
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
if (tag == 0)
|
|
|
|
{
|
|
|
|
// Try to find a matching map spot (fixes Hexen MAP10)
|
|
|
|
NActorIterator it2 (NAME_MapSpot, tid);
|
|
|
|
searcher = it2.Next ();
|
|
|
|
if (searcher == NULL)
|
|
|
|
{
|
|
|
|
// Try to find a matching non-blocking spot of any type (fixes Caldera MAP13)
|
|
|
|
FActorIterator it3 (tid);
|
|
|
|
searcher = it3.Next ();
|
|
|
|
while (searcher != NULL && (searcher->flags & MF_SOLID))
|
|
|
|
{
|
|
|
|
searcher = it3.Next ();
|
|
|
|
}
|
|
|
|
return searcher;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (count != 1 && !norandom)
|
|
|
|
{
|
|
|
|
count = 1 + (pr_teleport() % count);
|
|
|
|
}
|
|
|
|
searcher = NULL;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
searcher = iterator.Next ();
|
|
|
|
if (tag == 0 || tagManager.SectorHasTag(searcher->Sector, tag))
|
|
|
|
{
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return searcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag != 0)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
|
|
|
|
FSectorTagIterator itr(tag);
|
|
|
|
while ((secnum = itr.Next()) >= 0)
|
|
|
|
{
|
|
|
|
// Scanning the snext links of things in the sector will not work, because
|
|
|
|
// TeleportDests have MF_NOSECTOR set. So you have to search *everything*.
|
|
|
|
// If there is more than one sector with a matching tag, then the destination
|
|
|
|
// in the lowest-numbered sector is returned, rather than the earliest placed
|
|
|
|
// teleport destination. This means if 50 sectors have a matching tag and
|
|
|
|
// only the last one has a destination, *every* actor is scanned at least 49
|
|
|
|
// times. Yuck.
|
|
|
|
TThinkerIterator<AActor> it2(NAME_TeleportDest);
|
|
|
|
while ((searcher = it2.Next()) != NULL)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
if (searcher->Sector == &level.sectors[secnum])
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return searcher;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EV_Teleport (int tid, int tag, line_t *line, int side, AActor *thing, int flags)
|
|
|
|
{
|
|
|
|
AActor *searcher;
|
2016-03-28 22:31:59 +00:00
|
|
|
double z;
|
2016-03-16 21:29:35 +00:00
|
|
|
DAngle angle = 0.;
|
2016-03-19 23:54:18 +00:00
|
|
|
double s = 0, c = 0;
|
|
|
|
double vx = 0, vy = 0;
|
2016-03-16 21:29:35 +00:00
|
|
|
DAngle badangle = 0.;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (thing == NULL)
|
|
|
|
{ // Teleport function called with an invalid actor
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool predicting = (thing->player && (thing->player->cheats & CF_PREDICTING));
|
|
|
|
if (thing->flags2 & MF2_NOTELEPORT)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (side != 0)
|
|
|
|
{ // Don't teleport if hit back of line, so you can get out of teleporter.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
searcher = SelectTeleDest(tid, tag, predicting);
|
|
|
|
if (searcher == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// [RH] Lee Killough's changes for silent teleporters from BOOM
|
2016-04-23 19:32:40 +00:00
|
|
|
if ((flags & (TELF_ROTATEBOOM|TELF_ROTATEBOOMINVERSE)) && line)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// Get the angle between the exit thing and source linedef.
|
|
|
|
// Rotate 90 degrees, so that walking perpendicularly across
|
|
|
|
// teleporter linedef causes thing to exit in the direction
|
|
|
|
// indicated by the exit thing.
|
2016-03-27 18:58:01 +00:00
|
|
|
angle = line->Delta().Angle() - searcher->Angles.Yaw + 90.;
|
2016-04-23 19:32:40 +00:00
|
|
|
if (flags & TELF_ROTATEBOOMINVERSE) angle = -angle;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Sine, cosine of angle adjustment
|
2016-03-19 23:54:18 +00:00
|
|
|
s = angle.Sin();
|
|
|
|
c = angle.Cos();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Velocity of thing crossing teleporter linedef
|
2016-03-19 23:54:18 +00:00
|
|
|
vx = thing->Vel.X;
|
|
|
|
vy = thing->Vel.Y;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-28 22:31:59 +00:00
|
|
|
z = searcher->Z();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else if (searcher->IsKindOf (PClass::FindClass(NAME_TeleportDest2)))
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
z = searcher->Z();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
z = ONFLOORZ;
|
|
|
|
}
|
|
|
|
if ((i_compatflags2 & COMPATF2_BADANGLES) && (thing->player != NULL))
|
|
|
|
{
|
2016-03-16 11:41:26 +00:00
|
|
|
badangle = 0.01;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-28 22:31:59 +00:00
|
|
|
if (P_Teleport (thing, DVector3(searcher->Pos(), z), searcher->Angles.Yaw + badangle, flags))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// [RH] Lee Killough's changes for silent teleporters from BOOM
|
2016-04-23 19:32:40 +00:00
|
|
|
if (line)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-04-23 19:32:40 +00:00
|
|
|
if (flags & (TELF_ROTATEBOOM| TELF_ROTATEBOOMINVERSE))
|
|
|
|
{
|
|
|
|
// Rotate thing according to difference in angles (or not - Boom got the direction wrong here.)
|
|
|
|
thing->Angles.Yaw += angle;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-04-23 19:32:40 +00:00
|
|
|
// Rotate thing's velocity to come out of exit just like it entered
|
|
|
|
thing->Vel.X = vx*c - vy*s;
|
|
|
|
thing->Vel.Y = vy*c + vx*s;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-19 23:54:18 +00:00
|
|
|
if (vx == 0 && vy == 0 && thing->player != NULL && thing->player->mo == thing && !predicting)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-03 12:58:53 +00:00
|
|
|
PlayIdle (thing->player->mo);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Silent linedef-based TELEPORTATION, by Lee Killough
|
|
|
|
// Primarily for rooms-over-rooms etc.
|
|
|
|
// This is the complete player-preserving kind of teleporter.
|
|
|
|
// It has advantages over the teleporter with thing exits.
|
|
|
|
//
|
|
|
|
|
|
|
|
// [RH] Modified to support different source and destination ids.
|
|
|
|
// [RH] Modified some more to be accurate.
|
|
|
|
bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBOOL reverse)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
line_t *l;
|
|
|
|
|
|
|
|
if (side || thing->flags2 & MF2_NOTELEPORT || !line || line->sidedef[1] == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FLineIdIterator itr(id);
|
|
|
|
while ((i = itr.Next()) >= 0)
|
|
|
|
{
|
2017-01-08 13:39:16 +00:00
|
|
|
if (line->Index() == i)
|
2016-03-01 15:47:10 +00:00
|
|
|
continue;
|
|
|
|
|
2017-01-08 13:39:16 +00:00
|
|
|
if ((l=&level.lines[i]) != line && l->backsector)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// Get the thing's position along the source linedef
|
2016-03-19 23:54:18 +00:00
|
|
|
double pos;
|
|
|
|
DVector2 npos; // offsets from line
|
|
|
|
double den;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-19 23:54:18 +00:00
|
|
|
den = line->Delta().LengthSquared();
|
|
|
|
if (den == 0)
|
|
|
|
{
|
|
|
|
pos = 0;
|
|
|
|
npos.Zero();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-31 19:13:32 +00:00
|
|
|
double num = (thing->Pos().XY() - line->v1->fPos()) | line->Delta();
|
2016-03-19 23:54:18 +00:00
|
|
|
if (num <= 0)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
pos = 0;
|
2016-03-19 23:54:18 +00:00
|
|
|
}
|
|
|
|
else if (num >= den)
|
|
|
|
{
|
|
|
|
pos = 1;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-19 23:54:18 +00:00
|
|
|
pos = num / den;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-31 19:13:32 +00:00
|
|
|
npos = thing->Pos().XY() - line->v1->fPos() - line->Delta() * pos;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the angle between the two linedefs, for rotating
|
|
|
|
// orientation and velocity. Rotate 180 degrees, and flip
|
|
|
|
// the position across the exit linedef, if reversed.
|
2016-03-27 18:58:01 +00:00
|
|
|
DAngle angle = l->Delta().Angle() - line->Delta().Angle();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (!reverse)
|
|
|
|
{
|
2016-03-19 23:54:18 +00:00
|
|
|
angle += 180.;
|
|
|
|
pos = 1 - pos;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sine, cosine of angle adjustment
|
2016-03-19 23:54:18 +00:00
|
|
|
double s = angle.Sin();
|
|
|
|
double c = angle.Cos();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-19 23:54:18 +00:00
|
|
|
DVector2 p;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Rotate position along normal to match exit linedef
|
2016-03-19 23:54:18 +00:00
|
|
|
p.X = npos.X*c - npos.Y*s;
|
|
|
|
p.Y = npos.Y*c + npos.X*s;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Interpolate position across the exit linedef
|
2016-03-31 19:13:32 +00:00
|
|
|
p += l->v1->fPos() + pos*l->Delta();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Whether this is a player, and if so, a pointer to its player_t.
|
|
|
|
// Voodoo dolls are excluded by making sure thing->player->mo==thing.
|
|
|
|
player_t *player = thing->player && thing->player->mo == thing ?
|
|
|
|
thing->player : NULL;
|
|
|
|
|
|
|
|
// Whether walking towards first side of exit linedef steps down
|
2016-03-28 22:31:59 +00:00
|
|
|
bool stepdown = l->frontsector->floorplane.ZatPoint(p) < l->backsector->floorplane.ZatPoint(p);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Height of thing above ground
|
2016-03-28 22:31:59 +00:00
|
|
|
double z = thing->Z() - thing->floorz;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Side to exit the linedef on positionally.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
//
|
|
|
|
// This flag concerns exit position, not momentum. Due to
|
|
|
|
// roundoff error, the thing can land on either the left or
|
|
|
|
// the right side of the exit linedef, and steps must be
|
|
|
|
// taken to make sure it does not end up on the wrong side.
|
|
|
|
//
|
|
|
|
// Exit momentum is always towards side 1 in a reversed
|
|
|
|
// teleporter, and always towards side 0 otherwise.
|
|
|
|
//
|
|
|
|
// Exiting positionally on side 1 is always safe, as far
|
|
|
|
// as avoiding oscillations and stuck-in-wall problems,
|
|
|
|
// but may not be optimum for non-reversed teleporters.
|
|
|
|
//
|
|
|
|
// Exiting on side 0 can cause oscillations if momentum
|
|
|
|
// is towards side 1, as it is with reversed teleporters.
|
|
|
|
//
|
|
|
|
// Exiting on side 1 slightly improves player viewing
|
|
|
|
// when going down a step on a non-reversed teleporter.
|
|
|
|
|
2016-03-28 22:31:59 +00:00
|
|
|
// Is this really still necessary with real math instead of imprecise trig tables?
|
|
|
|
#if 1
|
2018-10-09 10:55:56 +00:00
|
|
|
const double fudgeamount = 1. / 65536.;
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
int side = reverse || (player && stepdown);
|
|
|
|
int fudge = FUDGEFACTOR;
|
|
|
|
|
2016-03-28 22:31:59 +00:00
|
|
|
double dx = line->Delta().X;
|
|
|
|
double dy = line->Delta().Y;
|
2018-10-09 10:55:56 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
// Make sure we are on correct side of exit linedef.
|
2016-03-28 22:31:59 +00:00
|
|
|
while (P_PointOnLineSidePrecise(p, l) != side && --fudge >= 0)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
if (fabs(dx) > fabs(dy))
|
2018-10-09 10:55:56 +00:00
|
|
|
p.Y -= (dx < 0) != side ? -fudgeamount : fudgeamount;
|
2016-03-01 15:47:10 +00:00
|
|
|
else
|
2018-10-09 10:55:56 +00:00
|
|
|
p.X += (dy < 0) != side ? -fudgeamount : fudgeamount;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-28 22:31:59 +00:00
|
|
|
#endif
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Adjust z position to be same height above ground as before.
|
|
|
|
// Ground level at the exit is measured as the higher of the
|
|
|
|
// two floor heights at the exit linedef.
|
2016-03-28 22:31:59 +00:00
|
|
|
z = z + l->sidedef[stepdown]->sector->floorplane.ZatPoint(p);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Attempt to teleport, aborting if blocked
|
2016-03-28 22:31:59 +00:00
|
|
|
if (!P_TeleportMove (thing, DVector3(p, z), false))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thing == players[consoleplayer].camera)
|
|
|
|
{
|
|
|
|
R_ResetViewInterpolation ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rotate thing's orientation according to difference in linedef angles
|
2016-03-19 23:54:18 +00:00
|
|
|
thing->Angles.Yaw += angle;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Rotate thing's velocity to come out of exit just like it entered
|
2016-03-28 22:31:59 +00:00
|
|
|
p = thing->Vel.XY();
|
2016-03-19 23:54:18 +00:00
|
|
|
thing->Vel.X = p.X*c - p.Y*s;
|
|
|
|
thing->Vel.Y = p.Y*c + p.X*s;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Adjust a player's view, in case there has been a height change
|
|
|
|
if (player && player->mo == thing)
|
|
|
|
{
|
|
|
|
// Adjust player's local copy of velocity
|
2016-03-19 23:54:18 +00:00
|
|
|
p = player->Vel;
|
|
|
|
player->Vel.X = p.X*c - p.Y*s;
|
|
|
|
player->Vel.Y = p.Y*c + p.X*s;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Save the current deltaviewheight, used in stepping
|
2016-03-22 11:42:27 +00:00
|
|
|
double deltaviewheight = player->deltaviewheight;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Clear deltaviewheight, since we don't want any changes now
|
|
|
|
player->deltaviewheight = 0;
|
|
|
|
|
|
|
|
// Set player's view according to the newly set parameters
|
2019-01-03 21:05:49 +00:00
|
|
|
IFVIRTUALPTRNAME(player->mo, NAME_PlayerPawn, CalcHeight)
|
2019-01-03 10:57:20 +00:00
|
|
|
{
|
|
|
|
VMValue param = player->mo;
|
|
|
|
VMCall(func, ¶m, 1, nullptr, 0);
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Reset the delta to have the same dynamics as before
|
|
|
|
player->deltaviewheight = deltaviewheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Teleport anything matching other_tid to dest_tid
|
|
|
|
bool EV_TeleportOther (int other_tid, int dest_tid, bool fog)
|
|
|
|
{
|
|
|
|
bool didSomething = false;
|
|
|
|
|
|
|
|
if (other_tid != 0 && dest_tid != 0)
|
|
|
|
{
|
|
|
|
AActor *victim;
|
|
|
|
FActorIterator iterator (other_tid);
|
|
|
|
|
|
|
|
while ( (victim = iterator.Next ()) )
|
|
|
|
{
|
|
|
|
didSomething |= EV_Teleport (dest_tid, 0, NULL, 0, victim,
|
|
|
|
fog ? (TELF_DESTFOG | TELF_SOURCEFOG) : TELF_KEEPORIENTATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return didSomething;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool DoGroupForOne (AActor *victim, AActor *source, AActor *dest, bool floorz, bool fog)
|
|
|
|
{
|
2016-03-28 22:31:59 +00:00
|
|
|
DAngle an = dest->Angles.Yaw - source->Angles.Yaw;
|
|
|
|
DVector2 off = victim->Pos() - source->Pos();
|
|
|
|
DAngle offAngle = victim->Angles.Yaw - source->Angles.Yaw;
|
|
|
|
DVector2 newp = { off.X * an.Cos() - off.Y * an.Sin(), off.X * an.Sin() + off.Y * an.Cos() };
|
|
|
|
double z = floorz ? ONFLOORZ : dest->Z() + victim->Z() - source->Z();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
bool res =
|
2016-03-28 22:31:59 +00:00
|
|
|
P_Teleport (victim, DVector3(dest->Pos().XY() + newp, z),
|
2016-03-16 21:29:35 +00:00
|
|
|
0., fog ? (TELF_DESTFOG | TELF_SOURCEFOG) : TELF_KEEPORIENTATION);
|
2016-03-01 15:47:10 +00:00
|
|
|
// P_Teleport only changes angle if fog is true
|
2016-03-16 11:41:26 +00:00
|
|
|
victim->Angles.Yaw = (dest->Angles.Yaw + victim->Angles.Yaw - source->Angles.Yaw).Normalized360();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Teleport a group of actors centered around source_tid so
|
|
|
|
// that they become centered around dest_tid instead.
|
|
|
|
bool EV_TeleportGroup (int group_tid, AActor *victim, int source_tid, int dest_tid, bool moveSource, bool fog)
|
|
|
|
{
|
|
|
|
AActor *sourceOrigin, *destOrigin;
|
|
|
|
{
|
|
|
|
FActorIterator iterator (source_tid);
|
|
|
|
sourceOrigin = iterator.Next ();
|
|
|
|
}
|
|
|
|
if (sourceOrigin == NULL)
|
|
|
|
{ // If there is no source origin, behave like TeleportOther
|
|
|
|
return EV_TeleportOther (group_tid, dest_tid, fog);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
NActorIterator iterator (NAME_TeleportDest, dest_tid);
|
|
|
|
destOrigin = iterator.Next ();
|
|
|
|
}
|
|
|
|
if (destOrigin == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool didSomething = false;
|
|
|
|
bool floorz = !destOrigin->IsKindOf (PClass::FindClass("TeleportDest2"));
|
|
|
|
|
|
|
|
// Use the passed victim if group_tid is 0
|
|
|
|
if (group_tid == 0 && victim != NULL)
|
|
|
|
{
|
|
|
|
didSomething = DoGroupForOne (victim, sourceOrigin, destOrigin, floorz, fog);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FActorIterator iterator (group_tid);
|
|
|
|
|
|
|
|
// For each actor with tid matching arg0, move it to the same
|
|
|
|
// position relative to destOrigin as it is relative to sourceOrigin
|
|
|
|
// before the teleport.
|
|
|
|
while ( (victim = iterator.Next ()) )
|
|
|
|
{
|
|
|
|
didSomething |= DoGroupForOne (victim, sourceOrigin, destOrigin, floorz, fog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moveSource && didSomething)
|
|
|
|
{
|
|
|
|
didSomething |=
|
2016-03-28 22:31:59 +00:00
|
|
|
P_Teleport (sourceOrigin, destOrigin->PosAtZ(floorz ? ONFLOORZ : destOrigin->Z()), 0., TELF_KEEPORIENTATION);
|
2016-03-16 11:41:26 +00:00
|
|
|
sourceOrigin->Angles.Yaw = destOrigin->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return didSomething;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Teleport a group of actors in a sector. Source_tid is used as a
|
|
|
|
// reference point so that they end up in the same position relative to
|
|
|
|
// dest_tid. Group_tid can be used to not teleport all actors in the sector.
|
|
|
|
bool EV_TeleportSector (int tag, int source_tid, int dest_tid, bool fog, int group_tid)
|
|
|
|
{
|
|
|
|
AActor *sourceOrigin, *destOrigin;
|
|
|
|
{
|
|
|
|
FActorIterator iterator (source_tid);
|
|
|
|
sourceOrigin = iterator.Next ();
|
|
|
|
}
|
|
|
|
if (sourceOrigin == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
NActorIterator iterator (NAME_TeleportDest, dest_tid);
|
|
|
|
destOrigin = iterator.Next ();
|
|
|
|
}
|
|
|
|
if (destOrigin == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool didSomething = false;
|
|
|
|
bool floorz = !destOrigin->IsKindOf (PClass::FindClass("TeleportDest2"));
|
|
|
|
int secnum;
|
|
|
|
|
|
|
|
secnum = -1;
|
|
|
|
FSectorTagIterator itr(tag);
|
|
|
|
while ((secnum = itr.Next()) >= 0)
|
|
|
|
{
|
|
|
|
msecnode_t *node;
|
2017-01-07 18:32:24 +00:00
|
|
|
const sector_t * const sec = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
for (node = sec->touching_thinglist; node; )
|
|
|
|
{
|
|
|
|
AActor *actor = node->m_thing;
|
|
|
|
msecnode_t *next = node->m_snext;
|
|
|
|
|
|
|
|
// possibly limit actors by group
|
|
|
|
if (actor != NULL && (group_tid == 0 || actor->tid == group_tid))
|
|
|
|
{
|
|
|
|
didSomething |= DoGroupForOne (actor, sourceOrigin, destOrigin, floorz, fog);
|
|
|
|
}
|
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return didSomething;
|
|
|
|
}
|