script.c 91 KB

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