ObjectDefectionHelper.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. ** Command & Conquer Generals(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() ||
  73. (obj->getStatusBits() & OBJECT_STATUS_IS_FIRING_WEAPON)!= 0)
  74. {
  75. // PLEASE NOTE:
  76. // checking the is_attacking statusbit above, only handles weapon related attacks...
  77. // I also set m_undetectedDefector = FALSE in the groupDoSpecialPower[...]( ) functions;
  78. obj->friend_setUndetectedDefector(FALSE);
  79. return UPDATE_SLEEP_FOREVER; // hey, we're done.
  80. }
  81. if (draw && m_doDefectorFX) // skip fx if merely 'invulnerable'
  82. {
  83. Bool lastPhase = ( ((Int)m_defectionDetectionFlashPhase) & 1 );// were we in a flashy phase last frame?
  84. UnsignedInt timeLeft = m_defectionDetectionEnd - now;
  85. m_defectionDetectionFlashPhase += 0.5f * ( 1.0f - ((Real)timeLeft / DEFECTION_DETECTION_TIME_MAX ) );
  86. Bool thisPhase = ( ((Int)m_defectionDetectionFlashPhase) & 1 );// are we in a flashy phase this frame?
  87. if ( lastPhase && ( ! thisPhase ) )
  88. {
  89. draw->flashAsSelected(); //Whew! that's easier, now, isn't it!
  90. AudioEventRTS defectorTimerSound = TheAudio->getMiscAudio()->m_defectorTimerTickSound;
  91. defectorTimerSound.setObjectID( obj->getID() );
  92. TheAudio->addAudioEvent(&defectorTimerSound);
  93. }
  94. }
  95. return UPDATE_SLEEP_NONE;
  96. }
  97. // ------------------------------------------------------------------------------------------------
  98. // ------------------------------------------------------------------------------------------------
  99. void ObjectDefectionHelper::startDefectionTimer(UnsignedInt numFrames, Bool withDefectorFX)
  100. {
  101. Object* obj = getObject();
  102. if (!obj->getIsUndetectedDefector())
  103. {
  104. setWakeFrame(obj, UPDATE_SLEEP_FOREVER);
  105. return;
  106. }
  107. UnsignedInt now = TheGameLogic->getFrame();
  108. m_defectionDetectionStart = now;
  109. m_defectionDetectionEnd = now + numFrames;
  110. m_defectionDetectionFlashPhase = 0.0f;
  111. m_doDefectorFX = withDefectorFX;
  112. setWakeFrame(obj, UPDATE_SLEEP_NONE);
  113. }
  114. // ------------------------------------------------------------------------------------------------
  115. /** CRC */
  116. // ------------------------------------------------------------------------------------------------
  117. void ObjectDefectionHelper::crc( Xfer *xfer )
  118. {
  119. // object helper crc
  120. ObjectHelper::crc( xfer );
  121. } // end crc
  122. // ------------------------------------------------------------------------------------------------
  123. /** Xfer method
  124. * Version Info;
  125. * 1: Initial version */
  126. // ------------------------------------------------------------------------------------------------
  127. void ObjectDefectionHelper::xfer( Xfer *xfer )
  128. {
  129. // version
  130. XferVersion currentVersion = 1;
  131. XferVersion version = currentVersion;
  132. xfer->xferVersion( &version, currentVersion );
  133. // object helper base class
  134. ObjectHelper::xfer( xfer );
  135. // detection start
  136. xfer->xferUnsignedInt( &m_defectionDetectionStart );
  137. // detection end
  138. xfer->xferUnsignedInt( &m_defectionDetectionEnd );
  139. // flash phase
  140. xfer->xferReal( &m_defectionDetectionFlashPhase );
  141. // do defector fx
  142. xfer->xferBool( &m_doDefectorFX );
  143. } // end xfer
  144. // ------------------------------------------------------------------------------------------------
  145. /** Load post process */
  146. // ------------------------------------------------------------------------------------------------
  147. void ObjectDefectionHelper::loadPostProcess( void )
  148. {
  149. // object helper base class
  150. ObjectHelper::loadPostProcess();
  151. } // end loadPostProcess