script.c 90 KB

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