script.c 84 KB

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