Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "smokegrenade_projectile.h"
  8. #include "sendproxy.h"
  9. #include "holiday_gift.h"
  10. #include "cs_player.h"
  11. #include "KeyValues.h"
  12. #include "bot_manager.h"
  13. #include "weapon_csbase.h"
  14. #define CHRISTMAS_MODEL "models/items/cs_gift.mdl"
  15. LINK_ENTITY_TO_CLASS( holiday_gift, CHolidayGift );
  16. PRECACHE_WEAPON_REGISTER( holiday_gift );
  17. //-----------------------------------------------------------------------------
  18. CHolidayGift* CHolidayGift::Create( const Vector &position, const QAngle &angles, const QAngle &eyeAngles, const Vector &velocity, CBaseCombatCharacter *pOwner )
  19. {
  20. CHolidayGift *pGift = (CHolidayGift*)CBaseEntity::Create( "holiday_gift", position, angles, pOwner );
  21. if ( pGift )
  22. {
  23. pGift->AddSpawnFlags( SF_NORESPAWN );
  24. Vector vecRight, vecUp;
  25. AngleVectors( eyeAngles, NULL, &vecRight, &vecUp );
  26. // Calculate the initial impulse on the gift.
  27. Vector vecImpulse( 0.0f, 0.0f, 0.0f );
  28. vecImpulse += vecUp * random->RandomFloat( 0, 0.25 );
  29. vecImpulse += vecRight * random->RandomFloat( -0.25, 0.25 );
  30. VectorNormalize( vecImpulse );
  31. vecImpulse *= random->RandomFloat( 100.0, 150.0 );
  32. vecImpulse += velocity;
  33. // Cap the impulse.
  34. float flSpeed = vecImpulse.Length();
  35. if ( flSpeed > 300.0 )
  36. {
  37. VectorScale( vecImpulse, 300.0 / flSpeed, vecImpulse );
  38. }
  39. pGift->SetMoveType( MOVETYPE_FLYGRAVITY );
  40. pGift->SetAbsVelocity( vecImpulse * 2.f + Vector(0,0,200) );
  41. pGift->SetAbsAngles( QAngle(0,0,0) );
  42. pGift->UseClientSideAnimation();
  43. pGift->ResetSequence( pGift->LookupSequence("idle") );
  44. pGift->EmitSound( "Christmas.GiftDrop" );
  45. pGift->ActivateWhenAtRest();
  46. }
  47. return pGift;
  48. }
  49. //-----------------------------------------------------------------------------
  50. void CHolidayGift::Precache()
  51. {
  52. BaseClass::Precache();
  53. PrecacheModel( CHRISTMAS_MODEL );
  54. PrecacheScriptSound( "Christmas.GiftDrop" );
  55. PrecacheScriptSound( "Christmas.GiftPickup" );
  56. }
  57. //-----------------------------------------------------------------------------
  58. void CHolidayGift::Spawn( void )
  59. {
  60. BaseClass::Spawn();
  61. SetModel( CHRISTMAS_MODEL );
  62. // Die in 30 seconds
  63. SetContextThink( &CBaseEntity::SUB_Remove, gpGlobals->curtime + 30, "DIE_THINK" );
  64. SetContextThink( &CHolidayGift::DropSoundThink, gpGlobals->curtime + 0.2f, "SOUND_THINK" );
  65. }
  66. //-----------------------------------------------------------------------------
  67. void CHolidayGift::DropSoundThink( void )
  68. {
  69. EmitSound( "Christmas.GiftDrop" );
  70. }
  71. //-----------------------------------------------------------------------------
  72. bool CHolidayGift::MyTouch( CBasePlayer *pPlayer )
  73. {
  74. if( !pPlayer )
  75. return false;
  76. if( !pPlayer->IsAlive() )
  77. return false;
  78. if ( pPlayer->IsBot() )
  79. return false;
  80. if ( ( pPlayer->GetTeamNumber() != TEAM_CT ) && ( pPlayer->GetTeamNumber() != TEAM_TERRORIST ) )
  81. return false;
  82. // Send a message for the achievement tracking.
  83. IGameEvent *event = gameeventmanager->CreateEvent( "christmas_gift_grab" );
  84. if ( event )
  85. {
  86. event->SetInt( "userid", pPlayer->GetUserID() );
  87. gameeventmanager->FireEvent( event );
  88. }
  89. pPlayer->EmitSound( "Christmas.GiftPickup" );
  90. return true;
  91. }
  92. //-----------------------------------------------------------------------------
  93. void CHolidayGift::ItemTouch( CBaseEntity *pOther )
  94. {
  95. if ( pOther->IsWorld() )
  96. {
  97. Vector absVel = GetAbsVelocity();
  98. SetAbsVelocity( Vector( 0,0,absVel.z ) );
  99. return;
  100. }
  101. BaseClass::ItemTouch( pOther );
  102. }