Comics.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include "3d_all.h"
  4. #include "Berusky3d_kofola_interface.h"
  5. #include "menu_script.h"
  6. #include "2D_graphic.h"
  7. #include "game_init.h"
  8. typedef struct
  9. {
  10. int iPicture;
  11. int iTimeToNextPicture;
  12. int xPos;
  13. int yPos;
  14. } COMICS_PICTURE;
  15. #define DARKEN_ADD -200
  16. static char bCimicsEnd;
  17. static int iActualBmp;
  18. static TIMER_ID uiTimerID;
  19. static COMICS_PICTURE cmcs_Picture[64];
  20. /*static MCI_DGV_OPEN_PARMS mciOpen;
  21. static MCI_DGV_WINDOW_PARMS mciWindow;
  22. static DWORD wDeviceID = 0;
  23. static DWORD wError;*/
  24. extern char pBmpDir[MAX_FILENAME];
  25. void cmcs_Draw(int iIndex, int xPos, int yPos)
  26. {
  27. /*
  28. BitBlt(_2dd.hDC, xPos, yPos,
  29. _2dd.bitmap[iIndex].bitmap.bmWidth,
  30. _2dd.bitmap[iIndex].bitmap.bmHeight,
  31. _2dd.bitmap[iIndex].bitmapDC,0,0,SRCCOPY);
  32. */
  33. }
  34. void cmcs_Read_Line(char *pLine, COMICS_PICTURE * pPicture)
  35. {
  36. int p = 0;
  37. char expression[MAX_FILENAME];
  38. p = Find_Next_Expresion(pLine, p, expression);
  39. pPicture->xPos = atoi(expression);
  40. p = Find_Next_Expresion(pLine, p, expression);
  41. pPicture->yPos = atoi(expression);
  42. p = Find_Next_Expresion(pLine, p, expression);
  43. pPicture->iTimeToNextPicture = atoi(expression);
  44. }
  45. void cmcs_Next_Picture(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  46. {
  47. COMICS_PICTURE *pPicture = &cmcs_Picture[iActualBmp];
  48. KillTimer(NULL, uiTimerID);
  49. if (pPicture->iPicture == -1) {
  50. bCimicsEnd = 1;
  51. return;
  52. }
  53. if (!pPicture->iTimeToNextPicture) {
  54. cmcs_Draw(pPicture->iPicture, pPicture->xPos, pPicture->yPos);
  55. iActualBmp++;
  56. pPicture = &cmcs_Picture[iActualBmp];
  57. }
  58. cmcs_Draw(pPicture->iPicture, pPicture->xPos, pPicture->yPos);
  59. uiTimerID =
  60. SetTimer(NULL, 0, pPicture->iTimeToNextPicture,
  61. (TIMERPROC) cmcs_Next_Picture);
  62. iActualBmp++;
  63. }
  64. void cmcs_Start_Comics(char *cFile, HWND hWnd, AUDIO_DATA * p_ad, char bMusic)
  65. {
  66. int i;
  67. char text[MAX_FILENAME] = "";
  68. FILE *file;
  69. bCimicsEnd = 0;
  70. iActualBmp = 0;
  71. file = fopen(cFile, "r");
  72. if (!file)
  73. return;
  74. for (i = 0; i < 64; i++)
  75. cmcs_Picture[i].iPicture = -1;
  76. while (strcmp(text, "LOAD_END")) {
  77. if (fgets(text, MAX_FILENAME, file) == NULL)
  78. return;
  79. newline_cut(text);
  80. if (!strcmp(text, "LOAD_END"))
  81. break;
  82. i = ddxLoadBitmap(text, pBmpDir);
  83. }
  84. i = 0;
  85. while (strcmp(text, "COMICS_END")) {
  86. if (fgets(text, MAX_FILENAME, file) == NULL)
  87. return;
  88. newline_cut(text);
  89. cmcs_Read_Line(text, &cmcs_Picture[i]);
  90. cmcs_Picture[i].iPicture = i + 1;
  91. i++;
  92. }
  93. fclose(file);
  94. if(bMusic)
  95. if (p_ad->bAudio && p_ad->Music_Gain >= 0.05f)
  96. ap_Setup_and_Play_Song(1,0, p_ad);
  97. cmcs_Draw(0, 0, 0);
  98. cmcs_Draw(cmcs_Picture[0].iPicture, cmcs_Picture[0].xPos,
  99. cmcs_Picture[0].yPos);
  100. uiTimerID =
  101. SetTimer(NULL, 0, (UINT) cmcs_Picture[0].iTimeToNextPicture,
  102. (TIMERPROC) cmcs_Next_Picture);
  103. iActualBmp++;
  104. while (!bCimicsEnd) {
  105. spracuj_spravy(0);
  106. if (key[K_ESC]) {
  107. key[K_ESC] = 0;
  108. bCimicsEnd = 1;
  109. }
  110. Sleep(10);
  111. }
  112. if(bMusic)
  113. if(ogg_playing())
  114. ap_Stop_Song(p_ad);
  115. KillTimer(NULL, uiTimerID);
  116. // TODO
  117. // _2D_Release()
  118. }
  119. void cmcs_Play_Intro(char *cFile, HWND hWnd, AUDIO_DATA * p_ad)
  120. {
  121. if (chdir(DATA_DIR))
  122. return;
  123. cmcs_Start_Comics("gamelogo.txt", hWnd, p_ad, 0);
  124. }
  125. /*DWORD cmcs_Play_Movie(DWORD wDevID, DWORD dwFrom, DWORD dwTo)
  126. {
  127. MCI_DGV_PLAY_PARMS mciPlay; // play parameters
  128. DWORD dwFlags = 0;
  129. // Check dwFrom. If it is != 0 then set parameters and flags.
  130. if (dwFrom){
  131. mciPlay.dwFrom = dwFrom; // set parameter
  132. dwFlags |= MCI_FROM; // set flag to validate member
  133. }
  134. // Check dwTo. If it is != 0 then set parameters and flags.
  135. if (dwTo){
  136. mciPlay.dwTo = dwTo; // set parameter
  137. dwFlags |= MCI_TO; // set flag to validate member
  138. }
  139. // Send the MCI_PLAY command and return the result.
  140. return mciSendCommand(wDevID, MCI_PLAY, dwFlags,
  141. (DWORD)(LPVOID)&mciPlay);
  142. }
  143. */
  144. /*void cmcs_Stop_Video(void)
  145. {
  146. mciSendCommand(wDeviceID, MCI_STOP, 0, 0);
  147. mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
  148. }*/
  149. void cmcs_Game_Down(void)
  150. {
  151. /*
  152. ShowCursor(FALSE);
  153. spracuj_spravy(0);
  154. ShowWindow(hWnd,SW_SHOW);
  155. spracuj_spravy(0);
  156. SetForegroundWindow(hWnd);
  157. spracuj_spravy(0);
  158. SetFocus(hWnd);
  159. spracuj_spravy(0);
  160. mciSendString("open digitalvideo", NULL, 0, NULL);
  161. */
  162. }
  163. void cmcs_Game_Up(void)
  164. {
  165. /*
  166. mciSendString("close digitalvideo", NULL, 0, NULL);
  167. ShowCursor(TRUE);
  168. spracuj_spravy(0);
  169. ShowWindow(hWnd,SW_SHOW);
  170. spracuj_spravy(0);
  171. ShowWindow(hWnd,SW_MAXIMIZE);
  172. spracuj_spravy(0);
  173. */
  174. }
  175. void cmcs_Play_Video(char *pFile, long dwVideoTime, AUDIO_DATA * p_ad)
  176. {
  177. /*
  178. int done = 0;
  179. long counter = 0;
  180. char lpstrFile[256];
  181. GetPrivateProfileString("files","bitmap_dir","/",lpstrFile,256,ini_file);
  182. working_file_translate(lpstrFile,256);
  183. chdir(lpstrFile);
  184. sprintf(lpstrFile, "open %s type mpegvideo alias anakreonvideo style overlapped", pFile, hWnd);
  185. done = mciSendString(lpstrFile,0,0,0);
  186. if(done)
  187. {
  188. mciGetErrorString(done, lpstrFile, 256);
  189. kprintf(1,"%s", lpstrFile);
  190. }
  191. done = mciSendString("break anakreonvideo on 27", 0, 0, 0);
  192. wsprintf(lpstrFile, "put %s %s %s", "anakreonvideo", "destination at 0 0 1024 768", "");
  193. done = mciSendString(lpstrFile,0,0,0);
  194. wsprintf(lpstrFile, "put %s %s %s", "anakreonvideo", "window client at 0 0 1024 768", "");
  195. done = mciSendString(lpstrFile,0,0,0);
  196. wsprintf(lpstrFile, "put %s %s %s", "anakreonvideo", "window client at 0 0 1024 768", "");
  197. done = mciSendString(lpstrFile,0,0,0);
  198. done = mciSendString("window anakreonvideo state show", 0, 0, 0);
  199. if(done)
  200. {
  201. mciGetErrorString(done, lpstrFile, 256);
  202. kprintf(1,"%s", lpstrFile);
  203. }
  204. //ShowWindow(hWnd,SW_MINIMIZE);
  205. spracuj_spravy(0);
  206. wsprintf(lpstrFile, "setaudio %s %s %s", "anakreonvideo", "volume to 250", "");
  207. done = mciSendString(lpstrFile,0,0,0);
  208. done = mciSendString("play anakreonvideo from 0 wait fullscreen",0,0,hWnd);
  209. if(done)
  210. {
  211. mciGetErrorString(done, lpstrFile, 256);
  212. kprintf(1,"%s", lpstrFile);
  213. }
  214. mciSendString("stop anakreonvideo",0,0,0);
  215. mciSendString("close anakreonvideo",0,0,0);
  216. */
  217. }
  218. void cmcs_Start_Picture(int Index, long time, AUDIO_DATA * p_ad, char bMusic)
  219. {
  220. long timecnt = 0;
  221. char bCimicsEnd = 0;
  222. cmcs_Draw(Index, 0, 0);
  223. while (!bCimicsEnd) {
  224. spracuj_spravy(0);
  225. if (key[K_ESC]) {
  226. key[K_ESC] = 0;
  227. bCimicsEnd = 1;
  228. }
  229. Sleep(10);
  230. timecnt += 10;
  231. if (timecnt > time)
  232. bCimicsEnd = 1;
  233. }
  234. if(bMusic)
  235. if(ogg_playing())
  236. ap_Stop_Song(p_ad);
  237. }