HiveStructureBody.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: HiveStructureBody.cpp ////////////////////////////////////////////////////////////////////////
  24. // Desc: Hive structure bodies are structure bodies with the ability to propagate specified
  25. // damage types to slaves when available. If there are no slaves, the the structure
  26. // will take the damage.
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Common/Xfer.h"
  31. #include "Common/ThingTemplate.h"
  32. #include "GameLogic/GameLogic.h"
  33. #include "GameLogic/Object.h"
  34. #include "GameLogic/Damage.h"
  35. #include "GameLogic/Module/HiveStructureBody.h"
  36. #include "GameLogic/Module/SpawnBehavior.h"
  37. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  38. //-------------------------------------------------------------------------------------------------
  39. HiveStructureBodyModuleData::HiveStructureBodyModuleData()
  40. {
  41. m_damageTypesToPropagateToSlaves = DAMAGE_TYPE_FLAGS_NONE;
  42. m_damageTypesToSwallow = DAMAGE_TYPE_FLAGS_NONE;
  43. }
  44. //-------------------------------------------------------------------------------------------------
  45. HiveStructureBody::HiveStructureBody( Thing *thing, const ModuleData* moduleData )
  46. : StructureBody( thing, moduleData )
  47. {
  48. }
  49. //-------------------------------------------------------------------------------------------------
  50. HiveStructureBody::~HiveStructureBody( void )
  51. {
  52. }
  53. //------------------------------------------------------------------------------------------------
  54. void HiveStructureBody::attemptDamage( DamageInfo *damageInfo )
  55. {
  56. const HiveStructureBodyModuleData *data = getHiveStructureBodyModuleData();
  57. Object *hive = getObject();
  58. if( getDamageTypeFlag( data->m_damageTypesToPropagateToSlaves, damageInfo->in.m_damageType ) )
  59. {
  60. //We have the right type of damage types incoming to propagate to slaves. Do we have slaves?
  61. SpawnBehaviorInterface *spawnInterface = hive->getSpawnBehaviorInterface();
  62. if( spawnInterface )
  63. {
  64. //We found the spawn interface, now get some slaves!
  65. Object *shooter = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );
  66. if( shooter )
  67. {
  68. Object *slave = spawnInterface->getClosestSlave( shooter->getPosition() );
  69. if( slave )
  70. {
  71. //Propagate damage and return!
  72. slave->attemptDamage( damageInfo );
  73. return;
  74. }
  75. else if( getDamageTypeFlag( data->m_damageTypesToSwallow, damageInfo->in.m_damageType ) )
  76. {
  77. //no slave to give to, so eat it
  78. damageInfo->out.m_actualDamageDealt = 0.0f;
  79. damageInfo->out.m_actualDamageClipped = 0.0f;
  80. damageInfo->out.m_noEffect = true;
  81. return;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. DEBUG_CRASH( ("%s has a HiveStructureBody module, which requires a SpawnBehavior module. Thus it is unable to propagate damage to slaves.", hive->getTemplate()->getName().str() ) );
  88. }
  89. }
  90. //Nothing to propagate (either different damage type or no slaves),
  91. //so damage me instead!
  92. StructureBody::attemptDamage( damageInfo );
  93. }
  94. //------------------------------------------------------------------------------------------------
  95. void HiveStructureBody::crc( Xfer *xfer )
  96. {
  97. // extend parent class
  98. StructureBody::crc( xfer );
  99. } // end crc
  100. // ------------------------------------------------------------------------------------------------
  101. /** Xfer method
  102. * Version Info:
  103. * 1: Initial version */
  104. // ------------------------------------------------------------------------------------------------
  105. void HiveStructureBody::xfer( Xfer *xfer )
  106. {
  107. // version
  108. XferVersion currentVersion = 1;
  109. XferVersion version = currentVersion;
  110. xfer->xferVersion( &version, currentVersion );
  111. // parent class
  112. StructureBody::xfer( xfer );
  113. }
  114. //------------------------------------------------------------------------------------------------
  115. void HiveStructureBody::loadPostProcess( void )
  116. {
  117. // extend parent class
  118. StructureBody::loadPostProcess();
  119. }