123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803 |
- /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
- //
- // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
- // All rights reserved.
- //
- // This file is part of SDLPAL.
- //
- // SDLPAL is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- // Modified by Lou Yihua <louyihua@21cn.com> with Unicode support, 2015
- //
- #include "main.h"
- extern WORD g_rgPlayerPos[3][3][2];
- static int g_iCurMiscMenuItem = 0;
- static int g_iCurSubMenuItem = 0;
- VOID
- PAL_PlayerInfoBox(
- PAL_POS pos,
- WORD wPlayerRole,
- INT iTimeMeter,
- BYTE bTimeMeterColor,
- BOOL fUpdate
- )
- /*++
- Purpose:
- Show the player info box.
- Parameters:
- [IN] pos - the top-left corner position of the box.
- [IN] wPlayerRole - the player role ID to be shown.
- [IN] iTimeMeter - the value of time meter. 0 = empty, 100 = full.
- [IN] bTimeMeterColor - the color of time meter.
- [IN] fUpdate - whether to update the screen area or not.
- Return value:
- None.
- --*/
- {
- SDL_Rect rect;
- BYTE bPoisonColor;
- int i, iPartyIndex;
- WORD wMaxLevel, w;
- const BYTE rgStatusPos[kStatusAll][2] =
- {
- {35, 19}, // confused
- {0, 0}, // slow
- {54, 1}, // sleep
- {55, 20}, // silence
- {0, 0}, // puppet
- {0, 0}, // bravery
- {0, 0}, // protect
- {0, 0}, // haste
- {0, 0}, // dualattack
- };
- const WORD rgwStatusWord[kStatusAll] =
- {
- 0x1D, // confused
- 0x00, // slow
- 0x1C, // sleep
- 0x1A, // silence
- 0x00, // puppet
- 0x00, // bravery
- 0x00, // protect
- 0x00, // haste
- 0x00, // dualattack
- };
- const BYTE rgbStatusColor[kStatusAll] =
- {
- 0x5F, // confused
- 0x00, // slow
- 0x0E, // sleep
- 0x3C, // silence
- 0x00, // puppet
- 0x00, // bravery
- 0x00, // protect
- 0x00, // haste
- 0x00, // dualattack
- };
- //
- // Draw the box
- //
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_PLAYERINFOBOX),
- gpScreen, pos);
- //
- // Draw the player face
- //
- wMaxLevel = 0;
- bPoisonColor = 0xFF;
- for (iPartyIndex = 0; iPartyIndex <= gpGlobals->wMaxPartyMemberIndex; iPartyIndex++)
- {
- if (gpGlobals->rgParty[iPartyIndex].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (iPartyIndex <= gpGlobals->wMaxPartyMemberIndex)
- {
- for (i = 0; i < MAX_POISONS; i++)
- {
- w = gpGlobals->rgPoisonStatus[i][iPartyIndex].wPoisonID;
- if (w != 0 &&
- gpGlobals->g.rgObject[w].poison.wPoisonLevel <= 3)
- {
- if (gpGlobals->g.rgObject[w].poison.wPoisonLevel >= wMaxLevel)
- {
- wMaxLevel = gpGlobals->g.rgObject[w].poison.wPoisonLevel;
- bPoisonColor = (BYTE)(gpGlobals->g.rgObject[w].poison.wColor);
- }
- }
- }
- }
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0)
- {
- //
- // Always use the black/white color for dead players
- // and do not use the time meter
- //
- bPoisonColor = 0;
- iTimeMeter = 0;
- }
- if (bPoisonColor == 0xFF)
- {
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_PLAYERFACE_FIRST + wPlayerRole),
- gpScreen, PAL_XY(PAL_X(pos) - 2, PAL_Y(pos) - 4));
- }
- else
- {
- PAL_RLEBlitMonoColor(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_PLAYERFACE_FIRST + wPlayerRole),
- gpScreen, PAL_XY(PAL_X(pos) - 2, PAL_Y(pos) - 4), bPoisonColor, 0);
- }
- #ifndef PAL_CLASSIC
- //
- // Draw a border for the Time Meter
- //
- rect.x = PAL_X(pos) + 31;
- rect.y = PAL_Y(pos) + 4;
- rect.w = 1;
- rect.h = 6;
- SDL_FillRect(gpScreen, &rect, 0xBD);
- rect.x += 39;
- SDL_FillRect(gpScreen, &rect, 0xBD);
- rect.x = PAL_X(pos) + 32;
- rect.y = PAL_Y(pos) + 3;
- rect.w = 38;
- rect.h = 1;
- SDL_FillRect(gpScreen, &rect, 0xBD);
- rect.y += 7;
- SDL_FillRect(gpScreen, &rect, 0xBD);
- //
- // Draw the Time meter bar
- //
- if (iTimeMeter >= 100)
- {
- rect.x = PAL_X(pos) + 33;
- rect.y = PAL_Y(pos) + 6;
- rect.w = 36;
- rect.h = 2;
- SDL_FillRect(gpScreen, &rect, 0x2C);
- }
- else if (iTimeMeter > 0)
- {
- rect.x = PAL_X(pos) + 33;
- rect.y = PAL_Y(pos) + 5;
- rect.w = iTimeMeter * 36 / 100;
- rect.h = 4;
- SDL_FillRect(gpScreen, &rect, bTimeMeterColor);
- }
- #endif
- //
- // Draw the HP and MP value
- //
- #ifdef PAL_CLASSIC
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
- PAL_XY(PAL_X(pos) + 49, PAL_Y(pos) + 6));
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 47, PAL_Y(pos) + 8), kNumColorYellow, kNumAlignRight);
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 26, PAL_Y(pos) + 5), kNumColorYellow, kNumAlignRight);
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
- PAL_XY(PAL_X(pos) + 49, PAL_Y(pos) + 22));
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 47, PAL_Y(pos) + 24), kNumColorCyan, kNumAlignRight);
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 26, PAL_Y(pos) + 21), kNumColorCyan, kNumAlignRight);
- #else
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
- PAL_XY(PAL_X(pos) + 49, PAL_Y(pos) + 14));
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 47, PAL_Y(pos) + 16), kNumColorYellow, kNumAlignRight);
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 26, PAL_Y(pos) + 13), kNumColorYellow, kNumAlignRight);
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
- PAL_XY(PAL_X(pos) + 49, PAL_Y(pos) + 24));
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 47, PAL_Y(pos) + 26), kNumColorCyan, kNumAlignRight);
- PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole], 4,
- PAL_XY(PAL_X(pos) + 26, PAL_Y(pos) + 23), kNumColorCyan, kNumAlignRight);
- #endif
- //
- // Draw Statuses
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] > 0)
- {
- for (i = 0; i < kStatusAll; i++)
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][i] > 0 &&
- rgwStatusWord[i] != 0)
- {
- PAL_DrawText(PAL_GetWord(rgwStatusWord[i]),
- PAL_XY(PAL_X(pos) + rgStatusPos[i][0], PAL_Y(pos) + rgStatusPos[i][1]),
- rgbStatusColor[i], TRUE, FALSE);
- }
- }
- }
- //
- // Update the screen area if needed
- //
- if (fUpdate)
- {
- rect.x = PAL_X(pos) - 2;
- rect.y = PAL_Y(pos) - 4;
- rect.w = 77;
- rect.h = 39;
- VIDEO_UpdateScreen(&rect);
- }
- }
- static BOOL
- PAL_BattleUIIsActionValid(
- BATTLEUIACTION ActionType
- )
- /*++
- Purpose:
- Check if the specified action is valid.
- Parameters:
- [IN] ActionType - the type of the action.
- Return value:
- TRUE if the action is valid, FALSE if not.
- --*/
- {
- WORD wPlayerRole, w;
- int i;
- wPlayerRole = gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole;
- switch (ActionType)
- {
- case kBattleUIActionAttack:
- case kBattleUIActionMisc:
- break;
- case kBattleUIActionMagic:
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSilence] != 0)
- {
- return FALSE;
- }
- break;
- case kBattleUIActionCoopMagic:
- if (gpGlobals->wMaxPartyMemberIndex == 0)
- {
- return FALSE;
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- #ifndef PAL_CLASSIC
- if (gpGlobals->g.PlayerRoles.rgwHP[w] < gpGlobals->g.PlayerRoles.rgwMaxHP[w] / 5 ||
- gpGlobals->rgPlayerStatus[w][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusConfused] != 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusSilence] != 0 ||
- g_Battle.rgPlayer[i].flTimeMeter < 100 ||
- g_Battle.rgPlayer[i].state == kFighterAct)
- #else
- if (gpGlobals->g.PlayerRoles.rgwHP[w] < gpGlobals->g.PlayerRoles.rgwMaxHP[w] / 5 ||
- gpGlobals->rgPlayerStatus[w][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusConfused] != 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusSilence] != 0)
- #endif
- {
- return FALSE;
- }
- }
- break;
- }
- return TRUE;
- }
- static VOID
- PAL_BattleUIDrawMiscMenu(
- WORD wCurrentItem,
- BOOL fConfirmed
- )
- /*++
- Purpose:
- Draw the misc menu.
- Parameters:
- [IN] wCurrentItem - the current selected menu item.
- [IN] fConfirmed - TRUE if confirmed, FALSE if not.
- Return value:
- None.
- --*/
- {
- int i;
- BYTE bColor;
- #ifdef PAL_CLASSIC
- MENUITEM rgMenuItem[] = {
- // value label enabled position
- { 0, BATTLEUI_LABEL_AUTO, TRUE, PAL_XY(16, 32) },
- { 1, BATTLEUI_LABEL_INVENTORY, TRUE, PAL_XY(16, 50) },
- { 2, BATTLEUI_LABEL_DEFEND, TRUE, PAL_XY(16, 68) },
- { 3, BATTLEUI_LABEL_FLEE, TRUE, PAL_XY(16, 86) },
- { 4, BATTLEUI_LABEL_STATUS, TRUE, PAL_XY(16, 104) }
- };
- #else
- MENUITEM rgMenuItem[] = {
- // value label enabled position
- { 0, BATTLEUI_LABEL_ITEM, TRUE, PAL_XY(16, 32) },
- { 1, BATTLEUI_LABEL_DEFEND, TRUE, PAL_XY(16, 50) },
- { 2, BATTLEUI_LABEL_AUTO, TRUE, PAL_XY(16, 68) },
- { 3, BATTLEUI_LABEL_FLEE, TRUE, PAL_XY(16, 86) },
- { 4, BATTLEUI_LABEL_STATUS, TRUE, PAL_XY(16, 104) }
- };
- #endif
- //
- // Draw the box
- //
- PAL_CreateBox(PAL_XY(2, 20), 4, 1, 0, FALSE);
- //
- // Draw the menu items
- //
- for (i = 0; i < 5; i++)
- {
- bColor = MENUITEM_COLOR;
- if (i == wCurrentItem)
- {
- if (fConfirmed)
- {
- bColor = MENUITEM_COLOR_CONFIRMED;
- }
- else
- {
- bColor = MENUITEM_COLOR_SELECTED;
- }
- }
- PAL_DrawText(PAL_GetWord(rgMenuItem[i].wNumWord), rgMenuItem[i].pos, bColor,
- TRUE, FALSE);
- }
- }
- static WORD
- PAL_BattleUIMiscMenuUpdate(
- VOID
- )
- /*++
- Purpose:
- Update the misc menu.
- Parameters:
- None.
- Return value:
- The selected item number. 0 if cancelled, 0xFFFF if not confirmed.
- --*/
- {
- //
- // Draw the menu
- //
- PAL_BattleUIDrawMiscMenu(g_iCurMiscMenuItem, FALSE);
- //
- // Process inputs
- //
- if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
- {
- g_iCurMiscMenuItem--;
- if (g_iCurMiscMenuItem < 0)
- {
- g_iCurMiscMenuItem = 4;
- }
- }
- else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
- {
- g_iCurMiscMenuItem++;
- if (g_iCurMiscMenuItem > 4)
- {
- g_iCurMiscMenuItem = 0;
- }
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- return g_iCurMiscMenuItem + 1;
- }
- else if (g_InputState.dwKeyPress & kKeyMenu)
- {
- return 0;
- }
- return 0xFFFF;
- }
- static WORD
- PAL_BattleUIMiscItemSubMenuUpdate(
- VOID
- )
- /*++
- Purpose:
- Update the item sub menu of the misc menu.
- Parameters:
- None.
- Return value:
- The selected item number. 0 if cancelled, 0xFFFF if not confirmed.
- --*/
- {
- int i;
- BYTE bColor;
- MENUITEM rgMenuItem[] = {
- // value label enabled position
- { 0, BATTLEUI_LABEL_USEITEM, TRUE, PAL_XY(44, 62) },
- { 1, BATTLEUI_LABEL_THROWITEM, TRUE, PAL_XY(44, 80) },
- };
- //
- // Draw the menu
- //
- #ifdef PAL_CLASSIC
- PAL_BattleUIDrawMiscMenu(1, TRUE);
- #else
- PAL_BattleUIDrawMiscMenu(0, TRUE);
- #endif
- PAL_CreateBox(PAL_XY(30, 50), 1, 1, 0, FALSE);
- //
- // Draw the menu items
- //
- for (i = 0; i < 2; i++)
- {
- bColor = MENUITEM_COLOR;
- if (i == g_iCurSubMenuItem)
- {
- bColor = MENUITEM_COLOR_SELECTED;
- }
- PAL_DrawText(PAL_GetWord(rgMenuItem[i].wNumWord), rgMenuItem[i].pos, bColor,
- TRUE, FALSE);
- }
- //
- // Process inputs
- //
- if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
- {
- g_iCurSubMenuItem = 0;
- }
- else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
- {
- g_iCurSubMenuItem = 1;
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- return g_iCurSubMenuItem + 1;
- }
- else if (g_InputState.dwKeyPress & kKeyMenu)
- {
- return 0;
- }
- return 0xFFFF;
- }
- VOID
- PAL_BattleUIShowText(
- #ifdef PAL_UNICODE
- LPCWSTR lpszText,
- #else
- LPCSTR lpszText,
- #endif
- WORD wDuration
- )
- /*++
- Purpose:
- Show a text message in the battle.
- Parameters:
- [IN] lpszText - the text message to be shown.
- [IN] wDuration - the duration of the message, in milliseconds.
- Return value:
- None.
- --*/
- {
- if (SDL_GetTicks() < g_Battle.UI.dwMsgShowTime)
- {
- # ifdef PAL_UNICODE
- wcscpy(g_Battle.UI.szNextMsg, lpszText);
- # else
- strcpy(g_Battle.UI.szNextMsg, lpszText);
- # endif
- g_Battle.UI.wNextMsgDuration = wDuration;
- }
- else
- {
- # ifdef PAL_UNICODE
- wcscpy(g_Battle.UI.szMsg, lpszText);
- # else
- strcpy(g_Battle.UI.szMsg, lpszText);
- # endif
- g_Battle.UI.dwMsgShowTime = SDL_GetTicks() + wDuration;
- }
- }
- VOID
- PAL_BattleUIPlayerReady(
- WORD wPlayerIndex
- )
- /*++
- Purpose:
- Start the action selection menu of the specified player.
- Parameters:
- [IN] wPlayerIndex - the player index.
- Return value:
- None.
- --*/
- {
- #ifndef PAL_CLASSIC
- WORD w = gpGlobals->rgParty[wPlayerIndex].wPlayerRole;
- #endif
- g_Battle.UI.wCurPlayerIndex = wPlayerIndex;
- g_Battle.UI.state = kBattleUISelectMove;
- g_Battle.UI.wSelectedAction = 0;
- g_Battle.UI.MenuState = kBattleMenuMain;
- #ifndef PAL_CLASSIC
- //
- // Play a sound which indicates the player is ready
- //
- if (gpGlobals->rgPlayerStatus[w][kStatusPuppet] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusSleep] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusConfused] == 0 &&
- !g_Battle.UI.fAutoAttack && !gpGlobals->fAutoBattle)
- {
- SOUND_PlayChannel(78, 1);
- }
- #endif
- }
- static VOID
- PAL_BattleUIUseItem(
- VOID
- )
- /*++
- Purpose:
- Use an item in the battle UI.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- WORD wSelectedItem;
- wSelectedItem = PAL_ItemSelectMenuUpdate();
- if (wSelectedItem != 0xFFFF)
- {
- if (wSelectedItem != 0)
- {
- g_Battle.UI.wActionType = kBattleActionUseItem;
- g_Battle.UI.wObjectID = wSelectedItem;
- if (gpGlobals->g.rgObject[wSelectedItem].item.wFlags & kItemFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetPlayerAll;
- }
- else
- {
- #ifdef PAL_CLASSIC
- g_Battle.UI.wSelectedIndex = 0;
- #else
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wCurPlayerIndex;
- #endif
- g_Battle.UI.state = kBattleUISelectTargetPlayer;
- }
- }
- else
- {
- g_Battle.UI.MenuState = kBattleMenuMain;
- }
- }
- }
- static VOID
- PAL_BattleUIThrowItem(
- VOID
- )
- /*++
- Purpose:
- Throw an item in the battle UI.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- WORD wSelectedItem = PAL_ItemSelectMenuUpdate();
- if (wSelectedItem != 0xFFFF)
- {
- if (wSelectedItem != 0)
- {
- g_Battle.UI.wActionType = kBattleActionThrowItem;
- g_Battle.UI.wObjectID = wSelectedItem;
- if (gpGlobals->g.rgObject[wSelectedItem].item.wFlags & kItemFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetEnemyAll;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wPrevEnemyTarget;
- g_Battle.UI.state = kBattleUISelectTargetEnemy;
- }
- }
- else
- {
- g_Battle.UI.MenuState = kBattleMenuMain;
- }
- }
- }
- static WORD
- PAL_BattleUIPickAutoMagic(
- WORD wPlayerRole,
- WORD wRandomRange
- )
- /*++
- Purpose:
- Pick a magic for the specified player for automatic usage.
- Parameters:
- [IN] wPlayerRole - the player role ID.
- [IN] wRandomRange - the range of the magic power.
- Return value:
- The object ID of the selected magic. 0 for physical attack.
- --*/
- {
- WORD wMagic = 0, w, wMagicNum;
- int i, iMaxPower = 0, iPower;
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSilence] != 0)
- {
- return 0;
- }
- for (i = 0; i < MAX_PLAYER_MAGICS; i++)
- {
- w = gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole];
- if (w == 0)
- {
- continue;
- }
- wMagicNum = gpGlobals->g.rgObject[w].magic.wMagicNumber;
- //
- // skip if the magic is an ultimate move or not enough MP
- //
- if (gpGlobals->g.lprgMagic[wMagicNum].wCostMP == 1 ||
- gpGlobals->g.lprgMagic[wMagicNum].wCostMP > gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] ||
- (SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wBaseDamage) <= 0)
- {
- continue;
- }
- iPower = (SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wBaseDamage) +
- RandomLong(0, wRandomRange);
- if (iPower > iMaxPower)
- {
- iMaxPower = iPower;
- wMagic = w;
- }
- }
- return wMagic;
- }
- VOID
- PAL_BattleUIUpdate(
- VOID
- )
- /*++
- Purpose:
- Update the status of battle UI.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- int i, j, x, y;
- WORD wPlayerRole, w;
- static int s_iFrame = 0;
- s_iFrame++;
- if (g_Battle.UI.fAutoAttack && !gpGlobals->fAutoBattle)
- {
- //
- // Draw the "auto attack" message if in the autoattack mode.
- //
- if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.UI.fAutoAttack = FALSE;
- }
- else
- {
- PAL_DrawText(PAL_GetWord(BATTLEUI_LABEL_AUTO), PAL_XY(280, 10),
- MENUITEM_COLOR_CONFIRMED, TRUE, FALSE);
- }
- }
- if (gpGlobals->fAutoBattle)
- {
- PAL_BattlePlayerCheckReady();
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (g_Battle.rgPlayer[i].state == kFighterCom)
- {
- PAL_BattleUIPlayerReady(i);
- break;
- }
- }
- if (g_Battle.UI.state != kBattleUIWait)
- {
- w = PAL_BattleUIPickAutoMagic(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole, 9999);
- if (w == 0)
- {
- g_Battle.UI.wActionType = kBattleActionAttack;
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- else
- {
- g_Battle.UI.wActionType = kBattleActionMagic;
- g_Battle.UI.wObjectID = w;
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.wSelectedIndex = -1;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- }
- PAL_BattleCommitAction(FALSE);
- }
- goto end;
- }
- if (g_InputState.dwKeyPress & kKeyAuto)
- {
- g_Battle.UI.fAutoAttack = !g_Battle.UI.fAutoAttack;
- g_Battle.UI.MenuState = kBattleMenuMain;
- }
- #ifdef PAL_CLASSIC
- if (g_Battle.Phase == kBattlePhasePerformAction)
- {
- goto end;
- }
- if (!g_Battle.UI.fAutoAttack)
- #endif
- {
- //
- // Draw the player info boxes.
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- w = (WORD)(g_Battle.rgPlayer[i].flTimeMeter);
- j = TIMEMETER_COLOR_DEFAULT;
- #ifndef PAL_CLASSIC
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusHaste] > 0)
- {
- j = TIMEMETER_COLOR_HASTE;
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSlow] > 0)
- {
- j = TIMEMETER_COLOR_SLOW;
- }
- #endif
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] != 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] != 0)
- {
- w = 0;
- }
- PAL_PlayerInfoBox(PAL_XY(91 + 77 * i, 165), wPlayerRole,
- w, j, FALSE);
- }
- }
- if (g_InputState.dwKeyPress & kKeyStatus)
- {
- PAL_PlayerStatus();
- goto end;
- }
- if (g_Battle.UI.state != kBattleUIWait)
- {
- wPlayerRole = gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet])
- {
- g_Battle.UI.wActionType = kBattleActionAttack;
- if (PAL_PlayerCanAttackAll(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole))
- {
- g_Battle.UI.wSelectedIndex = -1;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- PAL_BattleCommitAction(FALSE);
- goto end; // don't go further
- }
- //
- // Cancel any actions if player is dead or sleeping.
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzed] != 0)
- {
- g_Battle.UI.wActionType = kBattleActionPass;
- PAL_BattleCommitAction(FALSE);
- goto end; // don't go further
- }
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] != 0)
- {
- g_Battle.UI.wActionType = kBattleActionAttackMate;
- PAL_BattleCommitAction(FALSE);
- goto end; // don't go further
- }
- if (g_Battle.UI.fAutoAttack)
- {
- g_Battle.UI.wActionType = kBattleActionAttack;
- if (PAL_PlayerCanAttackAll(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole))
- {
- g_Battle.UI.wSelectedIndex = -1;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- PAL_BattleCommitAction(FALSE);
- goto end; // don't go further
- }
- //
- // Draw the arrow on the player's head.
- //
- i = SPRITENUM_BATTLE_ARROW_CURRENTPLAYER_RED;
- if (s_iFrame & 1)
- {
- i = SPRITENUM_BATTLE_ARROW_CURRENTPLAYER;
- }
- x = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][g_Battle.UI.wCurPlayerIndex][0] - 8;
- y = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][g_Battle.UI.wCurPlayerIndex][1] - 74;
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, i), gpScreen, PAL_XY(x, y));
- }
- switch (g_Battle.UI.state)
- {
- case kBattleUIWait:
- if (!g_Battle.fEnemyCleared)
- {
- PAL_BattlePlayerCheckReady();
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (g_Battle.rgPlayer[i].state == kFighterCom)
- {
- PAL_BattleUIPlayerReady(i);
- break;
- }
- }
- }
- break;
- case kBattleUISelectMove:
- //
- // Draw the icons
- //
- {
- struct {
- int iSpriteNum;
- PAL_POS pos;
- BATTLEUIACTION action;
- } rgItems[] =
- {
- {SPRITENUM_BATTLEICON_ATTACK, PAL_XY(27, 140), kBattleUIActionAttack},
- {SPRITENUM_BATTLEICON_MAGIC, PAL_XY(0, 155), kBattleUIActionMagic},
- {SPRITENUM_BATTLEICON_COOPMAGIC, PAL_XY(54, 155), kBattleUIActionCoopMagic},
- {SPRITENUM_BATTLEICON_MISCMENU, PAL_XY(27, 170), kBattleUIActionMisc}
- };
- if (g_Battle.UI.MenuState == kBattleMenuMain)
- {
- if (g_InputState.dir == kDirNorth)
- {
- g_Battle.UI.wSelectedAction = 0;
- }
- else if (g_InputState.dir == kDirSouth)
- {
- g_Battle.UI.wSelectedAction = 3;
- }
- else if (g_InputState.dir == kDirWest)
- {
- if (PAL_BattleUIIsActionValid(kBattleUIActionMagic))
- {
- g_Battle.UI.wSelectedAction = 1;
- }
- }
- else if (g_InputState.dir == kDirEast)
- {
- if (PAL_BattleUIIsActionValid(kBattleUIActionCoopMagic))
- {
- g_Battle.UI.wSelectedAction = 2;
- }
- }
- }
- if (!PAL_BattleUIIsActionValid(rgItems[g_Battle.UI.wSelectedAction].action))
- {
- g_Battle.UI.wSelectedAction = 0;
- }
- for (i = 0; i < 4; i++)
- {
- if (g_Battle.UI.wSelectedAction == i)
- {
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, rgItems[i].iSpriteNum),
- gpScreen, rgItems[i].pos);
- }
- else if (PAL_BattleUIIsActionValid(rgItems[i].action))
- {
- PAL_RLEBlitMonoColor(PAL_SpriteGetFrame(gpSpriteUI, rgItems[i].iSpriteNum),
- gpScreen, rgItems[i].pos, 0, -4);
- }
- else
- {
- PAL_RLEBlitMonoColor(PAL_SpriteGetFrame(gpSpriteUI, rgItems[i].iSpriteNum),
- gpScreen, rgItems[i].pos, 0x10, -4);
- }
- }
- switch (g_Battle.UI.MenuState)
- {
- case kBattleMenuMain:
- if (g_InputState.dwKeyPress & kKeySearch)
- {
- switch (g_Battle.UI.wSelectedAction)
- {
- case 0:
- //
- // Attack
- //
- g_Battle.UI.wActionType = kBattleActionAttack;
- if (PAL_PlayerCanAttackAll(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole))
- {
- g_Battle.UI.state = kBattleUISelectTargetEnemyAll;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wPrevEnemyTarget;
- g_Battle.UI.state = kBattleUISelectTargetEnemy;
- }
- break;
- case 1:
- //
- // Magic
- //
- g_Battle.UI.MenuState = kBattleMenuMagicSelect;
- PAL_MagicSelectionMenuInit(wPlayerRole, TRUE, 0);
- break;
- case 2:
- //
- // Cooperative magic
- //
- w = gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole;
- w = PAL_GetPlayerCooperativeMagic(w);
- g_Battle.UI.wActionType = kBattleActionCoopMagic;
- g_Battle.UI.wObjectID = w;
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagUsableToEnemy)
- {
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetEnemyAll;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wPrevEnemyTarget;
- g_Battle.UI.state = kBattleUISelectTargetEnemy;
- }
- }
- else
- {
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetPlayerAll;
- }
- else
- {
- #ifdef PAL_CLASSIC
- g_Battle.UI.wSelectedIndex = 0;
- #else
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wCurPlayerIndex;
- #endif
- g_Battle.UI.state = kBattleUISelectTargetPlayer;
- }
- }
- break;
- case 3:
- //
- // Misc menu
- //
- g_Battle.UI.MenuState = kBattleMenuMisc;
- g_iCurMiscMenuItem = 0;
- break;
- }
- }
- else if (g_InputState.dwKeyPress & kKeyDefend)
- {
- g_Battle.UI.wActionType = kBattleActionDefend;
- PAL_BattleCommitAction(FALSE);
- }
- else if (g_InputState.dwKeyPress & kKeyForce)
- {
- w = PAL_BattleUIPickAutoMagic(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole, 60);
- if (w == 0)
- {
- g_Battle.UI.wActionType = kBattleActionAttack;
- if (PAL_PlayerCanAttackAll(gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole))
- {
- g_Battle.UI.wSelectedIndex = -1;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- }
- else
- {
- g_Battle.UI.wActionType = kBattleActionMagic;
- g_Battle.UI.wObjectID = w;
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.wSelectedIndex = -1;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = PAL_BattleSelectAutoTarget();
- }
- }
- PAL_BattleCommitAction(FALSE);
- }
- else if (g_InputState.dwKeyPress & kKeyFlee)
- {
- g_Battle.UI.wActionType = kBattleActionFlee;
- PAL_BattleCommitAction(FALSE);
- }
- else if (g_InputState.dwKeyPress & kKeyUseItem)
- {
- g_Battle.UI.MenuState = kBattleMenuUseItemSelect;
- PAL_ItemSelectMenuInit(kItemFlagUsable);
- }
- else if (g_InputState.dwKeyPress & kKeyThrowItem)
- {
- g_Battle.UI.MenuState = kBattleMenuThrowItemSelect;
- PAL_ItemSelectMenuInit(kItemFlagThrowable);
- }
- else if (g_InputState.dwKeyPress & kKeyRepeat)
- {
- PAL_BattleCommitAction(TRUE);
- }
- #ifdef PAL_CLASSIC
- else if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].state = kFighterWait;
- g_Battle.UI.state = kBattleUIWait;
- if (g_Battle.UI.wCurPlayerIndex > 0)
- {
- //
- // Revert to the previous player
- //
- do
- {
- g_Battle.rgPlayer[--g_Battle.UI.wCurPlayerIndex].state = kFighterWait;
- if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType == kBattleActionThrowItem)
- {
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (gpGlobals->rgInventory[i].wItem ==
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID)
- {
- gpGlobals->rgInventory[i].nAmountInUse--;
- break;
- }
- }
- }
- else if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType == kBattleActionUseItem)
- {
- if (gpGlobals->g.rgObject[g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID].item.wFlags & kItemFlagConsuming)
- {
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (gpGlobals->rgInventory[i].wItem ==
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID)
- {
- gpGlobals->rgInventory[i].nAmountInUse--;
- break;
- }
- }
- }
- }
- } while (g_Battle.UI.wCurPlayerIndex > 0 &&
- (gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole] == 0 ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole][kStatusConfused] > 0 ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole][kStatusParalyzed] > 0));
- }
- }
- #else
- else if (g_InputState.dwKeyPress & kKeyMenu)
- {
- float flMin = -1;
- j = -1;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (g_Battle.rgPlayer[i].flTimeMeter >= 100)
- {
- g_Battle.rgPlayer[i].flTimeMeter += 100; // HACKHACK: Prevent the time meter from going below 100
- if ((g_Battle.rgPlayer[i].flTimeMeter < flMin || flMin < 0) &&
- i != (int)g_Battle.UI.wCurPlayerIndex &&
- g_Battle.rgPlayer[i].state == kFighterWait)
- {
- flMin = g_Battle.rgPlayer[i].flTimeMeter;
- j = i;
- }
- }
- }
- if (j != -1)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].flTimeMeter = flMin - 99;
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].state = kFighterWait;
- g_Battle.UI.state = kBattleUIWait;
- }
- }
- #endif
- break;
- case kBattleMenuMagicSelect:
- w = PAL_MagicSelectionMenuUpdate();
- if (w != 0xFFFF)
- {
- g_Battle.UI.MenuState = kBattleMenuMain;
- if (w != 0)
- {
- g_Battle.UI.wActionType = kBattleActionMagic;
- g_Battle.UI.wObjectID = w;
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagUsableToEnemy)
- {
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetEnemyAll;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wPrevEnemyTarget;
- g_Battle.UI.state = kBattleUISelectTargetEnemy;
- }
- }
- else
- {
- if (gpGlobals->g.rgObject[w].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.UI.state = kBattleUISelectTargetPlayerAll;
- }
- else
- {
- #ifdef PAL_CLASSIC
- g_Battle.UI.wSelectedIndex = 0;
- #else
- g_Battle.UI.wSelectedIndex = g_Battle.UI.wCurPlayerIndex;
- #endif
- g_Battle.UI.state = kBattleUISelectTargetPlayer;
- }
- }
- }
- }
- break;
- case kBattleMenuUseItemSelect:
- PAL_BattleUIUseItem();
- break;
- case kBattleMenuThrowItemSelect:
- PAL_BattleUIThrowItem();
- break;
- case kBattleMenuMisc:
- w = PAL_BattleUIMiscMenuUpdate();
- if (w != 0xFFFF)
- {
- g_Battle.UI.MenuState = kBattleMenuMain;
- switch (w)
- {
- #ifdef PAL_CLASSIC
- case 2: // item
- #else
- case 1: // item
- #endif
- g_Battle.UI.MenuState = kBattleMenuMiscItemSubMenu;
- g_iCurSubMenuItem = 0;
- break;
- #ifdef PAL_CLASSIC
- case 3: // defend
- #else
- case 2: // defend
- #endif
- g_Battle.UI.wActionType = kBattleActionDefend;
- PAL_BattleCommitAction(FALSE);
- break;
- #ifdef PAL_CLASSIC
- case 1: // auto
- #else
- case 3: // auto
- #endif
- g_Battle.UI.fAutoAttack = TRUE;
- break;
- case 4: // flee
- g_Battle.UI.wActionType = kBattleActionFlee;
- PAL_BattleCommitAction(FALSE);
- break;
- case 5: // status
- PAL_PlayerStatus();
- break;
- }
- }
- break;
- case kBattleMenuMiscItemSubMenu:
- w = PAL_BattleUIMiscItemSubMenuUpdate();
- if (w != 0xFFFF)
- {
- g_Battle.UI.MenuState = kBattleMenuMain;
- switch (w)
- {
- case 1: // use
- g_Battle.UI.MenuState = kBattleMenuUseItemSelect;
- PAL_ItemSelectMenuInit(kItemFlagUsable);
- break;
- case 2: // throw
- g_Battle.UI.MenuState = kBattleMenuThrowItemSelect;
- PAL_ItemSelectMenuInit(kItemFlagThrowable);
- break;
- }
- }
- break;
- }
- }
- break;
- case kBattleUISelectTargetEnemy:
- x = -1;
- y = 0;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID != 0)
- {
- x = i;
- y++;
- }
- }
- if (x == -1)
- {
- g_Battle.UI.state = kBattleUISelectMove;
- break;
- }
- if (g_Battle.UI.wActionType == kBattleActionCoopMagic)
- {
- if (!PAL_BattleUIIsActionValid(kBattleActionCoopMagic))
- {
- g_Battle.UI.state = kBattleUISelectMove;
- break;
- }
- }
- #ifdef PAL_CLASSIC
- //
- // Don't bother selecting when only 1 enemy left
- //
- if (y == 1)
- {
- g_Battle.UI.wPrevEnemyTarget = (WORD)x;
- PAL_BattleCommitAction(FALSE);
- break;
- }
- #endif
- if (g_Battle.UI.wSelectedIndex > x)
- {
- g_Battle.UI.wSelectedIndex = x;
- }
- for (i = 0; i <= x; i++)
- {
- if (g_Battle.rgEnemy[g_Battle.UI.wSelectedIndex].wObjectID != 0)
- {
- break;
- }
- g_Battle.UI.wSelectedIndex++;
- g_Battle.UI.wSelectedIndex %= x + 1;
- }
- //
- // Highlight the selected enemy
- //
- if (s_iFrame & 1)
- {
- i = g_Battle.UI.wSelectedIndex;
- x = PAL_X(g_Battle.rgEnemy[i].pos);
- y = PAL_Y(g_Battle.rgEnemy[i].pos);
- x -= PAL_RLEGetWidth(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame)) / 2;
- y -= PAL_RLEGetHeight(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame));
- PAL_RLEBlitWithColorShift(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame),
- gpScreen, PAL_XY(x, y), 7);
- }
- if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.UI.state = kBattleUISelectMove;
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- g_Battle.UI.wPrevEnemyTarget = g_Battle.UI.wSelectedIndex;
- PAL_BattleCommitAction(FALSE);
- }
- else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyDown))
- {
- if (g_Battle.UI.wSelectedIndex != 0)
- {
- g_Battle.UI.wSelectedIndex--;
- while (g_Battle.UI.wSelectedIndex != 0 &&
- g_Battle.rgEnemy[g_Battle.UI.wSelectedIndex].wObjectID == 0)
- {
- g_Battle.UI.wSelectedIndex--;
- }
- }
- }
- else if (g_InputState.dwKeyPress & (kKeyRight | kKeyUp))
- {
- if (g_Battle.UI.wSelectedIndex < x)
- {
- g_Battle.UI.wSelectedIndex++;
- while (g_Battle.UI.wSelectedIndex < x &&
- g_Battle.rgEnemy[g_Battle.UI.wSelectedIndex].wObjectID == 0)
- {
- g_Battle.UI.wSelectedIndex++;
- }
- }
- }
- break;
- case kBattleUISelectTargetPlayer:
- #ifdef PAL_CLASSIC
- //
- // Don't bother selecting when only 1 player is in the party
- //
- if (gpGlobals->wMaxPartyMemberIndex == 0)
- {
- g_Battle.UI.wSelectedIndex = 0;
- PAL_BattleCommitAction(FALSE);
- }
- #endif
- j = SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER;
- if (s_iFrame & 1)
- {
- j = SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER_RED;
- }
- //
- // Draw arrows on the selected player
- //
- x = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][g_Battle.UI.wSelectedIndex][0] - 8;
- y = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][g_Battle.UI.wSelectedIndex][1] - 67;
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, j), gpScreen, PAL_XY(x, y));
- if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.UI.state = kBattleUISelectMove;
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- PAL_BattleCommitAction(FALSE);
- }
- else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyDown))
- {
- if (g_Battle.UI.wSelectedIndex != 0)
- {
- g_Battle.UI.wSelectedIndex--;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = gpGlobals->wMaxPartyMemberIndex;
- }
- }
- else if (g_InputState.dwKeyPress & (kKeyRight | kKeyUp))
- {
- if (g_Battle.UI.wSelectedIndex < gpGlobals->wMaxPartyMemberIndex)
- {
- g_Battle.UI.wSelectedIndex++;
- }
- else
- {
- g_Battle.UI.wSelectedIndex = 0;
- }
- }
- break;
- case kBattleUISelectTargetEnemyAll:
- #ifdef PAL_CLASSIC
- //
- // Don't bother selecting
- //
- g_Battle.UI.wSelectedIndex = (WORD)-1;
- PAL_BattleCommitAction(FALSE);
- #else
- if (g_Battle.UI.wActionType == kBattleActionCoopMagic)
- {
- if (!PAL_BattleUIIsActionValid(kBattleActionCoopMagic))
- {
- g_Battle.UI.state = kBattleUISelectMove;
- break;
- }
- }
- if (s_iFrame & 1)
- {
- //
- // Highlight all enemies
- //
- for (i = g_Battle.wMaxEnemyIndex; i >= 0; i--)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- x = PAL_X(g_Battle.rgEnemy[i].pos);
- y = PAL_Y(g_Battle.rgEnemy[i].pos);
- x -= PAL_RLEGetWidth(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame)) / 2;
- y -= PAL_RLEGetHeight(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame));
- PAL_RLEBlitWithColorShift(PAL_SpriteGetFrame(g_Battle.rgEnemy[i].lpSprite, g_Battle.rgEnemy[i].wCurrentFrame),
- gpScreen, PAL_XY(x, y), 7);
- }
- }
- if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.UI.state = kBattleUISelectMove;
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- g_Battle.UI.wSelectedIndex = (WORD)-1;
- PAL_BattleCommitAction(FALSE);
- }
- #endif
- break;
- case kBattleUISelectTargetPlayerAll:
- #ifdef PAL_CLASSIC
- //
- // Don't bother selecting
- //
- g_Battle.UI.wSelectedIndex = (WORD)-1;
- PAL_BattleCommitAction(FALSE);
- #else
- j = SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER;
- if (s_iFrame & 1)
- {
- j = SPRITENUM_BATTLE_ARROW_SELECTEDPLAYER_RED;
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (g_Battle.UI.wActionType == kBattleActionMagic)
- {
- w = gpGlobals->g.rgObject[g_Battle.UI.wObjectID].magic.wMagicNumber;
- if (gpGlobals->g.lprgMagic[w].wType == kMagicTypeTrance)
- {
- if (i != g_Battle.UI.wCurPlayerIndex)
- continue;
- }
- }
- //
- // Draw arrows on all players, despite of dead or not
- //
- x = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][0] - 8;
- y = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][1] - 67;
- PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, j), gpScreen, PAL_XY(x, y));
- }
- if (g_InputState.dwKeyPress & kKeyMenu)
- {
- g_Battle.UI.state = kBattleUISelectMove;
- }
- else if (g_InputState.dwKeyPress & kKeySearch)
- {
- g_Battle.UI.wSelectedIndex = (WORD)-1;
- PAL_BattleCommitAction(FALSE);
- }
- #endif
- break;
- }
- end:
- //
- // Show the text message if there is one.
- //
- #ifndef PAL_CLASSIC
- if (SDL_GetTicks() < g_Battle.UI.dwMsgShowTime)
- {
- //
- // The text should be shown in a small window at the center of the screen
- //
- PAL_POS pos;
- # ifdef PAL_UNICODE
- int i, w = wcslen(g_Battle.UI.szMsg), len = 0;
- for (i = 0; i < w; i++)
- len += PAL_CharWidth(g_Battle.UI.szMsg[i]) >> 3;
- # else
- int len = strlen(g_Battle.UI.szMsg);
- # endif
- //
- // Create the window box
- //
- pos = PAL_XY(160 - len * 4, 40);
- PAL_CreateSingleLineBox(pos, (len + 1) / 2, FALSE);
- //
- // Show the text on the screen
- //
- pos = PAL_XY(PAL_X(pos) + 8 + ((len & 1) << 2), PAL_Y(pos) + 10);
- PAL_DrawText(g_Battle.UI.szMsg, pos, 0, FALSE, FALSE);
- }
- else if (g_Battle.UI.szNextMsg[0] != '\0')
- {
- # ifdef PAL_UNICODE
- wcscpy(g_Battle.UI.szMsg, g_Battle.UI.szNextMsg);
- # else
- strcpy(g_Battle.UI.szMsg, g_Battle.UI.szNextMsg);
- # endif
- g_Battle.UI.dwMsgShowTime = SDL_GetTicks() + g_Battle.UI.wNextMsgDuration;
- g_Battle.UI.szNextMsg[0] = '\0';
- }
- #endif
- //
- // Draw the numbers
- //
- for (i = 0; i < BATTLEUI_MAX_SHOWNUM; i++)
- {
- if (g_Battle.UI.rgShowNum[i].wNum > 0)
- {
- if ((SDL_GetTicks() - g_Battle.UI.rgShowNum[i].dwTime) / BATTLE_FRAME_TIME > 10)
- {
- g_Battle.UI.rgShowNum[i].wNum = 0;
- }
- else
- {
- PAL_DrawNumber(g_Battle.UI.rgShowNum[i].wNum, 5,
- PAL_XY(PAL_X(g_Battle.UI.rgShowNum[i].pos), PAL_Y(g_Battle.UI.rgShowNum[i].pos) - (SDL_GetTicks() - g_Battle.UI.rgShowNum[i].dwTime) / BATTLE_FRAME_TIME),
- g_Battle.UI.rgShowNum[i].color, kNumAlignRight);
- }
- }
- }
- PAL_ClearKeyState();
- }
- VOID
- PAL_BattleUIShowNum(
- WORD wNum,
- PAL_POS pos,
- NUMCOLOR color
- )
- /*++
- Purpose:
- Show a number on battle screen (indicates HP/MP change).
- Parameters:
- [IN] wNum - number to be shown.
- [IN] pos - position of the number on the screen.
- [IN] color - color of the number.
- Return value:
- None.
- --*/
- {
- int i;
- for (i = 0; i < BATTLEUI_MAX_SHOWNUM; i++)
- {
- if (g_Battle.UI.rgShowNum[i].wNum == 0)
- {
- g_Battle.UI.rgShowNum[i].wNum = wNum;
- g_Battle.UI.rgShowNum[i].pos = PAL_XY(PAL_X(pos) - 15, PAL_Y(pos));
- g_Battle.UI.rgShowNum[i].color = color;
- g_Battle.UI.rgShowNum[i].dwTime = SDL_GetTicks();
- break;
- }
- }
- }
|