RebuildHoleExposeDie.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: RebuildHoleExposeDie.cpp /////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, June 2002
  25. // Desc: When a structure dies with this module, a rebuild hole will be created in place
  26. // of the structure that will automatically rebuild the structure
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. // INCLUDE FILES //////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Common/Player.h"
  31. #include "Common/PlayerList.h"
  32. #include "Common/ThingFactory.h"
  33. #include "Common/Xfer.h"
  34. #include "GameLogic/AI.h"
  35. #include "GameLogic/AIPathfind.h"
  36. #include "GameLogic/GameLogic.h"
  37. #include "GameLogic/Module/AIUpdate.h"
  38. #include "GameLogic/Module/BodyModule.h"
  39. #include "GameLogic/Module/RebuildHoleBehavior.h"
  40. #include "GameLogic/Module/RebuildHoleExposeDie.h"
  41. #include "GameLogic/Object.h"
  42. #include "GameLogic/ScriptEngine.h"
  43. #include "GameClient/SelectionXlat.h"
  44. #ifdef _INTERNAL
  45. // for occasional debugging...
  46. //#pragma optimize("", off)
  47. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  48. #endif
  49. // ------------------------------------------------------------------------------------------------
  50. // ------------------------------------------------------------------------------------------------
  51. RebuildHoleExposeDieModuleData::RebuildHoleExposeDieModuleData()
  52. {
  53. m_holeMaxHealth = 0.0f;
  54. m_transferAttackers = true;
  55. }
  56. // ------------------------------------------------------------------------------------------------
  57. // ------------------------------------------------------------------------------------------------
  58. /*static*/ void RebuildHoleExposeDieModuleData::buildFieldParse( MultiIniFieldParse &p )
  59. {
  60. DieModuleData::buildFieldParse(p);
  61. static const FieldParse dataFieldParse[] =
  62. {
  63. { "HoleName", INI::parseAsciiString, NULL, offsetof( RebuildHoleExposeDieModuleData, m_holeName ) },
  64. { "HoleMaxHealth", INI::parseReal, NULL, offsetof( RebuildHoleExposeDieModuleData, m_holeMaxHealth ) },
  65. { "TransferAttackers", INI::parseBool, NULL, offsetof( RebuildHoleExposeDieModuleData, m_transferAttackers ) },
  66. { 0, 0, 0, 0 }
  67. };
  68. p.add( dataFieldParse );
  69. } // end buildFieldParse
  70. ///////////////////////////////////////////////////////////////////////////////////////////////////
  71. ///////////////////////////////////////////////////////////////////////////////////////////////////
  72. ///////////////////////////////////////////////////////////////////////////////////////////////////
  73. //-------------------------------------------------------------------------------------------------
  74. //-------------------------------------------------------------------------------------------------
  75. RebuildHoleExposeDie::RebuildHoleExposeDie( Thing *thing, const ModuleData* moduleData )
  76. : DieModule( thing, moduleData )
  77. {
  78. } // end RebuildHoleExposeDie
  79. //-------------------------------------------------------------------------------------------------
  80. //-------------------------------------------------------------------------------------------------
  81. RebuildHoleExposeDie::~RebuildHoleExposeDie( void )
  82. {
  83. } // end ~RebuildHoleExposeDie
  84. //-------------------------------------------------------------------------------------------------
  85. /** The die callback. */
  86. //-------------------------------------------------------------------------------------------------
  87. void RebuildHoleExposeDie::onDie( const DamageInfo *damageInfo )
  88. {
  89. if (!isDieApplicable(damageInfo))
  90. return;
  91. #if defined(_DEBUG) || defined(_INTERNAL) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
  92. if(TheSelectionTranslator->isHandOfGodSelectionMode())
  93. {
  94. if ( getObject()->isKindOf( KINDOF_STRUCTURE ) )
  95. {
  96. if ( damageInfo->in.m_damageType == DAMAGE_UNRESISTABLE )
  97. return;
  98. }
  99. }
  100. #endif
  101. const RebuildHoleExposeDieModuleData *modData = getRebuildHoleExposeDieModuleData();
  102. Object *us = getObject();
  103. //
  104. // if we are being constructed from either the first time or from a hole reconstruction
  105. // we do not "spawn" a hole object
  106. //
  107. if( us->getControllingPlayer() != ThePlayerList->getNeutralPlayer()
  108. && us->getControllingPlayer()->isPlayerActive()
  109. && !us->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
  110. {
  111. Object *hole;
  112. // create the hole
  113. hole = TheThingFactory->newObject( TheThingFactory->findTemplate( modData->m_holeName ),
  114. getObject()->getTeam() );
  115. // put the hole at our position and angle
  116. hole->setPosition( us->getPosition() );
  117. hole->setOrientation( us->getOrientation() );
  118. //
  119. // modify the hole extents to be the same as ours because we need to preserve the
  120. // same amount of space for the rebuilding process
  121. //
  122. hole->setGeometryInfo( us->getGeometryInfo() );
  123. //
  124. // Transfer the building's name to the hole
  125. //
  126. TheScriptEngine->transferObjectName( us->getName(), hole );
  127. //
  128. // add to pathfind map, this really should be wrapped up somewhere in the creation
  129. // pipeline of the object automagically!
  130. //
  131. TheAI->pathfinder()->addObjectToPathfindMap( hole );
  132. // set the health of the hole to that defined by our data
  133. BodyModuleInterface *body = hole->getBodyModule();
  134. body->setMaxHealth( modData->m_holeMaxHealth );
  135. // set the information in the hole about what to build
  136. RebuildHoleBehaviorInterface *rhbi = RebuildHoleBehavior::getRebuildHoleBehaviorInterfaceFromObject( hole );
  137. // sanity
  138. DEBUG_ASSERTCRASH( rhbi, ("RebuildHoleExposeDie: No Rebuild Hole Behavior interface on hole\n") );
  139. // start the rebuild process
  140. if( rhbi )
  141. rhbi->startRebuildProcess( us->getTemplate(), us->getID() );
  142. if (modData->m_transferAttackers)
  143. {
  144. for ( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
  145. {
  146. AIUpdateInterface* ai = obj->getAI();
  147. if (!ai)
  148. continue;
  149. ai->transferAttack(us->getID(), hole->getID());
  150. }
  151. }
  152. } // end if
  153. } // end onDie
  154. // ------------------------------------------------------------------------------------------------
  155. /** CRC */
  156. // ------------------------------------------------------------------------------------------------
  157. void RebuildHoleExposeDie::crc( Xfer *xfer )
  158. {
  159. // extend base class
  160. DieModule::crc( xfer );
  161. } // end crc
  162. // ------------------------------------------------------------------------------------------------
  163. /** Xfer method
  164. * Version Info:
  165. * 1: Initial version */
  166. // ------------------------------------------------------------------------------------------------
  167. void RebuildHoleExposeDie::xfer( Xfer *xfer )
  168. {
  169. // version
  170. XferVersion currentVersion = 1;
  171. XferVersion version = currentVersion;
  172. xfer->xferVersion( &version, currentVersion );
  173. // extend base class
  174. DieModule::xfer( xfer );
  175. } // end xfer
  176. // ------------------------------------------------------------------------------------------------
  177. /** Load post process */
  178. // ------------------------------------------------------------------------------------------------
  179. void RebuildHoleExposeDie::loadPostProcess( void )
  180. {
  181. // extend base class
  182. DieModule::loadPostProcess();
  183. } // end loadPostProcess