shddef.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 : WWSHADE *
  23. * *
  24. * $Archive:: wwshade/shddef.cpp $*
  25. * *
  26. * $Org Author:: Jani_p
  27. *
  28. * $Author:: Kenny_m
  29. *
  30. * $Modtime:: 6/07/02 3:12p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. * 6/07/02 KJM : Added validation enum
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "shddef.h"
  39. #include "chunkio.h"
  40. #include "w3d_file.h"
  41. ShdDefClass::ShdDefClass(uint32 classid) :
  42. ClassID(classid),
  43. Name("UnNamed"),
  44. SurfaceType(0)
  45. {
  46. ENUM_PARAM (
  47. ShdDefClass, SurfaceType,
  48. (
  49. "Light Metal", SURFACE_TYPE_LIGHT_METAL,
  50. "Heavy Metal", SURFACE_TYPE_HEAVY_METAL,
  51. "Water", SURFACE_TYPE_WATER,
  52. "Sand", SURFACE_TYPE_SAND,
  53. "Dirt", SURFACE_TYPE_DIRT,
  54. "Mud", SURFACE_TYPE_MUD,
  55. "Grass", SURFACE_TYPE_GRASS,
  56. "Wood", SURFACE_TYPE_WOOD,
  57. "Concrete", SURFACE_TYPE_CONCRETE,
  58. "Flesh", SURFACE_TYPE_FLESH,
  59. "Rock", SURFACE_TYPE_ROCK,
  60. "Snow", SURFACE_TYPE_SNOW,
  61. "Ice", SURFACE_TYPE_ICE,
  62. "Default", SURFACE_TYPE_DEFAULT,
  63. "Glass", SURFACE_TYPE_GLASS,
  64. "Cloth", SURFACE_TYPE_CLOTH,
  65. "Tiberium Field", SURFACE_TYPE_TIBERIUM_FIELD,
  66. "Foliage Permeable", SURFACE_TYPE_FOLIAGE_PERMEABLE,
  67. "Glass Permeable", SURFACE_TYPE_GLASS_PERMEABLE,
  68. "Ice Permeable", SURFACE_TYPE_ICE_PERMEABLE,
  69. "Cloth Permeable", SURFACE_TYPE_CLOTH_PERMEABLE,
  70. "Electrical", SURFACE_TYPE_ELECTRICAL,
  71. "Electrical Permeable", SURFACE_TYPE_ELECTRICAL_PERMEABLE,
  72. "Flammable", SURFACE_TYPE_FLAMMABLE,
  73. "Flammable Permeable", SURFACE_TYPE_FLAMMABLE_PERMEABLE ,
  74. "Steam", SURFACE_TYPE_STEAM,
  75. "Steam Permeable", SURFACE_TYPE_STEAM_PERMEABLE,
  76. "Water Permeable", SURFACE_TYPE_WATER_PERMEABLE,
  77. "Tiberium Water", SURFACE_TYPE_TIBERIUM_WATER,
  78. "Tiberium Water Permeable", SURFACE_TYPE_TIBERIUM_WATER_PERMEABLE,
  79. "Underwater Dirt", SURFACE_TYPE_UNDERWATER_DIRT,
  80. "Underwater Tiberium Dirt", SURFACE_TYPE_UNDERWATER_TIBERIUM_DIRT,
  81. NULL
  82. )
  83. );
  84. }
  85. ShdDefClass::ShdDefClass(const ShdDefClass & that):
  86. ClassID(that.ClassID),
  87. Name(that.Name),
  88. SurfaceType(that.SurfaceType)
  89. {
  90. }
  91. ShdDefClass::~ShdDefClass(void)
  92. {
  93. }
  94. const char * ShdDefClass::Get_Name (void) const
  95. {
  96. return Name;
  97. }
  98. void ShdDefClass::Set_Name (const char *new_name)
  99. {
  100. Name = new_name;
  101. }
  102. void ShdDefClass::Reset(void)
  103. {
  104. SurfaceType = 0;
  105. }
  106. /*******************************************************************************
  107. **
  108. ** Save-Load methods for ShdDefClass
  109. **
  110. *******************************************************************************/
  111. enum
  112. {
  113. CHUNKID_VARIABLES = 0x16490430,
  114. VARID_NAME = 0x00,
  115. VARID_SURFACETYPE,
  116. };
  117. //**********************************************************************************************
  118. //! Serialize this ShdDef into a chunk saver
  119. /*!
  120. @param csave - ChunkSave object to write into
  121. */
  122. bool ShdDefClass::Save (ChunkSaveClass &csave)
  123. {
  124. bool retval=true;
  125. csave.Begin_Chunk(CHUNKID_VARIABLES);
  126. retval=Save_Variables(csave);
  127. csave.End_Chunk ();
  128. return retval;
  129. }
  130. //**********************************************************************************************
  131. //! Load this ShdDef from a chunk loader
  132. /*!
  133. @param cload - ChunkLoad object to read from
  134. */
  135. bool ShdDefClass::Load (ChunkLoadClass &cload)
  136. {
  137. bool retval = true;
  138. cload.Open_Chunk();
  139. retval=cload.Cur_Chunk_ID()==CHUNKID_VARIABLES;
  140. Load_Variables(cload);
  141. cload.Close_Chunk();
  142. return retval;
  143. }
  144. //**********************************************************************************************
  145. //! Save the variables for this object
  146. /*!
  147. Each variable is stored in its own "micro-chunk" for flexibility.
  148. @param csave - chunk saver to write to.
  149. */
  150. bool ShdDefClass::Save_Variables (ChunkSaveClass &csave)
  151. {
  152. bool retval = true;
  153. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_NAME, Name);
  154. WRITE_MICRO_CHUNK (csave, VARID_SURFACETYPE, SurfaceType);
  155. return retval;
  156. }
  157. //**********************************************************************************************
  158. //! Load the variables for this object from a chunk
  159. /*!
  160. @param cload - chunk loader to read from
  161. */
  162. bool ShdDefClass::Load_Variables (ChunkLoadClass &cload)
  163. {
  164. bool retval = true;
  165. //
  166. // Loop through all the microchunks that define the variables
  167. //
  168. while (cload.Open_Micro_Chunk ())
  169. {
  170. switch (cload.Cur_Micro_Chunk_ID ())
  171. {
  172. READ_MICRO_CHUNK_WWSTRING (cload, VARID_NAME, Name);
  173. READ_MICRO_CHUNK (cload, VARID_SURFACETYPE, SurfaceType);
  174. }
  175. cload.Close_Micro_Chunk();
  176. }
  177. return retval;
  178. }