FireWeaponPower.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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: FireWeaponPower.h /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Created: August 2003
  34. //
  35. // Filename: FireWeaponPower.cpp
  36. //
  37. // Author: Kris Morness
  38. //
  39. // Purpose: Simply loads and fires a specific weapon controlled by a superweapon timer.
  40. //-----------------------------------------------------------------------------
  41. ///////////////////////////////////////////////////////////////////////////////
  42. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  43. #define DEFINE_WEAPONSLOTTYPE_NAMES //For access to TheWeaponSlotTypeNames
  44. #include "Common/Player.h"
  45. #include "Common/ThingFactory.h"
  46. #include "Common/Xfer.h"
  47. #include "GameLogic/GameLogic.h"
  48. #include "GameLogic/Object.h"
  49. #include "GameLogic/WeaponSet.h"
  50. #include "GameLogic/Module/AIUpdate.h"
  51. #include "GameLogic/Module/FireWeaponPower.h"
  52. #ifdef _INTERNAL
  53. // for occasional debugging...
  54. //#pragma optimize("", off)
  55. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  56. #endif
  57. FireWeaponPowerModuleData::FireWeaponPowerModuleData( void )
  58. {
  59. m_maxShotsToFire = 1;
  60. }
  61. // ------------------------------------------------------------------------------------------------
  62. // ------------------------------------------------------------------------------------------------
  63. /*static*/ void FireWeaponPowerModuleData::buildFieldParse(MultiIniFieldParse& p)
  64. {
  65. SpecialPowerModuleData::buildFieldParse( p );
  66. static const FieldParse dataFieldParse[] =
  67. {
  68. { "MaxShotsToFire", INI::parseUnsignedInt, NULL, offsetof( FireWeaponPowerModuleData, m_maxShotsToFire ) },
  69. { 0, 0, 0, 0 }
  70. };
  71. p.add(dataFieldParse);
  72. } // end buildFieldParse
  73. // ------------------------------------------------------------------------------------------------
  74. FireWeaponPower::FireWeaponPower( Thing *thing, const ModuleData *moduleData )
  75. : SpecialPowerModule( thing, moduleData )
  76. {
  77. }
  78. // ------------------------------------------------------------------------------------------------
  79. FireWeaponPower::~FireWeaponPower( void )
  80. {
  81. }
  82. // ------------------------------------------------------------------------------------------------
  83. void FireWeaponPower::doSpecialPower( UnsignedInt commandOptions )
  84. {
  85. Object *self = getObject();
  86. const FireWeaponPowerModuleData *data = getFireWeaponPowerModuleData();
  87. if( self->isDisabled() )
  88. return;
  89. // call the base class action cause we are *EXTENDING* functionality
  90. SpecialPowerModule::doSpecialPower( commandOptions );
  91. self->reloadAllAmmo( TRUE );
  92. AIUpdateInterface *ai = self->getAI();
  93. if( ai )
  94. {
  95. ai->aiAttackPosition( NULL, data->m_maxShotsToFire, CMD_FROM_AI );
  96. //Order any turrets to attack as well.
  97. for( Int i = 0; i < MAX_TURRETS; i++ )
  98. {
  99. ai->setTurretTargetPosition( (WhichTurretType)i, self->getPosition() );
  100. }
  101. }
  102. }
  103. // ------------------------------------------------------------------------------------------------
  104. void FireWeaponPower::doSpecialPowerAtLocation( const Coord3D *loc, Real angle, UnsignedInt commandOptions )
  105. {
  106. Object *self = getObject();
  107. const FireWeaponPowerModuleData *data = getFireWeaponPowerModuleData();
  108. if( self->isDisabled() )
  109. return;
  110. // call the base class action cause we are *EXTENDING* functionality
  111. SpecialPowerModule::doSpecialPowerAtLocation( loc, angle, commandOptions );
  112. self->reloadAllAmmo( TRUE );
  113. AIUpdateInterface *ai = self->getAI();
  114. if( ai )
  115. {
  116. ai->aiAttackPosition( loc, data->m_maxShotsToFire, CMD_FROM_AI );
  117. //Order any turrets to attack as well.
  118. for( Int i = 0; i < MAX_TURRETS; i++ )
  119. {
  120. ai->setTurretTargetPosition( (WhichTurretType)i, loc );
  121. }
  122. }
  123. }
  124. // ------------------------------------------------------------------------------------------------
  125. void FireWeaponPower::doSpecialPowerAtObject( Object *obj, UnsignedInt commandOptions )
  126. {
  127. Object *self = getObject();
  128. const FireWeaponPowerModuleData *data = getFireWeaponPowerModuleData();
  129. if( self->isDisabled() )
  130. return;
  131. // call the base class action cause we are *EXTENDING* functionality
  132. SpecialPowerModule::doSpecialPowerAtObject( obj, commandOptions );
  133. self->reloadAllAmmo( TRUE );
  134. AIUpdateInterface *ai = self->getAI();
  135. if( ai )
  136. {
  137. ai->aiAttackObject( obj, data->m_maxShotsToFire, CMD_FROM_AI );
  138. //Order any turrets to attack as well.
  139. for( Int i = 0; i < MAX_TURRETS; i++ )
  140. {
  141. ai->setTurretTargetObject( (WhichTurretType)i, obj );
  142. }
  143. }
  144. }
  145. // ------------------------------------------------------------------------------------------------
  146. /** CRC */
  147. // ------------------------------------------------------------------------------------------------
  148. void FireWeaponPower::crc( Xfer *xfer )
  149. {
  150. // extend base class
  151. SpecialPowerModule::crc( xfer );
  152. } // end crc
  153. // ------------------------------------------------------------------------------------------------
  154. /** Xfer method
  155. * Version Info:
  156. * 1: Initial version */
  157. // ------------------------------------------------------------------------------------------------
  158. void FireWeaponPower::xfer( Xfer *xfer )
  159. {
  160. // version
  161. XferVersion currentVersion = 1;
  162. XferVersion version = currentVersion;
  163. xfer->xferVersion( &version, currentVersion );
  164. // extend base class
  165. SpecialPowerModule::xfer( xfer );
  166. } // end xfer
  167. // ------------------------------------------------------------------------------------------------
  168. /** Load post process */
  169. // ------------------------------------------------------------------------------------------------
  170. void FireWeaponPower::loadPostProcess( void )
  171. {
  172. // extend base class
  173. SpecialPowerModule::loadPostProcess();
  174. } // end loadPostProcess