PathfindStartNode.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/PathfindStartNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/10/00 11:07a $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "pathfindstartnode.h"
  37. #include "sceneeditor.h"
  38. #include "collisiongroups.h"
  39. #include "persistfactory.h"
  40. #include "editorchunkids.h"
  41. #include "preset.h"
  42. #include "chunkio.h"
  43. #include "nodemgr.h"
  44. #include "modelutils.h"
  45. //////////////////////////////////////////////////////////////////////////////
  46. // Persist factory
  47. //////////////////////////////////////////////////////////////////////////////
  48. SimplePersistFactoryClass<PathfindStartNodeClass, CHUNKID_NODE_PATHFIND_START> _PathfindStartNodePersistFactory;
  49. enum
  50. {
  51. CHUNKID_VARIABLES = 0x11011130,
  52. CHUNKID_BASE_CLASS
  53. };
  54. enum
  55. {
  56. //VARID_TILE_LOCATION = 0x01,
  57. };
  58. //////////////////////////////////////////////////////////////////////////////
  59. //
  60. // PathfindStartNodeClass
  61. //
  62. //////////////////////////////////////////////////////////////////////////////
  63. PathfindStartNodeClass::PathfindStartNodeClass (PresetClass *preset)
  64. : m_PhysObj (NULL),
  65. NodeClass (preset)
  66. {
  67. return ;
  68. }
  69. //////////////////////////////////////////////////////////////////////////////
  70. //
  71. // PathfindStartNodeClass
  72. //
  73. //////////////////////////////////////////////////////////////////////////////
  74. PathfindStartNodeClass::PathfindStartNodeClass (const PathfindStartNodeClass &src)
  75. : m_PhysObj (NULL),
  76. NodeClass (NULL)
  77. {
  78. *this = src;
  79. return ;
  80. }
  81. //////////////////////////////////////////////////////////////////////////////
  82. //
  83. // ~PathfindStartNodeClass
  84. //
  85. //////////////////////////////////////////////////////////////////////////////
  86. PathfindStartNodeClass::~PathfindStartNodeClass (void)
  87. {
  88. Remove_From_Scene ();
  89. MEMBER_RELEASE (m_PhysObj);
  90. return ;
  91. }
  92. //////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Initialize
  95. //
  96. // Note: This may be called more than once. It is used as an 'initialize'
  97. // and a 're-initialize'.
  98. //
  99. //////////////////////////////////////////////////////////////////////////////
  100. void
  101. PathfindStartNodeClass::Initialize (void)
  102. {
  103. MEMBER_RELEASE (m_PhysObj);
  104. //
  105. // Create the camera render object
  106. //
  107. RenderObjClass *render_obj = ::Create_Render_Obj ("WAYMID");
  108. WWASSERT (render_obj != NULL);
  109. if (render_obj != NULL) {
  110. // Create the new physics object
  111. m_PhysObj = new DecorationPhysClass;
  112. //
  113. // Configure the physics object with information about
  114. // its new render object and collision data.
  115. //
  116. m_PhysObj->Set_Model (render_obj);
  117. m_PhysObj->Set_Transform (Matrix3D(1));
  118. m_PhysObj->Set_Collision_Group (EDITOR_COLLISION_GROUP);
  119. m_PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  120. m_PhysObj->Set_Transform (m_Transform);
  121. ::Set_Model_Collision_Type (m_PhysObj->Peek_Model (), COLLISION_TYPE_6);
  122. // Release our hold on the render object pointer
  123. MEMBER_RELEASE (render_obj);
  124. }
  125. return ;
  126. }
  127. ////////////////////////////////////////////////////////////////
  128. //
  129. // Get_Factory
  130. //
  131. ////////////////////////////////////////////////////////////////
  132. const PersistFactoryClass &
  133. PathfindStartNodeClass::Get_Factory (void) const
  134. {
  135. return _PathfindStartNodePersistFactory;
  136. }
  137. /////////////////////////////////////////////////////////////////
  138. //
  139. // Save
  140. //
  141. /////////////////////////////////////////////////////////////////
  142. bool
  143. PathfindStartNodeClass::Save (ChunkSaveClass &csave)
  144. {
  145. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  146. NodeClass::Save (csave);
  147. csave.End_Chunk ();
  148. csave.Begin_Chunk (CHUNKID_VARIABLES);
  149. csave.End_Chunk ();
  150. return true;
  151. }
  152. /////////////////////////////////////////////////////////////////
  153. //
  154. // Load
  155. //
  156. /////////////////////////////////////////////////////////////////
  157. bool
  158. PathfindStartNodeClass::Load (ChunkLoadClass &cload)
  159. {
  160. while (cload.Open_Chunk ()) {
  161. switch (cload.Cur_Chunk_ID ()) {
  162. case CHUNKID_BASE_CLASS:
  163. NodeClass::Load (cload);
  164. break;
  165. case CHUNKID_VARIABLES:
  166. Load_Variables (cload);
  167. break;
  168. }
  169. cload.Close_Chunk ();
  170. }
  171. return true;
  172. }
  173. ///////////////////////////////////////////////////////////////////////
  174. //
  175. // Load_Variables
  176. //
  177. ///////////////////////////////////////////////////////////////////////
  178. bool
  179. PathfindStartNodeClass::Load_Variables (ChunkLoadClass &cload)
  180. {
  181. //
  182. // Loop through all the microchunks that define the variables
  183. //
  184. while (cload.Open_Micro_Chunk ()) {
  185. /*switch (cload.Cur_Micro_Chunk_ID ()) {
  186. }*/
  187. cload.Close_Micro_Chunk ();
  188. }
  189. return true;
  190. }
  191. ///////////////////////////////////////////////////////////////////////
  192. //
  193. // Set_Transform
  194. //
  195. ///////////////////////////////////////////////////////////////////////
  196. void
  197. PathfindStartNodeClass::Set_Transform (const Matrix3D &tm)
  198. {
  199. NodeClass::Set_Transform (tm);
  200. return ;
  201. }
  202. /////////////////////////////////////////////////////////////////
  203. //
  204. // operator=
  205. //
  206. /////////////////////////////////////////////////////////////////
  207. const PathfindStartNodeClass &
  208. PathfindStartNodeClass::operator= (const PathfindStartNodeClass &src)
  209. {
  210. NodeClass::operator= (src);
  211. return *this;
  212. }
  213. //////////////////////////////////////////////////////////////////////
  214. //
  215. // Pre_Export
  216. //
  217. //////////////////////////////////////////////////////////////////////
  218. void
  219. PathfindStartNodeClass::Pre_Export (void)
  220. {
  221. //
  222. // Remove ourselves from the 'system' so we don't get accidentally
  223. // saved during the export.
  224. //
  225. Add_Ref ();
  226. if (m_PhysObj != NULL && m_IsInScene) {
  227. ::Get_Scene_Editor ()->Remove_Object (m_PhysObj);
  228. }
  229. return ;
  230. }
  231. //////////////////////////////////////////////////////////////////////
  232. //
  233. // Post_Export
  234. //
  235. //////////////////////////////////////////////////////////////////////
  236. void
  237. PathfindStartNodeClass::Post_Export (void)
  238. {
  239. //
  240. // Put ourselves back into the system
  241. //
  242. if (m_PhysObj != NULL && m_IsInScene) {
  243. ::Get_Scene_Editor ()->Add_Dynamic_Object (m_PhysObj);
  244. }
  245. Release_Ref ();
  246. return ;
  247. }