Skip to content

Commit

Permalink
server: added trigger_teleport_point entity from Diffusion mod
Browse files Browse the repository at this point in the history
Thanks to @Aynekko for sharing
  • Loading branch information
SNMetamorph committed Nov 22, 2024
1 parent c25e1cd commit 08bb151
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
70 changes: 70 additions & 0 deletions server/entities/trigger_teleport_point.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "trigger_teleport_point.h"
#include "player.h"
#include "monsters.h"

LINK_ENTITY_TO_CLASS( trigger_teleport_point, CTriggerTeleportPoint );

BEGIN_DATADESC( CTriggerTeleportPoint )
DEFINE_KEYFIELD( m_entity, FIELD_STRING, "entityname" ),
END_DATADESC();

void CTriggerTeleportPoint::KeyValue(KeyValueData* pkvd)
{
if (FStrEq(pkvd->szKeyName, "entityname"))
{
m_entity = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CBaseDelay::KeyValue(pkvd);
}

void CTriggerTeleportPoint::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
if (IsLockedByMaster(pActivator))
return;

if (!pActivator || !pActivator->IsPlayer())
pActivator = CBaseEntity::Instance(INDEXENT(1));

CBasePlayer* pPlayer = (CBasePlayer*)pActivator;
CBaseEntity* pEntity = NULL;

if (FStrEq(STRING(m_entity), "player") || !m_entity)
pEntity = pPlayer;
else
pEntity = UTIL_FindEntityByTargetname(pEntity, STRING(m_entity));

if (!pEntity)
{
ALERT(at_error, "trigger_teleport_point \"%s\" can't find specified entity!\n", STRING(pev->targetname));
return;
}

// this entity acts as a teleport target
Vector targetOrg = GetAbsOrigin();
Vector targetAng = GetAbsAngles();

Vector entityVelocity = g_vecZero;
if (FBitSet(pev->spawnflags, PT_KEEP_VELOCITY)) {
entityVelocity = pEntity->GetAbsVelocity();
}

Vector EntityAngles = targetAng;
if (FBitSet(pev->spawnflags, PT_KEEP_ANGLES)) {
EntityAngles = pEntity->GetAbsAngles();
}

// offset to correctly teleport the player...
if (pEntity->IsPlayer()) {
targetOrg.z += 36;
}

pEntity->Teleport(&targetOrg, &EntityAngles, &entityVelocity);

UTIL_FireTargets(pev->target, pActivator, pCaller, USE_TOGGLE, 0);

if (FBitSet(pev->spawnflags, PT_REMOVEONFIRE)) {
UTIL_Remove(this);
}
}
26 changes: 26 additions & 0 deletions server/entities/trigger_teleport_point.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "extdll.h"
#include "util.h"
#include "cbase.h"

//=======================================================================================================================
// diffusion - teleports entity regardless of its position (no teleport brush needed) - this entity also acts as a target
//=======================================================================================================================

#define PT_KEEP_VELOCITY BIT(0) // keep the velocity of the entity
#define PT_KEEP_ANGLES BIT(1) // don't snap to new angles
#define PT_REMOVEONFIRE BIT(2)

// UNDONE: redirect player's velocity to entity's view origin?

class CTriggerTeleportPoint : public CBaseDelay
{
DECLARE_CLASS(CTriggerTeleportPoint, CBaseDelay);
public:
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value);
void KeyValue(KeyValueData* pkvd);
int ObjectCaps(void) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }

DECLARE_DATADESC();

string_t m_entity;
};

0 comments on commit 08bb151

Please sign in to comment.