Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make husk code species-agnostic + Add VScript functionality #235

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions sp/src/game/server/ez2/npc_husk_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ extern ConVar sk_husk_common_infight_time;
DEFINE_OUTPUT(m_OnAggressionSuspicious, "OnAggressionSuspicious"), \
DEFINE_OUTPUT(m_OnAggressionAngry, "OnAggressionAngry"), \

#define DEFINE_BASE_HUSK_SCRIPTDESC() \
DEFINE_SCRIPTFUNC_NAMED( ScriptGetHuskAggressionLevel, "GetHuskAggressionLevel", "Get the husk's aggression level." ) \
DEFINE_SCRIPTFUNC_NAMED( ScriptGetHuskCognitionFlags, "GetHuskCognitionFlags", "Get the husk's aggression flags." ) \

#define DEFINE_BASE_HUSK_SENDPROPS() \
SendPropInt( SENDINFO( m_nHuskAggressionLevel ) ), \
SendPropInt( SENDINFO( m_nHuskCognitionFlags ) ), \
Expand Down Expand Up @@ -154,6 +158,7 @@ class CAI_BaseHusk : public BASE_NPC, public CAI_HuskSink

// From CAI_HuskSink
int GetHuskAggressionLevel() override { return this->m_nHuskAggressionLevel; }
int ScriptGetHuskAggressionLevel() { return this->m_nHuskAggressionLevel; }

void MakeCalm( CBaseEntity *pActivator ) override;
void MakeSuspicious( CBaseEntity *pActivator ) override;
Expand All @@ -169,6 +174,7 @@ class CAI_BaseHusk : public BASE_NPC, public CAI_HuskSink

// From CAI_HuskSink
int GetHuskCognitionFlags() override { return this->m_nHuskCognitionFlags; }
int ScriptGetHuskCognitionFlags() { return this->m_nHuskCognitionFlags; }

void RefreshCognitionFlags();

