RebuildHoleExposeDie.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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: 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. // ------------------------------------------------------------------------------------------------
  44. // ------------------------------------------------------------------------------------------------
  45. RebuildHoleExposeDieModuleData::RebuildHoleExposeDieModuleData()
  46. {
  47. m_holeMaxHealth = 0.0f;
  48. m_transferAttackers = true;
  49. }
  50. // ------------------------------------------------------------------------------------------------
  51. // ------------------------------------------------------------------------------------------------
  52. /*static*/ void RebuildHoleExposeDieModuleData::buildFieldParse( MultiIniFieldParse &p )
  53. {
  54. DieModuleData::buildFieldParse(p);
  55. static const FieldParse dataFieldParse[] =
  56. {
  57. { "HoleName", INI::parseAsciiString, NULL, offsetof( RebuildHoleExposeDieModuleData, m_holeName ) },
  58. { "HoleMaxHealth", INI::parseReal, NULL, offsetof( RebuildHoleExposeDieModuleData, m_holeMaxHealth ) },
  59. { "TransferAttackers", INI::parseBool, NULL, offsetof( RebuildHoleExposeDieModuleData, m_transferAttackers ) },
  60. { 0, 0, 0, 0 }
  61. };
  62. p.add( dataFieldParse );
  63. } // end buildFieldParse
  64. ///////////////////////////////////////////////////////////////////////////////////////////////////
  65. ///////////////////////////////////////////////////////////////////////////////////////////////////
  66. ///////////////////////////////////////////////////////////////////////////////////////////////////
  67. //-------------------------------------------------------------------------------------------------
  68. //-------------------------------------------------------------------------------------------------
  69. RebuildHoleExposeDie::RebuildHoleExposeDie( Thing *thing, const ModuleData* moduleData )
  70. : DieModule( thing, moduleData )
  71. {
  72. } // end RebuildHoleExposeDie
  73. //-------------------------------------------------------------------------------------------------
  74. //-------------------------------------------------------------------------------------------------
  75. RebuildHoleExposeDie::~RebuildHoleExposeDie( void )
  76. {
  77. } // end ~RebuildHoleExposeDie
  78. //-------------------------------------------------------------------------------------------------
  79. /** The die callback. */
  80. //-------------------------------------------------------------------------------------------------
  81. void RebuildHoleExposeDie::onDie( const DamageInfo *damageInfo )
  82. {
  83. if (!isDieApplicable(damageInfo))
  84. return;
  85. const RebuildHoleExposeDieModuleData *modData = getRebuildHoleExposeDieModuleData();
  86. Object *us = getObject();
  87. //
  88. // if we are being constructed from either the first time or from a hole reconstruction
  89. // we do not "spawn" a hole object
  90. //
  91. if( us->getControllingPlayer() != ThePlayerList->getNeutralPlayer() && (us->getControllingPlayer()->isPlayerActive()) &&
  92. (BitTest( us->getStatusBits(), OBJECT_STATUS_UNDER_CONSTRUCTION ) == FALSE ))
  93. {
  94. Object *hole;
  95. // create the hole
  96. hole = TheThingFactory->newObject( TheThingFactory->findTemplate( modData->m_holeName ),
  97. getObject()->getTeam() );
  98. // put the hole at our position and angle
  99. hole->setPosition( us->getPosition() );
  100. hole->setOrientation( us->getOrientation() );
  101. //
  102. // modify the hole extents to be the same as ours because we need to preserve the
  103. // same amount of space for the rebuilding process
  104. //
  105. hole->setGeometryInfo( us->getGeometryInfo() );
  106. //
  107. // Transfer the building's name to the hole
  108. //
  109. TheScriptEngine->transferObjectName( us->getName(), hole );
  110. //
  111. // add to pathfind map, this really should be wrapped up somewhere in the creation
  112. // pipeline of the object automagically!
  113. //
  114. TheAI->pathfinder()->addObjectToPathfindMap( hole );
  115. // set the health of the hole to that defined by our data
  116. BodyModuleInterface *body = hole->getBodyModule();
  117. body->setMaxHealth( modData->m_holeMaxHealth );
  118. // set the information in the hole about what to build
  119. RebuildHoleBehaviorInterface *rhbi = RebuildHoleBehavior::getRebuildHoleBehaviorInterfaceFromObject( hole );
  120. // sanity
  121. DEBUG_ASSERTCRASH( rhbi, ("RebuildHoleExposeDie: No Rebuild Hole Behavior interface on hole\n") );
  122. // start the rebuild process
  123. if( rhbi )
  124. rhbi->startRebuildProcess( us->getTemplate(), us->getID() );
  125. if (modData->m_transferAttackers)
  126. {
  127. for ( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
  128. {
  129. AIUpdateInterface* ai = obj->getAI();
  130. if (!ai)
  131. continue;
  132. ai->transferAttack(us->getID(), hole->getID());
  133. }
  134. }
  135. } // end if
  136. } // end onDie
  137. // ------------------------------------------------------------------------------------------------
  138. /** CRC */
  139. // ------------------------------------------------------------------------------------------------
  140. void RebuildHoleExposeDie::crc( Xfer *xfer )
  141. {
  142. // extend base class
  143. DieModule::crc( xfer );
  144. } // end crc
  145. // ------------------------------------------------------------------------------------------------
  146. /** Xfer method
  147. * Version Info:
  148. * 1: Initial version */
  149. // ------------------------------------------------------------------------------------------------
  150. void RebuildHoleExposeDie::xfer( Xfer *xfer )
  151. {
  152. // version
  153. XferVersion currentVersion = 1;
  154. XferVersion version = currentVersion;
  155. xfer->xferVersion( &version, currentVersion );
  156. // extend base class
  157. DieModule::xfer( xfer );
  158. } // end xfer
  159. // ------------------------------------------------------------------------------------------------
  160. /** Load post process */
  161. // ------------------------------------------------------------------------------------------------
  162. void RebuildHoleExposeDie::loadPostProcess( void )
  163. {
  164. // extend base class
  165. DieModule::loadPostProcess();
  166. } // end loadPostProcess