gamemaps.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. /* $Header: /Commando/Code/Tools/max2w3d/gamemaps.cpp 5 10/28/97 6:08p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D engine *
  24. * *
  25. * File Name : GAMEMAPS.CPP *
  26. * *
  27. * Programmer : Greg Hjelstrom *
  28. * *
  29. * Start Date : 06/26/97 *
  30. * *
  31. * Last Update : June 26, 1997 [GH] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * GameMapsClass::ClassID -- Returns the ClassID for GameMapsClass *
  36. * GameMapsClass::AssignController -- Assigns a controller to one of the Sub-Anims *
  37. * GameMapsClass::NotifyRefChanged -- Max is notifying GameMapsClass that a reference has cha*
  38. * GameMapsClass::Clone -- Create a clone of the GameMapsClass *
  39. * GameMapsClass::Save -- Saves the GameMapsClass data into a MAX file *
  40. * GameMapsClass::Load -- Loads GameMapsClass data from a MAX file *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "gamemaps.h"
  43. /*****************************************************************
  44. *
  45. * Chunk ID's for saving data in the MAX file.
  46. *
  47. *****************************************************************/
  48. #define GAMEMAPS_ONOFF_CHUNK 0x0000
  49. #define GAMEMAPS_AMT0_CHUNK 0x0001
  50. #define GAMEMAPS_AMT1_CHUNK 0x0002
  51. #define GAMEMAPS_AMT2_CHUNK 0x0003
  52. #define GAMEMAPS_AMT3_CHUNK 0x0004
  53. #define GAMEMAPS_AMT4_CHUNK 0x0005
  54. #define GAMEMAPS_AMT5_CHUNK 0x0006
  55. #define GAMEMAPS_AMT6_CHUNK 0x0007
  56. #define GAMEMAPS_AMT7_CHUNK 0x0008
  57. #define GAMEMAPS_AMT8_CHUNK 0x0009
  58. #define GAMEMAPS_AMT9_CHUNK 0x000A
  59. #define GAMEMAPS_AMTA_CHUNK 0x000B
  60. /*****************************************************************
  61. *
  62. * A PostLoadCallback which does nothing...
  63. *
  64. *****************************************************************/
  65. class GameMapsPostLoad : public PostLoadCallback
  66. {
  67. public:
  68. GameMapsClass *tm;
  69. GameMapsPostLoad(GameMapsClass *b) {tm=b;}
  70. void proc(ILoad *iload) { delete this; }
  71. };
  72. /*****************************************************************
  73. *
  74. * GameMapsClass Class Desriptor
  75. *
  76. *****************************************************************/
  77. static Class_ID _GameMapsClassID(0x36d23f7b, 0x79ce63e1);
  78. class GameMapsClassDesc : public ClassDesc
  79. {
  80. public:
  81. int IsPublic() { return 0; }
  82. void * Create(BOOL loading) { return new GameMapsClass(NULL); }
  83. const TCHAR * ClassName() { return _T("GameMaps"); }
  84. SClass_ID SuperClassID() { return REF_MAKER_CLASS_ID; }
  85. Class_ID ClassID() { return _GameMapsClassID; }
  86. const TCHAR* Category() { return _T(""); }
  87. };
  88. static GameMapsClassDesc _GameMapsCD;
  89. ClassDesc * Get_Game_Maps_Desc() { return &_GameMapsCD; }
  90. /***********************************************************************************************
  91. * GameMapsClass::ClassID -- Returns the ClassID for GameMapsClass *
  92. * *
  93. * INPUT: *
  94. * *
  95. * OUTPUT: *
  96. * *
  97. * WARNINGS: *
  98. * *
  99. * HISTORY: *
  100. * 06/26/1997 GH : Created. *
  101. *=============================================================================================*/
  102. Class_ID GameMapsClass::ClassID()
  103. {
  104. return _GameMapsClassID;
  105. }
  106. /***********************************************************************************************
  107. * GameMapsClass::AssignController -- Assigns a controller to one of the Sub-Anims *
  108. * *
  109. * INPUT: *
  110. * *
  111. * OUTPUT: *
  112. * *
  113. * WARNINGS: *
  114. * *
  115. * HISTORY: *
  116. * 06/26/1997 GH : Created. *
  117. *=============================================================================================*/
  118. BOOL GameMapsClass::AssignController(Animatable *control,int subAnim)
  119. {
  120. ReplaceReference(SubNumToRefNum(subAnim),(ReferenceTarget *)control);
  121. return TRUE;
  122. }
  123. /***********************************************************************************************
  124. * GameMapsClass::NotifyRefChanged -- Max is notifying GameMapsClass that a reference has chan *
  125. * *
  126. * INPUT: *
  127. * *
  128. * OUTPUT: *
  129. * *
  130. * WARNINGS: *
  131. * *
  132. * HISTORY: *
  133. * 06/26/1997 GH : Created. *
  134. *=============================================================================================*/
  135. RefResult GameMapsClass::NotifyRefChanged
  136. (
  137. Interval changeInt,
  138. RefTargetHandle hTarget,
  139. PartID & partID,
  140. RefMessage message
  141. )
  142. {
  143. switch (message) {
  144. case REFMSG_GET_PARAM_DIM: {
  145. GetParamDim *gpd = (GetParamDim*)partID;
  146. break;
  147. }
  148. case REFMSG_GET_PARAM_NAME: {
  149. GetParamName *gpn = (GetParamName*)partID;
  150. return REF_STOP;
  151. }
  152. }
  153. return(REF_SUCCEED);
  154. }
  155. /***********************************************************************************************
  156. * GameMapsClass::Clone -- Create a clone of the GameMapsClass *
  157. * *
  158. * INPUT: *
  159. * *
  160. * OUTPUT: *
  161. * *
  162. * WARNINGS: *
  163. * *
  164. * HISTORY: *
  165. * 06/26/1997 GH : Created. *
  166. *=============================================================================================*/
  167. RefTargetHandle GameMapsClass::Clone(RemapDir &remap)
  168. {
  169. GameMapsClass *tm = new GameMapsClass(NULL);
  170. for (int i=0; i<NTEXMAPS; i++) {
  171. tm->TextureSlot[i].MapOn = TextureSlot[i].MapOn;
  172. tm->TextureSlot[i].Map = NULL;
  173. if (TextureSlot[i].Map) {
  174. tm->ReplaceReference(i,remap.CloneRef(TextureSlot[i].Map));
  175. }
  176. }
  177. return tm;
  178. }
  179. /***********************************************************************************************
  180. * GameMapsClass::Save -- Saves the GameMapsClass data into a MAX file *
  181. * *
  182. * INPUT: *
  183. * *
  184. * OUTPUT: *
  185. * *
  186. * WARNINGS: *
  187. * *
  188. * HISTORY: *
  189. * 06/26/1997 GH : Created. *
  190. *=============================================================================================*/
  191. IOResult GameMapsClass::Save(ISave * isave)
  192. {
  193. ULONG nb,f=0;
  194. isave->BeginChunk(GAMEMAPS_ONOFF_CHUNK);
  195. for (int i=0; i<NTEXMAPS; i++) {
  196. if (TextureSlot[i].MapOn) f|= (1<<i);
  197. }
  198. isave->Write(&f,sizeof(f),&nb);
  199. isave->EndChunk();
  200. for (i=0; i<NTEXMAPS; i++) {
  201. if (TextureSlot[i].Amount != 1.0f) {
  202. isave->BeginChunk(GAMEMAPS_AMT0_CHUNK + i);
  203. isave->Write(&(TextureSlot[i].Amount),sizeof(float),&nb);
  204. isave->EndChunk();
  205. }
  206. }
  207. return IO_OK;
  208. }
  209. /***********************************************************************************************
  210. * GameMapsClass::Load -- Loads GameMapsClass data from a MAX file *
  211. * *
  212. * INPUT: *
  213. * *
  214. * OUTPUT: *
  215. * *
  216. * WARNINGS: *
  217. * *
  218. * HISTORY: *
  219. * 06/26/1997 GH : Created. *
  220. *=============================================================================================*/
  221. IOResult GameMapsClass::Load(ILoad * iload)
  222. {
  223. ULONG nb;
  224. int id;
  225. IOResult res;
  226. while (IO_OK==(res=iload->OpenChunk())) {
  227. switch (id = iload->CurChunkID()) {
  228. case GAMEMAPS_ONOFF_CHUNK:
  229. {
  230. ULONG f;
  231. res = iload->Read(&f,sizeof(f), &nb);
  232. for (int i=0; i<NTEXMAPS; i++)
  233. (*this)[i].MapOn = (f&(1<<i))?1:0;
  234. }
  235. break;
  236. case GAMEMAPS_AMT0_CHUNK:
  237. case GAMEMAPS_AMT1_CHUNK:
  238. case GAMEMAPS_AMT2_CHUNK:
  239. case GAMEMAPS_AMT3_CHUNK:
  240. case GAMEMAPS_AMT4_CHUNK:
  241. case GAMEMAPS_AMT5_CHUNK:
  242. case GAMEMAPS_AMT7_CHUNK:
  243. case GAMEMAPS_AMT8_CHUNK:
  244. case GAMEMAPS_AMT9_CHUNK:
  245. case GAMEMAPS_AMTA_CHUNK:
  246. int index = id - GAMEMAPS_AMT0_CHUNK;
  247. res = iload->Read(&(TextureSlot[index].Amount),sizeof(float),&nb);
  248. break;
  249. }
  250. iload->CloseChunk();
  251. if (res!=IO_OK) {
  252. return res;
  253. }
  254. }
  255. return IO_OK;
  256. }