W3DSupplyDraw.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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: W3DSupplyDraw.cpp ////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, September 2002
  25. // Desc: Draw module reacts to SupplyStatus setting by hiding an equal number of the specified bone array.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "Common/Xfer.h"
  28. #include "GameClient/Drawable.h"
  29. #include "W3DDevice/GameClient/Module/W3DSupplyDraw.h"
  30. //-------------------------------------------------------------------------------------------------
  31. W3DSupplyDrawModuleData::W3DSupplyDrawModuleData()
  32. {
  33. }
  34. //-------------------------------------------------------------------------------------------------
  35. W3DSupplyDrawModuleData::~W3DSupplyDrawModuleData()
  36. {
  37. }
  38. //-------------------------------------------------------------------------------------------------
  39. void W3DSupplyDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
  40. {
  41. W3DModelDrawModuleData::buildFieldParse(p);
  42. static const FieldParse dataFieldParse[] =
  43. {
  44. { "SupplyBonePrefix", INI::parseAsciiString, NULL, offsetof(W3DSupplyDrawModuleData, m_supplyBonePrefix) },
  45. { 0, 0, 0, 0 }
  46. };
  47. p.add(dataFieldParse);
  48. }
  49. //-------------------------------------------------------------------------------------------------
  50. //-------------------------------------------------------------------------------------------------
  51. W3DSupplyDraw::W3DSupplyDraw( Thing *thing, const ModuleData* moduleData ) : W3DModelDraw( thing, moduleData )
  52. {
  53. m_totalBones = -1;
  54. m_lastNumberShown = 0;
  55. }
  56. //-------------------------------------------------------------------------------------------------
  57. W3DSupplyDraw::~W3DSupplyDraw()
  58. {
  59. }
  60. void W3DSupplyDraw::updateDrawModuleSupplyStatus( Int maxSupply, Int currentSupply )
  61. {
  62. W3DModelDraw::updateDrawModuleSupplyStatus( maxSupply, currentSupply );
  63. AsciiString boneName = getW3DSupplyDrawModuleData()->m_supplyBonePrefix;
  64. if( m_totalBones == -1 )
  65. {
  66. m_totalBones = getDrawable()->getPristineBonePositions( boneName.str(), 1, NULL, NULL, INT_MAX );// The last arg is to guard the size of the arrays. I am not passing any in, I am just counting bones.
  67. m_lastNumberShown = m_totalBones;
  68. }
  69. // Figure the % of our bones we should show, and if it is a different % than last time
  70. // start showing and hiding them.
  71. Int bonesToShow = ceil(m_totalBones * ( currentSupply / (float)maxSupply ));
  72. bonesToShow = min( bonesToShow, m_totalBones );
  73. if( bonesToShow != m_lastNumberShown )
  74. {
  75. // Show/hide the bones that are now different, the indices between last and now (low, high].
  76. Int lowIndex = min( m_lastNumberShown, bonesToShow );
  77. Int highIndex = max( m_lastNumberShown, bonesToShow );
  78. Bool hide = bonesToShow < m_lastNumberShown;
  79. Int currentIndex = lowIndex + 1;
  80. std::vector<ModelConditionInfo::HideShowSubObjInfo> boneVector;
  81. while( currentIndex <= highIndex )
  82. {
  83. char buffer[16];
  84. sprintf( buffer, "%s%02d", boneName.str(), currentIndex );
  85. ModelConditionInfo::HideShowSubObjInfo info;
  86. info.hide = hide;
  87. info.subObjName = buffer;
  88. boneVector.push_back(info);
  89. ++currentIndex;
  90. }
  91. doHideShowSubObjs(&boneVector);
  92. m_lastNumberShown = bonesToShow;
  93. }
  94. }
  95. // ------------------------------------------------------------------------------------------------
  96. /** CRC */
  97. // ------------------------------------------------------------------------------------------------
  98. void W3DSupplyDraw::crc( Xfer *xfer )
  99. {
  100. // extend base class
  101. W3DModelDraw::crc( xfer );
  102. } // end crc
  103. // ------------------------------------------------------------------------------------------------
  104. /** Xfer method
  105. * Version Info:
  106. * 1: Initial version */
  107. // ------------------------------------------------------------------------------------------------
  108. void W3DSupplyDraw::xfer( Xfer *xfer )
  109. {
  110. // version
  111. XferVersion currentVersion = 1;
  112. XferVersion version = currentVersion;
  113. xfer->xferVersion( &version, currentVersion );
  114. // extend base class
  115. W3DModelDraw::xfer( xfer );
  116. // Graham says there's no data to save here
  117. } // end xfer
  118. // ------------------------------------------------------------------------------------------------
  119. /** Load post process */
  120. // ------------------------------------------------------------------------------------------------
  121. void W3DSupplyDraw::loadPostProcess( void )
  122. {
  123. // extend base class
  124. W3DModelDraw::loadPostProcess();
  125. } // end loadPostProcess