EjectPilotDie.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: EjectPilotDie.cpp ///////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, April 2002
  25. // Desc: Create an object upon this object's death
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/GameAudio.h"
  29. #include "Common/Player.h"
  30. #include "Common/ThingFactory.h"
  31. #include "Common/ThingTemplate.h"
  32. #include "Common/Xfer.h"
  33. #include "GameLogic/GameLogic.h"
  34. #include "GameLogic/Module/EjectPilotDie.h"
  35. #include "GameLogic/ExperienceTracker.h"
  36. #include "GameLogic/Object.h"
  37. #include "GameLogic/ObjectCreationList.h"
  38. //-------------------------------------------------------------------------------------------------
  39. //-------------------------------------------------------------------------------------------------
  40. EjectPilotDieModuleData::EjectPilotDieModuleData() :
  41. m_oclInAir(NULL),
  42. m_oclOnGround(NULL),
  43. m_invulnerableTime(0)
  44. {
  45. }
  46. //-------------------------------------------------------------------------------------------------
  47. //-------------------------------------------------------------------------------------------------
  48. void EjectPilotDieModuleData::buildFieldParse(MultiIniFieldParse& p)
  49. {
  50. DieModuleData::buildFieldParse(p);
  51. static const FieldParse dataFieldParse[] =
  52. {
  53. { "AirCreationList", INI::parseObjectCreationList, NULL, offsetof( EjectPilotDieModuleData, m_oclInAir ) },
  54. { "GroundCreationList", INI::parseObjectCreationList, NULL, offsetof( EjectPilotDieModuleData, m_oclOnGround ) },
  55. { "InvulnerableTime", INI::parseDurationUnsignedInt, NULL, offsetof(EjectPilotDieModuleData, m_invulnerableTime ) },
  56. { 0, 0, 0, 0 }
  57. };
  58. p.add(dataFieldParse);
  59. }
  60. //-------------------------------------------------------------------------------------------------
  61. //-------------------------------------------------------------------------------------------------
  62. EjectPilotDie::EjectPilotDie( Thing *thing, const ModuleData* moduleData ) : DieModule( thing, moduleData )
  63. {
  64. }
  65. //-------------------------------------------------------------------------------------------------
  66. //-------------------------------------------------------------------------------------------------
  67. EjectPilotDie::~EjectPilotDie( void )
  68. {
  69. }
  70. //-------------------------------------------------------------------------------------------------
  71. //-------------------------------------------------------------------------------------------------
  72. /*static*/ void EjectPilotDie::ejectPilot(const ObjectCreationList* ocl, const Object* dyingObject, const Object* damageDealer)
  73. {
  74. if (!ocl || !dyingObject)
  75. return; // it's OK for damageDealer to be null
  76. ObjectCreationList::create(ocl, dyingObject, damageDealer);
  77. AudioEventRTS voiceEject = *(dyingObject->getTemplate()->getPerUnitSound("VoiceEject"));
  78. voiceEject.setPosition( dyingObject->getPosition() );
  79. voiceEject.setPlayerIndex( dyingObject->getControllingPlayer()->getPlayerIndex() );
  80. TheAudio->addAudioEvent(&voiceEject);
  81. AudioEventRTS soundEject = *(dyingObject->getTemplate()->getPerUnitSound("SoundEject"));
  82. soundEject.setPosition( dyingObject->getPosition() );
  83. TheAudio->addAudioEvent(&soundEject);
  84. }
  85. //-------------------------------------------------------------------------------------------------
  86. /** The die callback. */
  87. //-------------------------------------------------------------------------------------------------
  88. void EjectPilotDie::onDie( const DamageInfo * damageInfo )
  89. {
  90. if (!isDieApplicable(damageInfo))
  91. return;
  92. Object* damageDealer = TheGameLogic->findObjectByID( damageInfo->in.m_sourceID );
  93. const EjectPilotDieModuleData* d = getEjectPilotDieModuleData();
  94. const ObjectCreationList* ocl = getObject()->isSignificantlyAboveTerrain() ? d->m_oclInAir : d->m_oclOnGround;
  95. ejectPilot(ocl, getObject(), damageDealer);
  96. }
  97. // ------------------------------------------------------------------------------------------------
  98. /** CRC */
  99. // ------------------------------------------------------------------------------------------------
  100. void EjectPilotDie::crc( Xfer *xfer )
  101. {
  102. // extend base class
  103. DieModule::crc( xfer );
  104. } // end crc
  105. // ------------------------------------------------------------------------------------------------
  106. /** Xfer method
  107. * Version Info:
  108. * 1: Initial version */
  109. // ------------------------------------------------------------------------------------------------
  110. void EjectPilotDie::xfer( Xfer *xfer )
  111. {
  112. // version
  113. XferVersion currentVersion = 1;
  114. XferVersion version = currentVersion;
  115. xfer->xferVersion( &version, currentVersion );
  116. // extend base class
  117. DieModule::xfer( xfer );
  118. } // end xfer
  119. // ------------------------------------------------------------------------------------------------
  120. /** Load post process */
  121. // ------------------------------------------------------------------------------------------------
  122. void EjectPilotDie::loadPostProcess( void )
  123. {
  124. // extend base class
  125. DieModule::loadPostProcess();
  126. } // end loadPostProcess