ConvertToHijackedVehicleCrateCollide.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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: ConvertToHijackedVehicleCrateCollide.cpp
  26. // Author: Mark Lorenzen, July 2002
  27. // Desc: A crate (actually a terrorist - mobile crate) that makes the target vehicle switch
  28. // sides, and kills its driver
  29. // @todo Needs to set the science of that vehicle (dozer) so still can build same stuff as always
  30. //
  31. ///////////////////////////////////////////////////////////////////////////////////////////////////
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  34. #include "Common/Player.h"
  35. #include "Common/PlayerList.h"
  36. #include "Common/Radar.h"
  37. #include "Common/ThingTemplate.h"
  38. #include "Common/Xfer.h"
  39. #include "GameClient/Drawable.h"
  40. #include "GameClient/Eva.h"
  41. #include "GameClient/InGameUI.h" // useful for printing quick debug strings when we need to
  42. #include "GameLogic/ExperienceTracker.h"
  43. #include "GameLogic/Module/AIUpdate.h"
  44. #include "GameLogic/Module/ConvertToHijackedVehicleCrateCollide.h"
  45. #include "GameLogic/Module/HijackerUpdate.h"
  46. #include "GameLogic/Module/ContainModule.h"
  47. #include "GameLogic/Object.h"
  48. #include "GameLogic/PartitionManager.h"
  49. #include "GameLogic/ScriptEngine.h"
  50. #include "GameLogic/Module/DozerAIUpdate.h"
  51. #ifdef _INTERNAL
  52. // for occasional debugging...
  53. //#pragma optimize("", off)
  54. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  55. #endif
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. ConvertToHijackedVehicleCrateCollide::ConvertToHijackedVehicleCrateCollide( Thing *thing, const ModuleData* moduleData ) : CrateCollide( thing, moduleData )
  59. {
  60. }
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. ConvertToHijackedVehicleCrateCollide::~ConvertToHijackedVehicleCrateCollide( void )
  64. {
  65. }
  66. //-------------------------------------------------------------------------------------------------
  67. //-------------------------------------------------------------------------------------------------
  68. Bool ConvertToHijackedVehicleCrateCollide::isValidToExecute( const Object *other ) const
  69. {
  70. if( !CrateCollide::isValidToExecute(other) )
  71. {
  72. return FALSE;
  73. }
  74. if( other->isEffectivelyDead() )
  75. {
  76. return FALSE;// can't hijack a dead vehicle
  77. }
  78. if( other->isKindOf( KINDOF_IMMUNE_TO_CAPTURE ) )
  79. {
  80. return FALSE; //Kris: Patch 1.03 -- Prevent hijackers from being able to hijack battle buses.
  81. }
  82. if( other->isKindOf( KINDOF_AIRCRAFT ) || other->isKindOf( KINDOF_BOAT ) )
  83. {
  84. //Can't hijack planes and boats!
  85. return FALSE;
  86. }
  87. if( other->isKindOf( KINDOF_DRONE ) )
  88. {
  89. //Can't hijack drones!
  90. return FALSE;
  91. }
  92. if( other->getStatusBits().test( OBJECT_STATUS_HIJACKED ) )
  93. {
  94. return FALSE;// oops, sorry, I'll jack the next one.
  95. }
  96. Relationship r = getObject()->getRelationship( other );
  97. //Only hijack enemy objects
  98. if( r != ENEMIES )
  99. {
  100. return FALSE;
  101. }
  102. if( other->isKindOf( KINDOF_TRANSPORT ) )
  103. {
  104. //Kris: Allow empty transports to be hijacked.
  105. if( other->getContain() && other->getContain()->getContainCount() > 0 )
  106. {
  107. return FALSE;// dustin sez: do not jack vehicles that may carry hostile passengers
  108. }
  109. }
  110. //Kris: Make sure you can't hijack any aircraft (or hijack-enter).
  111. if( other->isKindOf( KINDOF_AIRCRAFT ) )
  112. {
  113. return FALSE;
  114. }
  115. //VeterancyLevel veterancyLevel = other->getVeterancyLevel();
  116. //if( veterancyLevel >= LEVEL_ELITE )
  117. //{
  118. // return FALSE;
  119. //}
  120. return TRUE;
  121. }
  122. //-------------------------------------------------------------------------------------------------
  123. //-------------------------------------------------------------------------------------------------
  124. Bool ConvertToHijackedVehicleCrateCollide::executeCrateBehavior( Object *other )
  125. {
  126. //Check to make sure that the other object is also the goal object in the AIUpdateInterface
  127. //in order to prevent an unintentional conversion simply by having the terrorist walk too close
  128. //to it.
  129. //Assume ai is valid because CrateCollide::isValidToExecute(other) checks it.
  130. Object *obj = getObject();
  131. AIUpdateInterface* ai = obj->getAIUpdateInterface();
  132. if (ai && ai->getGoalObject() != other)
  133. {
  134. return false;
  135. }
  136. TheRadar->tryInfiltrationEvent( other );
  137. //Before the actual defection takes place, play the "vehicle stolen" EVA
  138. //event if the local player is the victim!
  139. if( other->isLocallyControlled() )
  140. {
  141. TheEva->setShouldPlay( EVA_VehicleStolen );
  142. }
  143. other->setTeam( obj->getControllingPlayer()->getDefaultTeam() );
  144. other->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_HIJACKED ) );// I claim this car in the name of the GLA
  145. AIUpdateInterface* targetAI = other->getAIUpdateInterface();
  146. targetAI->aiMoveToPosition( other->getPosition(), CMD_FROM_AI );
  147. targetAI->aiIdle( CMD_FROM_AI );
  148. //Just in case this target is a dozer, lets make him stop al his dozer tasks, like building and repairing,
  149. //So the previous owner does not benefit from these tasks
  150. DozerAIInterface * dozerAI = targetAI->getDozerAIInterface();
  151. if ( dozerAI )
  152. {
  153. for (UnsignedInt task = DOZER_TASK_FIRST; task < DOZER_NUM_TASKS; ++task)
  154. {
  155. dozerAI->cancelTask( (DozerTask)task );
  156. }
  157. }
  158. AudioEventRTS hijackEvent( "HijackDriver", obj->getID() );
  159. TheAudio->addAudioEvent( &hijackEvent );
  160. //In order to make things easier for the designers, we are going to transfer the hijacker's name
  161. //to the car... so the designer can control the car with their scripts.
  162. TheScriptEngine->transferObjectName( obj->getName(), other );
  163. ExperienceTracker *targetExp = other->getExperienceTracker();
  164. ExperienceTracker *jackerExp = obj->getExperienceTracker();
  165. if ( targetExp && jackerExp )
  166. {
  167. VeterancyLevel highestLevel = MAX(targetExp->getVeterancyLevel(),jackerExp->getVeterancyLevel());
  168. jackerExp->setVeterancyLevel( highestLevel, FALSE );
  169. targetExp->setVeterancyLevel( highestLevel, FALSE );
  170. }
  171. Bool targetCanEject = FALSE;
  172. BehaviorModule **dmi = NULL;
  173. for( dmi = other->getBehaviorModules(); *dmi; ++dmi )
  174. {
  175. if( (*dmi)->getEjectPilotDieInterface() )
  176. {
  177. targetCanEject = TRUE;
  178. break;
  179. }
  180. } // end for dmi
  181. if ( ! targetCanEject )
  182. {
  183. TheGameLogic->destroyObject( obj );
  184. return TRUE;
  185. }
  186. // I we have made it this far, we are going to ride in this vehicle for a while
  187. // get the name of the hijackerupdate
  188. static NameKeyType key_HijackerUpdate = NAMEKEY( "HijackerUpdate" );
  189. HijackerUpdate *hijackerUpdate = (HijackerUpdate*)obj->findUpdateModule( key_HijackerUpdate );
  190. if( hijackerUpdate )
  191. {
  192. hijackerUpdate->setTargetObject( other );
  193. hijackerUpdate->setIsInVehicle( TRUE );
  194. hijackerUpdate->setUpdate( TRUE );
  195. // flag bits so hijacker won't be selectible or collideable
  196. //while within the vehicle
  197. obj->setStatus( MAKE_OBJECT_STATUS_MASK3( OBJECT_STATUS_NO_COLLISIONS, OBJECT_STATUS_MASKED, OBJECT_STATUS_UNSELECTABLE ) );
  198. }
  199. // THIS BLOCK HIDES THE HIJACKER AND REMOVES HIM FROM PARTITION MANAGER
  200. // remove object from its group (if any)
  201. obj->leaveGroup();
  202. if( ai )
  203. {
  204. //By setting him to idle, we will prevent him from entering the target after this gets called.
  205. ai->aiIdle( CMD_FROM_AI );
  206. }
  207. //This is kinda special... we will endow our new ride with our vision and shroud range, since we are driving
  208. other->setVisionRange(getObject()->getVisionRange());
  209. other->setShroudClearingRange(getObject()->getShroudClearingRange());
  210. // remove rider from partition manager
  211. ThePartitionManager->unRegisterObject( obj );
  212. // hide the drawable associated with rider
  213. if( obj->getDrawable() )
  214. obj->getDrawable()->setDrawableHidden( true );
  215. // By returning FALSE, we will not remove the object (Hijacker)
  216. return FALSE;
  217. // return TRUE;
  218. }
  219. // ------------------------------------------------------------------------------------------------
  220. /** CRC */
  221. // ------------------------------------------------------------------------------------------------
  222. void ConvertToHijackedVehicleCrateCollide::crc( Xfer *xfer )
  223. {
  224. // extend base class
  225. CrateCollide::crc( xfer );
  226. } // end crc
  227. // ------------------------------------------------------------------------------------------------
  228. /** Xfer method
  229. * Version Info:
  230. * 1: Initial version */
  231. // ------------------------------------------------------------------------------------------------
  232. void ConvertToHijackedVehicleCrateCollide::xfer( Xfer *xfer )
  233. {
  234. // version
  235. XferVersion currentVersion = 1;
  236. XferVersion version = currentVersion;
  237. xfer->xferVersion( &version, currentVersion );
  238. // extend base class
  239. CrateCollide::xfer( xfer );
  240. } // end xfer
  241. // ------------------------------------------------------------------------------------------------
  242. /** Load post process */
  243. // ------------------------------------------------------------------------------------------------
  244. void ConvertToHijackedVehicleCrateCollide::loadPostProcess( void )
  245. {
  246. // extend base class
  247. CrateCollide::loadPostProcess();
  248. } // end loadPostProcess