simplegameobj.cpp 8.1 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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/simplegameobj.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 10/10/01 1:43p $*
  29. * *
  30. * $Revision:: 29 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "simplegameobj.h"
  36. #include "combat.h"
  37. #include "animcontrol.h"
  38. #include "pscene.h"
  39. #include "persistfactory.h"
  40. #include "combatchunkid.h"
  41. #include "debug.h"
  42. #include "simpledefinitionfactory.h"
  43. #include "wwhack.h"
  44. #include "phys.h"
  45. #include "apppackettypes.h"
  46. /*
  47. ** SimpleGameObjDef
  48. */
  49. DECLARE_FORCE_LINK( Simple )
  50. SimplePersistFactoryClass<SimpleGameObjDef, CHUNKID_GAME_OBJECT_DEF_SIMPLE> _SimpleGameObjDefPersistFactory;
  51. DECLARE_DEFINITION_FACTORY(SimpleGameObjDef, CLASSID_GAME_OBJECT_DEF_SIMPLE, "Simple") _SimpleGameObjDefDefFactory;
  52. SimpleGameObjDef::SimpleGameObjDef( void ) :
  53. IsEditorObject( false ),
  54. IsHiddenObject( false ),
  55. PlayerTerminalType( PlayerTerminalClass::TYPE_NONE )
  56. {
  57. MODEL_DEF_PARAM( SimpleGameObjDef, PhysDefID, "PhysDef" );
  58. EDITABLE_PARAM( SimpleGameObjDef, ParameterClass::TYPE_BOOL, IsEditorObject );
  59. EDITABLE_PARAM( SimpleGameObjDef, ParameterClass::TYPE_BOOL, IsHiddenObject );
  60. #ifdef PARAM_EDITING_ON
  61. //
  62. // Configure the orator types parameter
  63. //
  64. EnumParameterClass *pt_type_param = new EnumParameterClass( (int *)&PlayerTerminalType );
  65. pt_type_param->Set_Name( "Player Terminal Type" );
  66. pt_type_param->Add_Value( "<None>", PlayerTerminalClass::TYPE_NONE );
  67. pt_type_param->Add_Value( "GDI", PlayerTerminalClass::TYPE_GDI );
  68. pt_type_param->Add_Value( "NOD", PlayerTerminalClass::TYPE_NOD );
  69. pt_type_param->Add_Value( "Mutant", PlayerTerminalClass::TYPE_MUTANT );
  70. GENERIC_EDITABLE_PARAM( SimpleGameObjDef, pt_type_param );
  71. #endif
  72. return ;
  73. }
  74. uint32 SimpleGameObjDef::Get_Class_ID (void) const
  75. {
  76. return CLASSID_GAME_OBJECT_DEF_SIMPLE;
  77. }
  78. PersistClass * SimpleGameObjDef::Create( void ) const
  79. {
  80. SimpleGameObj * obj = new SimpleGameObj;
  81. obj->Init( *this );
  82. return obj;
  83. }
  84. enum {
  85. CHUNKID_DEF_PARENT = 930991656,
  86. CHUNKID_DEF_VARIABLES,
  87. MICROCHUNKID_DEF_IS_EDITOR_OBJECT = 1,
  88. MICROCHUNKID_DEF_IS_HIDDEN_OBJECT,
  89. MICROCHUNKID_DEF_PLAYER_TERM_TYPE
  90. };
  91. bool SimpleGameObjDef::Save( ChunkSaveClass & csave )
  92. {
  93. csave.Begin_Chunk( CHUNKID_DEF_PARENT );
  94. PhysicalGameObjDef::Save( csave );
  95. csave.End_Chunk();
  96. csave.Begin_Chunk( CHUNKID_DEF_VARIABLES );
  97. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_IS_EDITOR_OBJECT, IsEditorObject );
  98. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_IS_HIDDEN_OBJECT, IsHiddenObject );
  99. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_PLAYER_TERM_TYPE, PlayerTerminalType );
  100. csave.End_Chunk();
  101. return true;
  102. }
  103. bool SimpleGameObjDef::Load( ChunkLoadClass &cload )
  104. {
  105. while (cload.Open_Chunk()) {
  106. switch(cload.Cur_Chunk_ID()) {
  107. case CHUNKID_DEF_PARENT:
  108. PhysicalGameObjDef::Load( cload );
  109. break;
  110. case CHUNKID_DEF_VARIABLES:
  111. while (cload.Open_Micro_Chunk()) {
  112. switch(cload.Cur_Micro_Chunk_ID()) {
  113. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_IS_EDITOR_OBJECT, IsEditorObject );
  114. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_IS_HIDDEN_OBJECT, IsHiddenObject );
  115. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_PLAYER_TERM_TYPE, PlayerTerminalType );
  116. default:
  117. Debug_Say(( "Unrecognized SimpleDef Variable chunkID\n" ));
  118. break;
  119. }
  120. cload.Close_Micro_Chunk();
  121. }
  122. break;
  123. default:
  124. Debug_Say(( "Unrecognized SimpleDef chunkID\n" ));
  125. break;
  126. }
  127. cload.Close_Chunk();
  128. }
  129. return true;
  130. }
  131. const PersistFactoryClass & SimpleGameObjDef::Get_Factory (void) const
  132. {
  133. return _SimpleGameObjDefPersistFactory;
  134. }
  135. /*
  136. ** SimpleGameObj
  137. */
  138. SimplePersistFactoryClass<SimpleGameObj, CHUNKID_GAME_OBJECT_SIMPLE> _SimpleGameObjPersistFactory;
  139. const PersistFactoryClass & SimpleGameObj::Get_Factory (void) const
  140. {
  141. return _SimpleGameObjPersistFactory;
  142. }
  143. /*
  144. **
  145. */
  146. SimpleGameObj::SimpleGameObj()
  147. {
  148. Set_App_Packet_Type(APPPACKETTYPE_SIMPLE);
  149. //WWDEBUG_SAY(("SimpleGameObj::SimpleGameObj\n"));
  150. /*
  151. if (Get_Definition().Get_Name() != NULL) {
  152. WWDEBUG_SAY((" for %s\n", Get_Definition().Get_Name()));
  153. }
  154. /**/
  155. }
  156. SimpleGameObj::~SimpleGameObj()
  157. {
  158. }
  159. /*
  160. **
  161. */
  162. void SimpleGameObj::Init( void )
  163. {
  164. Init( Get_Definition() );
  165. /*
  166. if (Get_Definition().Get_Name() != NULL) {
  167. WWDEBUG_SAY(("SimpleGameObj::Init for %s\n", Get_Definition().Get_Name()));
  168. }
  169. /**/
  170. }
  171. void SimpleGameObj::Init( const SimpleGameObjDef & definition )
  172. {
  173. PhysicalGameObj::Init( definition );
  174. }
  175. const SimpleGameObjDef & SimpleGameObj::Get_Definition( void ) const
  176. {
  177. return (const SimpleGameObjDef &)BaseGameObj::Get_Definition();
  178. }
  179. /*
  180. ** SimpleGameObj Save and Load
  181. */
  182. enum {
  183. CHUNKID_PARENT = 927991712,
  184. CHUNKID_VARIABLES,
  185. XXXCHUNKID_ANIM_CONTROL,
  186. XXXMICROCHUNKID_PHYSOBJ = 1,
  187. };
  188. bool SimpleGameObj::Save( ChunkSaveClass & csave )
  189. {
  190. csave.Begin_Chunk( CHUNKID_PARENT );
  191. PhysicalGameObj::Save( csave );
  192. csave.End_Chunk();
  193. return true;
  194. }
  195. bool SimpleGameObj::Load( ChunkLoadClass &cload )
  196. {
  197. while (cload.Open_Chunk()) {
  198. switch(cload.Cur_Chunk_ID()) {
  199. case CHUNKID_PARENT:
  200. PhysicalGameObj::Load( cload );
  201. break;
  202. default:
  203. Debug_Say(( "Unrecognized SimpleGameObj chunkID\n" ));
  204. break;
  205. }
  206. cload.Close_Chunk();
  207. }
  208. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  209. return true;
  210. }
  211. void SimpleGameObj::On_Post_Load( void )
  212. {
  213. PhysicalGameObj::On_Post_Load();
  214. // NOTE: the On_Post_Load function is only run when loading a level in the game engine
  215. // so we can put game-specific behavior into this function without messing up the level
  216. // editor.
  217. if ( Get_Definition().IsEditorObject ) {
  218. // Switch to a NULL model
  219. Peek_Physical_Object()->Set_Model_By_Name( "NULL" );
  220. // Add clear anim_control
  221. if ( Get_Anim_Control() != NULL ) {
  222. Get_Anim_Control()->Set_Model( Peek_Model() );
  223. }
  224. }
  225. if ( Is_Hidden_Object() ) {
  226. RenderObjClass * model = Peek_Physical_Object()->Peek_Model();
  227. if (model) {
  228. model->Set_Hidden(true);
  229. }
  230. }
  231. /*
  232. if (Get_Definition().Get_Name() != NULL) {
  233. WWDEBUG_SAY(("SimpleGameObj::On_Post_Load for %s\n", Get_Definition().Get_Name()));
  234. }
  235. */
  236. }