Skip to content

Commit

Permalink
Add 'Forward activator' flag for trigger_timer
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jul 13, 2024
1 parent 7d57a66 commit 3905966
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
23 changes: 17 additions & 6 deletions dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4357,6 +4357,7 @@ void CTriggerKillMonster::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE

#define SF_TRIGGER_TIMER_START_ON 1
#define SF_TRIGGER_TIMER_NO_FIRST_DELAY 32
#define SF_TRIGGER_TIMER_FORWARD_ACTIVATOR 64
#define SF_TRIGGER_TIMER_PREDETERMINED_TIMED 128

class CTriggerTimer : public CPointEntity
Expand All @@ -4372,7 +4373,7 @@ class CTriggerTimer : public CPointEntity
static TYPEDESCRIPTION m_SaveData[];

float GetRandomDelay();
void SetActive(BOOL active);
void SetActive(BOOL active, CBaseEntity* pActivator = NULL);

bool HasPredeterminedDelays() const {
return FBitSet(pev->spawnflags, SF_TRIGGER_TIMER_PREDETERMINED_TIMED);
Expand All @@ -4385,6 +4386,7 @@ class CTriggerTimer : public CPointEntity
BOOL m_active;
string_t m_triggerOnLimit;
unsigned int m_delayRandomSeed;
EHANDLE m_hActivator;
};

LINK_ENTITY_TO_CLASS( trigger_timer, CTriggerTimer )
Expand All @@ -4398,6 +4400,7 @@ TYPEDESCRIPTION CTriggerTimer::m_SaveData[] =
DEFINE_FIELD( CTriggerTimer, m_active, FIELD_BOOLEAN ),
DEFINE_FIELD( CTriggerTimer, m_triggerOnLimit, FIELD_STRING ),
DEFINE_FIELD( CTriggerTimer, m_delayRandomSeed, FIELD_INTEGER ),
DEFINE_FIELD( CTriggerTimer, m_hActivator, FIELD_EHANDLE ),
};

IMPLEMENT_SAVERESTORE( CTriggerTimer, CPointEntity )
Expand Down Expand Up @@ -4453,27 +4456,33 @@ void CTriggerTimer::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE
SetActive(FALSE);
break;
case USE_ON:
SetActive(TRUE);
SetActive(TRUE, pActivator);
break;
default:
SetActive(!m_active);
SetActive(!m_active, pActivator);
break;
}
}

void CTriggerTimer::TimerThink()
{
if (m_active) {
CBaseEntity* pActivator = this;
if (FBitSet(pev->spawnflags, SF_TRIGGER_TIMER_FORWARD_ACTIVATOR))
pActivator = m_hActivator;

if (!FStringNull(pev->target)) {
FireTargets(STRING(pev->target), this, this);
FireTargets(STRING(pev->target), pActivator, this);
}

if (m_triggerNumberLimit) {
m_triggerCounter++;
if (m_triggerCounter >= m_triggerNumberLimit) {
SetActive(FALSE);
if (!FStringNull(m_triggerOnLimit))
FireTargets(STRING(m_triggerOnLimit), this, this);
{
FireTargets(STRING(m_triggerOnLimit), pActivator, this);
}
return;
}
}
Expand All @@ -4495,20 +4504,22 @@ float CTriggerTimer::GetRandomDelay()
return RANDOM_FLOAT(minDelay, maxDelay);
}

void CTriggerTimer::SetActive(BOOL active)
void CTriggerTimer::SetActive(BOOL active, CBaseEntity* pActivator)
{
if (m_active == active)
return;
m_active = active;
if (m_active)
{
m_hActivator = pActivator;
if (FBitSet(pev->spawnflags, SF_TRIGGER_TIMER_NO_FIRST_DELAY))
pev->nextthink = gpGlobals->time;
else
pev->nextthink = gpGlobals->time + GetRandomDelay();
}
else
{
m_hActivator = 0;
m_triggerCounter = 0;
}
}
Expand Down
5 changes: 3 additions & 2 deletions fgd/halflife.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -8561,10 +8561,11 @@
[
1 : "Start on" : 0 : "Automatically activate trigger_timer on the first map load"
32 : "Don't delay first fire" : 0 : "Don't use random delay on the first target fire upon the activation"
64 : "Forward activator" : 0 : "Forward my activator when triggering my target. Without this flag trigger_timer passes itself as an activator."
128 : "Predetermined delays" : 0
]
min_delay(string) : "Minimum delay"
max_delay(string) : "Maximum delay"
min_delay(string) : "Minimum delay" : "0.5"
max_delay(string) : "Maximum delay" : "1.0"
trigger_number(integer) : "Trigger number limit" : : "Automatically stop after triggering the target this number of times. After that trigger_timer can be reactivated again. 0 means no limit."
trigger_on_limit(target_destination) : "Trigger on limit" : : "Trigger when the trigger limit is reached"
]
Expand Down

0 comments on commit 3905966

Please sign in to comment.