Skip to content

Commit

Permalink
Add 'Allow use during speech' parameter for scripted_sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jan 5, 2025
1 parent 347c2f2 commit 95dce68
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dlls/followingmonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ bool CFollowingMonster::InScriptedSentence()
return false;
}

bool CFollowingMonster::AllowUseDuringScriptedSentence()
{
return false;
}

Schedule_t* CFollowingMonster::GetFollowingSchedule(bool ignoreEnemy)
{
if( (ignoreEnemy || m_hEnemy == 0 || !m_hEnemy->IsFullyAlive()) && IsFollowingPlayer() )
Expand Down Expand Up @@ -700,7 +705,11 @@ void CFollowingMonster::FollowerUse( CBaseEntity *pActivator, CBaseEntity *pCall
}
return;
}
DoFollowerUse(pCaller, true, USE_TOGGLE);
int result = DoFollowerUse(pCaller, true, USE_TOGGLE);
if (result == FOLLOWING_NOTREADY && AllowUseDuringScriptedSentence())
{
DoFollowerUse(pCaller, false, USE_TOGGLE, true);
}
}

bool CFollowingMonster::ShouldDeclineFollowing()
Expand Down
1 change: 1 addition & 0 deletions dlls/followingmonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CFollowingMonster : public CSquadMonster

CFollowingMonster* MyFollowingMonsterPointer() { return this; }
virtual bool InScriptedSentence();
virtual bool AllowUseDuringScriptedSentence();
Schedule_t* GetFollowingSchedule(bool ignoreEnemy = false);
void EXPORT FollowerUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
int DoFollowerUse(CBaseEntity* pCaller, bool saySentence, USE_TYPE useType, bool ignoreScriptedSentence = false);
Expand Down
17 changes: 16 additions & 1 deletion dlls/scripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ class CScriptedSentence : public CBaseDelay
short m_searchPolicy;
short m_applySearchRadius;
string_t m_searchOrigin;
short m_allowUse;
};

#define SF_SENTENCE_ONCE 0x0001
Expand Down Expand Up @@ -1330,6 +1331,7 @@ TYPEDESCRIPTION CScriptedSentence::m_SaveData[] =
DEFINE_FIELD( CScriptedSentence, m_searchPolicy, FIELD_SHORT ),
DEFINE_FIELD( CScriptedSentence, m_applySearchRadius, FIELD_SHORT ),
DEFINE_FIELD( CScriptedSentence, m_searchOrigin, FIELD_STRING ),
DEFINE_FIELD( CScriptedSentence, m_allowUse, FIELD_SHORT ),
};

IMPLEMENT_SAVERESTORE( CScriptedSentence, CBaseDelay )
Expand Down Expand Up @@ -1413,6 +1415,11 @@ void CScriptedSentence::KeyValue( KeyValueData *pkvd )
m_searchOrigin = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = true;
}
else if ( FStrEq( pkvd->szKeyName, "allow_use" ) )
{
m_allowUse = (short)atoi( pkvd->szValue );
pkvd->fHandled = true;
}
else
CBaseDelay::KeyValue( pkvd );
}
Expand Down Expand Up @@ -1649,8 +1656,16 @@ bool CScriptedSentence::StartSentence( CBaseToggle *pTarget )
}
}

pTarget->PlayScriptedSentence( STRING( m_iszSentence ), m_flDuration, m_flVolume, m_flAttenuation, bConcurrent, pListener );
CBaseMonster* pMonster = pTarget->MyMonsterPointer();
if (pMonster)
{
CTalkMonster* pTalkMonster = pMonster->MyTalkMonsterPointer();
if (pTalkMonster)
{
pTalkMonster->m_allowUseScriptedSentence = m_allowUse != 0;
}
}
pTarget->PlayScriptedSentence( STRING( m_iszSentence ), m_flDuration, m_flVolume, m_flAttenuation, bConcurrent, pListener );
if (pMonster != 0 && m_followAction)
{
CFollowingMonster* followingMonster = pMonster->MyFollowingMonsterPointer();
Expand Down
6 changes: 6 additions & 0 deletions dlls/talkmonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ TYPEDESCRIPTION CTalkMonster::m_SaveData[] =
DEFINE_FIELD( CTalkMonster, m_flStopLookTime, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_flNextFlinch, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_painTime, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_allowUseScriptedSentence, FIELD_BOOLEAN ),
};

IMPLEMENT_SAVERESTORE( CTalkMonster, CFollowingMonster )
Expand Down Expand Up @@ -734,6 +735,11 @@ bool CTalkMonster::InScriptedSentence()
return m_useTime > gpGlobals->time;
}

bool CTalkMonster::AllowUseDuringScriptedSentence()
{
return m_allowUseScriptedSentence;
}

void CTalkMonster::PlayUseSentence()
{
if (PlaySentence( SentenceGroup(TLK_USE), RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE ))
Expand Down
3 changes: 3 additions & 0 deletions dlls/talkmonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class CTalkMonster : public CFollowingMonster
void LimitFollowers( CBaseEntity *pPlayer, int maxFollowers );
virtual int TalkFriendCategory() { return TALK_FRIEND_PERSONNEL; }
bool InScriptedSentence();
bool AllowUseDuringScriptedSentence() override;
virtual void PlayUseSentence();
virtual void PlayUnUseSentence();
virtual void DeclineFollowing(CBaseEntity* pCaller);
Expand Down Expand Up @@ -273,6 +274,8 @@ class CTalkMonster : public CFollowingMonster
float m_flNextFlinch;
float m_painTime;

bool m_allowUseScriptedSentence;

CUSTOM_SCHEDULES
};

Expand Down
5 changes: 5 additions & 0 deletions fgd/halflife.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -8045,6 +8045,11 @@
1 : "Always"
]
search_origin(string) : "Speaker Search Origin (blank = here) [LP]" : : "Search the speaker relative to this position instead of the position of scripted_sentence"
allow_use(choices) : "Allow use during speech" =
[
0 : "No"
1 : "Yes"
]
]

@PointClass base(ScriptedSequence) = scripted_sequence : "Scripted Sequence"
Expand Down

0 comments on commit 95dce68

Please sign in to comment.