123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426 |
- /* -*- 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.
- //
- // Based on PALx Project by palxex.
- // Copyright (c) 2006-2008, Pal Lockheart <palxex@gmail.com>.
- //
- // 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/>.
- //
- #include "main.h"
- BOOL g_fScriptSuccess = TRUE;
- static int g_iCurEquipPart = -1;
- static BOOL
- PAL_NPCWalkTo(
- WORD wEventObjectID,
- INT x,
- INT y,
- INT h,
- INT iSpeed
- )
- /*++
- Purpose:
- Make the specified event object walk to the map position specified by (x, y, h)
- at the speed of iSpeed.
- Parameters:
- [IN] wEventObjectID - the event object to move.
- [IN] x - Column number of the tile.
- [IN] y - Line number in the map.
- [IN] h - Each line in the map has two lines of tiles, 0 and 1.
- (See map.h for details.)
- [IN] iSpeed - the speed to move.
- Return value:
- TRUE if the event object has successfully moved to the specified position,
- FALSE if still need more moving.
- --*/
- {
- LPEVENTOBJECT pEvtObj;
- int xOffset, yOffset;
- pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
- xOffset = (x * 32 + h * 16) - pEvtObj->x;
- yOffset = (y * 16 + h * 8) - pEvtObj->y;
- if (yOffset < 0)
- {
- pEvtObj->wDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
- }
- else
- {
- pEvtObj->wDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
- }
- if (abs(xOffset) < iSpeed * 2 || abs(yOffset) < iSpeed * 2)
- {
- pEvtObj->x = x * 32 + h * 16;
- pEvtObj->y = y * 16 + h * 8;
- }
- else
- {
- PAL_NPCWalkOneStep(wEventObjectID, iSpeed);
- }
- if (pEvtObj->x == x * 32 + h * 16 && pEvtObj->y == y * 16 + h * 8)
- {
- pEvtObj->wCurrentFrameNum = 0;
- return TRUE;
- }
- return FALSE;
- }
- static VOID
- PAL_PartyWalkTo(
- INT x,
- INT y,
- INT h,
- INT iSpeed
- )
- /*++
- Purpose:
- Make the party walk to the map position specified by (x, y, h)
- at the speed of iSpeed.
- Parameters:
- [IN] x - Column number of the tile.
- [IN] y - Line number in the map.
- [IN] h - Each line in the map has two lines of tiles, 0 and 1.
- (See map.h for details.)
- [IN] iSpeed - the speed to move.
- Return value:
- None.
- --*/
- {
- int xOffset, yOffset, i, dx, dy;
- DWORD t;
- xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
- yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
- t = 0;
- while (xOffset != 0 || yOffset != 0)
- {
- PAL_ProcessEvent();
- while (SDL_GetTicks() <= t)
- {
- PAL_ProcessEvent();
- SDL_Delay(1);
- }
- t = SDL_GetTicks() + FRAME_TIME;
- //
- // Store trail
- //
- for (i = 3; i >= 0; i--)
- {
- gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
- }
- gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
- gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
- gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
- if (yOffset < 0)
- {
- gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
- }
- else
- {
- gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
- }
- dx = PAL_X(gpGlobals->viewport);
- dy = PAL_Y(gpGlobals->viewport);
- if (abs(xOffset) <= iSpeed * 2)
- {
- dx += xOffset;
- }
- else
- {
- dx += iSpeed * (xOffset < 0 ? -2 : 2);
- }
- if (abs(yOffset) <= iSpeed)
- {
- dy += yOffset;
- }
- else
- {
- dy += iSpeed * (yOffset < 0 ? -1 : 1);
- }
- //
- // Move the viewport
- //
- gpGlobals->viewport = PAL_XY(dx, dy);
- PAL_UpdatePartyGestures(TRUE);
- PAL_GameUpdate(FALSE);
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
- yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
- }
- PAL_UpdatePartyGestures(FALSE);
- }
- static VOID
- PAL_PartyRideEventObject(
- WORD wEventObjectID,
- INT x,
- INT y,
- INT h,
- INT iSpeed
- )
- /*++
- Purpose:
- Move the party to the specified position, riding the specified event object.
- Parameters:
- [IN] wEventObjectID - the event object to be ridden.
- [IN] x - Column number of the tile.
- [IN] y - Line number in the map.
- [IN] h - Each line in the map has two lines of tiles, 0 and 1.
- (See map.h for details.)
- [IN] iSpeed - the speed to move.
- Return value:
- TRUE if the party and event object has successfully moved to the specified
- position, FALSE if still need more moving.
- --*/
- {
- int xOffset, yOffset, dx, dy, i;
- DWORD t;
- LPEVENTOBJECT p;
- p = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
- xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
- yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
- t = 0;
- while (xOffset != 0 || yOffset != 0)
- {
- PAL_ProcessEvent();
- while (SDL_GetTicks() <= t)
- {
- PAL_ProcessEvent();
- SDL_Delay(1);
- }
- t = SDL_GetTicks() + FRAME_TIME;
- if (yOffset < 0)
- {
- gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
- }
- else
- {
- gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
- }
- if (abs(xOffset) > iSpeed * 2)
- {
- dx = iSpeed * (xOffset < 0 ? -2 : 2);
- }
- else
- {
- dx = xOffset;
- }
- if (abs(yOffset) > iSpeed)
- {
- dy = iSpeed * (yOffset < 0 ? -1 : 1);
- }
- else
- {
- dy = yOffset;
- }
- //
- // Store trail
- //
- for (i = 3; i >= 0; i--)
- {
- gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
- }
- gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
- gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + dx + PAL_X(gpGlobals->partyoffset);
- gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + dy + PAL_Y(gpGlobals->partyoffset);
- //
- // Move the viewport
- //
- gpGlobals->viewport =
- PAL_XY(PAL_X(gpGlobals->viewport) + dx, PAL_Y(gpGlobals->viewport) + dy);
- p->x += dx;
- p->y += dy;
- PAL_GameUpdate(FALSE);
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
- yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
- }
- }
- static VOID
- PAL_MonsterChasePlayer(
- WORD wEventObjectID,
- WORD wSpeed,
- WORD wChaseRange,
- BOOL fFloating
- )
- /*++
- Purpose:
- Make the specified event object chase the players.
- Parameters:
- [IN] wEventObjectID - the event object ID of the monster.
- [IN] wSpeed - the speed of chasing.
- [IN] wChaseRange - sensitive range of the monster.
- [IN] fFloating - TRUE if monster is floating (i.e., ignore the obstacles)
- Return value:
- None.
- --*/
- {
- LPEVENTOBJECT pEvtObj = &gpGlobals->g.lprgEventObject[wEventObjectID - 1];
- WORD wMonsterSpeed = 0, prevx, prevy;
- int x, y, i, j, l;
- if (gpGlobals->wChaseRange != 0)
- {
- x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset) - pEvtObj->x;
- y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset) - pEvtObj->y;
- if (x == 0)
- {
- x = RandomLong(0, 1) ? -1 : 1;
- }
- if (y == 0)
- {
- y = RandomLong(0, 1) ? -1 : 1;
- }
- prevx = pEvtObj->x;
- prevy = pEvtObj->y;
- i = prevx % 32;
- j = prevy % 16;
- prevx /= 32;
- prevy /= 16;
- l = 0;
- if (i + j * 2 >= 16)
- {
- if (i + j * 2 >= 48)
- {
- prevx++;
- prevy++;
- }
- else if (32 - i + j * 2 < 16)
- {
- prevx++;
- }
- else if (32 - i + j * 2 < 48)
- {
- l = 1;
- }
- else
- {
- prevy++;
- }
- }
- prevx = prevx * 32 + l * 16;
- prevy = prevy * 16 + l * 8;
- //
- // Is the party near to the event object?
- //
- if (abs(x) + abs(y) * 2 < wChaseRange * 32 * gpGlobals->wChaseRange)
- {
- if (x < 0)
- {
- if (y < 0)
- {
- pEvtObj->wDirection = kDirWest;
- }
- else
- {
- pEvtObj->wDirection = kDirSouth;
- }
- }
- else
- {
- if (y < 0)
- {
- pEvtObj->wDirection = kDirNorth;
- }
- else
- {
- pEvtObj->wDirection = kDirEast;
- }
- }
- if (x != 0)
- {
- x = pEvtObj->x + x / abs(x) * 16;
- }
- else
- {
- x = pEvtObj->x;
- }
- if (y != 0)
- {
- y = pEvtObj->y + y / abs(y) * 8;
- }
- else
- {
- y = pEvtObj->y;
- }
- if (fFloating)
- {
- wMonsterSpeed = wSpeed;
- }
- else
- {
- if (!PAL_CheckObstacle(PAL_XY(x, y), TRUE, wEventObjectID))
- {
- wMonsterSpeed = wSpeed;
- }
- else
- {
- pEvtObj->x = prevx;
- pEvtObj->y = prevy;
- }
- for (l = 0; l < 4; l++)
- {
- switch (l)
- {
- case 0:
- pEvtObj->x -= 4;
- pEvtObj->y += 2;
- break;
- case 1:
- pEvtObj->x -= 4;
- pEvtObj->y -= 2;
- break;
- case 2:
- pEvtObj->x += 4;
- pEvtObj->y -= 2;
- break;
- case 3:
- pEvtObj->x += 4;
- pEvtObj->y += 2;
- break;
- }
- if (PAL_CheckObstacle(PAL_XY(pEvtObj->x, pEvtObj->y), FALSE, 0))
- {
- pEvtObj->x = prevx;
- pEvtObj->y = prevy;
- }
- }
- }
- }
- }
- PAL_NPCWalkOneStep(wEventObjectID, wMonsterSpeed);
- }
- static VOID
- PAL_AdditionalCredits(
- VOID
- )
- /*++
- Purpose:
- Show the additional credits.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- LPCSTR rgszStrings[] = {
- "SDLPAL (http://sdlpal.codeplex.com/)",
- #ifdef PAL_CLASSIC
- " (\xB8\x67\xA8\xE5\xAF\x53\xA7\x4F\xBD\x67 " __DATE__ ")",
- #else
- " (" __DATE__ ")",
- #endif
- " ",
- " (c) 2009-2011, Wei Mingzhi",
- " <whistler_wmz@users.sf.net>.",
- #ifdef __SYMBIAN32__
- " Symbian S60 \xB2\xBE\xB4\xD3 (c) 2009, netwan.",
- #endif
- #ifdef GPH
- " GPH Caanoo & Wiz \xB2\xBE\xB4\xD3 (c) 2011, Rikku2000.",
- #endif
- #ifdef GEKKO
- " Nintendo WII \xB2\xBE\xB4\xD3 (c) 2012, Rikku2000.",
- #endif
- #ifdef DINGOO
- " DINGOO & Dingux \xB2\xBE\xB4\xD3 (c) 2011, Rikku2000.",
- #endif
- " ",
- "\xA5\xBB\xB5\x7B\xA6\xA1\xAC\x4F\xA6\xDB\xA5\xD1\xB3\x6E\xC5\xE9\xA1\x41\xAB\xF6\xB7\xD3"
- " GNU General",
- "Public License (GPLv3) \xB5\x6F\xA7\x47",
- " ",
- " ...\xAB\xF6 Enter \xB5\xB2\xA7\xF4",
- ""
- };
- int i = 0;
- PAL_DrawOpeningMenuBackground();
- while (rgszStrings[i][0] != '\0')
- {
- PAL_DrawText(rgszStrings[i], PAL_XY(25, 20 + i * 16), DESCTEXT_COLOR, TRUE, FALSE);
- i++;
- }
- PAL_SetPalette(0, FALSE);
- VIDEO_UpdateScreen(NULL);
- PAL_WaitForKey(0);
- }
- static WORD
- PAL_InterpretInstruction(
- WORD wScriptEntry,
- WORD wEventObjectID
- )
- /*++
- Purpose:
- Interpret and execute one instruction in the script.
- Parameters:
- [IN] wScriptEntry - The script entry to execute.
- [IN] wEventObjectID - The event object ID which invoked the script.
- Return value:
- The address of the next script instruction to execute.
- --*/
- {
- LPEVENTOBJECT pEvtObj, pCurrent;
- LPSCRIPTENTRY pScript;
- int iPlayerRole, i, j, x, y;
- WORD w, wCurEventObjectID;
- pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
- if (wEventObjectID != 0)
- {
- pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
- }
- else
- {
- pEvtObj = NULL;
- }
- if (pScript->rgwOperand[0] == 0 || pScript->rgwOperand[0] == 0xFFFF)
- {
- pCurrent = pEvtObj;
- wCurEventObjectID = wEventObjectID;
- }
- else
- {
- i = pScript->rgwOperand[0] - 1;
- if (i > 0x9000)
- {
- // HACK for Dream 2.11 to avoid crash
- i -= 0x9000;
- }
- pCurrent = &(gpGlobals->g.lprgEventObject[i]);
- wCurEventObjectID = pScript->rgwOperand[0];
- }
- if (pScript->rgwOperand[0] < MAX_PLAYABLE_PLAYER_ROLES)
- {
- iPlayerRole = gpGlobals->rgParty[pScript->rgwOperand[0]].wPlayerRole;
- }
- else
- {
- iPlayerRole = gpGlobals->rgParty[0].wPlayerRole;
- }
- switch (pScript->wOperation)
- {
- case 0x000B:
- case 0x000C:
- case 0x000D:
- case 0x000E:
- //
- // walk one step
- //
- pEvtObj->wDirection = pScript->wOperation - 0x000B;
- PAL_NPCWalkOneStep(wEventObjectID, 2);
- break;
- case 0x000F:
- //
- // Set the direction and/or gesture for event object
- //
- if (pScript->rgwOperand[0] != 0xFFFF)
- {
- pEvtObj->wDirection = pScript->rgwOperand[0];
- }
- if (pScript->rgwOperand[1] != 0xFFFF)
- {
- pEvtObj->wCurrentFrameNum = pScript->rgwOperand[1];
- }
- break;
- case 0x0010:
- //
- // Walk straight to the specified position
- //
- if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 3))
- {
- wScriptEntry--;
- }
- break;
- case 0x0011:
- //
- // Walk straight to the specified position, at a lower speed
- //
- if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
- {
- if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 2))
- {
- wScriptEntry--;
- }
- }
- else
- {
- wScriptEntry--;
- }
- break;
- case 0x0012:
- //
- // Set the position of the event object, relative to the party
- //
- pCurrent->x =
- pScript->rgwOperand[1] + PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
- pCurrent->y =
- pScript->rgwOperand[2] + PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
- break;
- case 0x0013:
- //
- // Set the position of the event object
- //
- pCurrent->x = pScript->rgwOperand[1];
- pCurrent->y = pScript->rgwOperand[2];
- break;
- case 0x0014:
- //
- // Set the gesture of the event object
- //
- pEvtObj->wCurrentFrameNum = pScript->rgwOperand[0];
- pEvtObj->wDirection = kDirSouth;
- break;
- case 0x0015:
- //
- // Set the direction and gesture for a party member
- //
- gpGlobals->wPartyDirection = pScript->rgwOperand[0];
- gpGlobals->rgParty[pScript->rgwOperand[2]].wFrame =
- gpGlobals->wPartyDirection * 3 + pScript->rgwOperand[1];
- break;
- case 0x0016:
- //
- // Set the direction and gesture for an event object
- //
- if (pScript->rgwOperand[0] != 0)
- {
- pCurrent->wDirection = pScript->rgwOperand[1];
- pCurrent->wCurrentFrameNum = pScript->rgwOperand[2];
- }
- break;
- case 0x0017:
- //
- // set the player's extra attribute
- //
- {
- WORD *p;
- i = pScript->rgwOperand[0] - 0xB;
- p = (WORD *)(&gpGlobals->rgEquipmentEffect[i]); // HACKHACK
- p[pScript->rgwOperand[1] * MAX_PLAYER_ROLES + wEventObjectID] =
- (SHORT)pScript->rgwOperand[2];
- }
- break;
- case 0x0018:
- //
- // Equip the selected item
- //
- i = pScript->rgwOperand[0] - 0x0B;
- g_iCurEquipPart = i;
- //
- // The wEventObjectID parameter here should indicate the player role
- //
- PAL_RemoveEquipmentEffect(wEventObjectID, i);
- if (gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] != pScript->rgwOperand[1])
- {
- w = gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID];
- gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] = pScript->rgwOperand[1];
- PAL_AddItemToInventory(pScript->rgwOperand[1], -1);
- if (w != 0)
- {
- PAL_AddItemToInventory(w, 1);
- }
- gpGlobals->wLastUnequippedItem = w;
- }
- break;
- case 0x0019:
- //
- // Increase/decrease the player's attribute
- //
- {
- WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
- if (pScript->rgwOperand[2] == 0)
- {
- iPlayerRole = wEventObjectID;
- }
- else
- {
- iPlayerRole = pScript->rgwOperand[2] - 1;
- }
- p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] +=
- (SHORT)pScript->rgwOperand[1];
- }
- break;
- case 0x001A:
- //
- // Set player's stat
- //
- {
- WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
- if (g_iCurEquipPart != -1)
- {
- //
- // In the progress of equipping items
- //
- p = (WORD *)&(gpGlobals->rgEquipmentEffect[g_iCurEquipPart]);
- }
- if (pScript->rgwOperand[2] == 0)
- {
- //
- // Apply to the current player. The wEventObjectID should
- // indicate the player role.
- //
- iPlayerRole = wEventObjectID;
- }
- else
- {
- iPlayerRole = pScript->rgwOperand[2] - 1;
- }
- p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] =
- (SHORT)pScript->rgwOperand[1];
- }
- break;
- case 0x001B:
- //
- // Increase/decrease player's HP
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- PAL_IncreaseHPMP(w, (SHORT)(pScript->rgwOperand[1]), 0);
- }
- }
- else
- {
- //
- // Apply to one player. The wEventObjectID parameter should indicate the player role.
- //
- if (!PAL_IncreaseHPMP(wEventObjectID, (SHORT)(pScript->rgwOperand[1]), 0))
- {
- g_fScriptSuccess = FALSE;
- }
- }
- break;
- case 0x001C:
- //
- // Increase/decrease player's MP
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- PAL_IncreaseHPMP(w, 0, (SHORT)(pScript->rgwOperand[1]));
- }
- }
- else
- {
- //
- // Apply to one player. The wEventObjectID parameter should indicate the player role.
- //
- if (!PAL_IncreaseHPMP(wEventObjectID, 0, (SHORT)(pScript->rgwOperand[1])))
- {
- g_fScriptSuccess = FALSE;
- }
- }
- break;
- case 0x001D:
- //
- // Increase/decrease player's HP and MP
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- PAL_IncreaseHPMP(w,
- (SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1]));
- }
- }
- else
- {
- //
- // Apply to one player. The wEventObjectID parameter should indicate the player role.
- //
- if (!PAL_IncreaseHPMP(wEventObjectID,
- (SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1])))
- {
- g_fScriptSuccess = FALSE;
- }
- }
- break;
- case 0x001E:
- //
- // Increase or decrease cash by the specified amount
- //
- if ((SHORT)(pScript->rgwOperand[0]) < 0 &&
- gpGlobals->dwCash < (WORD)(-(SHORT)(pScript->rgwOperand[0])))
- {
- //
- // not enough cash
- //
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- else
- {
- gpGlobals->dwCash += (SHORT)(pScript->rgwOperand[0]);
- }
- break;
- case 0x001F:
- //
- // Add item to inventory
- //
- PAL_AddItemToInventory(pScript->rgwOperand[0], (SHORT)(pScript->rgwOperand[1]));
- break;
- case 0x0020:
- //
- // Remove item from inventory
- //
- if (!PAL_AddItemToInventory(pScript->rgwOperand[0],
- -((pScript->rgwOperand[1] == 0) ? 1 : pScript->rgwOperand[1])))
- {
- //
- // Try removing equipped item
- //
- x = pScript->rgwOperand[1];
- if (x == 0)
- {
- x = 1;
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- for (j = 0; j < MAX_PLAYER_EQUIPMENTS; j++)
- {
- if (gpGlobals->g.PlayerRoles.rgwEquipment[j][w] == pScript->rgwOperand[0])
- {
- PAL_RemoveEquipmentEffect(w, j);
- gpGlobals->g.PlayerRoles.rgwEquipment[j][w] = 0;
- if (--x == 0)
- {
- i = 9999;
- break;
- }
- }
- }
- }
- if (x > 0 && pScript->rgwOperand[2] != 0)
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- }
- break;
- case 0x0021:
- //
- // Inflict damage to the enemy
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Inflict damage to all enemies
- //
- for (i = 0;i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID != 0)
- {
- g_Battle.rgEnemy[i].e.wHealth -= pScript->rgwOperand[1];
- }
- }
- }
- else
- {
- //
- // Inflict damage to one enemy
- //
- g_Battle.rgEnemy[wEventObjectID].e.wHealth -= pScript->rgwOperand[1];
- }
- break;
- case 0x0022:
- //
- // Revive player
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- g_fScriptSuccess = FALSE;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[w] == 0)
- {
- gpGlobals->g.PlayerRoles.rgwHP[w] =
- gpGlobals->g.PlayerRoles.rgwMaxHP[w] * pScript->rgwOperand[1] / 10;
- PAL_CurePoisonByLevel(w, 3);
- for (x = 0; x < kStatusAll; x++)
- {
- PAL_RemovePlayerStatus(w, x);
- }
- g_fScriptSuccess = TRUE;
- }
- }
- }
- else
- {
- //
- // Apply to one player
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] == 0)
- {
- gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] =
- gpGlobals->g.PlayerRoles.rgwMaxHP[wEventObjectID] * pScript->rgwOperand[1] / 10;
- PAL_CurePoisonByLevel(wEventObjectID, 3);
- for (x = 0; x < kStatusAll; x++)
- {
- PAL_RemovePlayerStatus(wEventObjectID, x);
- }
- }
- else
- {
- g_fScriptSuccess = FALSE;
- }
- }
- break;
- case 0x0023:
- //
- // Remove equipment from the specified player
- //
- if (pScript->rgwOperand[1] == 0)
- {
- //
- // Remove all equipments
- //
- for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
- {
- w = gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole];
- if (w != 0)
- {
- PAL_AddItemToInventory(w, 1);
- gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole] = 0;
- }
- PAL_RemoveEquipmentEffect(iPlayerRole, i);
- }
- }
- else
- {
- w = gpGlobals->g.PlayerRoles.rgwEquipment[pScript->rgwOperand[1] - 1][iPlayerRole];
- if (w != 0)
- {
- PAL_RemoveEquipmentEffect(iPlayerRole, pScript->rgwOperand[1] - 1);
- PAL_AddItemToInventory(w, 1);
- gpGlobals->g.PlayerRoles.rgwEquipment[pScript->rgwOperand[1] - 1][iPlayerRole] = 0;
- }
- }
- break;
- case 0x0024:
- //
- // Set the autoscript entry address for an event object
- //
- if (pScript->rgwOperand[0] != 0)
- {
- pCurrent->wAutoScript = pScript->rgwOperand[1];
- }
- break;
- case 0x0025:
- //
- // Set the trigger script entry address for an event object
- //
- if (pScript->rgwOperand[0] != 0)
- {
- pCurrent->wTriggerScript = pScript->rgwOperand[1];
- }
- break;
- case 0x0026:
- //
- // Show the buy item menu
- //
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- PAL_BuyMenu(pScript->rgwOperand[0]);
- break;
- case 0x0027:
- //
- // Show the sell item menu
- //
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- PAL_SellMenu();
- break;
- case 0x0028:
- //
- // Apply poison to enemy
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- w = g_Battle.rgEnemy[i].wObjectID;
- if (w == 0)
- {
- continue;
- }
- if (RandomLong(0, 9) >=
- gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery)
- {
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID ==
- pScript->rgwOperand[1])
- {
- break;
- }
- }
- if (j >= MAX_POISONS)
- {
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID == 0)
- {
- g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID = pScript->rgwOperand[1];
- g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[pScript->rgwOperand[1]].poison.wEnemyScript, wEventObjectID);
- break;
- }
- }
- }
- }
- }
- }
- else
- {
- //
- // Apply to one enemy
- //
- w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
- if (RandomLong(0, 9) >=
- gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery)
- {
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID ==
- pScript->rgwOperand[1])
- {
- break;
- }
- }
- if (j >= MAX_POISONS)
- {
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID == 0)
- {
- g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID = pScript->rgwOperand[1];
- g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonScript =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[pScript->rgwOperand[1]].poison.wEnemyScript, wEventObjectID);
- break;
- }
- }
- }
- }
- }
- break;
- case 0x0029:
- //
- // Apply poison to player
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to everyone
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (RandomLong(1, 100) > PAL_GetPlayerPoisonResistance(w))
- {
- PAL_AddPoisonForPlayer(w, pScript->rgwOperand[1]);
- }
- }
- }
- else
- {
- //
- // Apply to one player
- //
- if (RandomLong(1, 100) > PAL_GetPlayerPoisonResistance(wEventObjectID))
- {
- PAL_AddPoisonForPlayer(wEventObjectID, pScript->rgwOperand[1]);
- }
- }
- break;
- case 0x002A:
- //
- // Cure poison by object ID for enemy
- //
- if (pScript->rgwOperand[0])
- {
- //
- // Apply to all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID == pScript->rgwOperand[1])
- {
- g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID = 0;
- g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript = 0;
- break;
- }
- }
- }
- }
- else
- {
- //
- // Apply to one enemy
- //
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID == pScript->rgwOperand[1])
- {
- g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID = 0;
- g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonScript = 0;
- break;
- }
- }
- }
- break;
- case 0x002B:
- //
- // Cure poison by object ID for player
- //
- if (pScript->rgwOperand[0])
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- PAL_CurePoisonByKind(w, pScript->rgwOperand[1]);
- }
- }
- else
- {
- PAL_CurePoisonByKind(wEventObjectID, pScript->rgwOperand[1]);
- }
- break;
- case 0x002C:
- //
- // Cure poisons by level
- //
- if (pScript->rgwOperand[0])
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- PAL_CurePoisonByLevel(w, pScript->rgwOperand[1]);
- }
- }
- else
- {
- PAL_CurePoisonByLevel(wEventObjectID, pScript->rgwOperand[1]);
- }
- break;
- case 0x002D:
- //
- // Set the status for player
- //
- PAL_SetPlayerStatus(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1]);
- break;
- case 0x002E:
- //
- // Set the status for enemy
- //
- w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
- #ifdef PAL_CLASSIC
- i = 9;
- #else
- i = ((pScript->rgwOperand[0] == kStatusSlow) ? 14 : 9);
- #endif
- if (RandomLong(0, i) >= gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery &&
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[pScript->rgwOperand[0]] == 0)
- {
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[pScript->rgwOperand[0]] = pScript->rgwOperand[1];
- }
- else
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- break;
- case 0x002F:
- //
- // Remove player's status
- //
- PAL_RemovePlayerStatus(wEventObjectID, pScript->rgwOperand[0]);
- break;
- case 0x0030:
- //
- // Increase player's stat temporarily by percent
- //
- {
- WORD *p = (WORD *)(&gpGlobals->rgEquipmentEffect[kBodyPartExtra]); // HACKHACK
- WORD *p1 = (WORD *)(&gpGlobals->g.PlayerRoles);
- if (pScript->rgwOperand[2] == 0)
- {
- iPlayerRole = wEventObjectID;
- }
- else
- {
- iPlayerRole = pScript->rgwOperand[2] - 1;
- }
- p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] =
- p1[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] *
- (SHORT)pScript->rgwOperand[1] / 100;
- }
- break;
- case 0x0031:
- //
- // Change battle sprite temporarily for player
- //
- gpGlobals->rgEquipmentEffect[kBodyPartExtra].rgwSpriteNumInBattle[wEventObjectID] =
- pScript->rgwOperand[0];
- break;
- case 0x0033:
- //
- // collect the enemy for items
- //
- if (g_Battle.rgEnemy[wEventObjectID].e.wCollectValue != 0)
- {
- gpGlobals->wCollectValue +=
- g_Battle.rgEnemy[wEventObjectID].e.wCollectValue;
- }
- else
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- break;
- case 0x0034:
- //
- // Transform collected enemies into items
- //
- if (gpGlobals->wCollectValue > 0)
- {
- char s[256];
- #ifdef PAL_CLASSIC
- i = RandomLong(1, gpGlobals->wCollectValue);
- if (i > 9)
- {
- i = 9;
- }
- #else
- i = RandomLong(1, 9);
- if (i > gpGlobals->wCollectValue)
- {
- i = gpGlobals->wCollectValue;
- }
- #endif
- gpGlobals->wCollectValue -= i;
- i--;
- PAL_AddItemToInventory(gpGlobals->g.lprgStore[0].rgwItems[i], 1);
- PAL_StartDialog(kDialogCenterWindow, 0, 0, FALSE);
- strcpy(s, PAL_GetWord(42));
- strcat(s, PAL_GetWord(gpGlobals->g.lprgStore[0].rgwItems[i]));
- PAL_ShowDialogText(s);
- }
- else
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- break;
- case 0x0035:
- //
- // Shake the screen
- //
- i = pScript->rgwOperand[1];
- if (i == 0)
- {
- i = 4;
- }
- VIDEO_ShakeScreen(pScript->rgwOperand[0], i);
- if (!pScript->rgwOperand[0])
- {
- VIDEO_UpdateScreen(NULL);
- }
- break;
- case 0x0036:
- //
- // Set the current playing RNG animation
- //
- gpGlobals->iCurPlayingRNG = pScript->rgwOperand[0];
- break;
- case 0x0037:
- //
- // Play RNG animation
- //
- PAL_RNGPlay(gpGlobals->iCurPlayingRNG,
- pScript->rgwOperand[0],
- pScript->rgwOperand[1] > 0 ? pScript->rgwOperand[1] : 999,
- pScript->rgwOperand[2] > 0 ? pScript->rgwOperand[2] : 16);
- break;
- case 0x0038:
- //
- // Teleport the party out of the scene
- //
- if (!gpGlobals->fInBattle &&
- gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport != 0)
- {
- gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport =
- PAL_RunTriggerScript(gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport, 0xFFFF);
- }
- else
- {
- //
- // failed
- //
- g_fScriptSuccess = FALSE;
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- break;
- case 0x0039:
- //
- // Drain HP from enemy
- //
- w = gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole;
- g_Battle.rgEnemy[wEventObjectID].e.wHealth -= pScript->rgwOperand[0];
- gpGlobals->g.PlayerRoles.rgwHP[w] += pScript->rgwOperand[0];
- if (gpGlobals->g.PlayerRoles.rgwHP[w] > gpGlobals->g.PlayerRoles.rgwMaxHP[w])
- {
- gpGlobals->g.PlayerRoles.rgwHP[w] = gpGlobals->g.PlayerRoles.rgwMaxHP[w];
- }
- break;
- case 0x003A:
- //
- // Player flee from the battle
- //
- if (g_Battle.fIsBoss)
- {
- //
- // Cannot flee from bosses
- //
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- else
- {
- PAL_BattlePlayerEscape();
- }
- break;
- case 0x003F:
- //
- // Ride the event object to the specified position, at a low speed
- //
- PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 2);
- break;
- case 0x0040:
- //
- // set the trigger method for a event object
- //
- if (pScript->rgwOperand[0] != 0)
- {
- pCurrent->wTriggerMode = pScript->rgwOperand[1];
- }
- break;
- case 0x0041:
- //
- // Mark the script as failed
- //
- g_fScriptSuccess = FALSE;
- break;
- case 0x0042:
- //
- // Simulate a magic for player
- //
- i = (SHORT)(pScript->rgwOperand[2]) - 1;
- if (i < 0)
- {
- i = wEventObjectID;
- }
- PAL_BattleSimulateMagic(i, pScript->rgwOperand[0], pScript->rgwOperand[1]);
- break;
- case 0x0043:
- //
- // Set background music
- //
- gpGlobals->wNumMusic = pScript->rgwOperand[0];
- PAL_PlayMUS(pScript->rgwOperand[0], (pScript->rgwOperand[0] != 0x3D), pScript->rgwOperand[1]);
- break;
- case 0x0044:
- //
- // Ride the event object to the specified position, at the normal speed
- //
- PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 4);
- break;
- case 0x0045:
- //
- // Set battle music
- //
- gpGlobals->wNumBattleMusic = pScript->rgwOperand[0];
- break;
- case 0x0046:
- //
- // Set the party position on the map
- //
- {
- int xOffset, yOffset, x, y;
- xOffset =
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
- ? 16 : -16);
- yOffset =
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
- ? 8 : -8);
- x = pScript->rgwOperand[0] * 32 + pScript->rgwOperand[2] * 16;
- y = pScript->rgwOperand[1] * 16 + pScript->rgwOperand[2] * 8;
- x -= PAL_X(gpGlobals->partyoffset);
- y -= PAL_Y(gpGlobals->partyoffset);
- gpGlobals->viewport = PAL_XY(x, y);
- x = PAL_X(gpGlobals->partyoffset);
- y = PAL_Y(gpGlobals->partyoffset);
- for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
- {
- gpGlobals->rgParty[i].x = x;
- gpGlobals->rgParty[i].y = y;
- gpGlobals->rgTrail[i].x = x + PAL_X(gpGlobals->viewport);
- gpGlobals->rgTrail[i].y = y + PAL_Y(gpGlobals->viewport);
- gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
- x += xOffset;
- y += yOffset;
- }
- }
- break;
- case 0x0047:
- //
- // Play sound effect
- //
- SOUND_Play(pScript->rgwOperand[0]);
- break;
- case 0x0049:
- //
- // Set the state of event object
- //
- pCurrent->sState = pScript->rgwOperand[1];
- break;
- case 0x004A:
- //
- // Set the current battlefield
- //
- gpGlobals->wNumBattleField = pScript->rgwOperand[0];
- break;
- case 0x004B:
- //
- // Nullify the event object for a short while
- //
- pEvtObj->sVanishTime = -15;
- break;
- case 0x004C:
- //
- // chase the player
- //
- i = pScript->rgwOperand[0]; // max. distance
- j = pScript->rgwOperand[1]; // speed
- if (i == 0)
- {
- i = 8;
- }
- if (j == 0)
- {
- j = 4;
- }
- PAL_MonsterChasePlayer(wEventObjectID, j, i, pScript->rgwOperand[2]);
- break;
- case 0x004D:
- //
- // wait for any key
- //
- PAL_WaitForKey(0);
- break;
- case 0x004E:
- //
- // Load the last saved game
- //
- PAL_FadeOut(1);
- PAL_InitGameData(gpGlobals->bCurrentSaveSlot);
- return 0; // don't go further
- case 0x004F:
- //
- // Fade the screen to red color (game over)
- //
- PAL_FadeToRed();
- break;
- case 0x0050:
- //
- // screen fade out
- //
- VIDEO_UpdateScreen(NULL);
- PAL_FadeOut(pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1);
- gpGlobals->fNeedToFadeIn = TRUE;
- break;
- case 0x0051:
- //
- // screen fade in
- //
- VIDEO_UpdateScreen(NULL);
- PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
- ((SHORT)(pScript->rgwOperand[0]) > 0) ? pScript->rgwOperand[0] : 1);
- gpGlobals->fNeedToFadeIn = FALSE;
- break;
- case 0x0052:
- //
- // hide the event object for a while, default 800 frames
- //
- pEvtObj->sState *= -1;
- pEvtObj->sVanishTime = (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 800);
- break;
- case 0x0053:
- //
- // use the day palette
- //
- gpGlobals->fNightPalette = FALSE;
- break;
- case 0x0054:
- //
- // use the night palette
- //
- gpGlobals->fNightPalette = TRUE;
- break;
- case 0x0055:
- //
- // Add magic to a player
- //
- i = pScript->rgwOperand[1];
- if (i == 0)
- {
- i = wEventObjectID;
- }
- else
- {
- i--;
- }
- PAL_AddMagic(i, pScript->rgwOperand[0]);
- break;
- case 0x0056:
- //
- // Remove magic from a player
- //
- i = pScript->rgwOperand[1];
- if (i == 0)
- {
- i = wEventObjectID;
- }
- else
- {
- i--;
- }
- PAL_RemoveMagic(i, pScript->rgwOperand[0]);
- break;
- case 0x0057:
- //
- // Set the base damage of magic according to MP value
- //
- i = ((pScript->rgwOperand[1] == 0) ? 8 : pScript->rgwOperand[1]);
- j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
- gpGlobals->g.lprgMagic[j].wBaseDamage =
- gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] * i;
- gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] = 0;
- break;
- case 0x0058:
- //
- // Jump if there is less than the specified number of the specified items
- // in the inventory
- //
- if (PAL_GetItemAmount(pScript->rgwOperand[0]) < (SHORT)(pScript->rgwOperand[1]))
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- break;
- case 0x0059:
- //
- // Change to the specified scene
- //
- if (pScript->rgwOperand[0] > 0 && pScript->rgwOperand[0] <= MAX_SCENES &&
- gpGlobals->wNumScene != pScript->rgwOperand[0])
- {
- //
- // Set data to load the scene in the next frame
- //
- gpGlobals->wNumScene = pScript->rgwOperand[0];
- PAL_SetLoadFlags(kLoadScene);
- gpGlobals->fEnteringScene = TRUE;
- gpGlobals->wLayer = 0;
- }
- break;
- case 0x005A:
- //
- // Halve the player's HP
- // The wEventObjectID parameter here should indicate the player role
- //
- gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] /= 2;
- break;
- case 0x005B:
- //
- // Halve the enemy's HP
- //
- w = g_Battle.rgEnemy[wEventObjectID].e.wHealth / 2 + 1;
- if (w > pScript->rgwOperand[0])
- {
- w = pScript->rgwOperand[0];
- }
- g_Battle.rgEnemy[wEventObjectID].e.wHealth -= w;
- break;
- case 0x005C:
- //
- // Hide for a while
- //
- g_Battle.iHidingTime = -(INT)(pScript->rgwOperand[0]);
- break;
- case 0x005D:
- //
- // Jump if player doesn't have the specified poison
- //
- if (!PAL_IsPlayerPoisonedByKind(wEventObjectID, pScript->rgwOperand[0]))
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- break;
- case 0x005E:
- //
- // Jump if enemy doesn't have the specified poison
- //
- for (i = 0; i < MAX_POISONS; i++)
- {
- if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[i].wPoisonID == pScript->rgwOperand[0])
- {
- break;
- }
- }
- if (i >= MAX_POISONS)
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- break;
- case 0x005F:
- //
- // Kill the player immediately
- // The wEventObjectID parameter here should indicate the player role
- //
- gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] = 0;
- break;
- case 0x0060:
- //
- // Immediate KO of the enemy
- //
- g_Battle.rgEnemy[wEventObjectID].e.wHealth = 0;
- break;
- case 0x0061:
- //
- // Jump if player is not poisoned
- //
- if (!PAL_IsPlayerPoisonedByLevel(wEventObjectID, 1))
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- break;
- case 0x0062:
- //
- // Pause enemy chasing for a while
- //
- gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
- gpGlobals->wChaseRange = 0;
- break;
- case 0x0063:
- //
- // Speed up enemy chasing for a while
- //
- gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
- gpGlobals->wChaseRange = 3;
- break;
- case 0x0064:
- //
- // Jump if enemy's HP is more than the specified percentage
- //
- i = gpGlobals->g.rgObject[g_Battle.rgEnemy[wEventObjectID].wObjectID].enemy.wEnemyID;
- if ((INT)(g_Battle.rgEnemy[wEventObjectID].e.wHealth) * 100 >
- (INT)(gpGlobals->g.lprgEnemy[i].wHealth) * pScript->rgwOperand[0])
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- break;
- case 0x0065:
- //
- // Set the player's sprite
- //
- gpGlobals->g.PlayerRoles.rgwSpriteNum[pScript->rgwOperand[0]] = pScript->rgwOperand[1];
- if (!gpGlobals->fInBattle && pScript->rgwOperand[2])
- {
- PAL_SetLoadFlags(kLoadPlayerSprite);
- PAL_LoadResources();
- }
- break;
- case 0x0066:
- //
- // Throw weapon to enemy
- //
- w = pScript->rgwOperand[1] * 5;
- w += gpGlobals->g.PlayerRoles.rgwAttackStrength[gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole];
- w += RandomLong(0, 4);
- PAL_BattleSimulateMagic((SHORT)wEventObjectID, pScript->rgwOperand[0], w);
- break;
- case 0x0067:
- //
- // Enemy use magic
- //
- g_Battle.rgEnemy[wEventObjectID].e.wMagic = pScript->rgwOperand[0];
- g_Battle.rgEnemy[wEventObjectID].e.wMagicRate =
- ((pScript->rgwOperand[1] == 0) ? 10 : pScript->rgwOperand[1]);
- break;
- case 0x0068:
- //
- // Jump if it's enemy's turn
- //
- if (g_Battle.fEnemyMoving)
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- }
- break;
- case 0x0069:
- //
- // Enemy escape in battle
- //
- PAL_BattleEnemyEscape();
- break;
- case 0x006A:
- //
- // Steal from the enemy
- //
- PAL_BattleStealFromEnemy(wEventObjectID, pScript->rgwOperand[0]);
- break;
- case 0x006B:
- //
- // Blow away enemies
- //
- g_Battle.iBlow = (SHORT)(pScript->rgwOperand[0]);
- break;
- case 0x006C:
- //
- // Walk the NPC in one step
- //
- pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
- pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
- PAL_NPCWalkOneStep(wCurEventObjectID, 0);
- break;
- case 0x006D:
- //
- // Set the enter script and teleport script for a scene
- //
- if (pScript->rgwOperand[0])
- {
- if (pScript->rgwOperand[1])
- {
- gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter =
- pScript->rgwOperand[1];
- }
- if (pScript->rgwOperand[2])
- {
- gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport =
- pScript->rgwOperand[2];
- }
- if (pScript->rgwOperand[1] == 0 && pScript->rgwOperand[2] == 0)
- {
- gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter = 0;
- gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport = 0;
- }
- }
- break;
- case 0x006E:
- //
- // Move the player to the specified position in one step
- //
- for (i = 3; i >= 0; i--)
- {
- gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
- }
- gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
- gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
- gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
- gpGlobals->viewport = PAL_XY(
- PAL_X(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[0]),
- PAL_Y(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[1]));
- gpGlobals->wLayer = pScript->rgwOperand[2] * 8;
- if (pScript->rgwOperand[0] != 0 || pScript->rgwOperand[1] != 0)
- {
- PAL_UpdatePartyGestures(TRUE);
- }
- break;
- case 0x006F:
- //
- // Sync the state of current event object with another event object
- //
- if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
- {
- pEvtObj->sState = (SHORT)(pScript->rgwOperand[1]);
- }
- break;
- case 0x0070:
- //
- // Walk the party to the specified position
- //
- PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 2);
- break;
- case 0x0071:
- //
- // Wave the screen
- //
- gpGlobals->wScreenWave = pScript->rgwOperand[0];
- gpGlobals->sWaveProgression = (SHORT)(pScript->rgwOperand[1]);
- break;
- case 0x0073:
- //
- // Fade the screen to scene
- //
- VIDEO_BackupScreen();
- PAL_MakeScene();
- VIDEO_FadeScreen(pScript->rgwOperand[0]);
- break;
- case 0x0074:
- //
- // Jump if not all players are full HP
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[w] < gpGlobals->g.PlayerRoles.rgwMaxHP[w])
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- break;
- }
- }
- break;
- case 0x0075:
- //
- // Set the player party
- //
- gpGlobals->wMaxPartyMemberIndex = 0;
- for (i = 0; i < 3; i++)
- {
- if (pScript->rgwOperand[i] != 0)
- {
- gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex].wPlayerRole =
- pScript->rgwOperand[i] - 1;
- g_Battle.rgPlayer[gpGlobals->wMaxPartyMemberIndex].action.ActionType =
- kBattleActionAttack;
- gpGlobals->wMaxPartyMemberIndex++;
- }
- }
- if (gpGlobals->wMaxPartyMemberIndex == 0)
- {
- // HACK for Dream 2.11
- gpGlobals->rgParty[0].wPlayerRole = 0;
- gpGlobals->wMaxPartyMemberIndex = 1;
- }
- gpGlobals->wMaxPartyMemberIndex--;
- //
- // Reload the player sprites
- //
- PAL_SetLoadFlags(kLoadPlayerSprite);
- PAL_LoadResources();
- memset(gpGlobals->rgPoisonStatus, 0, sizeof(gpGlobals->rgPoisonStatus));
- PAL_UpdateEquipments();
- break;
- case 0x0076:
- //
- // Show FBP picture
- //
- PAL_EndingSetEffectSprite(0);
- PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[1]);
- break;
- case 0x0077:
- //
- // Stop current playing music
- //
- PAL_PlayMUS(0, FALSE,
- (pScript->rgwOperand[0] == 0) ? 2.0f : (FLOAT)(pScript->rgwOperand[0]) * 2);
- gpGlobals->wNumMusic = 0;
- break;
- case 0x0078:
- //
- // FIXME: ???
- //
- break;
- case 0x0079:
- //
- // Jump if the specified player is in the party
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole] ==
- pScript->rgwOperand[0])
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- break;
- }
- }
- break;
- case 0x007A:
- //
- // Walk the party to the specified position, at a higher speed
- //
- PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 4);
- break;
- case 0x007B:
- //
- // Walk the party to the specified position, at the highest speed
- //
- PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 8);
- break;
- case 0x007C:
- //
- // Walk straight to the specified position
- //
- if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
- {
- if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 4))
- {
- wScriptEntry--;
- }
- }
- else
- {
- wScriptEntry--;
- }
- break;
- case 0x007D:
- //
- // Move the event object
- //
- pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
- pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
- break;
- case 0x007E:
- //
- // Set the layer of event object
- //
- pCurrent->sLayer = (SHORT)(pScript->rgwOperand[1]);
- break;
- case 0x007F:
- //
- // Move the viewport
- //
- if (pScript->rgwOperand[0] == 0 && pScript->rgwOperand[1] == 0)
- {
- //
- // Move the viewport back to normal state
- //
- x = gpGlobals->rgParty[0].x - 160;
- y = gpGlobals->rgParty[0].y - 112;
- gpGlobals->viewport =
- PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
- gpGlobals->partyoffset = PAL_XY(160, 112);
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- gpGlobals->rgParty[i].x -= x;
- gpGlobals->rgParty[i].y -= y;
- }
- if (pScript->rgwOperand[2] != 0xFFFF)
- {
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- }
- }
- else
- {
- DWORD time;
- i = 0;
- x = (SHORT)(pScript->rgwOperand[0]);
- y = (SHORT)(pScript->rgwOperand[1]);
- time = SDL_GetTicks() + FRAME_TIME;
- do
- {
- if (pScript->rgwOperand[2] == 0xFFFF)
- {
- x = PAL_X(gpGlobals->viewport);
- y = PAL_Y(gpGlobals->viewport);
- gpGlobals->viewport =
- PAL_XY(pScript->rgwOperand[0] * 32 - 160, pScript->rgwOperand[1] * 16 - 112);
- x -= PAL_X(gpGlobals->viewport);
- y -= PAL_Y(gpGlobals->viewport);
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- gpGlobals->rgParty[j].x += x;
- gpGlobals->rgParty[j].y += y;
- }
- }
- else
- {
- gpGlobals->viewport =
- PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
- gpGlobals->partyoffset =
- PAL_XY(PAL_X(gpGlobals->partyoffset) - x, PAL_Y(gpGlobals->partyoffset) - y);
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- gpGlobals->rgParty[j].x -= x;
- gpGlobals->rgParty[j].y -= y;
- }
- }
- if (pScript->rgwOperand[2] != 0xFFFF)
- {
- PAL_GameUpdate(FALSE);
- }
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- //
- // Delay for one frame
- //
- PAL_ProcessEvent();
- while (SDL_GetTicks() < time)
- {
- PAL_ProcessEvent();
- SDL_Delay(1);
- }
- time = SDL_GetTicks() + FRAME_TIME;
- } while (++i < (SHORT)(pScript->rgwOperand[2]));
- }
- break;
- case 0x0080:
- //
- // Toggle day/night palette
- //
- gpGlobals->fNightPalette = !(gpGlobals->fNightPalette);
- PAL_PaletteFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
- !(pScript->rgwOperand[0]));
- break;
- case 0x0081:
- //
- // Jump if the player is not facing the specified event object
- //
- {
- if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
- pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
- {
- //
- // The event object is not in the current scene
- //
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- break;
- }
- x = pCurrent->x;
- y = pCurrent->y;
- x +=
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
- ? 16 : -16);
- y +=
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
- ? 8 : -8);
- x -= PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
- y -= PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
- if (abs(x) + abs(y * 2) < pScript->rgwOperand[1] * 32 + 16)
- {
- if (pScript->rgwOperand[1] > 0)
- {
- //
- // Change the trigger mode so that the object can be triggered in next frame
- //
- pCurrent->wTriggerMode = kTriggerTouchNormal + pScript->rgwOperand[1];
- }
- }
- else
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- }
- }
- break;
- case 0x0082:
- //
- // Walk straight to the specified position, at a high speed
- //
- if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 8))
- {
- wScriptEntry--;
- }
- break;
- case 0x0083:
- //
- // Jump if event object is not in the specified zone of the current event object
- //
- if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
- pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
- {
- //
- // The event object is not in the current scene
- //
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- break;
- }
- x = pEvtObj->x - pCurrent->x;
- y = pEvtObj->y - pCurrent->y;
- if (abs(x) + abs(y * 2) >= pScript->rgwOperand[1] * 32 + 16)
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- }
- break;
- case 0x0084:
- //
- // Place the item which player used as an event object to the scene
- //
- if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
- pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
- {
- //
- // The event object is not in the current scene
- //
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- break;
- }
- x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
- y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
- x +=
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
- ? -16 : 16);
- y +=
- ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
- ? -8 : 8);
- if (PAL_CheckObstacle(PAL_XY(x, y), FALSE, 0))
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- g_fScriptSuccess = FALSE;
- }
- else
- {
- pCurrent->x = x;
- pCurrent->y = y;
- pCurrent->sState = (SHORT)(pScript->rgwOperand[1]);
- }
- break;
- case 0x0085:
- //
- // Delay for a period
- //
- UTIL_Delay(pScript->rgwOperand[0] * 80);
- break;
- case 0x0086:
- //
- // Jump if the specified item is not equipped
- //
- y = FALSE;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- for (x = 0; x < MAX_PLAYER_EQUIPMENTS; x++)
- {
- if (gpGlobals->g.PlayerRoles.rgwEquipment[x][w] == pScript->rgwOperand[0])
- {
- y = TRUE;
- i = 999;
- break;
- }
- }
- }
- if (!y)
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- break;
- case 0x0087:
- //
- // Animate the event object
- //
- PAL_NPCWalkOneStep(wCurEventObjectID, 0);
- break;
- case 0x0088:
- //
- // Set the base damage of magic according to amount of money
- //
- i = ((gpGlobals->dwCash > 5000) ? 5000 : gpGlobals->dwCash);
- gpGlobals->dwCash -= i;
- j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
- gpGlobals->g.lprgMagic[j].wBaseDamage = i * 2 / 5;
- break;
- case 0x0089:
- //
- // Set the battle result
- //
- g_Battle.BattleResult = pScript->rgwOperand[0];
- break;
- case 0x008A:
- //
- // Enable Auto-Battle for next battle
- //
- gpGlobals->fAutoBattle = TRUE;
- break;
- case 0x008B:
- //
- // change the current palette
- //
- gpGlobals->wNumPalette = pScript->rgwOperand[0];
- if (!gpGlobals->fNeedToFadeIn)
- {
- PAL_SetPalette(gpGlobals->wNumPalette, FALSE);
- }
- break;
- case 0x008C:
- //
- // Fade from/to color
- //
- PAL_ColorFade(pScript->rgwOperand[1], (BYTE)(pScript->rgwOperand[0]),
- pScript->rgwOperand[2]);
- gpGlobals->fNeedToFadeIn = FALSE;
- break;
- case 0x008D:
- //
- // Increase player's level
- //
- PAL_PlayerLevelUp(wEventObjectID, pScript->rgwOperand[0]);
- break;
- case 0x008F:
- //
- // Halve the cash amount
- //
- gpGlobals->dwCash /= 2;
- break;
- case 0x0090:
- //
- // Set the object script
- //
- gpGlobals->g.rgObject[pScript->rgwOperand[0]].rgwData[2 + pScript->rgwOperand[2]] =
- pScript->rgwOperand[1];
- break;
- case 0x0091:
- //
- // Jump if the enemy is not alone
- //
- if (gpGlobals->fInBattle)
- {
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (i != wEventObjectID &&
- g_Battle.rgEnemy[i].wObjectID == g_Battle.rgEnemy[wEventObjectID].wObjectID)
- {
- wScriptEntry = pScript->rgwOperand[0] - 1;
- break;
- }
- }
- }
- break;
- case 0x0092:
- //
- // Show a magic-casting animation for a player in battle
- //
- if (gpGlobals->fInBattle)
- {
- if (pScript->rgwOperand[0] != 0)
- {
- PAL_BattleShowPlayerPreMagicAnim(pScript->rgwOperand[0] - 1, FALSE);
- g_Battle.rgPlayer[pScript->rgwOperand[0] - 1].wCurrentFrame = 6;
- }
- for (i = 0; i < 5; i++)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i * 2;
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleBackupScene();
- PAL_BattleUpdateFighters();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- break;
- case 0x0093:
- //
- // Fade the screen. Update scene in the process.
- //
- PAL_SceneFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
- (SHORT)(pScript->rgwOperand[0]));
- gpGlobals->fNeedToFadeIn = ((SHORT)(pScript->rgwOperand[0]) < 0);
- break;
- case 0x0094:
- //
- // Jump if the state of event object is the specified one
- //
- if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- break;
- case 0x0095:
- //
- // Jump if the current scene is the specified one
- //
- if (gpGlobals->wNumScene == pScript->rgwOperand[0])
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- break;
- case 0x0096:
- //
- // Show the ending animation
- //
- PAL_EndingAnimation();
- break;
- case 0x0097:
- //
- // Ride the event object to the specified position, at a higher speed
- //
- PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], 8);
- break;
- case 0x0098:
- //
- // Set follower of the party
- //
- if (pScript->rgwOperand[0] > 0)
- {
- gpGlobals->nFollower = 1;
- gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wPlayerRole = pScript->rgwOperand[0];
- PAL_SetLoadFlags(kLoadPlayerSprite);
- PAL_LoadResources();
- //
- // Update the position and gesture for the follower
- //
- gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].x =
- gpGlobals->rgTrail[3].x - PAL_X(gpGlobals->viewport);
- gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].y =
- gpGlobals->rgTrail[3].y - PAL_Y(gpGlobals->viewport);
- gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wFrame =
- gpGlobals->rgTrail[3].wDirection * 3;
- }
- else
- {
- gpGlobals->nFollower = 0;
- }
- break;
- case 0x0099:
- //
- // Change the map for the specified scene
- //
- if (pScript->rgwOperand[0] == 0xFFFF)
- {
- gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wMapNum = pScript->rgwOperand[1];
- PAL_SetLoadFlags(kLoadScene);
- PAL_LoadResources();
- }
- else
- {
- gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wMapNum = pScript->rgwOperand[1];
- }
- break;
- case 0x009A:
- //
- // Set the state for multiple event objects
- //
- for (i = pScript->rgwOperand[0]; i <= pScript->rgwOperand[1]; i++)
- {
- gpGlobals->g.lprgEventObject[i - 1].sState = pScript->rgwOperand[2];
- }
- break;
- case 0x009B:
- //
- // Fade to the current scene
- // FIXME: This is obviously wrong
- //
- VIDEO_BackupScreen();
- PAL_MakeScene();
- VIDEO_FadeScreen(2);
- break;
- case 0x009C:
- //
- // Enemy duplicate itself
- //
- w = 0;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID != 0)
- {
- w++;
- }
- }
- if (w != 1)
- {
- //
- // Duplication is only possible when only 1 enemy left
- //
- if (pScript->rgwOperand[1] != 0)
- {
- wScriptEntry = pScript->rgwOperand[1] - 1;
- }
- break;
- }
- w = pScript->rgwOperand[0];
- if (w == 0)
- {
- w = 1;
- }
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (w > 0 && g_Battle.rgEnemy[i].wObjectID == 0)
- {
- w--;
- memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
- g_Battle.rgEnemy[i].wObjectID = g_Battle.rgEnemy[wEventObjectID].wObjectID;
- g_Battle.rgEnemy[i].e = g_Battle.rgEnemy[wEventObjectID].e;
- g_Battle.rgEnemy[i].wScriptOnTurnStart = g_Battle.rgEnemy[wEventObjectID].wScriptOnTurnStart;
- g_Battle.rgEnemy[i].wScriptOnBattleEnd = g_Battle.rgEnemy[wEventObjectID].wScriptOnBattleEnd;
- g_Battle.rgEnemy[i].wScriptOnReady = g_Battle.rgEnemy[wEventObjectID].wScriptOnReady;
- g_Battle.rgEnemy[i].state = kFighterWait;
- g_Battle.rgEnemy[i].flTimeMeter = 50;
- g_Battle.rgEnemy[i].iColorShift = 0;
- }
- }
- PAL_LoadBattleSprites();
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- g_Battle.rgEnemy[i].pos = g_Battle.rgEnemy[wEventObjectID].pos;
- }
- for (i = 0; i < 10; i++)
- {
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- x = (PAL_X(g_Battle.rgEnemy[j].pos) + PAL_X(g_Battle.rgEnemy[j].posOriginal)) / 2;
- y = (PAL_Y(g_Battle.rgEnemy[j].pos) + PAL_Y(g_Battle.rgEnemy[j].posOriginal)) / 2;
- g_Battle.rgEnemy[j].pos = PAL_XY(x, y);
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleUpdateFighters();
- PAL_BattleDelay(1, 0, TRUE);
- break;
- case 0x009E:
- //
- // Enemy summons another monster
- //
- x = 0;
- w = pScript->rgwOperand[0];
- y = (((SHORT)(pScript->rgwOperand[1]) <= 0) ? 1 : (SHORT)pScript->rgwOperand[1]);
- if (w == 0 || w == 0xFFFF)
- {
- w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
- }
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- x++;
- }
- }
- if (x < y || g_Battle.iHidingTime > 0 ||
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] != 0 ||
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] != 0 ||
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] != 0)
- {
- if (pScript->rgwOperand[2] != 0)
- {
- wScriptEntry = pScript->rgwOperand[2] - 1;
- }
- }
- else
- {
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
- g_Battle.rgEnemy[i].wObjectID = w;
- g_Battle.rgEnemy[i].e = gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[w].enemy.wEnemyID];
- g_Battle.rgEnemy[i].state = kFighterWait;
- g_Battle.rgEnemy[i].wScriptOnTurnStart = gpGlobals->g.rgObject[w].enemy.wScriptOnTurnStart;
- g_Battle.rgEnemy[i].wScriptOnBattleEnd = gpGlobals->g.rgObject[w].enemy.wScriptOnBattleEnd;
- g_Battle.rgEnemy[i].wScriptOnReady = gpGlobals->g.rgObject[w].enemy.wScriptOnReady;
- g_Battle.rgEnemy[i].flTimeMeter = 50;
- g_Battle.rgEnemy[i].iColorShift = 8;
- y--;
- if (y <= 0)
- {
- break;
- }
- }
- }
- PAL_BattleDelay(2, 0, TRUE);
- PAL_BattleBackupScene();
- PAL_LoadBattleSprites();
- PAL_BattleMakeScene();
- SOUND_Play(212);
- PAL_BattleFadeScene();
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- g_Battle.rgEnemy[i].iColorShift = 0;
- }
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- break;
- case 0x009F:
- //
- // Enemy transforms into something else
- //
- if (g_Battle.iHidingTime <= 0 &&
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] == 0 &&
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] == 0 &&
- g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] == 0)
- {
- w = g_Battle.rgEnemy[wEventObjectID].e.wHealth;
- g_Battle.rgEnemy[wEventObjectID].wObjectID = pScript->rgwOperand[0];
- g_Battle.rgEnemy[wEventObjectID].e =
- gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[pScript->rgwOperand[0]].enemy.wEnemyID];
- g_Battle.rgEnemy[wEventObjectID].e.wHealth = w;
- g_Battle.rgEnemy[wEventObjectID].wCurrentFrame = 0;
- for (i = 0; i < 6; i++)
- {
- g_Battle.rgEnemy[wEventObjectID].iColorShift = i;
- PAL_BattleDelay(1, 0, FALSE);
- }
- g_Battle.rgEnemy[wEventObjectID].iColorShift = 0;
- PAL_BattleBackupScene();
- PAL_LoadBattleSprites();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- break;
- case 0x00A0:
- //
- // Quit game
- //
- PAL_AdditionalCredits();
- PAL_Shutdown();
- exit(0);
- break;
- case 0x00A1:
- //
- // Set the positions of all party members to the same as the first one
- //
- for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
- {
- gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
- gpGlobals->rgTrail[i].x = gpGlobals->rgParty[0].x + PAL_X(gpGlobals->viewport);
- gpGlobals->rgTrail[i].y = gpGlobals->rgParty[0].y + PAL_Y(gpGlobals->viewport);
- }
- for (i = 1; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- gpGlobals->rgParty[i].x = gpGlobals->rgParty[0].x;
- gpGlobals->rgParty[i].y = gpGlobals->rgParty[0].y - 1;
- }
- PAL_UpdatePartyGestures(FALSE);
- break;
- case 0x00A2:
- //
- // Jump to one of the following instructions randomly
- //
- wScriptEntry += RandomLong(0, pScript->rgwOperand[0] - 1);
- break;
- case 0x00A3:
- //
- // Play CD music. Use the RIX music for fallback.
- //
- if (!SOUND_PlayCDA(pScript->rgwOperand[0]))
- {
- PAL_PlayMUS(pScript->rgwOperand[1], TRUE, 0);
- }
- break;
- case 0x00A4:
- //
- // Scroll FBP to the screen
- //
- if (pScript->rgwOperand[0] == 68)
- {
- //
- // HACKHACK: to make the ending picture show correctly
- //
- PAL_ShowFBP(69, 0);
- PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], TRUE);
- }
- else
- {
- PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], pScript->rgwOperand[1]);
- }
- break;
- case 0x00A5:
- //
- // Show FBP picture with sprite effects
- //
- if (pScript->rgwOperand[1] != 0xFFFF)
- {
- PAL_EndingSetEffectSprite(pScript->rgwOperand[1]);
- }
- PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[2]);
- break;
- case 0x00A6:
- //
- // backup screen
- //
- VIDEO_BackupScreen();
- break;
- default:
- TerminateOnError("SCRIPT: Invalid Instruction at %4x: (%4x - %4x, %4x, %4x)",
- wScriptEntry, pScript->wOperation, pScript->rgwOperand[0],
- pScript->rgwOperand[1], pScript->rgwOperand[2]);
- break;
- }
- return wScriptEntry + 1;
- }
- WORD
- PAL_RunTriggerScript(
- WORD wScriptEntry,
- WORD wEventObjectID
- )
- /*++
- Purpose:
- Runs a trigger script.
- Parameters:
- [IN] wScriptEntry - The script entry to execute.
- [IN] wEventObjectID - The event object ID which invoked the script.
- Return value:
- The entry point of the script.
- --*/
- {
- static WORD wLastEventObject = 0;
- WORD wNextScriptEntry;
- BOOL fEnded;
- LPSCRIPTENTRY pScript;
- LPEVENTOBJECT pEvtObj = NULL;
- int i;
- extern BOOL g_fUpdatedInBattle; // HACKHACK
- wNextScriptEntry = wScriptEntry;
- fEnded = FALSE;
- g_fUpdatedInBattle = FALSE;
- if (wEventObjectID == 0xFFFF)
- {
- wEventObjectID = wLastEventObject;
- }
- wLastEventObject = wEventObjectID;
- if (wEventObjectID != 0)
- {
- pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
- }
- g_fScriptSuccess = TRUE;
- //
- // Set the default dialog speed.
- //
- PAL_DialogSetDelayTime(3);
- while (wScriptEntry != 0 && !fEnded)
- {
- pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
- UTIL_WriteLog(LOG_DEBUG, "[SCRIPT] %.4x: %.4x %.4x %.4x %.4x\n", wScriptEntry,
- pScript->wOperation, pScript->rgwOperand[0], pScript->rgwOperand[1],
- pScript->rgwOperand[2], pScript->rgwOperand[3]);
- switch (pScript->wOperation)
- {
- case 0x0000:
- //
- // Stop running
- //
- fEnded = TRUE;
- break;
- case 0x0001:
- //
- // Stop running and replace the entry with the next line
- //
- fEnded = TRUE;
- wNextScriptEntry = wScriptEntry + 1;
- break;
- case 0x0002:
- //
- // Stop running and replace the entry with the specified one
- //
- if (pScript->rgwOperand[1] == 0 ||
- ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
- {
- fEnded = TRUE;
- wNextScriptEntry = pScript->rgwOperand[0];
- }
- else
- {
- //
- // failed
- //
- pEvtObj->nScriptIdleFrame = 0;
- wScriptEntry++;
- }
- break;
- case 0x0003:
- //
- // unconditional jump
- //
- if (pScript->rgwOperand[1] == 0 ||
- ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
- {
- wScriptEntry = pScript->rgwOperand[0];
- }
- else
- {
- //
- // failed
- //
- pEvtObj->nScriptIdleFrame = 0;
- wScriptEntry++;
- }
- break;
- case 0x0004:
- //
- // Call script
- //
- PAL_RunTriggerScript(pScript->rgwOperand[0],
- ((pScript->rgwOperand[1] == 0) ? wEventObjectID : pScript->rgwOperand[1]));
- wScriptEntry++;
- break;
- case 0x0005:
- //
- // Redraw screen
- //
- PAL_ClearDialog(TRUE);
- if (PAL_DialogIsPlayingRNG())
- {
- VIDEO_RestoreScreen();
- }
- else if (gpGlobals->fInBattle)
- {
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- VIDEO_UpdateScreen(NULL);
- }
- else
- {
- if (pScript->rgwOperand[2])
- {
- PAL_UpdatePartyGestures(FALSE);
- }
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- UTIL_Delay((pScript->rgwOperand[1] == 0) ? 60 : (pScript->rgwOperand[1] * 60));
- }
- wScriptEntry++;
- break;
- case 0x0006:
- //
- // Jump to the specified address by the specified rate
- //
- if (RandomLong(1, 100) >= pScript->rgwOperand[0])
- {
- wScriptEntry = pScript->rgwOperand[1];
- continue;
- }
- else
- {
- wScriptEntry++;
- }
- break;
- case 0x0007:
- //
- // Start battle
- //
- i = PAL_StartBattle(pScript->rgwOperand[0], !pScript->rgwOperand[2]);
- if (i == kBattleResultLost && pScript->rgwOperand[1] != 0)
- {
- wScriptEntry = pScript->rgwOperand[1];
- }
- else if (i == kBattleResultFleed && pScript->rgwOperand[2] != 0)
- {
- wScriptEntry = pScript->rgwOperand[2];
- }
- else
- {
- wScriptEntry++;
- }
- gpGlobals->fAutoBattle = FALSE;
- break;
- case 0x0008:
- //
- // Replace the entry with the next instruction
- //
- wScriptEntry++;
- wNextScriptEntry = wScriptEntry;
- break;
- case 0x0009:
- //
- // wait for the specified number of frames
- //
- {
- DWORD time;
- PAL_ClearDialog(TRUE);
- time = SDL_GetTicks() + FRAME_TIME;
- for (i = 0; i < (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1); i++)
- {
- PAL_ProcessEvent();
- while (SDL_GetTicks() < time)
- {
- PAL_ProcessEvent();
- SDL_Delay(1);
- }
- time = SDL_GetTicks() + FRAME_TIME;
- if (pScript->rgwOperand[2])
- {
- PAL_UpdatePartyGestures(FALSE);
- }
- PAL_GameUpdate(pScript->rgwOperand[1] ? TRUE : FALSE);
- PAL_MakeScene();
- VIDEO_UpdateScreen(NULL);
- }
- }
- wScriptEntry++;
- break;
- case 0x000A:
- //
- // Goto the specified address if player selected no
- //
- PAL_ClearDialog(FALSE);
- if (!PAL_ConfirmMenu())
- {
- wScriptEntry = pScript->rgwOperand[0];
- }
- else
- {
- wScriptEntry++;
- }
- break;
- case 0x003B:
- //
- // Show dialog in the middle part of the screen
- //
- PAL_ClearDialog(TRUE);
- PAL_StartDialog(kDialogCenter, (BYTE)pScript->rgwOperand[0], 0,
- pScript->rgwOperand[2] ? TRUE : FALSE);
- wScriptEntry++;
- break;
- case 0x003C:
- //
- // Show dialog in the upper part of the screen
- //
- PAL_ClearDialog(TRUE);
- PAL_StartDialog(kDialogUpper, (BYTE)pScript->rgwOperand[1],
- pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
- wScriptEntry++;
- break;
- case 0x003D:
- //
- // Show dialog in the lower part of the screen
- //
- PAL_ClearDialog(TRUE);
- PAL_StartDialog(kDialogLower, (BYTE)pScript->rgwOperand[1],
- pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
- wScriptEntry++;
- break;
- case 0x003E:
- //
- // Show text in a window at the center of the screen
- //
- PAL_ClearDialog(TRUE);
- PAL_StartDialog(kDialogCenterWindow, (BYTE)pScript->rgwOperand[0], 0, FALSE);
- wScriptEntry++;
- break;
- case 0x008E:
- //
- // Restore the screen
- //
- PAL_ClearDialog(TRUE);
- VIDEO_RestoreScreen();
- VIDEO_UpdateScreen(NULL);
- wScriptEntry++;
- break;
- case 0xFFFF:
- //
- // Print dialog text
- //
- PAL_ShowDialogText(PAL_GetMsg(pScript->rgwOperand[0]));
- wScriptEntry++;
- break;
- default:
- PAL_ClearDialog(TRUE);
- wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
- break;
- }
- }
- PAL_EndDialog();
- g_iCurEquipPart = -1;
- return wNextScriptEntry;
- }
- WORD
- PAL_RunAutoScript(
- WORD wScriptEntry,
- WORD wEventObjectID
- )
- /*++
- Purpose:
- Runs the autoscript of the specified event object.
- Parameters:
- [IN] wScriptEntry - The script entry to execute.
- [IN] wEventObjectID - The event object ID which invoked the script.
- Return value:
- The address of the next script instruction to execute.
- --*/
- {
- LPSCRIPTENTRY pScript;
- LPEVENTOBJECT pEvtObj;
- begin:
- pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
- pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
- //
- // For autoscript, we should interpret one instruction per frame (except
- // jumping) and save the address of next instruction.
- //
- switch (pScript->wOperation)
- {
- case 0x0000:
- //
- // Stop running
- //
- break;
- case 0x0001:
- //
- // Stop running and replace the entry with the next line
- //
- wScriptEntry++;
- break;
- case 0x0002:
- //
- // Stop running and replace the entry with the specified one
- //
- if (pScript->rgwOperand[1] == 0 ||
- ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
- {
- wScriptEntry = pScript->rgwOperand[0];
- }
- else
- {
- pEvtObj->wScriptIdleFrameCountAuto = 0;
- wScriptEntry++;
- }
- break;
- case 0x0003:
- //
- // unconditional jump
- //
- if (pScript->rgwOperand[1] == 0 ||
- ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
- {
- wScriptEntry = pScript->rgwOperand[0];
- goto begin;
- }
- else
- {
- pEvtObj->wScriptIdleFrameCountAuto = 0;
- wScriptEntry++;
- }
- break;
- case 0x0004:
- //
- // Call subroutine
- //
- PAL_RunTriggerScript(pScript->rgwOperand[0],
- pScript->rgwOperand[1] ? pScript->rgwOperand[1] : wEventObjectID);
- wScriptEntry++;
- break;
- case 0x0006:
- //
- // jump to the specified address by the specified rate
- //
- if (RandomLong(1, 100) >= pScript->rgwOperand[0] && pScript->rgwOperand[1] != 0)
- {
- wScriptEntry = pScript->rgwOperand[1];
- goto begin;
- }
- else
- {
- wScriptEntry++;
- }
- break;
- case 0x0009:
- //
- // Wait for a certain number of frames
- //
- if (++(pEvtObj->wScriptIdleFrameCountAuto) >= pScript->rgwOperand[0])
- {
- //
- // waiting ended; go further
- //
- pEvtObj->wScriptIdleFrameCountAuto = 0;
- wScriptEntry++;
- }
- break;
- case 0xFFFF:
- wScriptEntry++;
- break;
- default:
- //
- // Other operations
- //
- wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
- break;
- }
- return wScriptEntry;
- }
|