ConvertToCarBombCrateCollide.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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: ConvertToCarBombCrateCollide.cpp ///////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, March 2002
  25. // Desc: A crate that gives a level of experience to all within n distance
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/Player.h"
  30. #include "Common/Radar.h"
  31. #include "Common/ThingTemplate.h"
  32. #include "Common/Xfer.h"
  33. #include "GameClient/FXList.h"
  34. #include "GameLogic/ExperienceTracker.h"
  35. #include "GameLogic/Object.h"
  36. #include "GameLogic/Module/ConvertToCarBombCrateCollide.h"
  37. #include "GameLogic/Module/AIUpdate.h"
  38. #include "GameLogic/ScriptEngine.h"
  39. #include "GameLogic/ExperienceTracker.h"
  40. //-------------------------------------------------------------------------------------------------
  41. //-------------------------------------------------------------------------------------------------
  42. ConvertToCarBombCrateCollide::ConvertToCarBombCrateCollide( Thing *thing, const ModuleData* moduleData ) : CrateCollide( thing, moduleData )
  43. {
  44. }
  45. //-------------------------------------------------------------------------------------------------
  46. //-------------------------------------------------------------------------------------------------
  47. ConvertToCarBombCrateCollide::~ConvertToCarBombCrateCollide( void )
  48. {
  49. }
  50. //-------------------------------------------------------------------------------------------------
  51. //-------------------------------------------------------------------------------------------------
  52. Bool ConvertToCarBombCrateCollide::isValidToExecute( const Object *other ) const
  53. {
  54. if( !CrateCollide::isValidToExecute(other) )
  55. {
  56. return FALSE;
  57. }
  58. if( other->isEffectivelyDead() )
  59. {
  60. return FALSE;
  61. }
  62. if( other->isKindOf( KINDOF_AIRCRAFT ) || other->isKindOf( KINDOF_BOAT ) )
  63. {
  64. //Can't make carbombs out of planes and boats!
  65. return FALSE;
  66. }
  67. if ( other->getStatusBits() & OBJECT_STATUS_IS_CARBOMB )
  68. {
  69. return FALSE;// oops, sorry, I'll convert the next one.
  70. }
  71. // Check to see if this other object has a carbomb weapon set that isn't in use.
  72. WeaponSetFlags flags;
  73. flags.set( WEAPONSET_CARBOMB );
  74. const WeaponTemplateSet* set = other->getTemplate()->findWeaponTemplateSet( flags );
  75. if( !set )
  76. {
  77. //This unit has no weapon set!
  78. return FALSE;
  79. }
  80. if( !set->testWeaponSetFlag( WEAPONSET_CARBOMB ) )
  81. {
  82. //This unit has a weaponset, but the best match code above chose a different
  83. //weaponset.
  84. return FALSE;
  85. }
  86. // Also make sure that the car isn't already a carbomb!
  87. if( other->testWeaponSetFlag( WEAPONSET_CARBOMB ) )
  88. {
  89. return FALSE;
  90. }
  91. return TRUE;
  92. }
  93. //-------------------------------------------------------------------------------------------------
  94. //-------------------------------------------------------------------------------------------------
  95. Bool ConvertToCarBombCrateCollide::executeCrateBehavior( Object *other )
  96. {
  97. //Check to make sure that the other object is also the goal object in the AIUpdateInterface
  98. //in order to prevent an unintentional conversion simply by having the terrorist walk too close
  99. //to it.
  100. //Assume ai is valid because CrateCollide::isValidToExecute(other) checks it.
  101. Object *obj = getObject();
  102. AIUpdateInterface* ai = obj->getAIUpdateInterface();
  103. if (ai && ai->getGoalObject() != other)
  104. return false;
  105. other->setWeaponSetFlag( WEAPONSET_CARBOMB );
  106. FXList::doFXObj( getConvertToCarBombCrateCollideModuleData()->m_fxList, other );
  107. other->defect( getObject()->getControllingPlayer()->getDefaultTeam(), 0);
  108. //In order to make things easier for the designers, we are going to transfer the terrorist name
  109. //to the car... so the designer can control the car with their scripts.
  110. TheScriptEngine->transferObjectName( getObject()->getName(), other );
  111. //This is kinda special... we will endow our new ride with our vision and shroud range, since we are driving
  112. other->setVisionRange(getObject()->getVisionRange());
  113. other->setShroudClearingRange(getObject()->getShroudClearingRange());
  114. other->setStatus( OBJECT_STATUS_IS_CARBOMB );
  115. ExperienceTracker *exp = other->getExperienceTracker();
  116. if (exp)
  117. {
  118. exp->setVeterancyLevel(obj->getExperienceTracker()->getVeterancyLevel());
  119. }
  120. TheRadar->removeObject( other );
  121. TheRadar->addObject( other );
  122. return TRUE;
  123. }
  124. // ------------------------------------------------------------------------------------------------
  125. /** CRC */
  126. // ------------------------------------------------------------------------------------------------
  127. void ConvertToCarBombCrateCollide::crc( Xfer *xfer )
  128. {
  129. // extend base class
  130. CrateCollide::crc( xfer );
  131. } // end crc
  132. // ------------------------------------------------------------------------------------------------
  133. /** Xfer method
  134. * Version Info:
  135. * 1: Initial version */
  136. // ------------------------------------------------------------------------------------------------
  137. void ConvertToCarBombCrateCollide::xfer( Xfer *xfer )
  138. {
  139. // version
  140. XferVersion currentVersion = 1;
  141. XferVersion version = currentVersion;
  142. xfer->xferVersion( &version, currentVersion );
  143. // extend base class
  144. CrateCollide::xfer( xfer );
  145. } // end xfer
  146. // ------------------------------------------------------------------------------------------------
  147. /** Load post process */
  148. // ------------------------------------------------------------------------------------------------
  149. void ConvertToCarBombCrateCollide::loadPostProcess( void )
  150. {
  151. // extend base class
  152. CrateCollide::loadPostProcess();
  153. } // end loadPostProcess