Editor_Prvku.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "..\\komat\\mss_on.h"
  2. #include <windows.h>
  3. #include <commctrl.h>
  4. #include <io.h>
  5. #include <direct.h>
  6. //#include <d3d.h>
  7. #include <stdio.h>
  8. #include <math.h>
  9. #include <assert.h>
  10. #include "..\\komat\\resource.h"
  11. #include "..\\komat\\objekt_editor_all.h"
  12. #include "Object.h"
  13. #pragma comment(lib,"ComCtl32.lib")
  14. #pragma comment(lib,"winmm.lib")
  15. typedef struct
  16. {
  17. TCHAR Name[30];
  18. INT Index;
  19. } WAVEFILEDESC;
  20. const NUMOFOBJECTS = 1000;
  21. const NUMOFCLASSES = 20;
  22. FILE *file;
  23. WAVEFILEDESC *WaveFile;
  24. OBJECTDESC *Object;
  25. SECONDDATADESC *SecondData;
  26. TCHAR Directory[256];
  27. TCHAR Directory3[256];
  28. int NumOfFiles, i, ActualItem;
  29. char ActualName[30];
  30. BOOL CALLBACK ko_MainDlgProc(HWND hDlg, UINT msg, WPARAM wParam,
  31. LPARAM lParam);
  32. HRESULT ko_OnInitDialog(HWND hDlg);
  33. int ko_GetLayer(int Guid)
  34. {
  35. int i;
  36. i = Guid / 1000;
  37. if ((i == 3) ||
  38. (i == 4) ||
  39. (i == 8) ||
  40. (i == 9) || (i == 10) || (i == 11) || (i == 12) || (i == 15) || (i == 16))
  41. return 0;
  42. else
  43. return 1;
  44. }
  45. INT GetFreeObject()
  46. {
  47. for (i = 0; i < NUMOFOBJECTS; i++)
  48. if (Object[i].Class == 0)
  49. return i;
  50. return i;
  51. }
  52. INT TranslateWave(char *pFileName)
  53. {
  54. for (i = 0; i < NumOfFiles; i++)
  55. if (strcmp(WaveFile[i].Name, pFileName) == 0)
  56. return WaveFile[i].Index;
  57. return -1;
  58. }
  59. char *TranslateIndex(int FileIndex)
  60. {
  61. for (i = 0; i < NumOfFiles; i++)
  62. if (WaveFile[i].Index == FileIndex)
  63. return WaveFile[i].Name;
  64. return NULL;
  65. }
  66. INT CountObjects()
  67. {
  68. INT Count;
  69. Count = 0;
  70. for (i = 0; i < NUMOFOBJECTS; i++)
  71. if (Object[i].Class != 0)
  72. Count++;
  73. return Count;
  74. }
  75. BOOL CheckGuid(INT g)
  76. {
  77. INT j;
  78. for (j = 0; j < NUMOFOBJECTS; j++)
  79. if ((Object[j].GUID == g) && (Object[j].Class != 0))
  80. return TRUE;
  81. return FALSE;
  82. }
  83. void NaplnListBox(HWND hWnd, int Class)
  84. {
  85. int i;
  86. DWORD WordString;
  87. HWND hCombo = GetDlgItem(hWnd, IDC_LISTOFITEMS);
  88. SendMessage(hCombo, LB_RESETCONTENT, 0, 0);
  89. for (i = 0; i < NUMOFOBJECTS; i++)
  90. if ((Object[i].GUID >= Class) && (Object[i].GUID < (Class + 1000))) {
  91. WordString =
  92. SendMessage(hCombo, LB_ADDSTRING, 0,
  93. (LPARAM) (LPCTSTR) Object[i].Name);
  94. SendMessage(hCombo, LB_SETITEMDATA, WordString, i);
  95. }
  96. }
  97. OBJECTDESC *ko_Nahraj_herni_prvky(void)
  98. {
  99. char FileName[256];
  100. char Text[256];
  101. long error;
  102. int Count;
  103. int m;
  104. struct _finddata_t Data;
  105. long Done;
  106. GetPrivateProfileString("soundengine", "sound_dir", "c:\\", Directory, 256,
  107. ini_file);
  108. GetPrivateProfileString("game", "prvky_dir", "c:\\", Directory3, 256,
  109. ini_file);
  110. WaveFile = (WAVEFILEDESC *) malloc(1000 * sizeof(WAVEFILEDESC));
  111. if (WaveFile == NULL)
  112. MessageBox(NULL, "Nelze alokovat pamet pro WAVEFILEDESC", "!!!", MB_OK);
  113. strcpy(FileName, Directory);
  114. strcat(FileName, "\\Index.dat");
  115. file = fopen(FileName, "r");
  116. if (file) {
  117. fgets(Text, 30, file);
  118. NumOfFiles = atoi(Text);
  119. for (i = 0; i < NumOfFiles; i++) {
  120. fgets(Text, 30, file);
  121. Text[strlen(Text) - 1] = '\0';
  122. strcpy(WaveFile[i].Name, Text);
  123. fgets(Text, 30, file);
  124. WaveFile[i].Index = atoi(Text);
  125. }
  126. fclose(file);
  127. }
  128. else
  129. MessageBox(NULL, "Index.dat nenalezen", "Nahraj herni prvky", MB_OK);
  130. Object = (OBJECTDESC *) malloc(NUMOFOBJECTS * sizeof(OBJECTDESC));
  131. if (Object == NULL)
  132. MessageBox(NULL, "Nelze alokovat pamet pro OBJECTDESC", "!!!", MB_OK);
  133. for (i = 0; i < NUMOFOBJECTS; i++)
  134. Object[i].Class = 0;
  135. SecondData =
  136. (SECONDDATADESC *) malloc(NUMOFOBJECTS * sizeof(SECONDDATADESC));
  137. if (SecondData == NULL)
  138. MessageBox(NULL, "Nelze alokovat pamet pro SECONDDATADESC", "!!!", MB_OK);
  139. file = 0;
  140. strcpy(FileName, Directory3);
  141. strcat(FileName, "\\*.itm");
  142. Count = 0;
  143. Done = _findfirst(FileName, &Data);
  144. error = Done;
  145. while (error != -1) {
  146. Count++;
  147. error = _findnext(Done, &Data);
  148. }
  149. _findclose(Done);
  150. Done = _findfirst(FileName, &Data);
  151. error = Done;
  152. m = 0;
  153. if (error != -1) {
  154. do {
  155. strcpy(FileName, Directory3);
  156. strcat(FileName, "\\");
  157. strcat(FileName, Data.name);
  158. file = fopen(FileName, "rb");
  159. if (file) {
  160. fread(Object + m, sizeof(OBJECTDESC), 1, file);
  161. fseek(file, 1000, SEEK_SET);
  162. fread(SecondData + m, sizeof(SECONDDATADESC), 1, file);
  163. fclose(file);
  164. }
  165. else
  166. MessageBox(NULL, "Soubor nenalezen", "Nahraj herni prvky", MB_OK);
  167. error = _findnext(Done, &Data);
  168. m++;
  169. }
  170. while (error != -1);
  171. }
  172. _findclose(Done);
  173. return Object;
  174. }
  175. void ko_Uvolni_herni_prvky(void)
  176. {
  177. free((void *) Object);
  178. free((void *) WaveFile);
  179. free((void *) SecondData);
  180. }