Added I/O/KV for custom healthkits, custom battery models, and health/power multipliers

This commit is contained in:
Blixibon 2021-04-21 10:53:48 -05:00
parent d4311587c3
commit f580801a33
6 changed files with 183 additions and 18 deletions

View File

@ -97,6 +97,7 @@
#ifdef MAPBASE
#include "mapbase/matchers.h"
#include "items.h"
#endif
#include "env_debughistory.h"
@ -11509,17 +11510,9 @@ void CAI_BaseNPC::PickupItem( CBaseEntity *pItem )
m_OnItemPickup.Set( pItem, pItem, this );
Assert( pItem != NULL );
if( FClassnameIs( pItem, "item_healthkit" ) )
if( FClassnameIs( pItem, "item_health*" ) ) // item_healthkit, item_healthvial, item_healthkit_custom, etc.
{
if ( TakeHealth( sk_healthkit.GetFloat(), DMG_GENERIC ) )
{
RemoveAllDecals();
UTIL_Remove( pItem );
}
}
else if( FClassnameIs( pItem, "item_healthvial" ) )
{
if ( TakeHealth( sk_healthvial.GetFloat(), DMG_GENERIC ) )
if ( TakeHealth( static_cast<CItem*>(pItem)->GetItemAmount(), DMG_GENERIC ) )
{
RemoveAllDecals();
UTIL_Remove( pItem );

View File

@ -98,11 +98,6 @@ extern bool AIStrongOpt( void );
#ifdef MAPBASE
// Defines Mapbase's extended NPC response system usage.
#define EXPANDED_RESPONSE_SYSTEM_USAGE
// Use the model keyvalue if it is defined
#define DefaultOrCustomModel(defaultModel) GetModelName() != NULL_STRING ? STRING(GetModelName()) : defaultModel
#else
#define DefaultOrCustomModel() defaultModel
#endif
#ifdef EXPANDED_RESPONSE_SYSTEM_USAGE

View File

@ -104,6 +104,13 @@ extern void FireTargets( const char *targetName, CBaseEntity *pActivator, CBaseE
#define MAX_OLD_ENEMIES 4 // how many old enemies to remember
#ifdef MAPBASE
// Use the model keyvalue if it is defined
#define DefaultOrCustomModel(defaultModel) GetModelName() != NULL_STRING ? STRING(GetModelName()) : defaultModel
#else
#define DefaultOrCustomModel() defaultModel
#endif
// used by suit voice to indicate damage sustained and repaired type to player
enum

View File

@ -23,12 +23,12 @@ public:
void Spawn( void )
{
Precache( );
SetModel( "models/items/battery.mdl" );
SetModel( DefaultOrCustomModel( "models/items/battery.mdl" ) );
BaseClass::Spawn( );
}
void Precache( void )
{
PrecacheModel ("models/items/battery.mdl");
PrecacheModel( DefaultOrCustomModel( "models/items/battery.mdl" ) );
PrecacheScriptSound( "ItemBattery.Touch" );
@ -36,10 +36,30 @@ public:
bool MyTouch( CBasePlayer *pPlayer )
{
CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player *>( pPlayer );
#ifdef MAPBASE
return ( pHL2Player && pHL2Player->ApplyBattery( m_flPowerMultiplier ) );
#else
return ( pHL2Player && pHL2Player->ApplyBattery() );
#endif
}
#ifdef MAPBASE
void InputSetPowerMultiplier( inputdata_t &inputdata ) { m_flPowerMultiplier = inputdata.value.Float(); }
float m_flPowerMultiplier = 1.0f;
DECLARE_DATADESC();
#endif
};
LINK_ENTITY_TO_CLASS(item_battery, CItemBattery);
PRECACHE_REGISTER(item_battery);
#ifdef MAPBASE
BEGIN_DATADESC( CItemBattery )
DEFINE_KEYFIELD( m_flPowerMultiplier, FIELD_FLOAT, "PowerMultiplier" ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetPowerMultiplier", InputSetPowerMultiplier ),
END_DATADESC()
#endif

View File

@ -30,11 +30,29 @@ public:
void Spawn( void );
void Precache( void );
bool MyTouch( CBasePlayer *pPlayer );
#ifdef MAPBASE
float GetItemAmount() { return sk_healthkit.GetFloat() * m_flHealthMultiplier; }
void InputSetHealthMultiplier( inputdata_t &inputdata ) { m_flHealthMultiplier = inputdata.value.Float(); }
float m_flHealthMultiplier = 1.0f;
DECLARE_DATADESC();
#endif
};
LINK_ENTITY_TO_CLASS( item_healthkit, CHealthKit );
PRECACHE_REGISTER(item_healthkit);
#ifdef MAPBASE
BEGIN_DATADESC( CHealthKit )
DEFINE_KEYFIELD( m_flHealthMultiplier, FIELD_FLOAT, "HealthMultiplier" ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetHealthMultiplier", InputSetHealthMultiplier ),
END_DATADESC()
#endif
//-----------------------------------------------------------------------------
// Purpose:
@ -66,7 +84,11 @@ void CHealthKit::Precache( void )
//-----------------------------------------------------------------------------
bool CHealthKit::MyTouch( CBasePlayer *pPlayer )
{
#ifdef MAPBASE
if ( pPlayer->TakeHealth( GetItemAmount(), DMG_GENERIC ) )
#else
if ( pPlayer->TakeHealth( sk_healthkit.GetFloat(), DMG_GENERIC ) )
#endif
{
CSingleUserRecipientFilter user( pPlayer );
user.MakeReliable();
@ -119,7 +141,11 @@ public:
bool MyTouch( CBasePlayer *pPlayer )
{
#ifdef MAPBASE
if ( pPlayer->TakeHealth( GetItemAmount(), DMG_GENERIC ) )
#else
if ( pPlayer->TakeHealth( sk_healthvial.GetFloat(), DMG_GENERIC ) )
#endif
{
CSingleUserRecipientFilter user( pPlayer );
user.MakeReliable();
@ -145,11 +171,132 @@ public:
return false;
}
#ifdef MAPBASE
float GetItemAmount() { return sk_healthvial.GetFloat() * m_flHealthMultiplier; }
void InputSetHealthMultiplier( inputdata_t &inputdata ) { m_flHealthMultiplier = inputdata.value.Float(); }
float m_flHealthMultiplier = 1.0f;
DECLARE_DATADESC();
#endif
};
LINK_ENTITY_TO_CLASS( item_healthvial, CHealthVial );
PRECACHE_REGISTER( item_healthvial );
#ifdef MAPBASE
BEGIN_DATADESC( CHealthVial )
DEFINE_KEYFIELD( m_flHealthMultiplier, FIELD_FLOAT, "HealthMultiplier" ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetHealthMultiplier", InputSetHealthMultiplier ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Small health kit. Heals the player when picked up.
//-----------------------------------------------------------------------------
class CHealthKitCustom : public CItem
{
public:
DECLARE_CLASS( CHealthKitCustom, CItem );
CHealthKitCustom();
void Spawn( void );
void Precache( void );
bool MyTouch( CBasePlayer *pPlayer );
float GetItemAmount() { return m_flHealthAmount; }
void InputSetHealthAmount( inputdata_t &inputdata ) { m_flHealthAmount = inputdata.value.Float(); }
float m_flHealthAmount;
string_t m_iszTouchSound;
DECLARE_DATADESC();
};
LINK_ENTITY_TO_CLASS( item_healthkit_custom, CHealthKitCustom );
//PRECACHE_REGISTER(item_healthkit_custom);
#ifdef MAPBASE
BEGIN_DATADESC( CHealthKitCustom )
DEFINE_KEYFIELD( m_flHealthAmount, FIELD_FLOAT, "HealthAmount" ),
DEFINE_KEYFIELD( m_iszTouchSound, FIELD_STRING, "TouchSound" ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "SetHealthAmount", InputSetHealthAmount ),
END_DATADESC()
#endif
CHealthKitCustom::CHealthKitCustom()
{
SetModelName( AllocPooledString( "models/items/healthkit.mdl" ) );
m_flHealthAmount = sk_healthkit.GetFloat();
m_iszTouchSound = AllocPooledString( "HealthKit.Touch" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHealthKitCustom::Spawn( void )
{
Precache();
SetModel( STRING( GetModelName() ) );
BaseClass::Spawn();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHealthKitCustom::Precache( void )
{
PrecacheModel( STRING( GetModelName() ) );
PrecacheScriptSound( STRING( m_iszTouchSound ) );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pPlayer -
// Output :
//-----------------------------------------------------------------------------
bool CHealthKitCustom::MyTouch( CBasePlayer *pPlayer )
{
if ( pPlayer->TakeHealth( GetItemAmount(), DMG_GENERIC ) )
{
CSingleUserRecipientFilter user( pPlayer );
user.MakeReliable();
UserMessageBegin( user, "ItemPickup" );
WRITE_STRING( GetClassname() );
MessageEnd();
CPASAttenuationFilter filter( pPlayer, STRING( m_iszTouchSound ) );
EmitSound( filter, pPlayer->entindex(), STRING( m_iszTouchSound ) );
if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_YES )
{
Respawn();
}
else
{
UTIL_Remove(this);
}
return true;
}
return false;
}
#endif
//-----------------------------------------------------------------------------
// Wall mounted health kit. Heals the player when used.
//-----------------------------------------------------------------------------

View File

@ -90,9 +90,12 @@ public:
#ifdef MAPBASE
// This is in CBaseEntity, but I can't find a use for it anywhere.
// Must not have been fully implemented. Please remove this if it turns out to be something important.
// It may have been originally intended for TF2 or some other game-specific item class. Please remove this if it turns out to be something important.
virtual bool IsCombatItem() { return true; }
// Used to access item_healthkit values, etc. from outside of the class
virtual float GetItemAmount() { return 1.0f; }
void InputEnablePlayerPickup( inputdata_t &inputdata );
void InputDisablePlayerPickup( inputdata_t &inputdata );
void InputEnableNPCPickup( inputdata_t &inputdata );