script.c 91 KB

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