SmartBombTargetHomingUpdate.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: SmartBombTargetHomingUpdate.cpp /////////////////////////////////////////////////////////////////////////
  24. // Author: Mark Lorenzen, July 2003
  25. // Desc: Update that will fudge a falling object's position just slightly, to make it find its target better
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h"
  29. #include "Common/RandomValue.h"
  30. #include "Common/Xfer.h"
  31. #include "GameLogic/GameLogic.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameLogic/Module/SmartBombTargetHomingUpdate.h"
  34. //-------------------------------------------------------------------------------------------------
  35. //-------------------------------------------------------------------------------------------------
  36. SmartBombTargetHomingUpdate::SmartBombTargetHomingUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
  37. {
  38. m_targetReceived = FALSE;
  39. m_target.zero();
  40. setWakeFrame( getObject(), UPDATE_SLEEP_NONE );
  41. }
  42. //-------------------------------------------------------------------------------------------------
  43. //-------------------------------------------------------------------------------------------------
  44. SmartBombTargetHomingUpdate::~SmartBombTargetHomingUpdate( void )
  45. {
  46. }
  47. //#define CRISS_CROSS_GEOMETRY
  48. //-------------------------------------------------------------------------------------------------
  49. //-------------------------------------------------------------------------------------------------
  50. void SmartBombTargetHomingUpdate::SetTargetPosition( const Coord3D& target )
  51. {
  52. // Ensure that we have been passed a real-world location
  53. DEBUG_ASSERTCRASH( target.length() > 0.0f, ("SmartBombTargetHomingUpdate::SetTargetPosition() received a zero coord") );
  54. if ( ! (target.length() > 0.0f) )
  55. return;
  56. m_target.x = target.x;
  57. m_target.y = target.y;
  58. m_target.z = target.z;
  59. m_targetReceived = TRUE;
  60. }
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. UpdateSleepTime SmartBombTargetHomingUpdate::update( void )
  64. {
  65. if ( ! m_targetReceived )
  66. return UPDATE_SLEEP_NONE;
  67. const SmartBombTargetHomingUpdateModuleData* d = getSmartBombTargetHomingUpdateModuleData();
  68. if ( ! d )
  69. return UPDATE_SLEEP_NONE;
  70. Object *self = getObject();
  71. if ( ! self )
  72. return UPDATE_SLEEP_NONE;
  73. if ( ! self->isSignificantlyAboveTerrain() )
  74. return UPDATE_SLEEP_NONE;
  75. const Coord3D *currentPos = self->getPosition();
  76. Coord3D pos;
  77. pos.zero();
  78. Real statusCoeff = MAX( 0.0f, MIN( 1.0f, d->m_courseCorrectionScalar));
  79. Real targetCoeff = 1.0f - statusCoeff;
  80. pos.x = m_target.x * targetCoeff + currentPos->x * statusCoeff;
  81. pos.y = m_target.y * targetCoeff + currentPos->y * statusCoeff;
  82. pos.z = currentPos->z;
  83. self->setPosition( &pos );
  84. return UPDATE_SLEEP_NONE;
  85. }
  86. // ------------------------------------------------------------------------------------------------
  87. /** CRC */
  88. // ------------------------------------------------------------------------------------------------
  89. void SmartBombTargetHomingUpdate::crc( Xfer *xfer )
  90. {
  91. // extend base class
  92. UpdateModule::crc( xfer );
  93. } // end crc
  94. // ------------------------------------------------------------------------------------------------
  95. /** Xfer method
  96. * Version Info:
  97. * 1: Initial version */
  98. // ------------------------------------------------------------------------------------------------
  99. void SmartBombTargetHomingUpdate::xfer( Xfer *xfer )
  100. {
  101. // version
  102. XferVersion currentVersion = 1;
  103. XferVersion version = currentVersion;
  104. xfer->xferVersion( &version, currentVersion );
  105. // extend base class
  106. UpdateModule::xfer( xfer );
  107. } // end xfer
  108. // ------------------------------------------------------------------------------------------------
  109. /** Load post process */
  110. // ------------------------------------------------------------------------------------------------
  111. void SmartBombTargetHomingUpdate::loadPostProcess( void )
  112. {
  113. // extend base class
  114. UpdateModule::loadPostProcess();
  115. } // end loadPostProcess