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.

147 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "items.h"
  10. #include "cs_player.h"
  11. #include "weapon_csbase.h"
  12. #include "cs_ammodef.h"
  13. //-----------------------------------------------------------------------------
  14. class CItemAmmo : public CItem
  15. {
  16. public:
  17. DECLARE_CLASS( CItemAmmo, CItem );
  18. bool MyTouch( CBasePlayer *pBasePlayer )
  19. {
  20. CCSPlayer *pPlayer = dynamic_cast< CCSPlayer* >( pBasePlayer );
  21. if ( !pPlayer )
  22. {
  23. Assert( false );
  24. return false;
  25. }
  26. int ammoIndex = GetCSAmmoDef()->Index( GetAmmoName() );
  27. if ( ammoIndex < 0 )
  28. {
  29. Assert( false );
  30. return false;
  31. }
  32. pPlayer->GiveAmmo( GetCSAmmoDef()->GetBuySize( ammoIndex ), ammoIndex );
  33. return true;
  34. }
  35. virtual const char * GetAmmoName( void ) const { return NULL; }
  36. };
  37. //-----------------------------------------------------------------------------
  38. class CItemAmmo50AE : public CItemAmmo
  39. {
  40. public:
  41. DECLARE_CLASS( CItemAmmo50AE, CItemAmmo );
  42. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_50AE; }
  43. };
  44. LINK_ENTITY_TO_CLASS( ammo_50ae, CItemAmmo50AE );
  45. //-----------------------------------------------------------------------------
  46. class CItemAmmo762MM : public CItemAmmo
  47. {
  48. public:
  49. DECLARE_CLASS( CItemAmmo762MM, CItemAmmo );
  50. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_762MM; }
  51. };
  52. LINK_ENTITY_TO_CLASS( ammo_762mm, CItemAmmo762MM );
  53. //-----------------------------------------------------------------------------
  54. class CItemAmmo556MM : public CItemAmmo
  55. {
  56. public:
  57. DECLARE_CLASS( CItemAmmo556MM, CItemAmmo );
  58. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_556MM; }
  59. };
  60. LINK_ENTITY_TO_CLASS( ammo_556mm, CItemAmmo556MM );
  61. //-----------------------------------------------------------------------------
  62. class CItemAmmo556MM_BOX : public CItemAmmo
  63. {
  64. public:
  65. DECLARE_CLASS( CItemAmmo556MM_BOX, CItemAmmo );
  66. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_556MM_BOX; }
  67. };
  68. LINK_ENTITY_TO_CLASS( ammo_556mm_box, CItemAmmo556MM_BOX );
  69. //-----------------------------------------------------------------------------
  70. class CItemAmmo338MAG : public CItemAmmo
  71. {
  72. public:
  73. DECLARE_CLASS( CItemAmmo338MAG, CItemAmmo );
  74. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_338MAG; }
  75. };
  76. LINK_ENTITY_TO_CLASS( ammo_338mag, CItemAmmo338MAG );
  77. //-----------------------------------------------------------------------------
  78. class CItemAmmo9MM : public CItemAmmo
  79. {
  80. public:
  81. DECLARE_CLASS( CItemAmmo9MM, CItemAmmo );
  82. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_9MM; }
  83. };
  84. LINK_ENTITY_TO_CLASS( ammo_9mm, CItemAmmo9MM );
  85. //-----------------------------------------------------------------------------
  86. class CItemAmmoBuckshot : public CItemAmmo
  87. {
  88. public:
  89. DECLARE_CLASS( CItemAmmoBuckshot, CItemAmmo );
  90. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_BUCKSHOT; }
  91. };
  92. LINK_ENTITY_TO_CLASS( ammo_buckshot, CItemAmmoBuckshot );
  93. //-----------------------------------------------------------------------------
  94. class CItemAmmo45ACP : public CItemAmmo
  95. {
  96. public:
  97. DECLARE_CLASS( CItemAmmo45ACP, CItemAmmo );
  98. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_45ACP; }
  99. };
  100. LINK_ENTITY_TO_CLASS( ammo_45acp, CItemAmmo45ACP );
  101. //-----------------------------------------------------------------------------
  102. class CItemAmmo357SIG : public CItemAmmo
  103. {
  104. public:
  105. DECLARE_CLASS( CItemAmmo357SIG, CItemAmmo );
  106. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_357SIG; }
  107. };
  108. LINK_ENTITY_TO_CLASS( ammo_357sig, CItemAmmo357SIG );
  109. //-----------------------------------------------------------------------------
  110. class CItemAmmo57MM : public CItemAmmo
  111. {
  112. public:
  113. DECLARE_CLASS( CItemAmmo57MM, CItemAmmo );
  114. virtual const char * GetAmmoName( void ) const { return BULLET_PLAYER_57MM; }
  115. };
  116. LINK_ENTITY_TO_CLASS( ammo_57mm, CItemAmmo57MM );
  117. //-----------------------------------------------------------------------------