diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/dod/holiday_gift.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/dod/holiday_gift.cpp')
| -rw-r--r-- | game/server/dod/holiday_gift.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/game/server/dod/holiday_gift.cpp b/game/server/dod/holiday_gift.cpp new file mode 100644 index 0000000..d25514f --- /dev/null +++ b/game/server/dod/holiday_gift.cpp @@ -0,0 +1,123 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "cbase.h" +#include "holiday_gift.h" +#include "dod_shareddefs.h" + +#define CHRISTMAS_MODEL "models/items/dod_gift.mdl" + +LINK_ENTITY_TO_CLASS( holiday_gift, CHolidayGift ); +PRECACHE_WEAPON_REGISTER( holiday_gift ); + +//----------------------------------------------------------------------------- +CHolidayGift* CHolidayGift::Create( const Vector &position, const QAngle &angles, const QAngle &eyeAngles, const Vector &velocity, CBaseCombatCharacter *pOwner ) +{ + CHolidayGift *pGift = (CHolidayGift*)CBaseEntity::Create( "holiday_gift", position, angles, pOwner ); + + if ( pGift ) + { + pGift->AddSpawnFlags( SF_NORESPAWN ); + + Vector vecRight, vecUp; + AngleVectors( eyeAngles, NULL, &vecRight, &vecUp ); + + // Calculate the initial impulse on the gift. + Vector vecImpulse( 0.0f, 0.0f, 0.0f ); + vecImpulse += vecUp * random->RandomFloat( 0, 0.25 ); + vecImpulse += vecRight * random->RandomFloat( -0.25, 0.25 ); + VectorNormalize( vecImpulse ); + vecImpulse *= random->RandomFloat( 100.0, 150.0 ); + vecImpulse += velocity; + + // Cap the impulse. + float flSpeed = vecImpulse.Length(); + if ( flSpeed > 300.0 ) + { + VectorScale( vecImpulse, 300.0 / flSpeed, vecImpulse ); + } + + pGift->SetMoveType( MOVETYPE_FLYGRAVITY ); + pGift->SetAbsVelocity( vecImpulse * 2.f + Vector(0,0,200) ); + pGift->SetAbsAngles( QAngle(0,0,0) ); + pGift->UseClientSideAnimation(); + pGift->ResetSequence( pGift->LookupSequence("idle") ); + + pGift->EmitSound( "Christmas.GiftDrop" ); + + pGift->ActivateWhenAtRest(); + } + + return pGift; +} + +//----------------------------------------------------------------------------- +void CHolidayGift::Precache() +{ + BaseClass::Precache(); + + PrecacheModel( CHRISTMAS_MODEL ); + PrecacheScriptSound( "Christmas.GiftDrop" ); + PrecacheScriptSound( "Christmas.GiftPickup" ); +} + +//----------------------------------------------------------------------------- +void CHolidayGift::Spawn( void ) +{ + BaseClass::Spawn(); + + SetModel( CHRISTMAS_MODEL ); + + // Die in 30 seconds + SetContextThink( &CBaseEntity::SUB_Remove, gpGlobals->curtime + 30, "DIE_THINK" ); + SetContextThink( &CHolidayGift::DropSoundThink, gpGlobals->curtime + 0.2f, "SOUND_THINK" ); +} + +//----------------------------------------------------------------------------- +void CHolidayGift::DropSoundThink( void ) +{ + EmitSound( "Christmas.GiftDrop" ); +} + +//----------------------------------------------------------------------------- +bool CHolidayGift::MyTouch( CBasePlayer *pPlayer ) +{ + if( !pPlayer ) + return false; + + if( !pPlayer->IsAlive() ) + return false; + + if ( pPlayer->IsBot() ) + return false; + + if ( ( pPlayer->GetTeamNumber() != TEAM_ALLIES ) && ( pPlayer->GetTeamNumber() != TEAM_AXIS ) ) + return false; + + // Send a message for the achievement tracking. + IGameEvent *event = gameeventmanager->CreateEvent( "christmas_gift_grab" ); + if ( event ) + { + event->SetInt( "userid", pPlayer->GetUserID() ); + gameeventmanager->FireEvent( event ); + } + pPlayer->EmitSound( "Christmas.GiftPickup" ); + + return true; +} + +//----------------------------------------------------------------------------- +void CHolidayGift::ItemTouch( CBaseEntity *pOther ) +{ + if ( pOther->IsWorld() ) + { + Vector absVel = GetAbsVelocity(); + SetAbsVelocity( Vector( 0,0,absVel.z ) ); + return; + } + + BaseClass::ItemTouch( pOther ); +} |