script.c 90 KB

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