1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466 |
- /* -*- 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-2014, 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;
- #ifdef PAL_WIN95
- extern BOOL fIsBig5;
- fIsBig5 = TRUE;
- #endif
- 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
- //
- #ifdef PAL_WIN95
- SDL_FillRect(gpScreen, NULL, 0);
- VIDEO_UpdateScreen(NULL);
- #else
- PAL_EndingSetEffectSprite(0);
- PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[1]);
- #endif
- 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
- //
- #ifndef PAL_WIN95
- PAL_EndingAnimation();
- #endif
- 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
- //
- #ifdef PAL_WIN95
- PAL_EndingScreen();
- #endif
- 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
- //
- #ifndef PAL_WIN95
- 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]);
- }
- #endif
- break;
- case 0x00A5:
- //
- // Show FBP picture with sprite effects
- //
- #ifndef PAL_WIN95
- if (pScript->rgwOperand[1] != 0xFFFF)
- {
- PAL_EndingSetEffectSprite(pScript->rgwOperand[1]);
- }
- PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[2]);
- #endif
- 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;
- #ifdef PAL_WIN95
- int iDescLine = 0;
- #endif
- 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:
- #ifdef PAL_WIN95
- iDescLine = (wEventObjectID & ~(1 << 15));
- if (wEventObjectID & (1 << 15))
- {
- PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(75, iDescLine * 16 + 150), DESCTEXT_COLOR, TRUE, FALSE);
- }
- else
- {
- PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(100, iDescLine * 16 + 3), DESCTEXT_COLOR, TRUE, FALSE);
- }
- iDescLine++;
- #endif
- wScriptEntry++;
- break;
- #ifdef PAL_WIN95
- case 0x00A7:
- wScriptEntry++;
- break;
- #endif
- default:
- //
- // Other operations
- //
- wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
- break;
- }
- return wScriptEntry;
- }
|