definition.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : WWSaveLoad *
  23. * *
  24. * $Archive:: /Commando/Code/wwsaveload/definition.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/24/01 4:35p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "definition.h"
  36. #include "chunkio.h"
  37. //////////////////////////////////////////////////////////////////////////////////
  38. // Constants
  39. //////////////////////////////////////////////////////////////////////////////////
  40. enum
  41. {
  42. CHUNKID_VARIABLES = 0x00000100,
  43. };
  44. enum
  45. {
  46. VARID_INSTANCEID = 0x01,
  47. XXX_VARID_PARENTID,
  48. VARID_NAME,
  49. };
  50. /////////////////////////////////////////////////////////
  51. //
  52. // Save
  53. //
  54. /////////////////////////////////////////////////////////
  55. bool
  56. DefinitionClass::Save (ChunkSaveClass &csave)
  57. {
  58. bool retval = true;
  59. csave.Begin_Chunk (CHUNKID_VARIABLES);
  60. retval &= Save_Variables (csave);
  61. csave.End_Chunk ();
  62. return retval;
  63. }
  64. /////////////////////////////////////////////////////////
  65. //
  66. // Load
  67. //
  68. /////////////////////////////////////////////////////////
  69. bool
  70. DefinitionClass::Load (ChunkLoadClass &cload)
  71. {
  72. bool retval = true;
  73. while (cload.Open_Chunk ()) {
  74. switch (cload.Cur_Chunk_ID ()) {
  75. case CHUNKID_VARIABLES:
  76. Load_Variables (cload);
  77. break;
  78. }
  79. cload.Close_Chunk ();
  80. }
  81. return retval;
  82. }
  83. //////////////////////////////////////////////////////////////////////////////////
  84. //
  85. // Save_Variables
  86. //
  87. //////////////////////////////////////////////////////////////////////////////////
  88. bool
  89. DefinitionClass::Save_Variables (ChunkSaveClass &csave)
  90. {
  91. bool retval = true;
  92. WRITE_MICRO_CHUNK (csave, VARID_INSTANCEID, m_ID);
  93. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_NAME, m_Name);
  94. return retval;
  95. }
  96. //////////////////////////////////////////////////////////////////////////////////
  97. //
  98. // Load_Variables
  99. //
  100. //////////////////////////////////////////////////////////////////////////////////
  101. bool
  102. DefinitionClass::Load_Variables (ChunkLoadClass &cload)
  103. {
  104. bool retval = true;
  105. //
  106. // Loop through all the microchunks that define the variables
  107. //
  108. while (cload.Open_Micro_Chunk ()) {
  109. switch (cload.Cur_Micro_Chunk_ID ()) {
  110. READ_MICRO_CHUNK (cload, VARID_INSTANCEID, m_ID)
  111. READ_MICRO_CHUNK_WWSTRING (cload, VARID_NAME, m_Name)
  112. }
  113. cload.Close_Micro_Chunk ();
  114. }
  115. return retval;
  116. }
  117. //////////////////////////////////////////////////////////////////////////////////
  118. //
  119. // Set_ID
  120. //
  121. //////////////////////////////////////////////////////////////////////////////////
  122. void
  123. DefinitionClass::Set_ID (uint32 id)
  124. {
  125. m_ID = id;
  126. //
  127. // If we are registered with the definition manager, then we need to
  128. // re-link ourselves back into the list
  129. //
  130. if (m_DefinitionMgrLink != -1) {
  131. DefinitionMgrClass::Unregister_Definition (this);
  132. DefinitionMgrClass::Register_Definition (this);
  133. }
  134. return ;
  135. }