UnitCrateCollide.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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: UnitCrateCollide.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, March 2002
  25. // Desc: A crate that gives n units of type m the the pickerupper
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/AudioEventRTS.h"
  30. #include "Common/MiscAudio.h"
  31. #include "Common/Player.h"
  32. #include "Common/ThingFactory.h"
  33. #include "Common/Xfer.h"
  34. #include "GameLogic/Object.h"
  35. #include "GameLogic/PartitionManager.h"
  36. #include "GameLogic/Module/UnitCrateCollide.h"
  37. //-------------------------------------------------------------------------------------------------
  38. //-------------------------------------------------------------------------------------------------
  39. UnitCrateCollide::UnitCrateCollide( Thing *thing, const ModuleData* moduleData ) : CrateCollide( thing, moduleData )
  40. {
  41. }
  42. //-------------------------------------------------------------------------------------------------
  43. //-------------------------------------------------------------------------------------------------
  44. UnitCrateCollide::~UnitCrateCollide( void )
  45. {
  46. }
  47. //-------------------------------------------------------------------------------------------------
  48. Bool UnitCrateCollide::executeCrateBehavior( Object *other )
  49. {
  50. UnsignedInt unitCount = getUnitCrateCollideModuleData()->m_unitCount;
  51. ThingTemplate const *unitType = TheThingFactory->findTemplate( getUnitCrateCollideModuleData()->m_unitType );
  52. if( unitType == NULL )
  53. {
  54. return FALSE;
  55. }
  56. for( Int unitIndex = 0; unitIndex < unitCount; unitIndex++ )
  57. {
  58. Team *creationTeam = other->getControllingPlayer()->getDefaultTeam();
  59. Object *newObj = TheThingFactory->newObject( unitType, creationTeam );
  60. if( newObj )
  61. {
  62. Coord3D creationPoint = *other->getPosition();
  63. /// @todo As a user of the future findLegalPositionAround, I wouldn't mind not having to specify range. I just want a non colliding point.
  64. FindPositionOptions fpOptions;
  65. fpOptions.minRadius = 0.0f;
  66. fpOptions.maxRadius = 20.0f;
  67. ThePartitionManager->findPositionAround( &creationPoint,
  68. &fpOptions,
  69. &creationPoint );
  70. newObj->setOrientation( other->getOrientation() );
  71. newObj->setPosition( &creationPoint );
  72. }
  73. }
  74. //Play a crate pickup sound.
  75. AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_crateFreeUnit;
  76. soundToPlay.setObjectID( other->getID() );
  77. TheAudio->addAudioEvent(&soundToPlay);
  78. return TRUE;
  79. }
  80. // ------------------------------------------------------------------------------------------------
  81. /** CRC */
  82. // ------------------------------------------------------------------------------------------------
  83. void UnitCrateCollide::crc( Xfer *xfer )
  84. {
  85. // extend base class
  86. CrateCollide::crc( xfer );
  87. } // end crc
  88. // ------------------------------------------------------------------------------------------------
  89. /** Xfer method
  90. * Version Info:
  91. * 1: Initial version */
  92. // ------------------------------------------------------------------------------------------------
  93. void UnitCrateCollide::xfer( Xfer *xfer )
  94. {
  95. // version
  96. XferVersion currentVersion = 1;
  97. XferVersion version = currentVersion;
  98. xfer->xferVersion( &version, currentVersion );
  99. // extend base class
  100. CrateCollide::xfer( xfer );
  101. } // end xfer
  102. // ------------------------------------------------------------------------------------------------
  103. /** Load post process */
  104. // ------------------------------------------------------------------------------------------------
  105. void UnitCrateCollide::loadPostProcess( void )
  106. {
  107. // extend base class
  108. CrateCollide::loadPostProcess();
  109. } // end loadPostProcess