script.c 91 KB

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