accessiblephys.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 : wwphys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/accessiblephys.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/17/01 8:42p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "accessiblephys.h"
  36. #include "wwphysids.h"
  37. #include "persistfactory.h"
  38. #include "simpledefinitionfactory.h"
  39. /////////////////////////////////////////////////////////////////////////
  40. // Persist and definition factories
  41. /////////////////////////////////////////////////////////////////////////
  42. SimplePersistFactoryClass <AccessiblePhysClass, PHYSICS_CHUNKID_ACCESSIBLEPHYS> _AccessiblePhysClassFactory;
  43. SimplePersistFactoryClass <AccessiblePhysDefClass, PHYSICS_CHUNKID_ACCESSIBLEPHYSDEF> _AccessiblePhysDefFactory;
  44. DECLARE_DEFINITION_FACTORY (AccessiblePhysDefClass, CLASSID_ACCESSIBLEPHYSDEF, "AccessiblePhys") _AccessiblePhysDefDefFactory;
  45. /////////////////////////////////////////////////////////////////////////
  46. // Save/load constants
  47. /////////////////////////////////////////////////////////////////////////
  48. enum
  49. {
  50. CHUNKID_PARENT = 0x10311235,
  51. CHUNKID_VARIABLES,
  52. VARID_LOCKCODE = 1,
  53. };
  54. enum
  55. {
  56. CHUNKID_DEF_PARENT = 0x10311249,
  57. CHUNKID_DEF_VARIABLES,
  58. VARID_DEF_LOCKCODE = 1,
  59. };
  60. /////////////////////////////////////////////////////////////////////////
  61. //
  62. // AccessiblePhysClass
  63. //
  64. /////////////////////////////////////////////////////////////////////////
  65. AccessiblePhysClass::AccessiblePhysClass (void) :
  66. LockCode (0)
  67. {
  68. return ;
  69. }
  70. /////////////////////////////////////////////////////////////////////////
  71. //
  72. // ~AccessiblePhysClass
  73. //
  74. /////////////////////////////////////////////////////////////////////////
  75. AccessiblePhysClass::~AccessiblePhysClass (void)
  76. {
  77. return ;
  78. }
  79. /////////////////////////////////////////////////////////////////////////
  80. //
  81. // Init
  82. //
  83. /////////////////////////////////////////////////////////////////////////
  84. void
  85. AccessiblePhysClass::Init (const AccessiblePhysDefClass &definition)
  86. {
  87. LockCode = definition.LockCode;
  88. StaticAnimPhysClass::Init ((const StaticAnimPhysDefClass &)definition);
  89. return ;
  90. }
  91. /////////////////////////////////////////////////////////////////////////
  92. //
  93. // Get_Factory
  94. //
  95. /////////////////////////////////////////////////////////////////////////
  96. const PersistFactoryClass &
  97. AccessiblePhysClass::Get_Factory (void) const
  98. {
  99. return _AccessiblePhysClassFactory;
  100. }
  101. /////////////////////////////////////////////////////////////////////////
  102. //
  103. // Save
  104. //
  105. /////////////////////////////////////////////////////////////////////////
  106. bool
  107. AccessiblePhysClass::Save (ChunkSaveClass &csave)
  108. {
  109. csave.Begin_Chunk (CHUNKID_PARENT);
  110. StaticAnimPhysClass::Save (csave);
  111. csave.End_Chunk ();
  112. csave.Begin_Chunk (CHUNKID_VARIABLES);
  113. Save_Variables (csave);
  114. csave.End_Chunk ();
  115. return true;
  116. }
  117. /////////////////////////////////////////////////////////////////////////
  118. //
  119. // Save_Variables
  120. //
  121. /////////////////////////////////////////////////////////////////////////
  122. bool
  123. AccessiblePhysClass::Save_Variables (ChunkSaveClass &csave)
  124. {
  125. WRITE_MICRO_CHUNK (csave, VARID_LOCKCODE, LockCode);
  126. return true;
  127. }
  128. /////////////////////////////////////////////////////////////////////////
  129. //
  130. // Load
  131. //
  132. /////////////////////////////////////////////////////////////////////////
  133. bool
  134. AccessiblePhysClass::Load (ChunkLoadClass &cload)
  135. {
  136. while (cload.Open_Chunk ()) {
  137. switch(cload.Cur_Chunk_ID ())
  138. {
  139. case CHUNKID_PARENT:
  140. StaticAnimPhysClass::Load (cload);
  141. break;
  142. case CHUNKID_VARIABLES:
  143. Load_Variables (cload);
  144. break;
  145. default:
  146. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  147. break;
  148. }
  149. cload.Close_Chunk();
  150. }
  151. return true;
  152. }
  153. ///////////////////////////////////////////////////////////////////////
  154. //
  155. // Load_Variables
  156. //
  157. ///////////////////////////////////////////////////////////////////////
  158. bool
  159. AccessiblePhysClass::Load_Variables (ChunkLoadClass &cload)
  160. {
  161. //
  162. // Loop through all the microchunks that define the variables
  163. //
  164. while (cload.Open_Micro_Chunk ()) {
  165. switch (cload.Cur_Micro_Chunk_ID ()) {
  166. READ_MICRO_CHUNK (cload, VARID_LOCKCODE, LockCode);
  167. }
  168. cload.Close_Micro_Chunk ();
  169. }
  170. return true;
  171. }
  172. ///////////////////////////////////////////////////////////////////////
  173. //
  174. // AccessiblePhysDefClass
  175. //
  176. ///////////////////////////////////////////////////////////////////////
  177. AccessiblePhysDefClass::AccessiblePhysDefClass (void) :
  178. LockCode (0)
  179. {
  180. EDITABLE_PARAM (AccessiblePhysDefClass, ParameterClass::TYPE_INT, LockCode);
  181. return ;
  182. }
  183. ///////////////////////////////////////////////////////////////////////
  184. //
  185. // Get_Class_ID
  186. //
  187. ///////////////////////////////////////////////////////////////////////
  188. uint32
  189. AccessiblePhysDefClass::Get_Class_ID (void) const
  190. {
  191. return CLASSID_ACCESSIBLEPHYSDEF;
  192. }
  193. ///////////////////////////////////////////////////////////////////////
  194. //
  195. // Create
  196. //
  197. ///////////////////////////////////////////////////////////////////////
  198. PersistClass *
  199. AccessiblePhysDefClass::Create (void) const
  200. {
  201. AccessiblePhysClass * obj = NEW_REF(AccessiblePhysClass,());
  202. obj->Init(*this);
  203. return obj;
  204. }
  205. ///////////////////////////////////////////////////////////////////////
  206. //
  207. // Get_Factory
  208. //
  209. ///////////////////////////////////////////////////////////////////////
  210. const
  211. PersistFactoryClass &
  212. AccessiblePhysDefClass::Get_Factory (void) const
  213. {
  214. return _AccessiblePhysDefFactory;
  215. }
  216. ///////////////////////////////////////////////////////////////////////
  217. //
  218. // Is_Type
  219. //
  220. ///////////////////////////////////////////////////////////////////////
  221. bool
  222. AccessiblePhysDefClass::Is_Type (const char *type_name)
  223. {
  224. bool retval = false;
  225. if (::stricmp (type_name, AccessiblePhysDefClass::Get_Type_Name ()) == 0) {
  226. retval = true;
  227. } else {
  228. retval = StaticAnimPhysDefClass::Is_Type (type_name);
  229. }
  230. return retval;
  231. }
  232. /////////////////////////////////////////////////////////////////////////
  233. //
  234. // Save
  235. //
  236. /////////////////////////////////////////////////////////////////////////
  237. bool
  238. AccessiblePhysDefClass::Save (ChunkSaveClass &csave)
  239. {
  240. csave.Begin_Chunk (CHUNKID_DEF_PARENT);
  241. StaticAnimPhysDefClass::Save (csave);
  242. csave.End_Chunk ();
  243. csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
  244. Save_Variables (csave);
  245. csave.End_Chunk ();
  246. return true;
  247. }
  248. /////////////////////////////////////////////////////////////////////////
  249. //
  250. // Save_Variables
  251. //
  252. /////////////////////////////////////////////////////////////////////////
  253. bool
  254. AccessiblePhysDefClass::Save_Variables (ChunkSaveClass &csave)
  255. {
  256. WRITE_MICRO_CHUNK (csave, VARID_DEF_LOCKCODE, LockCode);
  257. return true;
  258. }
  259. /////////////////////////////////////////////////////////////////////////
  260. //
  261. // Load
  262. //
  263. /////////////////////////////////////////////////////////////////////////
  264. bool
  265. AccessiblePhysDefClass::Load (ChunkLoadClass &cload)
  266. {
  267. while (cload.Open_Chunk ()) {
  268. switch(cload.Cur_Chunk_ID ())
  269. {
  270. case CHUNKID_DEF_PARENT:
  271. StaticAnimPhysDefClass::Load (cload);
  272. break;
  273. case CHUNKID_DEF_VARIABLES:
  274. Load_Variables (cload);
  275. break;
  276. default:
  277. WWDEBUG_SAY (("Unhandled Chunk: 0x%X File: %s Line: %d\r\n", cload.Cur_Chunk_ID (), __FILE__, __LINE__));
  278. break;
  279. }
  280. cload.Close_Chunk();
  281. }
  282. return true;
  283. }
  284. ///////////////////////////////////////////////////////////////////////
  285. //
  286. // Load_Variables
  287. //
  288. ///////////////////////////////////////////////////////////////////////
  289. bool
  290. AccessiblePhysDefClass::Load_Variables (ChunkLoadClass &cload)
  291. {
  292. //
  293. // Loop through all the microchunks that define the variables
  294. //
  295. while (cload.Open_Micro_Chunk ()) {
  296. switch (cload.Cur_Micro_Chunk_ID ()) {
  297. READ_MICRO_CHUNK (cload, VARID_DEF_LOCKCODE, LockCode);
  298. }
  299. cload.Close_Micro_Chunk ();
  300. }
  301. return true;
  302. }