HijackerUpdate.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. ///////////////////////////////////////////////////////////////////////////////////////////////////
  24. //
  25. // FILE: HijackerUpdate.cpp
  26. // Author: Mark Lorenzen, July 2002
  27. // Desc: Allows hijacker to kepp with his hijacked vehicle (though hidden) until it dies, then
  28. // to become a hijacker once more
  29. //
  30. /////////////////////////////////////////////////////////////////////////////////////////////////
  31. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  32. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  33. #include "Common/Player.h"
  34. #include "Common/ThingFactory.h"
  35. #include "Common/ThingTemplate.h"
  36. #include "Common/Xfer.h"
  37. #include "GameClient/Drawable.h"
  38. #include "GameLogic/Object.h"
  39. #include "GameLogic/Module/HijackerUpdate.h"
  40. #include "GameLogic/Module/AIUpdate.h"
  41. #include "GameLogic/GameLogic.h"
  42. #include "GameLogic/PartitionManager.h"
  43. #include "GameLogic/Module/EjectPilotDie.h"
  44. #include "GameLogic/Module/ContainModule.h"
  45. #include "GameLogic/ExperienceTracker.h"
  46. //-------------------------------------------------------------------------------------------------
  47. //-------------------------------------------------------------------------------------------------
  48. HijackerUpdate::HijackerUpdate( Thing *thing, const ModuleData *moduleData ) : UpdateModule( thing, moduleData )
  49. {
  50. m_targetID = INVALID_ID;
  51. setUpdate( FALSE );
  52. setIsInVehicle( FALSE );
  53. m_wasTargetAirborne = false;
  54. m_ejectPos.zero();
  55. // m_ejectPilotDMI = NULL;
  56. }
  57. //-------------------------------------------------------------------------------------------------
  58. //-------------------------------------------------------------------------------------------------
  59. HijackerUpdate::~HijackerUpdate( void )
  60. {
  61. }
  62. //-------------------------------------------------------------------------------------------------
  63. //-------------------------------------------------------------------------------------------------
  64. UpdateSleepTime HijackerUpdate::update( void )
  65. {
  66. /// @todo srj use SLEEPY_UPDATE here
  67. if ( ! m_update) // have not flagged for updating
  68. {
  69. return UPDATE_SLEEP_NONE;
  70. }
  71. if (m_isInVehicle)
  72. {
  73. Object *obj = getObject();
  74. // If hijacker has hijacked a vehicle, he needs to move along with it...
  75. //Continually reset position of hijacker to match the position of the target.
  76. Object *target = getTargetObject();
  77. if( target )
  78. {
  79. // @todo I think we should test for ! IsEffectivelyDead() as well, here
  80. obj->setPosition( target->getPosition() );
  81. m_wasTargetAirborne = target->isSignificantlyAboveTerrain();
  82. m_ejectPos = *target->getPosition();
  83. // So, if while I am driving this American war vehicle, I gain skill points, I get to keep them when I wreck the vehicle
  84. ExperienceTracker *targetExp = target->getExperienceTracker();
  85. ExperienceTracker *jackerExp = obj->getExperienceTracker();
  86. if ( targetExp && jackerExp )
  87. {
  88. VeterancyLevel highestLevel = MAX(targetExp->getVeterancyLevel(),jackerExp->getVeterancyLevel());
  89. jackerExp->setVeterancyLevel( highestLevel );
  90. targetExp->setVeterancyLevel( highestLevel );
  91. }
  92. }
  93. else // the car we have been "driving" is dead now, and has safely ejected us
  94. {
  95. {
  96. //THIS BLOCK RESTORES HIJACKER TO PARTITION MANAGER AND UNHIDES HIM
  97. ThePartitionManager->registerObject( obj );
  98. if( obj->getDrawable() )
  99. {
  100. // so it is time to unhide ourselves and be a pedestrian hijacker again
  101. obj->getDrawable()->setDrawableHidden( false );
  102. }
  103. // We won't come back here until and unless we have hijacked another vehicle
  104. obj->clearStatus( MAKE_OBJECT_STATUS_MASK3( OBJECT_STATUS_NO_COLLISIONS, OBJECT_STATUS_MASKED, OBJECT_STATUS_UNSELECTABLE ) );
  105. AIUpdateInterface* ai = obj->getAIUpdateInterface();
  106. if ( ai )
  107. {
  108. ai->aiIdle( CMD_FROM_AI );
  109. }
  110. if (m_wasTargetAirborne)
  111. {
  112. const ThingTemplate* putInContainerTmpl = TheThingFactory->findTemplate(getHijackerUpdateModuleData()->m_parachuteName);
  113. DEBUG_ASSERTCRASH(putInContainerTmpl,("DeliverPayload: PutInContainer %s not found!",getHijackerUpdateModuleData()->m_parachuteName.str()));
  114. if (putInContainerTmpl)
  115. {
  116. Object* container = TheThingFactory->newObject( putInContainerTmpl, obj->getTeam() );
  117. container->setPosition(&m_ejectPos);
  118. if (container->getContain()->isValidContainerFor(obj, true))
  119. {
  120. container->getContain()->addToContain(obj);
  121. }
  122. else
  123. {
  124. DEBUG_CRASH(("DeliverPayload: PutInContainer %s is full, or not valid for the payload!",getHijackerUpdateModuleData()->m_parachuteName.str()));
  125. }
  126. }
  127. }
  128. }// end if (! hostVehicleHasEjection)
  129. setTargetObject( NULL );
  130. setIsInVehicle( FALSE );
  131. setUpdate( FALSE );
  132. m_wasTargetAirborne = false;
  133. }// end if( target )
  134. }
  135. else // not in vehicle
  136. {
  137. m_wasTargetAirborne = false;
  138. }
  139. return UPDATE_SLEEP_NONE;
  140. }
  141. void HijackerUpdate::setTargetObject( const Object *object )
  142. {
  143. if( object )
  144. {
  145. m_targetID = object->getID();
  146. // here we also test the target to see whether it ejects pilots
  147. // when it dies... if so, stores a pointer to that diemoduleinterface
  148. // NULL if not...
  149. // BehaviorModule **dmi = NULL;
  150. // for( dmi = object->getBehaviorModules(); *dmi; ++dmi )
  151. // {
  152. // m_ejectPilotDMI = (*dmi)->getEjectPilotDieInterface();
  153. // if( m_ejectPilotDMI )
  154. // return;
  155. // } // end for dmi
  156. }
  157. else
  158. {
  159. m_targetID = INVALID_ID;
  160. // m_ejectPilotDMI = NULL;
  161. }
  162. }
  163. Object* HijackerUpdate::getTargetObject() const
  164. {
  165. if( m_targetID != INVALID_ID )
  166. {
  167. return TheGameLogic->findObjectByID( m_targetID );
  168. }
  169. return NULL;
  170. }
  171. // ------------------------------------------------------------------------------------------------
  172. /** CRC */
  173. // ------------------------------------------------------------------------------------------------
  174. void HijackerUpdate::crc( Xfer *xfer )
  175. {
  176. // extend base class
  177. UpdateModule::crc( xfer );
  178. } // end crc
  179. // ------------------------------------------------------------------------------------------------
  180. /** Xfer method
  181. * Version Info:
  182. * 1: Initial version */
  183. // ------------------------------------------------------------------------------------------------
  184. void HijackerUpdate::xfer( Xfer *xfer )
  185. {
  186. // version
  187. XferVersion currentVersion = 1;
  188. XferVersion version = currentVersion;
  189. xfer->xferVersion( &version, currentVersion );
  190. // extend base class
  191. UpdateModule::xfer( xfer );
  192. // target ID
  193. xfer->xferObjectID( &m_targetID );
  194. // eject pos
  195. xfer->xferCoord3D( &m_ejectPos );
  196. // udpate
  197. xfer->xferBool( &m_update );
  198. // is in vehicle
  199. xfer->xferBool( &m_isInVehicle );
  200. // was target airborne
  201. xfer->xferBool( &m_wasTargetAirborne );
  202. } // end xfer
  203. // ------------------------------------------------------------------------------------------------
  204. /** Load post process */
  205. // ------------------------------------------------------------------------------------------------
  206. void HijackerUpdate::loadPostProcess( void )
  207. {
  208. // extend base class
  209. UpdateModule::loadPostProcess();
  210. // set the target object, this will also tie up teh m_ejectPilotDMI pointer
  211. Object *obj = TheGameLogic->findObjectByID( m_targetID );
  212. setTargetObject( obj );
  213. } // end loadPostProcess