script.c 90 KB

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