FloatUpdate.cpp 6.0 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: FloatUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, May 2002
  25. // Desc: Float on top of da water!!!
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Xfer.h"
  30. #include "GameLogic/Object.h"
  31. #include "GameLogic/TerrainLogic.h"
  32. #include "GameLogic/Module/FloatUpdate.h"
  33. #include "GameLogic/GameLogic.h"
  34. #include "GameClient/Drawable.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. FloatUpdateModuleData::FloatUpdateModuleData( void )
  43. {
  44. m_enabled = FALSE;
  45. } // end FloatUpdateModuleData
  46. // ------------------------------------------------------------------------------------------------
  47. // ------------------------------------------------------------------------------------------------
  48. /*static*/ void FloatUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  49. {
  50. UpdateModuleData::buildFieldParse( p );
  51. static const FieldParse dataFieldParse[] =
  52. {
  53. { "Enabled", INI::parseBool, NULL, offsetof( FloatUpdateModuleData, m_enabled ) },
  54. { 0, 0, 0, 0 }
  55. };
  56. p.add(dataFieldParse);
  57. } // end buildFieldParse
  58. ///////////////////////////////////////////////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////////////////////////
  61. // ------------------------------------------------------------------------------------------------
  62. // ------------------------------------------------------------------------------------------------
  63. FloatUpdate::FloatUpdate( Thing *thing, const ModuleData *moduleData )
  64. :UpdateModule( thing, moduleData )
  65. {
  66. // save our initial enabled status based on INI settings
  67. m_enabled = ((FloatUpdateModuleData *)moduleData)->m_enabled;
  68. } // end FloatUpdate
  69. // ------------------------------------------------------------------------------------------------
  70. // ------------------------------------------------------------------------------------------------
  71. FloatUpdate::~FloatUpdate( void )
  72. {
  73. } // end ~FloatUpdate
  74. // ------------------------------------------------------------------------------------------------
  75. // ------------------------------------------------------------------------------------------------
  76. UpdateSleepTime FloatUpdate::update( void )
  77. {
  78. /// @todo srj use SLEEPY_UPDATE here
  79. // if we're not enabled, do nothing
  80. if( m_enabled == TRUE )
  81. {
  82. // get object position
  83. const Coord3D *pos = getObject()->getPosition();
  84. // get the height of the water here
  85. Real waterZ;
  86. TheTerrainLogic->isUnderwater( pos->x, pos->y, &waterZ );
  87. // snap to the water surface
  88. Coord3D newPos;
  89. newPos.x = pos->x;
  90. newPos.y = pos->y;
  91. newPos.z = waterZ;
  92. getObject()->setPosition( &newPos );
  93. }
  94. Drawable *draw = getObject()->getDrawable();
  95. if (draw)
  96. {
  97. Real angle = INT_TO_REAL(TheGameLogic->getFrame());
  98. Real yaw = sin(angle * 0.0291f) * 0.05f;
  99. Real pitch = sin(angle * 0.0515f) * 0.05f;
  100. Matrix3D mx = *draw->getInstanceMatrix();
  101. Real zRot = mx.Get_Z_Rotation();
  102. mx.Make_Identity();
  103. mx.Rotate_Z(zRot);
  104. mx.Rotate_Y(yaw);
  105. mx.Rotate_X(pitch);
  106. draw->setInstanceMatrix(&mx);
  107. }
  108. return UPDATE_SLEEP_NONE;
  109. } // end update
  110. // ------------------------------------------------------------------------------------------------
  111. /** CRC */
  112. // ------------------------------------------------------------------------------------------------
  113. void FloatUpdate::crc( Xfer *xfer )
  114. {
  115. // extend base class
  116. UpdateModule::crc( xfer );
  117. } // end crc
  118. // ------------------------------------------------------------------------------------------------
  119. /** Xfer method
  120. * Version Info:
  121. * 1: Initial version */
  122. // ------------------------------------------------------------------------------------------------
  123. void FloatUpdate::xfer( Xfer *xfer )
  124. {
  125. // version
  126. XferVersion currentVersion = 1;
  127. XferVersion version = currentVersion;
  128. xfer->xferVersion( &version, currentVersion );
  129. // extend base class
  130. UpdateModule::xfer( xfer );
  131. // enabled
  132. xfer->xferBool( &m_enabled );
  133. } // end xfer
  134. // ------------------------------------------------------------------------------------------------
  135. /** Load post process */
  136. // ------------------------------------------------------------------------------------------------
  137. void FloatUpdate::loadPostProcess( void )
  138. {
  139. // extend base class
  140. UpdateModule::loadPostProcess();
  141. } // end loadPostProcess