winevent.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/winevent.cpp $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 2/07/02 9:43a $*
  29. * *
  30. * $Revision:: 25 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "winevent.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "wwaudio.h"
  40. #include "gamemode.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 "realcrc.h"
  48. #include "apppackettypes.h"
  49. #include "specialbuilds.h"
  50. #include "modpackagemgr.h"
  51. DECLARE_NETWORKOBJECT_FACTORY(cWinEvent, NETCLASSID_WIN);
  52. //-----------------------------------------------------------------------------
  53. cWinEvent::cWinEvent(void)
  54. {
  55. Winner = PLAYER_ID_UNKNOWN;
  56. Loser = PLAYER_ID_UNKNOWN;
  57. IsMapCycleOver = false;
  58. HostedGameNumber = -1;
  59. Set_App_Packet_Type(APPPACKETTYPE_WINEVENT);
  60. }
  61. //-----------------------------------------------------------------------------
  62. void
  63. cWinEvent::Init(int winner, int loser, bool is_cycle_over)
  64. {
  65. WWASSERT(cNetwork::I_Am_Server());
  66. Winner = winner;
  67. Loser = loser;
  68. IsMapCycleOver = is_cycle_over;
  69. WWASSERT(The_Game() != NULL);
  70. HostedGameNumber = The_Game()->Get_Hosted_Game_Number();
  71. Set_Object_Dirty_Bit(BIT_CREATION, true);
  72. if (cNetwork::I_Am_Client())
  73. {
  74. Act();
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. void
  79. cWinEvent::Act(void)
  80. {
  81. if (IS_MISSION || !GameModeManager::Find("Combat")->Is_Active()) {
  82. return;
  83. }
  84. WWASSERT(cNetwork::I_Am_Client());
  85. WWAudioClass::Get_Instance()->Create_Instant_Sound("Game_Over", Matrix3D(1));
  86. WideStringClass win_text;
  87. WWASSERT(PTheGameData != NULL);
  88. //if (The_Game()->Is_Team_Game()) {
  89. WideStringClass champ_text;
  90. champ_text.Format(
  91. L"%s %s",
  92. The_Game()->Get_Team_Word(),
  93. cTeamManager::Get_Team_Name(Winner));
  94. win_text.Format(
  95. L"%s %s",
  96. champ_text,
  97. TRANSLATION(IDS_MP_WIN_FORMATTING));
  98. /*
  99. } else {
  100. if (Loser == PLAYER_ID_UNKNOWN) {
  101. win_text.Format(
  102. L"%s %s",
  103. cPlayerManager::Get_Player_Name(Winner),
  104. TRANSLATION(IDS_MP_WIN_FORMATTING));
  105. } else {
  106. win_text.Format(
  107. L"%s %s %s",
  108. cPlayerManager::Get_Player_Name(Winner),
  109. TRANSLATION(IDS_MP_DEFEATS),
  110. cPlayerManager::Get_Player_Name(Loser));
  111. }
  112. }
  113. */
  114. cGameData::Set_Win_Text(win_text);
  115. //
  116. // Let the game know if the map cycle is over
  117. //
  118. if (The_Game () != NULL) {
  119. The_Game ()->Set_Is_Map_Cycle_Over (IsMapCycleOver);
  120. }
  121. Set_Delete_Pending();
  122. }
  123. //-----------------------------------------------------------------------------
  124. void
  125. cWinEvent::Export_Creation(BitStreamClass & packet)
  126. {
  127. WWASSERT(cNetwork::I_Am_Server());
  128. WWASSERT(The_Game() != NULL);
  129. cNetEvent::Export_Creation(packet);
  130. packet.Add(Winner);
  131. packet.Add(Loser);
  132. packet.Add(HostedGameNumber);
  133. packet.Add(IsMapCycleOver);
  134. packet.Add((int) The_Game()->Get_Win_Type());
  135. packet.Add(The_Game()->Get_Game_Duration_S());
  136. packet.Add_Wide_Terminated_String(The_Game()->Get_Mvp_Name(), true);
  137. packet.Add(The_Game()->Get_Mvp_Count());
  138. #ifndef MULTIPLAYERDEMO
  139. packet.Add(::CRC_Stringi(The_Game()->Get_Mod_Name()));
  140. packet.Add(::CRC_Stringi(The_Game()->Get_Map_Name()));
  141. #endif // MULTIPLAYERDEMO
  142. Set_Delete_Pending();
  143. }
  144. //-----------------------------------------------------------------------------
  145. void
  146. cWinEvent::Import_Creation(BitStreamClass & packet)
  147. {
  148. cNetEvent::Import_Creation(packet);
  149. WWASSERT(cNetwork::I_Am_Only_Client());
  150. int win_type = 0;
  151. DWORD duration_s = 0;
  152. WideStringClass mvp_name;
  153. int mvp_count = 0;
  154. packet.Get(Winner);
  155. packet.Get(Loser);
  156. packet.Get(HostedGameNumber);
  157. packet.Get(IsMapCycleOver);
  158. packet.Get(win_type);
  159. packet.Get(duration_s);
  160. packet.Get_Wide_Terminated_String(mvp_name.Get_Buffer(256), 256, true);
  161. packet.Get(mvp_count);
  162. //TSS092601
  163. WWASSERT(The_Game() != NULL);
  164. //
  165. // This is just causing no end of trouble so I'm going to simplify it.
  166. // The host has no business sending win events to people not in the same game anyway. ST - 1/18/2002 2:33PM
  167. //
  168. #pragma message("(TSS) Could this be causing problems?")
  169. The_Game()->Set_Hosted_Game_Number(HostedGameNumber + 1);
  170. #if (0)
  171. if (HostedGameNumber != The_Game()->Get_Hosted_Game_Number())
  172. {
  173. return;
  174. }
  175. else
  176. {
  177. The_Game()->Increment_Hosted_Game_Number();//TSS092901
  178. }
  179. #endif //(0)
  180. The_Game()->Set_Winner_ID(Winner);
  181. The_Game()->Set_Win_Type((cGameData::WinTypeEnum) win_type);
  182. The_Game()->Set_Game_Duration_S(duration_s);
  183. The_Game()->Set_Mvp_Name(mvp_name);
  184. The_Game()->Set_Mvp_Count(mvp_count);
  185. #ifndef MULTIPLAYERDEMO
  186. ULONG mod_name_crc = packet.Get(mod_name_crc);
  187. ULONG map_name_crc = packet.Get(map_name_crc);
  188. //
  189. // Try to find the map from its CRC
  190. //
  191. StringClass mod_name(0, true);
  192. StringClass map_name(0, true);
  193. ModPackageMgrClass::Get_Mod_Map_Name_From_CRC (mod_name_crc, map_name_crc, &mod_name, &map_name);
  194. The_Game()->Set_Mod_Name(mod_name);
  195. The_Game()->Set_Map_Name(map_name);
  196. #endif // MULTIPLAYERDEMO
  197. The_Game()->Begin_Intermission();
  198. Act();
  199. }