FireWeaponWhenDeadBehavior.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. ** Command & Conquer Generals(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 "GameClient/Drawable.h"
  36. #include "GameClient/FXList.h"
  37. #include "GameClient/InGameUI.h"
  38. #include "GameLogic/GameLogic.h"
  39. #include "GameLogic/Module/BodyModule.h"
  40. #include "GameLogic/Module/FireWeaponWhenDeadBehavior.h"
  41. #include "GameLogic/Module/AIUpdate.h"
  42. #include "GameLogic/Object.h"
  43. #include "GameLogic/ObjectCreationList.h"
  44. #include "GameLogic/Weapon.h"
  45. #include "GameClient/Drawable.h"
  46. #include "Common/Player.h"
  47. const Int MAX_IDX = 32;
  48. const Real BEGIN_MIDPOINT_RATIO = 0.35f;
  49. const Real END_MIDPOINT_RATIO = 0.65f;
  50. //-------------------------------------------------------------------------------------------------
  51. //-------------------------------------------------------------------------------------------------
  52. FireWeaponWhenDeadBehavior::FireWeaponWhenDeadBehavior( Thing *thing, const ModuleData* moduleData ) :
  53. BehaviorModule( thing, moduleData )
  54. {
  55. if (getFireWeaponWhenDeadBehaviorModuleData()->m_initiallyActive)
  56. {
  57. giveSelfUpgrade();
  58. }
  59. }
  60. //-------------------------------------------------------------------------------------------------
  61. //-------------------------------------------------------------------------------------------------
  62. FireWeaponWhenDeadBehavior::~FireWeaponWhenDeadBehavior( void )
  63. {
  64. }
  65. //-------------------------------------------------------------------------------------------------
  66. /** The die callback. */
  67. //-------------------------------------------------------------------------------------------------
  68. void FireWeaponWhenDeadBehavior::onDie( const DamageInfo *damageInfo )
  69. {
  70. const FireWeaponWhenDeadBehaviorModuleData* d = getFireWeaponWhenDeadBehaviorModuleData();
  71. if (!isUpgradeActive())
  72. return;
  73. // right type?
  74. if (!d->m_dieMuxData.isDieApplicable(getObject(), damageInfo))
  75. return;
  76. // This will never apply until built. Otherwise canceling construction sets it off, and killing
  77. // a one hitpoint one percent building will too.
  78. if( BitTest( getObject()->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == TRUE )
  79. return;
  80. Int64 activation, conflicting;
  81. getUpgradeActivationMasks( activation, conflicting );
  82. if( getObject()->getObjectCompletedUpgradeMask() & conflicting )
  83. {
  84. return;
  85. }
  86. if( getObject()->getControllingPlayer()->getCompletedUpgradeMask() & conflicting )
  87. {
  88. return;
  89. }
  90. if (d->m_deathWeapon)
  91. {
  92. // fire the default weapon
  93. TheWeaponStore->createAndFireTempWeapon(d->m_deathWeapon, getObject(), getObject()->getPosition());
  94. }
  95. }
  96. // ------------------------------------------------------------------------------------------------
  97. /** CRC */
  98. // ------------------------------------------------------------------------------------------------
  99. void FireWeaponWhenDeadBehavior::crc( Xfer *xfer )
  100. {
  101. // extend base class
  102. BehaviorModule::crc( xfer );
  103. // extend upgrade mux
  104. UpgradeMux::upgradeMuxCRC( xfer );
  105. } // end crc
  106. // ------------------------------------------------------------------------------------------------
  107. /** Xfer method
  108. * Version Info:
  109. * 1: Initial version */
  110. // ------------------------------------------------------------------------------------------------
  111. void FireWeaponWhenDeadBehavior::xfer( Xfer *xfer )
  112. {
  113. // version
  114. XferVersion currentVersion = 1;
  115. XferVersion version = currentVersion;
  116. xfer->xferVersion( &version, currentVersion );
  117. // extend base class
  118. BehaviorModule::xfer( xfer );
  119. // extend upgrade mux
  120. UpgradeMux::upgradeMuxXfer( xfer );
  121. } // end xfer
  122. // ------------------------------------------------------------------------------------------------
  123. /** Load post process */
  124. // ------------------------------------------------------------------------------------------------
  125. void FireWeaponWhenDeadBehavior::loadPostProcess( void )
  126. {
  127. // extend base class
  128. BehaviorModule::loadPostProcess();
  129. // extend upgrade mux
  130. UpgradeMux::upgradeMuxLoadPostProcess();
  131. } // end loadPostProcess