FireWeaponWhenDeadBehavior.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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: FireWeaponWhenDeadBehavior.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author:
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #define DEFINE_SLOWDEATHPHASE_NAMES
  30. #include "Common/Thing.h"
  31. #include "Common/ThingTemplate.h"
  32. #include "Common/INI.h"
  33. #include "Common/RandomValue.h"
  34. #include "Common/Xfer.h"
  35. #include "Common/Player.h"
  36. #include "GameClient/Drawable.h"
  37. #include "GameClient/FXList.h"
  38. #include "GameClient/InGameUI.h"
  39. #include "GameLogic/GameLogic.h"
  40. #include "GameLogic/Module/BodyModule.h"
  41. #include "GameLogic/Module/FireWeaponWhenDeadBehavior.h"
  42. #include "GameLogic/Module/AIUpdate.h"
  43. #include "GameLogic/Object.h"
  44. #include "GameLogic/ObjectCreationList.h"
  45. #include "GameLogic/Weapon.h"
  46. #include "GameClient/Drawable.h"
  47. #ifdef _INTERNAL
  48. // for occasional debugging...
  49. //#pragma optimize("", off)
  50. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  51. #endif
  52. const Int MAX_IDX = 32;
  53. const Real BEGIN_MIDPOINT_RATIO = 0.35f;
  54. const Real END_MIDPOINT_RATIO = 0.65f;
  55. //-------------------------------------------------------------------------------------------------
  56. //-------------------------------------------------------------------------------------------------
  57. FireWeaponWhenDeadBehavior::FireWeaponWhenDeadBehavior( Thing *thing, const ModuleData* moduleData ) :
  58. BehaviorModule( thing, moduleData )
  59. {
  60. if (getFireWeaponWhenDeadBehaviorModuleData()->m_initiallyActive)
  61. {
  62. giveSelfUpgrade();
  63. }
  64. }
  65. //-------------------------------------------------------------------------------------------------
  66. //-------------------------------------------------------------------------------------------------
  67. FireWeaponWhenDeadBehavior::~FireWeaponWhenDeadBehavior( void )
  68. {
  69. }
  70. //-------------------------------------------------------------------------------------------------
  71. /** The die callback. */
  72. //-------------------------------------------------------------------------------------------------
  73. void FireWeaponWhenDeadBehavior::onDie( const DamageInfo *damageInfo )
  74. {
  75. const FireWeaponWhenDeadBehaviorModuleData* d = getFireWeaponWhenDeadBehaviorModuleData();
  76. Object *obj = getObject();
  77. if (!isUpgradeActive())
  78. return;
  79. // right type?
  80. if (!d->m_dieMuxData.isDieApplicable(getObject(), damageInfo))
  81. return;
  82. // This will never apply until built. Otherwise canceling construction sets it off, and killing
  83. // a one hitpoint one percent building will too.
  84. if( obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  85. return;
  86. UpgradeMaskType activation, conflicting;
  87. getUpgradeActivationMasks( activation, conflicting );
  88. if( obj->getObjectCompletedUpgradeMask().testForAny( conflicting ) )
  89. {
  90. return;
  91. }
  92. if( obj->getControllingPlayer() && obj->getControllingPlayer()->getCompletedUpgradeMask().testForAny( conflicting ) )
  93. {
  94. return;
  95. }
  96. if (d->m_deathWeapon)
  97. {
  98. // fire the default weapon
  99. TheWeaponStore->createAndFireTempWeapon(d->m_deathWeapon, obj, obj->getPosition());
  100. }
  101. }
  102. // ------------------------------------------------------------------------------------------------
  103. /** CRC */
  104. // ------------------------------------------------------------------------------------------------
  105. void FireWeaponWhenDeadBehavior::crc( Xfer *xfer )
  106. {
  107. // extend base class
  108. BehaviorModule::crc( xfer );
  109. // extend upgrade mux
  110. UpgradeMux::upgradeMuxCRC( xfer );
  111. } // end crc
  112. // ------------------------------------------------------------------------------------------------
  113. /** Xfer method
  114. * Version Info:
  115. * 1: Initial version */
  116. // ------------------------------------------------------------------------------------------------
  117. void FireWeaponWhenDeadBehavior::xfer( Xfer *xfer )
  118. {
  119. // version
  120. XferVersion currentVersion = 1;
  121. XferVersion version = currentVersion;
  122. xfer->xferVersion( &version, currentVersion );
  123. // extend base class
  124. BehaviorModule::xfer( xfer );
  125. // extend upgrade mux
  126. UpgradeMux::upgradeMuxXfer( xfer );
  127. } // end xfer
  128. // ------------------------------------------------------------------------------------------------
  129. /** Load post process */
  130. // ------------------------------------------------------------------------------------------------
  131. void FireWeaponWhenDeadBehavior::loadPostProcess( void )
  132. {
  133. // extend base class
  134. BehaviorModule::loadPostProcess();
  135. // extend upgrade mux
  136. UpgradeMux::upgradeMuxLoadPostProcess();
  137. } // end loadPostProcess