12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524 |
- /* -*- 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/>.
- //
- // Modified by Lou Yihua <louyihua@21cn.com> with Unicode support, 2015
- //
- #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_DelayUntil(t);
- 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_DelayUntil(t);
- 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);
- }
- VOID
- PAL_AdditionalCredits(
- VOID
- )
- /*++
- Purpose:
- Show the additional credits.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- LPCWSTR rgszcps[][CP_MAX] = {
- // Traditional Chinese, Simplified Chinese
- { L"", L"", /*L""*/ },
- { L" \x7D93\x5178\x7279\x5225\x7BC7 ",
- L" \x7ECF\x5178\x7279\x522B\x7BC7 ",
- //L" \x30AF\x30E9\x30B7\x30C3\x30AF\x7279\x5225\x7DE8 "
- },
- { L"", L"", /*L""*/ },
- { L"", L"", /*L""*/ },
- { L"", L"", /*L""*/ },
- { L"", L"", /*L""*/ },
- { L"", L"", /*L""*/ },
- { L"", L"", /*L""*/ },
- { L" \x672C\x7A0B\x5F0F\x662F\x81EA\x7531\x8EDF\x9AD4\xFF0C\x6309\x7167 GNU General",
- L" \x672C\x7A0B\x5E8F\x662F\x81EA\x7531\x8F6F\x4EF6\xFF0C\x6309\x7167 GNU General",
- //L" \x3053\x306E\x30D7\x30ED\x30B0\x30E9\x30E0\x306F\x81EA\x7531\x30BD\x30D5\x30C8\x30A6\x30A7\x30A2\x3067\x3059\x3001"
- },
- { L" Public License v3 \x6216\x66F4\x9AD8\x7248\x672C\x767C\x4F48",
- L" Public License v3 \x6216\x66F4\x9AD8\x7248\x672C\x53D1\x5E03",
- //L" GNU General Public License v3 \x306E\x4E0B\x3067"
- },
- { L"", L"", /*L" \x914D\x5E03\x3055\x308C\x3066\x3044\x307E\x3059\x3002"*/ },
- { L" ...\x6309 Enter \x7D50\x675F",
- L" ...\x6309 Enter \x7ED3\x675F",
- //L" ...Enter\x30AD\x30FC\x3092\x62BC\x3057\x3066\x7D42\x4E86\x3057\x307E\x3059"
- },
- };
- LPCWSTR rgszStrings[] = {
- L" SDLPAL (http://sdlpal.codeplex.com/)",
- #ifdef PAL_CLASSIC
- L"%ls(" WIDETEXT(__DATE__) L")",
- #else
- L" (" WIDETEXT(__DATE__) L")",
- #endif
- L" ",
- L" (c) 2009-2011, Wei Mingzhi",
- L" <whistler_wmz@users.sf.net>.",
- L" (c) 2011-2015, SDLPAL Team",
- L"%ls", // Porting information line 1
- L"%ls", // Porting information line 2
- L"%ls", // GNU line 1
- L"%ls", // GNU line 2
- L"%ls", // GNU line 3
- L"%ls", // Press Enter to continue
- };
- int i = 0;
- PAL_DrawOpeningMenuBackground();
- for (i = 0; i < 12; i++)
- {
- WCHAR buffer[48];
- #if defined(__ANDROID__)
- // The support of swprintf in Android's NDK is very very bad, so we need an alternative way.
- if (wcsncmp(rgszStrings[i], L"%ls", 3) == 0)
- {
- // We've limited the length of g_rcCredits[i] in text.c, so no need to double check here.
- wcscpy(buffer, gConfig.pszMsgFile ? g_rcCredits[i] : rgszcps[i][gConfig.uCodePage]);
- wcscat(buffer, rgszStrings[i] + 3);
- }
- else
- wcscpy(buffer, rgszStrings[i]);
- #else
- swprintf(buffer, 48, rgszStrings[i], gConfig.pszMsgFile ? g_rcCredits[i] : rgszcps[i][gConfig.uCodePage]);
- #endif
- PAL_DrawText(buffer, PAL_XY(0, 2 + i * 16), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
- }
- 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)
- {
- WCHAR 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);
- wcscpy(s, PAL_GetWord(42));
- wcscat(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];
- AUDIO_PlayMusic(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
- //
- AUDIO_PlaySound(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
- //
- if (gConfig.fIsWIN95)
- {
- SDL_FillRect(gpScreen, NULL, 0);
- VIDEO_UpdateScreen(NULL);
- }
- else
- {
- PAL_EndingSetEffectSprite(0);
- PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[1]);
- }
- break;
- case 0x0077:
- //
- // Stop current playing music
- //
- AUDIO_PlayMusic(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_DelayUntil(time);
- 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
- //
- if (!gConfig.fIsWIN95)
- 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();
- AUDIO_PlaySound(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;
- AUDIO_PlaySound(47);
- PAL_BattleBackupScene();
- PAL_LoadBattleSprites();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- break;
- case 0x00A0:
- //
- // Quit game
- //
- if (gConfig.fIsWIN95)
- PAL_EndingScreen();
- PAL_AdditionalCredits();
- PAL_Shutdown(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 (!AUDIO_PlayCDTrack(pScript->rgwOperand[0]))
- {
- AUDIO_PlayMusic(pScript->rgwOperand[1], TRUE, 0);
- }
- break;
- case 0x00A4:
- //
- // Scroll FBP to the screen
- //
- if (!gConfig.fIsWIN95)
- {
- 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 (!gConfig.fIsWIN95)
- {
- 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_DelayUntil(time);
- 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
- //
- if (gConfig.pszMsgFile)
- {
- int idx = 0, iMsg;
- while ((iMsg = PAL_GetMsgNum(pScript->rgwOperand[0], idx++)) >= 0)
- {
- if (iMsg == 0)
- {
- //
- // Restore the screen
- //
- PAL_ClearDialog(TRUE);
- VIDEO_RestoreScreen();
- VIDEO_UpdateScreen(NULL);
- }
- else
- PAL_ShowDialogText(PAL_GetMsg(iMsg));
- }
- while (gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0xFFFF
- || gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0x008E)
- {
- //
- // Skip all following continuous 0xFFFF & 0x008E instructions
- //
- wScriptEntry++;
- }
- }
- else
- {
- 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])
- {
- if (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:
- if (gConfig.fIsWIN95)
- {
- int XBase = (wEventObjectID & PAL_ITEM_DESC_BOTTOM) ? 75 : 100;
- int YBase = (wEventObjectID & PAL_ITEM_DESC_BOTTOM) ? 150 - gConfig.ScreenLayout.ExtraItemDescLines * 16 : 3;
- int iDescLine = (wEventObjectID & ~PAL_ITEM_DESC_BOTTOM);
- if (gConfig.pszMsgFile)
- {
- int idx = 0, iMsg;
- while ((iMsg = PAL_GetMsgNum(pScript->rgwOperand[0], idx++)) >= 0)
- {
- if (iMsg > 0)
- {
- PAL_DrawText(PAL_GetMsg(iMsg), PAL_XY(XBase, iDescLine * 16 + YBase), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
- iDescLine++;
- }
- }
- while (gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0xFFFF)
- {
- //
- // Skip all following continuous 0xFFFF instructions
- //
- wScriptEntry++;
- }
- }
- else
- {
- PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(XBase, iDescLine * 16 + YBase), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
- wScriptEntry++;
- }
- }
- else
- {
- wScriptEntry++;
- }
- break;
- case 0x00A7:
- wScriptEntry++;
- break;
- default:
- //
- // Other operations
- //
- wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
- break;
- }
- return wScriptEntry;
- }
|