script.c 85 KB

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