HijackerUpdate.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. ///////////////////////////////////////////////////////////////////////////////////////////////////
  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( OBJECT_STATUS_NO_COLLISIONS );
  105. obj->clearStatus( OBJECT_STATUS_MASKED );
  106. obj->clearStatus( OBJECT_STATUS_UNSELECTABLE );
  107. AIUpdateInterface* ai = obj->getAIUpdateInterface();
  108. if ( ai )
  109. {
  110. ai->aiIdle( CMD_FROM_AI );
  111. }
  112. if (m_wasTargetAirborne)
  113. {
  114. const ThingTemplate* putInContainerTmpl = TheThingFactory->findTemplate(getHijackerUpdateModuleData()->m_parachuteName);
  115. DEBUG_ASSERTCRASH(putInContainerTmpl,("DeliverPayload: PutInContainer %s not found!",getHijackerUpdateModuleData()->m_parachuteName.str()));
  116. if (putInContainerTmpl)
  117. {
  118. Object* container = TheThingFactory->newObject( putInContainerTmpl, obj->getTeam() );
  119. container->setPosition(&m_ejectPos);
  120. if (container->getContain()->isValidContainerFor(obj, true))
  121. {
  122. container->getContain()->addToContain(obj);
  123. }
  124. else
  125. {
  126. DEBUG_CRASH(("DeliverPayload: PutInContainer %s is full, or not valid for the payload!",getHijackerUpdateModuleData()->m_parachuteName.str()));
  127. }
  128. }
  129. }
  130. }// end if (! hostVehicleHasEjection)
  131. setTargetObject( NULL );
  132. setIsInVehicle( FALSE );
  133. setUpdate( FALSE );
  134. m_wasTargetAirborne = false;
  135. }// end if( target )
  136. }
  137. else // not in vehicle
  138. {
  139. m_wasTargetAirborne = false;
  140. }
  141. return UPDATE_SLEEP_NONE;
  142. }
  143. void HijackerUpdate::setTargetObject( const Object *object )
  144. {
  145. if( object )
  146. {
  147. m_targetID = object->getID();
  148. // here we also test the target to see whether it ejects pilots
  149. // when it dies... if so, stores a pointer to that diemoduleinterface
  150. // NULL if not...
  151. // BehaviorModule **dmi = NULL;
  152. // for( dmi = object->getBehaviorModules(); *dmi; ++dmi )
  153. // {
  154. // m_ejectPilotDMI = (*dmi)->getEjectPilotDieInterface();
  155. // if( m_ejectPilotDMI )
  156. // return;
  157. // } // end for dmi
  158. }
  159. else
  160. {
  161. m_targetID = INVALID_ID;
  162. // m_ejectPilotDMI = NULL;
  163. }
  164. }
  165. Object* HijackerUpdate::getTargetObject() const
  166. {
  167. if( m_targetID != INVALID_ID )
  168. {
  169. return TheGameLogic->findObjectByID( m_targetID );
  170. }
  171. return NULL;
  172. }
  173. // ------------------------------------------------------------------------------------------------
  174. /** CRC */
  175. // ------------------------------------------------------------------------------------------------
  176. void HijackerUpdate::crc( Xfer *xfer )
  177. {
  178. // extend base class
  179. UpdateModule::crc( xfer );
  180. } // end crc
  181. // ------------------------------------------------------------------------------------------------
  182. /** Xfer method
  183. * Version Info:
  184. * 1: Initial version */
  185. // ------------------------------------------------------------------------------------------------
  186. void HijackerUpdate::xfer( Xfer *xfer )
  187. {
  188. // version
  189. XferVersion currentVersion = 1;
  190. XferVersion version = currentVersion;
  191. xfer->xferVersion( &version, currentVersion );
  192. // extend base class
  193. UpdateModule::xfer( xfer );
  194. // target ID
  195. xfer->xferObjectID( &m_targetID );
  196. // eject pos
  197. xfer->xferCoord3D( &m_ejectPos );
  198. // udpate
  199. xfer->xferBool( &m_update );
  200. // is in vehicle
  201. xfer->xferBool( &m_isInVehicle );
  202. // was target airborne
  203. xfer->xferBool( &m_wasTargetAirborne );
  204. } // end xfer
  205. // ------------------------------------------------------------------------------------------------
  206. /** Load post process */
  207. // ------------------------------------------------------------------------------------------------
  208. void HijackerUpdate::loadPostProcess( void )
  209. {
  210. // extend base class
  211. UpdateModule::loadPostProcess();
  212. // set the target object, this will also tie up teh m_ejectPilotDMI pointer
  213. Object *obj = TheGameLogic->findObjectByID( m_targetID );
  214. setTargetObject( obj );
  215. } // end loadPostProcess