script.c 91 KB

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