airstripgameobj.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. ** Command & Conquer Renegade(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/airstripgameobj.cpp $Author:: Patrick $*
  25. * *
  26. * $Modtime:: 2/24/02 2:06p $*
  27. * *
  28. * $Revision:: 19 $*
  29. * *
  30. *---------------------------------------------------------------------------------------------*
  31. * Functions: *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #include "airstripgameobj.h"
  34. #include "basecontroller.h"
  35. #include "vehicle.h"
  36. #include "wwhack.h"
  37. #include "simpledefinitionfactory.h"
  38. #include "persistfactory.h"
  39. #include "definitionmgr.h"
  40. #include "combatchunkid.h"
  41. #include "debug.h"
  42. #include "scriptzone.h"
  43. #include "wwprofile.h"
  44. #include "basecontroller.h"
  45. #include "combatchunkid.h"
  46. #include "objlibrary.h"
  47. #include "cinematicgameobj.h"
  48. #include "combat.h"
  49. ////////////////////////////////////////////////////////////////
  50. // Hacks
  51. ////////////////////////////////////////////////////////////////
  52. DECLARE_FORCE_LINK (AirStrip)
  53. ////////////////////////////////////////////////////////////////
  54. // Editable and persist factories
  55. ////////////////////////////////////////////////////////////////
  56. SimplePersistFactoryClass <AirStripGameObjDef, CHUNKID_GAME_OBJECT_DEF_AIRSTRIP> _AirStripGameObjDefPersistFactory;
  57. SimplePersistFactoryClass <AirStripGameObj, CHUNKID_GAME_OBJECT_AIRSTRIP> _AirStripGameObjPersistFactory;
  58. DECLARE_DEFINITION_FACTORY (AirStripGameObjDef, CLASSID_GAME_OBJECT_DEF_AIRSTRIP, "Airstrip") _AirStripGameObjDefDefFactory;
  59. ////////////////////////////////////////////////////////////////
  60. // Constants
  61. ////////////////////////////////////////////////////////////////
  62. static const float UNITIALIZED_TIMER = -100.0F;
  63. static const float VEHICLE_LOCK_TIME = 30.0f;
  64. ////////////////////////////////////////////////////////////////
  65. // Save/Load constants
  66. ////////////////////////////////////////////////////////////////
  67. enum
  68. {
  69. CHUNKID_DEF_PARENT = 0x02200638,
  70. CHUNKID_DEF_VARIABLES,
  71. MICROCHUNKID_DEF_CINEMATIC_DEFID = 1,
  72. MICROCHUNKID_DEF_CINEMATIC_LENGTH_TO_DROPOFF,
  73. MICROCHUNKID_DEF_CINEMATIC_SLOT_INDEX,
  74. MICROCHUNKID_DEF_DISPLAY_VEHICLE_TIME
  75. };
  76. enum
  77. {
  78. CHUNKID_PARENT = 0x0219043,
  79. CHUNKID_VARIABLES,
  80. MICROCHUNKID_UNUSED = 1,
  81. };
  82. ////////////////////////////////////////////////////////////////
  83. //
  84. // AirStripGameObjDef
  85. //
  86. ////////////////////////////////////////////////////////////////
  87. AirStripGameObjDef::AirStripGameObjDef (void) :
  88. CinematicLengthToDropOff (0),
  89. CinematicLengthToVehicleDisplay (0),
  90. CinematicDefID (0),
  91. CinematicSlotIndex (0)
  92. {
  93. //
  94. // Editable support
  95. //
  96. EDITABLE_PARAM (AirStripGameObjDef, ParameterClass::TYPE_FLOAT, CinematicLengthToDropOff);
  97. EDITABLE_PARAM (AirStripGameObjDef, ParameterClass::TYPE_INT, CinematicSlotIndex);
  98. EDITABLE_PARAM (AirStripGameObjDef, ParameterClass::TYPE_FLOAT, CinematicLengthToVehicleDisplay);
  99. #ifdef PARAM_EDITING_ON
  100. GenericDefParameterClass *param = new GenericDefParameterClass (&CinematicDefID);
  101. param->Set_Class_ID (CLASSID_GAME_OBJECT_DEF_SIMPLE);
  102. param->Set_Name ("Drop-Off Cinematic");
  103. GENERIC_EDITABLE_PARAM (AirStripGameObjDef, param)
  104. #endif //PARAM_EDITING_ON
  105. return ;
  106. }
  107. ////////////////////////////////////////////////////////////////
  108. //
  109. // ~AirStripGameObjDef
  110. //
  111. ////////////////////////////////////////////////////////////////
  112. AirStripGameObjDef::~AirStripGameObjDef (void)
  113. {
  114. return ;
  115. }
  116. ////////////////////////////////////////////////////////////////
  117. //
  118. // Get_Class_ID
  119. //
  120. ////////////////////////////////////////////////////////////////
  121. uint32
  122. AirStripGameObjDef::Get_Class_ID (void) const
  123. {
  124. return CLASSID_GAME_OBJECT_DEF_AIRSTRIP;
  125. }
  126. ////////////////////////////////////////////////////////////////
  127. //
  128. // Create
  129. //
  130. ////////////////////////////////////////////////////////////////
  131. PersistClass *
  132. AirStripGameObjDef::Create (void) const
  133. {
  134. AirStripGameObj *building = new AirStripGameObj;
  135. building->Init (*this);
  136. return building;
  137. }
  138. ////////////////////////////////////////////////////////////////
  139. //
  140. // Create
  141. //
  142. ////////////////////////////////////////////////////////////////
  143. bool
  144. AirStripGameObjDef::Save (ChunkSaveClass &csave)
  145. {
  146. csave.Begin_Chunk (CHUNKID_DEF_PARENT);
  147. VehicleFactoryGameObjDef::Save (csave);
  148. csave.End_Chunk ();
  149. csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
  150. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_CINEMATIC_LENGTH_TO_DROPOFF, CinematicLengthToDropOff);
  151. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_CINEMATIC_DEFID, CinematicDefID);
  152. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_CINEMATIC_SLOT_INDEX, CinematicSlotIndex);
  153. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_DISPLAY_VEHICLE_TIME, CinematicLengthToVehicleDisplay);
  154. csave.End_Chunk ();
  155. return true;
  156. }
  157. ////////////////////////////////////////////////////////////////
  158. //
  159. // Load
  160. //
  161. ////////////////////////////////////////////////////////////////
  162. bool
  163. AirStripGameObjDef::Load (ChunkLoadClass &cload)
  164. {
  165. while (cload.Open_Chunk ())
  166. {
  167. switch (cload.Cur_Chunk_ID ())
  168. {
  169. case CHUNKID_DEF_PARENT:
  170. VehicleFactoryGameObjDef::Load (cload);
  171. break;
  172. case CHUNKID_DEF_VARIABLES:
  173. Load_Variables (cload);
  174. break;
  175. default:
  176. Debug_Say (("Unrecognized AirStrip Def chunkID\n"));
  177. break;
  178. }
  179. cload.Close_Chunk ();
  180. }
  181. return true;
  182. }
  183. ////////////////////////////////////////////////////////////////
  184. //
  185. // Load_Variables
  186. //
  187. ////////////////////////////////////////////////////////////////
  188. void
  189. AirStripGameObjDef::Load_Variables (ChunkLoadClass &cload)
  190. {
  191. while (cload.Open_Micro_Chunk ()) {
  192. switch (cload.Cur_Micro_Chunk_ID ())
  193. {
  194. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_CINEMATIC_LENGTH_TO_DROPOFF, CinematicLengthToDropOff);
  195. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_CINEMATIC_DEFID, CinematicDefID);
  196. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_CINEMATIC_SLOT_INDEX, CinematicSlotIndex);
  197. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_DISPLAY_VEHICLE_TIME, CinematicLengthToVehicleDisplay);
  198. default:
  199. Debug_Say (("Unrecognized AirStrip Def Variable chunkID\n"));
  200. break;
  201. }
  202. cload.Close_Micro_Chunk();
  203. }
  204. return ;
  205. }
  206. ////////////////////////////////////////////////////////////////
  207. //
  208. // Get_Factory
  209. //
  210. ////////////////////////////////////////////////////////////////
  211. const PersistFactoryClass &
  212. AirStripGameObjDef::Get_Factory (void) const
  213. {
  214. return _AirStripGameObjDefPersistFactory;
  215. }
  216. ////////////////////////////////////////////////////////////////
  217. //
  218. // AirStripGameObj
  219. //
  220. ////////////////////////////////////////////////////////////////
  221. AirStripGameObj::AirStripGameObj (void) :
  222. CinematicStartTimer (0),
  223. ClearDropoffZoneTimer (UNITIALIZED_TIMER),
  224. DisplayVehicleTimer (UNITIALIZED_TIMER),
  225. IsCinematicStarted (false),
  226. CinematicObject (NULL)
  227. {
  228. return ;
  229. }
  230. ////////////////////////////////////////////////////////////////
  231. //
  232. // ~AirStripGameObj
  233. //
  234. ////////////////////////////////////////////////////////////////
  235. AirStripGameObj::~AirStripGameObj (void)
  236. {
  237. return ;
  238. }
  239. ////////////////////////////////////////////////////////////////
  240. //
  241. // Get_Factory
  242. //
  243. ////////////////////////////////////////////////////////////////
  244. const PersistFactoryClass &
  245. AirStripGameObj::Get_Factory (void) const
  246. {
  247. return _AirStripGameObjPersistFactory;
  248. }
  249. ////////////////////////////////////////////////////////////////
  250. //
  251. // Init
  252. //
  253. ////////////////////////////////////////////////////////////////
  254. void AirStripGameObj::Init( void )
  255. {
  256. Init( Get_Definition() );
  257. }
  258. ////////////////////////////////////////////////////////////////
  259. //
  260. // Init
  261. //
  262. ////////////////////////////////////////////////////////////////
  263. void
  264. AirStripGameObj::Init (const AirStripGameObjDef &definition)
  265. {
  266. VehicleFactoryGameObj::Init (definition);
  267. return ;
  268. }
  269. ////////////////////////////////////////////////////////////////
  270. //
  271. // Get_Definition
  272. //
  273. ////////////////////////////////////////////////////////////////
  274. const AirStripGameObjDef &
  275. AirStripGameObj::Get_Definition (void) const
  276. {
  277. return (const AirStripGameObjDef &)BaseGameObj::Get_Definition ();
  278. }
  279. ////////////////////////////////////////////////////////////////
  280. //
  281. // Save
  282. //
  283. ////////////////////////////////////////////////////////////////
  284. bool
  285. AirStripGameObj::Save (ChunkSaveClass &csave)
  286. {
  287. csave.Begin_Chunk (CHUNKID_PARENT);
  288. VehicleFactoryGameObj::Save (csave);
  289. csave.End_Chunk ();
  290. csave.Begin_Chunk (CHUNKID_VARIABLES);
  291. csave.End_Chunk ();
  292. return true;
  293. }
  294. ////////////////////////////////////////////////////////////////
  295. //
  296. // Load
  297. //
  298. ////////////////////////////////////////////////////////////////
  299. bool
  300. AirStripGameObj::Load (ChunkLoadClass &cload)
  301. {
  302. while (cload.Open_Chunk ()) {
  303. switch (cload.Cur_Chunk_ID ()) {
  304. case CHUNKID_PARENT:
  305. VehicleFactoryGameObj::Load (cload);
  306. break;
  307. case CHUNKID_VARIABLES:
  308. Load_Variables (cload);
  309. break;
  310. default:
  311. Debug_Say (("Unrecognized AirStrip chunkID\n"));
  312. break;
  313. }
  314. cload.Close_Chunk();
  315. }
  316. return true;
  317. }
  318. ////////////////////////////////////////////////////////////////
  319. //
  320. // Load_Variables
  321. //
  322. ////////////////////////////////////////////////////////////////
  323. void
  324. AirStripGameObj::Load_Variables (ChunkLoadClass &cload)
  325. {
  326. while (cload.Open_Micro_Chunk ()) {
  327. /*switch (cload.Cur_Micro_Chunk_ID ())
  328. {
  329. default:
  330. Debug_Say (("Unrecognized AirStrip Variable chunkID\n"));
  331. break;
  332. }*/
  333. cload.Close_Micro_Chunk();
  334. }
  335. return ;
  336. }
  337. ////////////////////////////////////////////////////////////////
  338. //
  339. // CnC_Initialize
  340. //
  341. ////////////////////////////////////////////////////////////////
  342. void
  343. AirStripGameObj::CnC_Initialize (BaseControllerClass *base)
  344. {
  345. VehicleFactoryGameObj::CnC_Initialize (base);
  346. return ;
  347. }
  348. ////////////////////////////////////////////////////////////////
  349. //
  350. // Think
  351. //
  352. ////////////////////////////////////////////////////////////////
  353. void
  354. AirStripGameObj::Think (void)
  355. {
  356. WWPROFILE ("AirStrip Think");
  357. //
  358. // Begin the cinematic if necessary
  359. //
  360. if (IsDestroyed == false && GeneratingVehicleID != 0) {
  361. //
  362. // Start the cinematic (if necessary)
  363. //
  364. if (IsCinematicStarted == false) {
  365. CinematicStartTimer -= TimeManager::Get_Frame_Seconds ();
  366. if (CinematicStartTimer <= 0) {
  367. Start_Cinematic ();
  368. ClearDropoffZoneTimer = 0.8f * Get_Definition().CinematicLengthToDropOff;
  369. }
  370. }
  371. }
  372. if ((GeneratingVehicleID != 0) && (IsCinematicStarted)) {
  373. //
  374. // Check to see if its time to display the object or not
  375. //
  376. if (DisplayVehicleTimer > UNITIALIZED_TIMER) {
  377. DisplayVehicleTimer -= TimeManager::Get_Frame_Seconds ();
  378. if (DisplayVehicleTimer < 0) {
  379. //
  380. // Display the vehicle
  381. //
  382. if (Vehicle != NULL) {
  383. PhysicalGameObj *physical_obj = Vehicle.Get_Ptr ()->As_PhysicalGameObj ();
  384. physical_obj->Peek_Model ()->Set_Hidden (false);
  385. physical_obj->Set_Object_Dirty_Bit (NetworkObjectClass::BIT_RARE, true);
  386. }
  387. DisplayVehicleTimer = UNITIALIZED_TIMER;
  388. // Tell the vehicle to drive to one of the delivery points
  389. Deliver_Vehicle();
  390. }
  391. }
  392. //
  393. // Check if we need to clear the dropoff zone
  394. //
  395. if (ClearDropoffZoneTimer > UNITIALIZED_TIMER) {
  396. ClearDropoffZoneTimer -= TimeManager::Get_Frame_Seconds ();
  397. if (ClearDropoffZoneTimer < 0) {
  398. Destroy_Blocking_Objects ();
  399. ClearDropoffZoneTimer = UNITIALIZED_TIMER;
  400. }
  401. }
  402. }
  403. VehicleFactoryGameObj::Think ();
  404. return ;
  405. }
  406. ////////////////////////////////////////////////////////////////
  407. //
  408. // Begin_Generation
  409. //
  410. ////////////////////////////////////////////////////////////////
  411. void
  412. AirStripGameObj::Begin_Generation (void)
  413. {
  414. CinematicStartTimer = GenerationTime - Get_Definition ().CinematicLengthToDropOff;
  415. IsCinematicStarted = false;
  416. return ;
  417. }
  418. ////////////////////////////////////////////////////////////////
  419. //
  420. // Start_Cinematic
  421. //
  422. ////////////////////////////////////////////////////////////////
  423. void
  424. AirStripGameObj::Start_Cinematic (void)
  425. {
  426. if (CombatManager::I_Am_Server () == false) {
  427. return ;
  428. }
  429. //
  430. // Create the vehicle
  431. //
  432. VehicleGameObj *vehicle = Create_Vehicle ();
  433. if (vehicle != NULL) {
  434. //
  435. // Hide the vehicle until later
  436. //
  437. if (vehicle->Peek_Model () != NULL) {
  438. vehicle->Peek_Model ()->Set_Hidden (true);
  439. vehicle->Set_Object_Dirty_Bit (NetworkObjectClass::BIT_RARE, true);
  440. }
  441. //
  442. // Lock the vehicle
  443. //
  444. if (Purchaser != NULL) {
  445. vehicle->Lock_Vehicle(Purchaser,VEHICLE_LOCK_TIME);
  446. }
  447. //
  448. // Create the cinematic controller
  449. //
  450. CinematicObject = ObjectLibraryManager::Create_Object (Get_Definition ().CinematicDefID);
  451. if (CinematicObject != NULL) {
  452. CinematicObject->Start_Observers ();
  453. //
  454. // Position the cinematic controller in the world
  455. //
  456. Matrix3D test_tm = CreationTM;
  457. CinematicObject->Set_Transform (test_tm);
  458. //
  459. // Try to find the script parser so we can communicate with it
  460. //
  461. const GameObjObserverList &script_list = CinematicObject->Get_Observers ();
  462. for (int index = 0; index < script_list.Count (); index ++) {
  463. GameObjObserverClass *script = script_list[index];
  464. if (::lstrcmpi (script->Get_Name (), "Test_Cinematic") == 0) {
  465. //
  466. // Attach the vehicle to the given slot in the cinematic
  467. //
  468. int slot = 10000 + Get_Definition ().CinematicSlotIndex;
  469. script->Custom (this, slot, vehicle->Get_ID (), this);
  470. break;
  471. }
  472. }
  473. }
  474. }
  475. IsCinematicStarted = true;
  476. DisplayVehicleTimer = Get_Definition ().CinematicLengthToVehicleDisplay;
  477. return ;
  478. }