From 75f142e18a7eeee6139908b76b33fc800eece44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20H=C3=A0n=20Minh=20Khang?= Date: Wed, 8 May 2024 10:52:41 -0400 Subject: [PATCH] Add trigger_teleport landmark (#952) * Add trigger_teleport landmark --- regamedll/dlls/triggers.cpp | 44 ++++++++++++++++++- regamedll/dlls/triggers.h | 6 +++ .../GameDefinitionFile/regamedll-cs.fgd | 2 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/regamedll/dlls/triggers.cpp b/regamedll/dlls/triggers.cpp index c4af258c4..49e4d14c4 100644 --- a/regamedll/dlls/triggers.cpp +++ b/regamedll/dlls/triggers.cpp @@ -1763,8 +1763,30 @@ void CBaseTrigger::TeleportTouch(CBaseEntity *pOther) if (pOther->IsPlayer()) { +#ifdef REGAMEDLL_ADD + // If a landmark was specified, offset the player relative to the landmark + if (m_iszLandmarkName) + { + edict_t *pentLandmark = FIND_ENTITY_BY_TARGETNAME(nullptr, STRING(m_iszLandmarkName)); + + if (!FNullEnt(pentLandmark)) + { + Vector diff = pevToucher->origin - VARS(pentLandmark)->origin; + tmp += diff; + tmp.z--; // offset by +1 because -1 will run out of this scope. + } + else + { + // fallback, shouldn't happen but anyway. + tmp.z -= pOther->pev->mins.z; + } + } + else +#endif // make origin adjustments in case the teleportee is a player. (origin in center, not at feet) - tmp.z -= pOther->pev->mins.z; + { + tmp.z -= pOther->pev->mins.z; + } } tmp.z++; @@ -1817,6 +1839,26 @@ void CTriggerTeleport::Spawn() SetTouch(&CTriggerTeleport::TeleportTouch); } +void CTriggerTeleport::KeyValue(KeyValueData *pkvd) +{ +#ifdef REGAMEDLL_ADD + if (FStrEq(pkvd->szKeyName, "landmark")) + { + if (Q_strlen(pkvd->szValue) > 0) + { + m_iszLandmarkName = ALLOC_STRING(pkvd->szValue); + } + + // If empty, handle it in the teleport touch instead + pkvd->fHandled = TRUE; + } + else +#endif + { + CBaseTrigger::KeyValue(pkvd); + } +} + LINK_ENTITY_TO_CLASS(info_teleport_destination, CPointEntity, CCSPointEntity) LINK_ENTITY_TO_CLASS(func_buyzone, CBuyZone, CCSBuyZone) diff --git a/regamedll/dlls/triggers.h b/regamedll/dlls/triggers.h index c16f969c8..b21a6bde5 100644 --- a/regamedll/dlls/triggers.h +++ b/regamedll/dlls/triggers.h @@ -204,6 +204,11 @@ class CBaseTrigger: public CBaseToggle void EXPORT CounterUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); void EXPORT ToggleUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); void InitTrigger(); + +#ifdef REGAMEDLL_ADD + // For trigger_teleport TriggerTouch + int m_iszLandmarkName = 0; +#endif }; #define SF_TRIGGER_HURT_TARGETONCE BIT(0) // Only fire hurt target once @@ -393,6 +398,7 @@ class CTriggerTeleport: public CBaseTrigger { public: virtual void Spawn(); + virtual void KeyValue(KeyValueData *pkvd); }; class CBuyZone: public CBaseTrigger diff --git a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd index 0e6838732..79fe8333a 100644 --- a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd +++ b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd @@ -1934,6 +1934,7 @@ bombradius(integer) : "Bomb Radius" : 500 ] +@PointClass base(Targetname) iconsprite("sprites/CS/info_target.spr") = info_landmark : "Transition/Relative teleport Landmark" [] @PointClass base(Targetname) iconsprite("sprites/CS/info_target.spr") = info_null : "info_null (spotlight target)" [] @PointClass iconsprite("sprites/CS/info_player_deathmatch.spr") base(PlayerClass) = info_player_deathmatch : "Terrorist start" [] @PointClass iconsprite("sprites/CS/info_player_start.spr") base(PlayerClass) = info_player_start : "Counter-terrorist start" [] @@ -2264,6 +2265,7 @@ @SolidClass base(Trigger) = trigger_teleport : "Trigger teleport" [ + landmark(string) : "Landmark name" spawnflags(flags) = [ 256: "Keep angles" : 0