SpawnerNode.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/SpawnerNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/13/01 9:44a $*
  29. * *
  30. * $Revision:: 22 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "spawnernode.h"
  37. #include "sceneeditor.h"
  38. #include "filemgr.h"
  39. #include "_assetmgr.h"
  40. #include "editorassetmgr.h"
  41. #include "w3d_file.h"
  42. #include "cameramgr.h"
  43. #include "collisiongroups.h"
  44. #include "persistfactory.h"
  45. #include "editorchunkids.h"
  46. #include "preset.h"
  47. #include "spawn.h"
  48. #include "physicalgameobj.h"
  49. #include "presetmgr.h"
  50. #include "decophys.h"
  51. #include "nodemgr.h"
  52. #include "modelutils.h"
  53. #include "spawnpointnode.h"
  54. #include "nodescriptsproppage.h"
  55. #include "nodeinfopage.h"
  56. #include "editorpropsheet.h"
  57. #include "positionpage.h"
  58. #include "editscript.h"
  59. //////////////////////////////////////////////////////////////////////////////
  60. // Persist factory
  61. //////////////////////////////////////////////////////////////////////////////
  62. SimplePersistFactoryClass<SpawnerNodeClass, CHUNKID_NODE_SPAWNER> _SpawnerNodePersistFactory;
  63. //////////////////////////////////////////////////////////////////////////////
  64. // Save/load constants
  65. //////////////////////////////////////////////////////////////////////////////
  66. enum
  67. {
  68. CHUNKID_VARIABLES = 0x10251200,
  69. CHUNKID_BASE_CLASS,
  70. CHUNKID_SCRIPT
  71. };
  72. enum
  73. {
  74. VARID_SPAWN_POINT = 0x01,
  75. };
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // SpawnerNodeClass
  79. //
  80. //////////////////////////////////////////////////////////////////////////////
  81. SpawnerNodeClass::SpawnerNodeClass (PresetClass *preset)
  82. : m_PhysObj (NULL),
  83. m_SpawnerObj (NULL),
  84. NodeClass (preset)
  85. {
  86. return ;
  87. }
  88. //////////////////////////////////////////////////////////////////////////////
  89. //
  90. // SpawnerNodeClass
  91. //
  92. //////////////////////////////////////////////////////////////////////////////
  93. SpawnerNodeClass::SpawnerNodeClass (const SpawnerNodeClass &src)
  94. : m_PhysObj (NULL),
  95. m_SpawnerObj (NULL),
  96. NodeClass (NULL)
  97. {
  98. *this = src;
  99. return ;
  100. }
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // ~SpawnerNodeClass
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. SpawnerNodeClass::~SpawnerNodeClass (void)
  107. {
  108. Free_Spawn_Points ();
  109. Remove_From_Scene ();
  110. Free_Scripts ();
  111. MEMBER_RELEASE (m_PhysObj);
  112. SAFE_DELETE (m_SpawnerObj);
  113. return ;
  114. }
  115. //////////////////////////////////////////////////////////////////////////////
  116. //
  117. // Initialize
  118. //
  119. // Note: This may be called more than once. It is used as an 'initialize'
  120. // and a 're-initialize'.
  121. //
  122. //////////////////////////////////////////////////////////////////////////////
  123. void
  124. SpawnerNodeClass::Initialize (void)
  125. {
  126. MEMBER_RELEASE (m_PhysObj);
  127. SAFE_DELETE (m_SpawnerObj);
  128. SpawnerDefClass *definition = static_cast<SpawnerDefClass *> (m_Preset->Get_Definition ());
  129. if (definition != NULL) {
  130. //
  131. // Create the spawner object object
  132. //
  133. Load_Assets ();
  134. m_Preset->Load_All_Assets ();
  135. Create_Spawner_Obj ();
  136. //
  137. // Get a model to represet the spawner with
  138. //
  139. RenderObjClass *model = Get_Spawned_Model ();
  140. if (model != NULL) {
  141. //
  142. // Create our own physics object around the visual representation
  143. // of the game object.
  144. //
  145. m_PhysObj = new DecorationPhysClass;
  146. m_PhysObj->Set_Model (model);
  147. model->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  148. ::Set_Model_Collision_Type (model, COLLISION_TYPE_6);
  149. MEMBER_RELEASE (model);
  150. //
  151. // Make sure the physics object has the correct position
  152. //
  153. Set_Transform (m_Transform);
  154. }
  155. }
  156. return ;
  157. }
  158. ////////////////////////////////////////////////////////////////
  159. //
  160. // Get_Factory
  161. //
  162. ////////////////////////////////////////////////////////////////
  163. const PersistFactoryClass &
  164. SpawnerNodeClass::Get_Factory (void) const
  165. {
  166. return _SpawnerNodePersistFactory;
  167. }
  168. /////////////////////////////////////////////////////////////////
  169. //
  170. // Save
  171. //
  172. /////////////////////////////////////////////////////////////////
  173. bool
  174. SpawnerNodeClass::Save (ChunkSaveClass &csave)
  175. {
  176. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  177. NodeClass::Save (csave);
  178. csave.End_Chunk ();
  179. //
  180. // Save the list of scripts
  181. //
  182. for (int index = 0; index < m_Scripts.Count (); index ++) {
  183. EditScriptClass *script = m_Scripts[index];
  184. //
  185. // Have this script save itself
  186. //
  187. csave.Begin_Chunk (CHUNKID_SCRIPT);
  188. script->Save (csave);
  189. csave.End_Chunk ();
  190. }
  191. csave.Begin_Chunk (CHUNKID_VARIABLES);
  192. //
  193. // Save the list of spawn points transforms
  194. //
  195. for (index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  196. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  197. if (spawn_point != NULL) {
  198. Matrix3D tm = spawn_point->Get_Transform ();
  199. WRITE_MICRO_CHUNK (csave, VARID_SPAWN_POINT, tm);
  200. }
  201. }
  202. csave.End_Chunk ();
  203. return true;
  204. }
  205. /////////////////////////////////////////////////////////////////
  206. //
  207. // Load
  208. //
  209. /////////////////////////////////////////////////////////////////
  210. bool
  211. SpawnerNodeClass::Load (ChunkLoadClass &cload)
  212. {
  213. Free_Spawn_Points ();
  214. Free_Scripts ();
  215. while (cload.Open_Chunk ()) {
  216. switch (cload.Cur_Chunk_ID ()) {
  217. case CHUNKID_BASE_CLASS:
  218. NodeClass::Load (cload);
  219. break;
  220. case CHUNKID_SCRIPT:
  221. {
  222. EditScriptClass *script = new EditScriptClass;
  223. if (script->Load (cload)) {
  224. m_Scripts.Add (script);
  225. }
  226. }
  227. break;
  228. case CHUNKID_VARIABLES:
  229. Load_Variables (cload);
  230. break;
  231. }
  232. cload.Close_Chunk ();
  233. }
  234. SaveLoadSystemClass::Register_Post_Load_Callback (this);
  235. return true;
  236. }
  237. ///////////////////////////////////////////////////////////////////////
  238. //
  239. // On_Post_Load
  240. //
  241. ///////////////////////////////////////////////////////////////////////
  242. void
  243. SpawnerNodeClass::On_Post_Load (void)
  244. {
  245. //
  246. // If the spawner isn't valid, then remove it from the system
  247. //
  248. if (m_Preset == NULL) {
  249. ::Get_Scene_Editor ()->Delete_Node (this, false);
  250. } else {
  251. //
  252. // Create the spawner object object
  253. //
  254. Load_Assets ();
  255. m_Preset->Load_All_Assets ();
  256. Create_Spawner_Obj ();
  257. //
  258. // Add each spawn point at the given locations
  259. //
  260. for (int index = 0; index < m_SpawnPointLoadList.Count (); index ++) {
  261. Add_Spawn_Point (m_SpawnPointLoadList[index]);
  262. }
  263. }
  264. return ;
  265. }
  266. ///////////////////////////////////////////////////////////////////////
  267. //
  268. // Load_Variables
  269. //
  270. ///////////////////////////////////////////////////////////////////////
  271. bool
  272. SpawnerNodeClass::Load_Variables (ChunkLoadClass &cload)
  273. {
  274. //
  275. // Loop through all the microchunks that define the variables
  276. //
  277. while (cload.Open_Micro_Chunk ()) {
  278. switch (cload.Cur_Micro_Chunk_ID ()) {
  279. case VARID_SPAWN_POINT:
  280. {
  281. //
  282. // Read the spawn point's transfrom from the chunk
  283. //
  284. Matrix3D tm;
  285. cload.Read (&tm, sizeof (tm));
  286. m_SpawnPointLoadList.Add (tm);
  287. //Add_Spawn_Point (tm);
  288. }
  289. break;
  290. }
  291. cload.Close_Micro_Chunk ();
  292. }
  293. return true;
  294. }
  295. ////////////////////////////////////////////////////////////////
  296. //
  297. // Get_Spawned_Model
  298. //
  299. ////////////////////////////////////////////////////////////////
  300. RenderObjClass *
  301. SpawnerNodeClass::Get_Spawned_Model (void)
  302. {
  303. RenderObjClass *model = NULL;
  304. if (m_SpawnerObj != NULL) {
  305. //
  306. // Spawn an object
  307. //
  308. PhysicalGameObj *game_obj = m_SpawnerObj->Create_Spawned_Object ();
  309. if (game_obj != NULL) {
  310. //
  311. // Dig the render object out of the game object
  312. //
  313. PhysClass *phys_obj = game_obj->Peek_Physical_Object ();
  314. RenderObjClass *render_obj = phys_obj->Peek_Model ();
  315. //
  316. // Make a copy of the render object to return to the caller
  317. //
  318. model = render_obj->Clone ();
  319. //
  320. // We don't need the game object, we just need the visual representation
  321. // of the gameobject
  322. //
  323. game_obj->Set_Delete_Pending ();
  324. }
  325. }
  326. return model;
  327. }
  328. ////////////////////////////////////////////////////////////////
  329. //
  330. // Load_Assets
  331. //
  332. ////////////////////////////////////////////////////////////////
  333. void
  334. SpawnerNodeClass::Load_Assets (void)
  335. {
  336. if (m_Preset != NULL) {
  337. SpawnerDefClass *definition = static_cast<SpawnerDefClass *> (m_Preset->Get_Definition ());
  338. if (definition != NULL) {
  339. //
  340. // Loop over all the possible spawned objects and make sure to load their assets
  341. //
  342. const DynamicVectorClass<int> &list = definition->Get_Spawn_Definition_ID_List ();
  343. for (int index = 0; index < list.Count (); index ++) {
  344. PresetClass *preset = PresetMgrClass::Find_Preset (list[index]);
  345. if (preset != NULL) {
  346. preset->Load_All_Assets ();
  347. }
  348. }
  349. }
  350. }
  351. return ;
  352. }
  353. ////////////////////////////////////////////////////////////////
  354. //
  355. // Get_Spawned_Definition_ID
  356. //
  357. ////////////////////////////////////////////////////////////////
  358. uint32
  359. SpawnerNodeClass::Get_Spawned_Definition_ID (void)
  360. {
  361. uint32 id = 0;
  362. if (m_Preset != NULL) {
  363. SpawnerDefClass *definition = static_cast<SpawnerDefClass *> (m_Preset->Get_Definition ());
  364. if (definition != NULL) {
  365. const DynamicVectorClass<int> &list = definition->Get_Spawn_Definition_ID_List ();
  366. if (list.Count () > 0) {
  367. id = list[0];
  368. }
  369. }
  370. }
  371. return id;
  372. }
  373. /////////////////////////////////////////////////////////////////
  374. //
  375. // operator=
  376. //
  377. /////////////////////////////////////////////////////////////////
  378. const SpawnerNodeClass &
  379. SpawnerNodeClass::operator= (const SpawnerNodeClass &src)
  380. {
  381. NodeClass::operator= (src);
  382. //
  383. // Make sure we have the spawner object created
  384. //
  385. Load_Assets ();
  386. m_Preset->Load_All_Assets ();
  387. Create_Spawner_Obj ();
  388. //
  389. // Copy the spawn point list
  390. //
  391. Free_Spawn_Points ();
  392. for (int index = 0; index < src.m_SpawnPointNodes.Count (); index ++) {
  393. SpawnPointNodeClass *spawn_point = src.m_SpawnPointNodes[index];
  394. if (spawn_point != NULL) {
  395. Add_Spawn_Point (spawn_point->Get_Transform ());
  396. }
  397. }
  398. //
  399. // Copy the script list from the source object
  400. //
  401. Copy_Scripts (src);
  402. return *this;
  403. }
  404. //////////////////////////////////////////////////////////////////////
  405. //
  406. // Pre_Export
  407. //
  408. //////////////////////////////////////////////////////////////////////
  409. void
  410. SpawnerNodeClass::Pre_Export (void)
  411. {
  412. //
  413. // Remove ourselves from the 'system' so we don't get accidentally
  414. // saved during the export.
  415. //
  416. Add_Ref ();
  417. if (m_PhysObj != NULL && m_IsInScene) {
  418. SceneEditorClass *scene = ::Get_Scene_Editor ();
  419. scene->Remove_Object (m_PhysObj);
  420. //
  421. // Get the fresh spawner list
  422. //
  423. SpawnPointListType *list = m_SpawnerObj->Get_Spawn_Point_List ();
  424. list->Delete_All ();
  425. //
  426. // Process each spawn point
  427. //
  428. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  429. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  430. EditorLineClass *line = m_SpawnPointLines[index];
  431. //
  432. // Remove the editor only objects from the world
  433. //
  434. scene->Remove_Object (line);
  435. //
  436. // Add this spawn point to the spawner
  437. //
  438. list->Add (spawn_point->Get_Transform ());
  439. }
  440. }
  441. return ;
  442. }
  443. //////////////////////////////////////////////////////////////////////
  444. //
  445. // Post_Export
  446. //
  447. //////////////////////////////////////////////////////////////////////
  448. void
  449. SpawnerNodeClass::Post_Export (void)
  450. {
  451. //
  452. // Put ourselves back into the system
  453. //
  454. if (m_PhysObj != NULL && m_IsInScene) {
  455. SceneEditorClass *scene = ::Get_Scene_Editor ();
  456. scene->Add_Dynamic_Object (m_PhysObj);
  457. //
  458. // Process each spawn point
  459. //
  460. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  461. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  462. EditorLineClass *line = m_SpawnPointLines[index];
  463. //
  464. // Remove the editor only objects from the world
  465. //
  466. scene->Add_Dynamic_Object (line);
  467. }
  468. }
  469. Release_Ref ();
  470. return ;
  471. }
  472. //////////////////////////////////////////////////////////////////////////////
  473. //
  474. // Add_To_Scene
  475. //
  476. //////////////////////////////////////////////////////////////////////////////
  477. void
  478. SpawnerNodeClass::Add_To_Scene (void)
  479. {
  480. SceneEditorClass *scene = ::Get_Scene_Editor ();
  481. Create_Spawner_Obj ();
  482. //
  483. // Add all the spawn points to the scene
  484. //
  485. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  486. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  487. EditorLineClass *line = m_SpawnPointLines[index];
  488. spawn_point->Add_To_Scene ();
  489. scene->Add_Dynamic_Object (line);
  490. }
  491. NodeClass::Add_To_Scene ();
  492. return ;
  493. }
  494. //////////////////////////////////////////////////////////////////////////////
  495. //
  496. // Remove_From_Scene
  497. //
  498. //////////////////////////////////////////////////////////////////////////////
  499. void
  500. SpawnerNodeClass::Remove_From_Scene (void)
  501. {
  502. SAFE_DELETE (m_SpawnerObj);
  503. SceneEditorClass *scene = ::Get_Scene_Editor ();
  504. if (scene != NULL && m_IsInScene) {
  505. //
  506. // Remove all the spawn points from the scene
  507. //
  508. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  509. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  510. EditorLineClass *line = m_SpawnPointLines[index];
  511. spawn_point->Remove_From_Scene ();
  512. scene->Remove_Object (line);
  513. }
  514. }
  515. NodeClass::Remove_From_Scene ();
  516. return ;
  517. }
  518. //////////////////////////////////////////////////////////////////////
  519. //
  520. // Create_Spawner_Obj
  521. //
  522. //////////////////////////////////////////////////////////////////////
  523. void
  524. SpawnerNodeClass::Create_Spawner_Obj (void)
  525. {
  526. if (m_SpawnerObj == NULL) {
  527. // Recreate the spawner object
  528. SpawnerDefClass *definition = static_cast<SpawnerDefClass *> (m_Preset->Get_Definition ());
  529. if (definition != NULL) {
  530. m_SpawnerObj = (SpawnerClass *)::Instance_Definition (definition);
  531. if (m_SpawnerObj != NULL) {
  532. m_SpawnerObj->Set_TM (m_Transform);
  533. m_SpawnerObj->Set_ID (m_ID);
  534. }
  535. }
  536. Assign_Scripts ();
  537. }
  538. return ;
  539. }
  540. /////////////////////////////////////////////////////////////////
  541. //
  542. // Set_ID
  543. //
  544. /////////////////////////////////////////////////////////////////
  545. void
  546. SpawnerNodeClass::Set_ID (uint32 id)
  547. {
  548. NodeClass::Set_ID (id);
  549. if (m_SpawnerObj != NULL) {
  550. m_SpawnerObj->Set_ID (m_ID);
  551. }
  552. return ;
  553. }
  554. //////////////////////////////////////////////////////////////////////
  555. //
  556. // Add_Spawn_Point
  557. //
  558. //////////////////////////////////////////////////////////////////////
  559. SpawnPointNodeClass *
  560. SpawnerNodeClass::Add_Spawn_Point (const Matrix3D &tm)
  561. {
  562. //
  563. // Create the new spawn point
  564. //
  565. SpawnPointNodeClass *spawn_point = new SpawnPointNodeClass;
  566. spawn_point->Set_Spawner (this);
  567. spawn_point->Initialize ();
  568. spawn_point->Set_Transform (tm);
  569. NodeMgrClass::Setup_Node_Identity (*spawn_point);
  570. //
  571. // Create the line from the spawner to the spawn point
  572. //
  573. EditorLineClass *line = new EditorLineClass;
  574. const AABoxClass &box1 = m_PhysObj->Peek_Model ()->Get_Bounding_Box ();
  575. const AABoxClass &box2 = spawn_point->Peek_Physics_Obj ()->Peek_Model ()->Get_Bounding_Box ();
  576. Vector3 offset1 (0, 0, box1.Extent.Z);
  577. Vector3 offset2 (0, 0, box2.Extent.Z);
  578. line->Set_Color (Vector3 (0.5F, 0, 0.75F));
  579. line->Reset (m_Transform.Get_Translation () + offset1, tm.Get_Translation () + offset2);
  580. //
  581. // Add the spawn point and its line to our data structures
  582. //
  583. m_SpawnPointLines.Add (line);
  584. m_SpawnPointNodes.Add (spawn_point);
  585. //
  586. // Add the spawn point to the scene
  587. //
  588. if (m_IsInScene) {
  589. spawn_point->Add_To_Scene ();
  590. ::Get_Scene_Editor ()->Add_Dynamic_Object (line);
  591. }
  592. return spawn_point;
  593. }
  594. //////////////////////////////////////////////////////////////////////
  595. //
  596. // Remove_Spawn_Point
  597. //
  598. //////////////////////////////////////////////////////////////////////
  599. void
  600. SpawnerNodeClass::Remove_Spawn_Point (SpawnPointNodeClass *spawn_point)
  601. {
  602. //
  603. // Try to find the spawn point
  604. //
  605. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  606. if (spawn_point == m_SpawnPointNodes[index]) {
  607. //
  608. // Free the spawn point
  609. //
  610. MEMBER_RELEASE (spawn_point);
  611. m_SpawnPointNodes.Delete (index);
  612. //
  613. // Remove and free the line to the spawn point
  614. //
  615. ::Get_Scene_Editor ()->Remove_Object (m_SpawnPointLines[index]);
  616. m_SpawnPointLines[index]->Release_Ref ();
  617. m_SpawnPointLines.Delete (index);
  618. break;
  619. }
  620. }
  621. return ;
  622. }
  623. //////////////////////////////////////////////////////////////////////
  624. //
  625. // Free_Spawn_Points
  626. //
  627. //////////////////////////////////////////////////////////////////////
  628. void
  629. SpawnerNodeClass::Free_Spawn_Points (void)
  630. {
  631. SceneEditorClass *scene = ::Get_Scene_Editor ();
  632. //
  633. // Release our hold on each spawn point
  634. //
  635. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  636. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  637. EditorLineClass *line = m_SpawnPointLines[index];
  638. scene->Remove_Object (line);
  639. spawn_point->Remove_From_Scene ();
  640. MEMBER_RELEASE (spawn_point);
  641. MEMBER_RELEASE (line);
  642. }
  643. //
  644. // Remove all the spawn points from the list
  645. //
  646. m_SpawnPointNodes.Delete_All ();
  647. m_SpawnPointLines.Delete_All ();
  648. return ;
  649. }
  650. //////////////////////////////////////////////////////////////////////////////
  651. //
  652. // Update_Lines
  653. //
  654. //////////////////////////////////////////////////////////////////////////////
  655. void
  656. SpawnerNodeClass::Update_Lines (void)
  657. {
  658. for (int index = 0; index < m_SpawnPointNodes.Count (); index ++) {
  659. SpawnPointNodeClass *spawn_point = m_SpawnPointNodes[index];
  660. EditorLineClass *line = m_SpawnPointLines[index];
  661. //
  662. // Update the line so it goes between the centers of the objects
  663. //
  664. const AABoxClass &box1 = m_PhysObj->Peek_Model ()->Get_Bounding_Box ();
  665. const AABoxClass &box2 = spawn_point->Peek_Physics_Obj ()->Peek_Model ()->Get_Bounding_Box ();
  666. Vector3 offset1 (0, 0, box1.Extent.Z);
  667. Vector3 offset2 (0, 0, box2.Extent.Z);
  668. line->Reset (m_Transform.Get_Translation () + offset1, spawn_point->Get_Position () + offset2);
  669. }
  670. return ;
  671. }
  672. //////////////////////////////////////////////////////////////////////////////
  673. //
  674. // Add_Child_Node
  675. //
  676. //////////////////////////////////////////////////////////////////////////////
  677. NodeClass *
  678. SpawnerNodeClass::Add_Child_Node (const Matrix3D &tm)
  679. {
  680. return Add_Spawn_Point (tm);
  681. }
  682. ////////////////////////////////////////////////////////////////
  683. //
  684. // Show_Settings_Dialog
  685. //
  686. ////////////////////////////////////////////////////////////////
  687. bool
  688. SpawnerNodeClass::Show_Settings_Dialog (void)
  689. {
  690. NodeInfoPageClass info_tab (this);
  691. PositionPageClass pos_tab (this);
  692. NodeScriptsPropPage scripts_tab (&m_Scripts);
  693. EditorPropSheetClass prop_sheet;
  694. prop_sheet.Add_Page (&info_tab);
  695. prop_sheet.Add_Page (&pos_tab);
  696. prop_sheet.Add_Page (&scripts_tab);
  697. // Show the property sheet
  698. UINT ret_code = prop_sheet.DoModal ();
  699. if (ret_code == IDOK) {
  700. //
  701. // If the scripts changed, then we need to
  702. // reload the object and assign it the new
  703. // set of scripts.
  704. //
  705. Reload ();
  706. }
  707. // Return true if the user clicked OK
  708. return (ret_code == IDOK);
  709. }
  710. /////////////////////////////////////////////////////////////////
  711. //
  712. // Copy_Scripts
  713. //
  714. /////////////////////////////////////////////////////////////////
  715. void
  716. SpawnerNodeClass::Copy_Scripts (const SpawnerNodeClass &src)
  717. {
  718. Free_Scripts ();
  719. //
  720. // Loop over all the scripts in the src object and copy them.
  721. //
  722. for (int index = 0; index < src.m_Scripts.Count (); index ++) {
  723. EditScriptClass *script = src.m_Scripts[index];
  724. if (script != NULL) {
  725. //
  726. // Make ourselves a copy of the script
  727. //
  728. EditScriptClass *our_copy = new EditScriptClass (*script);
  729. m_Scripts.Add (our_copy);
  730. }
  731. }
  732. return ;
  733. }
  734. /////////////////////////////////////////////////////////////////
  735. //
  736. // Free_Scripts
  737. //
  738. /////////////////////////////////////////////////////////////////
  739. void
  740. SpawnerNodeClass::Free_Scripts (void)
  741. {
  742. for (int index = 0; index < m_Scripts.Count (); index ++) {
  743. EditScriptClass *script = m_Scripts[index];
  744. SAFE_DELETE (script);
  745. }
  746. m_Scripts.Delete_All ();
  747. return ;
  748. }
  749. /////////////////////////////////////////////////////////////////
  750. //
  751. // Assign_Scripts
  752. //
  753. /////////////////////////////////////////////////////////////////
  754. void
  755. SpawnerNodeClass::Assign_Scripts (void)
  756. {
  757. if (m_SpawnerObj != NULL) {
  758. for (int index = 0; index < m_Scripts.Count (); index ++) {
  759. EditScriptClass *script = m_Scripts[index];
  760. m_SpawnerObj->Add_Script (script->Get_Name (), script->Get_Composite_String ());
  761. }
  762. }
  763. return ;
  764. }
  765. //////////////////////////////////////////////////////////////////////////////
  766. //
  767. // Get_Sub_Node
  768. //
  769. //////////////////////////////////////////////////////////////////////////////
  770. NodeClass *
  771. SpawnerNodeClass::Get_Sub_Node (int index)
  772. {
  773. return m_SpawnPointNodes[index];
  774. }