clientcontrol.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/Combat/clientcontrol.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 9/21/01 10:44a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "clientcontrol.h"
  36. #include "networkobjectfactory.h"
  37. #include "combat.h"
  38. #include "smartgameobj.h"
  39. #include "gameobjmanager.h"
  40. #include "apppackettypes.h"
  41. CClientControl * PClientControl = NULL;
  42. DECLARE_NETWORKOBJECT_FACTORY(CClientControl, NETCLASSID_CLIENTCONTROL);
  43. #pragma message("(TSS) high priority for me to fix this CClientControl bug...")
  44. //
  45. // TSS2001 problem: destruction of this object on the server. Quitting and rejoining
  46. // a game will crash the server.
  47. //
  48. //-----------------------------------------------------------------------------
  49. CClientControl::CClientControl(void)
  50. {
  51. ClientId = -1;
  52. SmartObjId = -1;
  53. Set_App_Packet_Type(APPPACKETTYPE_CLIENTCONTROL);
  54. }
  55. //-----------------------------------------------------------------------------
  56. CClientControl::~CClientControl(void)
  57. {
  58. }
  59. //-----------------------------------------------------------------------------
  60. void
  61. CClientControl::Init(void)
  62. {
  63. WWASSERT(CombatManager::I_Am_Client());
  64. ClientId = CombatManager::Get_My_Id();
  65. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  66. Set_Object_Dirty_Bit(0, NetworkObjectClass::BIT_CREATION, true);
  67. }
  68. //-----------------------------------------------------------------------------
  69. void
  70. CClientControl::Set_Update_Flag(int id)
  71. {
  72. WWASSERT(CombatManager::I_Am_Client());
  73. SmartObjId = id;
  74. if (id != -1) {
  75. Set_Object_Dirty_Bit(0, NetworkObjectClass::BIT_FREQUENT, true);
  76. }
  77. }
  78. //-----------------------------------------------------------------------------
  79. void
  80. CClientControl::Export_Creation(BitStreamClass & packet)
  81. {
  82. WWASSERT(CombatManager::I_Am_Client());
  83. NetworkObjectClass::Export_Creation(packet);
  84. packet.Add(ClientId);
  85. }
  86. //-----------------------------------------------------------------------------
  87. void
  88. CClientControl::Import_Creation(BitStreamClass & packet)
  89. {
  90. WWASSERT(CombatManager::I_Am_Server());
  91. NetworkObjectClass::Import_Creation(packet);
  92. packet.Get(ClientId);
  93. }
  94. //-----------------------------------------------------------------------------
  95. void
  96. CClientControl::Export_Frequent(BitStreamClass & packet)
  97. {
  98. WWASSERT(CombatManager::I_Am_Client());
  99. /*
  100. packet.Add(SmartObjId);
  101. if (SmartObjId != -1) {
  102. SmartGameObj * p_smart_go = GameObjManager::Find_SmartGameObj(SmartObjId);
  103. WWASSERT(p_smart_go != NULL);
  104. p_smart_go->Export_Control_Cs(packet);
  105. p_smart_go->Export_State_Cs(packet);
  106. }
  107. */
  108. SmartGameObj * p_smart_go = NULL;
  109. if (SmartObjId != -1) {
  110. p_smart_go = GameObjManager::Find_SmartGameObj(SmartObjId);
  111. if (p_smart_go == NULL) {
  112. SmartObjId = -1;
  113. }
  114. }
  115. packet.Add(SmartObjId);
  116. if (SmartObjId != -1) {
  117. WWASSERT(p_smart_go != NULL);
  118. p_smart_go->Export_Control_Cs(packet);
  119. p_smart_go->Export_State_Cs(packet);
  120. }
  121. SmartObjId = -1;//hack
  122. }
  123. //-----------------------------------------------------------------------------
  124. void
  125. CClientControl::Import_Frequent(BitStreamClass & packet)
  126. {
  127. WWASSERT(CombatManager::I_Am_Server());
  128. packet.Get(SmartObjId);
  129. if (SmartObjId != -1) {
  130. SmartGameObj * p_smart_go = GameObjManager::Find_SmartGameObj(SmartObjId);
  131. //WWASSERT(p_smart_go != NULL);
  132. if (p_smart_go == NULL) {
  133. packet.Flush();
  134. } else {
  135. p_smart_go->Import_Control_Cs(packet);
  136. //
  137. // Note: org code had control owner test here, reapply if problems arise.
  138. //
  139. p_smart_go->Import_State_Cs(packet);
  140. }
  141. }
  142. }