nethandler.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/nethandler.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 1/08/02 4:01p $*
  29. * *
  30. * $Revision:: 70 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "nethandler.h"
  36. #include "cnetwork.h"
  37. #include "playermanager.h"
  38. #include "playerkill.h"
  39. //-----------------------------------------------------------------------------
  40. bool GameCombatNetworkHandlerClass::Can_Damage(ArmedGameObj * p_armed_damager,
  41. PhysicalGameObj * p_phys_victim)
  42. {
  43. WWASSERT(p_phys_victim != NULL);
  44. WWASSERT(PTheGameData != NULL);
  45. if (!The_Game()->Is_Gameplay_Permitted()) {
  46. return false;
  47. }
  48. SmartGameObj * p_victim_obj = p_phys_victim->As_SmartGameObj();
  49. if (p_victim_obj != NULL && p_victim_obj->Has_Player()) {
  50. cPlayer * p_player = cPlayerManager::Find_Player(p_victim_obj->Get_Control_Owner());
  51. if (p_player && p_player->Invulnerable.Is_True()) {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. //-----------------------------------------------------------------------------
  58. float GameCombatNetworkHandlerClass::Get_Damage_Factor
  59. (
  60. ArmedGameObj * p_armed_damager,
  61. PhysicalGameObj * p_phys_victim
  62. )
  63. {
  64. float factor = 1.0f;
  65. SmartGameObj * p_victim_obj = p_phys_victim->As_SmartGameObj();
  66. if (p_victim_obj != NULL && p_victim_obj->Has_Player()) {
  67. cPlayer * p_player = cPlayerManager::Find_Player(p_victim_obj->Get_Control_Owner());
  68. if (p_player && p_player->Get_Damage_Scale_Factor() < 100) {
  69. factor = p_player->Get_Damage_Scale_Factor() / 100.0f;
  70. }
  71. }
  72. return factor;
  73. }
  74. //-----------------------------------------------------------------------------
  75. void GameCombatNetworkHandlerClass::On_Soldier_Kill(SoldierGameObj * p_soldier, SoldierGameObj * p_victim)
  76. {
  77. WWASSERT(p_soldier != NULL);
  78. WWASSERT(p_victim != NULL);
  79. WWASSERT(cNetwork::I_Am_Server());
  80. int killer_id = p_soldier->Get_Control_Owner();
  81. int victim_id = p_victim->Get_Control_Owner();
  82. if (p_soldier != p_victim) {
  83. cPlayer * p_soldier_player = NULL;
  84. if (p_soldier->Has_Player()) {
  85. p_soldier_player = cPlayerManager::Find_Player(killer_id);
  86. if (p_soldier_player != NULL) {
  87. p_soldier_player->Increment_Kills();
  88. }
  89. }
  90. cPlayer * p_victim_player = NULL;
  91. if (p_victim->Has_Player()) {
  92. p_victim_player = cPlayerManager::Find_Player(victim_id);
  93. }
  94. //
  95. // Send A killed B message (handled independently from scoring changes)
  96. // This presently includes AI killings
  97. //
  98. if (p_soldier_player != NULL && p_victim_player != NULL) {
  99. cPlayerKill * p_player_kill = new cPlayerKill;
  100. p_player_kill->Init(killer_id, victim_id);
  101. }
  102. if (p_soldier->Is_Team_Player()) {
  103. cTeam * p_team = cTeamManager::Find_Team(p_soldier->Get_Player_Type());
  104. WWASSERT(p_team != NULL);
  105. p_team->Increment_Kills();
  106. }
  107. }
  108. }
  109. //-----------------------------------------------------------------------------
  110. void GameCombatNetworkHandlerClass::On_Soldier_Death(SoldierGameObj * p_soldier)
  111. {
  112. WWASSERT(p_soldier != NULL);
  113. WWASSERT(cNetwork::I_Am_Server());
  114. if (p_soldier->Has_Player()) {
  115. cPlayer * p_player = cPlayerManager::Find_Player(p_soldier->Get_Control_Owner());
  116. if (p_player != NULL) {
  117. p_player->Increment_Deaths();
  118. }
  119. }
  120. if (p_soldier->Is_Team_Player()) {
  121. cTeam * p_team = cTeamManager::Find_Team(p_soldier->Get_Player_Type());
  122. WWASSERT(p_team != NULL);
  123. p_team->Increment_Deaths();
  124. }
  125. }
  126. //-----------------------------------------------------------------------------
  127. bool GameCombatNetworkHandlerClass::Is_Gameplay_Permitted(void)
  128. {
  129. WWASSERT(The_Game() != NULL);
  130. return The_Game()->Is_Gameplay_Permitted();
  131. }
  132. /*
  133. if (p_soldier->Has_Player()) {
  134. cPlayer * p_player = cPlayerManager::Find_Player(p_soldier->Get_Control_Owner());
  135. if (p_player != NULL) {
  136. p_player->Increment_Deaths();
  137. if (p_player->Is_Team_Player()) {
  138. cTeam * p_team = cTeamManager::Find_Team(p_player->Get_Player_Type());
  139. if (p_team != NULL) {
  140. p_team->Increment_Deaths();
  141. }
  142. }
  143. }
  144. }
  145. */