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.

185 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // NVNT haptic manager for tf2
  3. #include "cbase.h"
  4. #include "c_tf_haptics.h"
  5. #include "c_tf_player.h"
  6. // memdbgon must be the last include file in a .cpp file!!!
  7. #include "tier0/memdbgon.h"
  8. // for full cloak effect
  9. extern ConVar tf_teammate_max_invis;
  10. C_TFHaptics::C_TFHaptics()
  11. {
  12. memset(this, 0, sizeof(C_TFHaptics));
  13. }
  14. void C_TFHaptics::Revert() {
  15. if ( haptics )
  16. {
  17. if(wasBeingHealed)
  18. {
  19. haptics->ProcessHapticEvent(2,"Game","being_healed_stop");
  20. }
  21. if(wasHealing)
  22. {
  23. haptics->ProcessHapticEvent(2,"Game","healing_stop");
  24. }
  25. if(wasUber)
  26. {
  27. haptics->ProcessHapticEvent(2, "Game", "uber_stop");
  28. }
  29. if(wasFullyCloaked)
  30. {
  31. haptics->ProcessHapticEvent(2, "Game", "cloak_full_stop");
  32. }
  33. if(wasCloaked)
  34. {
  35. haptics->ProcessHapticEvent(2, "Game", "cloak_stop");
  36. }
  37. if(wasBurning)
  38. {
  39. haptics->ProcessHapticEvent(2, "Game", "burning_stop");
  40. }
  41. }
  42. memset(this, 0, sizeof(C_TFHaptics));
  43. if ( haptics )
  44. {
  45. haptics->LocalPlayerReset();
  46. haptics->SetNavigationClass("on_foot");
  47. }
  48. }
  49. void C_TFHaptics::HapticsThink(C_TFPlayer *player)
  50. {
  51. if ( !haptics )
  52. return;
  53. Assert(player!=C_TFPlayer::GetLocalPlayer());
  54. {// being healed check
  55. C_TFPlayer *pHealer = NULL;
  56. float uberCharge = 0.0f;
  57. player->GetHealer(&pHealer,&uberCharge);
  58. if(pHealer)
  59. {
  60. if(!wasBeingHealedMedic && !healingDispenserCount)
  61. isBeingHealed = true;
  62. }
  63. else
  64. {
  65. if(wasBeingHealedMedic && !healingDispenserCount)
  66. isBeingHealed = false;
  67. }
  68. wasBeingHealedMedic = pHealer!=NULL;
  69. if(isBeingHealed&&!wasBeingHealed&&haptics)
  70. haptics->ProcessHapticEvent(2,"Game","being_healed_start");
  71. else if(!isBeingHealed&&wasBeingHealed&&haptics)
  72. haptics->ProcessHapticEvent(2,"Game","being_healed_stop");
  73. wasBeingHealed = isBeingHealed;
  74. }
  75. {// healing check
  76. C_BaseEntity *pHealTarget = player->MedicGetHealTarget();
  77. if(pHealTarget)
  78. {
  79. if(!wasHealing&&haptics)
  80. haptics->ProcessHapticEvent(2,"Game","healing_start");
  81. }
  82. else
  83. {
  84. if(wasHealing&&haptics)
  85. haptics->ProcessHapticEvent(2,"Game","healing_stop");
  86. }
  87. wasHealing = pHealTarget!=NULL;
  88. }
  89. //uber
  90. if(player->m_Shared.InCond( TF_COND_INVULNERABLE ) && !player->m_Shared.InCond( TF_COND_INVULNERABLE_WEARINGOFF ) )
  91. {
  92. if(!wasUber&&haptics)
  93. {
  94. haptics->ProcessHapticEvent(2, "Game", "uber_start");
  95. }
  96. }else{
  97. if(wasUber&&haptics)
  98. {
  99. haptics->ProcessHapticEvent(2, "Game", "uber_stop");
  100. }
  101. }
  102. //burning
  103. if(player->m_Shared.InCond( TF_COND_BURNING ) )
  104. {
  105. if(!wasBurning&&haptics)
  106. {
  107. haptics->ProcessHapticEvent(2, "Game", "burning_start");
  108. wasBurning = true;
  109. }
  110. }else{
  111. if(wasBurning)
  112. {
  113. haptics->ProcessHapticEvent(2, "Game", "burning_stop");
  114. wasBurning = false;
  115. }
  116. }
  117. //cloak
  118. // note: theres some weird stuff going on here.
  119. float cloakLevel = player->GetPercentInvisible();
  120. if(readyForCloak)
  121. {
  122. if(cloakLevel>0.0f)
  123. {
  124. if(!wasCloaked)
  125. {
  126. haptics->ProcessHapticEvent(2, "Game", "cloak_start");
  127. wasCloaked = true;
  128. }
  129. if(!wasFullyCloaked)
  130. {
  131. if(cloakLevel >= tf_teammate_max_invis.GetFloat())
  132. {
  133. haptics->ProcessHapticEvent(2, "Game", "cloak_full_start");
  134. wasFullyCloaked = true;
  135. }
  136. }
  137. else
  138. {
  139. if(cloakLevel < tf_teammate_max_invis.GetFloat())
  140. {
  141. haptics->ProcessHapticEvent(2, "Game", "cloak_full_stop");
  142. wasFullyCloaked = false;
  143. }
  144. }
  145. }else{
  146. if(wasFullyCloaked)
  147. {
  148. haptics->ProcessHapticEvent(2, "Game", "cloak_full_stop");
  149. wasFullyCloaked = false;
  150. }
  151. if(wasCloaked)
  152. {
  153. haptics->ProcessHapticEvent(2, "Game", "cloak_stop");
  154. wasCloaked = false;
  155. }
  156. }
  157. }else{
  158. if(skippedFirstCloak)
  159. {
  160. if(cloakLevel==0.0f)
  161. readyForCloak = true;
  162. }else{
  163. if(cloakLevel!=0.0f)
  164. {
  165. skippedFirstCloak = true;
  166. }
  167. }
  168. }
  169. }
  170. class C_TFHapticsInternal : public C_TFHaptics
  171. {
  172. public:
  173. C_TFHapticsInternal() : C_TFHaptics() {};
  174. };
  175. static C_TFHapticsInternal tfInternalHaptics;
  176. C_TFHaptics &tfHaptics = *((C_TFHaptics*)&tfInternalHaptics);