OGAMMAIN.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OGAMMAIN.CPP
  21. //Description : Main Game Object - Main menu
  22. #include <OVGA.h>
  23. #include <OIMGRES.h>
  24. #include <OSYS.h>
  25. #include <OMOUSE.h>
  26. #include <OMOUSECR.h>
  27. #include <OFONT.h>
  28. #include <OTUTOR.h>
  29. #include <OBUTTON.h>
  30. #include <OBATTLE.h>
  31. #include <OGFILE.h>
  32. #include <OMUSIC.h>
  33. #include <OGAME.h>
  34. #include <OVGALOCK.h>
  35. #ifdef DEMO
  36. #define DISABLE_MULTI_PLAYER
  37. #define DISABLE_SINGLE_PLAYER_NEW_GAME
  38. #endif
  39. //----------- Define structure ---------//
  40. struct OptionInfo
  41. {
  42. short x1, y1, x2, y2;
  43. };
  44. // -------- define constant ----------//
  45. enum { SWORD1_X = 258, SWORD1_Y = 194 };
  46. //---------- Begin of function Game::main_menu ----------//
  47. //
  48. void Game::main_menu()
  49. {
  50. enum { MAIN_OPTION_COUNT = 6 };
  51. static OptionInfo main_option_array[MAIN_OPTION_COUNT] =
  52. {
  53. { 6+SWORD1_X, 11+SWORD1_Y, 282+SWORD1_X , 63+SWORD1_Y },
  54. { 6+SWORD1_X, 68+SWORD1_Y, 282+SWORD1_X , 113+SWORD1_Y },
  55. { 6+SWORD1_X, 121+SWORD1_Y, 282+SWORD1_X , 176+SWORD1_Y },
  56. // ####### begin Gilbert 20/10 ######//
  57. // { 6+SWORD1_X, 189+SWORD1_Y, 282+SWORD1_X , 219+SWORD1_Y },
  58. { 6+SWORD1_X, 184+SWORD1_Y, 282+SWORD1_X , 222+SWORD1_Y },
  59. // ####### end Gilbert 20/10 ######//
  60. { 6+SWORD1_X, 224+SWORD1_Y, 282+SWORD1_X , 295+SWORD1_Y },
  61. {40+SWORD1_X, 297+SWORD1_Y, 254+SWORD1_X , 337+SWORD1_Y },
  62. };
  63. char main_option_flag[MAIN_OPTION_COUNT] =
  64. {
  65. 1, 1, 1, 1, 1, 1,
  66. };
  67. // test sys.game_version, skip single player
  68. main_option_flag[0] = (sys.game_version == VERSION_MULTIPLAYER_ONLY) ? 0 : 1;
  69. // main_option_flag[0] = 1;
  70. // ###### begin Gilbert 25/9 #######//
  71. #ifdef DISABLE_MULTI_PLAYER
  72. // disable multiplayer game, Game::multi_player_menu is disabled
  73. main_option_flag[1] = 0;
  74. #endif
  75. // ###### end Gilbert 25/9 #######//
  76. // skip encyclopedia if not found
  77. main_option_flag[2] = *sys.dir_encyc ? 1 : 0;
  78. //------------- display menu options -------------//
  79. int refreshFlag=1, i;
  80. mouse_cursor.set_icon(CURSOR_NORMAL);
  81. vga_front.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_BLACK);
  82. OptionInfo* optionInfo;
  83. char *menuBitmap = NULL;
  84. char *brightBitmap = NULL;
  85. char *darkBitmap = NULL;
  86. int pointingOption = -1;
  87. while(1)
  88. {
  89. game_mode = GAME_PREGAME;
  90. //------- Display game title and paint menu box --------//
  91. if( refreshFlag )
  92. {
  93. mouse_cursor.set_icon(CURSOR_NORMAL);
  94. image_interface.put_to_buf( &vga_back, "M_MAIN" );
  95. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1); // blt the main menu screen from the back buffer to the front buffer
  96. disp_version();
  97. if(!menuBitmap)
  98. {
  99. int resSize;
  100. File *resFile;
  101. resFile = image_interface.get_file("SWRD-1", resSize);
  102. menuBitmap = mem_add(resSize);
  103. resFile->file_read(menuBitmap, resSize);
  104. }
  105. if(!brightBitmap)
  106. {
  107. int resSize;
  108. File *resFile;
  109. resFile = image_interface.get_file("SWRD-1B", resSize);
  110. brightBitmap = mem_add(resSize);
  111. resFile->file_read(brightBitmap, resSize);
  112. }
  113. if(!darkBitmap)
  114. {
  115. int resSize;
  116. File *resFile;
  117. resFile = image_interface.get_file("SWRD-1C", resSize);
  118. darkBitmap = mem_add(resSize);
  119. resFile->file_read(darkBitmap, resSize);
  120. }
  121. for( i = 0; i < MAIN_OPTION_COUNT; ++i )
  122. {
  123. if( main_option_flag[i] >= 0 )
  124. {
  125. mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
  126. main_option_array[i].x2, main_option_array[i].y2);
  127. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y,
  128. main_option_flag[i] ? menuBitmap : darkBitmap,
  129. main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
  130. main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
  131. mouse.show_area();
  132. }
  133. }
  134. pointingOption = -1;
  135. refreshFlag=0;
  136. }
  137. if( config.music_flag )
  138. {
  139. if( !music.is_playing(1) )
  140. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  141. }
  142. else
  143. {
  144. music.stop();
  145. }
  146. // display main menu
  147. int newPointingOption = -1;
  148. for(i = 0, optionInfo = main_option_array; i < MAIN_OPTION_COUNT; ++i, ++optionInfo)
  149. {
  150. if( main_option_flag[i] > 0 &&
  151. mouse.in_area(optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2) )
  152. {
  153. newPointingOption = i;
  154. break;
  155. }
  156. }
  157. if( pointingOption != newPointingOption)
  158. {
  159. err_when( !menuBitmap );
  160. err_when( !brightBitmap );
  161. err_when( !darkBitmap );
  162. // put un-highlighted option back
  163. i = pointingOption;
  164. if( i >= 0 && i < MAIN_OPTION_COUNT )
  165. {
  166. mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
  167. main_option_array[i].x2, main_option_array[i].y2);
  168. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, menuBitmap,
  169. main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
  170. main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
  171. mouse.show_area();
  172. }
  173. // put new hightlighted option
  174. i = newPointingOption;
  175. if( i >= 0 && i < MAIN_OPTION_COUNT )
  176. {
  177. mouse.hide_area(main_option_array[i].x1, main_option_array[i].y1,
  178. main_option_array[i].x2, main_option_array[i].y2);
  179. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, brightBitmap,
  180. main_option_array[i].x1 - SWORD1_X, main_option_array[i].y1 - SWORD1_Y,
  181. main_option_array[i].x2 - SWORD1_X, main_option_array[i].y2 - SWORD1_Y);
  182. mouse.show_area();
  183. }
  184. pointingOption = newPointingOption;
  185. }
  186. // ######### end Gilbert 23/7 ##########//
  187. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  188. //---------- detect buttons -----------//
  189. sys.yield();
  190. mouse.get_event();
  191. optionInfo = main_option_array;
  192. sys.signal_exit_flag = 0;
  193. for( i=0 ; i<MAIN_OPTION_COUNT ; i++, optionInfo++ )
  194. {
  195. if( main_option_flag[i] > 0 &&
  196. mouse.single_click( optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2 ) )
  197. {
  198. // ------- free some resource for a moment --------//
  199. if( menuBitmap )
  200. {
  201. mem_del(menuBitmap);
  202. menuBitmap = NULL;
  203. }
  204. if( brightBitmap)
  205. {
  206. mem_del(brightBitmap);
  207. brightBitmap = NULL;
  208. }
  209. if( darkBitmap)
  210. {
  211. mem_del(darkBitmap);
  212. darkBitmap = NULL;
  213. }
  214. run_main_menu_option(i+1);
  215. refreshFlag=1;
  216. break;
  217. }
  218. }
  219. //-------------------------------------//
  220. if( sys.signal_exit_flag == 1 || i == MAIN_OPTION_COUNT-1 ) // quit the system now
  221. break;
  222. }
  223. //--------------------------------------//
  224. music.stop();
  225. if( menuBitmap )
  226. mem_del(menuBitmap);
  227. if( brightBitmap)
  228. mem_del(brightBitmap);
  229. if( darkBitmap)
  230. mem_del(darkBitmap);
  231. //--------------------------------------//
  232. }
  233. //------------ End of function Game::main_menu -----------//
  234. //-------- Begin of function Game::run_main_menu_option --------//
  235. //
  236. // Run the selected game option.
  237. //
  238. void Game::run_main_menu_option(int optionId)
  239. {
  240. //------- Single Player Game -------//
  241. if( optionId==1 )
  242. {
  243. single_player_menu();
  244. }
  245. //-------- Multiplayer Game ----------//
  246. if( optionId==2 )
  247. {
  248. #ifndef DISABLE_MULTI_PLAYER
  249. game_mode = GAME_MULTI_PLAYER;
  250. multi_player_menu(NULL);
  251. // multi_player_game();
  252. #endif
  253. }
  254. //----------- Encyclopedia -----------//
  255. if( optionId==3 )
  256. {
  257. game_mode = GAME_ENCYCLOPEDIA;
  258. view_encyclopedia();
  259. }
  260. //----------- Hall of Fame -----------//
  261. if( optionId==4 )
  262. {
  263. game_file_array.disp_hall_of_fame();
  264. }
  265. //------------- Credits -----------//
  266. // ####### begin Gilbert 2/9 #######//
  267. if( optionId==5 )
  268. {
  269. if( m.is_file_exist("TESTING2.SYS") )
  270. {
  271. game_mode = GAME_TEST; // testing game instead
  272. test_game();
  273. }
  274. else
  275. {
  276. game_mode = GAME_CREDITS;
  277. view_credits();
  278. }
  279. }
  280. // ####### end Gilbert 2/9 #######//
  281. // ####### begin Gilbert 7/11 #########//
  282. if( optionId==6 )
  283. {
  284. sys.signal_exit_flag = 1;
  285. }
  286. // ####### end Gilbert 7/11 #########//
  287. }
  288. //---------- End of function Game::run_main_menu_option ---------//
  289. //-------- Begin of static function disp_version --------//
  290. //
  291. void Game::disp_version()
  292. {
  293. //----------- display version string --------//
  294. String str;
  295. str = "Version ";
  296. str += GAME_VERSION_STR;
  297. #ifdef DEMO
  298. str = "Demo Version";
  299. #endif
  300. #ifdef BETA
  301. str = "This is a Beta version. Unauthorized distribution of this Beta is illegal.";
  302. #endif
  303. if( str.len() > 40 )
  304. font_news.center_put( 0, VGA_HEIGHT-20, VGA_WIDTH-1, VGA_HEIGHT-1, str );
  305. else
  306. font_news.right_put( VGA_WIDTH-10, VGA_HEIGHT-20, str );
  307. }
  308. //---------- End of function Game::disp_version ---------//
  309. //---------- Begin of function Game::single_player_menu ----------//
  310. //
  311. void Game::single_player_menu()
  312. {
  313. enum { SINGLE_PLAYER_OPTION_COUNT = 5 };
  314. #ifndef DISABLE_SINGLE_PLAYER_NEW_GAME
  315. static OptionInfo single_player_option_array[SINGLE_PLAYER_OPTION_COUNT] =
  316. {
  317. { 5+SWORD1_X, 10+SWORD1_Y, 282+SWORD1_X, 62+SWORD1_Y },
  318. { 5+SWORD1_X, 67+SWORD1_Y, 282+SWORD1_X, 112+SWORD1_Y },
  319. { 5+SWORD1_X, 120+SWORD1_Y, 282+SWORD1_X, 175+SWORD1_Y },
  320. { 5+SWORD1_X, 182+SWORD1_Y, 282+SWORD1_X, 223+SWORD1_Y },
  321. {40+SWORD1_X, 238+SWORD1_Y, 254+SWORD1_X, 280+SWORD1_Y },
  322. };
  323. static char single_player_option_flag[SINGLE_PLAYER_OPTION_COUNT] =
  324. {
  325. 1, 1, 1, 1, 1, // 1 = in use, 0 = darken, -1 = invisible
  326. };
  327. #else
  328. static OptionInfo single_player_option_array[SINGLE_PLAYER_OPTION_COUNT] =
  329. {
  330. { 2+SWORD1_X, 10+SWORD1_Y, 286+SWORD1_X, 65+SWORD1_Y },
  331. { 2+SWORD1_X, 67+SWORD1_Y, 286+SWORD1_X, 109+SWORD1_Y },
  332. { 2+SWORD1_X, 112+SWORD1_Y, 286+SWORD1_X, 171+SWORD1_Y },
  333. { 2+SWORD1_X, 112+SWORD1_Y, 286+SWORD1_X, 171+SWORD1_Y }, // not used
  334. {38+SWORD1_X, 174+SWORD1_Y, 256+SWORD1_X, 216+SWORD1_Y },
  335. };
  336. static char single_player_option_flag[SINGLE_PLAYER_OPTION_COUNT] =
  337. {
  338. 1, 1, 1, -1, 1, // 1 = in use, 0 = darken, -1 = invisible
  339. };
  340. #endif
  341. game_mode = GAME_SINGLE_PLAYER;
  342. //------ display the single player menu options ------//
  343. // image_interface.put_large( &vga_back, 247, 242, "M_SINGLE" );
  344. // vga.blt_buf(247, 242, 545, 567);
  345. // sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  346. int refreshFlag = 1, i;
  347. mouse_cursor.set_icon(CURSOR_NORMAL);
  348. char *menuBitmap = NULL;
  349. char *brightBitmap = NULL;
  350. char *darkBitmap = NULL;
  351. int pointingOption = -1;
  352. //---------- detect buttons -----------//
  353. while(1)
  354. {
  355. sys.yield();
  356. mouse.get_event();
  357. if( refreshFlag )
  358. {
  359. image_interface.put_to_buf( &vga_back, "M_MAIN" );
  360. vga.blt_buf(0,0,VGA_WIDTH-1, VGA_HEIGHT-1);
  361. if(!menuBitmap)
  362. {
  363. int resSize;
  364. File *resFile;
  365. #ifndef DISABLE_SINGLE_PLAYER_NEW_GAME
  366. resFile = image_interface.get_file("SWRD-2", resSize);
  367. #else
  368. resFile = image_interface.get_file("SWRD-4", resSize);
  369. #endif
  370. menuBitmap = mem_add(resSize);
  371. resFile->file_read(menuBitmap, resSize);
  372. }
  373. if(!brightBitmap)
  374. {
  375. int resSize;
  376. File *resFile;
  377. #ifndef DISABLE_SINGLE_PLAYER_NEW_GAME
  378. resFile = image_interface.get_file("SWRD-2B", resSize);
  379. #else
  380. resFile = image_interface.get_file("SWRD-4B", resSize);
  381. #endif
  382. brightBitmap = mem_add(resSize);
  383. resFile->file_read(brightBitmap, resSize);
  384. }
  385. if(!darkBitmap)
  386. {
  387. int resSize;
  388. File *resFile;
  389. #ifndef DISABLE_SINGLE_PLAYER_NEW_GAME
  390. resFile = image_interface.get_file("SWRD-2C", resSize);
  391. #else
  392. resFile = image_interface.get_file("SWRD-2C", resSize); // no SWRD-4C
  393. #endif
  394. darkBitmap = mem_add(resSize);
  395. resFile->file_read(darkBitmap, resSize);
  396. }
  397. for( i = 0; i < SINGLE_PLAYER_OPTION_COUNT; ++i )
  398. {
  399. if( single_player_option_flag[i] >= 0)
  400. {
  401. mouse.hide_area(single_player_option_array[i].x1, single_player_option_array[i].y1,
  402. single_player_option_array[i].x2, single_player_option_array[i].y2);
  403. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y,
  404. single_player_option_flag[i] ? menuBitmap : darkBitmap,
  405. single_player_option_array[i].x1 - SWORD1_X, single_player_option_array[i].y1 - SWORD1_Y,
  406. single_player_option_array[i].x2 - SWORD1_X, single_player_option_array[i].y2 - SWORD1_Y);
  407. mouse.show_area();
  408. }
  409. }
  410. pointingOption = -1;
  411. refreshFlag=0;
  412. }
  413. // ###### begin Gilbert 18/9 ########//
  414. if( config.music_flag )
  415. {
  416. if( !music.is_playing(1) )
  417. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  418. }
  419. else
  420. music.stop();
  421. // ###### end Gilbert 18/9 ########//
  422. // display main menu
  423. int newPointingOption = -1;
  424. for(i = 0; i < SINGLE_PLAYER_OPTION_COUNT; ++i)
  425. {
  426. if( single_player_option_flag[i] > 0 &&
  427. mouse.in_area(single_player_option_array[i].x1, single_player_option_array[i].y1,
  428. single_player_option_array[i].x2, single_player_option_array[i].y2) )
  429. {
  430. newPointingOption = i;
  431. break;
  432. }
  433. }
  434. if( pointingOption != newPointingOption)
  435. {
  436. err_when( !menuBitmap );
  437. err_when( !brightBitmap );
  438. err_when( !darkBitmap );
  439. // put un-highlighted option back
  440. i = pointingOption;
  441. if( i >= 0 && i < SINGLE_PLAYER_OPTION_COUNT )
  442. {
  443. mouse.hide_area(single_player_option_array[i].x1, single_player_option_array[i].y1,
  444. single_player_option_array[i].x2, single_player_option_array[i].y2);
  445. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, menuBitmap,
  446. single_player_option_array[i].x1 - SWORD1_X, single_player_option_array[i].y1 - SWORD1_Y,
  447. single_player_option_array[i].x2 - SWORD1_X, single_player_option_array[i].y2 - SWORD1_Y);
  448. mouse.show_area();
  449. }
  450. // put new hightlighted option
  451. i = newPointingOption;
  452. if( i >= 0 && i < SINGLE_PLAYER_OPTION_COUNT )
  453. {
  454. mouse.hide_area(single_player_option_array[i].x1,single_player_option_array[i].y1,
  455. single_player_option_array[i].x2,single_player_option_array[i].y2);
  456. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, brightBitmap,
  457. single_player_option_array[i].x1 -SWORD1_X,single_player_option_array[i].y1 -SWORD1_Y,
  458. single_player_option_array[i].x2 -SWORD1_X,single_player_option_array[i].y2 -SWORD1_Y);
  459. mouse.show_area();
  460. }
  461. pointingOption = newPointingOption;
  462. }
  463. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  464. OptionInfo* optionInfo = single_player_option_array;
  465. for( int i=0 ; i<SINGLE_PLAYER_OPTION_COUNT ; i++, optionInfo++ )
  466. {
  467. if( single_player_option_flag[i] > 0 &&
  468. mouse.single_click( optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2 ) )
  469. {
  470. // free some resource
  471. if( menuBitmap )
  472. {
  473. mem_del(menuBitmap);
  474. menuBitmap = NULL;
  475. }
  476. if( brightBitmap )
  477. {
  478. mem_del(brightBitmap);
  479. brightBitmap = NULL;
  480. }
  481. if( darkBitmap )
  482. {
  483. mem_del(darkBitmap);
  484. darkBitmap = NULL;
  485. }
  486. refreshFlag = 1;
  487. switch(i+1)
  488. {
  489. case 1:
  490. tutor.select_run_tutor(0); // select and run tutorial, 0-called from the main menu, not from in-game
  491. break;
  492. case 2:
  493. #ifndef DEMO
  494. single_player_game(0);
  495. #else
  496. select_run_scenario();
  497. #endif
  498. break;
  499. case 3:
  500. game_file_array.init("*.SAV");
  501. if( game_file_array.menu(2) == 1)
  502. {
  503. battle.run_loaded();
  504. deinit();
  505. }
  506. {
  507. char signalExitFlagBackup = sys.signal_exit_flag;
  508. sys.signal_exit_flag = 2;
  509. game.deinit(); // game.deinit() is needed if game_file_array.menu fails
  510. sys.signal_exit_flag = signalExitFlagBackup;
  511. }
  512. break;
  513. case 4:
  514. select_run_scenario();
  515. break;
  516. }
  517. return;
  518. }
  519. }
  520. }
  521. if( menuBitmap )
  522. mem_del(menuBitmap);
  523. if( brightBitmap )
  524. mem_del(brightBitmap);
  525. if( darkBitmap )
  526. mem_del(darkBitmap);
  527. }
  528. //------------ End of function Game::single_player_menu -----------//
  529. //-------- Begin of function Game::test_game --------//
  530. //
  531. // <int> noAI - if there should be no AI in the game.
  532. //
  533. void Game::test_game()
  534. {
  535. init();
  536. battle.run_test();
  537. deinit();
  538. }
  539. //--------- End of function Game::test_game ---------//
  540. #ifndef DISABLE_MULTI_PLAYER
  541. //---------- Begin of function Game::multi_player_menu ----------//
  542. //
  543. // ####### begin Gilbert 13/2 ########//
  544. void Game::multi_player_menu(char *cmdLine)
  545. // ####### end Gilbert 13/2 ########//
  546. {
  547. enum { MULTI_PLAYER_OPTION_COUNT = 5 };
  548. static OptionInfo multi_player_option_array[MULTI_PLAYER_OPTION_COUNT] =
  549. {
  550. { 5+SWORD1_X, 10+SWORD1_Y, 282+SWORD1_X, 62+SWORD1_Y },
  551. { 5+SWORD1_X, 67+SWORD1_Y, 282+SWORD1_X, 112+SWORD1_Y },
  552. { 5+SWORD1_X, 120+SWORD1_Y, 282+SWORD1_X, 175+SWORD1_Y },
  553. { 5+SWORD1_X, 182+SWORD1_Y, 282+SWORD1_X, 223+SWORD1_Y },
  554. {40+SWORD1_X, 238+SWORD1_Y, 254+SWORD1_X, 280+SWORD1_Y },
  555. };
  556. static char multi_player_option_flag[MULTI_PLAYER_OPTION_COUNT] =
  557. {
  558. -1, 1, 1, -1, 1,
  559. };
  560. game_mode = GAME_MULTI_PLAYER;
  561. //------ display the multi player menu options ------//
  562. int refreshFlag = 1, i;
  563. mouse_cursor.set_icon(CURSOR_NORMAL);
  564. char *menuBitmap = NULL;
  565. char *brightBitmap = NULL;
  566. char *darkBitmap = NULL;
  567. int pointingOption = -1;
  568. //---------- detect buttons -----------//
  569. while(1)
  570. {
  571. sys.yield();
  572. mouse.get_event();
  573. if( refreshFlag )
  574. {
  575. image_interface.put_to_buf( &vga_back, "M_MAIN" );
  576. vga.blt_buf(0,0,VGA_WIDTH-1, VGA_HEIGHT-1);
  577. if(!menuBitmap)
  578. {
  579. int resSize;
  580. File *resFile;
  581. resFile = image_interface.get_file("SWRD-2", resSize);
  582. menuBitmap = mem_add(resSize);
  583. resFile->file_read(menuBitmap, resSize);
  584. }
  585. if(!brightBitmap)
  586. {
  587. int resSize;
  588. File *resFile;
  589. resFile = image_interface.get_file("SWRD-2B", resSize);
  590. brightBitmap = mem_add(resSize);
  591. resFile->file_read(brightBitmap, resSize);
  592. }
  593. if(!darkBitmap)
  594. {
  595. int resSize;
  596. File *resFile;
  597. resFile = image_interface.get_file("SWRD-2C", resSize);
  598. darkBitmap = mem_add(resSize);
  599. resFile->file_read(darkBitmap, resSize);
  600. }
  601. for( i = 0; i < MULTI_PLAYER_OPTION_COUNT; ++i )
  602. {
  603. if( multi_player_option_flag[i] >= 0 )
  604. {
  605. mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
  606. multi_player_option_array[i].x2, multi_player_option_array[i].y2);
  607. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y,
  608. multi_player_option_flag[i] ? menuBitmap : darkBitmap,
  609. multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
  610. multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
  611. mouse.show_area();
  612. }
  613. }
  614. pointingOption = -1;
  615. refreshFlag=0;
  616. }
  617. // ###### begin Gilbert 18/9 ########//
  618. if( config.music_flag )
  619. {
  620. if( !music.is_playing(1) )
  621. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  622. }
  623. else
  624. music.stop();
  625. // ###### end Gilbert 18/9 ########//
  626. // display main menu
  627. int newPointingOption = -1;
  628. for(i = 0; i < MULTI_PLAYER_OPTION_COUNT; ++i)
  629. {
  630. if( multi_player_option_flag[i] > 0 &&
  631. mouse.in_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
  632. multi_player_option_array[i].x2, multi_player_option_array[i].y2) )
  633. {
  634. newPointingOption = i;
  635. break;
  636. }
  637. }
  638. if( pointingOption != newPointingOption)
  639. {
  640. err_when( !menuBitmap );
  641. err_when( !brightBitmap );
  642. err_when( !darkBitmap );
  643. // put un-highlighted option back
  644. i = pointingOption;
  645. if( i >= 0 && i < MULTI_PLAYER_OPTION_COUNT )
  646. {
  647. mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
  648. multi_player_option_array[i].x2, multi_player_option_array[i].y2);
  649. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, menuBitmap,
  650. multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
  651. multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
  652. mouse.show_area();
  653. }
  654. // put new hightlighted option
  655. i = newPointingOption;
  656. if( i >= 0 && i < MULTI_PLAYER_OPTION_COUNT )
  657. {
  658. mouse.hide_area(multi_player_option_array[i].x1, multi_player_option_array[i].y1,
  659. multi_player_option_array[i].x2, multi_player_option_array[i].y2);
  660. vga_front.put_bitmap_area(SWORD1_X, SWORD1_Y, brightBitmap,
  661. multi_player_option_array[i].x1 - SWORD1_X, multi_player_option_array[i].y1 - SWORD1_Y,
  662. multi_player_option_array[i].x2 - SWORD1_X, multi_player_option_array[i].y2 - SWORD1_Y);
  663. mouse.show_area();
  664. }
  665. pointingOption = newPointingOption;
  666. }
  667. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  668. OptionInfo* optionInfo = multi_player_option_array;
  669. for( int i=0 ; i<MULTI_PLAYER_OPTION_COUNT ; i++, optionInfo++ )
  670. {
  671. if( multi_player_option_flag[i] > 0 &&
  672. mouse.single_click( optionInfo->x1, optionInfo->y1, optionInfo->x2, optionInfo->y2 ) )
  673. {
  674. // free some resource
  675. if( menuBitmap )
  676. {
  677. mem_del(menuBitmap);
  678. menuBitmap = NULL;
  679. }
  680. if( brightBitmap )
  681. {
  682. mem_del(brightBitmap);
  683. brightBitmap = NULL;
  684. }
  685. if( darkBitmap )
  686. {
  687. mem_del(darkBitmap);
  688. darkBitmap = NULL;
  689. }
  690. refreshFlag = 1;
  691. switch(i+1)
  692. {
  693. case 2:
  694. // ####### begin Gilbert 13/2 #######//
  695. multi_player_game(cmdLine);
  696. // ####### end Gilbert 13/2 #######//
  697. break;
  698. case 3:
  699. // ##### begin Gilbert 26/8 ######//
  700. {
  701. int loadedRecno = 0;
  702. game_file_array.init("*.SVM");
  703. if( game_file_array.menu(2, &loadedRecno) == 1 )
  704. {
  705. err_when( !loadedRecno );
  706. // ####### begin Gilbert 13/2 #######//
  707. load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
  708. // ####### begin Gilbert 13/2 #######//
  709. }
  710. {
  711. char signalExitFlagBackup = sys.signal_exit_flag;
  712. sys.signal_exit_flag = 2;
  713. game.deinit(); // game.deinit() is needed if game_file_array.menu fails
  714. sys.signal_exit_flag = signalExitFlagBackup;
  715. }
  716. // ##### end Gilbert 26/8 ######//
  717. }
  718. break;
  719. case 5:
  720. break;
  721. }
  722. return;
  723. }
  724. }
  725. }
  726. if( menuBitmap )
  727. mem_del(menuBitmap);
  728. if( brightBitmap )
  729. mem_del(brightBitmap);
  730. if( darkBitmap )
  731. mem_del(darkBitmap);
  732. }
  733. //------------ End of function Game::multi_player_menu -----------//
  734. #endif