Damage.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Damage.cpp ///////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, September 2002
  25. // Desc: Basic structures for the damage process
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Damage.h"
  31. #include "Common/BitFlagsIO.h"
  32. #include "Common/ThingFactory.h"
  33. #include "Common/ThingTemplate.h"
  34. ///////////////////////////////////////////////////////////////////////////////////////////////////
  35. ///////////////////////////////////////////////////////////////////////////////////////////////////
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. const char* DamageTypeFlags::s_bitNameList[] =
  38. {
  39. "EXPLOSION",
  40. "CRUSH",
  41. "ARMOR_PIERCING",
  42. "SMALL_ARMS",
  43. "GATTLING",
  44. "RADIATION",
  45. "FLAME",
  46. "LASER",
  47. "SNIPER",
  48. "POISON",
  49. "HEALING",
  50. "UNRESISTABLE",
  51. "WATER",
  52. "DEPLOY",
  53. "SURRENDER",
  54. "HACK",
  55. "KILL_PILOT",
  56. "PENALTY",
  57. "FALLING",
  58. "MELEE",
  59. "DISARM",
  60. "HAZARD_CLEANUP",
  61. "PARTICLE_BEAM",
  62. "TOPPLING",
  63. "INFANTRY_MISSILE",
  64. "AURORA_BOMB",
  65. "LAND_MINE",
  66. "JET_MISSILES",
  67. "STEALTHJET_MISSILES",
  68. "MOLOTOV_COCKTAIL",
  69. "COMANCHE_VULCAN",
  70. "SUBDUAL_MISSILE",
  71. "SUBDUAL_VEHICLE",
  72. "SUBDUAL_BUILDING",
  73. "SUBDUAL_UNRESISTABLE",
  74. "MICROWAVE",
  75. "KILL_GARRISONED",
  76. "STATUS",
  77. NULL
  78. };
  79. DamageTypeFlags DAMAGE_TYPE_FLAGS_NONE; // inits to all zeroes
  80. DamageTypeFlags DAMAGE_TYPE_FLAGS_ALL;
  81. void initDamageTypeFlags()
  82. {
  83. SET_ALL_DAMAGE_TYPE_BITS( DAMAGE_TYPE_FLAGS_ALL );
  84. }
  85. // ------------------------------------------------------------------------------------------------
  86. /** Xfer method
  87. * Version Info:
  88. * 1: Initial version */
  89. // ------------------------------------------------------------------------------------------------
  90. void DamageInfo::xfer( Xfer *xfer )
  91. {
  92. // version
  93. XferVersion currentVersion = 1;
  94. XferVersion version = currentVersion;
  95. xfer->xferVersion( &version, currentVersion );
  96. // xfer input
  97. xfer->xferSnapshot( &in );
  98. // xfer output
  99. xfer->xferSnapshot( &out );
  100. } // end xfer
  101. // ------------------------------------------------------------------------------------------------
  102. /** Xfer method
  103. * Version Info:
  104. * 1: Initial version
  105. * 2: Damage FX override
  106. */
  107. // ------------------------------------------------------------------------------------------------
  108. void DamageInfoInput::xfer( Xfer *xfer )
  109. {
  110. // version
  111. XferVersion currentVersion = 3;
  112. XferVersion version = currentVersion;
  113. xfer->xferVersion( &version, currentVersion );
  114. // source id
  115. xfer->xferObjectID( &m_sourceID );
  116. // source player mask
  117. xfer->xferUser( &m_sourcePlayerMask, sizeof( PlayerMaskType ) );
  118. // damage type
  119. xfer->xferUser( &m_damageType, sizeof( DamageType ) );
  120. // damage FX Override
  121. if( version >= 2 )
  122. xfer->xferUser( &m_damageFXOverride, sizeof( DamageType ) );
  123. // death type
  124. xfer->xferUser( &m_deathType, sizeof( DeathType ) );
  125. // amount
  126. xfer->xferReal( &m_amount );
  127. // kill no matter what (old versions default to FALSE).
  128. if( currentVersion >= 2 )
  129. {
  130. xfer->xferBool( &m_kill );
  131. }
  132. xfer->xferUser( &m_damageStatusType, sizeof(ObjectStatusTypes) );//It's an enum
  133. xfer->xferCoord3D(&m_shockWaveVector);
  134. xfer->xferReal( &m_shockWaveAmount );
  135. xfer->xferReal( &m_shockWaveRadius );
  136. xfer->xferReal( &m_shockWaveTaperOff );
  137. if( version >= 3 )
  138. {
  139. AsciiString thingString = m_sourceTemplate ? m_sourceTemplate->getName() : AsciiString::TheEmptyString;
  140. xfer->xferAsciiString( &thingString );
  141. if( xfer->getXferMode() == XFER_LOAD )
  142. {
  143. m_sourceTemplate = TheThingFactory->findTemplate( thingString );
  144. }
  145. }
  146. } // end xfer
  147. // ------------------------------------------------------------------------------------------------
  148. /** Xfer method
  149. * Version Info:
  150. * 1: Initial version */
  151. // ------------------------------------------------------------------------------------------------
  152. void DamageInfoOutput::xfer( Xfer *xfer )
  153. {
  154. // version
  155. XferVersion currentVersion = 1;
  156. XferVersion version = currentVersion;
  157. xfer->xferVersion( &version, currentVersion );
  158. // actual damage
  159. xfer->xferReal( &m_actualDamageDealt );
  160. // damage clipped
  161. xfer->xferReal( &m_actualDamageClipped );
  162. // no effect
  163. xfer->xferBool( &m_noEffect );
  164. } // end xfer