buildingaggregate.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/buildingaggregate.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Bhayes $*
  29. * *
  30. * $Modtime:: 1/07/03 1:38p $*
  31. * *
  32. * $Revision:: 14 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * BuildingAggregateClass::BuildingAggregateClass -- Constructor *
  37. * BuildingAggregateClass::BuildingAggregateClass -- Constructor *
  38. * BuildingAggregateClass::~BuildingAggregateClass -- Destructor *
  39. * BuildingAggregateClass::Init -- Initialze from a definition *
  40. * BuildingAggregateClass::Get_Current_State -- returns the current state *
  41. * BuildingAggregateClass::Set_Current_State -- Sets the current state *
  42. * BuildingAggregateClass::Is_MCT -- is this aggregate an MCT? *
  43. * BuildingAggregateClass::Save -- Get the persist factory for this clas *
  44. * BuildingAggregateClass::Save -- Save the state of this object *
  45. * BuildingAggregateClass::Load -- Load the state of this object *
  46. * BuildingAggregateClass::On_Post_Load -- post-load processing *
  47. * BuildingAggregateDefClass::BuildingAggregateDefClass -- Constructor *
  48. * BuildingAggregateDefClass::Get_Class_ID -- returns the definition class ID *
  49. * BuildingAggregateDefClass::Create -- creates an instance of a BuildingAggregateClass *
  50. * BuildingAggregateDefClass::Get_Factory -- returns the persist factory *
  51. * BuildingAggregateDefClass::Save -- Saves the contents of this object *
  52. * BuildingAggregateDefClass::Save_State_Animation_Data -- Save the data for one of the buil *
  53. * BuildingAggregateDefClass::Load -- Load the contents of this object *
  54. * BuildingAggregateDefClass::Load_State_Animation_Data -- Load anim data for a building sta *
  55. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  56. #include "buildingaggregate.h"
  57. #include "simpledefinitionfactory.h"
  58. #include "persistfactory.h"
  59. #include "wwphysids.h"
  60. #include "hanim.h"
  61. #include "combat.h"
  62. #include "wwaudio.h"
  63. #include "wwdebug.h"
  64. #include "wwhack.h"
  65. #include "wwprofile.h"
  66. DECLARE_FORCE_LINK( buildingaggregate );
  67. /*************************************************************************************************************
  68. **
  69. ** BuildingAggregateClass (BAG) Implementation
  70. **
  71. *************************************************************************************************************/
  72. SimplePersistFactoryClass<BuildingAggregateClass, PHYSICS_CHUNKID_BUILDINGAGGREGATE> _BuildingAggregatePersistFactory;
  73. enum
  74. {
  75. BAG_CHUNK_STATICANIMPHYS = 8281529,
  76. BAG_CHUNK_VARIABLES,
  77. BAG_VARIABLE_CURRENTSTATE = 0,
  78. };
  79. /***********************************************************************************************
  80. * BuildingAggregateClass::BuildingAggregateClass -- Constructor *
  81. * *
  82. * INPUT: *
  83. * *
  84. * OUTPUT: *
  85. * *
  86. * WARNINGS: *
  87. * *
  88. * HISTORY: *
  89. *=============================================================================================*/
  90. BuildingAggregateClass::BuildingAggregateClass(void) :
  91. CurrentState(BuildingStateClass::HEALTH100_POWERON)
  92. {
  93. }
  94. /***********************************************************************************************
  95. * BuildingAggregateClass::~BuildingAggregateClass -- Destructor *
  96. * *
  97. * INPUT: *
  98. * *
  99. * OUTPUT: *
  100. * *
  101. * WARNINGS: *
  102. * *
  103. * HISTORY: *
  104. *=============================================================================================*/
  105. BuildingAggregateClass::~BuildingAggregateClass(void)
  106. {
  107. }
  108. /***********************************************************************************************
  109. * BuildingAggregateClass::Init -- Initialze from a definition *
  110. * *
  111. * INPUT: *
  112. * *
  113. * OUTPUT: *
  114. * *
  115. * WARNINGS: *
  116. * *
  117. * HISTORY: *
  118. * 8/29/2000 gth : Created. *
  119. *=============================================================================================*/
  120. void BuildingAggregateClass::Init(const BuildingAggregateDefClass & def)
  121. {
  122. StaticAnimPhysClass::Init(def);
  123. AnimCollisionManagerClass & anim_mgr = Get_Animation_Manager();
  124. anim_mgr.Set_Current_Frame(def.Frame0[CurrentState]);
  125. }
  126. /***********************************************************************************************
  127. * BuildingAggregateClass::Get_Current_State -- returns the current state *
  128. * *
  129. * INPUT: *
  130. * *
  131. * OUTPUT: *
  132. * *
  133. * WARNINGS: *
  134. * *
  135. * HISTORY: *
  136. * 9/8/2000 gth : Created. *
  137. *=============================================================================================*/
  138. int BuildingAggregateClass::Get_Current_State(void)
  139. {
  140. return CurrentState;
  141. }
  142. /***********************************************************************************************
  143. * BuildingAggregateClass::Set_Current_State -- Sets the current state *
  144. * *
  145. * INPUT: *
  146. * *
  147. * OUTPUT: *
  148. * *
  149. * WARNINGS: *
  150. * *
  151. * HISTORY: *
  152. * 9/8/2000 gth : Created. *
  153. *=============================================================================================*/
  154. void BuildingAggregateClass::Set_Current_State(int new_state,bool force_update)
  155. {
  156. if ((new_state != CurrentState) || (force_update == true)) {
  157. AnimCollisionManagerClass & anim_mgr = Get_Animation_Manager();
  158. const BuildingAggregateDefClass * def = Get_BuildingAggregateDef();
  159. WWASSERT(def != NULL);
  160. switch (def->AnimLogicMode)
  161. {
  162. case BuildingAggregateDefClass::ANIM_LOGIC_LOOP:
  163. {
  164. /*
  165. ** Calculate the fractional position in our current loop
  166. */
  167. float normalized_frame = 0.0f;
  168. float cur_loop_len = def->Frame1[CurrentState] - def->Frame0[CurrentState];
  169. if (cur_loop_len > 0.0f) {
  170. normalized_frame = (anim_mgr.Get_Current_Frame() - def->Frame0[CurrentState]) /
  171. (def->Frame1[CurrentState] - def->Frame0[CurrentState]);
  172. }
  173. /*
  174. ** Switch the loop start and end
  175. */
  176. anim_mgr.Set_Loop_Start(def->Frame0[new_state]);
  177. anim_mgr.Set_Loop_End(def->Frame1[new_state]);
  178. /*
  179. ** Jump to the same fractional position in the new loop
  180. */
  181. anim_mgr.Set_Current_Frame(def->Frame0[new_state] + normalized_frame * (def->Frame1[new_state] - def->Frame0[new_state]));
  182. /*
  183. ** If animation is disabled, set the animation mode to manual, otherwise set it to loop
  184. */
  185. if (def->AnimationEnabled[new_state] == true) {
  186. anim_mgr.Set_Animation_Mode(AnimCollisionManagerClass::ANIMATE_LOOP);
  187. } else {
  188. anim_mgr.Set_Animation_Mode(AnimCollisionManagerClass::ANIMATE_MANUAL);
  189. }
  190. break;
  191. }
  192. case BuildingAggregateDefClass::ANIM_LOGIC_LINEAR:
  193. {
  194. /*
  195. ** The new target frame is determined by the new state
  196. */
  197. anim_mgr.Set_Target_Frame(def->Frame0[new_state]);
  198. anim_mgr.Set_Animation_Mode(AnimCollisionManagerClass::ANIMATE_TARGET);
  199. /*
  200. ** If we changed power states or animation is disabled, then we need to warp the current frame
  201. */
  202. if ( (BuildingStateClass::Is_Power_On(new_state) != BuildingStateClass::Is_Power_On(CurrentState)) ||
  203. (def->AnimationEnabled[new_state] == false))
  204. {
  205. anim_mgr.Set_Current_Frame(def->Frame0[new_state]);
  206. }
  207. break;
  208. }
  209. case BuildingAggregateDefClass::ANIM_LOGIC_SEQUENCE:
  210. {
  211. /*
  212. ** The current and target frames are determined by the new state. If the new sequence
  213. ** is the same as the previous sequence, don't do anything.
  214. */
  215. if ((def->Frame0[CurrentState] != def->Frame0[new_state]) || (def->Frame1[CurrentState] != def->Frame1[new_state])) {
  216. anim_mgr.Set_Animation_Mode(AnimCollisionManagerClass::ANIMATE_TARGET);
  217. anim_mgr.Set_Current_Frame(def->Frame0[new_state]);
  218. anim_mgr.Set_Target_Frame(def->Frame1[new_state]);
  219. }
  220. break;
  221. }
  222. }
  223. CurrentState = new_state;
  224. }
  225. }
  226. /***********************************************************************************************
  227. * BuildingAggregateClass::Is_MCT -- is this aggregate an MCT? *
  228. * *
  229. * MCT's are weak points for the building. The building will use an alternate skin type *
  230. * when applying damage that was done to the MCT. *
  231. * *
  232. * INPUT: *
  233. * *
  234. * OUTPUT: *
  235. * *
  236. * WARNINGS: *
  237. * *
  238. * HISTORY: *
  239. * 9/24/2000 gth : Created. *
  240. *=============================================================================================*/
  241. bool BuildingAggregateClass::Is_MCT(void)
  242. {
  243. return Get_BuildingAggregateDef()->IsMCT;
  244. }
  245. /*
  246. ** Save and Load
  247. */
  248. /***********************************************************************************************
  249. * BuildingAggregateClass::Save -- Get the persist factory for this class *
  250. * *
  251. * INPUT: *
  252. * *
  253. * OUTPUT: *
  254. * *
  255. * WARNINGS: *
  256. * *
  257. * HISTORY: *
  258. * 8/29/2000 gth : Created. *
  259. *=============================================================================================*/
  260. const PersistFactoryClass & BuildingAggregateClass::Get_Factory(void) const
  261. {
  262. return _BuildingAggregatePersistFactory;
  263. }
  264. /***********************************************************************************************
  265. * BuildingAggregateClass::Save -- Save the state of this object *
  266. * *
  267. * INPUT: *
  268. * *
  269. * OUTPUT: *
  270. * *
  271. * WARNINGS: *
  272. * *
  273. * HISTORY: *
  274. * 8/29/2000 gth : Created. *
  275. *=============================================================================================*/
  276. bool BuildingAggregateClass::Save(ChunkSaveClass & csave)
  277. {
  278. csave.Begin_Chunk(BAG_CHUNK_STATICANIMPHYS);
  279. StaticAnimPhysClass::Save(csave);
  280. csave.End_Chunk();
  281. csave.Begin_Chunk(BAG_CHUNK_VARIABLES);
  282. WRITE_MICRO_CHUNK(csave, BAG_VARIABLE_CURRENTSTATE, CurrentState );
  283. csave.End_Chunk();
  284. return true;
  285. }
  286. /***********************************************************************************************
  287. * BuildingAggregateClass::Load -- Load the state of this object *
  288. * *
  289. * INPUT: *
  290. * *
  291. * OUTPUT: *
  292. * *
  293. * WARNINGS: *
  294. * *
  295. * HISTORY: *
  296. * 8/29/2000 gth : Created. *
  297. *=============================================================================================*/
  298. bool BuildingAggregateClass::Load( ChunkLoadClass &cload )
  299. {
  300. while (cload.Open_Chunk()) {
  301. switch(cload.Cur_Chunk_ID()) {
  302. case BAG_CHUNK_STATICANIMPHYS:
  303. StaticAnimPhysClass::Load( cload );
  304. break;
  305. case BAG_CHUNK_VARIABLES:
  306. while (cload.Open_Micro_Chunk()) {
  307. switch(cload.Cur_Micro_Chunk_ID()) {
  308. READ_MICRO_CHUNK(cload, BAG_VARIABLE_CURRENTSTATE, CurrentState );
  309. default:
  310. WWDEBUG_SAY(( "Unrecognized BuildingAggregate Variable chunkID\n" ));
  311. break;
  312. }
  313. cload.Close_Micro_Chunk();
  314. }
  315. break;
  316. default:
  317. WWDEBUG_SAY(("Unrecognized BuildingAggregate Chunk: 0x%x in file %s, line %d\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  318. break;
  319. }
  320. cload.Close_Chunk();
  321. }
  322. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  323. return true;
  324. }
  325. /***********************************************************************************************
  326. * BuildingAggregateClass::On_Post_Load -- post-load processing *
  327. * *
  328. * INPUT: *
  329. * *
  330. * OUTPUT: *
  331. * *
  332. * WARNINGS: *
  333. * *
  334. * HISTORY: *
  335. * 9/8/2000 gth : Created. *
  336. *=============================================================================================*/
  337. void BuildingAggregateClass::On_Post_Load(void)
  338. {
  339. StaticAnimPhysClass::On_Post_Load();
  340. Set_Current_State(CurrentState,true);
  341. }
  342. /*
  343. **
  344. */
  345. void BuildingAggregateClass::Save_State( ChunkSaveClass & csave )
  346. {
  347. csave.Begin_Chunk( BAG_CHUNK_STATICANIMPHYS );
  348. StaticAnimPhysClass::Save_State(csave);
  349. csave.End_Chunk();
  350. csave.Begin_Chunk(BAG_CHUNK_VARIABLES);
  351. WRITE_MICRO_CHUNK(csave, BAG_VARIABLE_CURRENTSTATE, CurrentState );
  352. csave.End_Chunk();
  353. }
  354. /*
  355. **
  356. */
  357. void BuildingAggregateClass::Load_State( ChunkLoadClass &cload )
  358. {
  359. while (cload.Open_Chunk()) {
  360. switch(cload.Cur_Chunk_ID()) {
  361. case BAG_CHUNK_STATICANIMPHYS:
  362. StaticAnimPhysClass::Load_State( cload );
  363. break;
  364. case BAG_CHUNK_VARIABLES:
  365. while (cload.Open_Micro_Chunk()) {
  366. switch(cload.Cur_Micro_Chunk_ID()) {
  367. READ_MICRO_CHUNK(cload, BAG_VARIABLE_CURRENTSTATE, CurrentState );
  368. default:
  369. WWDEBUG_SAY(( "Unrecognized BuildingAggregate Variable chunkID\n" ));
  370. break;
  371. }
  372. cload.Close_Micro_Chunk();
  373. }
  374. break;
  375. default:
  376. WWDEBUG_SAY(( "Unrecognized BuildingAggregate chunkID\n" ));
  377. break;
  378. }
  379. cload.Close_Chunk();
  380. }
  381. }
  382. /*************************************************************************************************
  383. **
  384. ** BuildingAggregateDefClass Implementation
  385. **
  386. *************************************************************************************************/
  387. /*
  388. ** Persist Factory for BuildingAggregateDefClass, this makes them save and load.
  389. */
  390. SimplePersistFactoryClass<BuildingAggregateDefClass, PHYSICS_CHUNKID_BUILDINGAGGREGATEDEF> _BuildingAggregateDefPersistFactory;
  391. /*
  392. ** Definition Factory for BuildingAggregateDefClass, this makes them show up in the editor
  393. */
  394. DECLARE_DEFINITION_FACTORY(BuildingAggregateDefClass, CLASSID_BUILDINGAGGREGATEDEF, "BuildingAggregate") _BuildingAggregateDefDefFactory;
  395. /*
  396. ** Chunk ID's used by BuildingAggregateDefClass
  397. */
  398. enum
  399. {
  400. BAGDEF_CHUNK_STATICANIMPHYS = 8281441,
  401. BAGDEF_CHUNK_VARIABLES,
  402. BAGDEF_CHUNK_HEALTH100_POWERON_VARIABLES,
  403. BAGDEF_CHUNK_HEALTH75_POWERON_VARIABLES,
  404. BAGDEF_CHUNK_HEALTH50_POWERON_VARIABLES,
  405. BAGDEF_CHUNK_HEALTH25_POWERON_VARIABLES,
  406. BAGDEF_CHUNK_DESTROYED_POWERON_VARIABLES,
  407. BAGDEF_CHUNK_HEALTH100_POWEROFF_VARIABLES,
  408. BAGDEF_CHUNK_HEALTH75_POWEROFF_VARIABLES,
  409. BAGDEF_CHUNK_HEALTH50_POWEROFF_VARIABLES,
  410. BAGDEF_CHUNK_HEALTH25_POWEROFF_VARIABLES,
  411. BAGDEF_CHUNK_DESTROYED_POWEROFF_VARIABLES,
  412. BAGDEF_VARIABLE_ANIMLOGICMODE = 0,
  413. BAGDEF_VARIABLE_FRAME0,
  414. BAGDEF_VARIABLE_FRAME1,
  415. BAGDEF_VARIABLE_ANIMATIONENABLED,
  416. BAGDEF_VARIABLE_ISMCT,
  417. };
  418. /***********************************************************************************************
  419. * BuildingAggregateDefClass::BuildingAggregateDefClass -- Constructor *
  420. * *
  421. * INPUT: *
  422. * *
  423. * OUTPUT: *
  424. * *
  425. * WARNINGS: *
  426. * *
  427. * HISTORY: *
  428. * 8/29/2000 gth : Created. *
  429. *=============================================================================================*/
  430. BuildingAggregateDefClass::BuildingAggregateDefClass( void ) :
  431. StaticAnimPhysDefClass(),
  432. AnimLogicMode(ANIM_LOGIC_LOOP),
  433. IsMCT(false)
  434. {
  435. int i;
  436. for (i=0; i<BuildingStateClass::STATE_COUNT; i++) {
  437. Frame0[i] = 0;
  438. Frame1[i] = 0;
  439. AnimationEnabled[i] = true;
  440. }
  441. #ifdef PARAM_EDITING_ON
  442. PARAM_SEPARATOR(BuildingAggregateDefClass, "Building Behavior Settings");
  443. EnumParameterClass * anim_logic_param = new EnumParameterClass(&AnimLogicMode);
  444. anim_logic_param->Set_Name ("AnimLogicMode");
  445. anim_logic_param->Add_Value("ANIM_LOGIC_LINEAR",ANIM_LOGIC_LINEAR);
  446. anim_logic_param->Add_Value("ANIM_LOGIC_LOOP",ANIM_LOGIC_LOOP);
  447. anim_logic_param->Add_Value("ANIM_LOGIC_SEQUENCE",ANIM_LOGIC_SEQUENCE);
  448. GENERIC_EDITABLE_PARAM( BuildingAggregateDefClass, anim_logic_param);
  449. EDITABLE_PARAM(BuildingAggregateDefClass, ParameterClass::TYPE_BOOL, IsMCT);
  450. for (i=0; i<BuildingStateClass::STATE_COUNT; i++) {
  451. PARAM_SEPARATOR(BuildingAggregateDefClass, BuildingStateClass::Get_State_Name(i))
  452. NAMED_EDITABLE_PARAM(BuildingAggregateDefClass, ParameterClass::TYPE_INT, Frame0[i], "Frame0");
  453. NAMED_EDITABLE_PARAM(BuildingAggregateDefClass, ParameterClass::TYPE_INT, Frame1[i], "Frame1");
  454. NAMED_EDITABLE_PARAM(BuildingAggregateDefClass, ParameterClass::TYPE_BOOL, AnimationEnabled[i], "AnimationEnabled");
  455. }
  456. #endif
  457. }
  458. /***********************************************************************************************
  459. * BuildingAggregateDefClass::Get_Class_ID -- returns the definition class ID *
  460. * *
  461. * INPUT: *
  462. * *
  463. * OUTPUT: *
  464. * *
  465. * WARNINGS: *
  466. * *
  467. * HISTORY: *
  468. * 8/29/2000 gth : Created. *
  469. *=============================================================================================*/
  470. uint32 BuildingAggregateDefClass::Get_Class_ID(void) const
  471. {
  472. return CLASSID_BUILDINGAGGREGATEDEF;
  473. }
  474. bool BuildingAggregateDefClass::Is_Type(const char * type_name)
  475. {
  476. if (stricmp(type_name,BuildingAggregateDefClass::Get_Type_Name()) == 0) {
  477. return true;
  478. } else {
  479. return StaticAnimPhysDefClass::Is_Type(type_name);
  480. }
  481. }
  482. /***********************************************************************************************
  483. * BuildingAggregateDefClass::Create -- creates an instance of a BuildingAggregateClass *
  484. * *
  485. * INPUT: *
  486. * *
  487. * OUTPUT: *
  488. * *
  489. * WARNINGS: *
  490. * *
  491. * HISTORY: *
  492. * 8/29/2000 gth : Created. *
  493. *=============================================================================================*/
  494. PersistClass * BuildingAggregateDefClass::Create(void) const
  495. {
  496. BuildingAggregateClass * obj = new BuildingAggregateClass;
  497. obj->Init( *this );
  498. return obj;
  499. }
  500. /*
  501. ** Save and Load
  502. */
  503. /***********************************************************************************************
  504. * BuildingAggregateDefClass::Get_Factory -- returns the persist factory *
  505. * *
  506. * INPUT: *
  507. * *
  508. * OUTPUT: *
  509. * *
  510. * WARNINGS: *
  511. * *
  512. * HISTORY: *
  513. * 8/29/2000 gth : Created. *
  514. *=============================================================================================*/
  515. const PersistFactoryClass & BuildingAggregateDefClass::Get_Factory(void) const
  516. {
  517. return _BuildingAggregateDefPersistFactory;
  518. }
  519. /***********************************************************************************************
  520. * BuildingAggregateDefClass::Save -- Saves the contents of this object *
  521. * *
  522. * INPUT: *
  523. * *
  524. * OUTPUT: *
  525. * *
  526. * WARNINGS: *
  527. * *
  528. * HISTORY: *
  529. * 8/29/2000 gth : Created. *
  530. *=============================================================================================*/
  531. bool BuildingAggregateDefClass::Save(ChunkSaveClass & csave)
  532. {
  533. csave.Begin_Chunk( BAGDEF_CHUNK_STATICANIMPHYS );
  534. StaticAnimPhysDefClass::Save( csave );
  535. csave.End_Chunk();
  536. csave.Begin_Chunk( BAGDEF_CHUNK_VARIABLES );
  537. WRITE_MICRO_CHUNK( csave, BAGDEF_VARIABLE_ANIMLOGICMODE, AnimLogicMode );
  538. WRITE_MICRO_CHUNK( csave, BAGDEF_VARIABLE_ISMCT, IsMCT );
  539. csave.End_Chunk();
  540. for (int i=0; i<BuildingStateClass::STATE_COUNT; i++) {
  541. Save_State_Animation_Data(csave,i);
  542. }
  543. return true;
  544. }
  545. /***********************************************************************************************
  546. * BuildingAggregateDefClass::Save_State_Animation_Data -- Save the data for one of the buildi *
  547. * *
  548. * INPUT: *
  549. * *
  550. * OUTPUT: *
  551. * *
  552. * WARNINGS: *
  553. * *
  554. * HISTORY: *
  555. * 8/29/2000 gth : Created. *
  556. *=============================================================================================*/
  557. bool BuildingAggregateDefClass::Save_State_Animation_Data(ChunkSaveClass & csave,int state_index)
  558. {
  559. WWASSERT(state_index >= 0);
  560. WWASSERT(state_index < BuildingStateClass::STATE_COUNT);
  561. csave.Begin_Chunk(BAGDEF_CHUNK_HEALTH100_POWERON_VARIABLES + state_index);
  562. WRITE_MICRO_CHUNK(csave,BAGDEF_VARIABLE_FRAME0,Frame0[state_index]);
  563. WRITE_MICRO_CHUNK(csave,BAGDEF_VARIABLE_FRAME1,Frame1[state_index]);
  564. WRITE_MICRO_CHUNK(csave,BAGDEF_VARIABLE_ANIMATIONENABLED,AnimationEnabled[state_index]);
  565. csave.End_Chunk();
  566. return true;
  567. }
  568. /***********************************************************************************************
  569. * BuildingAggregateDefClass::Load -- Load the contents of this object *
  570. * *
  571. * INPUT: *
  572. * *
  573. * OUTPUT: *
  574. * *
  575. * WARNINGS: *
  576. * *
  577. * HISTORY: *
  578. * 8/29/2000 gth : Created. *
  579. *=============================================================================================*/
  580. bool BuildingAggregateDefClass::Load( ChunkLoadClass &cload )
  581. {
  582. while (cload.Open_Chunk()) {
  583. switch(cload.Cur_Chunk_ID()) {
  584. case BAGDEF_CHUNK_STATICANIMPHYS:
  585. StaticAnimPhysDefClass::Load( cload );
  586. break;
  587. case BAGDEF_CHUNK_VARIABLES:
  588. while (cload.Open_Micro_Chunk()) {
  589. switch(cload.Cur_Micro_Chunk_ID()) {
  590. READ_MICRO_CHUNK( cload, BAGDEF_VARIABLE_ANIMLOGICMODE,AnimLogicMode );
  591. READ_MICRO_CHUNK( cload, BAGDEF_VARIABLE_ISMCT, IsMCT );
  592. default:
  593. WWDEBUG_SAY(( "Unrecognized BuildingAggregateDef Variable chunkID\n" ));
  594. break;
  595. }
  596. cload.Close_Micro_Chunk();
  597. }
  598. break;
  599. case BAGDEF_CHUNK_HEALTH100_POWERON_VARIABLES:
  600. case BAGDEF_CHUNK_HEALTH75_POWERON_VARIABLES:
  601. case BAGDEF_CHUNK_HEALTH50_POWERON_VARIABLES:
  602. case BAGDEF_CHUNK_HEALTH25_POWERON_VARIABLES:
  603. case BAGDEF_CHUNK_DESTROYED_POWERON_VARIABLES:
  604. case BAGDEF_CHUNK_HEALTH100_POWEROFF_VARIABLES:
  605. case BAGDEF_CHUNK_HEALTH75_POWEROFF_VARIABLES:
  606. case BAGDEF_CHUNK_HEALTH50_POWEROFF_VARIABLES:
  607. case BAGDEF_CHUNK_HEALTH25_POWEROFF_VARIABLES:
  608. case BAGDEF_CHUNK_DESTROYED_POWEROFF_VARIABLES:
  609. Load_State_Animation_Data(cload,cload.Cur_Chunk_ID() - BAGDEF_CHUNK_HEALTH100_POWERON_VARIABLES);
  610. break;
  611. default:
  612. WWDEBUG_SAY(( "Unrecognized BuildingAggregateDef chunkID\n" ));
  613. break;
  614. }
  615. cload.Close_Chunk();
  616. }
  617. return true;
  618. }
  619. /***********************************************************************************************
  620. * BuildingAggregateDefClass::Load_State_Animation_Data -- Load anim data for a building state *
  621. * *
  622. * INPUT: *
  623. * *
  624. * OUTPUT: *
  625. * *
  626. * WARNINGS: *
  627. * *
  628. * HISTORY: *
  629. * 8/29/2000 gth : Created. *
  630. *=============================================================================================*/
  631. bool BuildingAggregateDefClass::Load_State_Animation_Data(ChunkLoadClass & cload,int state_index)
  632. {
  633. WWASSERT(state_index >= 0);
  634. WWASSERT(state_index < BuildingStateClass::STATE_COUNT);
  635. while (cload.Open_Micro_Chunk()) {
  636. switch(cload.Cur_Micro_Chunk_ID()) {
  637. READ_MICRO_CHUNK(cload,BAGDEF_VARIABLE_FRAME0,Frame0[state_index]);
  638. READ_MICRO_CHUNK(cload,BAGDEF_VARIABLE_FRAME1,Frame1[state_index]);
  639. READ_MICRO_CHUNK(cload,BAGDEF_VARIABLE_ANIMATIONENABLED,AnimationEnabled[state_index]);
  640. default:
  641. WWDEBUG_SAY(( "Unrecognized BuildingAggregateDef Variable chunkID\n" ));
  642. break;
  643. }
  644. cload.Close_Micro_Chunk();
  645. }
  646. return true;
  647. }