script.c 90 KB

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