VeterancyCrateCollide.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: VeterancyCrateCollide.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/Xfer.h"
  31. #include "GameLogic/ExperienceTracker.h"
  32. #include "GameLogic/Object.h"
  33. #include "GameLogic/PartitionManager.h"
  34. #include "GameLogic/Module/VeterancyCrateCollide.h"
  35. #include "GameLogic/ScriptEngine.h"
  36. #include "GameLogic/Module/AIUpdate.h"
  37. //-------------------------------------------------------------------------------------------------
  38. //-------------------------------------------------------------------------------------------------
  39. VeterancyCrateCollide::VeterancyCrateCollide( Thing *thing, const ModuleData* moduleData ) : CrateCollide( thing, moduleData )
  40. {
  41. }
  42. //-------------------------------------------------------------------------------------------------
  43. //-------------------------------------------------------------------------------------------------
  44. VeterancyCrateCollide::~VeterancyCrateCollide( void )
  45. {
  46. }
  47. //-------------------------------------------------------------------------------------------------
  48. //-------------------------------------------------------------------------------------------------
  49. Int VeterancyCrateCollide::getLevelsToGain() const
  50. {
  51. const VeterancyCrateCollideModuleData* d = getVeterancyCrateCollideModuleData();
  52. if (!d || !d->m_addsOwnerVeterancy)
  53. return 1;
  54. // this requires that "regular" is 0, vet is 1, etc.
  55. return (Int)getObject()->getVeterancyLevel();
  56. }
  57. //-------------------------------------------------------------------------------------------------
  58. //-------------------------------------------------------------------------------------------------
  59. Bool VeterancyCrateCollide::isValidToExecute( const Object *other ) const
  60. {
  61. const VeterancyCrateCollideModuleData* d = getVeterancyCrateCollideModuleData();
  62. if( !d )
  63. {
  64. return false;
  65. }
  66. if(!CrateCollide::isValidToExecute(other))
  67. return false;
  68. if (other->isEffectivelyDead())
  69. return false;
  70. if( other->isSignificantlyAboveTerrain() )
  71. {
  72. return false;
  73. }
  74. Int levelsToGain = getLevelsToGain();
  75. if (levelsToGain <= 0)
  76. return false;
  77. const ExperienceTracker *et = other->getExperienceTracker();
  78. if( !et || !et->isTrainable() )
  79. {
  80. //If the other unit can't gain experience, then we can't help promote it!
  81. return false;
  82. }
  83. if (!et || !et->canGainExpForLevel(levelsToGain))
  84. return false;
  85. if( d->m_isPilot )
  86. {
  87. if( other->getControllingPlayer() != getObject()->getControllingPlayer() )
  88. {
  89. //This is a pilot and we are checking to make sure the pilot is entering a vehicle on
  90. //the same team. If it's not, then don't allow it.. this is particularly the case for
  91. //pilots attempting to enter civilian vehicles.
  92. return false;
  93. }
  94. if( other->isUsingAirborneLocomotor() )
  95. {
  96. // Can't upgrade a helicopter or plane, but we will think we can for a moment while it
  97. // is on the ground from being built.
  98. return false;
  99. }
  100. }
  101. return true;
  102. }
  103. //-------------------------------------------------------------------------------------------------
  104. //-------------------------------------------------------------------------------------------------
  105. Bool VeterancyCrateCollide::executeCrateBehavior( Object *other )
  106. {
  107. //Make sure the pilot is actually *TRYING* to enter the object
  108. //unlike other crates
  109. AIUpdateInterface *ai = (AIUpdateInterface*)getObject()->getAIUpdateInterface();
  110. const VeterancyCrateCollideModuleData *md = getVeterancyCrateCollideModuleData();
  111. if( !ai || ai->getGoalObject() != other )
  112. {
  113. return false;
  114. }
  115. Int levelsToGain = getLevelsToGain();
  116. Real range = md->m_rangeOfEffect;
  117. if (range == 0)
  118. {
  119. // do just the collider
  120. if (other != NULL)
  121. {
  122. other->getExperienceTracker()->gainExpForLevel( levelsToGain, ( ! md->m_isPilot) );
  123. }
  124. }
  125. else
  126. {
  127. PartitionFilterSamePlayer othersPlayerFilter( other->getControllingPlayer() );
  128. PartitionFilterSameMapStatus filterMapStatus(other);
  129. PartitionFilter *filters[] = { &othersPlayerFilter, &filterMapStatus, NULL };
  130. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( other, range, FROM_CENTER_2D, filters, ITER_FASTEST );
  131. MemoryPoolObjectHolder hold(iter);
  132. for( Object *potentialObject = iter->first(); potentialObject; potentialObject = iter->next() )
  133. {
  134. // This function will give just enough exp for the Object to gain a level, if it can
  135. potentialObject->getExperienceTracker()->gainExpForLevel( levelsToGain, ( ! md->m_isPilot) );
  136. }
  137. }
  138. //In order to make things easier for the designers, we are going to transfer the terrorist name
  139. //to the car... so the designer can control the car with their scripts.
  140. if( md->m_isPilot )
  141. {
  142. TheScriptEngine->transferObjectName( getObject()->getName(), other );
  143. }
  144. return TRUE;
  145. }
  146. // ------------------------------------------------------------------------------------------------
  147. /** CRC */
  148. // ------------------------------------------------------------------------------------------------
  149. void VeterancyCrateCollide::crc( Xfer *xfer )
  150. {
  151. // extend base class
  152. CrateCollide::crc( xfer );
  153. } // end crc
  154. // ------------------------------------------------------------------------------------------------
  155. /** Xfer method
  156. * Version Info:
  157. * 1: Initial version */
  158. // ------------------------------------------------------------------------------------------------
  159. void VeterancyCrateCollide::xfer( Xfer *xfer )
  160. {
  161. // version
  162. XferVersion currentVersion = 1;
  163. XferVersion version = currentVersion;
  164. xfer->xferVersion( &version, currentVersion );
  165. // extend base class
  166. CrateCollide::xfer( xfer );
  167. } // end xfer
  168. // ------------------------------------------------------------------------------------------------
  169. /** Load post process */
  170. // ------------------------------------------------------------------------------------------------
  171. void VeterancyCrateCollide::loadPostProcess( void )
  172. {
  173. // extend base class
  174. CrateCollide::loadPostProcess();
  175. } // end loadPostProcess