DemoralizeSpecialPower.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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: DemoralizeSpecialPower.cpp ///////////////////////////////////////////////////////////////
  24. // Author: Colin Day, July 2002
  25. // Desc: Demoralize
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #ifdef ALLOW_DEMORALIZE
  30. #include "Common/Xfer.h"
  31. #include "GameClient/FXList.h"
  32. #include "GameClient/InGameUI.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/PartitionManager.h"
  35. #include "GameLogic/Module/AIUpdate.h"
  36. #include "GameLogic/Module/ContainModule.h"
  37. #include "GameLogic/Module/DemoralizeSpecialPower.h"
  38. // ------------------------------------------------------------------------------------------------
  39. // ------------------------------------------------------------------------------------------------
  40. DemoralizeSpecialPowerModuleData::DemoralizeSpecialPowerModuleData( void )
  41. {
  42. m_baseRange = 0.0f;
  43. m_bonusRangePerCaptured = 0.0f;
  44. m_maxRange = 0.0f;
  45. m_baseDurationInFrames = 0;
  46. m_bonusDurationPerCapturedInFrames = 0;
  47. m_maxDurationInFrames = 0;
  48. m_fxList = NULL;
  49. } // end DemoralizeSpecialPowerModuleData
  50. // ------------------------------------------------------------------------------------------------
  51. // ------------------------------------------------------------------------------------------------
  52. void DemoralizeSpecialPowerModuleData::buildFieldParse( MultiIniFieldParse &p )
  53. {
  54. SpecialPowerModuleData::buildFieldParse( p );
  55. static const FieldParse dataFieldParse[] =
  56. {
  57. { "BaseRange", INI::parseReal, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_baseRange ) },
  58. { "BonusRangePerCaptured", INI::parseReal, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_bonusRangePerCaptured ) },
  59. { "MaxRange", INI::parseReal, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_maxRange ) },
  60. { "BaseDuration", INI::parseDurationUnsignedInt, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_baseDurationInFrames ) },
  61. { "BonusDurationPerCaptured", INI::parseDurationUnsignedInt, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_bonusDurationPerCapturedInFrames ) },
  62. { "MaxDuration", INI::parseDurationUnsignedInt, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_maxDurationInFrames ) },
  63. { "FXList", INI::parseFXList, NULL, offsetof( DemoralizeSpecialPowerModuleData, m_fxList ) },
  64. { 0, 0, 0, 0 }
  65. };
  66. p.add( dataFieldParse );
  67. } // end buildFieldParse
  68. ///////////////////////////////////////////////////////////////////////////////////////////////////
  69. ///////////////////////////////////////////////////////////////////////////////////////////////////
  70. ///////////////////////////////////////////////////////////////////////////////////////////////////
  71. // ------------------------------------------------------------------------------------------------
  72. // ------------------------------------------------------------------------------------------------
  73. DemoralizeSpecialPower::DemoralizeSpecialPower( Thing *thing, const ModuleData *moduleData )
  74. : SpecialPowerModule( thing, moduleData )
  75. {
  76. } // end DemoralizeSpecialPower
  77. // ------------------------------------------------------------------------------------------------
  78. // ------------------------------------------------------------------------------------------------
  79. DemoralizeSpecialPower::~DemoralizeSpecialPower( void )
  80. {
  81. } // end ~DemoralizeSpecialPower
  82. // ------------------------------------------------------------------------------------------------
  83. // ------------------------------------------------------------------------------------------------
  84. void DemoralizeSpecialPower::doSpecialPowerAtLocation( const Coord3D *loc, Real angle, UnsignedInt commandOptions )
  85. {
  86. if (getObject()->isDisabled())
  87. return;
  88. // sanity
  89. if( loc == NULL )
  90. return;
  91. // call the base class action cause we are *EXTENDING* functionality
  92. SpecialPowerModule::doSpecialPowerAtLocation( loc, angle, commandOptions );
  93. // the source of my fiendish power
  94. Object *source = getObject();
  95. // get module data
  96. const DemoralizeSpecialPowerModuleData *modData = getDemoralizeSpecialPowerModuleData();
  97. //
  98. // the demoralize special power increases in range and duration of effect the more
  99. // units we have captured within us
  100. //
  101. UnsignedInt duration = modData->m_baseDurationInFrames;
  102. Real range = modData->m_baseRange;
  103. ContainModuleInterface *contain = source->getContain();
  104. if( contain )
  105. {
  106. // for every captured unit we get a bonus
  107. duration += contain->getContainCount() * modData->m_bonusDurationPerCapturedInFrames;
  108. // cap at the max
  109. if( duration > modData->m_maxDurationInFrames )
  110. duration = modData->m_maxDurationInFrames;
  111. // increase the range for every prisoner we got
  112. range += contain->getContainCount() * modData->m_bonusRangePerCaptured;
  113. // cap at the max
  114. if( range > modData->m_maxRange )
  115. range = modData->m_maxRange;
  116. } // end if
  117. // scan the objects in the area range and demoralize them
  118. PartitionFilterRelationship filter1( source, PartitionFilterRelationship::ALLOW_ENEMIES |
  119. PartitionFilterRelationship::ALLOW_NEUTRAL );
  120. PartitionFilterAcceptByKindOf filter2( MAKE_KINDOF_MASK( KINDOF_INFANTRY ),
  121. KINDOFMASK_NONE );
  122. PartitionFilterSameMapStatus filterMapStatus(source);
  123. PartitionFilter *filters[] = { &filter1, &filter2, &filterMapStatus, NULL };
  124. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( loc,
  125. range,
  126. FROM_CENTER_2D,
  127. filters );
  128. MemoryPoolObjectHolder hold( iter );
  129. AIUpdateInterface *ai;
  130. for( Object *obj = iter->first(); obj; obj = iter->next() )
  131. {
  132. // demoralize only affects with ai of course
  133. ai = obj->getAIUpdateInterface();
  134. if( ai )
  135. ai->setDemoralized( duration );
  136. } // end for obj
  137. // play an effect at the destination location
  138. if( modData->m_fxList )
  139. {
  140. // execute FX
  141. FXList::doFXPos( modData->m_fxList, loc );
  142. } // end if
  143. } // end doSpecialPowerAtLocation
  144. // ------------------------------------------------------------------------------------------------
  145. // ------------------------------------------------------------------------------------------------
  146. void DemoralizeSpecialPower::doSpecialPowerAtObject( const Object *obj, Real angle, UnsignedInt commandOptions )
  147. {
  148. if (getObject()->isDisabled())
  149. return;
  150. if( obj )
  151. doSpecialPowerAtLocation( obj->getPosition(), angle, commandOptions );
  152. } // end doSpecialPowerAtObject
  153. // ------------------------------------------------------------------------------------------------
  154. /** CRC */
  155. // ------------------------------------------------------------------------------------------------
  156. void DemoralizeSpecialPower::crc( Xfer *xfer )
  157. {
  158. // extend base class
  159. SpecialPowerModule::crc( xfer );
  160. } // end crc
  161. // ------------------------------------------------------------------------------------------------
  162. /** Xfer method
  163. * Version Info:
  164. * 1: Initial version */
  165. // ------------------------------------------------------------------------------------------------
  166. void DemoralizeSpecialPower::xfer( Xfer *xfer )
  167. {
  168. // version
  169. XferVersion currentVersion = 1;
  170. XferVersion version = currentVersion;
  171. xfer->xferVersion( &version, currentVersion );
  172. // extend base class
  173. SpecialPowerModule::xfer( xfer );
  174. } // end xfer
  175. // ------------------------------------------------------------------------------------------------
  176. /** Load post process */
  177. // ------------------------------------------------------------------------------------------------
  178. void DemoralizeSpecialPower::loadPostProcess( void )
  179. {
  180. // extend base class
  181. SpecialPowerModule::loadPostProcess();
  182. } // end loadPostProcess
  183. #endif // #ifdef ALLOW_DEMORALIZE