Expand Down Expand Up @@ -755,13 +761,23 @@ bool CAI_BaseHusk<BASE_NPC>::FCanCheckAttacks( void )
template <class BASE_NPC>
Vector CAI_BaseHusk<BASE_NPC>::GetShootEnemyDir( const Vector &shootOrigin, bool bNoisy )
{
if ( this->HasCognitionFlags( bits_HUSK_COGNITION_BLIND ) && this->GetActiveWeapon() )
if ( this->HasCognitionFlags( bits_HUSK_COGNITION_BLIND ) )
{
// Can't see our enemy, just shoot forwards
Vector vecShootOrigin, vecShootDir;
QAngle angShootDir;
this->GetActiveWeapon()->GetAttachment( this->GetActiveWeapon()->LookupAttachment( "muzzle" ), vecShootOrigin, angShootDir );
AngleVectors( angShootDir, &vecShootDir );
matrix3x4_t attachmentToWorld;
if ( this->GetActiveWeapon() )
{
this->GetActiveWeapon()->GetAttachment( this->GetActiveWeapon()->LookupAttachment( "muzzle" ), attachmentToWorld );
}
else if ( this->CapabilitiesGet() & bits_CAP_INNATE_RANGE_ATTACK1 )
{
this->GetAttachment( this->LookupAttachment( "muzzle" ), attachmentToWorld );
}
else
return BaseClass::GetShootEnemyDir( shootOrigin, bNoisy );

Vector vecShootDir;
MatrixGetColumn( attachmentToWorld, 0, vecShootDir );
return vecShootDir;
}

Expand All @@ -773,11 +789,21 @@ Vector CAI_BaseHusk<BASE_NPC>::GetShootEnemyDir( const Vector &shootOrigin, bool
template <class BASE_NPC>
Vector CAI_BaseHusk<BASE_NPC>::GetActualShootPosition( const Vector &shootOrigin )
{
if ( this->HasCognitionFlags( bits_HUSK_COGNITION_BLIND ) && this->GetActiveWeapon() )
if ( this->HasCognitionFlags( bits_HUSK_COGNITION_BLIND ) )
{
// Can't see our enemy, just shoot forwards
Vector vecShootOrigin, vecShootDir;
this->GetActiveWeapon()->GetAttachment( this->GetActiveWeapon()->LookupAttachment( "muzzle" ), vecShootOrigin, &vecShootDir );
if ( this->GetActiveWeapon() )
{
this->GetActiveWeapon()->GetAttachment( this->GetActiveWeapon()->LookupAttachment( "muzzle" ), vecShootOrigin, &vecShootDir );
}
else if ( this->CapabilitiesGet() & bits_CAP_INNATE_RANGE_ATTACK1 )
{
this->GetAttachment( this->LookupAttachment( "muzzle" ), vecShootOrigin, &vecShootDir );
}
else
return BaseClass::GetActualShootPosition( shootOrigin );

return vecShootOrigin + (vecShootDir * 128.0f);
}

Expand Down
9 changes: 9 additions & 0 deletions sp/src/game/server/ez2/npc_husk_police.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ BEGIN_DATADESC( CNPC_HuskPolice )

END_DATADESC()

//---------------------------------------------------------
// VScript
//---------------------------------------------------------
BEGIN_ENT_SCRIPTDESC( CNPC_HuskPolice, CAI_BaseActor, "Husk metrocop." )

DEFINE_BASE_HUSK_SCRIPTDESC()

END_SCRIPTDESC()

//---------------------------------------------------------
// Custom Client entity
//---------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions sp/src/game/server/ez2/npc_husk_police.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//=============================================================================//

#ifndef NPC_HUSK_SOLDIER_H
#define NPC_HUSK_SOLDIER_H
#ifndef NPC_HUSK_POLICE_H
#define NPC_HUSK_POLICE_H
#ifdef _WIN32
#pragma once
#endif
Expand All @@ -22,6 +22,7 @@ class CNPC_HuskPolice : public CAI_BaseHusk<CNPC_MetroPolice>
{
DECLARE_CLASS( CNPC_HuskPolice, CAI_BaseHusk<CNPC_MetroPolice> );
DECLARE_DATADESC();
DECLARE_ENT_SCRIPTDESC();
DECLARE_SERVERCLASS();

public:
Expand All @@ -43,6 +44,8 @@ class CNPC_HuskPolice : public CAI_BaseHusk<CNPC_MetroPolice>
int SelectAlertSchedule( void );
int SelectCombatSchedule( void );

bool HasHumanGibs( void ) { return true; }

WeaponProficiency_t CalcWeaponProficiency( CBaseCombatWeapon *pWeapon );

IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nHuskAggressionLevel );
Expand All @@ -64,4 +67,4 @@ class CNPC_HuskPolice : public CAI_BaseHusk<CNPC_MetroPolice>
};
};

#endif // NPC_HUSK_SOLDIER_H
#endif // NPC_HUSK_POLICE_H
9 changes: 9 additions & 0 deletions sp/src/game/server/ez2/npc_husk_soldier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ BEGIN_DATADESC( CNPC_HuskSoldier )

END_DATADESC()

//---------------------------------------------------------
// VScript
//---------------------------------------------------------
BEGIN_ENT_SCRIPTDESC( CNPC_HuskSoldier, CAI_BaseActor, "Husk Combine soldier." )

DEFINE_BASE_HUSK_SCRIPTDESC()

END_SCRIPTDESC()

//---------------------------------------------------------
// Custom Client entity
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions sp/src/game/server/ez2/npc_husk_soldier.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CNPC_HuskSoldier : public CAI_BaseHusk<CNPC_Combine>
{
DECLARE_CLASS( CNPC_HuskSoldier, CAI_BaseHusk<CNPC_Combine> );
DECLARE_DATADESC();
DECLARE_ENT_SCRIPTDESC();
DECLARE_SERVERCLASS();

public:
Expand Down Expand Up @@ -91,6 +92,7 @@ class CNPC_HuskSoldier : public CAI_BaseHusk<CNPC_Combine>
bool IsHeavyDamage( const CTakeDamageInfo &info );

bool AllowedToIgnite( void ) { return true; }
bool HasHumanGibs( void ) { return true; }

bool Crouch( void );

Expand Down