script.c 91 KB

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