script.c 91 KB

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