SpectreGunshipDeploymentUpdate.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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: SpectreGunshipDeploymentUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Mark Lorenzen, April 2003
  25. // Desc: Update module to handle deployment of the SpectreGunship Generals special power.from command center
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #define DEFINE_DEATH_NAMES
  29. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  30. #include "Common\ThingTemplate.h"
  31. #include "Common\ThingFactory.h"
  32. #include "Common\Player.h"
  33. #include "Common\PlayerList.h"
  34. #include "Common\Xfer.h"
  35. #include "Common\ClientUpdateModule.h"
  36. #include "GameClient\ControlBar.h"
  37. #include "GameClient\GameClient.h"
  38. #include "GameClient\Drawable.h"
  39. #include "GameClient\ParticleSys.h"
  40. #include "GameClient\FXList.h"
  41. #include "GameClient/ParticleSys.h"
  42. #include "GameLogic\Locomotor.h"
  43. #include "GameLogic\GameLogic.h"
  44. #include "GameLogic\PartitionManager.h"
  45. #include "GameLogic\Object.h"
  46. #include "GameLogic\ObjectIter.h"
  47. #include "GameLogic\Weaponset.h"
  48. #include "GameLogic\Weapon.h"
  49. #include "GameLogic\TerrainLogic.h"
  50. #include "GameLogic\Module\SpecialPowerModule.h"
  51. #include "GameLogic\Module\SpectreGunshipDeploymentUpdate.h"
  52. #include "GameLogic\Module\PhysicsUpdate.h"
  53. #include "GameLogic\Module\LaserUpdate.h"
  54. #include "GameLogic\Module\ActiveBody.h"
  55. #include "GameLogic\Module\AIUpdate.h"
  56. #include "GameLogic\Module\ContainModule.h"
  57. #ifdef _INTERNAL
  58. // for occasional debugging...
  59. //#pragma optimize("", off)
  60. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  61. #endif
  62. //-------------------------------------------------------------------------------------------------
  63. //-------------------------------------------------------------------------------------------------
  64. SpectreGunshipDeploymentUpdateModuleData::SpectreGunshipDeploymentUpdateModuleData()
  65. {
  66. m_specialPowerTemplate = NULL;
  67. m_extraRequiredScience = SCIENCE_INVALID;
  68. /******BOTH*******//*BOTH*//******BOTH*******//******BOTH*******/ m_attackAreaRadius = 200.0f;
  69. m_createLoc = CREATE_GUNSHIP_AT_EDGE_FARTHEST_FROM_TARGET;
  70. }
  71. static const char* TheGunshipCreateLocTypeNames[] =
  72. {
  73. "CREATE_AT_EDGE_NEAR_SOURCE",
  74. "CREATE_AT_EDGE_FARTHEST_FROM_SOURCE",
  75. "CREATE_AT_EDGE_NEAR_TARGET",
  76. "CREATE_AT_EDGE_FARTHEST_FROM_TARGET",
  77. NULL
  78. };
  79. static Real zero = 0.0f;
  80. //-------------------------------------------------------------------------------------------------
  81. /*static*/ void SpectreGunshipDeploymentUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  82. {
  83. ModuleData::buildFieldParse(p);
  84. static const FieldParse dataFieldParse[] =
  85. {
  86. { "GunshipTemplateName", INI::parseAsciiString, NULL, offsetof( SpectreGunshipDeploymentUpdateModuleData, m_gunshipTemplateName ) },
  87. { "RequiredScience", INI::parseScience, NULL, offsetof( SpectreGunshipDeploymentUpdateModuleData, m_extraRequiredScience ) },
  88. /******BOTH*******/ { "SpecialPowerTemplate", INI::parseSpecialPowerTemplate, NULL, offsetof( SpectreGunshipDeploymentUpdateModuleData, m_specialPowerTemplate ) },
  89. /*******BOTH******/ { "AttackAreaRadius", INI::parseReal, NULL, offsetof( SpectreGunshipDeploymentUpdateModuleData, m_attackAreaRadius ) },
  90. { "CreateLocation", INI::parseIndexList, TheGunshipCreateLocTypeNames, offsetof( SpectreGunshipDeploymentUpdateModuleData, m_createLoc ) },
  91. { 0, 0, 0, 0 }
  92. };
  93. p.add(dataFieldParse);
  94. }
  95. //-------------------------------------------------------------------------------------------------
  96. SpectreGunshipDeploymentUpdate::SpectreGunshipDeploymentUpdate( Thing *thing, const ModuleData* moduleData ) : SpecialPowerUpdateModule( thing, moduleData )
  97. {
  98. m_specialPowerModule = NULL;
  99. m_gunshipID = INVALID_ID;
  100. }
  101. //-------------------------------------------------------------------------------------------------
  102. SpectreGunshipDeploymentUpdate::~SpectreGunshipDeploymentUpdate( void )
  103. {
  104. }
  105. //-------------------------------------------------------------------------------------------------
  106. // Validate that we have the necessary data from the ini file.
  107. //-------------------------------------------------------------------------------------------------
  108. void SpectreGunshipDeploymentUpdate::onObjectCreated()
  109. {
  110. const SpectreGunshipDeploymentUpdateModuleData *data = getSpectreGunshipDeploymentUpdateModuleData();
  111. Object *obj = getObject();
  112. if( !data->m_specialPowerTemplate )
  113. {
  114. DEBUG_CRASH( ("%s object's SpectreGunshipDeploymentUpdate lacks access to the SpecialPowerTemplate. Needs to be specified in ini.", obj->getTemplate()->getName().str() ) );
  115. return;
  116. }
  117. m_specialPowerModule = obj->getSpecialPowerModule( data->m_specialPowerTemplate );
  118. }
  119. //-------------------------------------------------------------------------------------------------
  120. Bool SpectreGunshipDeploymentUpdate::initiateIntentToDoSpecialPower(const SpecialPowerTemplate *specialPowerTemplate, const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions )
  121. {
  122. const SpectreGunshipDeploymentUpdateModuleData *data = getSpectreGunshipDeploymentUpdateModuleData();
  123. if( m_specialPowerModule->getSpecialPowerTemplate() != specialPowerTemplate )
  124. {
  125. //Check to make sure our modules are connected.
  126. return FALSE;
  127. }
  128. // getObject()->getControllingPlayer()->getAcademyStats()->recordSpecialPowerUsed( specialPowerTemplate );
  129. if( !BitTest( commandOptions, COMMAND_FIRED_BY_SCRIPT ) )
  130. {
  131. /******CHANGE*******/ m_initialTargetPosition.set( targetPos );
  132. }
  133. else
  134. {
  135. UnsignedInt now = TheGameLogic->getFrame();
  136. m_specialPowerModule->setReadyFrame( now );
  137. /******CHANGE*******/ m_initialTargetPosition.set( targetPos );
  138. // setLogicalStatus( GUNSHIPDEPLOY_STATUS_INSERTING );
  139. }
  140. Object *newGunship = TheGameLogic->findObjectByID( m_gunshipID );
  141. const ThingTemplate *gunshipTemplate = TheThingFactory->findTemplate( data->m_gunshipTemplateName );
  142. if( newGunship != NULL )
  143. {
  144. // disengageAndDepartAO( newGunship );
  145. m_gunshipID = INVALID_ID;
  146. newGunship = NULL;
  147. }
  148. // Lets make a gunship, since we have none.
  149. {
  150. newGunship = TheThingFactory->newObject( gunshipTemplate, getObject()->getTeam() );
  151. }
  152. DEBUG_ASSERTCRASH( newGunship, ("SpecterGunshipUpdate failed to find or create a gunship object"));
  153. if ( newGunship )
  154. {
  155. //PRODUCER
  156. newGunship->setProducer( getObject() );
  157. //POSITION
  158. Coord3D creationCoord;
  159. switch (data->m_createLoc)
  160. {
  161. case CREATE_GUNSHIP_AT_EDGE_NEAR_SOURCE:
  162. creationCoord = TheTerrainLogic->findClosestEdgePoint( getObject()->getPosition() );
  163. break;
  164. case CREATE_GUNSHIP_AT_EDGE_FARTHEST_FROM_SOURCE:
  165. creationCoord = TheTerrainLogic->findFarthestEdgePoint( getObject()->getPosition() );
  166. break;
  167. case CREATE_GUNSHIP_AT_EDGE_NEAR_TARGET:
  168. creationCoord = TheTerrainLogic->findClosestEdgePoint(targetPos);
  169. break;
  170. case CREATE_GUNSHIP_AT_EDGE_FARTHEST_FROM_TARGET:
  171. default:
  172. creationCoord = TheTerrainLogic->findFarthestEdgePoint(targetPos);
  173. break;
  174. }
  175. // HERE WE NEED TO CREATE THE POINT FURTHER OFF THE MAP SO WE CANT SEE THE LAME HOVER AND ACCELLERATE BEHAVIOR
  176. Coord3D deltaToCreationPoint = m_initialTargetPosition;
  177. deltaToCreationPoint.sub( &creationCoord );
  178. Real distanceFromTarget = deltaToCreationPoint.length();
  179. deltaToCreationPoint.normalize();
  180. deltaToCreationPoint.x *= ( distanceFromTarget + data->m_gunshipOrbitRadius );
  181. deltaToCreationPoint.y *= ( distanceFromTarget + data->m_gunshipOrbitRadius );
  182. creationCoord.x = m_initialTargetPosition.x - deltaToCreationPoint.x;
  183. creationCoord.y = m_initialTargetPosition.y - deltaToCreationPoint.y;
  184. Real preferredElevation = newGunship->getAI()->getCurLocomotor()->getPreferredHeight();
  185. creationCoord.z = preferredElevation;
  186. newGunship->setPosition( &creationCoord );
  187. //ORIENTATION
  188. Real orient = atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x);
  189. newGunship->setOrientation( orient );
  190. // ID
  191. m_gunshipID = newGunship->getID();
  192. // FIRE THE SPECIAL POWER OF THE GUNSHIP
  193. SpecialPowerModuleInterface *shipSPMInterface = newGunship->getSpecialPowerModule( specialPowerTemplate );
  194. if( shipSPMInterface )
  195. {
  196. SpecialPowerModule *spModule = (SpecialPowerModule*)shipSPMInterface;
  197. spModule->markSpecialPowerTriggered( &m_initialTargetPosition );
  198. spModule->doSpecialPowerAtLocation( &m_initialTargetPosition, INVALID_ANGLE, commandOptions );
  199. }
  200. // MAKE THE GUNSHIP SELECTED
  201. TheGameLogic->selectObject( newGunship, TRUE, getObject()->getControllingPlayer()->getPlayerMask(), TRUE );
  202. }
  203. SpecialPowerModuleInterface *spmInterface = getObject()->getSpecialPowerModule( specialPowerTemplate );
  204. if( spmInterface )
  205. {
  206. SpecialPowerModule *spModule = (SpecialPowerModule*)spmInterface;
  207. spModule->markSpecialPowerTriggered( &m_initialTargetPosition );
  208. }
  209. return TRUE;
  210. }
  211. //-------------------------------------------------------------------------------------------------
  212. /** The update callback. */
  213. //-------------------------------------------------------------------------------------------------
  214. UpdateSleepTime SpectreGunshipDeploymentUpdate::update()
  215. {
  216. // const SpectreGunshipDeploymentUpdateModuleData *data = getSpectreGunshipDeploymentUpdateModuleData();
  217. Object *me = getObject();
  218. // Abort conditions.
  219. if( me->testStatus(OBJECT_STATUS_SOLD)
  220. || me->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION)
  221. || me->isEffectivelyDead() )
  222. {
  223. return UPDATE_SLEEP_FOREVER;
  224. }
  225. return UPDATE_SLEEP_NONE;
  226. }
  227. // ------------------------------------------------------------------------------------------------
  228. /** CRC */
  229. // ------------------------------------------------------------------------------------------------
  230. void SpectreGunshipDeploymentUpdate::crc( Xfer *xfer )
  231. {
  232. // extend base class
  233. UpdateModule::crc( xfer );
  234. } // end crc
  235. // ------------------------------------------------------------------------------------------------
  236. /** Xfer method
  237. * Version Info:
  238. * 1: Initial version */
  239. // ------------------------------------------------------------------------------------------------
  240. void SpectreGunshipDeploymentUpdate::xfer( Xfer *xfer )
  241. {
  242. // const SpectreGunshipDeploymentUpdateModuleData *data = getSpectreGunshipDeploymentUpdateModuleData();
  243. // version
  244. XferVersion currentVersion = 1;
  245. XferVersion version = currentVersion;
  246. xfer->xferVersion( &version, currentVersion );
  247. // extend base class
  248. UpdateModule::xfer( xfer );
  249. xfer->xferObjectID( &m_gunshipID );
  250. } // end xfer
  251. // ------------------------------------------------------------------------------------------------
  252. /** Load post process */
  253. // ------------------------------------------------------------------------------------------------
  254. void SpectreGunshipDeploymentUpdate::loadPostProcess( void )
  255. {
  256. // extend base class
  257. UpdateModule::loadPostProcess();
  258. } // end loadPostProcess