TempWeaponBonusHelper.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: TempWeaponBonusHelper.h ////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, June 2003
  25. // Desc: Object helper - Clears Temporary weapon bonus effects
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Module/TempWeaponBonusHelper.h"
  31. #include "GameClient/Drawable.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Weapon.h"
  35. // ------------------------------------------------------------------------------------------------
  36. // ------------------------------------------------------------------------------------------------
  37. TempWeaponBonusHelper::TempWeaponBonusHelper( Thing *thing, const ModuleData *modData ) : ObjectHelper( thing, modData )
  38. {
  39. m_currentBonus = WEAPONBONUSCONDITION_INVALID;
  40. m_frameToRemove = 0;
  41. setWakeFrame(getObject(), UPDATE_SLEEP_FOREVER);
  42. }
  43. // ------------------------------------------------------------------------------------------------
  44. // ------------------------------------------------------------------------------------------------
  45. TempWeaponBonusHelper::~TempWeaponBonusHelper( void )
  46. {
  47. }
  48. // ------------------------------------------------------------------------------------------------
  49. // ------------------------------------------------------------------------------------------------
  50. UpdateSleepTime TempWeaponBonusHelper::update()
  51. {
  52. DEBUG_ASSERTCRASH(m_frameToRemove <= TheGameLogic->getFrame(), ("TempWeaponBonusHelper woke up too soon.") );
  53. clearTempWeaponBonus(); // We are sleep driven, so seeing an update means our timer is ready implicitly
  54. return UPDATE_SLEEP_FOREVER;
  55. }
  56. // ------------------------------------------------------------------------------------------------
  57. // ------------------------------------------------------------------------------------------------
  58. void TempWeaponBonusHelper::clearTempWeaponBonus()
  59. {
  60. if( m_currentBonus != WEAPONBONUSCONDITION_INVALID )
  61. {
  62. getObject()->clearWeaponBonusCondition(m_currentBonus);
  63. m_currentBonus = WEAPONBONUSCONDITION_INVALID;
  64. m_frameToRemove = 0;
  65. if( getObject()->getDrawable() )
  66. {
  67. getObject()->getDrawable()->clearTintStatus(TINT_STATUS_FRENZY);
  68. // if (getObject()->isKindOf(KINDOF_INFANTRY))
  69. // getObject()->getDrawable()->setSecondMaterialPassOpacity( 0.0f );
  70. }
  71. }
  72. }
  73. // ------------------------------------------------------------------------------------------------
  74. // ------------------------------------------------------------------------------------------------
  75. void TempWeaponBonusHelper::doTempWeaponBonus( WeaponBonusConditionType status, UnsignedInt duration )
  76. {
  77. // Clear any different status we may have. Re-getting the same status will just reset the timer
  78. if( m_currentBonus != status )
  79. clearTempWeaponBonus();
  80. getObject()->setWeaponBonusCondition(status);
  81. m_currentBonus = status;
  82. m_frameToRemove = TheGameLogic->getFrame() + duration;
  83. if( getObject()->getDrawable() )
  84. {
  85. getObject()->getDrawable()->setTintStatus(TINT_STATUS_FRENZY);
  86. // if (getObject()->isKindOf(KINDOF_INFANTRY))
  87. // getObject()->getDrawable()->setSecondMaterialPassOpacity( 1.0f );
  88. }
  89. setWakeFrame( getObject(), UPDATE_SLEEP(duration) );
  90. }
  91. // ------------------------------------------------------------------------------------------------
  92. /** CRC */
  93. // ------------------------------------------------------------------------------------------------
  94. void TempWeaponBonusHelper::crc( Xfer *xfer )
  95. {
  96. // object helper crc
  97. ObjectHelper::crc( xfer );
  98. } // end crc
  99. // ------------------------------------------------------------------------------------------------
  100. /** Xfer method
  101. * Version Info;
  102. * 1: Initial version */
  103. // ------------------------------------------------------------------------------------------------
  104. void TempWeaponBonusHelper::xfer( Xfer *xfer )
  105. {
  106. // version
  107. XferVersion currentVersion = 1;
  108. XferVersion version = currentVersion;
  109. xfer->xferVersion( &version, currentVersion );
  110. // object helper base class
  111. ObjectHelper::xfer( xfer );
  112. xfer->xferUser( &m_currentBonus, sizeof(WeaponBonusConditionType) );// an enum
  113. xfer->xferUnsignedInt( &m_frameToRemove );
  114. } // end xfer
  115. // ------------------------------------------------------------------------------------------------
  116. /** Load post process */
  117. // ------------------------------------------------------------------------------------------------
  118. void TempWeaponBonusHelper::loadPostProcess( void )
  119. {
  120. // object helper base class
  121. ObjectHelper::loadPostProcess();
  122. } // end loadPostProcess