script.c 90 KB

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