BattleBusSlowDeathBehavior.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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: BattleBusSlowDeathBehavior.cpp /////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, June 2003
  25. // Desc: Death for the Battle Bus. Can do a fake slow death before the real one if triggered intentionally
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Module/BattleBusSlowDeathBehavior.h"
  31. #include "Common/ModelState.h"
  32. #include "GameClient/FXList.h"
  33. #include "GameLogic/GameLogic.h"
  34. #include "GameLogic/Object.h"
  35. #include "GameLogic/ObjectCreationList.h"
  36. #include "GameLogic/Module/AIUpdate.h"
  37. #include "GameLogic/Module/ContainModule.h"
  38. #include "GameLogic/Module/PhysicsUpdate.h"
  39. #ifdef _INTERNAL
  40. // for occasional debugging...
  41. //#pragma optimize("", off)
  42. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  43. #endif
  44. enum
  45. {
  46. GROUND_CHECK_DELAY = 10, ///< Check for colliding with the ground only after this long, to prevent hitting on the way up
  47. EMPTY_HULK_CHECK_DELAY = 15 ///< Check for empty hulk every this often instead of every frame
  48. };
  49. ///////////////////////////////////////////////////////////////////////////////////////////////////
  50. ///////////////////////////////////////////////////////////////////////////////////////////////////
  51. ///////////////////////////////////////////////////////////////////////////////////////////////////
  52. // ------------------------------------------------------------------------------------------------
  53. // ------------------------------------------------------------------------------------------------
  54. BattleBusSlowDeathBehaviorModuleData::BattleBusSlowDeathBehaviorModuleData( void )
  55. {
  56. m_fxStartUndeath = NULL;
  57. m_oclStartUndeath = NULL;
  58. m_fxHitGround = NULL;
  59. m_oclHitGround = NULL;
  60. m_throwForce = 1.0f;
  61. m_percentDamageToPassengers = 0.0f;
  62. m_emptyHulkDestructionDelay = 0;
  63. } // end BattleBusSlowDeathBehaviorModuleData
  64. // ------------------------------------------------------------------------------------------------
  65. // ------------------------------------------------------------------------------------------------
  66. /*static*/ void BattleBusSlowDeathBehaviorModuleData::buildFieldParse( MultiIniFieldParse &p )
  67. {
  68. SlowDeathBehaviorModuleData::buildFieldParse( p );
  69. static const FieldParse dataFieldParse[] =
  70. {
  71. { "FXStartUndeath", INI::parseFXList, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_fxStartUndeath ) },
  72. { "OCLStartUndeath", INI::parseObjectCreationList, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_oclStartUndeath ) },
  73. { "FXHitGround", INI::parseFXList, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_fxHitGround ) },
  74. { "OCLHitGround", INI::parseObjectCreationList, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_oclHitGround ) },
  75. { "ThrowForce", INI::parseReal, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_throwForce ) },
  76. { "PercentDamageToPassengers", INI::parsePercentToReal, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_percentDamageToPassengers ) },
  77. { "EmptyHulkDestructionDelay", INI::parseDurationUnsignedInt, NULL, offsetof( BattleBusSlowDeathBehaviorModuleData, m_emptyHulkDestructionDelay ) },
  78. { 0, 0, 0, 0 }
  79. };
  80. p.add( dataFieldParse );
  81. } // end buildFieldParse
  82. ///////////////////////////////////////////////////////////////////////////////////////////////////
  83. ///////////////////////////////////////////////////////////////////////////////////////////////////
  84. ///////////////////////////////////////////////////////////////////////////////////////////////////
  85. // ------------------------------------------------------------------------------------------------
  86. // ------------------------------------------------------------------------------------------------
  87. BattleBusSlowDeathBehavior::BattleBusSlowDeathBehavior( Thing *thing, const ModuleData *moduleData )
  88. : SlowDeathBehavior( thing, moduleData )
  89. {
  90. m_isRealDeath = FALSE;
  91. m_isInFirstDeath = FALSE;
  92. m_groundCheckFrame = 0;
  93. m_penaltyDeathFrame = 0;
  94. } // end BattleBusSlowDeathBehavior
  95. // ------------------------------------------------------------------------------------------------
  96. // ------------------------------------------------------------------------------------------------
  97. BattleBusSlowDeathBehavior::~BattleBusSlowDeathBehavior( void )
  98. {
  99. } // end ~BattleBusSlowDeathBehavior
  100. // ------------------------------------------------------------------------------------------------
  101. // ------------------------------------------------------------------------------------------------
  102. void BattleBusSlowDeathBehavior::onDie( const DamageInfo *damageInfo )
  103. {
  104. m_isRealDeath = TRUE;// Set beforehand because onDie could result in picking us to beginSlowDeath
  105. m_isInFirstDeath = FALSE; // and clear this incase we died while in the alternate death
  106. SlowDeathBehavior::onDie(damageInfo);
  107. } // end onDie
  108. // ------------------------------------------------------------------------------------------------
  109. // ------------------------------------------------------------------------------------------------
  110. void BattleBusSlowDeathBehavior::beginSlowDeath( const DamageInfo *damageInfo )
  111. {
  112. Object *me = getObject();
  113. const BattleBusSlowDeathBehaviorModuleData * data = getBattleBusSlowDeathBehaviorModuleData();
  114. if( !m_isRealDeath )
  115. {
  116. // We can intercept and do our extra slow death if this is not from a real onDie
  117. m_isInFirstDeath = TRUE;
  118. m_groundCheckFrame = TheGameLogic->getFrame() + GROUND_CHECK_DELAY;
  119. // First do the special effects
  120. FXList::doFXObj(data->m_fxStartUndeath, me );
  121. ObjectCreationList::create(data->m_oclStartUndeath, me, NULL );
  122. if( me->getAI() )
  123. {
  124. // Then stop what we were doing
  125. me->getAI()->aiIdle(CMD_FROM_AI);
  126. }
  127. if( me->getPhysics() )
  128. {
  129. // Then stop physically
  130. me->getPhysics()->clearAcceleration();
  131. me->getPhysics()->scrubVelocity2D(0);
  132. // Then get chucked in the air
  133. Coord3D throwForce;
  134. throwForce.x = 0;
  135. throwForce.y = 0;
  136. throwForce.z = data->m_throwForce;
  137. me->getPhysics()->applyShock(&throwForce);
  138. me->getPhysics()->applyRandomRotation();
  139. }
  140. // And finally hit those inside for some damage
  141. if( me->getContain() )
  142. me->getContain()->processDamageToContained(data->m_percentDamageToPassengers);
  143. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  144. }
  145. else
  146. {
  147. // If a real death, we aren't allowed to do anything
  148. SlowDeathBehavior::beginSlowDeath( damageInfo );
  149. }
  150. } // end beginSlowDeath
  151. // ------------------------------------------------------------------------------------------------
  152. // ------------------------------------------------------------------------------------------------
  153. UpdateSleepTime BattleBusSlowDeathBehavior::update( void )
  154. {
  155. Object *me = getObject();
  156. const BattleBusSlowDeathBehaviorModuleData * data = getBattleBusSlowDeathBehaviorModuleData();
  157. if( m_isInFirstDeath )
  158. {
  159. // First death means we are doing our throw up in the air conversion
  160. if( (m_groundCheckFrame< TheGameLogic->getFrame() ) && !me->isAboveTerrain() )
  161. {
  162. // We're done since we hit the ground
  163. m_isInFirstDeath = FALSE;
  164. // Do the special FX
  165. FXList::doFXObj(data->m_fxHitGround, me );
  166. ObjectCreationList::create(data->m_oclHitGround, me, NULL );
  167. me->setModelConditionState(MODELCONDITION_SECOND_LIFE);
  168. // And stop us forever
  169. if( me->getAI() )
  170. {
  171. // Stop doing anything again (could try to move while in air)
  172. me->getAI()->aiIdle(CMD_FROM_AI);
  173. }
  174. if( me->getPhysics() )
  175. {
  176. // And stop physically again
  177. me->getPhysics()->clearAcceleration();
  178. me->getPhysics()->scrubVelocity2D(0);
  179. }
  180. me->setDisabled(DISABLED_HELD);
  181. // We can only sleep if we don't have to watch out for being empty.
  182. if( data->m_emptyHulkDestructionDelay == 0 )
  183. return UPDATE_SLEEP_FOREVER;
  184. else
  185. return UPDATE_SLEEP_NONE; // None, so we check for empty as soon as possible
  186. }
  187. return UPDATE_SLEEP_NONE;// None, since we are waiting to be able to check for ground collision
  188. }
  189. else if( m_isRealDeath )
  190. {
  191. // If a real death, we aren't allowed to do anything
  192. return SlowDeathBehavior::update();
  193. }
  194. else
  195. {
  196. // If neither death is active, we must be awake to check for emptiness
  197. const ContainModuleInterface *contain = me->getContain();
  198. // Safety, no need to be awake if no special case to wait for
  199. if( contain == NULL )
  200. return UPDATE_SLEEP_FOREVER;
  201. if( m_penaltyDeathFrame != 0 )
  202. {
  203. // We have been timed for death, see if we have re-filled first
  204. if( contain->getContainCount() > 0 )
  205. {
  206. m_penaltyDeathFrame = 0;
  207. return UPDATE_SLEEP(EMPTY_HULK_CHECK_DELAY);
  208. }
  209. else if( TheGameLogic->getFrame() > m_penaltyDeathFrame )
  210. {
  211. // No salvation, see if the timer is up to be killed. Penalty prevents effects, Extra 4 prevents this die module from recalling.
  212. // Can't use Suicided death because a Terrorist actually inflicts Suicide deaths on others.
  213. me->kill(DAMAGE_PENALTY, DEATH_EXTRA_4);
  214. return UPDATE_SLEEP_FOREVER;// Forever, since we are dead and some other death module is in charge
  215. }
  216. else
  217. {
  218. return UPDATE_SLEEP(EMPTY_HULK_CHECK_DELAY);
  219. }
  220. }
  221. else
  222. {
  223. // We are not marked for death, so see if we should be
  224. if( contain->getContainCount() == 0 )
  225. {
  226. m_penaltyDeathFrame = TheGameLogic->getFrame() + data->m_emptyHulkDestructionDelay;
  227. }
  228. return UPDATE_SLEEP(EMPTY_HULK_CHECK_DELAY);// Stay awake regardless
  229. }
  230. }
  231. } // end update
  232. // ------------------------------------------------------------------------------------------------
  233. /** CRC */
  234. // ------------------------------------------------------------------------------------------------
  235. void BattleBusSlowDeathBehavior::crc( Xfer *xfer )
  236. {
  237. // extend base class
  238. SlowDeathBehavior::crc( xfer );
  239. } // end crc
  240. // ------------------------------------------------------------------------------------------------
  241. /** Xfer method
  242. * Version Info:
  243. * 1: Initial version */
  244. // ------------------------------------------------------------------------------------------------
  245. void BattleBusSlowDeathBehavior::xfer( Xfer *xfer )
  246. {
  247. // version
  248. XferVersion currentVersion = 1;
  249. XferVersion version = currentVersion;
  250. xfer->xferVersion( &version, currentVersion );
  251. // extend base class
  252. SlowDeathBehavior::xfer( xfer );
  253. xfer->xferBool( &m_isRealDeath );
  254. xfer->xferBool( &m_isInFirstDeath );
  255. xfer->xferUnsignedInt( &m_groundCheckFrame );
  256. xfer->xferUnsignedInt( &m_penaltyDeathFrame );
  257. } // end xfer
  258. // ------------------------------------------------------------------------------------------------
  259. /** Load post process */
  260. // ------------------------------------------------------------------------------------------------
  261. void BattleBusSlowDeathBehavior::loadPostProcess( void )
  262. {
  263. // extend base class
  264. SlowDeathBehavior::loadPostProcess();
  265. } // end loadPostProcess