script.c 92 KB

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