script.c 85 KB

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