uigame.c 45 KB

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