TechBuildingBehavior.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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: TechBuildingBehavior.cpp /////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, October 2002
  25. // Desc: Tech building basic behavior
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.H"
  29. #include "Common/Player.h"
  30. #include "Common/PlayerList.h"
  31. #include "Common/ThingTemplate.h"
  32. #include "Common/Xfer.h"
  33. #include "GameClient/FXList.h"
  34. #include "GameClient/InGameUI.h"
  35. #include "GameLogic/Module/TechBuildingBehavior.h"
  36. #include "GameLogic/Object.h"
  37. // ------------------------------------------------------------------------------------------------
  38. // ------------------------------------------------------------------------------------------------
  39. TechBuildingBehaviorModuleData::TechBuildingBehaviorModuleData( void )
  40. {
  41. m_pulseFX = NULL;
  42. m_pulseFXRate = 0;
  43. }
  44. // ------------------------------------------------------------------------------------------------
  45. // ------------------------------------------------------------------------------------------------
  46. /*static*/ void TechBuildingBehaviorModuleData::buildFieldParse( MultiIniFieldParse &p )
  47. {
  48. UpdateModuleData::buildFieldParse( p );
  49. static const FieldParse dataFieldParse[] =
  50. {
  51. { "PulseFX", INI::parseFXList, NULL, offsetof( TechBuildingBehaviorModuleData, m_pulseFX ) },
  52. { "PulseFXRate", INI::parseDurationUnsignedInt, NULL, offsetof( TechBuildingBehaviorModuleData, m_pulseFXRate ) },
  53. { 0, 0, 0, 0 }
  54. };
  55. p.add( dataFieldParse );
  56. } // end buildFieldParse
  57. // ------------------------------------------------------------------------------------------------
  58. // ------------------------------------------------------------------------------------------------
  59. TechBuildingBehavior::TechBuildingBehavior( Thing *thing, const ModuleData *modData )
  60. : UpdateModule( thing, modData )
  61. {
  62. //
  63. // setup ourselves so we do at least one update evaluation after the module
  64. // is in the world
  65. //
  66. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  67. }
  68. // ------------------------------------------------------------------------------------------------
  69. // ------------------------------------------------------------------------------------------------
  70. TechBuildingBehavior::~TechBuildingBehavior( void )
  71. {
  72. }
  73. // ------------------------------------------------------------------------------------------------
  74. // ------------------------------------------------------------------------------------------------
  75. UpdateSleepTime TechBuildingBehavior::update( void )
  76. {
  77. Object *us = getObject();
  78. const TechBuildingBehaviorModuleData* d = getTechBuildingBehaviorModuleData();
  79. Bool captured = false;
  80. // update our model condition for the captured status
  81. Player *player = us->getControllingPlayer();
  82. if( player && player->isPlayableSide() )
  83. {
  84. us->setModelConditionState( MODELCONDITION_CAPTURED );
  85. captured = true;
  86. }
  87. else
  88. {
  89. us->clearModelConditionState( MODELCONDITION_CAPTURED );
  90. captured = false;
  91. }
  92. // if we have a pulse fx, and are owned, sleep only a little while, otherwise sleep forever
  93. if (d->m_pulseFX != NULL && d->m_pulseFXRate > 0 && captured)
  94. {
  95. FXList::doFXObj( d->m_pulseFX, us );
  96. return UPDATE_SLEEP(d->m_pulseFXRate);
  97. }
  98. else
  99. {
  100. // now sleep forever my dear
  101. return UPDATE_SLEEP_FOREVER;
  102. }
  103. }
  104. // ------------------------------------------------------------------------------------------------
  105. // ------------------------------------------------------------------------------------------------
  106. void TechBuildingBehavior::onDie( const DamageInfo *damageInfo )
  107. {
  108. //
  109. // put us on the team of the neutral player so no player has any bonus from us
  110. //
  111. Object *us = getObject();
  112. us->setTeam( ThePlayerList->getNeutralPlayer()->getDefaultTeam() );
  113. } // end onDie
  114. // ------------------------------------------------------------------------------------------------
  115. // ------------------------------------------------------------------------------------------------
  116. // ------------------------------------------------------------------------------------------------
  117. // ------------------------------------------------------------------------------------------------
  118. void TechBuildingBehavior::onCapture( Player *oldOwner, Player *newOwner )
  119. {
  120. // wake up next frame so we can re-evaluate our captured status
  121. setWakeFrame( getObject(), UPDATE_SLEEP_NONE );
  122. } // end onCapture
  123. // ------------------------------------------------------------------------------------------------
  124. // ------------------------------------------------------------------------------------------------
  125. void TechBuildingBehavior::crc( Xfer *xfer )
  126. {
  127. // extend base class
  128. UpdateModule::crc( xfer );
  129. } // end crc
  130. // ------------------------------------------------------------------------------------------------
  131. // ------------------------------------------------------------------------------------------------
  132. void TechBuildingBehavior::xfer( Xfer *xfer )
  133. {
  134. // version
  135. XferVersion currentVersion = 1;
  136. XferVersion version = currentVersion;
  137. xfer->xferVersion( &version, currentVersion );
  138. // extend base class
  139. UpdateModule::xfer( xfer );
  140. } // end xfer
  141. // ------------------------------------------------------------------------------------------------
  142. // ------------------------------------------------------------------------------------------------
  143. void TechBuildingBehavior::loadPostProcess( void )
  144. {
  145. // extend base class
  146. UpdateModule::loadPostProcess();
  147. } // end loadPostProcess