BuildingNode.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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/BuildingNode.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/11/01 9:04a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __BUILDING_NODE_H
  39. #define __BUILDING_NODE_H
  40. #include "objectnode.h"
  41. #include "vector.h"
  42. #include "icons.h"
  43. #include "decophys.h"
  44. #include "building.h"
  45. #include "editorline.h"
  46. ////////////////////////////////////////////////////////////////////////////
  47. // Forward declarations
  48. ////////////////////////////////////////////////////////////////////////////
  49. class PresetClass;
  50. class BuildingChildNodeClass;
  51. ////////////////////////////////////////////////////////////////////////////
  52. //
  53. // BuildingNodeClass
  54. //
  55. ////////////////////////////////////////////////////////////////////////////
  56. class BuildingNodeClass : public ObjectNodeClass
  57. {
  58. public:
  59. //////////////////////////////////////////////////////////////////
  60. // Public constructors/destructors
  61. //////////////////////////////////////////////////////////////////
  62. BuildingNodeClass (PresetClass *preset = NULL);
  63. BuildingNodeClass (const BuildingNodeClass &src);
  64. ~BuildingNodeClass (void);
  65. //////////////////////////////////////////////////////////////
  66. // Public operators
  67. //////////////////////////////////////////////////////////////
  68. const BuildingNodeClass &operator= (const BuildingNodeClass &src);
  69. //////////////////////////////////////////////////////////////////
  70. // Public methods
  71. //////////////////////////////////////////////////////////////////
  72. // From PersistClass
  73. virtual const PersistFactoryClass & Get_Factory (void) const;
  74. // From NodeClass
  75. void Initialize (void);
  76. NodeClass * Clone (void) { return new BuildingNodeClass (*this); }
  77. NODE_TYPE Get_Type (void) const { return NODE_TYPE_BUILDING; }
  78. int Get_Icon_Index (void) const { return BUILDING_ICON; }
  79. PhysClass * Peek_Physics_Obj (void) const { return m_PhysObj; }
  80. bool Is_Static (void) const { return false; }
  81. bool Can_Be_Rotated_Freely (void) const { return true; }
  82. void On_Rotate (void);
  83. void On_Translate (void);
  84. void On_Transform (void);
  85. void Add_To_Scene (void);
  86. void Remove_From_Scene (void);
  87. void Hide (bool hide);
  88. NodeClass * Add_Child_Node (const Matrix3D &tm);
  89. bool Can_Add_Child_Nodes (void) const;
  90. int Get_Sub_Node_Count (void) const { return m_ChildNodes.Count (); }
  91. NodeClass * Get_Sub_Node (int index);
  92. //
  93. // Export methods
  94. //
  95. void Pre_Export (void);
  96. void Post_Export (void);
  97. //
  98. // From PersistClass
  99. //
  100. bool Save (ChunkSaveClass &csave);
  101. bool Load (ChunkLoadClass &cload);
  102. //
  103. // Building specific
  104. //
  105. void Enable_Power (bool onoff);
  106. bool Is_Power_Enabled (void) const;
  107. void Set_Normalized_Health (float health);
  108. void Remove_Child_Node (NodeClass *child_node);
  109. void Update_Lines (void);
  110. protected:
  111. //////////////////////////////////////////////////////////////////
  112. // Protected methods
  113. //////////////////////////////////////////////////////////////////
  114. bool Load_Variables (ChunkLoadClass &cload);
  115. void Free_Child_Nodes (void);
  116. BuildingGameObj * Get_Building (void) const { return reinterpret_cast<BuildingGameObj *> (m_GameObj); }
  117. //////////////////////////////////////////////////////////////////
  118. // Protected member data
  119. //////////////////////////////////////////////////////////////////
  120. DecorationPhysClass * m_PhysObj;
  121. DynamicVectorClass<BuildingChildNodeClass *> m_ChildNodes;
  122. DynamicVectorClass<EditorLineClass *> m_ChildLines;
  123. };
  124. //////////////////////////////////////////////////////////////////
  125. // On_Rotate
  126. //////////////////////////////////////////////////////////////////
  127. inline void
  128. BuildingNodeClass::On_Rotate (void)
  129. {
  130. if (m_GameObj != NULL) {
  131. ((BuildingGameObj *)m_GameObj)->Set_Position (m_Transform.Get_Translation ());
  132. }
  133. Update_Lines ();
  134. NodeClass::On_Rotate ();
  135. return ;
  136. }
  137. //////////////////////////////////////////////////////////////////
  138. // On_Translate
  139. //////////////////////////////////////////////////////////////////
  140. inline void
  141. BuildingNodeClass::On_Translate (void)
  142. {
  143. if (m_GameObj != NULL) {
  144. ((BuildingGameObj *)m_GameObj)->Set_Position (m_Transform.Get_Translation ());
  145. }
  146. Update_Lines ();
  147. NodeClass::On_Translate ();
  148. return ;
  149. }
  150. //////////////////////////////////////////////////////////////////
  151. // On_Transform
  152. //////////////////////////////////////////////////////////////////
  153. inline void
  154. BuildingNodeClass::On_Transform (void)
  155. {
  156. if (m_GameObj != NULL) {
  157. ((BuildingGameObj *)m_GameObj)->Set_Position (m_Transform.Get_Translation ());
  158. }
  159. Update_Lines ();
  160. NodeClass::On_Transform ();
  161. return ;
  162. }
  163. //////////////////////////////////////////////////////////////////
  164. // Enable_Power
  165. //////////////////////////////////////////////////////////////////
  166. inline void
  167. BuildingNodeClass::Enable_Power (bool onoff)
  168. {
  169. if (m_GameObj != NULL) {
  170. ((BuildingGameObj *)m_GameObj)->Enable_Power (onoff);
  171. }
  172. return ;
  173. }
  174. //////////////////////////////////////////////////////////////////
  175. // Is_Power_Enabled
  176. //////////////////////////////////////////////////////////////////
  177. inline bool
  178. BuildingNodeClass::Is_Power_Enabled (void) const
  179. {
  180. bool retval = false;
  181. if (m_GameObj != NULL) {
  182. retval = ((BuildingGameObj *)m_GameObj)->Is_Power_Enabled ();
  183. }
  184. return retval;
  185. }
  186. //////////////////////////////////////////////////////////////////
  187. // Set_Normalized_Health
  188. //////////////////////////////////////////////////////////////////
  189. inline void
  190. BuildingNodeClass::Set_Normalized_Health (float health)
  191. {
  192. if (m_GameObj != NULL) {
  193. ((BuildingGameObj *)m_GameObj)->Set_Normalized_Health (health);
  194. }
  195. return ;
  196. }
  197. #endif //__BUILDING_NODE_H