uigame.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. //
  5. // This file is part of SDLPAL.
  6. //
  7. // SDLPAL is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. #include "main.h"
  21. VOID
  22. PAL_DrawOpeningMenuBackground(
  23. VOID
  24. )
  25. /*++
  26. Purpose:
  27. Draw the background of the main menu.
  28. Parameters:
  29. None.
  30. Return value:
  31. None.
  32. --*/
  33. {
  34. LPBYTE buf;
  35. buf = (LPBYTE)malloc(320 * 200);
  36. if (buf == NULL)
  37. {
  38. return;
  39. }
  40. //
  41. // Read the picture from fbp.mkf.
  42. //
  43. PAL_MKFDecompressChunk(buf, 320 * 200, MAINMENU_BACKGROUND_FBPNUM, gpGlobals->f.fpFBP);
  44. //
  45. // ...and blit it to the screen buffer.
  46. //
  47. PAL_FBPBlitToSurface(buf, gpScreen);
  48. VIDEO_UpdateScreen(NULL);
  49. free(buf);
  50. }
  51. INT
  52. PAL_OpeningMenu(
  53. VOID
  54. )
  55. /*++
  56. Purpose:
  57. Show the opening menu.
  58. Parameters:
  59. None.
  60. Return value:
  61. Which saved slot to load from (1-5). 0 to start a new game.
  62. --*/
  63. {
  64. WORD wItemSelected;
  65. WORD wDefaultItem = 0;
  66. MENUITEM rgMainMenuItem[2] = {
  67. // value label enabled position
  68. { 0, MAINMENU_LABEL_NEWGAME, TRUE, PAL_XY(125, 95) },
  69. { 1, MAINMENU_LABEL_LOADGAME, TRUE, PAL_XY(125, 112) }
  70. };
  71. //
  72. // Play the background music
  73. //
  74. PAL_PlayMUS(RIX_NUM_OPENINGMENU, TRUE, 1);
  75. //
  76. // Draw the background
  77. //
  78. PAL_DrawOpeningMenuBackground();
  79. PAL_FadeIn(0, FALSE, 1);
  80. while (TRUE)
  81. {
  82. //
  83. // Activate the menu
  84. //
  85. wItemSelected = PAL_ReadMenu(NULL, rgMainMenuItem, 2, wDefaultItem, MENUITEM_COLOR);
  86. if (wItemSelected == 0 || wItemSelected == MENUITEM_VALUE_CANCELLED)
  87. {
  88. //
  89. // Start a new game
  90. //
  91. wItemSelected = 0;
  92. break;
  93. }
  94. else
  95. {
  96. //
  97. // Load game
  98. //
  99. wItemSelected = PAL_SaveSlotMenu(1);
  100. if (wItemSelected != MENUITEM_VALUE_CANCELLED)
  101. {
  102. break;
  103. }
  104. wDefaultItem = 1;
  105. }
  106. }
  107. //
  108. // Fade out the screen and the music
  109. //
  110. PAL_PlayMUS(0, FALSE, 1);
  111. PAL_FadeOut(1);
  112. return (INT)wItemSelected;
  113. }
  114. INT
  115. PAL_SaveSlotMenu(
  116. WORD wDefaultSlot
  117. )
  118. /*++
  119. Purpose:
  120. Show the load game menu.
  121. Parameters:
  122. [IN] wDefaultSlot - default save slot number (1-5).
  123. Return value:
  124. Which saved slot to load from (1-5). MENUITEM_VALUE_CANCELLED if cancelled.
  125. --*/
  126. {
  127. LPBOX rgpBox[5];
  128. int i;
  129. FILE *fp;
  130. WORD wItemSelected;
  131. WORD wSavedTimes;
  132. MENUITEM rgMenuItem[5];
  133. const SDL_Rect rect = {195, 7, 120, 190};
  134. //
  135. // Create the boxes and create the menu items
  136. //
  137. for (i = 0; i < 5; i++)
  138. {
  139. rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(195, 7 + 38 * i), 6, TRUE);
  140. rgMenuItem[i].wValue = i + 1;
  141. rgMenuItem[i].fEnabled = TRUE;
  142. rgMenuItem[i].wNumWord = LOADMENU_LABEL_SLOT_FIRST + i;
  143. rgMenuItem[i].pos = PAL_XY(210, 17 + 38 * i);
  144. }
  145. //
  146. // Draw the numbers of saved times
  147. //
  148. for (i = 1; i <= 5; i++)
  149. {
  150. fp = fopen(va("%s%d%s", PAL_SAVE_PREFIX, i, ".rpg"), "rb");
  151. if (fp == NULL)
  152. {
  153. wSavedTimes = 0;
  154. }
  155. else
  156. {
  157. fread(&wSavedTimes, sizeof(WORD), 1, fp);
  158. wSavedTimes = SWAP16(wSavedTimes);
  159. fclose(fp);
  160. }
  161. //
  162. // Draw the number
  163. //
  164. PAL_DrawNumber((UINT)wSavedTimes, 4, PAL_XY(270, 38 * i - 17),
  165. kNumColorYellow, kNumAlignRight);
  166. }
  167. VIDEO_UpdateScreen(&rect);
  168. //
  169. // Activate the menu
  170. //
  171. wItemSelected = PAL_ReadMenu(NULL, rgMenuItem, 5, wDefaultSlot - 1, MENUITEM_COLOR);
  172. //
  173. // Delete the boxes
  174. //
  175. for (i = 0; i < 5; i++)
  176. {
  177. PAL_DeleteBox(rgpBox[i]);
  178. }
  179. VIDEO_UpdateScreen(&rect);
  180. return wItemSelected;
  181. }
  182. BOOL
  183. PAL_ConfirmMenu(
  184. VOID
  185. )
  186. /*++
  187. Purpose:
  188. Show a "Yes or No?" confirm box.
  189. Parameters:
  190. None.
  191. Return value:
  192. TRUE if user selected Yes, FALSE if selected No.
  193. --*/
  194. {
  195. LPBOX rgpBox[2];
  196. MENUITEM rgMenuItem[2];
  197. int i;
  198. WORD wReturnValue;
  199. const SDL_Rect rect = {130, 100, 125, 50};
  200. //
  201. // Create menu items
  202. //
  203. rgMenuItem[0].fEnabled = TRUE;
  204. rgMenuItem[0].pos = PAL_XY(145, 110);
  205. rgMenuItem[0].wValue = 0;
  206. rgMenuItem[0].wNumWord = CONFIRMMENU_LABEL_NO;
  207. rgMenuItem[1].fEnabled = TRUE;
  208. rgMenuItem[1].pos = PAL_XY(220, 110);
  209. rgMenuItem[1].wValue = 1;
  210. rgMenuItem[1].wNumWord = CONFIRMMENU_LABEL_YES;
  211. //
  212. // Create the boxes
  213. //
  214. for (i = 0; i < 2; i++)
  215. {
  216. rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(130 + 75 * i, 100), 2, TRUE);
  217. }
  218. VIDEO_UpdateScreen(&rect);
  219. //
  220. // Activate the menu
  221. //
  222. wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, 2, 0, MENUITEM_COLOR);
  223. //
  224. // Delete the boxes
  225. //
  226. for (i = 0; i < 2; i++)
  227. {
  228. PAL_DeleteBox(rgpBox[i]);
  229. }
  230. VIDEO_UpdateScreen(&rect);
  231. return (wReturnValue == MENUITEM_VALUE_CANCELLED || wReturnValue == 0) ? FALSE : TRUE;
  232. }
  233. BOOL
  234. PAL_SwitchMenu(
  235. BOOL fEnabled
  236. )
  237. /*++
  238. Purpose:
  239. Show a "Enable/Disable" selection box.
  240. Parameters:
  241. [IN] fEnabled - whether the option is originally enabled or not.
  242. Return value:
  243. TRUE if user selected "Enable", FALSE if selected "Disable".
  244. --*/
  245. {
  246. LPBOX rgpBox[2];
  247. MENUITEM rgMenuItem[2];
  248. int i;
  249. WORD wReturnValue;
  250. const SDL_Rect rect = {130, 100, 125, 50};
  251. //
  252. // Create menu items
  253. //
  254. rgMenuItem[0].fEnabled = TRUE;
  255. rgMenuItem[0].pos = PAL_XY(145, 110);
  256. rgMenuItem[0].wValue = 0;
  257. rgMenuItem[0].wNumWord = SWITCHMENU_LABEL_DISABLE;
  258. rgMenuItem[1].fEnabled = TRUE;
  259. rgMenuItem[1].pos = PAL_XY(220, 110);
  260. rgMenuItem[1].wValue = 1;
  261. rgMenuItem[1].wNumWord = SWITCHMENU_LABEL_ENABLE;
  262. //
  263. // Create the boxes
  264. //
  265. for (i = 0; i < 2; i++)
  266. {
  267. rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(130 + 75 * i, 100), 2, TRUE);
  268. }
  269. VIDEO_UpdateScreen(&rect);
  270. //
  271. // Activate the menu
  272. //
  273. wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, 2, fEnabled ? 1 : 0, MENUITEM_COLOR);
  274. //
  275. // Delete the boxes
  276. //
  277. for (i = 0; i < 2; i++)
  278. {
  279. PAL_DeleteBox(rgpBox[i]);
  280. }
  281. VIDEO_UpdateScreen(&rect);
  282. if (wReturnValue == MENUITEM_VALUE_CANCELLED)
  283. {
  284. return fEnabled;
  285. }
  286. return (wReturnValue == 0) ? FALSE : TRUE;
  287. }
  288. #ifndef PAL_CLASSIC
  289. static VOID
  290. PAL_BattleSpeedMenu(
  291. VOID
  292. )
  293. /*++
  294. Purpose:
  295. Show the Battle Speed selection box.
  296. Parameters:
  297. None.
  298. Return value:
  299. None.
  300. --*/
  301. {
  302. LPBOX lpBox;
  303. WORD wReturnValue;
  304. const SDL_Rect rect = {131, 100, 165, 50};
  305. MENUITEM rgMenuItem[5] = {
  306. { 1, BATTLESPEEDMENU_LABEL_1, TRUE, PAL_XY(145, 110) },
  307. { 2, BATTLESPEEDMENU_LABEL_2, TRUE, PAL_XY(170, 110) },
  308. { 3, BATTLESPEEDMENU_LABEL_3, TRUE, PAL_XY(195, 110) },
  309. { 4, BATTLESPEEDMENU_LABEL_4, TRUE, PAL_XY(220, 110) },
  310. { 5, BATTLESPEEDMENU_LABEL_5, TRUE, PAL_XY(245, 110) },
  311. };
  312. //
  313. // Create the boxes
  314. //
  315. lpBox = PAL_CreateSingleLineBox(PAL_XY(131, 100), 8, TRUE);
  316. VIDEO_UpdateScreen(&rect);
  317. //
  318. // Activate the menu
  319. //
  320. wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, 5, gpGlobals->bBattleSpeed - 1,
  321. MENUITEM_COLOR);
  322. //
  323. // Delete the boxes
  324. //
  325. PAL_DeleteBox(lpBox);
  326. VIDEO_UpdateScreen(&rect);
  327. if (wReturnValue != MENUITEM_VALUE_CANCELLED)
  328. {
  329. gpGlobals->bBattleSpeed = wReturnValue;
  330. }
  331. }
  332. #endif
  333. LPBOX
  334. PAL_ShowCash(
  335. DWORD dwCash
  336. )
  337. /*++
  338. Purpose:
  339. Show the cash amount at the top left corner of the screen.
  340. Parameters:
  341. [IN] dwCash - amount of cash.
  342. Return value:
  343. pointer to the saved screen part.
  344. --*/
  345. {
  346. LPBOX lpBox;
  347. //
  348. // Create the box.
  349. //
  350. lpBox = PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, TRUE);
  351. if (lpBox == NULL)
  352. {
  353. return NULL;
  354. }
  355. //
  356. // Draw the text label.
  357. //
  358. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(10, 10), 0, FALSE, FALSE);
  359. //
  360. // Draw the cash amount.
  361. //
  362. PAL_DrawNumber(dwCash, 6, PAL_XY(49, 14), kNumColorYellow, kNumAlignRight);
  363. return lpBox;
  364. }
  365. static VOID
  366. PAL_SystemMenu_OnItemChange(
  367. WORD wCurrentItem
  368. )
  369. /*++
  370. Purpose:
  371. Callback function when user selected another item in the system menu.
  372. Parameters:
  373. [IN] wCurrentItem - current selected item.
  374. Return value:
  375. None.
  376. --*/
  377. {
  378. gpGlobals->iCurSystemMenuItem = wCurrentItem - 1;
  379. }
  380. static BOOL
  381. PAL_SystemMenu(
  382. VOID
  383. )
  384. /*++
  385. Purpose:
  386. Show the system menu.
  387. Parameters:
  388. None.
  389. Return value:
  390. TRUE if user made some operations in the menu, FALSE if user cancelled.
  391. --*/
  392. {
  393. LPBOX lpMenuBox;
  394. WORD wReturnValue;
  395. int iSlot, i, iSavedTimes;
  396. FILE *fp;
  397. const SDL_Rect rect = {40, 60, 100, 135};
  398. //
  399. // Create menu items
  400. //
  401. #ifdef PAL_CLASSIC
  402. MENUITEM rgSystemMenuItem[5] =
  403. {
  404. // value label enabled pos
  405. { 1, SYSMENU_LABEL_SAVE, TRUE, PAL_XY(53, 72) },
  406. { 2, SYSMENU_LABEL_LOAD, TRUE, PAL_XY(53, 72 + 18) },
  407. { 3, SYSMENU_LABEL_MUSIC, TRUE, PAL_XY(53, 72 + 36) },
  408. { 4, SYSMENU_LABEL_SOUND, TRUE, PAL_XY(53, 72 + 54) },
  409. { 5, SYSMENU_LABEL_QUIT, TRUE, PAL_XY(53, 72 + 72) },
  410. };
  411. #else
  412. MENUITEM rgSystemMenuItem[6] =
  413. {
  414. // value label enabled pos
  415. { 1, SYSMENU_LABEL_SAVE, TRUE, PAL_XY(53, 72) },
  416. { 2, SYSMENU_LABEL_LOAD, TRUE, PAL_XY(53, 72 + 18) },
  417. { 3, SYSMENU_LABEL_MUSIC, TRUE, PAL_XY(53, 72 + 36) },
  418. { 4, SYSMENU_LABEL_SOUND, TRUE, PAL_XY(53, 72 + 54) },
  419. { 5, SYSMENU_LABEL_BATTLEMODE, TRUE, PAL_XY(53, 72 + 72) },
  420. { 6, SYSMENU_LABEL_QUIT, TRUE, PAL_XY(53, 72 + 90) },
  421. };
  422. #endif
  423. //
  424. // Create the menu box.
  425. //
  426. #ifdef PAL_CLASSIC
  427. lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), 4, 3, 0, TRUE);
  428. #else
  429. lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), 5, 3, 0, TRUE);
  430. #endif
  431. VIDEO_UpdateScreen(&rect);
  432. //
  433. // Perform the menu.
  434. //
  435. #ifdef PAL_CLASSIC
  436. wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, 5,
  437. gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
  438. #else
  439. wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, 6,
  440. gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
  441. #endif
  442. if (wReturnValue == MENUITEM_VALUE_CANCELLED)
  443. {
  444. //
  445. // User cancelled the menu
  446. //
  447. PAL_DeleteBox(lpMenuBox);
  448. VIDEO_UpdateScreen(&rect);
  449. return FALSE;
  450. }
  451. switch (wReturnValue)
  452. {
  453. case 1:
  454. //
  455. // Save game
  456. //
  457. iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
  458. if (iSlot != MENUITEM_VALUE_CANCELLED)
  459. {
  460. gpGlobals->bCurrentSaveSlot = (BYTE)iSlot;
  461. iSavedTimes = 0;
  462. for (i = 1; i <= 5; i++)
  463. {
  464. fp = fopen(va("%s%d%s", PAL_SAVE_PREFIX, i, ".rpg"), "rb");
  465. if (fp != NULL)
  466. {
  467. WORD wSavedTimes;
  468. fread(&wSavedTimes, sizeof(WORD), 1, fp);
  469. fclose(fp);
  470. wSavedTimes = SWAP16(wSavedTimes);
  471. if ((int)wSavedTimes > iSavedTimes)
  472. {
  473. iSavedTimes = wSavedTimes;
  474. }
  475. }
  476. }
  477. PAL_SaveGame(va("%s%d%s", PAL_SAVE_PREFIX, iSlot, ".rpg"), iSavedTimes + 1);
  478. }
  479. break;
  480. case 2:
  481. //
  482. // Load game
  483. //
  484. iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
  485. if (iSlot != MENUITEM_VALUE_CANCELLED)
  486. {
  487. PAL_PlayMUS(0, FALSE, 1);
  488. PAL_FadeOut(1);
  489. PAL_InitGameData(iSlot);
  490. }
  491. break;
  492. case 3:
  493. //
  494. // Music
  495. //
  496. g_fNoMusic = !PAL_SwitchMenu(!g_fNoMusic);
  497. #ifdef PAL_HAS_NATIVEMIDI
  498. if (g_fUseMidi)
  499. {
  500. if (g_fNoMusic)
  501. {
  502. PAL_PlayMUS(0, FALSE, 0);
  503. }
  504. else
  505. {
  506. PAL_PlayMUS(gpGlobals->wNumMusic, TRUE, 0);
  507. }
  508. }
  509. #endif
  510. break;
  511. case 4:
  512. //
  513. // Sound
  514. //
  515. g_fNoSound = !PAL_SwitchMenu(!g_fNoSound);
  516. break;
  517. #ifndef PAL_CLASSIC
  518. case 5:
  519. //
  520. // Battle Mode
  521. //
  522. PAL_BattleSpeedMenu();
  523. break;
  524. case 6:
  525. #else
  526. case 5:
  527. #endif
  528. //
  529. // Quit
  530. //
  531. if (PAL_ConfirmMenu())
  532. {
  533. PAL_PlayMUS(0, FALSE, 2);
  534. PAL_FadeOut(2);
  535. PAL_Shutdown();
  536. exit(0);
  537. }
  538. break;
  539. }
  540. PAL_DeleteBox(lpMenuBox);
  541. return TRUE;
  542. }
  543. VOID
  544. PAL_InGameMagicMenu(
  545. VOID
  546. )
  547. /*++
  548. Purpose:
  549. Show the magic menu.
  550. Parameters:
  551. None.
  552. Return value:
  553. None.
  554. --*/
  555. {
  556. MENUITEM rgMenuItem[MAX_PLAYERS_IN_PARTY];
  557. int i, y;
  558. static WORD w;
  559. WORD wMagic;
  560. const SDL_Rect rect = {35, 62, 95, 90};
  561. //
  562. // Draw the player info boxes
  563. //
  564. y = 45;
  565. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  566. {
  567. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  568. TIMEMETER_COLOR_DEFAULT, TRUE);
  569. y += 78;
  570. }
  571. y = 75;
  572. //
  573. // Generate one menu items for each player in the party
  574. //
  575. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  576. {
  577. assert(i <= MAX_PLAYERS_IN_PARTY);
  578. rgMenuItem[i].wValue = i;
  579. rgMenuItem[i].wNumWord =
  580. gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole];
  581. rgMenuItem[i].fEnabled =
  582. (gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] > 0);
  583. rgMenuItem[i].pos = PAL_XY(48, y);
  584. y += 18;
  585. }
  586. //
  587. // Draw the box
  588. //
  589. PAL_CreateBox(PAL_XY(35, 62), gpGlobals->wMaxPartyMemberIndex, 2, 0, FALSE);
  590. VIDEO_UpdateScreen(&rect);
  591. w = PAL_ReadMenu(NULL, rgMenuItem, gpGlobals->wMaxPartyMemberIndex + 1, w, MENUITEM_COLOR);
  592. if (w == MENUITEM_VALUE_CANCELLED)
  593. {
  594. return;
  595. }
  596. wMagic = 0;
  597. while (TRUE)
  598. {
  599. wMagic = PAL_MagicSelectionMenu(gpGlobals->rgParty[w].wPlayerRole, FALSE, wMagic);
  600. if (wMagic == 0)
  601. {
  602. break;
  603. }
  604. if (gpGlobals->g.rgObject[wMagic].magic.wFlags & kMagicFlagApplyToAll)
  605. {
  606. gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
  607. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse, 0);
  608. if (g_fScriptSuccess)
  609. {
  610. gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
  611. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess, 0);
  612. gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
  613. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
  614. }
  615. if (gpGlobals->fNeedToFadeIn)
  616. {
  617. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  618. gpGlobals->fNeedToFadeIn = FALSE;
  619. }
  620. }
  621. else
  622. {
  623. //
  624. // Need to select which player to use the magic on.
  625. //
  626. WORD wPlayer = 0;
  627. SDL_Rect rect;
  628. while (wPlayer != MENUITEM_VALUE_CANCELLED)
  629. {
  630. //
  631. // Redraw the player info boxes first
  632. //
  633. y = 45;
  634. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  635. {
  636. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  637. TIMEMETER_COLOR_DEFAULT, TRUE);
  638. y += 78;
  639. }
  640. //
  641. // Draw the cursor on the selected item
  642. //
  643. rect.x = 70 + 78 * wPlayer;
  644. rect.y = 193;
  645. rect.w = 9;
  646. rect.h = 6;
  647. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
  648. gpScreen, PAL_XY(rect.x, rect.y));
  649. VIDEO_UpdateScreen(&rect);
  650. while (TRUE)
  651. {
  652. PAL_ClearKeyState();
  653. PAL_ProcessEvent();
  654. if (g_InputState.dwKeyPress & kKeyMenu)
  655. {
  656. wPlayer = MENUITEM_VALUE_CANCELLED;
  657. break;
  658. }
  659. else if (g_InputState.dwKeyPress & kKeySearch)
  660. {
  661. gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
  662. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse,
  663. gpGlobals->rgParty[wPlayer].wPlayerRole);
  664. if (g_fScriptSuccess)
  665. {
  666. gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
  667. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess,
  668. gpGlobals->rgParty[wPlayer].wPlayerRole);
  669. if (g_fScriptSuccess)
  670. {
  671. gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
  672. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
  673. //
  674. // Check if we have run out of MP
  675. //
  676. if (gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] <
  677. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP)
  678. {
  679. //
  680. // Don't go further if run out of MP
  681. //
  682. wPlayer = MENUITEM_VALUE_CANCELLED;
  683. }
  684. }
  685. }
  686. break;
  687. }
  688. else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyUp))
  689. {
  690. if (wPlayer > 0)
  691. {
  692. wPlayer--;
  693. break;
  694. }
  695. }
  696. else if (g_InputState.dwKeyPress & (kKeyRight | kKeyDown))
  697. {
  698. if (wPlayer < gpGlobals->wMaxPartyMemberIndex)
  699. {
  700. wPlayer++;
  701. break;
  702. }
  703. }
  704. SDL_Delay(1);
  705. }
  706. }
  707. }
  708. //
  709. // Redraw the player info boxes
  710. //
  711. y = 45;
  712. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  713. {
  714. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  715. TIMEMETER_COLOR_DEFAULT, TRUE);
  716. y += 78;
  717. }
  718. }
  719. }
  720. static VOID
  721. PAL_InventoryMenu(
  722. VOID
  723. )
  724. /*++
  725. Purpose:
  726. Show the inventory menu.
  727. Parameters:
  728. None.
  729. Return value:
  730. None.
  731. --*/
  732. {
  733. static WORD w = 0;
  734. const SDL_Rect rect = {30, 60, 75, 60};
  735. MENUITEM rgMenuItem[2] =
  736. {
  737. // value label enabled pos
  738. { 1, INVMENU_LABEL_USE, TRUE, PAL_XY(43, 73) },
  739. { 2, INVMENU_LABEL_EQUIP, TRUE, PAL_XY(43, 73 + 18) },
  740. };
  741. PAL_CreateBox(PAL_XY(30, 60), 1, 1, 0, FALSE);
  742. VIDEO_UpdateScreen(&rect);
  743. w = PAL_ReadMenu(NULL, rgMenuItem, 2, w - 1, MENUITEM_COLOR);
  744. switch (w)
  745. {
  746. case 1:
  747. PAL_GameUseItem();
  748. break;
  749. case 2:
  750. PAL_GameEquipItem();
  751. break;
  752. }
  753. }
  754. static VOID
  755. PAL_InGameMenu_OnItemChange(
  756. WORD wCurrentItem
  757. )
  758. /*++
  759. Purpose:
  760. Callback function when user selected another item in the in-game menu.
  761. Parameters:
  762. [IN] wCurrentItem - current selected item.
  763. Return value:
  764. None.
  765. --*/
  766. {
  767. gpGlobals->iCurMainMenuItem = wCurrentItem - 1;
  768. }
  769. VOID
  770. PAL_InGameMenu(
  771. VOID
  772. )
  773. /*++
  774. Purpose:
  775. Show the in-game main menu.
  776. Parameters:
  777. None.
  778. Return value:
  779. None.
  780. --*/
  781. {
  782. LPBOX lpCashBox, lpMenuBox;
  783. WORD wReturnValue;
  784. const SDL_Rect rect = {0, 0, 150, 185};
  785. //
  786. // Create menu items
  787. //
  788. MENUITEM rgMainMenuItem[4] =
  789. {
  790. // value label enabled pos
  791. { 1, GAMEMENU_LABEL_STATUS, TRUE, PAL_XY(16, 50) },
  792. { 2, GAMEMENU_LABEL_MAGIC, TRUE, PAL_XY(16, 50 + 18) },
  793. { 3, GAMEMENU_LABEL_INVENTORY, TRUE, PAL_XY(16, 50 + 36) },
  794. { 4, GAMEMENU_LABEL_SYSTEM, TRUE, PAL_XY(16, 50 + 54) },
  795. };
  796. //
  797. // Display the cash amount.
  798. //
  799. lpCashBox = PAL_ShowCash(gpGlobals->dwCash);
  800. //
  801. // Create the menu box.
  802. //
  803. lpMenuBox = PAL_CreateBox(PAL_XY(3, 37), 3, 1, 0, TRUE);
  804. VIDEO_UpdateScreen(&rect);
  805. //
  806. // Process the menu
  807. //
  808. while (TRUE)
  809. {
  810. wReturnValue = PAL_ReadMenu(PAL_InGameMenu_OnItemChange, rgMainMenuItem, 4,
  811. gpGlobals->iCurMainMenuItem, MENUITEM_COLOR);
  812. if (wReturnValue == MENUITEM_VALUE_CANCELLED)
  813. {
  814. break;
  815. }
  816. switch (wReturnValue)
  817. {
  818. case 1:
  819. //
  820. // Status
  821. //
  822. PAL_PlayerStatus();
  823. goto out;
  824. case 2:
  825. //
  826. // Magic
  827. //
  828. PAL_InGameMagicMenu();
  829. goto out;
  830. case 3:
  831. //
  832. // Inventory
  833. //
  834. PAL_InventoryMenu();
  835. goto out;
  836. case 4:
  837. //
  838. // System
  839. //
  840. if (PAL_SystemMenu())
  841. {
  842. goto out;
  843. }
  844. break;
  845. }
  846. }
  847. out:
  848. //
  849. // Remove the boxes.
  850. //
  851. PAL_DeleteBox(lpCashBox);
  852. PAL_DeleteBox(lpMenuBox);
  853. VIDEO_UpdateScreen(&rect);
  854. }
  855. VOID
  856. PAL_PlayerStatus(
  857. VOID
  858. )
  859. /*++
  860. Purpose:
  861. Show the player status.
  862. Parameters:
  863. None.
  864. Return value:
  865. None.
  866. --*/
  867. {
  868. PAL_LARGE BYTE bufBackground[320 * 200];
  869. PAL_LARGE BYTE bufImage[16384];
  870. int iCurrent;
  871. int iPlayerRole;
  872. int i, y;
  873. WORD w;
  874. const int rgEquipPos[MAX_PLAYER_EQUIPMENTS][2] = {
  875. {190, 0}, {248, 40}, {252, 102}, {202, 134}, {142, 142}, {82, 126}
  876. };
  877. PAL_MKFDecompressChunk(bufBackground, 320 * 200, STATUS_BACKGROUND_FBPNUM,
  878. gpGlobals->f.fpFBP);
  879. iCurrent = 0;
  880. while (iCurrent >= 0 && iCurrent <= gpGlobals->wMaxPartyMemberIndex)
  881. {
  882. iPlayerRole = gpGlobals->rgParty[iCurrent].wPlayerRole;
  883. //
  884. // Draw the background image
  885. //
  886. PAL_FBPBlitToSurface(bufBackground, gpScreen);
  887. //
  888. // Draw the text labels
  889. //
  890. PAL_DrawText(PAL_GetWord(STATUS_LABEL_EXP), PAL_XY(6, 6), MENUITEM_COLOR, TRUE, FALSE);
  891. PAL_DrawText(PAL_GetWord(STATUS_LABEL_LEVEL), PAL_XY(6, 32), MENUITEM_COLOR, TRUE, FALSE);
  892. PAL_DrawText(PAL_GetWord(STATUS_LABEL_HP), PAL_XY(6, 54), MENUITEM_COLOR, TRUE, FALSE);
  893. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MP), PAL_XY(6, 76), MENUITEM_COLOR, TRUE, FALSE);
  894. PAL_DrawText(PAL_GetWord(STATUS_LABEL_ATTACKPOWER), PAL_XY(6, 98), MENUITEM_COLOR, TRUE, FALSE);
  895. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MAGICPOWER), PAL_XY(6, 118), MENUITEM_COLOR, TRUE, FALSE);
  896. PAL_DrawText(PAL_GetWord(STATUS_LABEL_RESISTANCE), PAL_XY(6, 138), MENUITEM_COLOR, TRUE, FALSE);
  897. PAL_DrawText(PAL_GetWord(STATUS_LABEL_DEXTERITY), PAL_XY(6, 158), MENUITEM_COLOR, TRUE, FALSE);
  898. PAL_DrawText(PAL_GetWord(STATUS_LABEL_FLEERATE), PAL_XY(6, 178), MENUITEM_COLOR, TRUE, FALSE);
  899. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[iPlayerRole]),
  900. PAL_XY(110, 8), MENUITEM_COLOR_CONFIRMED, TRUE, FALSE);
  901. //
  902. // Draw the stats
  903. //
  904. PAL_DrawNumber(gpGlobals->Exp.rgPrimaryExp[iPlayerRole].wExp, 5,
  905. PAL_XY(58, 6), kNumColorYellow, kNumAlignRight);
  906. PAL_DrawNumber(gpGlobals->g.rgLevelUpExp[gpGlobals->g.PlayerRoles.rgwLevel[iPlayerRole]],
  907. 5, PAL_XY(58, 15), kNumColorCyan, kNumAlignRight);
  908. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwLevel[iPlayerRole], 2,
  909. PAL_XY(54, 35), kNumColorYellow, kNumAlignRight);
  910. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  911. PAL_XY(65, 58));
  912. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  913. PAL_XY(65, 80));
  914. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[iPlayerRole], 4, PAL_XY(42, 56),
  915. kNumColorYellow, kNumAlignRight);
  916. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[iPlayerRole], 4, PAL_XY(63, 61),
  917. kNumColorBlue, kNumAlignRight);
  918. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[iPlayerRole], 4, PAL_XY(42, 78),
  919. kNumColorYellow, kNumAlignRight);
  920. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[iPlayerRole], 4, PAL_XY(63, 83),
  921. kNumColorBlue, kNumAlignRight);
  922. PAL_DrawNumber(PAL_GetPlayerAttackStrength(iPlayerRole), 4,
  923. PAL_XY(42, 102), kNumColorYellow, kNumAlignRight);
  924. PAL_DrawNumber(PAL_GetPlayerMagicStrength(iPlayerRole), 4,
  925. PAL_XY(42, 122), kNumColorYellow, kNumAlignRight);
  926. PAL_DrawNumber(PAL_GetPlayerDefense(iPlayerRole), 4,
  927. PAL_XY(42, 142), kNumColorYellow, kNumAlignRight);
  928. PAL_DrawNumber(PAL_GetPlayerDexterity(iPlayerRole), 4,
  929. PAL_XY(42, 162), kNumColorYellow, kNumAlignRight);
  930. PAL_DrawNumber(PAL_GetPlayerFleeRate(iPlayerRole), 4,
  931. PAL_XY(42, 182), kNumColorYellow, kNumAlignRight);
  932. //
  933. // Draw the equipments
  934. //
  935. for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  936. {
  937. w = gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole];
  938. if (w == 0)
  939. {
  940. continue;
  941. }
  942. //
  943. // Draw the image
  944. //
  945. if (PAL_MKFReadChunk(bufImage, 16384,
  946. gpGlobals->g.rgObject[w].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  947. {
  948. PAL_RLEBlitToSurface(bufImage, gpScreen,
  949. PAL_XY(rgEquipPos[i][0], rgEquipPos[i][1]));
  950. }
  951. //
  952. // Draw the text label
  953. //
  954. PAL_DrawText(PAL_GetWord(w),
  955. PAL_XY(rgEquipPos[i][0] + 5, rgEquipPos[i][1] + 38), STATUS_COLOR_EQUIPMENT, TRUE, FALSE);
  956. }
  957. //
  958. // Draw the image of player role
  959. //
  960. if (PAL_MKFReadChunk(bufImage, 16384,
  961. gpGlobals->g.PlayerRoles.rgwAvatar[iPlayerRole], gpGlobals->f.fpRGM) > 0)
  962. {
  963. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(110, 30));
  964. }
  965. //
  966. // Draw all poisons
  967. //
  968. y = 58;
  969. for (i = 0; i < MAX_POISONS; i++)
  970. {
  971. w = gpGlobals->rgPoisonStatus[i][iCurrent].wPoisonID;
  972. if (w != 0 &&
  973. gpGlobals->g.rgObject[w].poison.wPoisonLevel <= 3)
  974. {
  975. PAL_DrawText(PAL_GetWord(w), PAL_XY(185, y),
  976. (BYTE)(gpGlobals->g.rgObject[w].poison.wColor + 10), TRUE, FALSE);
  977. y += 18;
  978. }
  979. }
  980. //
  981. // Update the screen
  982. //
  983. VIDEO_UpdateScreen(NULL);
  984. //
  985. // Wait for input
  986. //
  987. PAL_ClearKeyState();
  988. while (TRUE)
  989. {
  990. UTIL_Delay(1);
  991. if (g_InputState.dwKeyPress & kKeyMenu)
  992. {
  993. iCurrent = -1;
  994. break;
  995. }
  996. else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyUp))
  997. {
  998. iCurrent--;
  999. break;
  1000. }
  1001. else if (g_InputState.dwKeyPress & (kKeyRight | kKeyDown | kKeySearch))
  1002. {
  1003. iCurrent++;
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. WORD
  1010. PAL_ItemUseMenu(
  1011. WORD wItemToUse
  1012. )
  1013. /*++
  1014. Purpose:
  1015. Show the use item menu.
  1016. Parameters:
  1017. [IN] wItemToUse - the object ID of the item to use.
  1018. Return value:
  1019. The selected player to use the item onto.
  1020. MENUITEM_VALUE_CANCELLED if user cancelled.
  1021. --*/
  1022. {
  1023. BYTE bColor, bSelectedColor;
  1024. PAL_LARGE BYTE bufImage[2048];
  1025. DWORD dwColorChangeTime;
  1026. static WORD wSelectedPlayer = 0;
  1027. SDL_Rect rect = {110, 2, 200, 180};
  1028. int i;
  1029. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1030. dwColorChangeTime = 0;
  1031. while (TRUE)
  1032. {
  1033. if (wSelectedPlayer > gpGlobals->wMaxPartyMemberIndex)
  1034. {
  1035. wSelectedPlayer = 0;
  1036. }
  1037. //
  1038. // Draw the box
  1039. //
  1040. PAL_CreateBox(PAL_XY(110, 2), 7, 9, 0, FALSE);
  1041. //
  1042. // Draw the stats of the selected player
  1043. //
  1044. PAL_DrawText(PAL_GetWord(STATUS_LABEL_LEVEL), PAL_XY(200, 16),
  1045. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1046. PAL_DrawText(PAL_GetWord(STATUS_LABEL_HP), PAL_XY(200, 34),
  1047. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1048. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MP), PAL_XY(200, 52),
  1049. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1050. PAL_DrawText(PAL_GetWord(STATUS_LABEL_ATTACKPOWER), PAL_XY(200, 70),
  1051. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1052. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MAGICPOWER), PAL_XY(200, 88),
  1053. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1054. PAL_DrawText(PAL_GetWord(STATUS_LABEL_RESISTANCE), PAL_XY(200, 106),
  1055. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1056. PAL_DrawText(PAL_GetWord(STATUS_LABEL_DEXTERITY), PAL_XY(200, 124),
  1057. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1058. PAL_DrawText(PAL_GetWord(STATUS_LABEL_FLEERATE), PAL_XY(200, 142),
  1059. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE);
  1060. i = gpGlobals->rgParty[wSelectedPlayer].wPlayerRole;
  1061. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwLevel[i], 4, PAL_XY(240, 20),
  1062. kNumColorYellow, kNumAlignRight);
  1063. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  1064. PAL_XY(263, 38));
  1065. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[i], 4,
  1066. PAL_XY(261, 40), kNumColorBlue, kNumAlignRight);
  1067. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[i], 4,
  1068. PAL_XY(240, 37), kNumColorYellow, kNumAlignRight);
  1069. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  1070. PAL_XY(263, 56));
  1071. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[i], 4,
  1072. PAL_XY(261, 58), kNumColorBlue, kNumAlignRight);
  1073. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[i], 4,
  1074. PAL_XY(240, 55), kNumColorYellow, kNumAlignRight);
  1075. PAL_DrawNumber(PAL_GetPlayerAttackStrength(i), 4, PAL_XY(240, 74),
  1076. kNumColorYellow, kNumAlignRight);
  1077. PAL_DrawNumber(PAL_GetPlayerMagicStrength(i), 4, PAL_XY(240, 92),
  1078. kNumColorYellow, kNumAlignRight);
  1079. PAL_DrawNumber(PAL_GetPlayerDefense(i), 4, PAL_XY(240, 110),
  1080. kNumColorYellow, kNumAlignRight);
  1081. PAL_DrawNumber(PAL_GetPlayerDexterity(i), 4, PAL_XY(240, 128),
  1082. kNumColorYellow, kNumAlignRight);
  1083. PAL_DrawNumber(PAL_GetPlayerFleeRate(i), 4, PAL_XY(240, 146),
  1084. kNumColorYellow, kNumAlignRight);
  1085. //
  1086. // Draw the names of the players in the party
  1087. //
  1088. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1089. {
  1090. if (i == wSelectedPlayer)
  1091. {
  1092. bColor = bSelectedColor;
  1093. }
  1094. else
  1095. {
  1096. bColor = MENUITEM_COLOR;
  1097. }
  1098. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole]),
  1099. PAL_XY(125, 16 + 20 * i), bColor, TRUE, FALSE);
  1100. }
  1101. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_ITEMBOX), gpScreen,
  1102. PAL_XY(120, 80));
  1103. i = PAL_GetItemAmount(wItemToUse);
  1104. if (i > 0)
  1105. {
  1106. //
  1107. // Draw the picture of the item
  1108. //
  1109. if (PAL_MKFReadChunk(bufImage, 2048,
  1110. gpGlobals->g.rgObject[wItemToUse].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1111. {
  1112. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(127, 88));
  1113. }
  1114. //
  1115. // Draw the amount and label of the item
  1116. //
  1117. PAL_DrawText(PAL_GetWord(wItemToUse), PAL_XY(116, 143), STATUS_COLOR_EQUIPMENT,
  1118. TRUE, FALSE);
  1119. PAL_DrawNumber(i, 2, PAL_XY(170, 133), kNumColorCyan, kNumAlignRight);
  1120. }
  1121. //
  1122. // Update the screen area
  1123. //
  1124. VIDEO_UpdateScreen(&rect);
  1125. //
  1126. // Wait for key
  1127. //
  1128. PAL_ClearKeyState();
  1129. while (TRUE)
  1130. {
  1131. //
  1132. // See if we should change the highlight color
  1133. //
  1134. if (SDL_GetTicks() > dwColorChangeTime)
  1135. {
  1136. if ((WORD)bSelectedColor + 1 >=
  1137. (WORD)MENUITEM_COLOR_SELECTED_FIRST + MENUITEM_COLOR_SELECTED_TOTALNUM)
  1138. {
  1139. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1140. }
  1141. else
  1142. {
  1143. bSelectedColor++;
  1144. }
  1145. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1146. //
  1147. // Redraw the selected item.
  1148. //
  1149. PAL_DrawText(
  1150. PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[wSelectedPlayer].wPlayerRole]),
  1151. PAL_XY(125, 16 + 20 * wSelectedPlayer), bSelectedColor, FALSE, TRUE);
  1152. }
  1153. PAL_ProcessEvent();
  1154. if (g_InputState.dwKeyPress != 0)
  1155. {
  1156. break;
  1157. }
  1158. SDL_Delay(1);
  1159. }
  1160. if (i <= 0)
  1161. {
  1162. return MENUITEM_VALUE_CANCELLED;
  1163. }
  1164. if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
  1165. {
  1166. wSelectedPlayer--;
  1167. }
  1168. else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
  1169. {
  1170. if (wSelectedPlayer < gpGlobals->wMaxPartyMemberIndex)
  1171. {
  1172. wSelectedPlayer++;
  1173. }
  1174. }
  1175. else if (g_InputState.dwKeyPress & kKeyMenu)
  1176. {
  1177. break;
  1178. }
  1179. else if (g_InputState.dwKeyPress & kKeySearch)
  1180. {
  1181. return gpGlobals->rgParty[wSelectedPlayer].wPlayerRole;
  1182. }
  1183. }
  1184. return MENUITEM_VALUE_CANCELLED;
  1185. }
  1186. static VOID
  1187. PAL_BuyMenu_OnItemChange(
  1188. WORD wCurrentItem
  1189. )
  1190. /*++
  1191. Purpose:
  1192. Callback function which is called when player selected another item
  1193. in the buy menu.
  1194. Parameters:
  1195. [IN] wCurrentItem - current item on the menu, indicates the object ID of
  1196. the currently selected item.
  1197. Return value:
  1198. None.
  1199. --*/
  1200. {
  1201. const SDL_Rect rect = {20, 8, 128, 175};
  1202. int i, n;
  1203. PAL_LARGE BYTE bufImage[2048];
  1204. //
  1205. // Draw the picture of current selected item
  1206. //
  1207. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_ITEMBOX), gpScreen,
  1208. PAL_XY(35, 8));
  1209. if (PAL_MKFReadChunk(bufImage, 2048,
  1210. gpGlobals->g.rgObject[wCurrentItem].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1211. {
  1212. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(42, 16));
  1213. }
  1214. //
  1215. // See how many of this item we have in the inventory
  1216. //
  1217. n = 0;
  1218. for (i = 0; i < MAX_INVENTORY; i++)
  1219. {
  1220. if (gpGlobals->rgInventory[i].wItem == 0)
  1221. {
  1222. break;
  1223. }
  1224. else if (gpGlobals->rgInventory[i].wItem == wCurrentItem)
  1225. {
  1226. n = gpGlobals->rgInventory[i].nAmount;
  1227. break;
  1228. }
  1229. }
  1230. //
  1231. // Draw the amount of this item in the inventory
  1232. //
  1233. PAL_CreateSingleLineBox(PAL_XY(20, 105), 5, FALSE);
  1234. PAL_DrawText(PAL_GetWord(BUYMENU_LABEL_CURRENT), PAL_XY(30, 115), 0, FALSE, FALSE);
  1235. PAL_DrawNumber(n, 6, PAL_XY(69, 119), kNumColorYellow, kNumAlignRight);
  1236. //
  1237. // Draw the cash amount
  1238. //
  1239. PAL_CreateSingleLineBox(PAL_XY(20, 145), 5, FALSE);
  1240. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(30, 155), 0, FALSE, FALSE);
  1241. PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(69, 159), kNumColorYellow, kNumAlignRight);
  1242. VIDEO_UpdateScreen(&rect);
  1243. }
  1244. VOID
  1245. PAL_BuyMenu(
  1246. WORD wStoreNum
  1247. )
  1248. /*++
  1249. Purpose:
  1250. Show the buy item menu.
  1251. Parameters:
  1252. [IN] wStoreNum - number of the store to buy items from.
  1253. Return value:
  1254. None.
  1255. --*/
  1256. {
  1257. MENUITEM rgMenuItem[MAX_STORE_ITEM];
  1258. int i, y;
  1259. WORD w;
  1260. SDL_Rect rect = {125, 8, 190, 190};
  1261. //
  1262. // create the menu items
  1263. //
  1264. y = 22;
  1265. for (i = 0; i < MAX_STORE_ITEM; i++)
  1266. {
  1267. if (gpGlobals->g.lprgStore[wStoreNum].rgwItems[i] == 0)
  1268. {
  1269. break;
  1270. }
  1271. rgMenuItem[i].wValue = gpGlobals->g.lprgStore[wStoreNum].rgwItems[i];
  1272. rgMenuItem[i].wNumWord = gpGlobals->g.lprgStore[wStoreNum].rgwItems[i];
  1273. rgMenuItem[i].fEnabled = TRUE;
  1274. rgMenuItem[i].pos = PAL_XY(150, y);
  1275. y += 18;
  1276. }
  1277. //
  1278. // Draw the box
  1279. //
  1280. PAL_CreateBox(PAL_XY(125, 8), 8, 8, 1, FALSE);
  1281. //
  1282. // Draw the number of prices
  1283. //
  1284. for (y = 0; y < i; y++)
  1285. {
  1286. w = gpGlobals->g.rgObject[rgMenuItem[y].wValue].item.wPrice;
  1287. PAL_DrawNumber(w, 6, PAL_XY(235, 25 + y * 18), kNumColorCyan, kNumAlignRight);
  1288. }
  1289. VIDEO_UpdateScreen(&rect);
  1290. w = 0;
  1291. while (TRUE)
  1292. {
  1293. w = PAL_ReadMenu(PAL_BuyMenu_OnItemChange, rgMenuItem, i, w, MENUITEM_COLOR);
  1294. if (w == MENUITEM_VALUE_CANCELLED)
  1295. {
  1296. break;
  1297. }
  1298. if (gpGlobals->g.rgObject[w].item.wPrice <= gpGlobals->dwCash)
  1299. {
  1300. if (PAL_ConfirmMenu())
  1301. {
  1302. //
  1303. // Player bought an item
  1304. //
  1305. gpGlobals->dwCash -= gpGlobals->g.rgObject[w].item.wPrice;
  1306. PAL_AddItemToInventory(w, 1);
  1307. }
  1308. }
  1309. //
  1310. // Place the cursor to the current item on next loop
  1311. //
  1312. for (y = 0; y < i; y++)
  1313. {
  1314. if (w == rgMenuItem[y].wValue)
  1315. {
  1316. w = y;
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. }
  1322. static VOID
  1323. PAL_SellMenu_OnItemChange(
  1324. WORD wCurrentItem
  1325. )
  1326. /*++
  1327. Purpose:
  1328. Callback function which is called when player selected another item
  1329. in the sell item menu.
  1330. Parameters:
  1331. [IN] wCurrentItem - current item on the menu, indicates the object ID of
  1332. the currently selected item.
  1333. Return value:
  1334. None.
  1335. --*/
  1336. {
  1337. //
  1338. // Draw the cash amount
  1339. //
  1340. PAL_CreateSingleLineBox(PAL_XY(100, 150), 5, FALSE);
  1341. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(110, 160), 0, FALSE, FALSE);
  1342. PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(149, 164), kNumColorYellow, kNumAlignRight);
  1343. //
  1344. // Draw the price
  1345. //
  1346. PAL_CreateSingleLineBox(PAL_XY(220, 150), 5, FALSE);
  1347. if (gpGlobals->g.rgObject[wCurrentItem].item.wFlags & kItemFlagSellable)
  1348. {
  1349. PAL_DrawText(PAL_GetWord(SELLMENU_LABEL_PRICE), PAL_XY(230, 160), 0, FALSE, FALSE);
  1350. PAL_DrawNumber(gpGlobals->g.rgObject[wCurrentItem].item.wPrice / 2, 6,
  1351. PAL_XY(269, 164), kNumColorYellow, kNumAlignRight);
  1352. }
  1353. }
  1354. VOID
  1355. PAL_SellMenu(
  1356. VOID
  1357. )
  1358. /*++
  1359. Purpose:
  1360. Show the sell item menu.
  1361. Parameters:
  1362. None.
  1363. Return value:
  1364. None.
  1365. --*/
  1366. {
  1367. WORD w;
  1368. while (TRUE)
  1369. {
  1370. w = PAL_ItemSelectMenu(PAL_SellMenu_OnItemChange, kItemFlagSellable);
  1371. if (w == 0)
  1372. {
  1373. break;
  1374. }
  1375. if (PAL_ConfirmMenu())
  1376. {
  1377. if (PAL_AddItemToInventory(w, -1))
  1378. {
  1379. gpGlobals->dwCash += gpGlobals->g.rgObject[w].item.wPrice / 2;
  1380. }
  1381. }
  1382. }
  1383. }
  1384. VOID
  1385. PAL_EquipItemMenu(
  1386. WORD wItem
  1387. )
  1388. /*++
  1389. Purpose:
  1390. Show the menu which allow players to equip the specified item.
  1391. Parameters:
  1392. [IN] wItem - the object ID of the item.
  1393. Return value:
  1394. None.
  1395. --*/
  1396. {
  1397. PAL_LARGE BYTE bufBackground[320 * 200];
  1398. PAL_LARGE BYTE bufImage[2048];
  1399. WORD w;
  1400. int iCurrentPlayer, i;
  1401. BYTE bColor, bSelectedColor;
  1402. DWORD dwColorChangeTime;
  1403. gpGlobals->wLastUnequippedItem = wItem;
  1404. PAL_MKFDecompressChunk(bufBackground, 320 * 200, EQUIPMENU_BACKGROUND_FBPNUM,
  1405. gpGlobals->f.fpFBP);
  1406. iCurrentPlayer = 0;
  1407. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1408. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1409. while (TRUE)
  1410. {
  1411. wItem = gpGlobals->wLastUnequippedItem;
  1412. //
  1413. // Draw the background
  1414. //
  1415. PAL_FBPBlitToSurface(bufBackground, gpScreen);
  1416. //
  1417. // Draw the item picture
  1418. //
  1419. if (PAL_MKFReadChunk(bufImage, 2048,
  1420. gpGlobals->g.rgObject[wItem].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1421. {
  1422. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(16, 16));
  1423. }
  1424. //
  1425. // Draw the current equipment of the selected player
  1426. //
  1427. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1428. for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  1429. {
  1430. if (gpGlobals->g.PlayerRoles.rgwEquipment[i][w] != 0)
  1431. {
  1432. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwEquipment[i][w]),
  1433. PAL_XY(130, 11 + i * 22), MENUITEM_COLOR, TRUE, FALSE);
  1434. }
  1435. }
  1436. //
  1437. // Draw the stats of the currently selected player
  1438. //
  1439. PAL_DrawNumber(PAL_GetPlayerAttackStrength(w), 4, PAL_XY(260, 14),
  1440. kNumColorCyan, kNumAlignRight);
  1441. PAL_DrawNumber(PAL_GetPlayerMagicStrength(w), 4, PAL_XY(260, 36),
  1442. kNumColorCyan, kNumAlignRight);
  1443. PAL_DrawNumber(PAL_GetPlayerDefense(w), 4, PAL_XY(260, 58),
  1444. kNumColorCyan, kNumAlignRight);
  1445. PAL_DrawNumber(PAL_GetPlayerDexterity(w), 4, PAL_XY(260, 80),
  1446. kNumColorCyan, kNumAlignRight);
  1447. PAL_DrawNumber(PAL_GetPlayerFleeRate(w), 4, PAL_XY(260, 102),
  1448. kNumColorCyan, kNumAlignRight);
  1449. //
  1450. // Draw a box for player selection
  1451. //
  1452. PAL_CreateBox(PAL_XY(2, 95), gpGlobals->wMaxPartyMemberIndex, 2, 0, FALSE);
  1453. //
  1454. // Draw the label of players
  1455. //
  1456. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1457. {
  1458. w = gpGlobals->rgParty[i].wPlayerRole;
  1459. if (iCurrentPlayer == i)
  1460. {
  1461. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1462. {
  1463. bColor = bSelectedColor;
  1464. }
  1465. else
  1466. {
  1467. bColor = MENUITEM_COLOR_SELECTED_INACTIVE;
  1468. }
  1469. }
  1470. else
  1471. {
  1472. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1473. {
  1474. bColor = MENUITEM_COLOR;
  1475. }
  1476. else
  1477. {
  1478. bColor = MENUITEM_COLOR_INACTIVE;
  1479. }
  1480. }
  1481. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[w]),
  1482. PAL_XY(15, 108 + 18 * i), bColor, TRUE, FALSE);
  1483. }
  1484. //
  1485. // Draw the text label and amount of the item
  1486. //
  1487. if (wItem != 0)
  1488. {
  1489. PAL_DrawText(PAL_GetWord(wItem), PAL_XY(5, 70), MENUITEM_COLOR_CONFIRMED, TRUE, FALSE);
  1490. PAL_DrawNumber(PAL_GetItemAmount(wItem), 2, PAL_XY(65, 73), kNumColorCyan, kNumAlignRight);
  1491. }
  1492. //
  1493. // Update the screen
  1494. //
  1495. VIDEO_UpdateScreen(NULL);
  1496. //
  1497. // Accept input
  1498. //
  1499. PAL_ClearKeyState();
  1500. while (TRUE)
  1501. {
  1502. PAL_ProcessEvent();
  1503. //
  1504. // See if we should change the highlight color
  1505. //
  1506. if (SDL_GetTicks() > dwColorChangeTime)
  1507. {
  1508. if ((WORD)bSelectedColor + 1 >=
  1509. (WORD)MENUITEM_COLOR_SELECTED_FIRST + MENUITEM_COLOR_SELECTED_TOTALNUM)
  1510. {
  1511. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1512. }
  1513. else
  1514. {
  1515. bSelectedColor++;
  1516. }
  1517. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1518. //
  1519. // Redraw the selected item if needed.
  1520. //
  1521. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1522. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1523. {
  1524. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[w]),
  1525. PAL_XY(15, 108 + 18 * iCurrentPlayer), bSelectedColor, TRUE, TRUE);
  1526. }
  1527. }
  1528. if (g_InputState.dwKeyPress != 0)
  1529. {
  1530. break;
  1531. }
  1532. SDL_Delay(1);
  1533. }
  1534. if (wItem == 0)
  1535. {
  1536. return;
  1537. }
  1538. if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
  1539. {
  1540. iCurrentPlayer--;
  1541. if (iCurrentPlayer < 0)
  1542. {
  1543. iCurrentPlayer = 0;
  1544. }
  1545. }
  1546. else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
  1547. {
  1548. iCurrentPlayer++;
  1549. if (iCurrentPlayer > gpGlobals->wMaxPartyMemberIndex)
  1550. {
  1551. iCurrentPlayer = gpGlobals->wMaxPartyMemberIndex;
  1552. }
  1553. }
  1554. else if (g_InputState.dwKeyPress & kKeyMenu)
  1555. {
  1556. return;
  1557. }
  1558. else if (g_InputState.dwKeyPress & kKeySearch)
  1559. {
  1560. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1561. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1562. {
  1563. //
  1564. // Run the equip script
  1565. //
  1566. gpGlobals->g.rgObject[wItem].item.wScriptOnEquip =
  1567. PAL_RunTriggerScript(gpGlobals->g.rgObject[wItem].item.wScriptOnEquip,
  1568. gpGlobals->rgParty[iCurrentPlayer].wPlayerRole);
  1569. }
  1570. }
  1571. }
  1572. }