ObjectDefectionHelper.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: ObjectDefectionHelper.cpp ////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, Steven Johnson - September 2002
  25. // Desc: Object helper module
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/MiscAudio.h"
  30. #include "Common/Xfer.h"
  31. #include "GameClient/Drawable.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Module/ObjectDefectionHelper.h"
  35. #ifdef _INTERNAL
  36. // for occasional debugging...
  37. //#pragma optimize("", off)
  38. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  39. #endif
  40. // ------------------------------------------------------------------------------------------------
  41. // ------------------------------------------------------------------------------------------------
  42. ObjectDefectionHelper::~ObjectDefectionHelper( void )
  43. {
  44. }
  45. // ------------------------------------------------------------------------------------------------
  46. // ------------------------------------------------------------------------------------------------
  47. UpdateSleepTime ObjectDefectionHelper::update()
  48. {
  49. Object* obj = getObject();
  50. Drawable* draw = obj->getDrawable();
  51. // if we are here, we should be an undetected defector, but
  52. // just in case someone has changed us behind our backs...
  53. if (!obj->getIsUndetectedDefector())
  54. return UPDATE_SLEEP_FOREVER;
  55. UnsignedInt now = TheGameLogic->getFrame();
  56. if (now >= m_defectionDetectionEnd)
  57. {
  58. obj->friend_setUndetectedDefector(FALSE);
  59. // timer has reached zero, so we flash white once!!!! -- lorenzen
  60. if (draw && m_doDefectorFX)
  61. {
  62. RGBColor white = {1,1,1};
  63. if (draw)
  64. draw->flashAsSelected( &white ); //Whew! that's easier, now, isn't it!
  65. AudioEventRTS defectorVulnerableSound = TheAudio->getMiscAudio()->m_defectorTimerDingSound;
  66. defectorVulnerableSound.setObjectID( obj->getID() );
  67. TheAudio->addAudioEvent(&defectorVulnerableSound);
  68. }
  69. return UPDATE_SLEEP_FOREVER; // hey, we're done.
  70. }
  71. // dead or attacking... our cover is blown.
  72. if( obj->isEffectivelyDead() || obj->getStatusBits().test( OBJECT_STATUS_IS_FIRING_WEAPON ) )
  73. {
  74. // PLEASE NOTE:
  75. // checking the is_attacking statusbit above, only handles weapon related attacks...
  76. // I also set m_undetectedDefector = FALSE in the groupDoSpecialPower[...]( ) functions;
  77. obj->friend_setUndetectedDefector(FALSE);
  78. return UPDATE_SLEEP_FOREVER; // hey, we're done.
  79. }
  80. if (draw && m_doDefectorFX) // skip fx if merely 'invulnerable'
  81. {
  82. Bool lastPhase = ( ((Int)m_defectionDetectionFlashPhase) & 1 );// were we in a flashy phase last frame?
  83. UnsignedInt timeLeft = m_defectionDetectionEnd - now;
  84. m_defectionDetectionFlashPhase += 0.5f * ( 1.0f - ((Real)timeLeft / DEFECTION_DETECTION_TIME_MAX ) );
  85. Bool thisPhase = ( ((Int)m_defectionDetectionFlashPhase) & 1 );// are we in a flashy phase this frame?
  86. if ( lastPhase && ( ! thisPhase ) )
  87. {
  88. draw->flashAsSelected(); //Whew! that's easier, now, isn't it!
  89. AudioEventRTS defectorTimerSound = TheAudio->getMiscAudio()->m_defectorTimerTickSound;
  90. defectorTimerSound.setObjectID( obj->getID() );
  91. TheAudio->addAudioEvent(&defectorTimerSound);
  92. }
  93. }
  94. return UPDATE_SLEEP_NONE;
  95. }
  96. // ------------------------------------------------------------------------------------------------
  97. // ------------------------------------------------------------------------------------------------
  98. void ObjectDefectionHelper::startDefectionTimer(UnsignedInt numFrames, Bool withDefectorFX)
  99. {
  100. Object* obj = getObject();
  101. if (!obj->getIsUndetectedDefector())
  102. {
  103. setWakeFrame(obj, UPDATE_SLEEP_FOREVER);
  104. return;
  105. }
  106. UnsignedInt now = TheGameLogic->getFrame();
  107. m_defectionDetectionStart = now;
  108. m_defectionDetectionEnd = now + numFrames;
  109. m_defectionDetectionFlashPhase = 0.0f;
  110. m_doDefectorFX = withDefectorFX;
  111. setWakeFrame(obj, UPDATE_SLEEP_NONE);
  112. }
  113. // ------------------------------------------------------------------------------------------------
  114. /** CRC */
  115. // ------------------------------------------------------------------------------------------------
  116. void ObjectDefectionHelper::crc( Xfer *xfer )
  117. {
  118. // object helper crc
  119. ObjectHelper::crc( xfer );
  120. } // end crc
  121. // ------------------------------------------------------------------------------------------------
  122. /** Xfer method
  123. * Version Info;
  124. * 1: Initial version */
  125. // ------------------------------------------------------------------------------------------------
  126. void ObjectDefectionHelper::xfer( Xfer *xfer )
  127. {
  128. // version
  129. XferVersion currentVersion = 1;
  130. XferVersion version = currentVersion;
  131. xfer->xferVersion( &version, currentVersion );
  132. // object helper base class
  133. ObjectHelper::xfer( xfer );
  134. // detection start
  135. xfer->xferUnsignedInt( &m_defectionDetectionStart );
  136. // detection end
  137. xfer->xferUnsignedInt( &m_defectionDetectionEnd );
  138. // flash phase
  139. xfer->xferReal( &m_defectionDetectionFlashPhase );
  140. // do defector fx
  141. xfer->xferBool( &m_doDefectorFX );
  142. } // end xfer
  143. // ------------------------------------------------------------------------------------------------
  144. /** Load post process */
  145. // ------------------------------------------------------------------------------------------------
  146. void ObjectDefectionHelper::loadPostProcess( void )
  147. {
  148. // object helper base class
  149. ObjectHelper::loadPostProcess();
  150. } // end loadPostProcess