csdamageevent.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/csdamageevent.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 11/24/01 10:36a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "csdamageevent.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "combat.h"
  40. #include "networkobjectmgr.h"
  41. #include "gameobjmanager.h"
  42. #include "apppackettypes.h"
  43. #include "damage.h"
  44. #include "armedgameobj.h"
  45. #include "debug.h"
  46. DECLARE_NETWORKOBJECT_FACTORY(cCsDamageEvent, NETCLASSID_CSDAMAGEEVENT);
  47. //
  48. // Class statics
  49. //
  50. bool cCsDamageEvent::AreClientsTrusted = true;
  51. //-----------------------------------------------------------------------------
  52. cCsDamageEvent::cCsDamageEvent(void)
  53. {
  54. SenderId = 0;
  55. DamagerGOID = 0;
  56. DamageeGOID = 0;
  57. Damage = 0;
  58. Warhead = 0;
  59. Set_App_Packet_Type(APPPACKETTYPE_CSDAMAGEEVENT);
  60. Set_Unreliable_Override(true);
  61. }
  62. //-----------------------------------------------------------------------------
  63. void
  64. cCsDamageEvent::Init
  65. (
  66. int damager_go_id,
  67. int damagee_go_id,
  68. float damage,
  69. int warhead
  70. )
  71. {
  72. WWASSERT(CombatManager::I_Am_Only_Client());
  73. WWASSERT(AreClientsTrusted);
  74. SenderId = CombatManager::Get_My_Id();
  75. DamagerGOID = damager_go_id;
  76. DamageeGOID = damagee_go_id;
  77. Damage = damage;
  78. Warhead = warhead;
  79. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  80. Set_Object_Dirty_Bit(0, BIT_CREATION, true);
  81. }
  82. //-----------------------------------------------------------------------------
  83. void
  84. cCsDamageEvent::Act
  85. (
  86. void
  87. )
  88. {
  89. WWASSERT(CombatManager::I_Am_Server());
  90. if (AreClientsTrusted)
  91. {
  92. // process the member data here. Include sanity checks.
  93. // Find the gameobj with the damagee id
  94. PhysicalGameObj * obj = GameObjManager::Find_PhysicalGameObj( DamageeGOID );
  95. if ( obj ) {
  96. // Make an offense object
  97. PhysicalGameObj * damager = GameObjManager::Find_PhysicalGameObj( DamagerGOID );
  98. if ( damager != NULL && damager->As_ArmedGameObj() != NULL ) {
  99. OffenseObjectClass offense( Damage, Warhead, damager->As_ArmedGameObj());
  100. // obj->Get_Defense_Object()->Do_Damage( offense );
  101. // We need to use apply damage extended in order to allow things to die.
  102. offense.ForceServerDamage = true;
  103. #if 0
  104. // guess at the damage direction
  105. Vector3 direction;
  106. Vector3 pos;
  107. damager->Get_Position( &pos );
  108. obj->Get_Position( &direction );
  109. direction -= pos;
  110. direction.Normalize();
  111. obj->Apply_Damage_Extended( offense, 1.0f, direction );
  112. #else
  113. obj->Apply_Damage_Extended( offense );
  114. #endif
  115. // Debug_Say(( "Applying Client damage of %f from %d to %d\n", Damage, DamagerGOID, DamageeGOID ));
  116. } else {
  117. // Debug_Say(( "Error: Client damage Damagee %d not found\n", DamageeGOID ));
  118. }
  119. } else {
  120. // Debug_Say(( "Error: Client damage Damagee %d not found\n", DamageeGOID ));
  121. }
  122. } else {
  123. Debug_Say(( "Error: Receiving Client damage when clients are not trusted\n" ));
  124. }
  125. Set_Delete_Pending();
  126. }
  127. //-----------------------------------------------------------------------------
  128. void
  129. cCsDamageEvent::Export_Creation
  130. (
  131. BitStreamClass & packet
  132. )
  133. {
  134. WWASSERT(CombatManager::I_Am_Only_Client());
  135. NetworkObjectClass::Export_Creation(packet);
  136. WWASSERT(SenderId > 0);
  137. packet.Add(SenderId);
  138. packet.Add(DamagerGOID);
  139. packet.Add(DamageeGOID);
  140. packet.Add(Damage);
  141. packet.Add(Warhead);
  142. Set_Delete_Pending();
  143. }
  144. //-----------------------------------------------------------------------------
  145. void
  146. cCsDamageEvent::Import_Creation
  147. (
  148. BitStreamClass & packet
  149. )
  150. {
  151. WWASSERT(CombatManager::I_Am_Server());
  152. NetworkObjectClass::Import_Creation(packet);
  153. packet.Get(SenderId);
  154. packet.Get(DamagerGOID);
  155. packet.Get(DamageeGOID);
  156. packet.Get(Damage);
  157. packet.Get(Warhead);
  158. WWASSERT(SenderId > 0);
  159. Act();
  160. }