script.c 91 KB

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