playerkill.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/playerkill.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 11/09/01 12:31p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "playerkill.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "textdisplay.h"
  40. #include "wwaudio.h"
  41. #include "playermanager.h"
  42. #include "matrix3d.h"
  43. #include "cnetwork.h"
  44. #include "gametype.h"
  45. #include "translatedb.h"
  46. #include "string_ids.h"
  47. #include "apppackettypes.h"
  48. #include "messagewindow.h"
  49. DECLARE_NETWORKOBJECT_FACTORY(cPlayerKill, NETCLASSID_PLAYERKILL);
  50. //-----------------------------------------------------------------------------
  51. cPlayerKill::cPlayerKill(void)
  52. {
  53. KillerId = PLAYER_ID_UNKNOWN;
  54. VictimId = PLAYER_ID_UNKNOWN;
  55. Set_App_Packet_Type(APPPACKETTYPE_PLAYERKILLEVENT);
  56. }
  57. //-----------------------------------------------------------------------------
  58. void
  59. cPlayerKill::Init(int killer_id, int victim_id)
  60. {
  61. WWASSERT(cNetwork::I_Am_Server());
  62. KillerId = killer_id;
  63. VictimId = victim_id;
  64. //
  65. // This skips the local client
  66. //
  67. Set_Object_Dirty_Bit(BIT_CREATION, true);
  68. if (cNetwork::I_Am_Client())
  69. {
  70. Act();
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. void
  75. cPlayerKill::Act(void)
  76. {
  77. if (IS_MISSION ||
  78. GameModeManager::Find("Menu")->Is_Active() ||
  79. !GameModeManager::Find("Combat")->Is_Active()) {
  80. return;
  81. }
  82. WideStringClass killer_name = TRANSLATION(IDS_MP_SOMEBODY);
  83. WideStringClass victim_name = TRANSLATION(IDS_MP_SOMEBODY);
  84. cPlayer * p_killer = NULL;
  85. cPlayer * p_victim = NULL;
  86. if (KillerId != PLAYER_ID_UNKNOWN) {
  87. p_killer = cPlayerManager::Find_Player(KillerId);
  88. if (p_killer != NULL) {
  89. killer_name = p_killer->Get_Name();
  90. }
  91. }
  92. if (VictimId != PLAYER_ID_UNKNOWN) {
  93. p_victim = cPlayerManager::Find_Player(VictimId);
  94. if (p_victim != NULL) {
  95. victim_name = p_victim->Get_Name();
  96. }
  97. }
  98. /*
  99. if (cPlayerManager::Is_Kill_Treasonous(p_killer, p_victim)) {
  100. WideStringClass formatted_text;
  101. formatted_text.Format(
  102. L"%s %s %s\n",
  103. killer_name,
  104. TRANSLATION(IDS_MP_TREASON_PHRASE),
  105. victim_name);
  106. WWASSERT(Get_Text_Display() != NULL);
  107. Get_Text_Display()->Print_Informational(formatted_text);
  108. } else {
  109. WideStringClass formatted_text;
  110. formatted_text.Format(
  111. L"%s %s %s\n",
  112. killer_name,
  113. TRANSLATION(IDS_MP_DEFAULT_KILL_PHRASE),
  114. victim_name);
  115. WWASSERT(Get_Text_Display() != NULL);
  116. Get_Text_Display()->Print_Informational(formatted_text);
  117. if (cNetwork::I_Am_Client() && KillerId == cNetwork::Get_My_Id() &&
  118. KillerId != VictimId) {
  119. WWAudioClass::Get_Instance()->Create_Instant_Sound("My_Kill", Matrix3D(1));
  120. }
  121. }
  122. */
  123. if (p_killer != NULL && p_victim != NULL) {
  124. WWASSERT(CombatManager::Get_Message_Window() != NULL);
  125. //
  126. // Determine which message to display
  127. //
  128. WideStringClass message;
  129. if (cPlayerManager::Is_Kill_Treasonous(p_killer, p_victim)) {
  130. message.Format(TRANSLATION(IDS_MP_TREASON_PHRASE));
  131. } else {
  132. message.Format(TRANSLATION(IDS_MP_DEFAULT_KILL_PHRASE));
  133. if (cNetwork::I_Am_Client() && KillerId == cNetwork::Get_My_Id() &&
  134. KillerId != VictimId) {
  135. WWAudioClass::Get_Instance()->Create_Instant_Sound("My_Kill", Matrix3D(1));
  136. }
  137. }
  138. //
  139. // Display the message...
  140. //
  141. WideStringClass formatted_text;
  142. formatted_text.Format(L"%s %s %s\n", killer_name.Peek_Buffer (), message.Peek_Buffer (), victim_name.Peek_Buffer ());
  143. CombatManager::Get_Message_Window ()->Add_Message (formatted_text, p_killer->Get_Color ());
  144. }
  145. Set_Delete_Pending();
  146. }
  147. //-----------------------------------------------------------------------------
  148. void
  149. cPlayerKill::Export_Creation(BitStreamClass & packet)
  150. {
  151. cNetEvent::Export_Creation(packet);
  152. packet.Add(KillerId);
  153. packet.Add(VictimId);
  154. Set_Delete_Pending();
  155. }
  156. //-----------------------------------------------------------------------------
  157. void
  158. cPlayerKill::Import_Creation(BitStreamClass & packet)
  159. {
  160. cNetEvent::Import_Creation(packet);
  161. WWASSERT(cNetwork::I_Am_Only_Client());
  162. packet.Get(KillerId);
  163. packet.Get(VictimId);
  164. Act();
  165. }