AnnounceEvent.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. *
  20. * FILE
  21. * $Archive: /Commando/Code/Commando/AnnounceEvent.cpp $
  22. *
  23. * DESCRIPTION
  24. * Client announcement
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 9 $
  32. * $Modtime: 1/12/02 9:33p $
  33. *
  34. ******************************************************************************/
  35. #include "announceevent.h"
  36. #include "networkobjectfactory.h"
  37. #include "apppackettypes.h"
  38. #include "networkobjectmgr.h"
  39. #include "cnetwork.h"
  40. #include "gamemode.h"
  41. #include "playertype.h"
  42. #include "translateobj.h"
  43. #include "translatedb.h"
  44. #include "wwaudio.h"
  45. #include "messagewindow.h"
  46. #include <wwlib\widestring.h>
  47. #include "cncmodesettings.h"
  48. #include "floodprotectionmgr.h"
  49. DECLARE_NETWORKOBJECT_FACTORY(CSAnnouncement, NETCLASSID_CSANNOUNCEMENT);
  50. CSAnnouncement::CSAnnouncement(void) :
  51. mFromID(-1),
  52. mToID(-1),
  53. mAnnouncementID(0),
  54. mRadioCmdID(-1),
  55. mType(ANNOUNCEMENT_PUBLIC)
  56. {
  57. Set_App_Packet_Type(APPPACKETTYPE_CSANNOUNCEMENT);
  58. }
  59. CSAnnouncement::~CSAnnouncement()
  60. {
  61. }
  62. void CSAnnouncement::Init(int to_id, int announcementID, AnnouncementEnum type, int radio_cmd_id)
  63. {
  64. WWASSERT(cNetwork::I_Am_Client());
  65. mToID = to_id;
  66. mFromID = cNetwork::Get_My_Id();
  67. mAnnouncementID = announcementID;
  68. mRadioCmdID = radio_cmd_id;
  69. mType = type;
  70. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  71. //
  72. // Is this user "flooding" the server with text?
  73. //
  74. if (FloodProtectionMgrClass::Detect_Flooding (L"") == false)
  75. {
  76. if (cNetwork::I_Am_Server())
  77. {
  78. Act();
  79. }
  80. else
  81. {
  82. Set_Object_Dirty_Bit(0, BIT_CREATION, true);
  83. }
  84. }
  85. else
  86. {
  87. //
  88. // Flooding detected -- don't send the message
  89. //
  90. Set_Delete_Pending();
  91. }
  92. }
  93. void CSAnnouncement::Act(void)
  94. {
  95. WWASSERT(cNetwork::I_Am_Server());
  96. if (GameModeManager::Find("Combat")->Is_Active())
  97. {
  98. SCAnnouncement* announce = new SCAnnouncement;
  99. announce->Init(mToID, mFromID, mAnnouncementID, mType, mRadioCmdID);
  100. }
  101. Set_Delete_Pending();
  102. }
  103. void CSAnnouncement::Export_Creation(BitStreamClass& packet)
  104. {
  105. WWASSERT(cNetwork::I_Am_Only_Client());
  106. cNetEvent::Export_Creation(packet);
  107. packet.Add(mToID);
  108. packet.Add(mFromID);
  109. packet.Add(mAnnouncementID);
  110. packet.Add(mRadioCmdID);
  111. packet.Add((BYTE)mType);
  112. Set_Delete_Pending();
  113. }
  114. void CSAnnouncement::Import_Creation(BitStreamClass& packet)
  115. {
  116. WWASSERT(cNetwork::I_Am_Server());
  117. cNetEvent::Import_Creation(packet);
  118. packet.Get(mToID);
  119. packet.Get(mFromID);
  120. packet.Get(mAnnouncementID);
  121. packet.Get(mRadioCmdID);
  122. BYTE type = 0;
  123. packet.Get(type);
  124. mType = (AnnouncementEnum)type;
  125. Act();
  126. }
  127. //-----------------------------------------------------------------------------
  128. DECLARE_NETWORKOBJECT_FACTORY(SCAnnouncement, NETCLASSID_SCANNOUNCEMENT);
  129. SCAnnouncement::SCAnnouncement(void) :
  130. mToID(-1),
  131. mFromID(-1),
  132. mAnnouncementID(0),
  133. mRadioCmdID(-1),
  134. mType(ANNOUNCEMENT_PUBLIC)
  135. {
  136. Set_App_Packet_Type(APPPACKETTYPE_SCANNOUNCEMENT);
  137. }
  138. SCAnnouncement::~SCAnnouncement()
  139. {
  140. }
  141. void SCAnnouncement::Init(int to_id, int from_id, int announcementID, AnnouncementEnum type, int radio_cmd_id)
  142. {
  143. WWASSERT(cNetwork::I_Am_Server());
  144. mToID = to_id;
  145. mFromID = from_id;
  146. mAnnouncementID = announcementID;
  147. mRadioCmdID = radio_cmd_id;
  148. mType = type;
  149. switch (type)
  150. {
  151. case ANNOUNCEMENT_PUBLIC:
  152. Set_Object_Dirty_Bit(BIT_CREATION, true);
  153. break;
  154. case ANNOUNCEMENT_TEAM:
  155. if (mToID >= 0)
  156. {
  157. Set_Dirty_Bit_For_Team(BIT_CREATION, mToID);
  158. }
  159. break;
  160. case ANNOUNCEMENT_PRIVATE:
  161. if (mToID >= 0)
  162. {
  163. Set_Object_Dirty_Bit(mToID, BIT_CREATION, true);
  164. }
  165. break;
  166. default:
  167. break;
  168. }
  169. // Explicitly show the message on the server if he is among the recipients.
  170. if (cNetwork::I_Am_Client() && Is_Client_Dirty(cNetwork::Get_My_Id()))
  171. {
  172. Act();
  173. }
  174. }
  175. void SCAnnouncement::Set_Dirty_Bit_For_Team(DIRTY_BIT bit, int team)
  176. {
  177. WWASSERT(team == PLAYERTYPE_NOD || team == PLAYERTYPE_GDI);
  178. SList<cPlayer>* playerList = cPlayerManager::Get_Player_Object_List();
  179. if (playerList)
  180. {
  181. SLNode<cPlayer>* playerNode = playerList->Head();
  182. while (playerNode)
  183. {
  184. cPlayer* player = playerNode->Data();
  185. if (player && player->Is_Active() && (player->Get_Player_Type() == team))
  186. {
  187. Set_Object_Dirty_Bit(player->Get_Id(), bit, true);
  188. }
  189. playerNode = playerNode->Next();
  190. }
  191. }
  192. }
  193. void SCAnnouncement::Act(void)
  194. {
  195. if (mAnnouncementID > 0)
  196. {
  197. // Lookup the translation object from the strings database
  198. TDBObjClass* translateObj = TranslateDBClass::Find_Object(mAnnouncementID);
  199. cPlayer* sender = cPlayerManager::Find_Player(mFromID);
  200. //
  201. // Display the emot icon as ncessary
  202. //
  203. if (sender != NULL && mRadioCmdID != -1)
  204. {
  205. //
  206. // Dig the soldier game object out from the player data
  207. //
  208. SmartGameObj *game_obj = sender->Get_GameObj();
  209. if (game_obj != NULL && game_obj->As_SoldierGameObj () != NULL)
  210. {
  211. CNCModeSettingsDef* cncDef = CNCModeSettingsDef::Get_Instance();
  212. if (cncDef != NULL)
  213. {
  214. //
  215. // Display the emot icon
  216. //
  217. const float EMOT_ICON_DURATION = 2.0F;
  218. const char *emot_icon_name = cncDef->Get_Radio_Command_Emot_Icon (mRadioCmdID);
  219. game_obj->As_SoldierGameObj ()->Set_Emot_Icon (emot_icon_name, EMOT_ICON_DURATION);
  220. }
  221. }
  222. }
  223. if (translateObj)
  224. {
  225. // Display the text on the screen
  226. const WCHAR* string = translateObj->Get_String();
  227. if (string)
  228. {
  229. if (sender)
  230. {
  231. WideStringClass message(0, true);
  232. message.Format(L"%s: %s", sender->Get_Name(), string);
  233. CombatManager::Get_Message_Window()->Add_Message(message, sender->Get_Color());
  234. }
  235. else
  236. {
  237. CombatManager::Get_Message_Window()->Add_Message(string, Vector3(1,1,1));
  238. }
  239. }
  240. // Play the sound effect
  241. int soundID = (int)translateObj->Get_Sound_ID();
  242. if (soundID > 0)
  243. {
  244. WWAudioClass::Get_Instance()->Create_Instant_Sound(soundID, Matrix3D(1));
  245. }
  246. }
  247. }
  248. Set_Delete_Pending();
  249. }
  250. //-----------------------------------------------------------------------------
  251. void SCAnnouncement::Export_Creation(BitStreamClass& packet)
  252. {
  253. cNetEvent::Export_Creation(packet);
  254. packet.Add(mToID);
  255. packet.Add(mFromID);
  256. packet.Add(mAnnouncementID);
  257. packet.Add(mRadioCmdID);
  258. packet.Add((BYTE)mType);
  259. Set_Delete_Pending();
  260. }
  261. //-----------------------------------------------------------------------------
  262. void SCAnnouncement::Import_Creation(BitStreamClass& packet)
  263. {
  264. cNetEvent::Import_Creation(packet);
  265. WWASSERT(cNetwork::I_Am_Only_Client());
  266. packet.Get(mToID);
  267. packet.Get(mFromID);
  268. packet.Get(mAnnouncementID);
  269. packet.Add(mRadioCmdID);
  270. BYTE type = 0;
  271. packet.Get(type);
  272. mType = (AnnouncementEnum)type;
  273. Act();
  274. }