script.c 90 KB

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