script.c 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510
  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.codeplex.com/)",
  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][gConfig.uCodePage]);
  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. gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport =
  1293. PAL_RunTriggerScript(gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wScriptOnTeleport, 0xFFFF);
  1294. }
  1295. else
  1296. {
  1297. //
  1298. // failed
  1299. //
  1300. g_fScriptSuccess = FALSE;
  1301. wScriptEntry = pScript->rgwOperand[0] - 1;
  1302. }
  1303. break;
  1304. case 0x0039:
  1305. //
  1306. // Drain HP from enemy
  1307. //
  1308. w = gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole;
  1309. g_Battle.rgEnemy[wEventObjectID].e.wHealth -= pScript->rgwOperand[0];
  1310. gpGlobals->g.PlayerRoles.rgwHP[w] += pScript->rgwOperand[0];
  1311. if (gpGlobals->g.PlayerRoles.rgwHP[w] > gpGlobals->g.PlayerRoles.rgwMaxHP[w])
  1312. {
  1313. gpGlobals->g.PlayerRoles.rgwHP[w] = gpGlobals->g.PlayerRoles.rgwMaxHP[w];
  1314. }
  1315. break;
  1316. case 0x003A:
  1317. //
  1318. // Player flee from the battle
  1319. //
  1320. if (g_Battle.fIsBoss)
  1321. {
  1322. //
  1323. // Cannot flee from bosses
  1324. //
  1325. wScriptEntry = pScript->rgwOperand[0] - 1;
  1326. }
  1327. else
  1328. {
  1329. PAL_BattlePlayerEscape();
  1330. }
  1331. break;
  1332. case 0x003F:
  1333. //
  1334. // Ride the event object to the specified position, at a low speed
  1335. //
  1336. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1337. pScript->rgwOperand[2], 2);
  1338. break;
  1339. case 0x0040:
  1340. //
  1341. // set the trigger method for a event object
  1342. //
  1343. if (pScript->rgwOperand[0] != 0)
  1344. {
  1345. pCurrent->wTriggerMode = pScript->rgwOperand[1];
  1346. }
  1347. break;
  1348. case 0x0041:
  1349. //
  1350. // Mark the script as failed
  1351. //
  1352. g_fScriptSuccess = FALSE;
  1353. break;
  1354. case 0x0042:
  1355. //
  1356. // Simulate a magic for player
  1357. //
  1358. i = (SHORT)(pScript->rgwOperand[2]) - 1;
  1359. if (i < 0)
  1360. {
  1361. i = wEventObjectID;
  1362. }
  1363. PAL_BattleSimulateMagic(i, pScript->rgwOperand[0], pScript->rgwOperand[1]);
  1364. break;
  1365. case 0x0043:
  1366. //
  1367. // Set background music
  1368. //
  1369. gpGlobals->wNumMusic = pScript->rgwOperand[0];
  1370. AUDIO_PlayMusic(pScript->rgwOperand[0], (pScript->rgwOperand[0] != 0x3D), pScript->rgwOperand[1]);
  1371. break;
  1372. case 0x0044:
  1373. //
  1374. // Ride the event object to the specified position, at the normal speed
  1375. //
  1376. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1377. pScript->rgwOperand[2], 4);
  1378. break;
  1379. case 0x0045:
  1380. //
  1381. // Set battle music
  1382. //
  1383. gpGlobals->wNumBattleMusic = pScript->rgwOperand[0];
  1384. break;
  1385. case 0x0046:
  1386. //
  1387. // Set the party position on the map
  1388. //
  1389. {
  1390. int xOffset, yOffset, x, y;
  1391. xOffset =
  1392. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  1393. ? 16 : -16);
  1394. yOffset =
  1395. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  1396. ? 8 : -8);
  1397. x = pScript->rgwOperand[0] * 32 + pScript->rgwOperand[2] * 16;
  1398. y = pScript->rgwOperand[1] * 16 + pScript->rgwOperand[2] * 8;
  1399. x -= PAL_X(gpGlobals->partyoffset);
  1400. y -= PAL_Y(gpGlobals->partyoffset);
  1401. gpGlobals->viewport = PAL_XY(x, y);
  1402. x = PAL_X(gpGlobals->partyoffset);
  1403. y = PAL_Y(gpGlobals->partyoffset);
  1404. for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
  1405. {
  1406. gpGlobals->rgParty[i].x = x;
  1407. gpGlobals->rgParty[i].y = y;
  1408. gpGlobals->rgTrail[i].x = x + PAL_X(gpGlobals->viewport);
  1409. gpGlobals->rgTrail[i].y = y + PAL_Y(gpGlobals->viewport);
  1410. gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
  1411. x += xOffset;
  1412. y += yOffset;
  1413. }
  1414. }
  1415. break;
  1416. case 0x0047:
  1417. //
  1418. // Play sound effect
  1419. //
  1420. AUDIO_PlaySound(pScript->rgwOperand[0]);
  1421. break;
  1422. case 0x0049:
  1423. //
  1424. // Set the state of event object
  1425. //
  1426. pCurrent->sState = pScript->rgwOperand[1];
  1427. break;
  1428. case 0x004A:
  1429. //
  1430. // Set the current battlefield
  1431. //
  1432. gpGlobals->wNumBattleField = pScript->rgwOperand[0];
  1433. break;
  1434. case 0x004B:
  1435. //
  1436. // Nullify the event object for a short while
  1437. //
  1438. pEvtObj->sVanishTime = -15;
  1439. break;
  1440. case 0x004C:
  1441. //
  1442. // chase the player
  1443. //
  1444. i = pScript->rgwOperand[0]; // max. distance
  1445. j = pScript->rgwOperand[1]; // speed
  1446. if (i == 0)
  1447. {
  1448. i = 8;
  1449. }
  1450. if (j == 0)
  1451. {
  1452. j = 4;
  1453. }
  1454. PAL_MonsterChasePlayer(wEventObjectID, j, i, pScript->rgwOperand[2]);
  1455. break;
  1456. case 0x004D:
  1457. //
  1458. // wait for any key
  1459. //
  1460. PAL_WaitForKey(0);
  1461. break;
  1462. case 0x004E:
  1463. //
  1464. // Load the last saved game
  1465. //
  1466. PAL_FadeOut(1);
  1467. PAL_InitGameData(gpGlobals->bCurrentSaveSlot);
  1468. return 0; // don't go further
  1469. case 0x004F:
  1470. //
  1471. // Fade the screen to red color (game over)
  1472. //
  1473. PAL_FadeToRed();
  1474. break;
  1475. case 0x0050:
  1476. //
  1477. // screen fade out
  1478. //
  1479. VIDEO_UpdateScreen(NULL);
  1480. PAL_FadeOut(pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1);
  1481. gpGlobals->fNeedToFadeIn = TRUE;
  1482. break;
  1483. case 0x0051:
  1484. //
  1485. // screen fade in
  1486. //
  1487. VIDEO_UpdateScreen(NULL);
  1488. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  1489. ((SHORT)(pScript->rgwOperand[0]) > 0) ? pScript->rgwOperand[0] : 1);
  1490. gpGlobals->fNeedToFadeIn = FALSE;
  1491. break;
  1492. case 0x0052:
  1493. //
  1494. // hide the event object for a while, default 800 frames
  1495. //
  1496. pEvtObj->sState *= -1;
  1497. pEvtObj->sVanishTime = (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 800);
  1498. break;
  1499. case 0x0053:
  1500. //
  1501. // use the day palette
  1502. //
  1503. gpGlobals->fNightPalette = FALSE;
  1504. break;
  1505. case 0x0054:
  1506. //
  1507. // use the night palette
  1508. //
  1509. gpGlobals->fNightPalette = TRUE;
  1510. break;
  1511. case 0x0055:
  1512. //
  1513. // Add magic to a player
  1514. //
  1515. i = pScript->rgwOperand[1];
  1516. if (i == 0)
  1517. {
  1518. i = wEventObjectID;
  1519. }
  1520. else
  1521. {
  1522. i--;
  1523. }
  1524. PAL_AddMagic(i, pScript->rgwOperand[0]);
  1525. break;
  1526. case 0x0056:
  1527. //
  1528. // Remove magic from a player
  1529. //
  1530. i = pScript->rgwOperand[1];
  1531. if (i == 0)
  1532. {
  1533. i = wEventObjectID;
  1534. }
  1535. else
  1536. {
  1537. i--;
  1538. }
  1539. PAL_RemoveMagic(i, pScript->rgwOperand[0]);
  1540. break;
  1541. case 0x0057:
  1542. //
  1543. // Set the base damage of magic according to MP value
  1544. //
  1545. i = ((pScript->rgwOperand[1] == 0) ? 8 : pScript->rgwOperand[1]);
  1546. j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
  1547. gpGlobals->g.lprgMagic[j].wBaseDamage =
  1548. gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] * i;
  1549. gpGlobals->g.PlayerRoles.rgwMP[wEventObjectID] = 0;
  1550. break;
  1551. case 0x0058:
  1552. //
  1553. // Jump if there is less than the specified number of the specified items
  1554. // in the inventory
  1555. //
  1556. if (PAL_GetItemAmount(pScript->rgwOperand[0]) < (SHORT)(pScript->rgwOperand[1]))
  1557. {
  1558. wScriptEntry = pScript->rgwOperand[2] - 1;
  1559. }
  1560. break;
  1561. case 0x0059:
  1562. //
  1563. // Change to the specified scene
  1564. //
  1565. if (pScript->rgwOperand[0] > 0 && pScript->rgwOperand[0] <= MAX_SCENES &&
  1566. gpGlobals->wNumScene != pScript->rgwOperand[0])
  1567. {
  1568. //
  1569. // Set data to load the scene in the next frame
  1570. //
  1571. gpGlobals->wNumScene = pScript->rgwOperand[0];
  1572. PAL_SetLoadFlags(kLoadScene);
  1573. gpGlobals->fEnteringScene = TRUE;
  1574. gpGlobals->wLayer = 0;
  1575. }
  1576. break;
  1577. case 0x005A:
  1578. //
  1579. // Halve the player's HP
  1580. // The wEventObjectID parameter here should indicate the player role
  1581. //
  1582. gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] /= 2;
  1583. break;
  1584. case 0x005B:
  1585. //
  1586. // Halve the enemy's HP
  1587. //
  1588. w = g_Battle.rgEnemy[wEventObjectID].e.wHealth / 2 + 1;
  1589. if (w > pScript->rgwOperand[0])
  1590. {
  1591. w = pScript->rgwOperand[0];
  1592. }
  1593. g_Battle.rgEnemy[wEventObjectID].e.wHealth -= w;
  1594. break;
  1595. case 0x005C:
  1596. //
  1597. // Hide for a while
  1598. //
  1599. g_Battle.iHidingTime = -(INT)(pScript->rgwOperand[0]);
  1600. break;
  1601. case 0x005D:
  1602. //
  1603. // Jump if player doesn't have the specified poison
  1604. //
  1605. if (!PAL_IsPlayerPoisonedByKind(wEventObjectID, pScript->rgwOperand[0]))
  1606. {
  1607. wScriptEntry = pScript->rgwOperand[1] - 1;
  1608. }
  1609. break;
  1610. case 0x005E:
  1611. //
  1612. // Jump if enemy doesn't have the specified poison
  1613. //
  1614. for (i = 0; i < MAX_POISONS; i++)
  1615. {
  1616. if (g_Battle.rgEnemy[wEventObjectID].rgPoisons[i].wPoisonID == pScript->rgwOperand[0])
  1617. {
  1618. break;
  1619. }
  1620. }
  1621. if (i >= MAX_POISONS)
  1622. {
  1623. wScriptEntry = pScript->rgwOperand[1] - 1;
  1624. }
  1625. break;
  1626. case 0x005F:
  1627. //
  1628. // Kill the player immediately
  1629. // The wEventObjectID parameter here should indicate the player role
  1630. //
  1631. gpGlobals->g.PlayerRoles.rgwHP[wEventObjectID] = 0;
  1632. break;
  1633. case 0x0060:
  1634. //
  1635. // Immediate KO of the enemy
  1636. //
  1637. g_Battle.rgEnemy[wEventObjectID].e.wHealth = 0;
  1638. break;
  1639. case 0x0061:
  1640. //
  1641. // Jump if player is not poisoned
  1642. //
  1643. if (!PAL_IsPlayerPoisonedByLevel(wEventObjectID, 1))
  1644. {
  1645. wScriptEntry = pScript->rgwOperand[0] - 1;
  1646. }
  1647. break;
  1648. case 0x0062:
  1649. //
  1650. // Pause enemy chasing for a while
  1651. //
  1652. gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
  1653. gpGlobals->wChaseRange = 0;
  1654. break;
  1655. case 0x0063:
  1656. //
  1657. // Speed up enemy chasing for a while
  1658. //
  1659. gpGlobals->wChasespeedChangeCycles = pScript->rgwOperand[0];
  1660. gpGlobals->wChaseRange = 3;
  1661. break;
  1662. case 0x0064:
  1663. //
  1664. // Jump if enemy's HP is more than the specified percentage
  1665. //
  1666. i = gpGlobals->g.rgObject[g_Battle.rgEnemy[wEventObjectID].wObjectID].enemy.wEnemyID;
  1667. if ((INT)(g_Battle.rgEnemy[wEventObjectID].e.wHealth) * 100 >
  1668. (INT)(gpGlobals->g.lprgEnemy[i].wHealth) * pScript->rgwOperand[0])
  1669. {
  1670. wScriptEntry = pScript->rgwOperand[1] - 1;
  1671. }
  1672. break;
  1673. case 0x0065:
  1674. //
  1675. // Set the player's sprite
  1676. //
  1677. gpGlobals->g.PlayerRoles.rgwSpriteNum[pScript->rgwOperand[0]] = pScript->rgwOperand[1];
  1678. if (!gpGlobals->fInBattle && pScript->rgwOperand[2])
  1679. {
  1680. PAL_SetLoadFlags(kLoadPlayerSprite);
  1681. PAL_LoadResources();
  1682. }
  1683. break;
  1684. case 0x0066:
  1685. //
  1686. // Throw weapon to enemy
  1687. //
  1688. w = pScript->rgwOperand[1] * 5;
  1689. w += gpGlobals->g.PlayerRoles.rgwAttackStrength[gpGlobals->rgParty[g_Battle.wMovingPlayerIndex].wPlayerRole];
  1690. w += RandomLong(0, 4);
  1691. PAL_BattleSimulateMagic((SHORT)wEventObjectID, pScript->rgwOperand[0], w);
  1692. break;
  1693. case 0x0067:
  1694. //
  1695. // Enemy use magic
  1696. //
  1697. g_Battle.rgEnemy[wEventObjectID].e.wMagic = pScript->rgwOperand[0];
  1698. g_Battle.rgEnemy[wEventObjectID].e.wMagicRate =
  1699. ((pScript->rgwOperand[1] == 0) ? 10 : pScript->rgwOperand[1]);
  1700. break;
  1701. case 0x0068:
  1702. //
  1703. // Jump if it's enemy's turn
  1704. //
  1705. if (g_Battle.fEnemyMoving)
  1706. {
  1707. wScriptEntry = pScript->rgwOperand[0] - 1;
  1708. }
  1709. break;
  1710. case 0x0069:
  1711. //
  1712. // Enemy escape in battle
  1713. //
  1714. PAL_BattleEnemyEscape();
  1715. break;
  1716. case 0x006A:
  1717. //
  1718. // Steal from the enemy
  1719. //
  1720. PAL_BattleStealFromEnemy(wEventObjectID, pScript->rgwOperand[0]);
  1721. break;
  1722. case 0x006B:
  1723. //
  1724. // Blow away enemies
  1725. //
  1726. g_Battle.iBlow = (SHORT)(pScript->rgwOperand[0]);
  1727. break;
  1728. case 0x006C:
  1729. //
  1730. // Walk the NPC in one step
  1731. //
  1732. pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
  1733. pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
  1734. PAL_NPCWalkOneStep(wCurEventObjectID, 0);
  1735. break;
  1736. case 0x006D:
  1737. //
  1738. // Set the enter script and teleport script for a scene
  1739. //
  1740. if (pScript->rgwOperand[0])
  1741. {
  1742. if (pScript->rgwOperand[1])
  1743. {
  1744. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter =
  1745. pScript->rgwOperand[1];
  1746. }
  1747. if (pScript->rgwOperand[2])
  1748. {
  1749. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport =
  1750. pScript->rgwOperand[2];
  1751. }
  1752. if (pScript->rgwOperand[1] == 0 && pScript->rgwOperand[2] == 0)
  1753. {
  1754. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnEnter = 0;
  1755. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wScriptOnTeleport = 0;
  1756. }
  1757. }
  1758. break;
  1759. case 0x006E:
  1760. //
  1761. // Move the player to the specified position in one step
  1762. //
  1763. for (i = 3; i >= 0; i--)
  1764. {
  1765. gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
  1766. }
  1767. gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
  1768. gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  1769. gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  1770. gpGlobals->viewport = PAL_XY(
  1771. PAL_X(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[0]),
  1772. PAL_Y(gpGlobals->viewport) + (SHORT)(pScript->rgwOperand[1]));
  1773. gpGlobals->wLayer = pScript->rgwOperand[2] * 8;
  1774. if (pScript->rgwOperand[0] != 0 || pScript->rgwOperand[1] != 0)
  1775. {
  1776. PAL_UpdatePartyGestures(TRUE);
  1777. }
  1778. break;
  1779. case 0x006F:
  1780. //
  1781. // Sync the state of current event object with another event object
  1782. //
  1783. if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
  1784. {
  1785. pEvtObj->sState = (SHORT)(pScript->rgwOperand[1]);
  1786. }
  1787. break;
  1788. case 0x0070:
  1789. //
  1790. // Walk the party to the specified position
  1791. //
  1792. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 2);
  1793. break;
  1794. case 0x0071:
  1795. //
  1796. // Wave the screen
  1797. //
  1798. gpGlobals->wScreenWave = pScript->rgwOperand[0];
  1799. gpGlobals->sWaveProgression = (SHORT)(pScript->rgwOperand[1]);
  1800. break;
  1801. case 0x0073:
  1802. //
  1803. // Fade the screen to scene
  1804. //
  1805. VIDEO_BackupScreen(gpScreen);
  1806. PAL_MakeScene();
  1807. VIDEO_FadeScreen(pScript->rgwOperand[0]);
  1808. break;
  1809. case 0x0074:
  1810. //
  1811. // Jump if not all players are full HP
  1812. //
  1813. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1814. {
  1815. w = gpGlobals->rgParty[i].wPlayerRole;
  1816. if (gpGlobals->g.PlayerRoles.rgwHP[w] < gpGlobals->g.PlayerRoles.rgwMaxHP[w])
  1817. {
  1818. wScriptEntry = pScript->rgwOperand[0] - 1;
  1819. break;
  1820. }
  1821. }
  1822. break;
  1823. case 0x0075:
  1824. //
  1825. // Set the player party
  1826. //
  1827. gpGlobals->wMaxPartyMemberIndex = 0;
  1828. for (i = 0; i < 3; i++)
  1829. {
  1830. if (pScript->rgwOperand[i] != 0)
  1831. {
  1832. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex].wPlayerRole =
  1833. pScript->rgwOperand[i] - 1;
  1834. g_Battle.rgPlayer[gpGlobals->wMaxPartyMemberIndex].action.ActionType =
  1835. kBattleActionAttack;
  1836. gpGlobals->wMaxPartyMemberIndex++;
  1837. }
  1838. }
  1839. if (gpGlobals->wMaxPartyMemberIndex == 0)
  1840. {
  1841. // HACK for Dream 2.11
  1842. gpGlobals->rgParty[0].wPlayerRole = 0;
  1843. gpGlobals->wMaxPartyMemberIndex = 1;
  1844. }
  1845. gpGlobals->wMaxPartyMemberIndex--;
  1846. //
  1847. // Reload the player sprites
  1848. //
  1849. PAL_SetLoadFlags(kLoadPlayerSprite);
  1850. PAL_LoadResources();
  1851. memset(gpGlobals->rgPoisonStatus, 0, sizeof(gpGlobals->rgPoisonStatus));
  1852. PAL_UpdateEquipments();
  1853. break;
  1854. case 0x0076:
  1855. //
  1856. // Show FBP picture
  1857. //
  1858. if (gConfig.fIsWIN95)
  1859. {
  1860. SDL_FillRect(gpScreen, NULL, 0);
  1861. VIDEO_UpdateScreen(NULL);
  1862. }
  1863. else
  1864. {
  1865. PAL_EndingSetEffectSprite(0);
  1866. PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[1]);
  1867. }
  1868. break;
  1869. case 0x0077:
  1870. //
  1871. // Stop current playing music
  1872. //
  1873. AUDIO_PlayMusic(0, FALSE,
  1874. (pScript->rgwOperand[0] == 0) ? 2.0f : (FLOAT)(pScript->rgwOperand[0]) * 2);
  1875. gpGlobals->wNumMusic = 0;
  1876. break;
  1877. case 0x0078:
  1878. //
  1879. // FIXME: ???
  1880. //
  1881. break;
  1882. case 0x0079:
  1883. //
  1884. // Jump if the specified player is in the party
  1885. //
  1886. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1887. {
  1888. if (gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole] ==
  1889. pScript->rgwOperand[0])
  1890. {
  1891. wScriptEntry = pScript->rgwOperand[1] - 1;
  1892. break;
  1893. }
  1894. }
  1895. break;
  1896. case 0x007A:
  1897. //
  1898. // Walk the party to the specified position, at a higher speed
  1899. //
  1900. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 4);
  1901. break;
  1902. case 0x007B:
  1903. //
  1904. // Walk the party to the specified position, at the highest speed
  1905. //
  1906. PAL_PartyWalkTo(pScript->rgwOperand[0], pScript->rgwOperand[1], pScript->rgwOperand[2], 8);
  1907. break;
  1908. case 0x007C:
  1909. //
  1910. // Walk straight to the specified position
  1911. //
  1912. if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
  1913. {
  1914. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  1915. pScript->rgwOperand[2], 4))
  1916. {
  1917. wScriptEntry--;
  1918. }
  1919. }
  1920. else
  1921. {
  1922. wScriptEntry--;
  1923. }
  1924. break;
  1925. case 0x007D:
  1926. //
  1927. // Move the event object
  1928. //
  1929. pCurrent->x += (SHORT)(pScript->rgwOperand[1]);
  1930. pCurrent->y += (SHORT)(pScript->rgwOperand[2]);
  1931. break;
  1932. case 0x007E:
  1933. //
  1934. // Set the layer of event object
  1935. //
  1936. pCurrent->sLayer = (SHORT)(pScript->rgwOperand[1]);
  1937. break;
  1938. case 0x007F:
  1939. //
  1940. // Move the viewport
  1941. //
  1942. if (pScript->rgwOperand[0] == 0 && pScript->rgwOperand[1] == 0)
  1943. {
  1944. //
  1945. // Move the viewport back to normal state
  1946. //
  1947. x = gpGlobals->rgParty[0].x - 160;
  1948. y = gpGlobals->rgParty[0].y - 112;
  1949. gpGlobals->viewport =
  1950. PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
  1951. gpGlobals->partyoffset = PAL_XY(160, 112);
  1952. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1953. {
  1954. gpGlobals->rgParty[i].x -= x;
  1955. gpGlobals->rgParty[i].y -= y;
  1956. }
  1957. if (pScript->rgwOperand[2] != 0xFFFF)
  1958. {
  1959. PAL_MakeScene();
  1960. VIDEO_UpdateScreen(NULL);
  1961. }
  1962. }
  1963. else
  1964. {
  1965. DWORD time;
  1966. i = 0;
  1967. x = (SHORT)(pScript->rgwOperand[0]);
  1968. y = (SHORT)(pScript->rgwOperand[1]);
  1969. time = SDL_GetTicks() + FRAME_TIME;
  1970. do
  1971. {
  1972. if (pScript->rgwOperand[2] == 0xFFFF)
  1973. {
  1974. x = PAL_X(gpGlobals->viewport);
  1975. y = PAL_Y(gpGlobals->viewport);
  1976. gpGlobals->viewport =
  1977. PAL_XY(pScript->rgwOperand[0] * 32 - 160, pScript->rgwOperand[1] * 16 - 112);
  1978. x -= PAL_X(gpGlobals->viewport);
  1979. y -= PAL_Y(gpGlobals->viewport);
  1980. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  1981. {
  1982. gpGlobals->rgParty[j].x += x;
  1983. gpGlobals->rgParty[j].y += y;
  1984. }
  1985. }
  1986. else
  1987. {
  1988. gpGlobals->viewport =
  1989. PAL_XY(PAL_X(gpGlobals->viewport) + x, PAL_Y(gpGlobals->viewport) + y);
  1990. gpGlobals->partyoffset =
  1991. PAL_XY(PAL_X(gpGlobals->partyoffset) - x, PAL_Y(gpGlobals->partyoffset) - y);
  1992. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  1993. {
  1994. gpGlobals->rgParty[j].x -= x;
  1995. gpGlobals->rgParty[j].y -= y;
  1996. }
  1997. }
  1998. if (pScript->rgwOperand[2] != 0xFFFF)
  1999. {
  2000. PAL_GameUpdate(FALSE);
  2001. }
  2002. PAL_MakeScene();
  2003. VIDEO_UpdateScreen(NULL);
  2004. //
  2005. // Delay for one frame
  2006. //
  2007. PAL_DelayUntil(time);
  2008. time = SDL_GetTicks() + FRAME_TIME;
  2009. } while (++i < (SHORT)(pScript->rgwOperand[2]));
  2010. }
  2011. break;
  2012. case 0x0080:
  2013. //
  2014. // Toggle day/night palette
  2015. //
  2016. gpGlobals->fNightPalette = !(gpGlobals->fNightPalette);
  2017. PAL_PaletteFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  2018. !(pScript->rgwOperand[0]));
  2019. break;
  2020. case 0x0081:
  2021. //
  2022. // Jump if the player is not facing the specified event object
  2023. //
  2024. {
  2025. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2026. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2027. {
  2028. //
  2029. // The event object is not in the current scene
  2030. //
  2031. wScriptEntry = pScript->rgwOperand[2] - 1;
  2032. g_fScriptSuccess = FALSE;
  2033. break;
  2034. }
  2035. x = pCurrent->x;
  2036. y = pCurrent->y;
  2037. x +=
  2038. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  2039. ? 16 : -16);
  2040. y +=
  2041. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  2042. ? 8 : -8);
  2043. x -= PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  2044. y -= PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  2045. if (abs(x) + abs(y * 2) < pScript->rgwOperand[1] * 32 + 16)
  2046. {
  2047. if (pScript->rgwOperand[1] > 0)
  2048. {
  2049. //
  2050. // Change the trigger mode so that the object can be triggered in next frame
  2051. //
  2052. pCurrent->wTriggerMode = kTriggerTouchNormal + pScript->rgwOperand[1];
  2053. }
  2054. }
  2055. else
  2056. {
  2057. wScriptEntry = pScript->rgwOperand[2] - 1;
  2058. g_fScriptSuccess = FALSE;
  2059. }
  2060. }
  2061. break;
  2062. case 0x0082:
  2063. //
  2064. // Walk straight to the specified position, at a high speed
  2065. //
  2066. if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2067. pScript->rgwOperand[2], 8))
  2068. {
  2069. wScriptEntry--;
  2070. }
  2071. break;
  2072. case 0x0083:
  2073. //
  2074. // Jump if event object is not in the specified zone of the current event object
  2075. //
  2076. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2077. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2078. {
  2079. //
  2080. // The event object is not in the current scene
  2081. //
  2082. wScriptEntry = pScript->rgwOperand[2] - 1;
  2083. g_fScriptSuccess = FALSE;
  2084. break;
  2085. }
  2086. x = pEvtObj->x - pCurrent->x;
  2087. y = pEvtObj->y - pCurrent->y;
  2088. if (abs(x) + abs(y * 2) >= pScript->rgwOperand[1] * 32 + 16)
  2089. {
  2090. wScriptEntry = pScript->rgwOperand[2] - 1;
  2091. g_fScriptSuccess = FALSE;
  2092. }
  2093. break;
  2094. case 0x0084:
  2095. //
  2096. // Place the item which player used as an event object to the scene
  2097. //
  2098. if (pScript->rgwOperand[0] <= gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex ||
  2099. pScript->rgwOperand[0] > gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex)
  2100. {
  2101. //
  2102. // The event object is not in the current scene
  2103. //
  2104. wScriptEntry = pScript->rgwOperand[2] - 1;
  2105. g_fScriptSuccess = FALSE;
  2106. break;
  2107. }
  2108. x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
  2109. y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
  2110. x +=
  2111. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirSouth)
  2112. ? -16 : 16);
  2113. y +=
  2114. ((gpGlobals->wPartyDirection == kDirWest || gpGlobals->wPartyDirection == kDirNorth)
  2115. ? -8 : 8);
  2116. if (PAL_CheckObstacle(PAL_XY(x, y), FALSE, 0))
  2117. {
  2118. wScriptEntry = pScript->rgwOperand[2] - 1;
  2119. g_fScriptSuccess = FALSE;
  2120. }
  2121. else
  2122. {
  2123. pCurrent->x = x;
  2124. pCurrent->y = y;
  2125. pCurrent->sState = (SHORT)(pScript->rgwOperand[1]);
  2126. }
  2127. break;
  2128. case 0x0085:
  2129. //
  2130. // Delay for a period
  2131. //
  2132. UTIL_Delay(pScript->rgwOperand[0] * 80);
  2133. break;
  2134. case 0x0086:
  2135. //
  2136. // Jump if the specified item is not equipped
  2137. //
  2138. y = FALSE;
  2139. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  2140. {
  2141. w = gpGlobals->rgParty[i].wPlayerRole;
  2142. for (x = 0; x < MAX_PLAYER_EQUIPMENTS; x++)
  2143. {
  2144. if (gpGlobals->g.PlayerRoles.rgwEquipment[x][w] == pScript->rgwOperand[0])
  2145. {
  2146. y = TRUE;
  2147. i = 999;
  2148. break;
  2149. }
  2150. }
  2151. }
  2152. if (!y)
  2153. {
  2154. wScriptEntry = pScript->rgwOperand[2] - 1;
  2155. }
  2156. break;
  2157. case 0x0087:
  2158. //
  2159. // Animate the event object
  2160. //
  2161. PAL_NPCWalkOneStep(wCurEventObjectID, 0);
  2162. break;
  2163. case 0x0088:
  2164. //
  2165. // Set the base damage of magic according to amount of money
  2166. //
  2167. i = ((gpGlobals->dwCash > 5000) ? 5000 : gpGlobals->dwCash);
  2168. gpGlobals->dwCash -= i;
  2169. j = gpGlobals->g.rgObject[pScript->rgwOperand[0]].magic.wMagicNumber;
  2170. gpGlobals->g.lprgMagic[j].wBaseDamage = i * 2 / 5;
  2171. break;
  2172. case 0x0089:
  2173. //
  2174. // Set the battle result
  2175. //
  2176. g_Battle.BattleResult = pScript->rgwOperand[0];
  2177. break;
  2178. case 0x008A:
  2179. //
  2180. // Enable Auto-Battle for next battle
  2181. //
  2182. gpGlobals->fAutoBattle = TRUE;
  2183. break;
  2184. case 0x008B:
  2185. //
  2186. // change the current palette
  2187. //
  2188. gpGlobals->wNumPalette = pScript->rgwOperand[0];
  2189. if (!gpGlobals->fNeedToFadeIn)
  2190. {
  2191. PAL_SetPalette(gpGlobals->wNumPalette, FALSE);
  2192. }
  2193. break;
  2194. case 0x008C:
  2195. //
  2196. // Fade from/to color
  2197. //
  2198. PAL_ColorFade(pScript->rgwOperand[1], (BYTE)(pScript->rgwOperand[0]),
  2199. pScript->rgwOperand[2]);
  2200. gpGlobals->fNeedToFadeIn = FALSE;
  2201. break;
  2202. case 0x008D:
  2203. //
  2204. // Increase player's level
  2205. //
  2206. PAL_PlayerLevelUp(wEventObjectID, pScript->rgwOperand[0]);
  2207. break;
  2208. case 0x008F:
  2209. //
  2210. // Halve the cash amount
  2211. //
  2212. gpGlobals->dwCash /= 2;
  2213. break;
  2214. case 0x0090:
  2215. //
  2216. // Set the object script
  2217. //
  2218. gpGlobals->g.rgObject[pScript->rgwOperand[0]].rgwData[2 + pScript->rgwOperand[2]] =
  2219. pScript->rgwOperand[1];
  2220. break;
  2221. case 0x0091:
  2222. //
  2223. // Jump if the enemy is not alone
  2224. //
  2225. if (gpGlobals->fInBattle)
  2226. {
  2227. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2228. {
  2229. if (i != wEventObjectID &&
  2230. g_Battle.rgEnemy[i].wObjectID == g_Battle.rgEnemy[wEventObjectID].wObjectID)
  2231. {
  2232. wScriptEntry = pScript->rgwOperand[0] - 1;
  2233. break;
  2234. }
  2235. }
  2236. }
  2237. break;
  2238. case 0x0092:
  2239. //
  2240. // Show a magic-casting animation for a player in battle
  2241. //
  2242. if (gpGlobals->fInBattle)
  2243. {
  2244. if (pScript->rgwOperand[0] != 0)
  2245. {
  2246. PAL_BattleShowPlayerPreMagicAnim(pScript->rgwOperand[0] - 1, FALSE);
  2247. g_Battle.rgPlayer[pScript->rgwOperand[0] - 1].wCurrentFrame = 6;
  2248. }
  2249. for (i = 0; i < 5; i++)
  2250. {
  2251. for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
  2252. {
  2253. g_Battle.rgPlayer[j].iColorShift = i * 2;
  2254. }
  2255. PAL_BattleDelay(1, 0, TRUE);
  2256. }
  2257. VIDEO_BackupScreen(g_Battle.lpSceneBuf);
  2258. PAL_BattleUpdateFighters();
  2259. PAL_BattleMakeScene();
  2260. PAL_BattleFadeScene();
  2261. }
  2262. break;
  2263. case 0x0093:
  2264. //
  2265. // Fade the screen. Update scene in the process.
  2266. //
  2267. PAL_SceneFade(gpGlobals->wNumPalette, gpGlobals->fNightPalette,
  2268. (SHORT)(pScript->rgwOperand[0]));
  2269. gpGlobals->fNeedToFadeIn = ((SHORT)(pScript->rgwOperand[0]) < 0);
  2270. break;
  2271. case 0x0094:
  2272. //
  2273. // Jump if the state of event object is the specified one
  2274. //
  2275. if (pCurrent->sState == (SHORT)(pScript->rgwOperand[1]))
  2276. {
  2277. wScriptEntry = pScript->rgwOperand[2] - 1;
  2278. }
  2279. break;
  2280. case 0x0095:
  2281. //
  2282. // Jump if the current scene is the specified one
  2283. //
  2284. if (gpGlobals->wNumScene == pScript->rgwOperand[0])
  2285. {
  2286. wScriptEntry = pScript->rgwOperand[1] - 1;
  2287. }
  2288. break;
  2289. case 0x0096:
  2290. //
  2291. // Show the ending animation
  2292. //
  2293. if (!gConfig.fIsWIN95)
  2294. PAL_EndingAnimation();
  2295. break;
  2296. case 0x0097:
  2297. //
  2298. // Ride the event object to the specified position, at a higher speed
  2299. //
  2300. PAL_PartyRideEventObject(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2301. pScript->rgwOperand[2], 8);
  2302. break;
  2303. case 0x0098:
  2304. //
  2305. // Set follower of the party
  2306. //
  2307. if (pScript->rgwOperand[0] > 0)
  2308. {
  2309. gpGlobals->nFollower = 1;
  2310. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wPlayerRole = pScript->rgwOperand[0];
  2311. PAL_SetLoadFlags(kLoadPlayerSprite);
  2312. PAL_LoadResources();
  2313. //
  2314. // Update the position and gesture for the follower
  2315. //
  2316. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].x =
  2317. gpGlobals->rgTrail[3].x - PAL_X(gpGlobals->viewport);
  2318. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].y =
  2319. gpGlobals->rgTrail[3].y - PAL_Y(gpGlobals->viewport);
  2320. gpGlobals->rgParty[gpGlobals->wMaxPartyMemberIndex + 1].wFrame =
  2321. gpGlobals->rgTrail[3].wDirection * 3;
  2322. }
  2323. else
  2324. {
  2325. gpGlobals->nFollower = 0;
  2326. }
  2327. break;
  2328. case 0x0099:
  2329. //
  2330. // Change the map for the specified scene
  2331. //
  2332. if (pScript->rgwOperand[0] == 0xFFFF)
  2333. {
  2334. gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wMapNum = pScript->rgwOperand[1];
  2335. PAL_SetLoadFlags(kLoadScene);
  2336. PAL_LoadResources();
  2337. }
  2338. else
  2339. {
  2340. gpGlobals->g.rgScene[pScript->rgwOperand[0] - 1].wMapNum = pScript->rgwOperand[1];
  2341. }
  2342. break;
  2343. case 0x009A:
  2344. //
  2345. // Set the state for multiple event objects
  2346. //
  2347. for (i = pScript->rgwOperand[0]; i <= pScript->rgwOperand[1]; i++)
  2348. {
  2349. gpGlobals->g.lprgEventObject[i - 1].sState = pScript->rgwOperand[2];
  2350. }
  2351. break;
  2352. case 0x009B:
  2353. //
  2354. // Fade to the current scene
  2355. // FIXME: This is obviously wrong
  2356. //
  2357. VIDEO_BackupScreen(gpScreen);
  2358. PAL_MakeScene();
  2359. VIDEO_FadeScreen(2);
  2360. break;
  2361. case 0x009C:
  2362. //
  2363. // Enemy duplicate itself
  2364. //
  2365. w = 0;
  2366. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2367. {
  2368. if (g_Battle.rgEnemy[i].wObjectID != 0)
  2369. {
  2370. w++;
  2371. }
  2372. }
  2373. if (w != 1)
  2374. {
  2375. //
  2376. // Duplication is only possible when only 1 enemy left
  2377. //
  2378. if (pScript->rgwOperand[1] != 0)
  2379. {
  2380. wScriptEntry = pScript->rgwOperand[1] - 1;
  2381. }
  2382. break;
  2383. }
  2384. w = pScript->rgwOperand[0];
  2385. if (w == 0)
  2386. {
  2387. w = 1;
  2388. }
  2389. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2390. {
  2391. if (w > 0 && g_Battle.rgEnemy[i].wObjectID == 0)
  2392. {
  2393. w--;
  2394. memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
  2395. g_Battle.rgEnemy[i].wObjectID = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  2396. g_Battle.rgEnemy[i].e = g_Battle.rgEnemy[wEventObjectID].e;
  2397. g_Battle.rgEnemy[i].wScriptOnTurnStart = g_Battle.rgEnemy[wEventObjectID].wScriptOnTurnStart;
  2398. g_Battle.rgEnemy[i].wScriptOnBattleEnd = g_Battle.rgEnemy[wEventObjectID].wScriptOnBattleEnd;
  2399. g_Battle.rgEnemy[i].wScriptOnReady = g_Battle.rgEnemy[wEventObjectID].wScriptOnReady;
  2400. g_Battle.rgEnemy[i].state = kFighterWait;
  2401. g_Battle.rgEnemy[i].flTimeMeter = 50;
  2402. g_Battle.rgEnemy[i].iColorShift = 0;
  2403. }
  2404. }
  2405. PAL_LoadBattleSprites();
  2406. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2407. {
  2408. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2409. {
  2410. continue;
  2411. }
  2412. g_Battle.rgEnemy[i].pos = g_Battle.rgEnemy[wEventObjectID].pos;
  2413. }
  2414. for (i = 0; i < 10; i++)
  2415. {
  2416. for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
  2417. {
  2418. x = (PAL_X(g_Battle.rgEnemy[j].pos) + PAL_X(g_Battle.rgEnemy[j].posOriginal)) / 2;
  2419. y = (PAL_Y(g_Battle.rgEnemy[j].pos) + PAL_Y(g_Battle.rgEnemy[j].posOriginal)) / 2;
  2420. g_Battle.rgEnemy[j].pos = PAL_XY(x, y);
  2421. }
  2422. PAL_BattleDelay(1, 0, TRUE);
  2423. }
  2424. PAL_BattleUpdateFighters();
  2425. PAL_BattleDelay(1, 0, TRUE);
  2426. break;
  2427. case 0x009E:
  2428. //
  2429. // Enemy summons another monster
  2430. //
  2431. x = 0;
  2432. w = pScript->rgwOperand[0];
  2433. y = (((SHORT)(pScript->rgwOperand[1]) <= 0) ? 1 : (SHORT)pScript->rgwOperand[1]);
  2434. if (w == 0 || w == 0xFFFF)
  2435. {
  2436. w = g_Battle.rgEnemy[wEventObjectID].wObjectID;
  2437. }
  2438. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2439. {
  2440. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2441. {
  2442. x++;
  2443. }
  2444. }
  2445. if (x < y || g_Battle.iHidingTime > 0 ||
  2446. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] != 0 ||
  2447. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] != 0 ||
  2448. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] != 0)
  2449. {
  2450. if (pScript->rgwOperand[2] != 0)
  2451. {
  2452. wScriptEntry = pScript->rgwOperand[2] - 1;
  2453. }
  2454. }
  2455. else
  2456. {
  2457. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2458. {
  2459. if (g_Battle.rgEnemy[i].wObjectID == 0)
  2460. {
  2461. memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY));
  2462. g_Battle.rgEnemy[i].wObjectID = w;
  2463. g_Battle.rgEnemy[i].e = gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[w].enemy.wEnemyID];
  2464. g_Battle.rgEnemy[i].state = kFighterWait;
  2465. g_Battle.rgEnemy[i].wScriptOnTurnStart = gpGlobals->g.rgObject[w].enemy.wScriptOnTurnStart;
  2466. g_Battle.rgEnemy[i].wScriptOnBattleEnd = gpGlobals->g.rgObject[w].enemy.wScriptOnBattleEnd;
  2467. g_Battle.rgEnemy[i].wScriptOnReady = gpGlobals->g.rgObject[w].enemy.wScriptOnReady;
  2468. g_Battle.rgEnemy[i].flTimeMeter = 50;
  2469. g_Battle.rgEnemy[i].iColorShift = 8;
  2470. y--;
  2471. if (y <= 0)
  2472. {
  2473. break;
  2474. }
  2475. }
  2476. }
  2477. PAL_BattleDelay(2, 0, TRUE);
  2478. VIDEO_BackupScreen(g_Battle.lpSceneBuf);
  2479. PAL_LoadBattleSprites();
  2480. PAL_BattleMakeScene();
  2481. AUDIO_PlaySound(212);
  2482. PAL_BattleFadeScene();
  2483. for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
  2484. {
  2485. g_Battle.rgEnemy[i].iColorShift = 0;
  2486. }
  2487. VIDEO_BackupScreen(g_Battle.lpSceneBuf);
  2488. PAL_BattleMakeScene();
  2489. PAL_BattleFadeScene();
  2490. }
  2491. break;
  2492. case 0x009F:
  2493. //
  2494. // Enemy transforms into something else
  2495. //
  2496. if (g_Battle.iHidingTime <= 0 &&
  2497. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusSleep] == 0 &&
  2498. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusParalyzed] == 0 &&
  2499. g_Battle.rgEnemy[wEventObjectID].rgwStatus[kStatusConfused] == 0)
  2500. {
  2501. w = g_Battle.rgEnemy[wEventObjectID].e.wHealth;
  2502. g_Battle.rgEnemy[wEventObjectID].wObjectID = pScript->rgwOperand[0];
  2503. g_Battle.rgEnemy[wEventObjectID].e =
  2504. gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[pScript->rgwOperand[0]].enemy.wEnemyID];
  2505. g_Battle.rgEnemy[wEventObjectID].e.wHealth = w;
  2506. g_Battle.rgEnemy[wEventObjectID].wCurrentFrame = 0;
  2507. for (i = 0; i < 6; i++)
  2508. {
  2509. g_Battle.rgEnemy[wEventObjectID].iColorShift = i;
  2510. PAL_BattleDelay(1, 0, FALSE);
  2511. }
  2512. g_Battle.rgEnemy[wEventObjectID].iColorShift = 0;
  2513. AUDIO_PlaySound(47);
  2514. VIDEO_BackupScreen(g_Battle.lpSceneBuf);
  2515. PAL_LoadBattleSprites();
  2516. PAL_BattleMakeScene();
  2517. PAL_BattleFadeScene();
  2518. }
  2519. break;
  2520. case 0x00A0:
  2521. //
  2522. // Quit game
  2523. //
  2524. if (gConfig.fIsWIN95)
  2525. PAL_EndingScreen();
  2526. PAL_AdditionalCredits();
  2527. PAL_Shutdown(0);
  2528. break;
  2529. case 0x00A1:
  2530. //
  2531. // Set the positions of all party members to the same as the first one
  2532. //
  2533. for (i = 0; i < MAX_PLAYABLE_PLAYER_ROLES; i++)
  2534. {
  2535. gpGlobals->rgTrail[i].wDirection = gpGlobals->wPartyDirection;
  2536. gpGlobals->rgTrail[i].x = gpGlobals->rgParty[0].x + PAL_X(gpGlobals->viewport);
  2537. gpGlobals->rgTrail[i].y = gpGlobals->rgParty[0].y + PAL_Y(gpGlobals->viewport);
  2538. }
  2539. for (i = 1; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  2540. {
  2541. gpGlobals->rgParty[i].x = gpGlobals->rgParty[0].x;
  2542. gpGlobals->rgParty[i].y = gpGlobals->rgParty[0].y - 1;
  2543. }
  2544. PAL_UpdatePartyGestures(FALSE);
  2545. break;
  2546. case 0x00A2:
  2547. //
  2548. // Jump to one of the following instructions randomly
  2549. //
  2550. wScriptEntry += RandomLong(0, pScript->rgwOperand[0] - 1);
  2551. break;
  2552. case 0x00A3:
  2553. //
  2554. // Play CD music. Use the RIX music for fallback.
  2555. //
  2556. if (!AUDIO_PlayCDTrack(pScript->rgwOperand[0]))
  2557. {
  2558. AUDIO_PlayMusic(pScript->rgwOperand[1], TRUE, 0);
  2559. }
  2560. break;
  2561. case 0x00A4:
  2562. //
  2563. // Scroll FBP to the screen
  2564. //
  2565. if (!gConfig.fIsWIN95)
  2566. {
  2567. if (pScript->rgwOperand[0] == 68)
  2568. {
  2569. //
  2570. // HACKHACK: to make the ending picture show correctly
  2571. //
  2572. PAL_ShowFBP(69, 0);
  2573. PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], TRUE);
  2574. }
  2575. else
  2576. {
  2577. PAL_ScrollFBP(pScript->rgwOperand[0], pScript->rgwOperand[2], pScript->rgwOperand[1]);
  2578. }
  2579. }
  2580. break;
  2581. case 0x00A5:
  2582. //
  2583. // Show FBP picture with sprite effects
  2584. //
  2585. if (!gConfig.fIsWIN95)
  2586. {
  2587. if (pScript->rgwOperand[1] != 0xFFFF)
  2588. {
  2589. PAL_EndingSetEffectSprite(pScript->rgwOperand[1]);
  2590. }
  2591. PAL_ShowFBP(pScript->rgwOperand[0], pScript->rgwOperand[2]);
  2592. }
  2593. break;
  2594. case 0x00A6:
  2595. //
  2596. // backup screen
  2597. //
  2598. VIDEO_BackupScreen(gpScreen);
  2599. break;
  2600. default:
  2601. TerminateOnError("SCRIPT: Invalid Instruction at %4x: (%4x - %4x, %4x, %4x)",
  2602. wScriptEntry, pScript->wOperation, pScript->rgwOperand[0],
  2603. pScript->rgwOperand[1], pScript->rgwOperand[2]);
  2604. break;
  2605. }
  2606. return wScriptEntry + 1;
  2607. }
  2608. WORD
  2609. PAL_RunTriggerScript(
  2610. WORD wScriptEntry,
  2611. WORD wEventObjectID
  2612. )
  2613. /*++
  2614. Purpose:
  2615. Runs a trigger script.
  2616. Parameters:
  2617. [IN] wScriptEntry - The script entry to execute.
  2618. [IN] wEventObjectID - The event object ID which invoked the script.
  2619. Return value:
  2620. The entry point of the script.
  2621. --*/
  2622. {
  2623. static WORD wLastEventObject = 0;
  2624. WORD wNextScriptEntry;
  2625. BOOL fEnded;
  2626. LPSCRIPTENTRY pScript;
  2627. LPEVENTOBJECT pEvtObj = NULL;
  2628. int i;
  2629. extern BOOL g_fUpdatedInBattle; // HACKHACK
  2630. wNextScriptEntry = wScriptEntry;
  2631. fEnded = FALSE;
  2632. g_fUpdatedInBattle = FALSE;
  2633. if (wEventObjectID == 0xFFFF)
  2634. {
  2635. wEventObjectID = wLastEventObject;
  2636. }
  2637. wLastEventObject = wEventObjectID;
  2638. if (wEventObjectID != 0)
  2639. {
  2640. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  2641. }
  2642. g_fScriptSuccess = TRUE;
  2643. //
  2644. // Set the default dialog speed.
  2645. //
  2646. PAL_DialogSetDelayTime(3);
  2647. while (wScriptEntry != 0 && !fEnded)
  2648. {
  2649. pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
  2650. UTIL_WriteLog(LOG_DEBUG, "[SCRIPT] %.4x: %.4x %.4x %.4x %.4x\n", wScriptEntry,
  2651. pScript->wOperation, pScript->rgwOperand[0], pScript->rgwOperand[1],
  2652. pScript->rgwOperand[2], pScript->rgwOperand[3]);
  2653. switch (pScript->wOperation)
  2654. {
  2655. case 0x0000:
  2656. //
  2657. // Stop running
  2658. //
  2659. fEnded = TRUE;
  2660. break;
  2661. case 0x0001:
  2662. //
  2663. // Stop running and replace the entry with the next line
  2664. //
  2665. fEnded = TRUE;
  2666. wNextScriptEntry = wScriptEntry + 1;
  2667. break;
  2668. case 0x0002:
  2669. //
  2670. // Stop running and replace the entry with the specified one
  2671. //
  2672. if (pScript->rgwOperand[1] == 0 ||
  2673. ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
  2674. {
  2675. fEnded = TRUE;
  2676. wNextScriptEntry = pScript->rgwOperand[0];
  2677. }
  2678. else
  2679. {
  2680. //
  2681. // failed
  2682. //
  2683. pEvtObj->nScriptIdleFrame = 0;
  2684. wScriptEntry++;
  2685. }
  2686. break;
  2687. case 0x0003:
  2688. //
  2689. // unconditional jump
  2690. //
  2691. if (pScript->rgwOperand[1] == 0 ||
  2692. ++(pEvtObj->nScriptIdleFrame) < pScript->rgwOperand[1])
  2693. {
  2694. wScriptEntry = pScript->rgwOperand[0];
  2695. }
  2696. else
  2697. {
  2698. //
  2699. // failed
  2700. //
  2701. pEvtObj->nScriptIdleFrame = 0;
  2702. wScriptEntry++;
  2703. }
  2704. break;
  2705. case 0x0004:
  2706. //
  2707. // Call script
  2708. //
  2709. PAL_RunTriggerScript(pScript->rgwOperand[0],
  2710. ((pScript->rgwOperand[1] == 0) ? wEventObjectID : pScript->rgwOperand[1]));
  2711. wScriptEntry++;
  2712. break;
  2713. case 0x0005:
  2714. //
  2715. // Redraw screen
  2716. //
  2717. PAL_ClearDialog(TRUE);
  2718. if (PAL_DialogIsPlayingRNG())
  2719. {
  2720. VIDEO_RestoreScreen(gpScreen);
  2721. }
  2722. else if (gpGlobals->fInBattle)
  2723. {
  2724. PAL_BattleMakeScene();
  2725. VIDEO_CopyEntireSurface(g_Battle.lpSceneBuf, gpScreen);
  2726. VIDEO_UpdateScreen(NULL);
  2727. }
  2728. else
  2729. {
  2730. if (pScript->rgwOperand[2])
  2731. {
  2732. PAL_UpdatePartyGestures(FALSE);
  2733. }
  2734. PAL_MakeScene();
  2735. VIDEO_UpdateScreen(NULL);
  2736. UTIL_Delay((pScript->rgwOperand[1] == 0) ? 60 : (pScript->rgwOperand[1] * 60));
  2737. }
  2738. wScriptEntry++;
  2739. break;
  2740. case 0x0006:
  2741. //
  2742. // Jump to the specified address by the specified rate
  2743. //
  2744. if (RandomLong(1, 100) >= pScript->rgwOperand[0])
  2745. {
  2746. wScriptEntry = pScript->rgwOperand[1];
  2747. continue;
  2748. }
  2749. else
  2750. {
  2751. wScriptEntry++;
  2752. }
  2753. break;
  2754. case 0x0007:
  2755. //
  2756. // Start battle
  2757. //
  2758. i = PAL_StartBattle(pScript->rgwOperand[0], !pScript->rgwOperand[2]);
  2759. if (i == kBattleResultLost && pScript->rgwOperand[1] != 0)
  2760. {
  2761. wScriptEntry = pScript->rgwOperand[1];
  2762. }
  2763. else if (i == kBattleResultFleed && pScript->rgwOperand[2] != 0)
  2764. {
  2765. wScriptEntry = pScript->rgwOperand[2];
  2766. }
  2767. else
  2768. {
  2769. wScriptEntry++;
  2770. }
  2771. gpGlobals->fAutoBattle = FALSE;
  2772. break;
  2773. case 0x0008:
  2774. //
  2775. // Replace the entry with the next instruction
  2776. //
  2777. wScriptEntry++;
  2778. wNextScriptEntry = wScriptEntry;
  2779. break;
  2780. case 0x0009:
  2781. //
  2782. // wait for the specified number of frames
  2783. //
  2784. {
  2785. DWORD time;
  2786. PAL_ClearDialog(TRUE);
  2787. time = SDL_GetTicks() + FRAME_TIME;
  2788. for (i = 0; i < (pScript->rgwOperand[0] ? pScript->rgwOperand[0] : 1); i++)
  2789. {
  2790. PAL_DelayUntil(time);
  2791. time = SDL_GetTicks() + FRAME_TIME;
  2792. if (pScript->rgwOperand[2])
  2793. {
  2794. PAL_UpdatePartyGestures(FALSE);
  2795. }
  2796. PAL_GameUpdate(pScript->rgwOperand[1] ? TRUE : FALSE);
  2797. PAL_MakeScene();
  2798. VIDEO_UpdateScreen(NULL);
  2799. }
  2800. }
  2801. wScriptEntry++;
  2802. break;
  2803. case 0x000A:
  2804. //
  2805. // Goto the specified address if player selected no
  2806. //
  2807. PAL_ClearDialog(FALSE);
  2808. if (!PAL_ConfirmMenu())
  2809. {
  2810. wScriptEntry = pScript->rgwOperand[0];
  2811. }
  2812. else
  2813. {
  2814. wScriptEntry++;
  2815. }
  2816. break;
  2817. case 0x003B:
  2818. //
  2819. // Show dialog in the middle part of the screen
  2820. //
  2821. PAL_ClearDialog(TRUE);
  2822. PAL_StartDialog(kDialogCenter, (BYTE)pScript->rgwOperand[0], 0,
  2823. pScript->rgwOperand[2] ? TRUE : FALSE);
  2824. wScriptEntry++;
  2825. break;
  2826. case 0x003C:
  2827. //
  2828. // Show dialog in the upper part of the screen
  2829. //
  2830. PAL_ClearDialog(TRUE);
  2831. PAL_StartDialog(kDialogUpper, (BYTE)pScript->rgwOperand[1],
  2832. pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
  2833. wScriptEntry++;
  2834. break;
  2835. case 0x003D:
  2836. //
  2837. // Show dialog in the lower part of the screen
  2838. //
  2839. PAL_ClearDialog(TRUE);
  2840. PAL_StartDialog(kDialogLower, (BYTE)pScript->rgwOperand[1],
  2841. pScript->rgwOperand[0], pScript->rgwOperand[2] ? TRUE : FALSE);
  2842. wScriptEntry++;
  2843. break;
  2844. case 0x003E:
  2845. //
  2846. // Show text in a window at the center of the screen
  2847. //
  2848. PAL_ClearDialog(TRUE);
  2849. PAL_StartDialog(kDialogCenterWindow, (BYTE)pScript->rgwOperand[0], 0, FALSE);
  2850. wScriptEntry++;
  2851. break;
  2852. case 0x008E:
  2853. //
  2854. // Restore the screen
  2855. //
  2856. PAL_ClearDialog(TRUE);
  2857. VIDEO_RestoreScreen(gpScreen);
  2858. VIDEO_UpdateScreen(NULL);
  2859. wScriptEntry++;
  2860. break;
  2861. case 0xFFFF:
  2862. //
  2863. // Print dialog text
  2864. //
  2865. if (gConfig.pszMsgFile)
  2866. {
  2867. int idx = 0, iMsg;
  2868. while ((iMsg = PAL_GetMsgNum(pScript->rgwOperand[0], idx++)) >= 0)
  2869. {
  2870. if (iMsg == 0)
  2871. {
  2872. //
  2873. // Restore the screen
  2874. //
  2875. PAL_ClearDialog(TRUE);
  2876. VIDEO_RestoreScreen(gpScreen);
  2877. VIDEO_UpdateScreen(NULL);
  2878. }
  2879. else
  2880. PAL_ShowDialogText(PAL_GetMsg(iMsg));
  2881. }
  2882. while (gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0xFFFF
  2883. || gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0x008E)
  2884. {
  2885. //
  2886. // Skip all following continuous 0xFFFF & 0x008E instructions
  2887. //
  2888. wScriptEntry++;
  2889. }
  2890. }
  2891. else
  2892. {
  2893. PAL_ShowDialogText(PAL_GetMsg(pScript->rgwOperand[0]));
  2894. wScriptEntry++;
  2895. }
  2896. break;
  2897. default:
  2898. PAL_ClearDialog(TRUE);
  2899. wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
  2900. break;
  2901. }
  2902. }
  2903. PAL_EndDialog();
  2904. g_iCurEquipPart = -1;
  2905. return wNextScriptEntry;
  2906. }
  2907. WORD
  2908. PAL_RunAutoScript(
  2909. WORD wScriptEntry,
  2910. WORD wEventObjectID
  2911. )
  2912. /*++
  2913. Purpose:
  2914. Runs the autoscript of the specified event object.
  2915. Parameters:
  2916. [IN] wScriptEntry - The script entry to execute.
  2917. [IN] wEventObjectID - The event object ID which invoked the script.
  2918. Return value:
  2919. The address of the next script instruction to execute.
  2920. --*/
  2921. {
  2922. LPSCRIPTENTRY pScript;
  2923. LPEVENTOBJECT pEvtObj;
  2924. begin:
  2925. pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
  2926. pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
  2927. //
  2928. // For autoscript, we should interpret one instruction per frame (except
  2929. // jumping) and save the address of next instruction.
  2930. //
  2931. switch (pScript->wOperation)
  2932. {
  2933. case 0x0000:
  2934. //
  2935. // Stop running
  2936. //
  2937. break;
  2938. case 0x0001:
  2939. //
  2940. // Stop running and replace the entry with the next line
  2941. //
  2942. wScriptEntry++;
  2943. break;
  2944. case 0x0002:
  2945. //
  2946. // Stop running and replace the entry with the specified one
  2947. //
  2948. if (pScript->rgwOperand[1] == 0 ||
  2949. ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
  2950. {
  2951. wScriptEntry = pScript->rgwOperand[0];
  2952. }
  2953. else
  2954. {
  2955. pEvtObj->wScriptIdleFrameCountAuto = 0;
  2956. wScriptEntry++;
  2957. }
  2958. break;
  2959. case 0x0003:
  2960. //
  2961. // unconditional jump
  2962. //
  2963. if (pScript->rgwOperand[1] == 0 ||
  2964. ++(pEvtObj->wScriptIdleFrameCountAuto) < pScript->rgwOperand[1])
  2965. {
  2966. wScriptEntry = pScript->rgwOperand[0];
  2967. goto begin;
  2968. }
  2969. else
  2970. {
  2971. pEvtObj->wScriptIdleFrameCountAuto = 0;
  2972. wScriptEntry++;
  2973. }
  2974. break;
  2975. case 0x0004:
  2976. //
  2977. // Call subroutine
  2978. //
  2979. PAL_RunTriggerScript(pScript->rgwOperand[0],
  2980. pScript->rgwOperand[1] ? pScript->rgwOperand[1] : wEventObjectID);
  2981. wScriptEntry++;
  2982. break;
  2983. case 0x0006:
  2984. //
  2985. // jump to the specified address by the specified rate
  2986. //
  2987. if (RandomLong(1, 100) >= pScript->rgwOperand[0])
  2988. {
  2989. if (pScript->rgwOperand[1] != 0)
  2990. {
  2991. wScriptEntry = pScript->rgwOperand[1];
  2992. goto begin;
  2993. }
  2994. }
  2995. else
  2996. {
  2997. wScriptEntry++;
  2998. }
  2999. break;
  3000. case 0x0009:
  3001. //
  3002. // Wait for a certain number of frames
  3003. //
  3004. if (++(pEvtObj->wScriptIdleFrameCountAuto) >= pScript->rgwOperand[0])
  3005. {
  3006. //
  3007. // waiting ended; go further
  3008. //
  3009. pEvtObj->wScriptIdleFrameCountAuto = 0;
  3010. wScriptEntry++;
  3011. }
  3012. break;
  3013. case 0xFFFF:
  3014. if (gConfig.fIsWIN95)
  3015. {
  3016. int XBase = (wEventObjectID & PAL_ITEM_DESC_BOTTOM) ? 75 : 102;
  3017. int YBase = (wEventObjectID & PAL_ITEM_DESC_BOTTOM) ? 150 - gConfig.ScreenLayout.ExtraItemDescLines * 16 : 3;
  3018. int iDescLine = (wEventObjectID & ~PAL_ITEM_DESC_BOTTOM);
  3019. if (gConfig.pszMsgFile)
  3020. {
  3021. int idx = 0, iMsg;
  3022. while ((iMsg = PAL_GetMsgNum(pScript->rgwOperand[0], idx++)) >= 0)
  3023. {
  3024. if (iMsg > 0)
  3025. {
  3026. PAL_DrawText(PAL_GetMsg(iMsg), PAL_XY(XBase, iDescLine * 16 + YBase), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
  3027. iDescLine++;
  3028. }
  3029. }
  3030. while (gpGlobals->g.lprgScriptEntry[wScriptEntry].wOperation == 0xFFFF)
  3031. {
  3032. //
  3033. // Skip all following continuous 0xFFFF instructions
  3034. //
  3035. wScriptEntry++;
  3036. }
  3037. }
  3038. else
  3039. {
  3040. PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(XBase, iDescLine * 16 + YBase), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
  3041. wScriptEntry++;
  3042. }
  3043. }
  3044. else
  3045. {
  3046. wScriptEntry++;
  3047. }
  3048. break;
  3049. case 0x00A7:
  3050. wScriptEntry++;
  3051. break;
  3052. default:
  3053. //
  3054. // Other operations
  3055. //
  3056. wScriptEntry = PAL_InterpretInstruction(wScriptEntry, wEventObjectID);
  3057. break;
  3058. }
  3059. return wScriptEntry;
  3060. }