sctextobj.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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/sctextobj.cpp $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 9/03/02 1:34a $*
  29. * *
  30. * $Revision:: 26 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "sctextobj.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "textdisplay.h"
  40. #include "wwaudio.h"
  41. #include "colors.h"
  42. #include "playermanager.h"
  43. #include "matrix3d.h"
  44. #include "playertype.h"
  45. #include "cnetwork.h"
  46. #include "translatedb.h"
  47. #include "string_ids.h"
  48. #include "apppackettypes.h"
  49. #include "messagewindow.h"
  50. #include "dlgmessagebox.h"
  51. #include "consolemode.h"
  52. #include "mpsettingsmgr.h"
  53. DECLARE_NETWORKOBJECT_FACTORY(cScTextObj, NETCLASSID_SCTEXTOBJ);
  54. //-----------------------------------------------------------------------------
  55. cScTextObj::cScTextObj(void)
  56. {
  57. SenderId = HOST_TEXT_SENDER;
  58. RecipientId = HOST_TEXT_SENDER;
  59. Type = TEXT_MESSAGE_PUBLIC;
  60. IsHostAdminMessage = false;
  61. Set_App_Packet_Type(APPPACKETTYPE_SCTEXTOBJ);
  62. }
  63. //-----------------------------------------------------------------------------
  64. void
  65. cScTextObj::Init
  66. (
  67. const WideStringClass & text,
  68. TextMessageEnum type,
  69. bool is_host_admin_message,
  70. int sender_id,
  71. int recipient_id
  72. )
  73. {
  74. WWASSERT(sender_id == HOST_TEXT_SENDER || sender_id >= 0);
  75. WWASSERT(cNetwork::I_Am_Server());
  76. Text = text;
  77. Type = type;
  78. SenderId = sender_id;
  79. RecipientId = recipient_id;
  80. IsHostAdminMessage = is_host_admin_message;
  81. switch (Type)
  82. {
  83. case TEXT_MESSAGE_PUBLIC:
  84. {
  85. Set_Object_Dirty_Bit(BIT_CREATION, true);
  86. break;
  87. }
  88. case TEXT_MESSAGE_TEAM:
  89. {
  90. //WWASSERT(The_Game()->Is_Team_Game());
  91. WWASSERT(SenderId >= 0);
  92. cPlayer * p_sender = cPlayerManager::Find_Player(SenderId);
  93. WWASSERT(p_sender != NULL);
  94. WWASSERT(p_sender->Is_Team_Player());
  95. int team = p_sender->Get_Player_Type();
  96. Set_Dirty_Bit_For_Team(BIT_CREATION, team);
  97. break;
  98. }
  99. case TEXT_MESSAGE_PRIVATE:
  100. {
  101. if (RecipientId >= 0) {
  102. Set_Object_Dirty_Bit(RecipientId, BIT_CREATION, true);
  103. }
  104. break;
  105. }
  106. default:
  107. DIE;
  108. }
  109. //
  110. // The sender always gets to see his own sent messages
  111. //
  112. if (SenderId != HOST_TEXT_SENDER)
  113. {
  114. Set_Object_Dirty_Bit(SenderId, BIT_CREATION, true);
  115. }
  116. //
  117. // Explicitly show the message on the server if he is among the recipients.
  118. // We also need to show it if he is dedicated and it is a public message, because
  119. // it may be a response to one of his own important messages.
  120. //
  121. if ((cNetwork::I_Am_Client() && Is_Client_Dirty(cNetwork::Get_My_Id())) ||
  122. //(cNetwork::I_Am_Only_Server() && Type == TEXT_MESSAGE_PUBLIC) ||
  123. (SenderId == HOST_TEXT_SENDER) ||
  124. (RecipientId == HOST_TEXT_SENDER))
  125. {
  126. bool allow_act = true;
  127. //
  128. // Check to see if the server is on the same team as the sender
  129. // before displaying the message
  130. //
  131. if (Type == TEXT_MESSAGE_TEAM) {
  132. allow_act = false;
  133. //
  134. // Lookup the player that's sending the message
  135. //
  136. cPlayer *p_sender = cPlayerManager::Find_Player (SenderId);
  137. if (p_sender != NULL && p_sender->Is_Team_Player () && COMBAT_STAR != NULL) {
  138. //
  139. // Is the player on the same team as the local player?
  140. //
  141. if (p_sender->Get_Player_Type() == COMBAT_STAR->Get_Player_Type()) {
  142. allow_act = true;
  143. }
  144. } else {
  145. if (cNetwork::I_Am_Only_Server() && ConsoleBox.Is_Exclusive() && (The_Game() && The_Game()->IsClanGame.Is_False())) {
  146. allow_act = true;
  147. }
  148. }
  149. }
  150. //
  151. // Display the message
  152. //
  153. if (allow_act) {
  154. Act();
  155. }
  156. }
  157. //
  158. // This is a transient object. It is created, rendered, and destroyed immediately.
  159. //
  160. //Set_Delete_Pending();
  161. }
  162. //-----------------------------------------------------------------------------
  163. void
  164. cScTextObj::Set_Dirty_Bit_For_Team(DIRTY_BIT bit, int team)
  165. {
  166. WWASSERT(team == PLAYERTYPE_NOD || team == PLAYERTYPE_GDI);
  167. for (
  168. SLNode<cPlayer> * player_node = cPlayerManager::Get_Player_Object_List()->Head();
  169. player_node != NULL;
  170. player_node = player_node->Next())
  171. {
  172. cPlayer * p_player = player_node->Data();
  173. WWASSERT(p_player != NULL);
  174. if (p_player->Get_Is_Active().Is_True() &&
  175. p_player->Get_Player_Type() == team)
  176. {
  177. Set_Object_Dirty_Bit(p_player->Get_Id(), bit, true);
  178. }
  179. }
  180. }
  181. //-----------------------------------------------------------------------------
  182. void
  183. cScTextObj::Act(void)
  184. {
  185. bool isAnsi = Text.Is_ANSI();
  186. bool showAsian = MPSettingsMgrClass::Get_Option_Flag(MPSettingsMgrClass::OPTION_DISPLAY_ASIAN);
  187. bool showLatin = MPSettingsMgrClass::Get_Option_Flag(MPSettingsMgrClass::OPTION_DISPLAY_NONASIAN);
  188. if ((isAnsi && showLatin) || (!isAnsi && showAsian)) {
  189. WideStringClass sender_name;
  190. WideStringClass recipient_name;
  191. Vector3 sender_color;
  192. //
  193. // Determine the sender name
  194. //
  195. if (SenderId == HOST_TEXT_SENDER)
  196. {
  197. sender_name = TRANSLATION(IDS_MP_HOST);
  198. sender_color = COLOR_PUBLIC_TEXT;
  199. }
  200. else
  201. {
  202. cPlayer * p_sender = cPlayerManager::Find_Player(SenderId);
  203. if (p_sender != NULL)
  204. {
  205. sender_name = p_sender->Get_Name();
  206. sender_color = p_sender->Get_Color();
  207. }
  208. }
  209. //
  210. // Determine the recipient name
  211. //
  212. if (RecipientId == HOST_TEXT_SENDER)
  213. {
  214. recipient_name = TRANSLATION(IDS_MP_HOST);
  215. }
  216. else
  217. {
  218. cPlayer * p_recipient = cPlayerManager::Find_Player(RecipientId);
  219. if (p_recipient != NULL)
  220. {
  221. recipient_name = p_recipient->Get_Name();
  222. }
  223. }
  224. if (!sender_name.Is_Empty() && !recipient_name.Is_Empty())
  225. {
  226. StringClass sound_name;
  227. Vector3 text_color;
  228. switch (Type)
  229. {
  230. case TEXT_MESSAGE_PUBLIC:
  231. sound_name = "Public_Message";
  232. text_color = COLOR_PUBLIC_TEXT;
  233. break;
  234. case TEXT_MESSAGE_TEAM:
  235. sound_name = "Team_Message";
  236. text_color = sender_color;
  237. break;
  238. case TEXT_MESSAGE_PRIVATE:
  239. sound_name = "Private_Message";
  240. text_color = COLOR_PRIVATE_TEXT;
  241. break;
  242. default:
  243. DIE;
  244. }
  245. WWASSERT(WWAudioClass::Get_Instance() != NULL);
  246. WWAudioClass::Get_Instance()->Create_Instant_Sound(sound_name, Matrix3D(1));
  247. WideStringClass formatted_text;
  248. if (Type == TEXT_MESSAGE_PRIVATE)
  249. {
  250. formatted_text.Format(L"%s (%s %s): ",
  251. sender_name,
  252. TRANSLATION(IDS_MP_TO),
  253. recipient_name);
  254. }
  255. else
  256. {
  257. formatted_text.Format(L"%s: ", sender_name);
  258. }
  259. //
  260. // Display the message...
  261. //
  262. /*
  263. WWASSERT(Get_Text_Display() != NULL);
  264. Get_Text_Display()->Print(formatted_text, sender_color);
  265. formatted_text.Format(L"%s\n", Text);
  266. Get_Text_Display()->Print(formatted_text, text_color);
  267. */
  268. /*
  269. WideStringClass message;
  270. message.Format(L"%s\n", Text);
  271. formatted_text += message;
  272. CombatManager::Get_Message_Window ()->Add_Message (formatted_text, text_color);
  273. */
  274. bool do_popup = IsHostAdminMessage && cNetwork::I_Am_Client();
  275. if (do_popup && cNetwork::I_Am_Server() && Type == TEXT_MESSAGE_PRIVATE &&
  276. RecipientId != cNetwork::Get_My_Id())
  277. {
  278. do_popup = false;
  279. }
  280. if (do_popup) {
  281. DlgMsgBox::DoDialog(TRANSLATE(IDS_MENU_ADMIN_MESSAGE), Text);
  282. } else {
  283. WideStringClass message;
  284. message.Format(L"%s\n", Text);
  285. formatted_text += message;
  286. if (CombatManager::Get_Message_Window() != NULL) {
  287. CombatManager::Get_Message_Window()->Add_Message(formatted_text, text_color);
  288. }
  289. if (isAnsi) {
  290. if (Type == TEXT_MESSAGE_PUBLIC) {
  291. ConsoleBox.Add_Message(&formatted_text, &text_color);
  292. } else {
  293. if (Type == TEXT_MESSAGE_TEAM) {
  294. if (cNetwork::I_Am_Only_Server() && ConsoleBox.Is_Exclusive() && (The_Game() && The_Game()->IsClanGame.Is_False())) {
  295. StringClass tempstr(true);
  296. StringClass teamstr("[Team] ", true);
  297. formatted_text.Convert_To(tempstr);
  298. teamstr += tempstr;
  299. ConsoleBox.Log_To_Disk(teamstr.Peek_Buffer());
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. Set_Delete_Pending();
  308. }
  309. //-----------------------------------------------------------------------------
  310. void
  311. cScTextObj::Export_Creation(BitStreamClass & packet)
  312. {
  313. cNetEvent::Export_Creation(packet);
  314. packet.Add((BYTE) Type);
  315. packet.Add(SenderId);
  316. packet.Add(RecipientId);
  317. packet.Add(IsHostAdminMessage);
  318. packet.Add_Wide_Terminated_String(Text);
  319. Set_Delete_Pending();
  320. }
  321. //-----------------------------------------------------------------------------
  322. void
  323. cScTextObj::Import_Creation(BitStreamClass & packet)
  324. {
  325. cNetEvent::Import_Creation(packet);
  326. WWASSERT(cNetwork::I_Am_Only_Client());
  327. BYTE type = packet.Get(type);
  328. Type = (TextMessageEnum) type;
  329. packet.Get(SenderId);
  330. packet.Get(RecipientId);
  331. packet.Get(IsHostAdminMessage);
  332. packet.Get_Wide_Terminated_String(Text.Get_Buffer(256), 256);
  333. Act();
  334. }
  335. /*
  336. //
  337. // Let's play a "yo" if our name is in the text.
  338. //
  339. if (cNetwork::I_Am_Client()) {
  340. cPlayer * p_my_player = cNetwork::Get_My_Player_Object();
  341. if (p_my_player != NULL) {
  342. StringClass text;
  343. Text.Convert_To(text);
  344. StringClass name;
  345. p_my_player->Get_Name().Convert_To(name);
  346. if () {
  347. }
  348. }
  349. }
  350. */