NeutonBlastBehavior.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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: NeutronBlastBehavior.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author: Daniel Teh
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////
  26. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "GameLogic/Module/NeutronBlastBehavior.h"
  29. #include "Common/Player.h"
  30. #include "Common/PlayerList.h"
  31. #include "GameLogic/Module/ContainModule.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/PartitionManager.h"
  35. #include "GameLogic/Module/AIUpdate.h"
  36. #include "GameClient/Drawable.h"
  37. #ifdef _INTERNAL
  38. // for occasional debugging...
  39. //#pragma optimize("", off)
  40. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  41. #endif
  42. //-------------------------------------------------------------------------------------------------
  43. //-------------------------------------------------------------------------------------------------
  44. NeutronBlastBehavior::NeutronBlastBehavior( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  45. {
  46. setWakeFrame( getObject(), UPDATE_SLEEP_FOREVER );
  47. }
  48. //-------------------------------------------------------------------------------------------------
  49. //-------------------------------------------------------------------------------------------------
  50. NeutronBlastBehavior::~NeutronBlastBehavior()
  51. {
  52. // GAME STUFF DOES NOT GO IN THE DESTRUCTOR
  53. // (Crash if end game with Neutron shell in air)
  54. }
  55. //-------------------------------------------------------------------------------------------------
  56. //-------------------------------------------------------------------------------------------------
  57. void NeutronBlastBehavior::onDie( const DamageInfo *damageInfo )
  58. {
  59. // On death, perform the Neutron Blast!!
  60. Object *self = getObject();
  61. if (!self)
  62. return;
  63. const NeutronBlastBehaviorModuleData *data = getNeutronBlastBehaviorModuleData();
  64. Real blastRadius = data->m_blastRadius;
  65. Bool hitAir = data->m_isAffectAirborne;
  66. // setup scan filters
  67. PartitionFilterSameMapStatus filterMapStatus( self );
  68. PartitionFilterAlive filterAlive;
  69. PartitionFilter *filters[] = { &filterAlive, &filterMapStatus, NULL };
  70. // scan objects in our region
  71. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( self->getPosition(), blastRadius, FROM_CENTER_2D, filters );
  72. MemoryPoolObjectHolder hold( iter );
  73. // Apply neutron blast to object
  74. for( Object *obj = iter->first(); obj; obj = iter->next() )
  75. {
  76. if( hitAir || ( !obj->isKindOf(KINDOF_AIRCRAFT) && !obj->isAirborneTarget() ) )
  77. {
  78. neutronBlastToObject( obj );
  79. }
  80. }
  81. }
  82. //-------------------------------------------------------------------------------------------------
  83. /** The update callback. */
  84. //-------------------------------------------------------------------------------------------------
  85. UpdateSleepTime NeutronBlastBehavior::update( void )
  86. {
  87. return UPDATE_SLEEP_FOREVER;
  88. }
  89. //-------------------------------------------------------------------------------------------------
  90. //-------------------------------------------------------------------------------------------------
  91. void NeutronBlastBehavior::neutronBlastToObject( Object *obj )
  92. {
  93. // early exit check
  94. if ( !obj || obj == getObject() )
  95. return;
  96. // Check for allies and quick exit if we are not suppose to hurt our own.
  97. const NeutronBlastBehaviorModuleData *data = getNeutronBlastBehaviorModuleData();
  98. if (!data->m_affectAllies && getObject()->getRelationship( obj ) == ALLIES)
  99. {
  100. return;
  101. }
  102. // Kill if object is infantry
  103. if (obj->isKindOf(KINDOF_INFANTRY))
  104. {
  105. obj->kill();
  106. }
  107. // Kill all contained if it is a container
  108. ContainModuleInterface *contain = obj->getContain();
  109. if( contain )
  110. {
  111. contain->killAllContained();
  112. }
  113. // Kill pilots of vehicles
  114. if( obj->isKindOf( KINDOF_VEHICLE ) && !obj->isKindOf( KINDOF_DRONE ) )
  115. {
  116. // If the vehicle is a combat bike, kill the whole thing
  117. if ( obj->isKindOf( KINDOF_CLIFF_JUMPER ) )
  118. {
  119. obj->kill();
  120. }
  121. // Just kill the pilot of the vehicle
  122. else
  123. {
  124. // Make it unmanned, so units can easily check the ability to "take control of it"
  125. obj->setDisabled( DISABLED_UNMANNED );
  126. if ( obj->getAI() )
  127. obj->getAI()->aiIdle( CMD_FROM_AI );
  128. TheGameLogic->deselectObject(obj, PLAYERMASK_ALL, TRUE);
  129. // Clear any terrain decals here
  130. Drawable* draw = obj->getDrawable();
  131. if (draw)
  132. draw->setTerrainDecal(TERRAIN_DECAL_NONE);
  133. // Convert it to the neutral team so it renders gray giving visual representation that it is unmanned.
  134. obj->setTeam( ThePlayerList->getNeutralPlayer()->getDefaultTeam() );
  135. }
  136. }
  137. }
  138. // ------------------------------------------------------------------------------------------------
  139. /** CRC */
  140. // ------------------------------------------------------------------------------------------------
  141. void NeutronBlastBehavior::crc( Xfer *xfer )
  142. {
  143. // extend base class
  144. UpdateModule::crc( xfer );
  145. } // end crc
  146. // ------------------------------------------------------------------------------------------------
  147. /** Xfer method
  148. * Version Info:
  149. * 1: Initial version */
  150. // ------------------------------------------------------------------------------------------------
  151. void NeutronBlastBehavior::xfer( Xfer *xfer )
  152. {
  153. // version
  154. XferVersion currentVersion = 1;
  155. XferVersion version = currentVersion;
  156. xfer->xferVersion( &version, currentVersion );
  157. // extend base class
  158. UpdateModule::xfer( xfer );
  159. } // end xfer
  160. // ------------------------------------------------------------------------------------------------
  161. /** Load post process */
  162. // ------------------------------------------------------------------------------------------------
  163. void NeutronBlastBehavior::loadPostProcess( void )
  164. {
  165. // extend base class
  166. UpdateModule::loadPostProcess();
  167. } // end loadPostProcess