WeaponBonusUpdate.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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: WeaponBonusUpdate.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002-2003 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: July 2003
  34. //
  35. // Filename: WeaponBonusUpdate.cpp
  36. //
  37. // author: Graham Smallwood
  38. //
  39. // purpose: Like healing in that it can affect just me or people around,
  40. // except this gives a Weapon Bonus instead of health
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //-----------------------------------------------------------------------------
  45. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  46. //-----------------------------------------------------------------------------
  47. //-----------------------------------------------------------------------------
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. //-----------------------------------------------------------------------------
  50. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  51. #include "GameLogic/Module/WeaponBonusUpdate.h"
  52. #define DEFINE_WEAPONBONUSCONDITION_NAMES
  53. #include "GameLogic/Module/ContainModule.h"
  54. #include "GameLogic/Object.h"
  55. #include "GameLogic/PartitionManager.h"
  56. #include "GameLogic/Weapon.h"
  57. //-----------------------------------------------------------------------------
  58. WeaponBonusUpdateModuleData::WeaponBonusUpdateModuleData()
  59. {
  60. m_requiredAffectKindOf.clear();
  61. m_forbiddenAffectKindOf.clear();
  62. m_bonusDuration = 0;
  63. m_bonusDelay = 0;
  64. m_bonusRange = 0;
  65. m_bonusConditionType = WEAPONBONUSCONDITION_INVALID;
  66. }
  67. //-----------------------------------------------------------------------------
  68. void WeaponBonusUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  69. {
  70. UpdateModuleData::buildFieldParse(p);
  71. static const FieldParse dataFieldParse[] =
  72. {
  73. { "RequiredAffectKindOf", KindOfMaskType::parseFromINI, NULL, offsetof( WeaponBonusUpdateModuleData, m_requiredAffectKindOf ) },
  74. { "ForbiddenAffectKindOf", KindOfMaskType::parseFromINI, NULL, offsetof( WeaponBonusUpdateModuleData, m_forbiddenAffectKindOf ) },
  75. { "BonusDuration", INI::parseDurationUnsignedInt, NULL, offsetof( WeaponBonusUpdateModuleData, m_bonusDuration ) },
  76. { "BonusDelay", INI::parseDurationUnsignedInt, NULL, offsetof( WeaponBonusUpdateModuleData, m_bonusDelay ) },
  77. { "BonusRange", INI::parseReal, NULL, offsetof( WeaponBonusUpdateModuleData, m_bonusRange ) },
  78. { "BonusConditionType", INI::parseIndexList, TheWeaponBonusNames, offsetof( WeaponBonusUpdateModuleData, m_bonusConditionType ) },
  79. { 0, 0, 0, 0 }
  80. };
  81. p.add(dataFieldParse);
  82. }
  83. //-----------------------------------------------------------------------------
  84. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  85. //-----------------------------------------------------------------------------
  86. WeaponBonusUpdate::WeaponBonusUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  87. {
  88. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  89. }
  90. //-------------------------------------------------------------------------------------------------
  91. //-------------------------------------------------------------------------------------------------
  92. WeaponBonusUpdate::~WeaponBonusUpdate( void )
  93. {
  94. }
  95. //-------------------------------------------------------------------------------------------------
  96. //-------------------------------------------------------------------------------------------------
  97. struct tempWeaponBonusData // Hey Steven, bite me! hahahaha _Lowercase_ since Local to the file.
  98. {
  99. WeaponBonusConditionType m_type;
  100. UnsignedInt m_duration;
  101. KindOfMaskType m_requiredMask;
  102. KindOfMaskType m_forbiddenMask;
  103. };
  104. void containIteratingDoTempWeaponBonus( Object *passenger, void *voidData)
  105. {
  106. tempWeaponBonusData *data = (tempWeaponBonusData *)voidData;
  107. if( passenger->isKindOfMulti(data->m_requiredMask, data->m_forbiddenMask) )
  108. passenger->doTempWeaponBonus(data->m_type, data->m_duration);
  109. }
  110. //-------------------------------------------------------------------------------------------------
  111. //-------------------------------------------------------------------------------------------------
  112. UpdateSleepTime WeaponBonusUpdate::update( void )
  113. {
  114. const WeaponBonusUpdateModuleData * data = getWeaponBonusUpdateModuleData();
  115. Object *me = getObject();
  116. PartitionFilterRelationship relationship( me, PartitionFilterRelationship::ALLOW_ALLIES );
  117. PartitionFilterSameMapStatus filterMapStatus(me);
  118. PartitionFilterAlive filterAlive;
  119. // Leaving this here commented out to show that I need to reach valid contents of invalid transports.
  120. // So these checks are on an individual basis, not in the Partition query
  121. // PartitionFilterAcceptByKindOf filterKindof(data->m_requiredAffectKindOf,data->m_forbiddenAffectKindOf);
  122. PartitionFilter *filters[] = { &relationship, &filterAlive, &filterMapStatus, NULL };
  123. // scan objects in our region
  124. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( me->getPosition(),
  125. data->m_bonusRange,
  126. FROM_CENTER_2D,
  127. filters );
  128. MemoryPoolObjectHolder hold( iter );
  129. tempWeaponBonusData weaponBonusData;
  130. weaponBonusData.m_type = data->m_bonusConditionType;
  131. weaponBonusData.m_duration = data->m_bonusDuration;
  132. weaponBonusData.m_requiredMask = data->m_requiredAffectKindOf;
  133. weaponBonusData.m_forbiddenMask = data->m_forbiddenAffectKindOf;
  134. for( Object *currentObj = iter->first(); currentObj != NULL; currentObj = iter->next() )
  135. {
  136. if( currentObj->isKindOfMulti(data->m_requiredAffectKindOf, data->m_forbiddenAffectKindOf) )
  137. {
  138. currentObj->doTempWeaponBonus(data->m_bonusConditionType, data->m_bonusDuration);
  139. }
  140. if( currentObj->getContain() )
  141. {
  142. currentObj->getContain()->iterateContained(containIteratingDoTempWeaponBonus, &weaponBonusData, FALSE);
  143. }
  144. }
  145. return UPDATE_SLEEP(data->m_bonusDelay); // Only need an internal timer if there are external hooks for wakning us up, or a second thing we can do
  146. }
  147. // ------------------------------------------------------------------------------------------------
  148. /** CRC */
  149. // ------------------------------------------------------------------------------------------------
  150. void WeaponBonusUpdate::crc( Xfer *xfer )
  151. {
  152. // extend base class
  153. UpdateModule::crc( xfer );
  154. } // end crc
  155. // ------------------------------------------------------------------------------------------------
  156. /** Xfer method
  157. * Version Info:
  158. * 1: Initial version */
  159. // ------------------------------------------------------------------------------------------------
  160. void WeaponBonusUpdate::xfer( Xfer *xfer )
  161. {
  162. // version
  163. XferVersion currentVersion = 1;
  164. XferVersion version = currentVersion;
  165. xfer->xferVersion( &version, currentVersion );
  166. // extend base class
  167. UpdateModule::xfer( xfer );
  168. } // end xfer
  169. // ------------------------------------------------------------------------------------------------
  170. /** Load post process */
  171. // ------------------------------------------------------------------------------------------------
  172. void WeaponBonusUpdate::loadPostProcess( void )
  173. {
  174. // extend base class
  175. UpdateModule::loadPostProcess();
  176. } // end loadPostProcess