script.c 92 KB

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