script.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // Based on PALx Project by palxex.
  7. // Copyright (c) 2006-2008, Pal Lockheart <palxex@gmail.com>.
  8. //
  9. // This file is part of SDLPAL.
  10. //
  11. // SDLPAL is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. #include "main.h"
  25. BOOL g_fScriptSuccess = TRUE;
  26. static int g_iCurEquipPart = -1;
  27. static BOOL
  28. PAL_NPCWalkTo(
  29. WORD wEventObjectID,
  30. INT x,
  31. INT y,
  32. INT h,
  33. INT iSpeed
  34. )
  35. /*++
  36. Purpose:
  37. Make the specified event object walk to the map position specified by (x, y, h)
  38. at the speed of iSpeed.
  39. Parameters:
  40. [IN] wEventObjectID - the event object to move.
  41. [IN] x - Column number of the tile.
  42. [IN] y - Line number in the map.
  43. [IN] h - Each line in the map has two lines of tiles, 0 and 1.
  44. (See map.h for details.)
  45. [IN] iSpeed - the speed to move.
  46. Return value:
  47. TRUE if the event object has successfully moved to the specified position,
  48. FALSE if still need more moving.
  49. --*/
  50. {
  51. LPEVENTOBJECT pEvtObj;
  52. int xOffset, yOffset;
  53. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  54. xOffset = (x * 32 + h * 16) - pEvtObj->x;
  55. yOffset = (y * 16 + h * 8) - pEvtObj->y;
  56. if (yOffset < 0)
  57. {
  58. pEvtObj->wDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
  59. }
  60. else
  61. {
  62. pEvtObj->wDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
  63. }
  64. if (abs(xOffset) < iSpeed * 2 || abs(yOffset) < iSpeed * 2)
  65. {
  66. pEvtObj->x = x * 32 + h * 16;
  67. pEvtObj->y = y * 16 + h * 8;
  68. }
  69. else
  70. {
  71. PAL_NPCWalkOneStep(wEventObjectID, iSpeed);
  72. }
  73. if (pEvtObj->x == x * 32 + h * 16 && pEvtObj->y == y * 16 + h * 8)
  74. {
  75. pEvtObj->wCurrentFrameNum = 0;
  76. return TRUE;
  77. }
  78. return FALSE;
  79. }
  80. static VOID
  81. PAL_PartyWalkTo(
  82. INT x,
  83. INT y,
  84. INT h,
  85. INT iSpeed
  86. )
  87. /*++
  88. Purpose:
  89. Make the party walk to the map position specified by (x, y, h)
  90. at the speed of iSpeed.
  91. Parameters:
  92. [IN] x - Column number of the tile.
  93. [IN] y - Line number in the map.
  94. [IN] h - Each line in the map has two lines of tiles, 0 and 1.
  95. (See map.h for details.)
  96. [IN] iSpeed - the speed to move.
  97. Return value:
  98. None.
  99. --*/
  100. {
  101. int xOffset, yOffset, i, dx, dy;
  102. DWORD t;
  103. xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
  104. yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
  105. t = 0;
  106. while (xOffset != 0 || yOffset != 0)
  107. {
  108. PAL_ProcessEvent();
  109. while (SDL_GetTicks() <= t)
  110. {
  111. PAL_ProcessEvent();
  112. SDL_Delay(1);
  113. }
  114. t = SDL_GetTicks() + FRAME_TIME;
  115. //
  116. // Store trail
  117. //
  118. for (i = 3; i >= 0; i--)
  119. {
  120. gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
  121. }
  122. gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
  123. gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  124. gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  125. if (yOffset < 0)
  126. {
  127. gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
  128. }
  129. else
  130. {
  131. gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
  132. }
  133. dx = PAL_X(gpGlobals->viewport);
  134. dy = PAL_Y(gpGlobals->viewport);
  135. if (abs(xOffset) <= iSpeed * 2)
  136. {
  137. dx += xOffset;
  138. }
  139. else
  140. {
  141. dx += iSpeed * (xOffset < 0 ? -2 : 2);
  142. }
  143. if (abs(yOffset) <= iSpeed)
  144. {
  145. dy += yOffset;
  146. }
  147. else
  148. {
  149. dy += iSpeed * (yOffset < 0 ? -1 : 1);
  150. }
  151. //
  152. // Move the viewport
  153. //
  154. gpGlobals->viewport = PAL_XY(dx, dy);
  155. PAL_UpdatePartyGestures(TRUE);
  156. PAL_GameUpdate(FALSE);
  157. PAL_MakeScene();
  158. VIDEO_UpdateScreen(NULL);
  159. xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
  160. yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
  161. }
  162. PAL_UpdatePartyGestures(FALSE);
  163. }
  164. static VOID
  165. PAL_PartyRideEventObject(
  166. WORD wEventObjectID,
  167. INT x,
  168. INT y,
  169. INT h,
  170. INT iSpeed
  171. )
  172. /*++
  173. Purpose:
  174. Move the party to the specified position, riding the specified event object.
  175. Parameters:
  176. [IN] wEventObjectID - the event object to be ridden.
  177. [IN] x - Column number of the tile.
  178. [IN] y - Line number in the map.
  179. [IN] h - Each line in the map has two lines of tiles, 0 and 1.
  180. (See map.h for details.)
  181. [IN] iSpeed - the speed to move.
  182. Return value:
  183. TRUE if the party and event object has successfully moved to the specified
  184. position, FALSE if still need more moving.
  185. --*/
  186. {
  187. int xOffset, yOffset, dx, dy, i;
  188. DWORD t;
  189. LPEVENTOBJECT p;
  190. p = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  191. xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
  192. yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
  193. t = 0;
  194. while (xOffset != 0 || yOffset != 0)
  195. {
  196. PAL_ProcessEvent();
  197. while (SDL_GetTicks() <= t)
  198. {
  199. PAL_ProcessEvent();
  200. SDL_Delay(1);
  201. }
  202. t = SDL_GetTicks() + FRAME_TIME;
  203. if (yOffset < 0)
  204. {
  205. gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
  206. }
  207. else
  208. {
  209. gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
  210. }
  211. if (abs(xOffset) > iSpeed * 2)
  212. {
  213. dx = iSpeed * (xOffset < 0 ? -2 : 2);
  214. }
  215. else
  216. {
  217. dx = xOffset;
  218. }
  219. if (abs(yOffset) > iSpeed)
  220. {
  221. dy = iSpeed * (yOffset < 0 ? -1 : 1);
  222. }
  223. else
  224. {
  225. dy = yOffset;
  226. }
  227. //
  228. // Store trail
  229. //
  230. for (i = 3; i >= 0; i--)
  231. {
  232. gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
  233. }
  234. gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
  235. gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + dx + PAL_X(gpGlobals->partyoffset);
  236. gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + dy + PAL_Y(gpGlobals->partyoffset);
  237. //
  238. // Move the viewport
  239. //
  240. gpGlobals->viewport =
  241. PAL_XY(PAL_X(gpGlobals->viewport) + dx, PAL_Y(gpGlobals->viewport) + dy);
  242. p->x += dx;
  243. p->y += dy;
  244. PAL_GameUpdate(FALSE);
  245. PAL_MakeScene();
  246. VIDEO_UpdateScreen(NULL);
  247. xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
  248. yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
  249. }
  250. }
  251. static VOID
  252. PAL_MonsterChasePlayer(
  253. WORD wEventObjectID,
  254. WORD wSpeed,
  255. WORD wChaseRange,
  256. BOOL fFloating
  257. )
  258. /*++
  259. Purpose:
  260. Make the specified event object chase the players.
  261. Parameters:
  262. [IN] wEventObjectID - the event object ID of the monster.
  263. [IN] wSpeed - the speed of chasing.
  264. [IN] wChaseRange - sensitive range of the monster.
  265. [IN] fFloating - TRUE if monster is floating (i.e., ignore the obstacles)
  266. Return value:
  267. None.
  268. --*/
  269. {
  270. LPEVENTOBJECT pEvtObj = &gpGlobals->g.lprgEventObject[wEventObjectID - 1];
  271. WORD wMonsterSpeed = 0, prevx, prevy;
  272. int x, y, i, j, l;
  273. if (gpGlobals->wChaseRange != 0)
  274. {
  275. x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset) - pEvtObj->x;
  276. y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset) - pEvtObj->y;
  277. if (x == 0)
  278. {
  279. x = RandomLong(0, 1) ? -1 : 1;
  280. }
  281. if (y == 0)
  282. {
  283. y = RandomLong(0, 1) ? -1 : 1;
  284. }
  285. prevx = pEvtObj->x;
  286. prevy = pEvtObj->y;
  287. i = prevx % 32;
  288. j = prevy % 16;
  289. prevx /= 32;
  290. prevy /= 16;
  291. l = 0;
  292. if (i + j * 2 >= 16)
  293. {
  294. if (i + j * 2 >= 48)
  295. {
  296. prevx++;
  297. prevy++;
  298. }
  299. else if (32 - i + j * 2 < 16)
  300. {
  301. prevx++;
  302. }
  303. else if (32 - i + j * 2 < 48)
  304. {
  305. l = 1;
  306. }
  307. else
  308. {
  309. prevy++;
  310. }
  311. }
  312. prevx = prevx * 32 + l * 16;
  313. prevy = prevy * 16 + l * 8;
  314. //
  315. // Is the party near to the event object?
  316. //
  317. if (abs(x) + abs(y) * 2 < wChaseRange * 32 * gpGlobals->wChaseRange)
  318. {
  319. if (x < 0)
  320. {
  321. if (y < 0)
  322. {
  323. pEvtObj->wDirection = kDirWest;
  324. }
  325. else
  326. {
  327. pEvtObj->wDirection = kDirSouth;
  328. }
  329. }
  330. else
  331. {
  332. if (y < 0)
  333. {
  334. pEvtObj->wDirection = kDirNorth;
  335. }
  336. else
  337. {
  338. pEvtObj->wDirection = kDirEast;
  339. }
  340. }
  341. if (x != 0)
  342. {
  343. x = pEvtObj->x + x / abs(x) * 16;
  344. }
  345. else
  346. {
  347. x = pEvtObj->x;
  348. }
  349. if (y != 0)
  350. {
  351. y = pEvtObj->y + y / abs(y) * 8;
  352. }
  353. else
  354. {
  355. y = pEvtObj->y;
  356. }
  357. if (fFloating)
  358. {
  359. wMonsterSpeed = wSpeed;
  360. }
  361. else
  362. {
  363. if (!PAL_CheckObstacle(PAL_XY(x, y), TRUE, wEventObjectID))
  364. {
  365. wMonsterSpeed = wSpeed;
  366. }
  367. else
  368. {
  369. pEvtObj->x = prevx;
  370. pEvtObj->y = prevy;
  371. }
  372. for (l = 0; l < 4; l++)
  373. {
  374. switch (l)
  375. {
  376. case 0:
  377. pEvtObj->x -= 4;
  378. pEvtObj->y += 2;
  379. break;
  380. case 1:
  381. pEvtObj->x -= 4;
  382. pEvtObj->y -= 2;
  383. break;
  384. case 2:
  385. pEvtObj->x += 4;
  386. pEvtObj->y -= 2;
  387. break;
  388. case 3:
  389. pEvtObj->x += 4;
  390. pEvtObj->y += 2;
  391. break;
  392. }
  393. if (PAL_CheckObstacle(PAL_XY(pEvtObj->x, pEvtObj->y), FALSE, 0))
  394. {
  395. pEvtObj->x = prevx;
  396. pEvtObj->y = prevy;
  397. }
  398. }
  399. }
  400. }
  401. }
  402. PAL_NPCWalkOneStep(wEventObjectID, wMonsterSpeed);
  403. }
  404. static VOID
  405. PAL_AdditionalCredits(
  406. VOID
  407. )
  408. /*++
  409. Purpose:
  410. Show the additional credits.
  411. Parameters:
  412. None.
  413. Return value:
  414. None.
  415. --*/
  416. {
  417. LPCSTR rgszStrings[] = {
  418. "SDLPAL (http://sdlpal.codeplex.com/)",
  419. #ifdef PAL_CLASSIC
  420. " (\xB8\x67\xA8\xE5\xAF\x53\xA7\x4F\xBD\x67 " __DATE__ ")",
  421. #else
  422. " (" __DATE__ ")",
  423. #endif
  424. " ",
  425. " (c) 2009-2011, Wei Mingzhi",
  426. " <whistler_wmz@users.sf.net>.",
  427. #ifdef __SYMBIAN32__
  428. " Symbian S60 \xB2\xBE\xB4\xD3 (c) 2009, netwan.",
  429. #endif
  430. #ifdef GPH
  431. " GPH Caanoo & Wiz \xB2\xBE\xB4\xD3 (c) 2011, Rikku2000.",
  432. #endif
  433. #ifdef GEKKO
  434. " Nintendo WII \xB2\xBE\xB4\xD3 (c) 2012, Rikku2000.",
  435. #endif
  436. #ifdef DINGOO
  437. " DINGOO & Dingux \xB2\xBE\xB4\xD3 (c) 2011, Rikku2000.",
  438. #endif
  439. " ",
  440. "\xA5\xBB\xB5\x7B\xA6\xA1\xAC\x4F\xA6\xDB\xA5\xD1\xB3\x6E\xC5\xE9\xA1\x41\xAB\xF6\xB7\xD3"
  441. " GNU General",
  442. "Public License (GPLv3) \xB5\x6F\xA7\x47",
  443. " ",
  444. " ...\xAB\xF6 Enter \xB5\xB2\xA7\xF4",
  445. ""
  446. };
  447. int i = 0;
  448. PAL_DrawOpeningMenuBackground();
  449. while (rgszStrings[i][0] != '\0')
  450. {
  451. PAL_DrawText(rgszStrings[i], PAL_XY(25, 20 + i * 16), DESCTEXT_COLOR, TRUE, FALSE);
  452. i++;
  453. }
  454. PAL_SetPalette(0, FALSE);
  455. VIDEO_UpdateScreen(NULL);
  456. PAL_WaitForKey(0);
  457. }
  458. static WORD
  459. PAL_InterpretInstruction(
  460. WORD wScriptEntry,
  461. WORD wEventObjectID
  462. )
  463. /*++
  464. Purpose:
  465. Interpret and execute one instruction in the script.
  466. Parameters:
  467. [IN] wScriptEntry - The script entry to execute.
  468. [IN] wEventObjectID - The event object ID which invoked the script.
  469. Return value:
  470. The address of the next script instruction to execute.
  471. --*/
  472. {
  473. LPEVENTOBJECT pEvtObj, pCurrent;
  474. LPSCRIPTENTRY pScript;
  475. int iPlayerRole, i, j, x, y;
  476. WORD w, wCurEventObjectID;
  477. pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
  478. if (wEventObjectID != 0)
  479. {
  480. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  481. }
  482. else
  483. {
  484. pEvtObj = NULL;
  485. }
  486. if (pScript->rgwOperand[0] == 0 || pScript->rgwOperand[0] == 0xFFFF)
  487. {
  488. pCurrent = pEvtObj;
  489. wCurEventObjectID = wEventObjectID;
  490. }
  491. else
  492. {
  493. i = pScript->rgwOperand[0] - 1;
  494. if (i > 0x9000)
  495. {
  496. // HACK for Dream 2.11 to avoid crash
  497. i -= 0x9000;
  498. }
  499. pCurrent = &(gpGlobals->g.lprgEventObject[i]);
  500. wCurEventObjectID = pScript->rgwOperand[0];
  501. }
  502. if (pScript->rgwOperand[0] < MAX_PLAYABLE_PLAYER_ROLES)
  503. {
  504. iPlayerRole = gpGlobals->rgParty[pScript->rgwOperand[0]].wPlayerRole;
  505. }
  506. else
  507. {
  508. iPlayerRole = gpGlobals->rgParty[0].wPlayerRole;
  509. }
  510. switch (pScript->wOperation)
  511. {
  512. case 0x000B:
  513. case 0x000C:
  514. case 0x000D:
  515. case 0x000E:
  516. //
  517. // walk one step
  518. //
  519. pEvtObj->wDirection = pScript->wOperation - 0x000B;
  520. PAL_NPCWalkOneStep(wEventObjectID, 2);
  521. break;
  522. case 0x000F:
  523. //
  524. // Set the direction and/or gesture for event object
  525. //
  526. if (pScript->rgwOperand[0] != 0xFFFF)
  527. {
  528. pEvtObj->wDirection = pScript->rgwOperand[0];
  529. }
  530. if (pScript->rgwOperand[1] != 0xFFFF)
  531. {
  532. pEvtObj->wCurrentFrameNum = pScript->rgwOperand[1];
  533. }
  534. break;
  535. case 0x0010:
  536. //
  537. // Walk straight to the specified position
  538. //
  539. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  540. pScript->rgwOperand[2], 3))
  541. {
  542. wScriptEntry--;
  543. }
  544. break;
  545. case 0x0011:
  546. //
  547. // Walk straight to the specified position, at a lower speed
  548. //
  549. if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
  550. {
  551. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  552. pScript->rgwOperand[2], 2))
  553. {
  554. wScriptEntry--;
  555. }
  556. }
  557. else
  558. {
  559. wScriptEntry--;
  560. }
  561. break;
  562. case 0x0012:
  563. //
  564. // Set the position of the event object, relative to the party
  565. //
  566. pCurrent->x =
  567. pScript->rgwOperand[1] + PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  568. pCurrent->y =
  569. pScript->rgwOperand[2] + PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  570. break;
  571. case 0x0013:
  572. //
  573. // Set the position of the event object
  574. //
  575. pCurrent->x = pScript->rgwOperand[1];
  576. pCurrent->y = pScript->rgwOperand[2];
  577. break;
  578. case 0x0014:
  579. //
  580. // Set the gesture of the event object
  581. //
  582. pEvtObj->wCurrentFrameNum = pScript->rgwOperand[0];
  583. pEvtObj->wDirection = kDirSouth;
  584. break;
  585. case 0x0015:
  586. //
  587. // Set the direction and gesture for a party member
  588. //
  589. gpGlobals->wPartyDirection = pScript->rgwOperand[0];
  590. gpGlobals->rgParty[pScript->rgwOperand[2]].wFrame =
  591. gpGlobals->wPartyDirection * 3 + pScript->rgwOperand[1];
  592. break;
  593. case 0x0016:
  594. //
  595. // Set the direction and gesture for an event object
  596. //
  597. if (pScript->rgwOperand[0] != 0)
  598. {
  599. pCurrent->wDirection = pScript->rgwOperand[1];
  600. pCurrent->wCurrentFrameNum = pScript->rgwOperand[2];
  601. }
  602. break;
  603. case 0x0017:
  604. //
  605. // set the player's extra attribute
  606. //
  607. {
  608. WORD *p;
  609. i = pScript->rgwOperand[0] - 0xB;
  610. p = (WORD *)(&gpGlobals->rgEquipmentEffect[i]); // HACKHACK
  611. p[pScript->rgwOperand[1] * MAX_PLAYER_ROLES + wEventObjectID] =
  612. (SHORT)pScript->rgwOperand[2];
  613. }
  614. break;
  615. case 0x0018:
  616. //
  617. // Equip the selected item
  618. //
  619. i = pScript->rgwOperand[0] - 0x0B;
  620. g_iCurEquipPart = i;
  621. //
  622. // The wEventObjectID parameter here should indicate the player role
  623. //
  624. PAL_RemoveEquipmentEffect(wEventObjectID, i);
  625. if (gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] != pScript->rgwOperand[1])
  626. {
  627. w = gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID];
  628. gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] = pScript->rgwOperand[1];
  629. PAL_AddItemToInventory(pScript->rgwOperand[1], -1);
  630. if (w != 0)
  631. {
  632. PAL_AddItemToInventory(w, 1);
  633. }
  634. gpGlobals->wLastUnequippedItem = w;
  635. }
  636. break;
  637. case 0x0019:
  638. //
  639. // Increase/decrease the player's attribute
  640. //
  641. {
  642. WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
  643. if (pScript->rgwOperand[2] == 0)
  644. {
  645. iPlayerRole = wEventObjectID;
  646. }
  647. else
  648. {
  649. iPlayerRole = pScript->rgwOperand[2] - 1;
  650. }
  651. p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] +=
  652. (SHORT)pScript->rgwOperand[1];
  653. }
  654. break;
  655. case 0x001A:
  656. //
  657. // Set player's stat
  658. //
  659. {
  660. WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
  661. if (g_iCurEquipPart != -1)
  662. {
  663. //
  664. // In the progress of equipping items
  665. //
  666. p = (WORD *)&(gpGlobals->rgEquipmentEffect[g_iCurEquipPart]);
  667. }
  668. if (pScript->rgwOperand[2] == 0)
  669. {
  670. //
  671. // Apply to the current player. The wEventObjectID should
  672. // indicate the player role.
  673. //
  674. iPlayerRole = wEventObjectID;
  675. }
  676. else
  677. {
  678. iPlayerRole = pScript->rgwOperand[2] - 1;
  679. }
  680. p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] =
  681. (SHORT)pScript->rgwOperand[1];
  682. }
  683. break;
  684. case 0x001B:
  685. //
  686. // Increase/decrease player's HP
  687. //
  688. if (pScript->rgwOperand[0])
  689. {
  690. //
  691. // Apply to everyone
  692. //
  693. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  694. {
  695. w = gpGlobals->rgParty[i].wPlayerRole;
  696. PAL_IncreaseHPMP(w, (SHORT)(pScript->rgwOperand[1]), 0);
  697. }
  698. }
  699. else
  700. {
  701. //
  702. // Apply to one player. The wEventObjectID parameter should indicate the player role.
  703. //
  704. if (!PAL_IncreaseHPMP(wEventObjectID, (SHORT)(pScript->rgwOperand[1]), 0))
  705. {
  706. g_fScriptSuccess = FALSE;
  707. }
  708. }
  709. break;
  710. case 0x001C:
  711. //
  712. // Increase/decrease player's MP
  713. //
  714. if (pScript->rgwOperand[0])
  715. {
  716. //
  717. // Apply to everyone
  718. //
  719. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  720. {
  721. w = gpGlobals->rgParty[i].wPlayerRole;
  722. PAL_IncreaseHPMP(w, 0, (SHORT)(pScript->rgwOperand[1]));
  723. }
  724. }
  725. else
  726. {
  727. //
  728. // Apply to one player. The wEventObjectID parameter should indicate the player role.
  729. //
  730. if (!PAL_IncreaseHPMP(wEventObjectID, 0, (SHORT)(pScript->rgwOperand[1])))
  731. {
  732. g_fScriptSuccess = FALSE;
  733. }
  734. }
  735. break;
  736. case 0x001D:
  737. //
  738. // Increase/decrease player's HP and MP
  739. //
  740. if (pScript->rgwOperand[0])
  741. {
  742. //
  743. // Apply to everyone
  744. //
  745. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  746. {
  747. w = gpGlobals->rgParty[i].wPlayerRole;
  748. PAL_IncreaseHPMP(w,
  749. (SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1]));
  750. }
  751. }
  752. else
  753. {
  754. //
  755. // Apply to one player. The wEventObjectID parameter should indicate the player role.
  756. //
  757. if (!PAL_IncreaseHPMP(wEventObjectID,
  758. (SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1])))
  759. {
  760. g_fScriptSuccess = FALSE;
  761. }
  762. }
  763. break;
  764. case 0x001E:
  765. //
  766. // Increase or decrease cash by the specified amount
  767. //
  768. if ((SHORT)(pScript->rgwOperand[0]) < 0 &&
  769. gpGlobals->dwCash < (WORD)(-(SHORT)(pScript->rgwOperand[0])))
  770. {
  771. //
  772. // not enough cash
  773. //
  774. wScriptEntry = pScript->rgwOperand[1] - 1;
  775. }
  776. else
  777. {
  778. gpGlobals->dwCash += (SHORT)(pScript->rgwOperand[0]);
  779. }
  780. break;
  781. case 0x001F:
  782. //
  783. // Add item to inventory
  784. //
  785. PAL_AddItemToInventory(pScript->rgwOperand[0], (SHORT)(pScript->rgwOperand[1]));
  786. break;
  787. case 0x0020:
  788. //
  789. // Remove item from inventory
  790. //
  791. if (!PAL_AddItemToInventory(pScript->rgwOperand[0],
  792. -((pScript->rgwOperand[1] == 0) ? 1 : pScript->rgwOperand[1])))
  793. {
  794. //
  795. // Try removing equipped item
  796. //
  797. x = pScript->rgwOperand[1];
  798. if (x == 0)
  799. {
  800. x = 1;
  801. }
  802. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  803. {
  804. w = gpGlobals->rgParty[i].wPlayerRole;
  805. for (j = 0; j < MAX_PLAYER_EQUIPMENTS; j++)
  806. {
  807. if (gpGlobals->g.PlayerRoles.rgwEquipment[j][w] == pScript->rgwOperand[0])
  808. {
  809. PAL_RemoveEquipmentEffect(w, j);
  810. gpGlobals->g.PlayerRoles.rgwEquipment[j][w] = 0;
  811. if (--x == 0)
  812. {
  813. i = 9999;
  814. break;
  815. }
  816. }
  817. }
  818. }
  819. if (x > 0 && pScript->rgwOperand[2] != 0)
  820. {
  821. wScriptEntry = pScript->rgwOperand[2] - 1;
  822. }
  823. }
  824. break;
  825. case 0x0021:
  826. //
  827. // Inflict damage to the enemy
  828. //
  829. if (pScript->rgwOperand[0])
  830. {
  831. //
  832. // Inflict damage to all enemies
  833. //
  834. for (i = 0;i <= g_Battle.wMaxEnemyIndex; i++)
  835. {
  836. if (g_Battle.rgEnemy[i].wObjectID != 0)
  837. {
  838. g_Battle.rgEnemy[i].e.wHealth -= pScript->rgwOperand[1];
  839. }
  840. }
  841. }
  842. else
  843. {
  844. //
  845. // Inflict damage to one enemy
  846. //
  847. g_Battle.rgEnemy[wEventObjectID].e.wHealth -= pScript->rgwOperand[1];
  848. }
  849. break;
  850. case 0x0022:
  851. //
  852. // Revive player
  853. //
  854. if (pScript->rgwOperand[0])
  855. {
  856. //
  857. // Apply to everyone
  858. //
  859. g_fScriptSuccess = FALSE;
  860. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  861. {
  862. w = gpGlobals->rgParty[i].wPlayerRole;
  863. if (gpGlobals->g.PlayerRoles.rgwHP[w] == 0)
  864. {
  865. gpGlobals->g.PlayerRoles.rgwHP[w] =
  866. gpGlobals->g.PlayerRoles.rgwMaxHP[w] * pScript->rgwOperand[1] / 10;
  867. PAL_CurePoisonByLevel(w, 3);
  868. for (x = 0; x < kStatusAll; x++)
  869. {
  870. PAL_RemovePlayerStatus(w, x);
  871. }
  872. g_fScriptSuccess = TRUE;
  873. }
  874. }
  875. }
  876. else
  877. {
  878. //
  879. // Apply to one player
  880. //
  881. if (gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] == 0)
  882. {
  883. gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] =
  884. gpGlobals->g.PlayerRoles.rgwMaxHP[wEventObjectID] * pScript->rgwOperand[1] / 10;
  885. PAL_CurePoisonByLevel(wEventObjectID, 3);
  886. for (x = 0; x < kStatusAll; x++)
  887. {
  888. PAL_RemovePlayerStatus(wEventObjectID, x);
  889. }
  890. }
  891. else
  892. {
  893. g_fScriptSuccess = FALSE;
  894. }
  895. }
  896. break;
  897. case 0x0023:
  898. //
  899. // Remove equipment from the specified player
  900. //
  901. if (pScript->rgwOperand[1] == 0)
  902. {
  903. //
  904. // Remove all equipments
  905. //
  906. for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  907. {
  908. w = gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole];
  909. if (w != 0)
  910. {
  911. PAL_AddItemToInventory(w, 1);
  912. gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole] = 0;
  913. }
  914. PAL_RemoveEquipmentEffect(iPlayerRole, i);
  915. }
  916. }
  917. else
  918. {
  919. w = gpGlobals->g.PlayerRoles.rgwEquipment[pScript->rgwOperand[1] - 1][iPlayerRole];
  920. if (w != 0)
  921. {
  922. PAL_RemoveEquipmentEffect(iPlayerRole, pScript->rgwOperand[1] - 1);
  923. PAL_AddItemToInventory(w, 1);
  924. gpGlobals->g.PlayerRoles.rgwEquipment[pScript->rgwOperand[1] - 1][iPlayerRole] = 0;
  925. }
  926. }
  927. break;
  928. case 0x0024:
  929. //
  930. // Set the autoscript entry address for an event object
  931. //
  932. if (pScript->rgwOperand[0] != 0)
  933. {
  934. pCurrent->wAutoScript = pScript->rgwOperand[1];
  935. }
  936. break;
  937. case 0x0025:
  938. //
  939. // Set the trigger script entry address for an event object
  940. //
  941. if (pScript->rgwOperand[0] != 0)
  942. {
  943. pCurrent->wTriggerScript = pScript->rgwOperand[1];
  944. }
  945. break;
  946. case 0x0026:
  947. //
  948. // Show the buy item menu
  949. //
  950. PAL_MakeScene();
  951. VIDEO_UpdateScreen(NULL);
  952. PAL_BuyMenu(pScript->rgwOperand[0]);
  953. break;
  954. case 0x0027:
  955. //
  956. // Show the sell item menu
  957. //
  958. PAL_MakeScene();
  959. VIDEO_UpdateScreen(NULL);
  960. PAL_SellMenu();
  961. break;
  962. case 0x0028:
  963. //
  964. // Apply poison to enemy
  965. //
  966. if (pScript->rgwOperand[0])
  967. {
  968. //
  969. // Apply to everyone
  970. //
  971. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  972. {
  973. w = g_Battle.rgEnemy[i].wObjectID;
  974. if (w == 0)
  975. {
  976. continue;
  977. }
  978. if (RandomLong(0, 9) >=
  979. gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery)
  980. {
  981. for (j = 0; j < MAX_POISONS; j++)
  982. {
  983. if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID ==
  984. pScript->rgwOperand[1])
  985. {
  986. break;
  987. }
  988. }
  989. if (j >= MAX_POISONS)
  990. {
  991. for (j = 0; j < MAX_POISONS; j++)
  992. {
  993. if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID == 0)
  994. {
  995. g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID = pScript->rgwOperand[1];
  996. g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript =
  997. PAL_RunTriggerScript(gpGlobals->g.rgObject[pScript->rgwOperand[1]].poison.wEnemyScript, wEventObjectID);
  998. break;
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. }
  1005. else
  1006. {
  1007. //
  1008. // Apply to one enemy
  1009. //
  1010. w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  1011. if (RandomLong(0, 9) >=
  1012. gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery)
  1013. {
  1014. for (j = 0; j < MAX_POISONS; j++)
  1015. {
  1016. if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID ==
  1017. pScript->rgwOperand[1])
  1018. {
  1019. break;
  1020. }
  1021. }
  1022. if (j >= MAX_POISONS)
  1023. {
  1024. for (j = 0; j < MAX_POISONS; j++)
  1025. {
  1026. if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID == 0)
  1027. {
  1028. g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID = pScript->rgwOperand[1];
  1029. g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonScript =
  1030. PAL_RunTriggerScript(gpGlobals->g.rgObject[pScript->rgwOperand[1]].poison.wEnemyScript, wEventObjectID);
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. break;
  1038. case 0x0029:
  1039. //
  1040. // Apply poison to player
  1041. //
  1042. if (pScript->rgwOperand[0])
  1043. {
  1044. //
  1045. // Apply to everyone
  1046. //
  1047. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1048. {
  1049. w = gpGlobals->rgParty[i].wPlayerRole;
  1050. if (RandomLong(1, 100) > PAL_GetPlayerPoisonResistance(w))
  1051. {
  1052. PAL_AddPoisonForPlayer(w, pScript->rgwOperand[1]);
  1053. }
  1054. }
  1055. }
  1056. else
  1057. {
  1058. //
  1059. // Apply to one player
  1060. //
  1061. if (RandomLong(1, 100) > PAL_GetPlayerPoisonResistance(wEventObjectID))
  1062. {
  1063. PAL_AddPoisonForPlayer(wEventObjectID, pScript->rgwOperand[1]);
  1064. }
  1065. }
  1066. break;
  1067. case 0x002A:
  1068. //
  1069. // Cure poison by object ID for enemy
  1070. //
  1071. if (pScript->rgwOperand[0])
  1072. {
  1073. //
  1074. // Apply to all enemies
  1075. //
  1076. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  1077. {
  1078. if (g_Battle.rgEnemy[i].wObjectID == 0)
  1079. {
  1080. continue;
  1081. }
  1082. for (j = 0; j < MAX_POISONS; j++)
  1083. {
  1084. if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID == pScript->rgwOperand[1])
  1085. {
  1086. g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID = 0;
  1087. g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript = 0;
  1088. break;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. else
  1094. {
  1095. //
  1096. // Apply to one enemy
  1097. //
  1098. for (j = 0; j < MAX_POISONS; j++)
  1099. {
  1100. if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID == pScript->rgwOperand[1])
  1101. {
  1102. g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonID = 0;
  1103. g_Battle.rgEnemy[wEventObjectID].rgPoisons[j].wPoisonScript = 0;
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. break;
  1109. case 0x002B:
  1110. //
  1111. // Cure poison by object ID for player
  1112. //
  1113. if (pScript->rgwOperand[0])
  1114. {
  1115. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1116. {
  1117. w = gpGlobals->rgParty[i].wPlayerRole;
  1118. PAL_CurePoisonByKind(w, pScript->rgwOperand[1]);
  1119. }
  1120. }
  1121. else
  1122. {
  1123. PAL_CurePoisonByKind(wEventObjectID, pScript->rgwOperand[1]);
  1124. }
  1125. break;
  1126. case 0x002C:
  1127. //
  1128. // Cure poisons by level
  1129. //
  1130. if (pScript->rgwOperand[0])
  1131. {
  1132. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1133. {
  1134. w = gpGlobals->rgParty[i].wPlayerRole;
  1135. PAL_CurePoisonByLevel(w, pScript->rgwOperand[1]);
  1136. }
  1137. }
  1138. else
  1139. {
  1140. PAL_CurePoisonByLevel(wEventObjectID, pScript->rgwOperand[1]);
  1141. }
  1142. break;
  1143. case 0x002D:
  1144. //
  1145. // Set the status for player
  1146. //
  1147. PAL_SetPlayerStatus(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1]);
  1148. break;
  1149. case 0x002E:
  1150. //
  1151. // Set the status for enemy
  1152. //
  1153. w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  1154. #ifdef PAL_CLASSIC
  1155. i = 9;
  1156. #else
  1157. i = ((pScript->rgwOperand[0] == kStatusSlow) ? 14 : 9);
  1158. #endif
  1159. if (RandomLong(0, i) >= gpGlobals->g.rgObject[w].enemy.wResistanceToSorcery &&
  1160. g_Battle.rgEnemy[wEventObjectID].rgwStatus[pScript->rgwOperand[0]] == 0)
  1161. {
  1162. g_Battle.rgEnemy[wEventObjectID].rgwStatus[pScript->rgwOperand[0]] = pScript->rgwOperand[1];
  1163. }
  1164. else
  1165. {
  1166. wScriptEntry = pScript->rgwOperand[2] - 1;
  1167. }
  1168. break;
  1169. case 0x002F:
  1170. //
  1171. // Remove player's status
  1172. //
  1173. PAL_RemovePlayerStatus(wEventObjectID, pScript->rgwOperand[0]);
  1174. break;
  1175. case 0x0030:
  1176. //
  1177. // Increase player's stat temporarily by percent
  1178. //
  1179. {
  1180. WORD *p = (WORD *)(&gpGlobals->rgEquipmentEffect[kBodyPartExtra]); // HACKHACK
  1181. WORD *p1 = (WORD *)(&gpGlobals->g.PlayerRoles);
  1182. if (pScript->rgwOperand[2] == 0)
  1183. {
  1184. iPlayerRole = wEventObjectID;
  1185. }
  1186. else
  1187. {
  1188. iPlayerRole = pScript->rgwOperand[2] - 1;
  1189. }
  1190. p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] =
  1191. p1[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] *
  1192. (SHORT)pScript->rgwOperand[1] / 100;
  1193. }
  1194. break;
  1195. case 0x0031:
  1196. //
  1197. // Change battle sprite temporarily for player
  1198. //
  1199. gpGlobals->rgEquipmentEffect[kBodyPartExtra].rgwSpriteNumInBattle[wEventObjectID] =
  1200. pScript->rgwOperand[0];
  1201. break;
  1202. case 0x0033:
  1203. //
  1204. // collect the enemy for items
  1205. //
  1206. if (g_Battle.rgEnemy[wEventObjectID].e.wCollectValue != 0)
  1207. {
  1208. gpGlobals->wCollectValue +=
  1209. g_Battle.rgEnemy[wEventObjectID].e.wCollectValue;
  1210. }
  1211. else
  1212. {
  1213. wScriptEntry = pScript->rgwOperand[0] - 1;
  1214. }
  1215. break;
  1216. case 0x0034:
  1217. //
  1218. // Transform collected enemies into items
  1219. //
  1220. if (gpGlobals->wCollectValue > 0)
  1221. {
  1222. char s[256];
  1223. #ifdef PAL_CLASSIC
  1224. i = RandomLong(1, gpGlobals->wCollectValue);
  1225. if (i > 9)
  1226. {
  1227. i = 9;
  1228. }
  1229. #else
  1230. i = RandomLong(1, 9);
  1231. if (i > gpGlobals->wCollectValue)
  1232. {
  1233. i = gpGlobals->wCollectValue;
  1234. }
  1235. #endif
  1236. gpGlobals->wCollectValue -= i;
  1237. i--;
  1238. PAL_AddItemToInventory(gpGlobals->g.lprgStore[0].rgwItems[i], 1);
  1239. PAL_StartDialog(kDialogCenterWindow, 0, 0, FALSE);
  1240. strcpy(s, PAL_GetWord(42));
  1241. strcat(s, PAL_GetWord(gpGlobals->g.lprgStore[0].rgwItems[i]));
  1242. PAL_ShowDialogText(s);
  1243. }
  1244. else
  1245. {
  1246. wScriptEntry = pScript->rgwOperand[0] - 1;
  1247. }
  1248. break;
  1249. case 0x0035:
  1250. //
  1251. // Shake the screen
  1252. //
  1253. i = pScript->rgwOperand[1];
  1254. if (i == 0)
  1255. {
  1256. i = 4;
  1257. }
  1258. VIDEO_ShakeScreen(pScript->rgwOperand[0], i);
  1259. if (!pScript->rgwOperand[0])
  1260. {
  1261. VIDEO_UpdateScreen(NULL);
  1262. }
  1263. break;
  1264. case 0x0036:
  1265. //
  1266. // Set the current playing RNG animation
  1267. //
  1268. gpGlobals->iCurPlayingRNG = pScript->rgwOperand[0];
  1269. break;
  1270. case 0x0037:
  1271. //
  1272. // Play RNG animation
  1273. //
  1274. PAL_RNGPlay(gpGlobals->iCurPlayingRNG,
  1275. pScript->rgwOperand[0],
  1276. pScript->rgwOperand[1] > 0 ? pScript->rgwOperand[1] : 999,
  1277. pScript->rgwOperand[2] > 0 ? pScript->rgwOperand[2] : 16);
  1278. break;
  1279. case 0x0038:
  1280. //
  1281. // Teleport the party out of the scene
  1282. //
  1283. if (!gpGlobals->fInBattle &&
  1284. gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport != 0)
  1285. {
  1286. gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport =
  1287. PAL_RunTriggerScript(gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport, 0xFFFF);
  1288. }
  1289. else
  1290. {
  1291. //
  1292. // failed
  1293. //
  1294. g_fScriptSuccess = FALSE;
  1295. wScriptEntry = pScript->rgwOperand[0] - 1;
  1296. }
  1297. break;
  1298. case 0x0039:
  1299. //
  1300. // Drain HP from enemy
  1301. //
  1302. w = gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole;
  1303. g_Battle.rgEnemy[wEventObjectID].e.wHealth -= pScript->rgwOperand[0];
  1304. gpGlobals->g.PlayerRoles.rgwHP[w] += pScript->rgwOperand[0];
  1305. if (gpGlobals->g.PlayerRoles.rgwHP[w] > gpGlobals->g.PlayerRoles.rgwMaxHP[w])
  1306. {
  1307. gpGlobals->g.PlayerRoles.rgwHP[w] = gpGlobals->g.PlayerRoles.rgwMaxHP[w];
  1308. }
  1309. break;
  1310. case 0x003A:
  1311. //
  1312. // Player flee from the battle
  1313. //
  1314. if (g_Battle.fIsBoss)
  1315. {
  1316. //
  1317. // Cannot flee from bosses
  1318. //
  1319. wScriptEntry = pScript->rgwOperand[0] - 1;
  1320. }
  1321. else
  1322. {
  1323. PAL_BattlePlayerEscape();
  1324. }
  1325. break;
  1326. case 0x003F:
  1327. //
  1328. // Ride the event object to the specified position, at a low speed
  1329. //
  1330. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1331. pScript->rgwOperand[2], 2);
  1332. break;
  1333. case 0x0040:
  1334. //
  1335. // set the trigger method for a event object
  1336. //
  1337. if (pScript->rgwOperand[0] != 0)
  1338. {
  1339. pCurrent->wTriggerMode = pScript->rgwOperand[1];
  1340. }
  1341. break;
  1342. case 0x0041:
  1343. //
  1344. // Mark the script as failed
  1345. //
  1346. g_fScriptSuccess = FALSE;
  1347. break;
  1348. case 0x0042:
  1349. //
  1350. // Simulate a magic for player
  1351. //
  1352. i = (SHORT)(pScript->rgwOperand[2]) - 1;
  1353. if (i < 0)
  1354. {
  1355. i = wEventObjectID;
  1356. }
  1357. PAL_BattleSimulateMagic(i, pScript->rgwOperand[0], pScript->rgwOperand[1]);
  1358. break;
  1359. case 0x0043:
  1360. //
  1361. // Set background music
  1362. //
  1363. gpGlobals->wNumMusic = pScript->rgwOperand[0];
  1364. PAL_PlayMUS(pScript->rgwOperand[0], (pScript->rgwOperand[0] != 0x3D), pScript->rgwOperand[1]);
  1365. break;
  1366. case 0x0044:
  1367. //
  1368. // Ride the event object to the specified position, at the normal speed
  1369. //
  1370. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1371. pScript->rgwOperand[2], 4);
  1372. break;
  1373. case 0x0045:
  1374. //
  1375. // Set battle music
  1376. //
  1377. gpGlobals->wNumBattleMusic = pScript->rgwOperand[0];
  1378. break;
  1379. case 0x0046:
  1380. //
  1381. // Set the party position on the map
  1382. //
  1383. {
  1384. int xOffset, yOffset, x, y;
  1385. xOffset =
  1386. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  1387. ? 16 : -16);
  1388. yOffset =
  1389. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  1390. ? 8 : -8);
  1391. x = pScript->rgwOperand[0] * 32 + pScript->rgwOperand[2] * 16;
  1392. y = pScript->rgwOperand[1] * 16 + pScript->rgwOperand[2] * 8;
  1393. x -= PAL_X(gpGlobals->partyoffset);
  1394. y -= PAL_Y(gpGlobals->partyoffset);
  1395. gpGlobals->viewport = PAL_XY(x, y);
  1396. x = PAL_X(gpGlobals->partyoffset);
  1397. y = PAL_Y(gpGlobals->partyoffset);
  1398. for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
  1399. {
  1400. gpGlobals->rgParty[i].x = x;
  1401. gpGlobals->rgParty[i].y = y;
  1402. gpGlobals->rgTrail[i].x = x + PAL_X(gpGlobals->viewport);
  1403. gpGlobals->rgTrail[i].y = y + PAL_Y(gpGlobals->viewport);
  1404. gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
  1405. x += xOffset;
  1406. y += yOffset;
  1407. }
  1408. }
  1409. break;
  1410. case 0x0047:
  1411. //
  1412. // Play sound effect
  1413. //
  1414. SOUND_Play(pScript->rgwOperand[0]);
  1415. break;
  1416. case 0x0049:
  1417. //
  1418. // Set the state of event object
  1419. //
  1420. pCurrent->sState = pScript->rgwOperand[1];
  1421. break;
  1422. case 0x004A:
  1423. //
  1424. // Set the current battlefield
  1425. //
  1426. gpGlobals->wNumBattleField = pScript->rgwOperand[0];
  1427. break;
  1428. case 0x004B:
  1429. //
  1430. // Nullify the event object for a short while
  1431. //
  1432. pEvtObj->sVanishTime = -15;
  1433. break;
  1434. case 0x004C:
  1435. //
  1436. // chase the player
  1437. //
  1438. i = pScript->rgwOperand[0]; // max. distance
  1439. j = pScript->rgwOperand[1]; // speed
  1440. if (i == 0)
  1441. {
  1442. i = 8;
  1443. }
  1444. if (j == 0)
  1445. {
  1446. j = 4;
  1447. }
  1448. PAL_MonsterChasePlayer(wEventObjectID, j, i, pScript->rgwOperand[2]);
  1449. break;
  1450. case 0x004D:
  1451. //
  1452. // wait for any key
  1453. //
  1454. PAL_WaitForKey(0);
  1455. break;
  1456. case 0x004E:
  1457. //
  1458. // Load the last saved game
  1459. //
  1460. PAL_FadeOut(1);
  1461. PAL_InitGameData(gpGlobals->bCurrentSaveSlot);
  1462. return 0; // don't go further
  1463. case 0x004F:
  1464. //
  1465. // Fade the screen to red color (game over)
  1466. //
  1467. PAL_FadeToRed();
  1468. break;
  1469. case 0x0050:
  1470. //
  1471. // screen fade out
  1472. //
  1473. VIDEO_UpdateScreen(NULL);
  1474. PAL_FadeOut(pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1);
  1475. gpGlobals->fNeedToFadeIn = TRUE;
  1476. break;
  1477. case 0x0051:
  1478. //
  1479. // screen fade in
  1480. //
  1481. VIDEO_UpdateScreen(NULL);
  1482. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  1483. ((SHORT)(pScript->rgwOperand[0]) > 0) ? pScript->rgwOperand[0] : 1);
  1484. gpGlobals->fNeedToFadeIn = FALSE;
  1485. break;
  1486. case 0x0052:
  1487. //
  1488. // hide the event object for a while, default 800 frames
  1489. //
  1490. pEvtObj->sState *= -1;
  1491. pEvtObj->sVanishTime = (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 800);
  1492. break;
  1493. case 0x0053:
  1494. //
  1495. // use the day palette
  1496. //
  1497. gpGlobals->fNightPalette = FALSE;
  1498. break;
  1499. case 0x0054:
  1500. //
  1501. // use the night palette
  1502. //
  1503. gpGlobals->fNightPalette = TRUE;
  1504. break;
  1505. case 0x0055:
  1506. //
  1507. // Add magic to a player
  1508. //
  1509. i = pScript->rgwOperand[1];
  1510. if (i == 0)
  1511. {
  1512. i = wEventObjectID;
  1513. }
  1514. else
  1515. {
  1516. i--;
  1517. }
  1518. PAL_AddMagic(i, pScript->rgwOperand[0]);
  1519. break;
  1520. case 0x0056:
  1521. //
  1522. // Remove magic from a player
  1523. //
  1524. i = pScript->rgwOperand[1];
  1525. if (i == 0)
  1526. {
  1527. i = wEventObjectID;
  1528. }
  1529. else
  1530. {
  1531. i--;
  1532. }
  1533. PAL_RemoveMagic(i, pScript->rgwOperand[0]);
  1534. break;
  1535. case 0x0057:
  1536. //
  1537. // Set the base damage of magic according to MP value
  1538. //
  1539. i = ((pScript->rgwOperand[1] == 0) ? 8 : pScript->rgwOperand[1]);
  1540. j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
  1541. gpGlobals->g.lprgMagic[j].wBaseDamage =
  1542. gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] * i;
  1543. gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] = 0;
  1544. break;
  1545. case 0x0058:
  1546. //
  1547. // Jump if there is less than the specified number of the specified items
  1548. // in the inventory
  1549. //
  1550. if (PAL_GetItemAmount(pScript->rgwOperand[0]) < (SHORT)(pScript->rgwOperand[1]))
  1551. {
  1552. wScriptEntry = pScript->rgwOperand[2] - 1;
  1553. }
  1554. break;
  1555. case 0x0059:
  1556. //
  1557. // Change to the specified scene
  1558. //
  1559. if (pScript->rgwOperand[0] > 0 && pScript->rgwOperand[0] <= MAX_SCENES &&
  1560. gpGlobals->wNumScene != pScript->rgwOperand[0])
  1561. {
  1562. //
  1563. // Set data to load the scene in the next frame
  1564. //
  1565. gpGlobals->wNumScene = pScript->rgwOperand[0];
  1566. PAL_SetLoadFlags(kLoadScene);
  1567. gpGlobals->fEnteringScene = TRUE;
  1568. gpGlobals->wLayer = 0;
  1569. }
  1570. break;
  1571. case 0x005A:
  1572. //
  1573. // Halve the player's HP
  1574. // The wEventObjectID parameter here should indicate the player role
  1575. //
  1576. gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] /= 2;
  1577. break;
  1578. case 0x005B:
  1579. //
  1580. // Halve the enemy's HP
  1581. //
  1582. w = g_Battle.rgEnemy[wEventObjectID].e.wHealth / 2 + 1;
  1583. if (w > pScript->rgwOperand[0])
  1584. {
  1585. w = pScript->rgwOperand[0];
  1586. }
  1587. g_Battle.rgEnemy[wEventObjectID].e.wHealth -= w;
  1588. break;
  1589. case 0x005C:
  1590. //
  1591. // Hide for a while
  1592. //
  1593. g_Battle.iHidingTime = -(INT)(pScript->rgwOperand[0]);
  1594. break;
  1595. case 0x005D:
  1596. //
  1597. // Jump if player doesn't have the specified poison
  1598. //
  1599. if (!PAL_IsPlayerPoisonedByKind(wEventObjectID, pScript->rgwOperand[0]))
  1600. {
  1601. wScriptEntry = pScript->rgwOperand[1] - 1;
  1602. }
  1603. break;
  1604. case 0x005E:
  1605. //
  1606. // Jump if enemy doesn't have the specified poison
  1607. //
  1608. for (i = 0; i < MAX_POISONS; i++)
  1609. {
  1610. if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[i].wPoisonID == pScript->rgwOperand[0])
  1611. {
  1612. break;
  1613. }
  1614. }
  1615. if (i >= MAX_POISONS)
  1616. {
  1617. wScriptEntry = pScript->rgwOperand[1] - 1;
  1618. }
  1619. break;
  1620. case 0x005F:
  1621. //
  1622. // Kill the player immediately
  1623. // The wEventObjectID parameter here should indicate the player role
  1624. //
  1625. gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] = 0;
  1626. break;
  1627. case 0x0060:
  1628. //
  1629. // Immediate KO of the enemy
  1630. //
  1631. g_Battle.rgEnemy[wEventObjectID].e.wHealth = 0;
  1632. break;
  1633. case 0x0061:
  1634. //
  1635. // Jump if player is not poisoned
  1636. //
  1637. if (!PAL_IsPlayerPoisonedByLevel(wEventObjectID, 1))
  1638. {
  1639. wScriptEntry = pScript->rgwOperand[0] - 1;
  1640. }
  1641. break;
  1642. case 0x0062:
  1643. //
  1644. // Pause enemy chasing for a while
  1645. //
  1646. gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
  1647. gpGlobals->wChaseRange = 0;
  1648. break;
  1649. case 0x0063:
  1650. //
  1651. // Speed up enemy chasing for a while
  1652. //
  1653. gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
  1654. gpGlobals->wChaseRange = 3;
  1655. break;
  1656. case 0x0064:
  1657. //
  1658. // Jump if enemy's HP is more than the specified percentage
  1659. //
  1660. i = gpGlobals->g.rgObject[g_Battle.rgEnemy[wEventObjectID].wObjectID].enemy.wEnemyID;
  1661. if ((INT)(g_Battle.rgEnemy[wEventObjectID].e.wHealth) * 100 >
  1662. (INT)(gpGlobals->g.lprgEnemy[i].wHealth) * pScript->rgwOperand[0])
  1663. {
  1664. wScriptEntry = pScript->rgwOperand[1] - 1;
  1665. }
  1666. break;
  1667. case 0x0065:
  1668. //
  1669. // Set the player's sprite
  1670. //
  1671. gpGlobals->g.PlayerRoles.rgwSpriteNum[pScript->rgwOperand[0]] = pScript->rgwOperand[1];
  1672. if (!gpGlobals->fInBattle && pScript->rgwOperand[2])
  1673. {
  1674. PAL_SetLoadFlags(kLoadPlayerSprite);
  1675. PAL_LoadResources();
  1676. }
  1677. break;
  1678. case 0x0066:
  1679. //
  1680. // Throw weapon to enemy
  1681. //
  1682. w = pScript->rgwOperand[1] * 5;
  1683. w += gpGlobals->g.PlayerRoles.rgwAttackStrength[gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole];
  1684. w += RandomLong(0, 4);
  1685. PAL_BattleSimulateMagic((SHORT)wEventObjectID, pScript->rgwOperand[0], w);
  1686. break;
  1687. case 0x0067:
  1688. //
  1689. // Enemy use magic
  1690. //
  1691. g_Battle.rgEnemy[wEventObjectID].e.wMagic = pScript->rgwOperand[0];
  1692. g_Battle.rgEnemy[wEventObjectID].e.wMagicRate =
  1693. ((pScript->rgwOperand[1] == 0) ? 10 : pScript->rgwOperand[1]);
  1694. break;
  1695. case 0x0068:
  1696. //
  1697. // Jump if it's enemy's turn
  1698. //
  1699. if (g_Battle.fEnemyMoving)
  1700. {
  1701. wScriptEntry = pScript->rgwOperand[0] - 1;
  1702. }
  1703. break;
  1704. case 0x0069:
  1705. //
  1706. // Enemy escape in battle
  1707. //
  1708. PAL_BattleEnemyEscape();
  1709. break;
  1710. case 0x006A:
  1711. //
  1712. // Steal from the enemy
  1713. //
  1714. PAL_BattleStealFromEnemy(wEventObjectID, pScript->rgwOperand[0]);
  1715. break;
  1716. case 0x006B:
  1717. //
  1718. // Blow away enemies
  1719. //
  1720. g_Battle.iBlow = (SHORT)(pScript->rgwOperand[0]);
  1721. break;
  1722. case 0x006C:
  1723. //
  1724. // Walk the NPC in one step
  1725. //
  1726. pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
  1727. pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
  1728. PAL_NPCWalkOneStep(wCurEventObjectID, 0);
  1729. break;
  1730. case 0x006D:
  1731. //
  1732. // Set the enter script and teleport script for a scene
  1733. //
  1734. if (pScript->rgwOperand[0])
  1735. {
  1736. if (pScript->rgwOperand[1])
  1737. {
  1738. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter =
  1739. pScript->rgwOperand[1];
  1740. }
  1741. if (pScript->rgwOperand[2])
  1742. {
  1743. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport =
  1744. pScript->rgwOperand[2];
  1745. }
  1746. if (pScript->rgwOperand[1] == 0 && pScript->rgwOperand[2] == 0)
  1747. {
  1748. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter = 0;
  1749. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport = 0;
  1750. }
  1751. }
  1752. break;
  1753. case 0x006E:
  1754. //
  1755. // Move the player to the specified position in one step
  1756. //
  1757. for (i = 3; i >= 0; i--)
  1758. {
  1759. gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
  1760. }
  1761. gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
  1762. gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  1763. gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  1764. gpGlobals->viewport = PAL_XY(
  1765. PAL_X(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[0]),
  1766. PAL_Y(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[1]));
  1767. gpGlobals->wLayer = pScript->rgwOperand[2] * 8;
  1768. if (pScript->rgwOperand[0] != 0 || pScript->rgwOperand[1] != 0)
  1769. {
  1770. PAL_UpdatePartyGestures(TRUE);
  1771. }
  1772. break;
  1773. case 0x006F:
  1774. //
  1775. // Sync the state of current event object with another event object
  1776. //
  1777. if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
  1778. {
  1779. pEvtObj->sState = (SHORT)(pScript->rgwOperand[1]);
  1780. }
  1781. break;
  1782. case 0x0070:
  1783. //
  1784. // Walk the party to the specified position
  1785. //
  1786. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 2);
  1787. break;
  1788. case 0x0071:
  1789. //
  1790. // Wave the screen
  1791. //
  1792. gpGlobals->wScreenWave = pScript->rgwOperand[0];
  1793. gpGlobals->sWaveProgression = (SHORT)(pScript->rgwOperand[1]);
  1794. break;
  1795. case 0x0073:
  1796. //
  1797. // Fade the screen to scene
  1798. //
  1799. VIDEO_BackupScreen();
  1800. PAL_MakeScene();
  1801. VIDEO_FadeScreen(pScript->rgwOperand[0]);
  1802. break;
  1803. case 0x0074:
  1804. //
  1805. // Jump if not all players are full HP
  1806. //
  1807. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1808. {
  1809. w = gpGlobals->rgParty[i].wPlayerRole;
  1810. if (gpGlobals->g.PlayerRoles.rgwHP[w] < gpGlobals->g.PlayerRoles.rgwMaxHP[w])
  1811. {
  1812. wScriptEntry = pScript->rgwOperand[0] - 1;
  1813. break;
  1814. }
  1815. }
  1816. break;
  1817. case 0x0075:
  1818. //
  1819. // Set the player party
  1820. //
  1821. gpGlobals->wMaxPartyMemberIndex = 0;
  1822. for (i = 0; i < 3; i++)
  1823. {
  1824. if (pScript->rgwOperand[i] != 0)
  1825. {
  1826. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex].wPlayerRole =
  1827. pScript->rgwOperand[i] - 1;
  1828. g_Battle.rgPlayer[gpGlobals->wMaxPartyMemberIndex].action.ActionType =
  1829. kBattleActionAttack;
  1830. gpGlobals->wMaxPartyMemberIndex++;
  1831. }
  1832. }
  1833. if (gpGlobals->wMaxPartyMemberIndex == 0)
  1834. {
  1835. // HACK for Dream 2.11
  1836. gpGlobals->rgParty[0].wPlayerRole = 0;
  1837. gpGlobals->wMaxPartyMemberIndex = 1;
  1838. }
  1839. gpGlobals->wMaxPartyMemberIndex--;
  1840. //
  1841. // Reload the player sprites
  1842. //
  1843. PAL_SetLoadFlags(kLoadPlayerSprite);
  1844. PAL_LoadResources();
  1845. memset(gpGlobals->rgPoisonStatus, 0, sizeof(gpGlobals->rgPoisonStatus));
  1846. PAL_UpdateEquipments();
  1847. break;
  1848. case 0x0076:
  1849. //
  1850. // Show FBP picture
  1851. //
  1852. PAL_EndingSetEffectSprite(0);
  1853. PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[1]);
  1854. break;
  1855. case 0x0077:
  1856. //
  1857. // Stop current playing music
  1858. //
  1859. PAL_PlayMUS(0, FALSE,
  1860. (pScript->rgwOperand[0] == 0) ? 2.0f : (FLOAT)(pScript->rgwOperand[0]) * 2);
  1861. gpGlobals->wNumMusic = 0;
  1862. break;
  1863. case 0x0078:
  1864. //
  1865. // FIXME: ???
  1866. //
  1867. break;
  1868. case 0x0079:
  1869. //
  1870. // Jump if the specified player is in the party
  1871. //
  1872. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1873. {
  1874. if (gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole] ==
  1875. pScript->rgwOperand[0])
  1876. {
  1877. wScriptEntry = pScript->rgwOperand[1] - 1;
  1878. break;
  1879. }
  1880. }
  1881. break;
  1882. case 0x007A:
  1883. //
  1884. // Walk the party to the specified position, at a higher speed
  1885. //
  1886. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 4);
  1887. break;
  1888. case 0x007B:
  1889. //
  1890. // Walk the party to the specified position, at the highest speed
  1891. //
  1892. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 8);
  1893. break;
  1894. case 0x007C:
  1895. //
  1896. // Walk straight to the specified position
  1897. //
  1898. if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
  1899. {
  1900. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1901. pScript->rgwOperand[2], 4))
  1902. {
  1903. wScriptEntry--;
  1904. }
  1905. }
  1906. else
  1907. {
  1908. wScriptEntry--;
  1909. }
  1910. break;
  1911. case 0x007D:
  1912. //
  1913. // Move the event object
  1914. //
  1915. pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
  1916. pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
  1917. break;
  1918. case 0x007E:
  1919. //
  1920. // Set the layer of event object
  1921. //
  1922. pCurrent->sLayer = (SHORT)(pScript->rgwOperand[1]);
  1923. break;
  1924. case 0x007F:
  1925. //
  1926. // Move the viewport
  1927. //
  1928. if (pScript->rgwOperand[0] == 0 && pScript->rgwOperand[1] == 0)
  1929. {
  1930. //
  1931. // Move the viewport back to normal state
  1932. //
  1933. x = gpGlobals->rgParty[0].x - 160;
  1934. y = gpGlobals->rgParty[0].y - 112;
  1935. gpGlobals->viewport =
  1936. PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
  1937. gpGlobals->partyoffset = PAL_XY(160, 112);
  1938. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1939. {
  1940. gpGlobals->rgParty[i].x -= x;
  1941. gpGlobals->rgParty[i].y -= y;
  1942. }
  1943. if (pScript->rgwOperand[2] != 0xFFFF)
  1944. {
  1945. PAL_MakeScene();
  1946. VIDEO_UpdateScreen(NULL);
  1947. }
  1948. }
  1949. else
  1950. {
  1951. DWORD time;
  1952. i = 0;
  1953. x = (SHORT)(pScript->rgwOperand[0]);
  1954. y = (SHORT)(pScript->rgwOperand[1]);
  1955. time = SDL_GetTicks() + FRAME_TIME;
  1956. do
  1957. {
  1958. if (pScript->rgwOperand[2] == 0xFFFF)
  1959. {
  1960. x = PAL_X(gpGlobals->viewport);
  1961. y = PAL_Y(gpGlobals->viewport);
  1962. gpGlobals->viewport =
  1963. PAL_XY(pScript->rgwOperand[0] * 32 - 160, pScript->rgwOperand[1] * 16 - 112);
  1964. x -= PAL_X(gpGlobals->viewport);
  1965. y -= PAL_Y(gpGlobals->viewport);
  1966. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  1967. {
  1968. gpGlobals->rgParty[j].x += x;
  1969. gpGlobals->rgParty[j].y += y;
  1970. }
  1971. }
  1972. else
  1973. {
  1974. gpGlobals->viewport =
  1975. PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
  1976. gpGlobals->partyoffset =
  1977. PAL_XY(PAL_X(gpGlobals->partyoffset) - x, PAL_Y(gpGlobals->partyoffset) - y);
  1978. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  1979. {
  1980. gpGlobals->rgParty[j].x -= x;
  1981. gpGlobals->rgParty[j].y -= y;
  1982. }
  1983. }
  1984. if (pScript->rgwOperand[2] != 0xFFFF)
  1985. {
  1986. PAL_GameUpdate(FALSE);
  1987. }
  1988. PAL_MakeScene();
  1989. VIDEO_UpdateScreen(NULL);
  1990. //
  1991. // Delay for one frame
  1992. //
  1993. PAL_ProcessEvent();
  1994. while (SDL_GetTicks() < time)
  1995. {
  1996. PAL_ProcessEvent();
  1997. SDL_Delay(1);
  1998. }
  1999. time = SDL_GetTicks() + FRAME_TIME;
  2000. } while (++i < (SHORT)(pScript->rgwOperand[2]));
  2001. }
  2002. break;
  2003. case 0x0080:
  2004. //
  2005. // Toggle day/night palette
  2006. //
  2007. gpGlobals->fNightPalette = !(gpGlobals->fNightPalette);
  2008. PAL_PaletteFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  2009. !(pScript->rgwOperand[0]));
  2010. break;
  2011. case 0x0081:
  2012. //
  2013. // Jump if the player is not facing the specified event object
  2014. //
  2015. {
  2016. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2017. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2018. {
  2019. //
  2020. // The event object is not in the current scene
  2021. //
  2022. wScriptEntry = pScript->rgwOperand[2] - 1;
  2023. g_fScriptSuccess = FALSE;
  2024. break;
  2025. }
  2026. x = pCurrent->x;
  2027. y = pCurrent->y;
  2028. x +=
  2029. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  2030. ? 16 : -16);
  2031. y +=
  2032. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  2033. ? 8 : -8);
  2034. x -= PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  2035. y -= PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  2036. if (abs(x) + abs(y * 2) < pScript->rgwOperand[1] * 32 + 16)
  2037. {
  2038. if (pScript->rgwOperand[1] > 0)
  2039. {
  2040. //
  2041. // Change the trigger mode so that the object can be triggered in next frame
  2042. //
  2043. pCurrent->wTriggerMode = kTriggerTouchNormal + pScript->rgwOperand[1];
  2044. }
  2045. }
  2046. else
  2047. {
  2048. wScriptEntry = pScript->rgwOperand[2] - 1;
  2049. g_fScriptSuccess = FALSE;
  2050. }
  2051. }
  2052. break;
  2053. case 0x0082:
  2054. //
  2055. // Walk straight to the specified position, at a high speed
  2056. //
  2057. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2058. pScript->rgwOperand[2], 8))
  2059. {
  2060. wScriptEntry--;
  2061. }
  2062. break;
  2063. case 0x0083:
  2064. //
  2065. // Jump if event object is not in the specified zone of the current event object
  2066. //
  2067. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2068. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2069. {
  2070. //
  2071. // The event object is not in the current scene
  2072. //
  2073. wScriptEntry = pScript->rgwOperand[2] - 1;
  2074. g_fScriptSuccess = FALSE;
  2075. break;
  2076. }
  2077. x = pEvtObj->x - pCurrent->x;
  2078. y = pEvtObj->y - pCurrent->y;
  2079. if (abs(x) + abs(y * 2) >= pScript->rgwOperand[1] * 32 + 16)
  2080. {
  2081. wScriptEntry = pScript->rgwOperand[2] - 1;
  2082. g_fScriptSuccess = FALSE;
  2083. }
  2084. break;
  2085. case 0x0084:
  2086. //
  2087. // Place the item which player used as an event object to the scene
  2088. //
  2089. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2090. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2091. {
  2092. //
  2093. // The event object is not in the current scene
  2094. //
  2095. wScriptEntry = pScript->rgwOperand[2] - 1;
  2096. g_fScriptSuccess = FALSE;
  2097. break;
  2098. }
  2099. x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  2100. y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  2101. x +=
  2102. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  2103. ? -16 : 16);
  2104. y +=
  2105. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  2106. ? -8 : 8);
  2107. if (PAL_CheckObstacle(PAL_XY(x, y), FALSE, 0))
  2108. {
  2109. wScriptEntry = pScript->rgwOperand[2] - 1;
  2110. g_fScriptSuccess = FALSE;
  2111. }
  2112. else
  2113. {
  2114. pCurrent->x = x;
  2115. pCurrent->y = y;
  2116. pCurrent->sState = (SHORT)(pScript->rgwOperand[1]);
  2117. }
  2118. break;
  2119. case 0x0085:
  2120. //
  2121. // Delay for a period
  2122. //
  2123. UTIL_Delay(pScript->rgwOperand[0] * 80);
  2124. break;
  2125. case 0x0086:
  2126. //
  2127. // Jump if the specified item is not equipped
  2128. //
  2129. y = FALSE;
  2130. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  2131. {
  2132. w = gpGlobals->rgParty[i].wPlayerRole;
  2133. for (x = 0; x < MAX_PLAYER_EQUIPMENTS; x++)
  2134. {
  2135. if (gpGlobals->g.PlayerRoles.rgwEquipment[x][w] == pScript->rgwOperand[0])
  2136. {
  2137. y = TRUE;
  2138. i = 999;
  2139. break;
  2140. }
  2141. }
  2142. }
  2143. if (!y)
  2144. {
  2145. wScriptEntry = pScript->rgwOperand[2] - 1;
  2146. }
  2147. break;
  2148. case 0x0087:
  2149. //
  2150. // Animate the event object
  2151. //
  2152. PAL_NPCWalkOneStep(wCurEventObjectID, 0);
  2153. break;
  2154. case 0x0088:
  2155. //
  2156. // Set the base damage of magic according to amount of money
  2157. //
  2158. i = ((gpGlobals->dwCash > 5000) ? 5000 : gpGlobals->dwCash);
  2159. gpGlobals->dwCash -= i;
  2160. j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
  2161. gpGlobals->g.lprgMagic[j].wBaseDamage = i * 2 / 5;
  2162. break;
  2163. case 0x0089:
  2164. //
  2165. // Set the battle result
  2166. //
  2167. g_Battle.BattleResult = pScript->rgwOperand[0];
  2168. break;
  2169. case 0x008A:
  2170. //
  2171. // Enable Auto-Battle for next battle
  2172. //
  2173. gpGlobals->fAutoBattle = TRUE;
  2174. break;
  2175. case 0x008B:
  2176. //
  2177. // change the current palette
  2178. //
  2179. gpGlobals->wNumPalette = pScript->rgwOperand[0];
  2180. if (!gpGlobals->fNeedToFadeIn)
  2181. {
  2182. PAL_SetPalette(gpGlobals->wNumPalette, FALSE);
  2183. }
  2184. break;
  2185. case 0x008C:
  2186. //
  2187. // Fade from/to color
  2188. //
  2189. PAL_ColorFade(pScript->rgwOperand[1], (BYTE)(pScript->rgwOperand[0]),
  2190. pScript->rgwOperand[2]);
  2191. gpGlobals->fNeedToFadeIn = FALSE;
  2192. break;
  2193. case 0x008D:
  2194. //
  2195. // Increase player's level
  2196. //
  2197. PAL_PlayerLevelUp(wEventObjectID, pScript->rgwOperand[0]);
  2198. break;
  2199. case 0x008F:
  2200. //
  2201. // Halve the cash amount
  2202. //
  2203. gpGlobals->dwCash /= 2;
  2204. break;
  2205. case 0x0090:
  2206. //
  2207. // Set the object script
  2208. //
  2209. gpGlobals->g.rgObject[pScript->rgwOperand[0]].rgwData[2 + pScript->rgwOperand[2]] =
  2210. pScript->rgwOperand[1];
  2211. break;
  2212. case 0x0091:
  2213. //
  2214. // Jump if the enemy is not alone
  2215. //
  2216. if (gpGlobals->fInBattle)
  2217. {
  2218. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2219. {
  2220. if (i != wEventObjectID &&
  2221. g_Battle.rgEnemy[i].wObjectID == g_Battle.rgEnemy[wEventObjectID].wObjectID)
  2222. {
  2223. wScriptEntry = pScript->rgwOperand[0] - 1;
  2224. break;
  2225. }
  2226. }
  2227. }
  2228. break;
  2229. case 0x0092:
  2230. //
  2231. // Show a magic-casting animation for a player in battle
  2232. //
  2233. if (gpGlobals->fInBattle)
  2234. {
  2235. if (pScript->rgwOperand[0] != 0)
  2236. {
  2237. PAL_BattleShowPlayerPreMagicAnim(pScript->rgwOperand[0] - 1, FALSE);
  2238. g_Battle.rgPlayer[pScript->rgwOperand[0] - 1].wCurrentFrame = 6;
  2239. }
  2240. for (i = 0; i < 5; i++)
  2241. {
  2242. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  2243. {
  2244. g_Battle.rgPlayer[j].iColorShift = i * 2;
  2245. }
  2246. PAL_BattleDelay(1, 0, TRUE);
  2247. }
  2248. PAL_BattleBackupScene();
  2249. PAL_BattleUpdateFighters();
  2250. PAL_BattleMakeScene();
  2251. PAL_BattleFadeScene();
  2252. }
  2253. break;
  2254. case 0x0093:
  2255. //
  2256. // Fade the screen. Update scene in the process.
  2257. //
  2258. PAL_SceneFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  2259. (SHORT)(pScript->rgwOperand[0]));
  2260. gpGlobals->fNeedToFadeIn = ((SHORT)(pScript->rgwOperand[0]) < 0);
  2261. break;
  2262. case 0x0094:
  2263. //
  2264. // Jump if the state of event object is the specified one
  2265. //
  2266. if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
  2267. {
  2268. wScriptEntry = pScript->rgwOperand[2] - 1;
  2269. }
  2270. break;
  2271. case 0x0095:
  2272. //
  2273. // Jump if the current scene is the specified one
  2274. //
  2275. if (gpGlobals->wNumScene == pScript->rgwOperand[0])
  2276. {
  2277. wScriptEntry = pScript->rgwOperand[1] - 1;
  2278. }
  2279. break;
  2280. case 0x0096:
  2281. //
  2282. // Show the ending animation
  2283. //
  2284. PAL_EndingAnimation();
  2285. break;
  2286. case 0x0097:
  2287. //
  2288. // Ride the event object to the specified position, at a higher speed
  2289. //
  2290. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2291. pScript->rgwOperand[2], 8);
  2292. break;
  2293. case 0x0098:
  2294. //
  2295. // Set follower of the party
  2296. //
  2297. if (pScript->rgwOperand[0] > 0)
  2298. {
  2299. gpGlobals->nFollower = 1;
  2300. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wPlayerRole = pScript->rgwOperand[0];
  2301. PAL_SetLoadFlags(kLoadPlayerSprite);
  2302. PAL_LoadResources();
  2303. //
  2304. // Update the position and gesture for the follower
  2305. //
  2306. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].x =
  2307. gpGlobals->rgTrail[3].x - PAL_X(gpGlobals->viewport);
  2308. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].y =
  2309. gpGlobals->rgTrail[3].y - PAL_Y(gpGlobals->viewport);
  2310. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wFrame =
  2311. gpGlobals->rgTrail[3].wDirection * 3;
  2312. }
  2313. else
  2314. {
  2315. gpGlobals->nFollower = 0;
  2316. }
  2317. break;
  2318. case 0x0099:
  2319. //
  2320. // Change the map for the specified scene
  2321. //
  2322. if (pScript->rgwOperand[0] == 0xFFFF)
  2323. {
  2324. gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wMapNum = pScript->rgwOperand[1];
  2325. PAL_SetLoadFlags(kLoadScene);
  2326. PAL_LoadResources();
  2327. }
  2328. else
  2329. {
  2330. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wMapNum = pScript->rgwOperand[1];
  2331. }
  2332. break;
  2333. case 0x009A:
  2334. //
  2335. // Set the state for multiple event objects
  2336. //
  2337. for (i = pScript->rgwOperand[0]; i <= pScript->rgwOperand[1]; i++)
  2338. {
  2339. gpGlobals->g.lprgEventObject[i - 1].sState = pScript->rgwOperand[2];
  2340. }
  2341. break;
  2342. case 0x009B:
  2343. //
  2344. // Fade to the current scene
  2345. // FIXME: This is obviously wrong
  2346. //
  2347. VIDEO_BackupScreen();
  2348. PAL_MakeScene();
  2349. VIDEO_FadeScreen(2);
  2350. break;
  2351. case 0x009C:
  2352. //
  2353. // Enemy duplicate itself
  2354. //
  2355. w = 0;
  2356. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2357. {
  2358. if (g_Battle.rgEnemy[i].wObjectID != 0)
  2359. {
  2360. w++;
  2361. }
  2362. }
  2363. if (w != 1)
  2364. {
  2365. //
  2366. // Duplication is only possible when only 1 enemy left
  2367. //
  2368. if (pScript->rgwOperand[1] != 0)
  2369. {
  2370. wScriptEntry = pScript->rgwOperand[1] - 1;
  2371. }
  2372. break;
  2373. }
  2374. w = pScript->rgwOperand[0];
  2375. if (w == 0)
  2376. {
  2377. w = 1;
  2378. }
  2379. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2380. {
  2381. if (w > 0 && g_Battle.rgEnemy[i].wObjectID == 0)
  2382. {
  2383. w--;
  2384. memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
  2385. g_Battle.rgEnemy[i].wObjectID = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  2386. g_Battle.rgEnemy[i].e = g_Battle.rgEnemy[wEventObjectID].e;
  2387. g_Battle.rgEnemy[i].wScriptOnTurnStart = g_Battle.rgEnemy[wEventObjectID].wScriptOnTurnStart;
  2388. g_Battle.rgEnemy[i].wScriptOnBattleEnd = g_Battle.rgEnemy[wEventObjectID].wScriptOnBattleEnd;
  2389. g_Battle.rgEnemy[i].wScriptOnReady = g_Battle.rgEnemy[wEventObjectID].wScriptOnReady;
  2390. g_Battle.rgEnemy[i].state = kFighterWait;
  2391. g_Battle.rgEnemy[i].flTimeMeter = 50;
  2392. g_Battle.rgEnemy[i].iColorShift = 0;
  2393. }
  2394. }
  2395. PAL_LoadBattleSprites();
  2396. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2397. {
  2398. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2399. {
  2400. continue;
  2401. }
  2402. g_Battle.rgEnemy[i].pos = g_Battle.rgEnemy[wEventObjectID].pos;
  2403. }
  2404. for (i = 0; i < 10; i++)
  2405. {
  2406. for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
  2407. {
  2408. x = (PAL_X(g_Battle.rgEnemy[j].pos) + PAL_X(g_Battle.rgEnemy[j].posOriginal)) / 2;
  2409. y = (PAL_Y(g_Battle.rgEnemy[j].pos) + PAL_Y(g_Battle.rgEnemy[j].posOriginal)) / 2;
  2410. g_Battle.rgEnemy[j].pos = PAL_XY(x, y);
  2411. }
  2412. PAL_BattleDelay(1, 0, TRUE);
  2413. }
  2414. PAL_BattleUpdateFighters();
  2415. PAL_BattleDelay(1, 0, TRUE);
  2416. break;
  2417. case 0x009E:
  2418. //
  2419. // Enemy summons another monster
  2420. //
  2421. x = 0;
  2422. w = pScript->rgwOperand[0];
  2423. y = (((SHORT)(pScript->rgwOperand[1]) <= 0) ? 1 : (SHORT)pScript->rgwOperand[1]);
  2424. if (w == 0 || w == 0xFFFF)
  2425. {
  2426. w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  2427. }
  2428. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2429. {
  2430. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2431. {
  2432. x++;
  2433. }
  2434. }
  2435. if (x < y || g_Battle.iHidingTime > 0 ||
  2436. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] != 0 ||
  2437. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] != 0 ||
  2438. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] != 0)
  2439. {
  2440. if (pScript->rgwOperand[2] != 0)
  2441. {
  2442. wScriptEntry = pScript->rgwOperand[2] - 1;
  2443. }
  2444. }
  2445. else
  2446. {
  2447. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2448. {
  2449. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2450. {
  2451. memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
  2452. g_Battle.rgEnemy[i].wObjectID = w;
  2453. g_Battle.rgEnemy[i].e = gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[w].enemy.wEnemyID];
  2454. g_Battle.rgEnemy[i].state = kFighterWait;
  2455. g_Battle.rgEnemy[i].wScriptOnTurnStart = gpGlobals->g.rgObject[w].enemy.wScriptOnTurnStart;
  2456. g_Battle.rgEnemy[i].wScriptOnBattleEnd = gpGlobals->g.rgObject[w].enemy.wScriptOnBattleEnd;
  2457. g_Battle.rgEnemy[i].wScriptOnReady = gpGlobals->g.rgObject[w].enemy.wScriptOnReady;
  2458. g_Battle.rgEnemy[i].flTimeMeter = 50;
  2459. g_Battle.rgEnemy[i].iColorShift = 8;
  2460. y--;
  2461. if (y <= 0)
  2462. {
  2463. break;
  2464. }
  2465. }
  2466. }
  2467. PAL_BattleDelay(2, 0, TRUE);
  2468. PAL_BattleBackupScene();
  2469. PAL_LoadBattleSprites();
  2470. PAL_BattleMakeScene();
  2471. SOUND_Play(212);
  2472. PAL_BattleFadeScene();
  2473. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2474. {
  2475. g_Battle.rgEnemy[i].iColorShift = 0;
  2476. }
  2477. PAL_BattleBackupScene();
  2478. PAL_BattleMakeScene();
  2479. PAL_BattleFadeScene();
  2480. }
  2481. break;
  2482. case 0x009F:
  2483. //
  2484. // Enemy transforms into something else
  2485. //
  2486. if (g_Battle.iHidingTime <= 0 &&
  2487. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] == 0 &&
  2488. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] == 0 &&
  2489. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] == 0)
  2490. {
  2491. w = g_Battle.rgEnemy[wEventObjectID].e.wHealth;
  2492. g_Battle.rgEnemy[wEventObjectID].wObjectID = pScript->rgwOperand[0];
  2493. g_Battle.rgEnemy[wEventObjectID].e =
  2494. gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[pScript->rgwOperand[0]].enemy.wEnemyID];
  2495. g_Battle.rgEnemy[wEventObjectID].e.wHealth = w;
  2496. g_Battle.rgEnemy[wEventObjectID].wCurrentFrame = 0;
  2497. for (i = 0; i < 6; i++)
  2498. {
  2499. g_Battle.rgEnemy[wEventObjectID].iColorShift = i;
  2500. PAL_BattleDelay(1, 0, FALSE);
  2501. }
  2502. g_Battle.rgEnemy[wEventObjectID].iColorShift = 0;
  2503. PAL_BattleBackupScene();
  2504. PAL_LoadBattleSprites();
  2505. PAL_BattleMakeScene();
  2506. PAL_BattleFadeScene();
  2507. }
  2508. break;
  2509. case 0x00A0:
  2510. //
  2511. // Quit game
  2512. //
  2513. PAL_AdditionalCredits();
  2514. PAL_Shutdown();
  2515. exit(0);
  2516. break;
  2517. case 0x00A1:
  2518. //
  2519. // Set the positions of all party members to the same as the first one
  2520. //
  2521. for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
  2522. {
  2523. gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
  2524. gpGlobals->rgTrail[i].x = gpGlobals->rgParty[0].x + PAL_X(gpGlobals->viewport);
  2525. gpGlobals->rgTrail[i].y = gpGlobals->rgParty[0].y + PAL_Y(gpGlobals->viewport);
  2526. }
  2527. for (i = 1; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  2528. {
  2529. gpGlobals->rgParty[i].x = gpGlobals->rgParty[0].x;
  2530. gpGlobals->rgParty[i].y = gpGlobals->rgParty[0].y - 1;
  2531. }
  2532. PAL_UpdatePartyGestures(FALSE);
  2533. break;
  2534. case 0x00A2:
  2535. //
  2536. // Jump to one of the following instructions randomly
  2537. //
  2538. wScriptEntry += RandomLong(0, pScript->rgwOperand[0] - 1);
  2539. break;
  2540. case 0x00A3:
  2541. //
  2542. // Play CD music. Use the RIX music for fallback.
  2543. //
  2544. if (!SOUND_PlayCDA(pScript->rgwOperand[0]))
  2545. {
  2546. PAL_PlayMUS(pScript->rgwOperand[1], TRUE, 0);
  2547. }
  2548. break;
  2549. case 0x00A4:
  2550. //
  2551. // Scroll FBP to the screen
  2552. //
  2553. if (pScript->rgwOperand[0] == 68)
  2554. {
  2555. //
  2556. // HACKHACK: to make the ending picture show correctly
  2557. //
  2558. PAL_ShowFBP(69, 0);
  2559. PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], TRUE);
  2560. }
  2561. else
  2562. {
  2563. PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], pScript->rgwOperand[1]);
  2564. }
  2565. break;
  2566. case 0x00A5:
  2567. //
  2568. // Show FBP picture with sprite effects
  2569. //
  2570. if (pScript->rgwOperand[1] != 0xFFFF)
  2571. {
  2572. PAL_EndingSetEffectSprite(pScript->rgwOperand[1]);
  2573. }
  2574. PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[2]);
  2575. break;
  2576. case 0x00A6:
  2577. //
  2578. // backup screen
  2579. //
  2580. VIDEO_BackupScreen();
  2581. break;
  2582. default:
  2583. TerminateOnError("SCRIPT: Invalid Instruction at %4x: (%4x - %4x, %4x, %4x)",
  2584. wScriptEntry, pScript->wOperation, pScript->rgwOperand[0],
  2585. pScript->rgwOperand[1], pScript->rgwOperand[2]);
  2586. break;
  2587. }
  2588. return wScriptEntry + 1;
  2589. }
  2590. WORD
  2591. PAL_RunTriggerScript(
  2592. WORD wScriptEntry,
  2593. WORD wEventObjectID
  2594. )
  2595. /*++
  2596. Purpose:
  2597. Runs a trigger script.
  2598. Parameters:
  2599. [IN] wScriptEntry - The script entry to execute.
  2600. [IN] wEventObjectID - The event object ID which invoked the script.
  2601. Return value:
  2602. The entry point of the script.
  2603. --*/
  2604. {
  2605. static WORD wLastEventObject = 0;
  2606. WORD wNextScriptEntry;
  2607. BOOL fEnded;
  2608. LPSCRIPTENTRY pScript;
  2609. LPEVENTOBJECT pEvtObj = NULL;
  2610. int i;
  2611. extern BOOL g_fUpdatedInBattle; // HACKHACK
  2612. wNextScriptEntry = wScriptEntry;
  2613. fEnded = FALSE;
  2614. g_fUpdatedInBattle = FALSE;
  2615. if (wEventObjectID == 0xFFFF)
  2616. {
  2617. wEventObjectID = wLastEventObject;
  2618. }
  2619. wLastEventObject = wEventObjectID;
  2620. if (wEventObjectID != 0)
  2621. {
  2622. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  2623. }
  2624. g_fScriptSuccess = TRUE;
  2625. //
  2626. // Set the default dialog speed.
  2627. //
  2628. PAL_DialogSetDelayTime(3);
  2629. while (wScriptEntry != 0 && !fEnded)
  2630. {
  2631. pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
  2632. UTIL_WriteLog(LOG_DEBUG, "[SCRIPT] %.4x: %.4x %.4x %.4x %.4x\n", wScriptEntry,
  2633. pScript->wOperation, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2634. pScript->rgwOperand[2], pScript->rgwOperand[3]);
  2635. switch (pScript->wOperation)
  2636. {
  2637. case 0x0000:
  2638. //
  2639. // Stop running
  2640. //
  2641. fEnded = TRUE;
  2642. break;
  2643. case 0x0001:
  2644. //
  2645. // Stop running and replace the entry with the next line
  2646. //
  2647. fEnded = TRUE;
  2648. wNextScriptEntry = wScriptEntry + 1;
  2649. break;
  2650. case 0x0002:
  2651. //
  2652. // Stop running and replace the entry with the specified one
  2653. //
  2654. if (pScript->rgwOperand[1] == 0 ||
  2655. ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
  2656. {
  2657. fEnded = TRUE;
  2658. wNextScriptEntry = pScript->rgwOperand[0];
  2659. }
  2660. else
  2661. {
  2662. //
  2663. // failed
  2664. //
  2665. pEvtObj->nScriptIdleFrame = 0;
  2666. wScriptEntry++;
  2667. }
  2668. break;
  2669. case 0x0003:
  2670. //
  2671. // unconditional jump
  2672. //
  2673. if (pScript->rgwOperand[1] == 0 ||
  2674. ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
  2675. {
  2676. wScriptEntry = pScript->rgwOperand[0];
  2677. }
  2678. else
  2679. {
  2680. //
  2681. // failed
  2682. //
  2683. pEvtObj->nScriptIdleFrame = 0;
  2684. wScriptEntry++;
  2685. }
  2686. break;
  2687. case 0x0004:
  2688. //
  2689. // Call script
  2690. //
  2691. PAL_RunTriggerScript(pScript->rgwOperand[0],
  2692. ((pScript->rgwOperand[1] == 0) ? wEventObjectID : pScript->rgwOperand[1]));
  2693. wScriptEntry++;
  2694. break;
  2695. case 0x0005:
  2696. //
  2697. // Redraw screen
  2698. //
  2699. PAL_ClearDialog(TRUE);
  2700. if (PAL_DialogIsPlayingRNG())
  2701. {
  2702. VIDEO_RestoreScreen();
  2703. }
  2704. else if (gpGlobals->fInBattle)
  2705. {
  2706. PAL_BattleMakeScene();
  2707. SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
  2708. VIDEO_UpdateScreen(NULL);
  2709. }
  2710. else
  2711. {
  2712. if (pScript->rgwOperand[2])
  2713. {
  2714. PAL_UpdatePartyGestures(FALSE);
  2715. }
  2716. PAL_MakeScene();
  2717. VIDEO_UpdateScreen(NULL);
  2718. UTIL_Delay((pScript->rgwOperand[1] == 0) ? 60 : (pScript->rgwOperand[1] * 60));
  2719. }
  2720. wScriptEntry++;
  2721. break;
  2722. case 0x0006:
  2723. //
  2724. // Jump to the specified address by the specified rate
  2725. //
  2726. if (RandomLong(1, 100) >= pScript->rgwOperand[0])
  2727. {
  2728. wScriptEntry = pScript->rgwOperand[1];
  2729. continue;
  2730. }
  2731. else
  2732. {
  2733. wScriptEntry++;
  2734. }
  2735. break;
  2736. case 0x0007:
  2737. //
  2738. // Start battle
  2739. //
  2740. i = PAL_StartBattle(pScript->rgwOperand[0], !pScript->rgwOperand[2]);
  2741. if (i == kBattleResultLost && pScript->rgwOperand[1] != 0)
  2742. {
  2743. wScriptEntry = pScript->rgwOperand[1];
  2744. }
  2745. else if (i == kBattleResultFleed && pScript->rgwOperand[2] != 0)
  2746. {
  2747. wScriptEntry = pScript->rgwOperand[2];
  2748. }
  2749. else
  2750. {
  2751. wScriptEntry++;
  2752. }
  2753. gpGlobals->fAutoBattle = FALSE;
  2754. break;
  2755. case 0x0008:
  2756. //
  2757. // Replace the entry with the next instruction
  2758. //
  2759. wScriptEntry++;
  2760. wNextScriptEntry = wScriptEntry;
  2761. break;
  2762. case 0x0009:
  2763. //
  2764. // wait for the specified number of frames
  2765. //
  2766. {
  2767. DWORD time;
  2768. PAL_ClearDialog(TRUE);
  2769. time = SDL_GetTicks() + FRAME_TIME;
  2770. for (i = 0; i < (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1); i++)
  2771. {
  2772. PAL_ProcessEvent();
  2773. while (SDL_GetTicks() < time)
  2774. {
  2775. PAL_ProcessEvent();
  2776. SDL_Delay(1);
  2777. }
  2778. time = SDL_GetTicks() + FRAME_TIME;
  2779. if (pScript->rgwOperand[2])
  2780. {
  2781. PAL_UpdatePartyGestures(FALSE);
  2782. }
  2783. PAL_GameUpdate(pScript->rgwOperand[1] ? TRUE : FALSE);
  2784. PAL_MakeScene();
  2785. VIDEO_UpdateScreen(NULL);
  2786. }
  2787. }
  2788. wScriptEntry++;
  2789. break;
  2790. case 0x000A:
  2791. //
  2792. // Goto the specified address if player selected no
  2793. //
  2794. PAL_ClearDialog(FALSE);
  2795. if (!PAL_ConfirmMenu())
  2796. {
  2797. wScriptEntry = pScript->rgwOperand[0];
  2798. }
  2799. else
  2800. {
  2801. wScriptEntry++;
  2802. }
  2803. break;
  2804. case 0x003B:
  2805. //
  2806. // Show dialog in the middle part of the screen
  2807. //
  2808. PAL_ClearDialog(TRUE);
  2809. PAL_StartDialog(kDialogCenter, (BYTE)pScript->rgwOperand[0], 0,
  2810. pScript->rgwOperand[2] ? TRUE : FALSE);
  2811. wScriptEntry++;
  2812. break;
  2813. case 0x003C:
  2814. //
  2815. // Show dialog in the upper part of the screen
  2816. //
  2817. PAL_ClearDialog(TRUE);
  2818. PAL_StartDialog(kDialogUpper, (BYTE)pScript->rgwOperand[1],
  2819. pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
  2820. wScriptEntry++;
  2821. break;
  2822. case 0x003D:
  2823. //
  2824. // Show dialog in the lower part of the screen
  2825. //
  2826. PAL_ClearDialog(TRUE);
  2827. PAL_StartDialog(kDialogLower, (BYTE)pScript->rgwOperand[1],
  2828. pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
  2829. wScriptEntry++;
  2830. break;
  2831. case 0x003E:
  2832. //
  2833. // Show text in a window at the center of the screen
  2834. //
  2835. PAL_ClearDialog(TRUE);
  2836. PAL_StartDialog(kDialogCenterWindow, (BYTE)pScript->rgwOperand[0], 0, FALSE);
  2837. wScriptEntry++;
  2838. break;
  2839. case 0x008E:
  2840. //
  2841. // Restore the screen
  2842. //
  2843. PAL_ClearDialog(TRUE);
  2844. VIDEO_RestoreScreen();
  2845. VIDEO_UpdateScreen(NULL);
  2846. wScriptEntry++;
  2847. break;
  2848. case 0xFFFF:
  2849. //
  2850. // Print dialog text
  2851. //
  2852. PAL_ShowDialogText(PAL_GetMsg(pScript->rgwOperand[0]));
  2853. wScriptEntry++;
  2854. break;
  2855. default:
  2856. PAL_ClearDialog(TRUE);
  2857. wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
  2858. break;
  2859. }
  2860. }
  2861. PAL_EndDialog();
  2862. g_iCurEquipPart = -1;
  2863. return wNextScriptEntry;
  2864. }
  2865. WORD
  2866. PAL_RunAutoScript(
  2867. WORD wScriptEntry,
  2868. WORD wEventObjectID
  2869. )
  2870. /*++
  2871. Purpose:
  2872. Runs the autoscript of the specified event object.
  2873. Parameters:
  2874. [IN] wScriptEntry - The script entry to execute.
  2875. [IN] wEventObjectID - The event object ID which invoked the script.
  2876. Return value:
  2877. The address of the next script instruction to execute.
  2878. --*/
  2879. {
  2880. LPSCRIPTENTRY pScript;
  2881. LPEVENTOBJECT pEvtObj;
  2882. begin:
  2883. pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
  2884. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  2885. //
  2886. // For autoscript, we should interpret one instruction per frame (except
  2887. // jumping) and save the address of next instruction.
  2888. //
  2889. switch (pScript->wOperation)
  2890. {
  2891. case 0x0000:
  2892. //
  2893. // Stop running
  2894. //
  2895. break;
  2896. case 0x0001:
  2897. //
  2898. // Stop running and replace the entry with the next line
  2899. //
  2900. wScriptEntry++;
  2901. break;
  2902. case 0x0002:
  2903. //
  2904. // Stop running and replace the entry with the specified one
  2905. //
  2906. if (pScript->rgwOperand[1] == 0 ||
  2907. ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
  2908. {
  2909. wScriptEntry = pScript->rgwOperand[0];
  2910. }
  2911. else
  2912. {
  2913. pEvtObj->wScriptIdleFrameCountAuto = 0;
  2914. wScriptEntry++;
  2915. }
  2916. break;
  2917. case 0x0003:
  2918. //
  2919. // unconditional jump
  2920. //
  2921. if (pScript->rgwOperand[1] == 0 ||
  2922. ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
  2923. {
  2924. wScriptEntry = pScript->rgwOperand[0];
  2925. goto begin;
  2926. }
  2927. else
  2928. {
  2929. pEvtObj->wScriptIdleFrameCountAuto = 0;
  2930. wScriptEntry++;
  2931. }
  2932. break;
  2933. case 0x0004:
  2934. //
  2935. // Call subroutine
  2936. //
  2937. PAL_RunTriggerScript(pScript->rgwOperand[0],
  2938. pScript->rgwOperand[1] ? pScript->rgwOperand[1] : wEventObjectID);
  2939. wScriptEntry++;
  2940. break;
  2941. case 0x0006:
  2942. //
  2943. // jump to the specified address by the specified rate
  2944. //
  2945. if (RandomLong(1, 100) >= pScript->rgwOperand[0] && pScript->rgwOperand[1] != 0)
  2946. {
  2947. wScriptEntry = pScript->rgwOperand[1];
  2948. goto begin;
  2949. }
  2950. else
  2951. {
  2952. wScriptEntry++;
  2953. }
  2954. break;
  2955. case 0x0009:
  2956. //
  2957. // Wait for a certain number of frames
  2958. //
  2959. if (++(pEvtObj->wScriptIdleFrameCountAuto) >= pScript->rgwOperand[0])
  2960. {
  2961. //
  2962. // waiting ended; go further
  2963. //
  2964. pEvtObj->wScriptIdleFrameCountAuto = 0;
  2965. wScriptEntry++;
  2966. }
  2967. break;
  2968. case 0xFFFF:
  2969. wScriptEntry++;
  2970. break;
  2971. default:
  2972. //
  2973. // Other operations
  2974. //
  2975. wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
  2976. break;
  2977. }
  2978. return wScriptEntry;
  2979. }