vehiclefactorygameobj.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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/vehiclefactorygameobj.cpp $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/19/02 10:44a $*
  29. * *
  30. * $Revision:: 26 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "vehiclefactorygameobj.h"
  36. #include "basecontroller.h"
  37. #include "vehicle.h"
  38. #include "wwhack.h"
  39. #include "simpledefinitionfactory.h"
  40. #include "persistfactory.h"
  41. #include "definitionmgr.h"
  42. #include "combatchunkid.h"
  43. #include "debug.h"
  44. #include "scriptzone.h"
  45. #include "wwprofile.h"
  46. #include "basecontroller.h"
  47. #include "doors.h"
  48. #include "objlibrary.h"
  49. #include "combat.h"
  50. #include "soldier.h"
  51. #include "pathfind.h"
  52. #include "waypath.h"
  53. #include "gameobjmanager.h"
  54. #include "mapmgr.h"
  55. const float UNITIALIZED_TIMER = -100.0F;
  56. const int DEFAULT_MAX_VEHICLES_PER_TEAM = 8;
  57. ////////////////////////////////////////////////////////////////
  58. // Hacks
  59. ////////////////////////////////////////////////////////////////
  60. DECLARE_FORCE_LINK (VehicleFactory)
  61. ////////////////////////////////////////////////////////////////
  62. // Editable and persist factories
  63. ////////////////////////////////////////////////////////////////
  64. SimplePersistFactoryClass <VehicleFactoryGameObjDef, CHUNKID_GAME_OBJECT_DEF_VEHICLE_FACTORY> _VehicleFactoryGameObjDefPersistFactory;
  65. SimplePersistFactoryClass <VehicleFactoryGameObj, CHUNKID_GAME_OBJECT_VEHICLE_FACTORY> _VehicleFactoryGameObjPersistFactory;
  66. DECLARE_DEFINITION_FACTORY (VehicleFactoryGameObjDef, CLASSID_GAME_OBJECT_DEF_VEHICLE_FACTORY, "Vehicle Factory") _VehicleFactoryGameObjDefDefFactory (false);
  67. ////////////////////////////////////////////////////////////////
  68. // Static members
  69. ////////////////////////////////////////////////////////////////
  70. int VehicleFactoryGameObj::MaxVehiclesPerTeam = DEFAULT_MAX_VEHICLES_PER_TEAM;
  71. ////////////////////////////////////////////////////////////////
  72. // Save/Load constants
  73. ////////////////////////////////////////////////////////////////
  74. enum
  75. {
  76. CHUNKID_DEF_PARENT = 0x02200638,
  77. CHUNKID_DEF_VARIABLES,
  78. MICROCHUNKID_DEF_UNUSED = 1,
  79. MICROCHUNKID_DEF_PADCLEARINGWARHEAD,
  80. MICROCHUNKID_DEF_TOTALBUILDINGTIME,
  81. };
  82. enum
  83. {
  84. CHUNKID_PARENT = 0x0219043,
  85. CHUNKID_VARIABLES,
  86. MICROCHUNKID_CREATION_TM = 1,
  87. MICROCHUNKID_IS_BUSY,
  88. MICROCHUNKID_GENERATION_TIME,
  89. MICROCHUNKID_GENERATING_VEHICLE_ID,
  90. };
  91. ////////////////////////////////////////////////////////////////
  92. //
  93. // VehicleFactoryGameObjDef
  94. //
  95. ////////////////////////////////////////////////////////////////
  96. VehicleFactoryGameObjDef::VehicleFactoryGameObjDef (void) :
  97. PadClearingWarhead(25), // default to "DEATH"
  98. TotalBuildingTime(12.0f)
  99. {
  100. #ifdef PARAM_EDITING_ON
  101. EnumParameterClass *param = new EnumParameterClass( &PadClearingWarhead );
  102. param->Set_Name ( "Pad Clearing Warhead" );
  103. for (int i = 0; i < ArmorWarheadManager::Get_Num_Warhead_Types(); i++) {
  104. param->Add_Value ( ArmorWarheadManager::Get_Warhead_Name( i ), i );
  105. }
  106. GENERIC_EDITABLE_PARAM(VehicleFactoryGameObjDef,param)
  107. #endif
  108. return ;
  109. }
  110. ////////////////////////////////////////////////////////////////
  111. //
  112. // ~VehicleFactoryGameObjDef
  113. //
  114. ////////////////////////////////////////////////////////////////
  115. VehicleFactoryGameObjDef::~VehicleFactoryGameObjDef (void)
  116. {
  117. return ;
  118. }
  119. ////////////////////////////////////////////////////////////////
  120. //
  121. // Get_Class_ID
  122. //
  123. ////////////////////////////////////////////////////////////////
  124. uint32
  125. VehicleFactoryGameObjDef::Get_Class_ID (void) const
  126. {
  127. return CLASSID_GAME_OBJECT_DEF_VEHICLE_FACTORY;
  128. }
  129. ////////////////////////////////////////////////////////////////
  130. //
  131. // Create
  132. //
  133. ////////////////////////////////////////////////////////////////
  134. PersistClass *
  135. VehicleFactoryGameObjDef::Create (void) const
  136. {
  137. VehicleFactoryGameObj *building = new VehicleFactoryGameObj;
  138. building->Init (*this);
  139. return building;
  140. }
  141. ////////////////////////////////////////////////////////////////
  142. //
  143. // Create
  144. //
  145. ////////////////////////////////////////////////////////////////
  146. bool
  147. VehicleFactoryGameObjDef::Save (ChunkSaveClass &csave)
  148. {
  149. csave.Begin_Chunk (CHUNKID_DEF_PARENT);
  150. BuildingGameObjDef::Save (csave);
  151. csave.End_Chunk ();
  152. csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
  153. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_PADCLEARINGWARHEAD, PadClearingWarhead);
  154. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_DEF_TOTALBUILDINGTIME, TotalBuildingTime);
  155. csave.End_Chunk ();
  156. return true;
  157. }
  158. ////////////////////////////////////////////////////////////////
  159. //
  160. // Load
  161. //
  162. ////////////////////////////////////////////////////////////////
  163. bool
  164. VehicleFactoryGameObjDef::Load (ChunkLoadClass &cload)
  165. {
  166. while (cload.Open_Chunk ())
  167. {
  168. switch (cload.Cur_Chunk_ID ())
  169. {
  170. case CHUNKID_DEF_PARENT:
  171. BuildingGameObjDef::Load (cload);
  172. break;
  173. case CHUNKID_DEF_VARIABLES:
  174. Load_Variables (cload);
  175. break;
  176. default:
  177. Debug_Say (("Unrecognized Vehicle Factory Def chunkID\n"));
  178. break;
  179. }
  180. cload.Close_Chunk ();
  181. }
  182. return true;
  183. }
  184. ////////////////////////////////////////////////////////////////
  185. //
  186. // Load_Variables
  187. //
  188. ////////////////////////////////////////////////////////////////
  189. void
  190. VehicleFactoryGameObjDef::Load_Variables (ChunkLoadClass &cload)
  191. {
  192. while (cload.Open_Micro_Chunk ()) {
  193. switch (cload.Cur_Micro_Chunk_ID ())
  194. {
  195. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_PADCLEARINGWARHEAD, PadClearingWarhead);
  196. READ_MICRO_CHUNK (cload, MICROCHUNKID_DEF_TOTALBUILDINGTIME, TotalBuildingTime);
  197. default:
  198. Debug_Say (("Unrecognized Vehicle Factory Def Variable chunkID\n"));
  199. break;
  200. }
  201. cload.Close_Micro_Chunk();
  202. }
  203. return ;
  204. }
  205. ////////////////////////////////////////////////////////////////
  206. //
  207. // Get_Factory
  208. //
  209. ////////////////////////////////////////////////////////////////
  210. const PersistFactoryClass &
  211. VehicleFactoryGameObjDef::Get_Factory (void) const
  212. {
  213. return _VehicleFactoryGameObjDefPersistFactory;
  214. }
  215. ////////////////////////////////////////////////////////////////
  216. //
  217. // VehicleFactoryGameObj
  218. //
  219. ////////////////////////////////////////////////////////////////
  220. VehicleFactoryGameObj::VehicleFactoryGameObj (void) :
  221. CreationTM (1),
  222. IsBusy (false),
  223. GenerationTime (0),
  224. GeneratingVehicleID (0),
  225. GeneratingRegion (Vector3 (0, 0, 0), Vector3 (0, 0, 0)),
  226. LastDeliveryPath (0),
  227. EndTimer (UNITIALIZED_TIMER)
  228. {
  229. return ;
  230. }
  231. ////////////////////////////////////////////////////////////////
  232. //
  233. // ~VehicleFactoryGameObj
  234. //
  235. ////////////////////////////////////////////////////////////////
  236. VehicleFactoryGameObj::~VehicleFactoryGameObj (void)
  237. {
  238. return ;
  239. }
  240. ////////////////////////////////////////////////////////////////
  241. //
  242. // Get_Factory
  243. //
  244. ////////////////////////////////////////////////////////////////
  245. const PersistFactoryClass &
  246. VehicleFactoryGameObj::Get_Factory (void) const
  247. {
  248. return _VehicleFactoryGameObjPersistFactory;
  249. }
  250. ////////////////////////////////////////////////////////////////
  251. //
  252. // Init
  253. //
  254. ////////////////////////////////////////////////////////////////
  255. void VehicleFactoryGameObj::Init (void)
  256. {
  257. Init (Get_Definition ());
  258. return ;
  259. }
  260. ////////////////////////////////////////////////////////////////
  261. //
  262. // Init
  263. //
  264. ////////////////////////////////////////////////////////////////
  265. void
  266. VehicleFactoryGameObj::Init (const VehicleFactoryGameObjDef &definition)
  267. {
  268. BuildingGameObj::Init (definition);
  269. return ;
  270. }
  271. ////////////////////////////////////////////////////////////////
  272. //
  273. // Get_Definition
  274. //
  275. ////////////////////////////////////////////////////////////////
  276. const VehicleFactoryGameObjDef &
  277. VehicleFactoryGameObj::Get_Definition (void) const
  278. {
  279. return (const VehicleFactoryGameObjDef &)BaseGameObj::Get_Definition ();
  280. }
  281. ////////////////////////////////////////////////////////////////
  282. //
  283. // Save
  284. //
  285. ////////////////////////////////////////////////////////////////
  286. bool
  287. VehicleFactoryGameObj::Save (ChunkSaveClass &csave)
  288. {
  289. csave.Begin_Chunk (CHUNKID_PARENT);
  290. BuildingGameObj::Save (csave);
  291. csave.End_Chunk ();
  292. csave.Begin_Chunk (CHUNKID_VARIABLES);
  293. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_CREATION_TM, CreationTM);
  294. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_IS_BUSY, IsBusy);
  295. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_GENERATION_TIME, GenerationTime);
  296. WRITE_MICRO_CHUNK (csave, MICROCHUNKID_GENERATING_VEHICLE_ID, GeneratingVehicleID);
  297. csave.End_Chunk ();
  298. return true;
  299. }
  300. ////////////////////////////////////////////////////////////////
  301. //
  302. // Load
  303. //
  304. ////////////////////////////////////////////////////////////////
  305. bool
  306. VehicleFactoryGameObj::Load (ChunkLoadClass &cload)
  307. {
  308. while (cload.Open_Chunk ()) {
  309. switch (cload.Cur_Chunk_ID ()) {
  310. case CHUNKID_PARENT:
  311. BuildingGameObj::Load (cload);
  312. break;
  313. case CHUNKID_VARIABLES:
  314. Load_Variables (cload);
  315. break;
  316. default:
  317. Debug_Say (("Unrecognized Vehicle Factory chunkID\n"));
  318. break;
  319. }
  320. cload.Close_Chunk();
  321. }
  322. return true;
  323. }
  324. ////////////////////////////////////////////////////////////////
  325. //
  326. // Load_Variables
  327. //
  328. ////////////////////////////////////////////////////////////////
  329. void
  330. VehicleFactoryGameObj::Load_Variables (ChunkLoadClass &cload)
  331. {
  332. while (cload.Open_Micro_Chunk ()) {
  333. switch (cload.Cur_Micro_Chunk_ID ())
  334. {
  335. READ_MICRO_CHUNK (cload, MICROCHUNKID_CREATION_TM, CreationTM);
  336. READ_MICRO_CHUNK (cload, MICROCHUNKID_IS_BUSY, IsBusy);
  337. READ_MICRO_CHUNK (cload, MICROCHUNKID_GENERATION_TIME, GenerationTime);
  338. READ_MICRO_CHUNK (cload, MICROCHUNKID_GENERATING_VEHICLE_ID, GeneratingVehicleID);
  339. default:
  340. Debug_Say (("Unrecognized Vehicle Factory Variable chunkID\n"));
  341. break;
  342. }
  343. cload.Close_Micro_Chunk();
  344. }
  345. return ;
  346. }
  347. ////////////////////////////////////////////////////////////////
  348. //
  349. // CnC_Initialize
  350. //
  351. ////////////////////////////////////////////////////////////////
  352. void
  353. VehicleFactoryGameObj::CnC_Initialize (BaseControllerClass *base)
  354. {
  355. BuildingGameObj::CnC_Initialize (base);
  356. //
  357. // Get the building's "position"
  358. //
  359. Vector3 pos;
  360. Get_Position (&pos);
  361. //
  362. // Find the closest vehicle construction zone to the building
  363. //
  364. ScriptZoneGameObj *zone = NULL;
  365. zone = ScriptZoneGameObj::Find_Closest_Zone (pos, ZoneConstants::TYPE_VEHICLE_CONSTRUCTION);
  366. if (zone != NULL) {
  367. GeneratingRegion = zone->Get_Bounding_Box ();
  368. //
  369. // Get rid of the zone (if the game doesn't need it anymore)
  370. //
  371. if (zone->Get_Observers ().Count () == 0) {
  372. zone->Set_Delete_Pending ();
  373. }
  374. }
  375. //
  376. // Let the base know it can generate vehicles
  377. //
  378. if (BaseController != NULL) {
  379. BaseController->Set_Can_Generate_Vehicles (true);
  380. }
  381. return ;
  382. }
  383. ////////////////////////////////////////////////////////////////
  384. //
  385. // Think
  386. //
  387. ////////////////////////////////////////////////////////////////
  388. void
  389. VehicleFactoryGameObj::Think (void)
  390. {
  391. WWPROFILE ("Vehicle Factory Think");
  392. if (EndTimer > UNITIALIZED_TIMER) {
  393. EndTimer -= TimeManager::Get_Frame_Seconds ();
  394. if (EndTimer < 0) {
  395. //
  396. // Handle the end-condition
  397. //
  398. On_Generation_Complete ();
  399. EndTimer = UNITIALIZED_TIMER;
  400. }
  401. }
  402. BuildingGameObj::Think ();
  403. return ;
  404. }
  405. ////////////////////////////////////////////////////////////////
  406. //
  407. // Is_Available_For_Purchase
  408. //
  409. // In addition to checking whether the factory is busy or
  410. // destroyed, this function checks whether the team has
  411. // already created its maximum number of vehicles.
  412. //
  413. ////////////////////////////////////////////////////////////////
  414. bool
  415. VehicleFactoryGameObj::Is_Available_For_Purchase (void) const
  416. {
  417. int team_vehicle_count = Get_Team_Vehicle_Count();
  418. return (Is_Available() & (team_vehicle_count < Get_Max_Vehicles_Per_Team()));
  419. }
  420. ////////////////////////////////////////////////////////////////
  421. //
  422. // Is_Available_For_Purchase
  423. //
  424. // Counts the number of vehicles active for this factory's team
  425. // (not including the harvester!)
  426. //
  427. ////////////////////////////////////////////////////////////////
  428. int
  429. VehicleFactoryGameObj::Get_Team_Vehicle_Count(void) const
  430. {
  431. int team_vehicle_count = 0;
  432. VehicleGameObj * harvy = NULL;
  433. BaseControllerClass * base = BaseControllerClass::Find_Base(Get_Player_Type());
  434. if (base != NULL) {
  435. harvy = base->Get_Harvester_Vehicle();
  436. }
  437. SLNode<SmartGameObj> * smart_objnode;
  438. for (smart_objnode = GameObjManager::Get_Smart_Game_Obj_List()->Head(); smart_objnode; smart_objnode = smart_objnode->Next()) {
  439. VehicleGameObj * obj = smart_objnode->Data()->As_VehicleGameObj();
  440. if ( (obj != NULL) &&
  441. (obj != harvy) &&
  442. (obj->Peek_Physical_Object() != NULL) &&
  443. (obj->Peek_Physical_Object()->As_VehiclePhysClass() != NULL) )
  444. {
  445. if (obj->Get_Definition().Get_Default_Player_Type() == Get_Player_Type()) {
  446. team_vehicle_count++;
  447. }
  448. }
  449. }
  450. return team_vehicle_count;
  451. }
  452. ////////////////////////////////////////////////////////////////
  453. //
  454. // On_Generation_Complete
  455. //
  456. ////////////////////////////////////////////////////////////////
  457. void
  458. VehicleFactoryGameObj::On_Generation_Complete (void)
  459. {
  460. //
  461. // Notify the base that we just created a vehicle
  462. //
  463. if (Vehicle != NULL) {
  464. //
  465. // Shut off the action making the vehicle drive off the pad.
  466. // (if it didn't make it by now, give up anyway)
  467. //
  468. VehicleGameObj * vehicle_obj = Vehicle.Get_Ptr ()->As_VehicleGameObj();
  469. if (vehicle_obj != NULL) {
  470. ActionClass * action = vehicle_obj->Get_Action();
  471. if (action != NULL) {
  472. // Change the arrived distance so the vehicles think
  473. // they've arrived at their destination (complete the action)
  474. action->Get_Parameters().Set_Movement(Vector3(0,0,0), 0.0f, 1000.0f);
  475. }
  476. BaseController->On_Vehicle_Generated (vehicle_obj);
  477. }
  478. }
  479. //
  480. // Reset our variables
  481. //
  482. GeneratingVehicleID = 0;
  483. GenerationTime = 0;
  484. IsBusy = false;
  485. Set_Object_Dirty_Bit (BIT_RARE, true);
  486. return ;
  487. }
  488. ////////////////////////////////////////////////////////////////
  489. //
  490. // On_Destroyed
  491. //
  492. ////////////////////////////////////////////////////////////////
  493. void
  494. VehicleFactoryGameObj::On_Destroyed (void)
  495. {
  496. BuildingGameObj::On_Destroyed ();
  497. //
  498. // Switch off the ability to build vehicles
  499. //
  500. if (BaseController != NULL && CombatManager::I_Am_Server ()) {
  501. BaseController->Set_Can_Generate_Vehicles (false);
  502. }
  503. return ;
  504. }
  505. ////////////////////////////////////////////////////////////////
  506. //
  507. // Request_Vehicle
  508. //
  509. ////////////////////////////////////////////////////////////////
  510. bool
  511. VehicleFactoryGameObj::Request_Vehicle (int definition_id, float generation_time,SoldierGameObj * purchaser)
  512. {
  513. bool retval = false;
  514. //
  515. // Start the generation if possible
  516. //
  517. if (IsBusy == false && definition_id != 0) {
  518. GeneratingVehicleID = definition_id;
  519. GenerationTime = generation_time;
  520. IsBusy = true;
  521. Purchaser = purchaser;
  522. EndTimer = Get_Definition().Get_Total_Building_Time();
  523. Begin_Generation ();
  524. Set_Object_Dirty_Bit (BIT_RARE, true);
  525. }
  526. return retval;
  527. }
  528. ////////////////////////////////////////////////////////////////
  529. //
  530. // Destroy_Blocking_Objects
  531. //
  532. ////////////////////////////////////////////////////////////////
  533. void
  534. VehicleFactoryGameObj::Destroy_Blocking_Objects (void)
  535. {
  536. if (CombatManager::I_Am_Server () == false) {
  537. return ;
  538. }
  539. //
  540. // Collect the dynamic physics objects in the generation region
  541. //
  542. NonRefPhysListClass objs_to_kill;
  543. PhysicsSceneClass::Get_Instance ()->Collect_Objects (GeneratingRegion, false, true, &objs_to_kill);
  544. //
  545. // Loop over all the objects
  546. //
  547. NonRefPhysListIterator it (&objs_to_kill);
  548. for (it.First (); !it.Is_Done (); it.Next ()) {
  549. PhysicalGameObj *gameobj = NULL;
  550. //
  551. // Get the game object from this physics object
  552. //
  553. if (it.Peek_Obj()->Get_Observer () != NULL) {
  554. gameobj = ((CombatPhysObserverClass *)it.Peek_Obj()->Get_Observer())->As_PhysicalGameObj();
  555. }
  556. //
  557. // Kill the object
  558. //
  559. if (gameobj != NULL && gameobj != Vehicle && gameobj->As_ArmedGameObj () != NULL) {
  560. //
  561. // Destroy the object
  562. //
  563. OffenseObjectClass offense_obj (10000.0F, Get_Definition().Get_Pad_Clearing_Warhead());
  564. gameobj->Apply_Damage_Extended( offense_obj );
  565. }
  566. }
  567. return ;
  568. }
  569. ////////////////////////////////////////////////////////////////
  570. //
  571. // Deliver_Vehicle,
  572. // Gives the vehicle an action to follow one of the delivery
  573. // waypaths out of the construction zone.
  574. //
  575. ////////////////////////////////////////////////////////////////
  576. void
  577. VehicleFactoryGameObj::Deliver_Vehicle(void)
  578. {
  579. //
  580. // Give the vehicle a command to drive to one of the delivery points
  581. //
  582. PathfindClass * pathfind = PathfindClass::Get_Instance();
  583. AABoxClass box;
  584. box.Center = GeneratingRegion.Center;
  585. box.Extent = GeneratingRegion.Extent;
  586. if (pathfind != NULL) {
  587. WaypathClass * path = pathfind->Get_Waypath_Starting_In_Box(box,LastDeliveryPath);
  588. if (path != NULL) {
  589. LastDeliveryPath = (LastDeliveryPath + 1) % pathfind->Count_Waypaths_Starting_In_Box(box);
  590. if ((Vehicle.Get_Ptr() != NULL) && (Vehicle.Get_Ptr()->As_VehicleGameObj() != NULL)) {
  591. VehicleGameObj * vehicle = Vehicle.Get_Ptr ()->As_VehicleGameObj();
  592. ActionClass * action = vehicle->Get_Action();
  593. if (action != NULL) {
  594. ActionParamsStruct parameters;
  595. parameters.Priority = 1;
  596. parameters.Set_Movement(Vector3(0,0,0), 1.0f, 1.0f);
  597. parameters.WaypathID = path->Get_ID();
  598. parameters.ShutdownEngineOnArrival = true;
  599. action->Goto(parameters);
  600. vehicle->Set_Vehicle_Delivered();
  601. BaseController->On_Vehicle_Delivered(vehicle);
  602. }
  603. }
  604. REF_PTR_RELEASE(path);
  605. }
  606. }
  607. }
  608. ////////////////////////////////////////////////////////////////
  609. //
  610. // Create_Vehicle
  611. //
  612. ////////////////////////////////////////////////////////////////
  613. VehicleGameObj *
  614. VehicleFactoryGameObj::Create_Vehicle (void)
  615. {
  616. if (CombatManager::I_Am_Server () == false) {
  617. return NULL;
  618. }
  619. VehicleGameObj *vehicle = NULL;
  620. if (GeneratingVehicleID != 0) {
  621. //
  622. // Create the vehicle object
  623. //
  624. PhysicalGameObj *physical_obj = ObjectLibraryManager::Create_Object (GeneratingVehicleID);
  625. //
  626. // If this is a VTOL vehicle, see if we should let them have it...
  627. //
  628. if ((physical_obj != NULL) && (physical_obj->Peek_Physical_Object() != NULL)) {
  629. if ( (MapMgrClass::Are_VTOL_Vehicles_Enabled() == false) &&
  630. (physical_obj->Peek_Physical_Object()->As_VTOLVehicleClass() != NULL)
  631. )
  632. {
  633. physical_obj->Set_Delete_Pending();
  634. physical_obj = NULL;
  635. }
  636. }
  637. //
  638. // If everything is ok, proceed
  639. //
  640. if (physical_obj != NULL && physical_obj->As_VehicleGameObj () != NULL) {
  641. vehicle = physical_obj->As_VehicleGameObj ();
  642. vehicle->Start_Observers();
  643. Vehicle = vehicle;
  644. }
  645. }
  646. return vehicle;
  647. }
  648. /////////////////////////////////////////////////////////////////////////////
  649. //
  650. // Import_Rare
  651. //
  652. /////////////////////////////////////////////////////////////////////////////
  653. void
  654. VehicleFactoryGameObj::Import_Rare (BitStreamClass &packet)
  655. {
  656. BuildingGameObj::Import_Rare (packet);
  657. //
  658. // Read the state information from the server
  659. //
  660. packet.Get (IsBusy);
  661. return ;
  662. }
  663. /////////////////////////////////////////////////////////////////////////////
  664. //
  665. // Export_Rare
  666. //
  667. /////////////////////////////////////////////////////////////////////////////
  668. void
  669. VehicleFactoryGameObj::Export_Rare (BitStreamClass &packet)
  670. {
  671. BuildingGameObj::Export_Rare (packet);
  672. //
  673. // Transmit the state information
  674. //
  675. packet.Add (IsBusy);
  676. return ;
  677. }