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.

123 lines
3.4 KiB

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