Skip to content

Commit

Permalink
Add trigger_teleport landmark (#952)
Browse files Browse the repository at this point in the history
* Add trigger_teleport landmark
  • Loading branch information
khanghugo authored May 8, 2024
1 parent 8cd9086 commit 75f142e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
44 changes: 43 additions & 1 deletion regamedll/dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/triggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -393,6 +398,7 @@ class CTriggerTeleport: public CBaseTrigger
{
public:
virtual void Spawn();
virtual void KeyValue(KeyValueData *pkvd);
};

class CBuyZone: public CBaseTrigger
Expand Down
2 changes: 2 additions & 0 deletions regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -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" []
Expand Down Expand Up @@ -2264,6 +2265,7 @@

@SolidClass base(Trigger) = trigger_teleport : "Trigger teleport"
[
landmark(string) : "Landmark name"
spawnflags(flags) =
[
256: "Keep angles" : 0
Expand Down

0 comments on commit 75f142e

Please sign in to comment.