Skip to content

Commit

Permalink
initial experiment code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed Apr 3, 2024
1 parent 175e43f commit 327f068
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/game/server/entities/NPCs/basemonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
#include "CBaseToggle.h"
#include "monsters.h"

enum ScriptedCondition : int
{
None = 0,
Death,
GiveHealth,
TakeDamage,
TraceAttack,
BarnacleVictimBitten,
FoundCover,
DropItem,
StopFollowing,
};

/**
* @brief Enum namespace
*/
Expand Down Expand Up @@ -129,10 +142,14 @@ class CBaseMonster : public CBaseToggle

private:
int m_afConditions;
int m_szScriptedCondition;
string_t m_szScriptedTarget;

public:
static inline std::shared_ptr<spdlog::logger> AILogger;

void CheckScriptedCondition( ScriptedCondition m_iCondition, CBaseEntity* pActivator, float fValue );

enum SCRIPTSTATE
{
SCRIPT_PLAYING = 0, //!< Playing the sequence
Expand Down
8 changes: 8 additions & 0 deletions src/game/server/entities/NPCs/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ void CBaseMonster::CallGibMonster()

void CBaseMonster::Killed(CBaseEntity* attacker, int iGib)
{
CheckScriptedCondition( ScriptedCondition::Death, attacker, (float)iGib );

// If this NPC is using the follower use function, remove it to prevent players from using it.
if (m_pfnUse == &CBaseMonster::FollowerUse)
{
Expand Down Expand Up @@ -833,6 +835,8 @@ bool CBaseMonster::GiveHealth(float flHealth, int bitsDamageType)
// UNDONE: generic health should not heal any
// UNDONE: time-based damage

CheckScriptedCondition( ScriptedCondition::GiveHealth, nullptr, flHealth );

m_bitsDamageType &= ~(bitsDamageType & ~DMG_TIMEBASED);

return CBaseEntity::GiveHealth(flHealth, bitsDamageType);
Expand All @@ -846,6 +850,8 @@ bool CBaseMonster::TakeDamage(CBaseEntity* inflictor, CBaseEntity* attacker, flo
if (0 == pev->takedamage)
return false;

CheckScriptedCondition( ScriptedCondition::TakeDamage, inflictor, flDamage );

if (!IsAlive())
{
return DeadTakeDamage(inflictor, attacker, flDamage, bitsDamageType);
Expand Down Expand Up @@ -1257,6 +1263,8 @@ void CBaseMonster::TraceAttack(CBaseEntity* attacker, float flDamage, Vector vec
{
if (0 != pev->takedamage)
{
CheckScriptedCondition( ScriptedCondition::TraceAttack, attacker, flDamage );

m_LastHitGroup = ptr->iHitgroup;

switch (ptr->iHitgroup)
Expand Down
24 changes: 24 additions & 0 deletions src/game/server/entities/NPCs/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void CBaseMonster::BarnacleVictimBitten(CBaseEntity* pevBarnacle)
{
ChangeSchedule(pNewSchedule);
}
CheckScriptedCondition( ScriptedCondition::BarnacleVictimBitten, pevBarnacle, 0 );
}

void CBaseMonster::BarnacleVictimReleased()
Expand Down Expand Up @@ -2083,6 +2084,7 @@ bool CBaseMonster::FindCover(Vector vecThreat, Vector vecViewOffset, float flMin
MESSAGE_END();
*/

CheckScriptedCondition( ScriptedCondition::FoundCover, nullptr, 0 );
return true;
}
}
Expand Down Expand Up @@ -2720,10 +2722,29 @@ bool CBaseMonster::KeyValue(KeyValueData* pkvd)
m_iszUnUse = ALLOC_STRING(pkvd->szValue);
return true;
}
else if( FStrEq( pkvd->szKeyName, "m_szScriptedCondition" ) )
{
m_szScriptedCondition = atoi( pkvd->szValue );
return true;
}
else if( FStrEq( pkvd->szKeyName, "m_szScriptedTarget" ) )
{
m_szScriptedTarget = ALLOC_STRING( pkvd->szValue );
return true;
}

return BaseClass::KeyValue(pkvd);
}

void CBaseMonster :: CheckScriptedCondition( ScriptedCondition m_iCondition, CBaseEntity* pActivator, float fValue );

Check warning on line 2739 in src/game/server/entities/NPCs/monsters.cpp

View workflow job for this annotation

GitHub Actions / Linux-x86

declaration of ‘void CBaseMonster::CheckScriptedCondition(ScriptedCondition, CBaseEntity*, float)’ outside of class is not definition [-fpermissive]
{

Check failure on line 2740 in src/game/server/entities/NPCs/monsters.cpp

View workflow job for this annotation

GitHub Actions / Linux-x86

expected unqualified-id before ‘{’ token
if( !FStringNull( m_szScriptedTarget ) && m_szScriptedCondition == m_iCondition )
{
FireTargets( STRING( m_szScriptedTarget ), ( pActivator ? pActivator : this ), this, USE_TOGGLE, fValue );
m_szScriptedCondition = ScriptedCondition::None;
}
}

bool CBaseMonster::FCheckAITrigger()
{
bool fFireTarget;
Expand Down Expand Up @@ -3143,6 +3164,7 @@ CBaseEntity* CBaseMonster::DropItem(const char* pszItemName, const Vector& vecPo
// do we want this behavior to be default?! (sjb)
entity->pev->velocity = pev->velocity;
entity->pev->avelocity = Vector(0, RANDOM_FLOAT(0, 100), 0);
CheckScriptedCondition( ScriptedCondition::DropItem, entity, entity->pev->avelocity.y );
return entity;
}
else
Expand Down Expand Up @@ -3227,6 +3249,8 @@ void CBaseMonster::StopFollowing(bool clearSchedule)
{
if (IsFollowing())
{
CheckScriptedCondition( ScriptedCondition::StopFollowing, m_hTargetEnt, m_movementGoal );

if (IRelationship(m_hTargetEnt) == Relationship::Ally)
{
if (!FStringNull(m_iszUnUse))
Expand Down

0 comments on commit 327f068

Please sign in to comment.