123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926 |
- /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
- //
- // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
- // All rights reserved.
- //
- // This file is part of SDLPAL.
- //
- // SDLPAL is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- // Modified by Lou Yihua <louyihua@21cn.com> with Unicode support, 2015
- //
- #include "main.h"
- #include <math.h>
- //#define INVINCIBLE 1
- static BOOL
- PAL_IsPlayerDying(
- WORD wPlayerRole
- )
- /*++
- Purpose:
- Check if the player is dying.
- Parameters:
- [IN] wPlayerRole - the player role ID.
- Return value:
- TRUE if the player is dying, FALSE if not.
- --*/
- {
- return gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] < gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole] / 5;
- }
- INT
- PAL_BattleSelectAutoTarget(
- VOID
- )
- /*++
- Purpose:
- Pick an enemy target automatically.
- Parameters:
- None.
- Return value:
- The index of enemy. -1 if failed.
- --*/
- {
- int i;
- i = (int)g_Battle.UI.wPrevEnemyTarget;
- if (i >= 0 && i <= g_Battle.wMaxEnemyIndex &&
- g_Battle.rgEnemy[i].wObjectID != 0 &&
- g_Battle.rgEnemy[i].e.wHealth > 0)
- {
- return i;
- }
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID != 0 &&
- g_Battle.rgEnemy[i].e.wHealth > 0)
- {
- return i;
- }
- }
- return -1;
- }
- static SHORT
- PAL_CalcBaseDamage(
- WORD wAttackStrength,
- WORD wDefense
- )
- /*++
- Purpose:
- Calculate the base damage value of attacking.
- Parameters:
- [IN] wAttackStrength - attack strength of attacker.
- [IN] wDefense - defense value of inflictor.
- Return value:
- The base damage value of the attacking.
- --*/
- {
- SHORT sDamage;
- //
- // Formula courtesy of palxex and shenyanduxing
- //
- if (wAttackStrength > wDefense)
- {
- sDamage = (SHORT)(wAttackStrength * 2 - wDefense * 1.6 + 0.5);
- }
- else if (wAttackStrength > wDefense * 0.6)
- {
- sDamage = (SHORT)(wAttackStrength - wDefense * 0.6 + 0.5);
- }
- else
- {
- sDamage = 0;
- }
- return sDamage;
- }
- static SHORT
- PAL_CalcMagicDamage(
- WORD wMagicStrength,
- WORD wDefense,
- const WORD rgwElementalResistance[NUM_MAGIC_ELEMENTAL],
- WORD wPoisonResistance,
- WORD wMagicID
- )
- /*++
- Purpose:
- Calculate the damage of magic.
- Parameters:
- [IN] wMagicStrength - magic strength of attacker.
- [IN] wDefense - defense value of inflictor.
- [IN] rgwElementalResistance - inflictor's resistance to the elemental magics.
- [IN] wPoisonResistance - inflictor's resistance to poison.
- [IN] wMagicID - object ID of the magic.
- Return value:
- The damage value of the magic attack.
- --*/
- {
- SHORT sDamage;
- WORD wElem;
- wMagicID = gpGlobals->g.rgObject[wMagicID].magic.wMagicNumber;
- //
- // Formula courtesy of palxex and shenyanduxing
- //
- wMagicStrength *= RandomFloat(10, 11);
- wMagicStrength /= 10;
- sDamage = PAL_CalcBaseDamage(wMagicStrength, wDefense);
- sDamage /= 4;
- sDamage += gpGlobals->g.lprgMagic[wMagicID].wBaseDamage;
- if (gpGlobals->g.lprgMagic[wMagicID].wElemental != 0)
- {
- wElem = gpGlobals->g.lprgMagic[wMagicID].wElemental;
- if (wElem > NUM_MAGIC_ELEMENTAL)
- {
- sDamage *= 10 - wPoisonResistance;
- }
- else if (wElem == 0)
- {
- sDamage *= 5;
- }
- else
- {
- sDamage *= 10 - rgwElementalResistance[wElem - 1];
- }
- sDamage /= 5;
- if (wElem <= NUM_MAGIC_ELEMENTAL)
- {
- sDamage *= 10 + gpGlobals->g.lprgBattleField[gpGlobals->wNumBattleField].rgsMagicEffect[wElem - 1];
- sDamage /= 10;
- }
- }
- return sDamage;
- }
- SHORT
- PAL_CalcPhysicalAttackDamage(
- WORD wAttackStrength,
- WORD wDefense,
- WORD wAttackResistance
- )
- /*++
- Purpose:
- Calculate the damage value of physical attacking.
- Parameters:
- [IN] wAttackStrength - attack strength of attacker.
- [IN] wDefense - defense value of inflictor.
- [IN] wAttackResistance - inflictor's resistance to physical attack.
- Return value:
- The damage value of the physical attacking.
- --*/
- {
- SHORT sDamage;
- sDamage = PAL_CalcBaseDamage(wAttackStrength, wDefense);
- if (wAttackResistance != 0)
- {
- sDamage /= wAttackResistance;
- }
- return sDamage;
- }
- static SHORT
- PAL_GetEnemyDexterity(
- WORD wEnemyIndex
- )
- /*++
- Purpose:
- Get the dexterity value of the enemy.
- Parameters:
- [IN] wEnemyIndex - the index of the enemy.
- Return value:
- The dexterity value of the enemy.
- --*/
- {
- SHORT s;
- assert(g_Battle.rgEnemy[wEnemyIndex].wObjectID != 0);
- s = (g_Battle.rgEnemy[wEnemyIndex].e.wLevel + 6) * 3;
- s += (SHORT)g_Battle.rgEnemy[wEnemyIndex].e.wDexterity;
- if (!gConfig.fIsClassic)
- {
- if (s < 20)
- {
- s = 20;
- }
- if (g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusHaste] != 0)
- {
- s *= 6;
- s /= 5;
- }
- else if (g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusSlow] != 0)
- {
- s *= 2;
- s /= 3;
- }
- }
- return s;
- }
- static WORD
- PAL_GetPlayerActualDexterity(
- WORD wPlayerRole
- )
- /*++
- Purpose:
- Get player's actual dexterity value in battle.
- Parameters:
- [IN] wPlayerRole - the player role ID.
- Return value:
- The player's actual dexterity value.
- --*/
- {
- WORD wDexterity = PAL_GetPlayerDexterity(wPlayerRole);
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusHaste] != 0)
- {
- if (gConfig.fIsClassic)
- {
- wDexterity *= 3;
- }
- else
- {
- wDexterity *= 6;
- wDexterity /= 5;
- }
- }
- else if (!gConfig.fIsClassic && gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSlow] != 0)
- {
- wDexterity *= 2;
- wDexterity /= 3;
- }
- if (PAL_IsPlayerDying(wPlayerRole))
- {
- //
- // player who is low of HP should be slower
- //
- if (gConfig.fIsClassic)
- {
- wDexterity /= 2;
- }
- else
- {
- wDexterity *= 4;
- wDexterity /= 5;
- }
- }
- if (gConfig.fIsClassic && wDexterity > 999)
- {
- wDexterity = 999;
- }
- return wDexterity;
- }
- VOID
- PAL_UpdateTimeChargingUnit(
- VOID
- )
- /*++
- Purpose:
- Update the base time unit of time-charging.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- g_Battle.flTimeChargingUnit = (FLOAT)(pow(PAL_GetPlayerDexterity(0) + 5, 0.3));
- g_Battle.flTimeChargingUnit /= PAL_GetPlayerDexterity(0);
- if (gpGlobals->bBattleSpeed > 1)
- {
- g_Battle.flTimeChargingUnit /= 1 + (gpGlobals->bBattleSpeed - 1) * 0.5;
- }
- else
- {
- g_Battle.flTimeChargingUnit /= 1.2f;
- }
- }
- FLOAT
- PAL_GetTimeChargingSpeed(
- WORD wDexterity
- )
- /*++
- Purpose:
- Calculate the time charging speed.
- Parameters:
- [IN] wDexterity - the dexterity value of player or enemy.
- Return value:
- The time-charging speed of the player or enemy.
- --*/
- {
- if ((g_Battle.UI.state == kBattleUISelectMove &&
- g_Battle.UI.MenuState != kBattleMenuMain) ||
- !SDL_TICKS_PASSED(SDL_GetTicks(), g_Battle.UI.dwMsgShowTime))
- {
- //
- // Pause the time when there are submenus or text messages
- //
- return 0;
- }
- //
- // The battle should be faster when using Auto-Battle
- //
- if (gpGlobals->fAutoBattle)
- {
- wDexterity *= 3;
- }
- return g_Battle.flTimeChargingUnit * wDexterity;
- }
- VOID
- PAL_BattleDelay(
- WORD wDuration,
- WORD wObjectID,
- BOOL fUpdateGesture
- )
- /*++
- Purpose:
- Delay a while during battle.
- Parameters:
- [IN] wDuration - Number of frames of the delay.
- [IN] wObjectID - The object ID to be displayed during the delay.
- [IN] fUpdateGesture - TRUE if update the gesture for enemies, FALSE if not.
- Return value:
- None.
- --*/
- {
- int i, j;
- DWORD dwTime = SDL_GetTicks() + BATTLE_FRAME_TIME;
- for (i = 0; i < wDuration; i++)
- {
- if (fUpdateGesture)
- {
- //
- // Update the gesture of enemies.
- //
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- if (g_Battle.rgEnemy[j].wObjectID == 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusSleep] != 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusParalyzed] != 0)
- {
- continue;
- }
- if (--g_Battle.rgEnemy[j].e.wIdleAnimSpeed == 0)
- {
- g_Battle.rgEnemy[j].wCurrentFrame++;
- g_Battle.rgEnemy[j].e.wIdleAnimSpeed =
- gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[g_Battle.rgEnemy[j].wObjectID].enemy.wEnemyID].wIdleAnimSpeed;
- }
- if (g_Battle.rgEnemy[j].wCurrentFrame >= g_Battle.rgEnemy[j].e.wIdleFrames)
- {
- g_Battle.rgEnemy[j].wCurrentFrame = 0;
- }
- }
- }
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() + BATTLE_FRAME_TIME;
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- PAL_BattleUIUpdate();
- if (wObjectID != 0)
- {
- if (wObjectID == BATTLE_LABEL_ESCAPEFAIL) // HACKHACK
- {
- PAL_DrawText(PAL_GetWord(wObjectID), PAL_XY(130, 75), 15, TRUE, FALSE, FALSE);
- }
- else if ((SHORT)wObjectID < 0)
- {
- PAL_DrawText(PAL_GetWord(-((SHORT)wObjectID)), PAL_XY(170, 45), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
- }
- else
- {
- PAL_DrawText(PAL_GetWord(wObjectID), PAL_XY(210, 50), 15, TRUE, FALSE, FALSE);
- }
- }
- VIDEO_UpdateScreen(NULL);
- }
- }
- static VOID
- PAL_BattleBackupStat(
- VOID
- )
- /*++
- Purpose:
- Backup HP and MP values of all players and enemies.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- int i;
- WORD wPlayerRole;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- g_Battle.rgEnemy[i].wPrevHP = g_Battle.rgEnemy[i].e.wHealth;
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- g_Battle.rgPlayer[i].wPrevHP =
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole];
- g_Battle.rgPlayer[i].wPrevMP =
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole];
- }
- }
- static BOOL
- PAL_BattleDisplayStatChange(
- VOID
- )
- /*++
- Purpose:
- Display the HP and MP changes of all players and enemies.
- Parameters:
- None.
- Return value:
- TRUE if there are any number displayed, FALSE if not.
- --*/
- {
- int i, x, y;
- SHORT sDamage;
- WORD wPlayerRole;
- BOOL f = FALSE;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- if (g_Battle.rgEnemy[i].wPrevHP != g_Battle.rgEnemy[i].e.wHealth)
- {
- //
- // Show the number of damage
- //
- sDamage = g_Battle.rgEnemy[i].e.wHealth - g_Battle.rgEnemy[i].wPrevHP;
- x = PAL_X(g_Battle.rgEnemy[i].pos) - 9;
- y = PAL_Y(g_Battle.rgEnemy[i].pos) - 115;
- if (y < 10)
- {
- y = 10;
- }
- if (sDamage < 0)
- {
- PAL_BattleUIShowNum((WORD)(-sDamage), PAL_XY(x, y), kNumColorBlue);
- }
- else
- {
- PAL_BattleUIShowNum((WORD)(sDamage), PAL_XY(x, y), kNumColorYellow);
- }
- f = TRUE;
- }
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- if (g_Battle.rgPlayer[i].wPrevHP != gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole])
- {
- sDamage =
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] - g_Battle.rgPlayer[i].wPrevHP;
- x = PAL_X(g_Battle.rgPlayer[i].pos) - 9;
- y = PAL_Y(g_Battle.rgPlayer[i].pos) - 75;
- if (y < 10)
- {
- y = 10;
- }
- if (sDamage < 0)
- {
- PAL_BattleUIShowNum((WORD)(-sDamage), PAL_XY(x, y), kNumColorBlue);
- }
- else
- {
- PAL_BattleUIShowNum((WORD)(sDamage), PAL_XY(x, y), kNumColorYellow);
- }
- f = TRUE;
- }
- if (g_Battle.rgPlayer[i].wPrevMP != gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole])
- {
- sDamage =
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] - g_Battle.rgPlayer[i].wPrevMP;
- x = PAL_X(g_Battle.rgPlayer[i].pos) - 9;
- y = PAL_Y(g_Battle.rgPlayer[i].pos) - 67;
- if (y < 10)
- {
- y = 10;
- }
- //
- // Only show MP increasing
- //
- if (sDamage > 0)
- {
- PAL_BattleUIShowNum((WORD)(sDamage), PAL_XY(x, y), kNumColorCyan);
- }
- f = TRUE;
- }
- }
- return f;
- }
- static VOID
- PAL_BattlePostActionCheck(
- BOOL fCheckPlayers
- )
- /*++
- Purpose:
- Essential checks after an action is executed.
- Parameters:
- [IN] fCheckPlayers - TRUE if check for players, FALSE if not.
- Return value:
- None.
- --*/
- {
- int i, j;
- BOOL fFade = FALSE;
- BOOL fEnemyRemaining = FALSE;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- if ((SHORT)(g_Battle.rgEnemy[i].e.wHealth) <= 0)
- {
- //
- // This enemy is KO'ed
- //
- g_Battle.iExpGained += g_Battle.rgEnemy[i].e.wExp;
- g_Battle.iCashGained += g_Battle.rgEnemy[i].e.wCash;
- SOUND_Play(g_Battle.rgEnemy[i].e.wDeathSound);
- g_Battle.rgEnemy[i].wObjectID = 0;
- fFade = TRUE;
- continue;
- }
- fEnemyRemaining = TRUE;
- }
- if (!fEnemyRemaining)
- {
- g_Battle.fEnemyCleared = TRUE;
- g_Battle.UI.state = kBattleUIWait;
- }
- if (fCheckPlayers && !gpGlobals->fAutoBattle)
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- WORD w = gpGlobals->rgParty[i].wPlayerRole, wName;
- if (gpGlobals->g.PlayerRoles.rgwHP[w] < g_Battle.rgPlayer[i].wPrevHP &&
- gpGlobals->g.PlayerRoles.rgwHP[w] == 0)
- {
- w = gpGlobals->g.PlayerRoles.rgwCoveredBy[w];
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- if (gpGlobals->rgParty[j].wPlayerRole == w)
- {
- break;
- }
- }
- if (gpGlobals->g.PlayerRoles.rgwHP[w] > 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusSleep] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusParalyzed] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusConfused] == 0 &&
- j <= gpGlobals->wMaxPartyMemberIndex)
- {
- wName = gpGlobals->g.PlayerRoles.rgwName[w];
- if (gpGlobals->g.rgObject[wName].player.wScriptOnFriendDeath != 0)
- {
- PAL_BattleDelay(10, 0, TRUE);
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- VIDEO_UpdateScreen(NULL);
- g_Battle.BattleResult = kBattleResultPause;
- gpGlobals->g.rgObject[wName].player.wScriptOnFriendDeath =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wName].player.wScriptOnFriendDeath, w);
- g_Battle.BattleResult = kBattleResultOnGoing;
- PAL_ClearKeyState();
- goto end;
- }
- }
- }
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- WORD w = gpGlobals->rgParty[i].wPlayerRole, wName;
- if (gpGlobals->rgPlayerStatus[w][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusConfused] != 0)
- {
- continue;
- }
- if (gpGlobals->g.PlayerRoles.rgwHP[w] < g_Battle.rgPlayer[i].wPrevHP)
- {
- if (gpGlobals->g.PlayerRoles.rgwHP[w] > 0 && PAL_IsPlayerDying(w) &&
- g_Battle.rgPlayer[i].wPrevHP >= gpGlobals->g.PlayerRoles.rgwMaxHP[w] / 5)
- {
- WORD wCover = gpGlobals->g.PlayerRoles.rgwCoveredBy[w];
- if (gpGlobals->rgPlayerStatus[wCover][kStatusSleep] != 0 ||
- gpGlobals->rgPlayerStatus[wCover][kStatusParalyzed] != 0 ||
- gpGlobals->rgPlayerStatus[wCover][kStatusConfused] != 0)
- {
- continue;
- }
- wName = gpGlobals->g.PlayerRoles.rgwName[w];
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwDyingSound[w]);
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- if (gpGlobals->rgParty[j].wPlayerRole == wCover)
- {
- break;
- }
- }
- if (j > gpGlobals->wMaxPartyMemberIndex || gpGlobals->g.PlayerRoles.rgwHP[wCover] == 0)
- {
- continue;
- }
- if (gpGlobals->g.rgObject[wName].player.wScriptOnDying != 0)
- {
- PAL_BattleDelay(10, 0, TRUE);
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- VIDEO_UpdateScreen(NULL);
- g_Battle.BattleResult = kBattleResultPause;
- gpGlobals->g.rgObject[wName].player.wScriptOnDying =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wName].player.wScriptOnDying, w);
- g_Battle.BattleResult = kBattleResultOnGoing;
- PAL_ClearKeyState();
- }
- goto end;
- }
- }
- }
- }
- end:
- if (fFade)
- {
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- //
- // Fade out the summoned god
- //
- if (g_Battle.lpSummonSprite != NULL)
- {
- PAL_BattleUpdateFighters();
- PAL_BattleDelay(1, 0, FALSE);
- free(g_Battle.lpSummonSprite);
- g_Battle.lpSummonSprite = NULL;
- g_Battle.sBackgroundColorShift = 0;
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- }
- VOID
- PAL_BattleUpdateFighters(
- VOID
- )
- /*++
- Purpose:
- Update players' and enemies' gestures and locations in battle.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- int i;
- WORD wPlayerRole;
- //
- // Update the gesture for all players
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- g_Battle.rgPlayer[i].pos = g_Battle.rgPlayer[i].posOriginal;
- g_Battle.rgPlayer[i].iColorShift = 0;
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0)
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] == 0)
- {
- g_Battle.rgPlayer[i].wCurrentFrame = 2; // dead
- }
- else
- {
- g_Battle.rgPlayer[i].wCurrentFrame = 0; // puppet
- }
- }
- else
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] != 0 ||
- PAL_IsPlayerDying(wPlayerRole))
- {
- g_Battle.rgPlayer[i].wCurrentFrame = 1;
- }
- else if (!gConfig.fIsClassic && g_Battle.rgPlayer[i].state == kFighterAct &&
- g_Battle.rgPlayer[i].action.ActionType == kBattleActionMagic &&
- !g_Battle.fEnemyCleared)
- {
- //
- // Player is using a magic
- //
- g_Battle.rgPlayer[i].wCurrentFrame = 5;
- }
- else if (g_Battle.rgPlayer[i].fDefending && !g_Battle.fEnemyCleared)
- {
- g_Battle.rgPlayer[i].wCurrentFrame = 3;
- }
- else
- {
- g_Battle.rgPlayer[i].wCurrentFrame = 0;
- }
- }
- }
- //
- // Update the gesture for all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- g_Battle.rgEnemy[i].pos = g_Battle.rgEnemy[i].posOriginal;
- g_Battle.rgEnemy[i].iColorShift = 0;
- if (g_Battle.rgEnemy[i].rgwStatus[kStatusSleep] > 0 ||
- g_Battle.rgEnemy[i].rgwStatus[kStatusParalyzed] > 0)
- {
- g_Battle.rgEnemy[i].wCurrentFrame = 0;
- continue;
- }
- if (--g_Battle.rgEnemy[i].e.wIdleAnimSpeed == 0)
- {
- g_Battle.rgEnemy[i].wCurrentFrame++;
- g_Battle.rgEnemy[i].e.wIdleAnimSpeed =
- gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[g_Battle.rgEnemy[i].wObjectID].enemy.wEnemyID].wIdleAnimSpeed;
- }
- if (g_Battle.rgEnemy[i].wCurrentFrame >= g_Battle.rgEnemy[i].e.wIdleFrames)
- {
- g_Battle.rgEnemy[i].wCurrentFrame = 0;
- }
- }
- }
- VOID
- PAL_BattlePlayerCheckReady(
- VOID
- )
- /*++
- Purpose:
- Check if there are player who is ready.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- float flMax = 0;
- int iMax = 0, i;
- //
- // Start the UI for the fastest and ready player
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (g_Battle.rgPlayer[i].state == kFighterCom ||
- (g_Battle.rgPlayer[i].state == kFighterAct && g_Battle.rgPlayer[i].action.ActionType == kBattleActionCoopMagic))
- {
- flMax = 0;
- break;
- }
- else if (g_Battle.rgPlayer[i].state == kFighterWait)
- {
- if (g_Battle.rgPlayer[i].flTimeMeter > flMax)
- {
- iMax = i;
- flMax = g_Battle.rgPlayer[i].flTimeMeter;
- }
- }
- }
- if (flMax >= 100.0f)
- {
- g_Battle.rgPlayer[iMax].state = kFighterCom;
- g_Battle.rgPlayer[iMax].fDefending = FALSE;
- }
- }
- VOID
- PAL_BattleStartFrame(
- VOID
- )
- /*++
- Purpose:
- Called once per video frame in battle.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- int i, j;
- WORD wPlayerRole;
- WORD wDexterity;
- BOOL fOnlyPuppet = TRUE;
- if (!g_Battle.fEnemyCleared)
- {
- PAL_BattleUpdateFighters();
- }
- //
- // Update the scene
- //
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- //
- // Check if the battle is over
- //
- if (g_Battle.fEnemyCleared)
- {
- //
- // All enemies are cleared. Won the battle.
- //
- g_Battle.BattleResult = kBattleResultWon;
- SOUND_Play(-1);
- return;
- }
- else
- {
- BOOL fEnded = TRUE;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] != 0)
- {
- fOnlyPuppet = FALSE;
- fEnded = FALSE;
- break;
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] != 0)
- {
- fEnded = FALSE;
- }
- }
- if (fEnded)
- {
- //
- // All players are dead. Lost the battle.
- //
- g_Battle.BattleResult = kBattleResultLost;
- return;
- }
- }
- if (!gConfig.fIsClassic)
- {
- FLOAT flMax;
- BOOL fMoved = FALSE;
- SHORT sMax, sMaxIndex;
- //
- // Check for hiding status
- //
- if (g_Battle.iHidingTime > 0)
- {
- if (PAL_GetTimeChargingSpeed(9999) > 0)
- {
- g_Battle.iHidingTime--;
- }
- if (g_Battle.iHidingTime == 0)
- {
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- }
- //
- // Run the logic for all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- if (g_Battle.rgEnemy[i].fTurnStart)
- {
- g_Battle.rgEnemy[i].wScriptOnTurnStart =
- PAL_RunTriggerScript(g_Battle.rgEnemy[i].wScriptOnTurnStart, i);
- g_Battle.rgEnemy[i].fTurnStart = FALSE;
- fMoved = TRUE;
- }
- }
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- switch (g_Battle.rgEnemy[i].state)
- {
- case kFighterWait:
- flMax = PAL_GetTimeChargingSpeed(PAL_GetEnemyDexterity(i));
- flMax /= (gpGlobals->fAutoBattle ? 2 : 1);
- if (flMax != 0)
- {
- g_Battle.rgEnemy[i].flTimeMeter += flMax;
- if (g_Battle.rgEnemy[i].flTimeMeter > 100 && flMax > 0)
- {
- if (g_Battle.iHidingTime == 0)
- {
- g_Battle.rgEnemy[i].state = kFighterCom;
- }
- else
- {
- g_Battle.rgEnemy[i].flTimeMeter = 0;
- }
- }
- }
- break;
- case kFighterCom:
- g_Battle.rgEnemy[i].wScriptOnReady =
- PAL_RunTriggerScript(g_Battle.rgEnemy[i].wScriptOnReady, i);
- g_Battle.rgEnemy[i].state = kFighterAct;
- fMoved = TRUE;
- break;
- case kFighterAct:
- if (!fMoved && (PAL_GetTimeChargingSpeed(9999) > 0 || g_Battle.rgEnemy[i].fDualMove) && !fOnlyPuppet)
- {
- fMoved = TRUE;
- g_Battle.fEnemyMoving = TRUE;
- g_Battle.rgEnemy[i].fDualMove =
- (!g_Battle.rgEnemy[i].fFirstMoveDone &&
- (g_Battle.rgEnemy[i].e.wDualMove >= 2 ||
- (g_Battle.rgEnemy[i].e.wDualMove != 0 && RandomLong(0, 1))));
- PAL_BattleEnemyPerformAction(i);
- g_Battle.rgEnemy[i].flTimeMeter = 0;
- g_Battle.rgEnemy[i].state = kFighterWait;
- g_Battle.fEnemyMoving = FALSE;
- if (g_Battle.rgEnemy[i].fDualMove)
- {
- g_Battle.rgEnemy[i].flTimeMeter = 100;
- g_Battle.rgEnemy[i].state = kFighterCom;
- g_Battle.rgEnemy[i].fFirstMoveDone = TRUE;
- }
- else
- {
- g_Battle.rgEnemy[i].fFirstMoveDone = FALSE;
- g_Battle.rgEnemy[i].fTurnStart = TRUE;
- }
- }
- break;
- }
- }
- //
- // Update the battle UI
- //
- PAL_BattleUIUpdate();
- //
- // Run the logic for all players
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- //
- // Skip dead players
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] == 0)
- {
- g_Battle.rgPlayer[i].state = kFighterWait;
- g_Battle.rgPlayer[i].flTimeMeter = 0;
- g_Battle.rgPlayer[i].flTimeSpeedModifier = 1.0f;
- g_Battle.rgPlayer[i].sTurnOrder = -1;
- continue;
- }
- switch (g_Battle.rgPlayer[i].state)
- {
- case kFighterWait:
- wDexterity = PAL_GetPlayerActualDexterity(wPlayerRole);
- g_Battle.rgPlayer[i].flTimeMeter +=
- PAL_GetTimeChargingSpeed(wDexterity) * g_Battle.rgPlayer[i].flTimeSpeedModifier;
- break;
- case kFighterCom:
- break;
- case kFighterAct:
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] > 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionPass;
- g_Battle.rgPlayer[i].action.flRemainingTime = 0;
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] > 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionAttackMate;
- g_Battle.rgPlayer[i].action.flRemainingTime = 0;
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSilence] > 0 &&
- g_Battle.rgPlayer[i].action.ActionType == kBattleActionMagic)
- {
- g_Battle.rgPlayer[i].action.flRemainingTime = 0;
- }
- wDexterity = PAL_GetPlayerActualDexterity(wPlayerRole);
- g_Battle.rgPlayer[i].action.flRemainingTime -= PAL_GetTimeChargingSpeed(wDexterity);
- if (g_Battle.rgPlayer[i].action.flRemainingTime <= 0 &&
- g_Battle.rgPlayer[i].sTurnOrder == -1)
- {
- sMax = -1;
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- if (g_Battle.rgPlayer[j].sTurnOrder > sMax)
- {
- sMax = g_Battle.rgPlayer[j].sTurnOrder;
- }
- }
- g_Battle.rgPlayer[i].sTurnOrder = sMax + 1;
- }
- break;
- }
- }
- //
- // Preform action for player
- //
- if (!fMoved)
- {
- sMax = 9999;
- sMaxIndex = -1;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- //
- // Skip dead players
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] == 0)
- {
- continue;
- }
- if (g_Battle.rgPlayer[i].state == kFighterAct &&
- g_Battle.rgPlayer[i].sTurnOrder != -1 &&
- g_Battle.rgPlayer[i].sTurnOrder < sMax)
- {
- sMax = g_Battle.rgPlayer[i].sTurnOrder;
- sMaxIndex = i;
- }
- }
- if (sMaxIndex != -1)
- {
- //
- // Perform the action for this player.
- //
- PAL_BattlePlayerPerformAction(sMaxIndex);
- g_Battle.rgPlayer[sMaxIndex].flTimeMeter = 0;
- g_Battle.rgPlayer[sMaxIndex].flTimeSpeedModifier = 1.0f;
- g_Battle.rgPlayer[sMaxIndex].sTurnOrder = -1;
- }
- }
- }
- else
- {
- if (g_Battle.Phase == kBattlePhaseSelectAction)
- {
- if (g_Battle.UI.state == kBattleUIWait)
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- //
- // Don't select action for this player if player is KO'ed,
- // sleeped, confused or paralyzed
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzed])
- {
- continue;
- }
- //
- // Start the menu for the first player whose action is not
- // yet selected
- //
- if (g_Battle.rgPlayer[i].state == kFighterWait)
- {
- g_Battle.wMovingPlayerIndex = i;
- g_Battle.rgPlayer[i].state = kFighterCom;
- PAL_BattleUIPlayerReady(i);
- break;
- }
- else if (g_Battle.rgPlayer[i].action.ActionType == kBattleActionCoopMagic)
- {
- //
- // Skip other players if someone selected coopmagic
- //
- i = gpGlobals->wMaxPartyMemberIndex + 1;
- break;
- }
- }
- if (i > gpGlobals->wMaxPartyMemberIndex)
- {
- //
- // actions for all players are decided. fill in the action queue.
- //
- g_Battle.fRepeat = FALSE;
- g_Battle.fForce = FALSE;
- g_Battle.fFlee = FALSE;
- g_Battle.iCurAction = 0;
- for (i = 0; i < MAX_ACTIONQUEUE_ITEMS; i++)
- {
- g_Battle.ActionQueue[i].wIndex = 0xFFFF;
- g_Battle.ActionQueue[i].wDexterity = 0xFFFF;
- }
- j = 0;
- //
- // Put all enemies into action queue
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- g_Battle.ActionQueue[j].fIsEnemy = TRUE;
- g_Battle.ActionQueue[j].wIndex = i;
- g_Battle.ActionQueue[j].wDexterity = PAL_GetEnemyDexterity(i);
- g_Battle.ActionQueue[j].wDexterity *= RandomFloat(0.9f, 1.1f);
- j++;
- if (g_Battle.rgEnemy[i].e.wDualMove * 50 + RandomLong(0, 100) > 100)
- {
- g_Battle.ActionQueue[j].fIsEnemy = TRUE;
- g_Battle.ActionQueue[j].wIndex = i;
- g_Battle.ActionQueue[j].wDexterity = PAL_GetEnemyDexterity(i);
- g_Battle.ActionQueue[j].wDexterity *= RandomFloat(0.9f, 1.1f);
- j++;
- }
- }
- //
- // Put all players into action queue
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- g_Battle.ActionQueue[j].fIsEnemy = FALSE;
- g_Battle.ActionQueue[j].wIndex = i;
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzed] > 0)
- {
- //
- // players who are unable to move should attack physically if recovered
- // in the same turn
- //
- g_Battle.ActionQueue[j].wDexterity = 0;
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionAttack;
- g_Battle.rgPlayer[i].state = kFighterAct;
- }
- else
- {
- wDexterity = PAL_GetPlayerActualDexterity(wPlayerRole);
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] > 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionAttack;
- g_Battle.rgPlayer[i].state = kFighterAct;
- }
- switch (g_Battle.rgPlayer[i].action.ActionType)
- {
- case kBattleActionCoopMagic:
- wDexterity *= 10;
- break;
- case kBattleActionDefend:
- wDexterity *= 5;
- break;
- case kBattleActionMagic:
- if ((gpGlobals->g.rgObject[g_Battle.rgPlayer[i].action.wActionID].magic.wFlags & kMagicFlagUsableToEnemy) == 0)
- {
- wDexterity *= 3;
- }
- break;
- case kBattleActionFlee:
- wDexterity /= 2;
- break;
- case kBattleActionUseItem:
- wDexterity *= 3;
- break;
- default:
- break;
- }
- if (PAL_IsPlayerDying(wPlayerRole))
- {
- wDexterity /= 2;
- }
- wDexterity *= RandomFloat(0.9f, 1.1f);
- g_Battle.ActionQueue[j].wDexterity = wDexterity;
- }
- j++;
- }
- //
- // Sort the action queue by dexterity value
- //
- for (i = 0; i < MAX_ACTIONQUEUE_ITEMS; i++)
- {
- for (j = i; j < MAX_ACTIONQUEUE_ITEMS; j++)
- {
- if ((SHORT)g_Battle.ActionQueue[i].wDexterity < (SHORT)g_Battle.ActionQueue[j].wDexterity)
- {
- ACTIONQUEUE t = g_Battle.ActionQueue[i];
- g_Battle.ActionQueue[i] = g_Battle.ActionQueue[j];
- g_Battle.ActionQueue[j] = t;
- }
- }
- }
- //
- // Perform the actions
- //
- g_Battle.Phase = kBattlePhasePerformAction;
- }
- }
- }
- else
- {
- //
- // Are all actions finished?
- //
- if (g_Battle.iCurAction >= MAX_ACTIONQUEUE_ITEMS ||
- g_Battle.ActionQueue[g_Battle.iCurAction].wDexterity == 0xFFFF)
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- g_Battle.rgPlayer[i].fDefending = FALSE;
- }
- //
- // Run poison scripts
- //
- PAL_BattleBackupStat();
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (gpGlobals->rgPoisonStatus[j][i].wPoisonID != 0)
- {
- gpGlobals->rgPoisonStatus[j][i].wPoisonScript =
- PAL_RunTriggerScript(gpGlobals->rgPoisonStatus[j][i].wPoisonScript, wPlayerRole);
- }
- }
- //
- // Update statuses
- //
- for (j = 0; j < kStatusAll; j++)
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][j] > 0)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][j]--;
- }
- }
- }
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- for (j = 0; j < MAX_POISONS; j++)
- {
- if (g_Battle.rgEnemy[i].rgPoisons[j].wPoisonID != 0)
- {
- g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript =
- PAL_RunTriggerScript(g_Battle.rgEnemy[i].rgPoisons[j].wPoisonScript, (WORD)i);
- }
- }
- //
- // Update statuses
- //
- for (j = 0; j < kStatusAll; j++)
- {
- if (g_Battle.rgEnemy[i].rgwStatus[j] > 0)
- {
- g_Battle.rgEnemy[i].rgwStatus[j]--;
- }
- }
- }
- PAL_BattlePostActionCheck(FALSE);
- if (PAL_BattleDisplayStatChange())
- {
- PAL_BattleDelay(8, 0, TRUE);
- }
- if (g_Battle.iHidingTime > 0)
- {
- if (--g_Battle.iHidingTime == 0)
- {
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- }
- if (g_Battle.iHidingTime == 0)
- {
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- g_Battle.rgEnemy[i].wScriptOnTurnStart =
- PAL_RunTriggerScript(g_Battle.rgEnemy[i].wScriptOnTurnStart, i);
- }
- }
- //
- // Clear all item-using records
- //
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- gpGlobals->rgInventory[i].nAmountInUse = 0;
- }
- //
- // Proceed to next turn...
- //
- g_Battle.Phase = kBattlePhaseSelectAction;
- }
- else
- {
- i = g_Battle.ActionQueue[g_Battle.iCurAction].wIndex;
- if (g_Battle.ActionQueue[g_Battle.iCurAction].fIsEnemy)
- {
- if (g_Battle.iHidingTime == 0 && !fOnlyPuppet &&
- g_Battle.rgEnemy[i].wObjectID != 0)
- {
- g_Battle.rgEnemy[i].wScriptOnReady =
- PAL_RunTriggerScript(g_Battle.rgEnemy[i].wScriptOnReady, i);
- g_Battle.fEnemyMoving = TRUE;
- PAL_BattleEnemyPerformAction(i);
- g_Battle.fEnemyMoving = FALSE;
- }
- }
- else if (g_Battle.rgPlayer[i].state == kFighterAct)
- {
- wPlayerRole = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0)
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusPuppet] == 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionPass;
- }
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzed] > 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionPass;
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] > 0)
- {
- g_Battle.rgPlayer[i].action.ActionType = kBattleActionAttackMate;
- }
- //
- // Perform the action for this player.
- //
- g_Battle.wMovingPlayerIndex = i;
- PAL_BattlePlayerPerformAction(i);
- }
- g_Battle.iCurAction++;
- }
- }
- //
- // The R and F keys and Fleeing should affect all players
- //
- if (g_Battle.UI.MenuState == kBattleMenuMain &&
- g_Battle.UI.state == kBattleUISelectMove)
- {
- if (g_InputState.dwKeyPress & kKeyRepeat)
- {
- g_Battle.fRepeat = TRUE;
- }
- else if (g_InputState.dwKeyPress & kKeyForce)
- {
- g_Battle.fForce = TRUE;
- }
- }
- if (g_Battle.fRepeat)
- {
- g_InputState.dwKeyPress = kKeyRepeat;
- }
- else if (g_Battle.fForce)
- {
- g_InputState.dwKeyPress = kKeyForce;
- }
- else if (g_Battle.fFlee)
- {
- g_InputState.dwKeyPress = kKeyFlee;
- }
- //
- // Update the battle UI
- //
- PAL_BattleUIUpdate();
- }
- }
- VOID
- PAL_BattleCommitAction(
- BOOL fRepeat
- )
- /*++
- Purpose:
- Commit the action which the player decided.
- Parameters:
- [IN] fRepeat - TRUE if repeat the last action.
- Return value:
- None.
- --*/
- {
- WORD w;
- if (!fRepeat)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType =
- g_Battle.UI.wActionType;
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.sTarget =
- (SHORT)g_Battle.UI.wSelectedIndex;
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID =
- g_Battle.UI.wObjectID;
- }
- else if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType == kBattleActionPass)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType = kBattleActionAttack;
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.sTarget = -1;
- }
- //
- // Check if the action is valid
- //
- switch (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType)
- {
- case kBattleActionMagic:
- w = g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID;
- w = gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[w].magic.wMagicNumber].wCostMP;
- if (gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[g_Battle.UI.wCurPlayerIndex].wPlayerRole] < w)
- {
- w = g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID;
- w = gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[w].magic.wMagicNumber].wType;
- if (w == kMagicTypeApplyToPlayer || w == kMagicTypeApplyToParty ||
- w == kMagicTypeTrance)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType = kBattleActionDefend;
- }
- else
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType = kBattleActionAttack;
- if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.sTarget == -1)
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.sTarget = 0;
- }
- }
- }
- break;
- case kBattleActionUseItem:
- if (gConfig.fIsClassic && (gpGlobals->g.rgObject[g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID].item.wFlags & kItemFlagConsuming) == 0)
- {
- break;
- }
- case kBattleActionThrowItem:
- if (gConfig.fIsClassic)
- {
- for (w = 0; w < MAX_INVENTORY; w++)
- {
- if (gpGlobals->rgInventory[w].wItem == g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID)
- {
- gpGlobals->rgInventory[w].nAmountInUse++;
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- if (!gConfig.fIsClassic)
- {
- //
- // Calculate the waiting time for the action
- //
- if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.ActionType == kBattleActionMagic)
- {
- LPMAGIC p;
- WORD wCostMP;
- //
- // The base casting time of magic is set to the MP costed
- //
- w = g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.wActionID;
- p = &(gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[w].magic.wMagicNumber]);
- wCostMP = p->wCostMP;
- if (wCostMP == 1)
- {
- if (p->wType == kMagicTypeSummon)
- {
- //
- // The Wine God is an ultimate move which should take long
- //
- wCostMP = 175;
- }
- }
- else if (p->wType == kMagicTypeApplyToPlayer || p->wType == kMagicTypeApplyToParty ||
- p->wType == kMagicTypeTrance)
- {
- //
- // Healing magics should take shorter
- //
- wCostMP /= 3;
- }
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.flRemainingTime = wCostMP + 5;
- }
- else
- {
- //
- // Other actions take no time
- //
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.flRemainingTime = 0;
- }
- }
- else if (g_Battle.UI.wActionType == kBattleActionFlee)
- {
- g_Battle.fFlee = TRUE;
- }
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].state = kFighterAct;
- g_Battle.UI.state = kBattleUIWait;
- if (!gConfig.fIsClassic)
- {
- if (g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].action.flRemainingTime <= 0)
- {
- SHORT sMax = -1;
- for (w = 0; w <= gpGlobals->wMaxPartyMemberIndex; w++)
- {
- if (g_Battle.rgPlayer[w].sTurnOrder > sMax)
- {
- sMax = g_Battle.rgPlayer[w].sTurnOrder;
- }
- }
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].sTurnOrder = sMax + 1;
- }
- else
- {
- g_Battle.rgPlayer[g_Battle.UI.wCurPlayerIndex].sTurnOrder = -1;
- }
- }
- }
- static VOID
- PAL_BattleShowPlayerAttackAnim(
- WORD wPlayerIndex,
- BOOL fCritical
- )
- /*++
- Purpose:
- Show the physical attack effect for player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] fCritical - TRUE if this is a critical hit.
- Return value:
- None.
- --*/
- {
- WORD wPlayerRole = gpGlobals->rgParty[wPlayerIndex].wPlayerRole;
- SHORT sTarget = g_Battle.rgPlayer[wPlayerIndex].action.sTarget;
- int index, i, j;
- int enemy_x = 0, enemy_y = 0, enemy_h = 0, x, y, dist = 0;
- DWORD dwTime;
- if (sTarget != -1)
- {
- enemy_x = PAL_X(g_Battle.rgEnemy[sTarget].pos);
- enemy_y = PAL_Y(g_Battle.rgEnemy[sTarget].pos);
- enemy_h = PAL_RLEGetHeight(PAL_SpriteGetFrame(g_Battle.rgEnemy[sTarget].lpSprite, g_Battle.rgEnemy[sTarget].wCurrentFrame));
- if (sTarget >= 3)
- {
- dist = (sTarget - wPlayerIndex) * 8;
- }
- }
- else
- {
- enemy_x = 150;
- enemy_y = 100;
- }
- index = gpGlobals->g.rgwBattleEffectIndex[PAL_GetPlayerBattleSprite(wPlayerRole)][1];
- index *= 3;
- //
- // Play the attack voice
- //
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] > 0)
- {
- if (!fCritical)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwAttackSound[wPlayerRole]);
- }
- else
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwCriticalSound[wPlayerRole]);
- }
- }
- //
- // Show the animation
- //
- x = enemy_x - dist + 64;
- y = enemy_y + dist + 20;
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 8;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(2, 0, TRUE);
- x -= 10;
- y -= 2;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(1, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 9;
- x -= 16;
- y -= 4;
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwWeaponSound[wPlayerRole]);
- x = enemy_x;
- y = enemy_y - enemy_h / 3 + 10;
- dwTime = SDL_GetTicks() + BATTLE_FRAME_TIME;
- for (i = 0; i < 3; i++)
- {
- LPCBITMAPRLE b = PAL_SpriteGetFrame(g_Battle.lpEffectSprite, index++);
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() + BATTLE_FRAME_TIME;
- //
- // Update the gesture of enemies.
- //
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- if (g_Battle.rgEnemy[j].wObjectID == 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusSleep] > 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusParalyzed] > 0)
- {
- continue;
- }
- if (--g_Battle.rgEnemy[j].e.wIdleAnimSpeed == 0)
- {
- g_Battle.rgEnemy[j].wCurrentFrame++;
- g_Battle.rgEnemy[j].e.wIdleAnimSpeed =
- gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[g_Battle.rgEnemy[j].wObjectID].enemy.wEnemyID].wIdleAnimSpeed;
- }
- if (g_Battle.rgEnemy[j].wCurrentFrame >= g_Battle.rgEnemy[j].e.wIdleFrames)
- {
- g_Battle.rgEnemy[j].wCurrentFrame = 0;
- }
- }
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- x -= 16;
- y += 16;
- PAL_BattleUIUpdate();
- if (i == 0)
- {
- if (sTarget == -1)
- {
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- g_Battle.rgEnemy[j].iColorShift = 6;
- }
- }
- else
- {
- g_Battle.rgEnemy[sTarget].iColorShift = 6;
- }
- PAL_BattleDisplayStatChange();
- PAL_BattleBackupStat();
- }
- VIDEO_UpdateScreen(NULL);
- if (i == 1)
- {
- g_Battle.rgPlayer[wPlayerIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos) + 2,
- PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos) + 1);
- }
- }
- dist = 8;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- g_Battle.rgEnemy[i].iColorShift = 0;
- }
- if (sTarget == -1)
- {
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- x = PAL_X(g_Battle.rgEnemy[j].pos);
- y = PAL_Y(g_Battle.rgEnemy[j].pos);
- x -= dist;
- y -= dist / 2;
- g_Battle.rgEnemy[j].pos = PAL_XY(x, y);
- }
- PAL_BattleDelay(1, 0, TRUE);
- dist /= -2;
- }
- }
- else
- {
- x = PAL_X(g_Battle.rgEnemy[sTarget].pos);
- y = PAL_Y(g_Battle.rgEnemy[sTarget].pos);
- for (i = 0; i < 3; i++)
- {
- x -= dist;
- dist /= -2;
- y += dist;
- g_Battle.rgEnemy[sTarget].pos = PAL_XY(x, y);
- PAL_BattleDelay(1, 0, TRUE);
- }
- }
- }
- static VOID
- PAL_BattleShowPlayerUseItemAnim(
- WORD wPlayerIndex,
- WORD wObjectID,
- SHORT sTarget
- )
- /*++
- Purpose:
- Show the "use item" effect for player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] wObjectID - the object ID of the item to be used.
- [IN] sTarget - the target player of the action.
- Return value:
- None.
- --*/
- {
- int i, j;
- PAL_BattleDelay(4, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos) - 15,
- PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos) - 7);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 5;
- SOUND_Play(28);
- for (i = 0; i <= 6; i++)
- {
- if (sTarget == -1)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i;
- }
- }
- else
- {
- g_Battle.rgPlayer[sTarget].iColorShift = i;
- }
- PAL_BattleDelay(1, wObjectID, TRUE);
- }
- for (i = 5; i >= 0; i--)
- {
- if (sTarget == -1)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i;
- }
- }
- else
- {
- g_Battle.rgPlayer[sTarget].iColorShift = i;
- }
- PAL_BattleDelay(1, wObjectID, TRUE);
- }
- }
- VOID
- PAL_BattleShowPlayerPreMagicAnim(
- WORD wPlayerIndex,
- BOOL fSummon
- )
- /*++
- Purpose:
- Show the effect for player before using a magic.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] fSummon - TRUE if player is using a summon magic.
- Return value:
- None.
- --*/
- {
- int i, j;
- DWORD dwTime = SDL_GetTicks();
- WORD wPlayerRole = gpGlobals->rgParty[wPlayerIndex].wPlayerRole;
- for (i = 0; i < 4; i++)
- {
- g_Battle.rgPlayer[wPlayerIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos) - (4 - i),
- PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos) - (4 - i) / 2);
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleDelay(2, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 5;
- if (!gConfig.fIsWIN95)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwMagicSound[wPlayerRole]);
- }
- if (!fSummon)
- {
- int x, y, index;
- x = PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos);
- y = PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos);
- index = gpGlobals->g.rgwBattleEffectIndex[PAL_GetPlayerBattleSprite(wPlayerRole)][0];
- index *= 10;
- index += 15;
- if (gConfig.fIsWIN95)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwMagicSound[wPlayerRole]);
- }
- for (i = 0; i < 10; i++)
- {
- LPCBITMAPRLE b = PAL_SpriteGetFrame(g_Battle.lpEffectSprite, index++);
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() + BATTLE_FRAME_TIME;
- //
- // Update the gesture of enemies.
- //
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- if (g_Battle.rgEnemy[j].wObjectID == 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusSleep] != 0 ||
- g_Battle.rgEnemy[j].rgwStatus[kStatusParalyzed] != 0)
- {
- continue;
- }
- if (--g_Battle.rgEnemy[j].e.wIdleAnimSpeed == 0)
- {
- g_Battle.rgEnemy[j].wCurrentFrame++;
- g_Battle.rgEnemy[j].e.wIdleAnimSpeed =
- gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[g_Battle.rgEnemy[j].wObjectID].enemy.wEnemyID].wIdleAnimSpeed;
- }
- if (g_Battle.rgEnemy[j].wCurrentFrame >= g_Battle.rgEnemy[j].e.wIdleFrames)
- {
- g_Battle.rgEnemy[j].wCurrentFrame = 0;
- }
- }
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- PAL_BattleUIUpdate();
- VIDEO_UpdateScreen(NULL);
- }
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- static VOID
- PAL_BattleShowPlayerDefMagicAnim(
- WORD wPlayerIndex,
- WORD wObjectID,
- SHORT sTarget
- )
- /*++
- Purpose:
- Show the defensive magic effect for player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] wObjectID - the object ID of the magic to be used.
- [IN] sTarget - the target player of the action.
- Return value:
- None.
- --*/
- {
- LPSPRITE lpSpriteEffect;
- int l, iMagicNum, iEffectNum, n, i, j, x, y;
- DWORD dwTime = SDL_GetTicks();
- iMagicNum = gpGlobals->g.rgObject[wObjectID].magic.wMagicNumber;
- iEffectNum = gpGlobals->g.lprgMagic[iMagicNum].wEffect;
- l = PAL_MKFGetDecompressedSize(iEffectNum, gpGlobals->f.fpFIRE);
- if (l <= 0)
- {
- return;
- }
- lpSpriteEffect = (LPSPRITE)UTIL_malloc(l);
- PAL_MKFDecompressChunk((LPBYTE)lpSpriteEffect, l, iEffectNum, gpGlobals->f.fpFIRE);
- n = PAL_SpriteGetNumFrames(lpSpriteEffect);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 6;
- PAL_BattleDelay(1, 0, TRUE);
- for (i = 0; i < n; i++)
- {
- LPCBITMAPRLE b = PAL_SpriteGetFrame(lpSpriteEffect, i);
- if (i == gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay)
- {
- SOUND_Play(gpGlobals->g.lprgMagic[iMagicNum].wSound);
- }
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() +
- ((SHORT)(gpGlobals->g.lprgMagic[iMagicNum].wSpeed) + 5) * 10;
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeApplyToParty)
- {
- assert(sTarget == -1);
- for (l = 0; l <= gpGlobals->wMaxPartyMemberIndex; l++)
- {
- x = PAL_X(g_Battle.rgPlayer[l].pos);
- y = PAL_Y(g_Battle.rgPlayer[l].pos);
- x += (SHORT) gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT) gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- else if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeApplyToPlayer)
- {
- assert(sTarget != -1);
- x = PAL_X(g_Battle.rgPlayer[sTarget].pos);
- y = PAL_Y(g_Battle.rgPlayer[sTarget].pos);
- x += (SHORT) gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT) gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- //
- // Repaint the previous player
- //
- if (sTarget > 0 && g_Battle.iHidingTime == 0)
- {
- if (gpGlobals->rgPlayerStatus[gpGlobals->rgParty[sTarget - 1].wPlayerRole][kStatusConfused] == 0)
- {
- LPCBITMAPRLE p = PAL_SpriteGetFrame(g_Battle.rgPlayer[sTarget - 1].lpSprite, g_Battle.rgPlayer[sTarget - 1].wCurrentFrame);
- x = PAL_X(g_Battle.rgPlayer[sTarget - 1].pos);
- y = PAL_Y(g_Battle.rgPlayer[sTarget - 1].pos);
- x -= PAL_RLEGetWidth(p) / 2;
- y -= PAL_RLEGetHeight(p);
- PAL_RLEBlitToSurface(p, gpScreen, PAL_XY(x, y));
- }
- }
- }
- else
- {
- assert(FALSE);
- }
- PAL_BattleUIUpdate();
- VIDEO_UpdateScreen(NULL);
- }
- free(lpSpriteEffect);
- for (i = 0; i < 6; i++)
- {
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeApplyToParty)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i;
- }
- }
- else
- {
- g_Battle.rgPlayer[sTarget].iColorShift = i;
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- for (i = 6; i >= 0; i--)
- {
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeApplyToParty)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i;
- }
- }
- else
- {
- g_Battle.rgPlayer[sTarget].iColorShift = i;
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- }
- static VOID
- PAL_BattleShowPlayerOffMagicAnim(
- WORD wPlayerIndex,
- WORD wObjectID,
- SHORT sTarget,
- BOOL fSummon
- )
- /*++
- Purpose:
- Show the offensive magic animation for player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] wObjectID - the object ID of the magic to be used.
- [IN] sTarget - the target enemy of the action.
- Return value:
- None.
- --*/
- {
- LPSPRITE lpSpriteEffect;
- int l, iMagicNum, iEffectNum, n, i, k, x, y, wave, blow;
- DWORD dwTime = SDL_GetTicks();
- iMagicNum = gpGlobals->g.rgObject[wObjectID].magic.wMagicNumber;
- iEffectNum = gpGlobals->g.lprgMagic[iMagicNum].wEffect;
- l = PAL_MKFGetDecompressedSize(iEffectNum, gpGlobals->f.fpFIRE);
- if (l <= 0)
- {
- return;
- }
- lpSpriteEffect = (LPSPRITE)UTIL_malloc(l);
- PAL_MKFDecompressChunk((LPBYTE)lpSpriteEffect, l, iEffectNum, gpGlobals->f.fpFIRE);
- n = PAL_SpriteGetNumFrames(lpSpriteEffect);
- if (gConfig.fIsWIN95 && wPlayerIndex != (WORD)-1)
- {
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 6;
- }
- PAL_BattleDelay(1, 0, TRUE);
- l = n - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- l *= (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wEffectTimes;
- l += n;
- l += gpGlobals->g.lprgMagic[iMagicNum].wShake;
- wave = gpGlobals->wScreenWave;
- gpGlobals->wScreenWave += gpGlobals->g.lprgMagic[iMagicNum].wWave;
- if (gConfig.fIsWIN95 && !fSummon && gpGlobals->g.lprgMagic[iMagicNum].wSound != 0)
- {
- SOUND_Play(gpGlobals->g.lprgMagic[iMagicNum].wSound);
- }
- for (i = 0; i < l; i++)
- {
- LPCBITMAPRLE b;
- if (!gConfig.fIsWIN95 && i == gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay && wPlayerIndex != (WORD)-1)
- {
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 6;
- }
- blow = ((g_Battle.iBlow > 0) ? RandomLong(0, g_Battle.iBlow) : RandomLong(g_Battle.iBlow, 0));
- for (k = 0; k <= g_Battle.wMaxEnemyIndex; k++)
- {
- if (g_Battle.rgEnemy[k].wObjectID == 0)
- {
- continue;
- }
- x = PAL_X(g_Battle.rgEnemy[k].pos) + blow;
- y = PAL_Y(g_Battle.rgEnemy[k].pos) + blow / 2;
- g_Battle.rgEnemy[k].pos = PAL_XY(x, y);
- }
- if (l - i > gpGlobals->g.lprgMagic[iMagicNum].wShake)
- {
- if (i < n)
- {
- k = i;
- }
- else
- {
- k = i - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- k %= n - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- k += gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- }
- b = PAL_SpriteGetFrame(lpSpriteEffect, k);
- if (!gConfig.fIsWIN95 && (i - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay) % n == 0)
- {
- SOUND_Play(gpGlobals->g.lprgMagic[iMagicNum].wSound);
- }
- }
- else
- {
- VIDEO_ShakeScreen(i, 3);
- b = PAL_SpriteGetFrame(lpSpriteEffect, (l - gpGlobals->g.lprgMagic[iMagicNum].wShake - 1) % n);
- }
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() +
- ((SHORT)(gpGlobals->g.lprgMagic[iMagicNum].wSpeed) + 5) * 10;
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeNormal)
- {
- assert(sTarget != -1);
- x = PAL_X(g_Battle.rgEnemy[sTarget].pos);
- y = PAL_Y(g_Battle.rgEnemy[sTarget].pos);
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- else if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackAll)
- {
- const int effectpos[3][2] = {{70, 140}, {100, 110}, {160, 100}};
- assert(sTarget == -1);
- for (k = 0; k < 3; k++)
- {
- x = effectpos[k][0];
- y = effectpos[k][1];
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- }
- else if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackWhole ||
- gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackField)
- {
- assert(sTarget == -1);
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackWhole)
- {
- x = 120;
- y = 100;
- }
- else
- {
- x = 160;
- y = 200;
- }
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- else
- {
- assert(FALSE);
- }
- PAL_BattleUIUpdate();
- VIDEO_UpdateScreen(NULL);
- }
- gpGlobals->wScreenWave = wave;
- VIDEO_ShakeScreen(0, 0);
- free(lpSpriteEffect);
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- g_Battle.rgEnemy[i].pos = g_Battle.rgEnemy[i].posOriginal;
- }
- }
- static VOID
- PAL_BattleShowEnemyMagicAnim(
- WORD wObjectID,
- SHORT sTarget
- )
- /*++
- Purpose:
- Show the offensive magic animation for enemy.
- Parameters:
- [IN] wObjectID - the object ID of the magic to be used.
- [IN] sTarget - the target player index of the action.
- Return value:
- None.
- --*/
- {
- LPSPRITE lpSpriteEffect;
- int l, iMagicNum, iEffectNum, n, i, k, x, y, wave, blow;
- DWORD dwTime = SDL_GetTicks();
- iMagicNum = gpGlobals->g.rgObject[wObjectID].magic.wMagicNumber;
- iEffectNum = gpGlobals->g.lprgMagic[iMagicNum].wEffect;
- l = PAL_MKFGetDecompressedSize(iEffectNum, gpGlobals->f.fpFIRE);
- if (l <= 0)
- {
- return;
- }
- lpSpriteEffect = (LPSPRITE)UTIL_malloc(l);
- PAL_MKFDecompressChunk((LPBYTE)lpSpriteEffect, l, iEffectNum, gpGlobals->f.fpFIRE);
- n = PAL_SpriteGetNumFrames(lpSpriteEffect);
- l = n - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- l *= (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wEffectTimes;
- l += n;
- l += gpGlobals->g.lprgMagic[iMagicNum].wShake;
- wave = gpGlobals->wScreenWave;
- gpGlobals->wScreenWave += gpGlobals->g.lprgMagic[iMagicNum].wWave;
- for (i = 0; i < l; i++)
- {
- LPCBITMAPRLE b;
- blow = ((g_Battle.iBlow > 0) ? RandomLong(0, g_Battle.iBlow) : RandomLong(g_Battle.iBlow, 0));
- for (k = 0; k <= gpGlobals->wMaxPartyMemberIndex; k++)
- {
- x = PAL_X(g_Battle.rgPlayer[k].pos) + blow;
- y = PAL_Y(g_Battle.rgPlayer[k].pos) + blow / 2;
- g_Battle.rgPlayer[k].pos = PAL_XY(x, y);
- }
- if (l - i > gpGlobals->g.lprgMagic[iMagicNum].wShake)
- {
- if (i < n)
- {
- k = i;
- }
- else
- {
- k = i - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- k %= n - gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- k += gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay;
- }
- b = PAL_SpriteGetFrame(lpSpriteEffect, k);
- if (i == gpGlobals->g.lprgMagic[iMagicNum].wSoundDelay)
- {
- SOUND_Play(gpGlobals->g.lprgMagic[iMagicNum].wSound);
- }
- }
- else
- {
- VIDEO_ShakeScreen(i, 3);
- b = PAL_SpriteGetFrame(lpSpriteEffect, (l - gpGlobals->g.lprgMagic[iMagicNum].wShake - 1) % n);
- }
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() +
- ((SHORT)(gpGlobals->g.lprgMagic[iMagicNum].wSpeed) + 5) * 10;
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeNormal)
- {
- assert(sTarget != -1);
- x = PAL_X(g_Battle.rgPlayer[sTarget].pos);
- y = PAL_Y(g_Battle.rgPlayer[sTarget].pos);
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- else if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackAll)
- {
- const int effectpos[3][2] = {{180, 180}, {234, 170}, {270, 146}};
- assert(sTarget == -1);
- for (k = 0; k < 3; k++)
- {
- x = effectpos[k][0];
- y = effectpos[k][1];
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- }
- else if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackWhole ||
- gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackField)
- {
- assert(sTarget == -1);
- if (gpGlobals->g.lprgMagic[iMagicNum].wType == kMagicTypeAttackWhole)
- {
- x = 240;
- y = 150;
- }
- else
- {
- x = 160;
- y = 200;
- }
- x += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wXOffset;
- y += (SHORT)gpGlobals->g.lprgMagic[iMagicNum].wYOffset;
- PAL_RLEBlitToSurface(b, gpScreen, PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- if (i == l - 1 && gpGlobals->wScreenWave < 9 &&
- gpGlobals->g.lprgMagic[iMagicNum].wKeepEffect == 0xFFFF)
- {
- PAL_RLEBlitToSurface(b, g_Battle.lpBackground,
- PAL_XY(x - PAL_RLEGetWidth(b) / 2, y - PAL_RLEGetHeight(b)));
- }
- }
- else
- {
- assert(FALSE);
- }
- PAL_BattleUIUpdate();
- VIDEO_UpdateScreen(NULL);
- }
- gpGlobals->wScreenWave = wave;
- VIDEO_ShakeScreen(0, 0);
- free(lpSpriteEffect);
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- g_Battle.rgPlayer[i].pos = g_Battle.rgPlayer[i].posOriginal;
- }
- }
- static VOID
- PAL_BattleShowPlayerSummonMagicAnim(
- WORD wPlayerIndex,
- WORD wObjectID
- )
- /*++
- Purpose:
- Show the summon magic animation for player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- [IN] wObjectID - the object ID of the magic to be used.
- Return value:
- None.
- --*/
- {
- int i, j;
- WORD wMagicNum = gpGlobals->g.rgObject[wObjectID].magic.wMagicNumber;
- WORD wEffectMagicID = 0;
- DWORD dwTime = SDL_GetTicks();
- for (wEffectMagicID = 0; wEffectMagicID < MAX_OBJECTS; wEffectMagicID++)
- {
- if (gpGlobals->g.rgObject[wEffectMagicID].magic.wMagicNumber ==
- gpGlobals->g.lprgMagic[wMagicNum].wEffect)
- {
- break;
- }
- }
- assert(wEffectMagicID < MAX_OBJECTS);
- //
- // Brighten the players
- //
- for (i = 1; i <= 10; i++)
- {
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].iColorShift = i;
- }
- PAL_BattleDelay(1, wObjectID, TRUE);
- }
- PAL_BattleBackupScene();
- if (gConfig.fIsWIN95)
- {
- SOUND_Play(gpGlobals->g.lprgMagic[wMagicNum].wSound);
- }
- //
- // Load the sprite of the summoned god
- //
- j = gpGlobals->g.lprgMagic[wMagicNum].wSummonEffect + 10;
- i = PAL_MKFGetDecompressedSize(j, gpGlobals->f.fpF);
- g_Battle.lpSummonSprite = UTIL_malloc(i);
- PAL_MKFDecompressChunk(g_Battle.lpSummonSprite, i, j, gpGlobals->f.fpF);
- g_Battle.iSummonFrame = 0;
- g_Battle.posSummon = PAL_XY(230 + (SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wXOffset),
- 155 + (SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wYOffset));
- g_Battle.sBackgroundColorShift = (SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wEffectTimes);
- //
- // Fade in the summoned god
- //
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- //
- // Show the animation of the summoned god
- // TODO: There is still something missing here compared to the original game.
- //
- while (g_Battle.iSummonFrame < PAL_SpriteGetNumFrames(g_Battle.lpSummonSprite) - 1)
- {
- //
- // Wait for the time of one frame. Accept input here.
- //
- PAL_DelayUntil(dwTime);
- //
- // Set the time of the next frame.
- //
- dwTime = SDL_GetTicks() +
- ((SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wSpeed) + 5) * 10;
- PAL_BattleMakeScene();
- SDL_BlitSurface(g_Battle.lpSceneBuf, NULL, gpScreen, NULL);
- PAL_BattleUIUpdate();
- VIDEO_UpdateScreen(NULL);
- g_Battle.iSummonFrame++;
- }
- //
- // Show the actual magic effect
- //
- PAL_BattleShowPlayerOffMagicAnim((WORD)-1, wEffectMagicID, -1, TRUE);
- }
- static VOID
- PAL_BattleShowPostMagicAnim(
- VOID
- )
- /*++
- Purpose:
- Show the post-magic animation.
- Parameters:
- None
- Return value:
- None.
- --*/
- {
- int i, j, x, y, dist = 8;
- PAL_POS rgEnemyPosBak[MAX_ENEMIES_IN_TEAM];
- for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++)
- {
- rgEnemyPosBak[i] = g_Battle.rgEnemy[i].pos;
- }
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j <= g_Battle.wMaxEnemyIndex; j++)
- {
- if (g_Battle.rgEnemy[j].e.wHealth == g_Battle.rgEnemy[j].wPrevHP)
- {
- continue;
- }
- x = PAL_X(g_Battle.rgEnemy[j].pos);
- y = PAL_Y(g_Battle.rgEnemy[j].pos);
- x -= dist;
- y -= dist / 2;
- g_Battle.rgEnemy[j].pos = PAL_XY(x, y);
- g_Battle.rgEnemy[j].iColorShift = ((i == 1) ? 6 : 0);
- }
- PAL_BattleDelay(1, 0, TRUE);
- dist /= -2;
- }
- for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++)
- {
- g_Battle.rgEnemy[i].pos = rgEnemyPosBak[i];
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- static VOID
- PAL_BattlePlayerValidateAction(
- WORD wPlayerIndex
- )
- /*++
- Purpose:
- Validate player's action, fallback to other action when needed.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- Return value:
- None.
- --*/
- {
- const WORD wPlayerRole = gpGlobals->rgParty[wPlayerIndex].wPlayerRole;
- const WORD wObjectID = g_Battle.rgPlayer[wPlayerIndex].action.wActionID;
- const SHORT sTarget = g_Battle.rgPlayer[wPlayerIndex].action.sTarget;
- BOOL fValid = TRUE, fToEnemy = FALSE;
- WORD w;
- int i;
- switch (g_Battle.rgPlayer[wPlayerIndex].action.ActionType)
- {
- case kBattleActionAttack:
- fToEnemy = TRUE;
- break;
- case kBattleActionPass:
- break;
- case kBattleActionDefend:
- break;
- case kBattleActionMagic:
- //
- // Make sure player actually has the magic to be used
- //
- for (i = 0; i < MAX_PLAYER_MAGICS; i++)
- {
- if (gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] == wObjectID)
- {
- break; // player has this magic
- }
- }
- if (i >= MAX_PLAYER_MAGICS)
- {
- fValid = FALSE;
- }
- w = gpGlobals->g.rgObject[wObjectID].magic.wMagicNumber;
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSilence] > 0)
- {
- //
- // Player is silenced
- //
- fValid = FALSE;
- }
- if (gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] <
- gpGlobals->g.lprgMagic[w].wCostMP)
- {
- //
- // No enough MP
- //
- fValid = FALSE;
- }
- //
- // Fallback to physical attack if player is using an offensive magic,
- // defend if player is using a defensive or healing magic
- //
- if (gpGlobals->g.rgObject[wObjectID].magic.wFlags & kMagicFlagUsableToEnemy)
- {
- if (!fValid)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionAttack;
- }
- else if (gpGlobals->g.rgObject[wObjectID].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- else if (sTarget == -1)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = PAL_BattleSelectAutoTarget();
- }
- fToEnemy = TRUE;
- }
- else
- {
- if (!fValid)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionDefend;
- }
- else if (gpGlobals->g.rgObject[wObjectID].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- else if (g_Battle.rgPlayer[wPlayerIndex].action.sTarget == -1)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = wPlayerIndex;
- }
- }
- break;
- case kBattleActionCoopMagic:
- fToEnemy = TRUE;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (PAL_IsPlayerDying(w) ||
- gpGlobals->rgPlayerStatus[w][kStatusSilence] > 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusConfused] > 0 ||
- gpGlobals->rgPlayerStatus[w][kStatusParalyzed] > 0 ||
- (!gConfig.fIsClassic && (g_Battle.rgPlayer[i].flTimeMeter < 100 ||
- (g_Battle.rgPlayer[i].state == kFighterAct && i != wPlayerIndex)))
- )
- {
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionAttack;
- break;
- }
- }
- if (g_Battle.rgPlayer[wPlayerIndex].action.ActionType == kBattleActionCoopMagic)
- {
- if (gpGlobals->g.rgObject[wObjectID].magic.wFlags & kMagicFlagApplyToAll)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- else if (sTarget == -1)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = PAL_BattleSelectAutoTarget();
- }
- }
- break;
- case kBattleActionFlee:
- break;
- case kBattleActionThrowItem:
- fToEnemy = TRUE;
- if (PAL_GetItemAmount(wObjectID) == 0)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionAttack;
- }
- else if (gpGlobals->g.rgObject[wObjectID].item.wFlags & kItemFlagApplyToAll)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- else if (g_Battle.rgPlayer[wPlayerIndex].action.sTarget == -1)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = PAL_BattleSelectAutoTarget();
- }
- break;
- case kBattleActionUseItem:
- if (PAL_GetItemAmount(wObjectID) == 0)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionDefend;
- }
- else if (gpGlobals->g.rgObject[wObjectID].item.wFlags & kItemFlagApplyToAll)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- else if (g_Battle.rgPlayer[wPlayerIndex].action.sTarget == -1)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = wPlayerIndex;
- }
- break;
- case kBattleActionAttackMate:
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] == 0)
- {
- //
- // Attack enemies instead if player is not confused
- //
- fToEnemy = TRUE;
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionAttack;
- }
- else
- {
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (i != wPlayerIndex &&
- gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] != 0)
- {
- break;
- }
- }
- if (i > gpGlobals->wMaxPartyMemberIndex)
- {
- //
- // Attack enemies if no one else is alive
- //
- fToEnemy = TRUE;
- g_Battle.rgPlayer[wPlayerIndex].action.ActionType = kBattleActionAttack;
- }
- }
- break;
- }
- //
- // Check if player can attack all enemies at once, or attack one enemy
- //
- if (g_Battle.rgPlayer[wPlayerIndex].action.ActionType == kBattleActionAttack)
- {
- if (sTarget == -1)
- {
- if (!PAL_PlayerCanAttackAll(wPlayerRole))
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = PAL_BattleSelectAutoTarget();
- }
- }
- else if (PAL_PlayerCanAttackAll(wPlayerRole))
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = -1;
- }
- }
- if (fToEnemy && g_Battle.rgPlayer[wPlayerIndex].action.sTarget >= 0)
- {
- if (g_Battle.rgEnemy[g_Battle.rgPlayer[wPlayerIndex].action.sTarget].wObjectID == 0)
- {
- g_Battle.rgPlayer[wPlayerIndex].action.sTarget = PAL_BattleSelectAutoTarget();
- assert(g_Battle.rgPlayer[wPlayerIndex].action.sTarget >= 0);
- }
- }
- }
- VOID
- PAL_BattlePlayerPerformAction(
- WORD wPlayerIndex
- )
- /*++
- Purpose:
- Perform the selected action for a player.
- Parameters:
- [IN] wPlayerIndex - the index of the player.
- Return value:
- None.
- --*/
- {
- SHORT sDamage;
- WORD wPlayerRole = gpGlobals->rgParty[wPlayerIndex].wPlayerRole;
- SHORT sTarget;
- int x, y;
- int i, j, t;
- WORD str, def, res, wObject, wMagicNum;
- BOOL fCritical;
- WORD rgwCoopPos[3][2] = {{208, 157}, {234, 170}, {260, 183}};
- g_Battle.wMovingPlayerIndex = wPlayerIndex;
- g_Battle.iBlow = 0;
- PAL_BattlePlayerValidateAction(wPlayerIndex);
- PAL_BattleBackupStat();
- sTarget = g_Battle.rgPlayer[wPlayerIndex].action.sTarget;
- switch (g_Battle.rgPlayer[wPlayerIndex].action.ActionType)
- {
- case kBattleActionAttack:
- if (sTarget != -1)
- {
- //
- // Attack one enemy
- //
- for (t = 0; t < (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusDualAttack] ? 2 : 1); t++)
- {
- str = PAL_GetPlayerAttackStrength(wPlayerRole);
- def = g_Battle.rgEnemy[sTarget].e.wDefense;
- def += (g_Battle.rgEnemy[sTarget].e.wLevel + 6) * 4;
- res = g_Battle.rgEnemy[sTarget].e.wPhysicalResistance;
- fCritical = FALSE;
- sDamage = PAL_CalcPhysicalAttackDamage(str, def, res);
- sDamage += RandomLong(1, 2);
- if (RandomLong(0, 5) == 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusBravery] > 0)
- {
- //
- // Critical Hit
- //
- sDamage *= 3;
- fCritical = TRUE;
- }
- if (wPlayerRole == 0 && RandomLong(0, 11) == 0)
- {
- //
- // Bonus hit for Li Xiaoyao
- //
- sDamage *= 2;
- fCritical = TRUE;
- }
- sDamage = (SHORT)(sDamage * RandomFloat(1, 1.125));
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[sTarget].e.wHealth -= sDamage;
- if (t == 0)
- {
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 7;
- PAL_BattleDelay(4, 0, TRUE);
- }
- PAL_BattleShowPlayerAttackAnim(wPlayerIndex, fCritical);
- }
- }
- else
- {
- //
- // Attack all enemies
- //
- for (t = 0; t < (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusDualAttack] ? 2 : 1); t++)
- {
- int division = 1;
- const int index[MAX_ENEMIES_IN_TEAM] = {2, 1, 0, 4, 3};
- fCritical =
- (RandomLong(0, 5) == 0 || gpGlobals->rgPlayerStatus[wPlayerRole][kStatusBravery] > 0);
- if (t == 0)
- {
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 7;
- PAL_BattleDelay(4, 0, TRUE);
- }
- for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++)
- {
- if (g_Battle.rgEnemy[index[i]].wObjectID == 0 ||
- index[i] > g_Battle.wMaxEnemyIndex)
- {
- continue;
- }
- str = PAL_GetPlayerAttackStrength(wPlayerRole);
- def = g_Battle.rgEnemy[index[i]].e.wDefense;
- def += (g_Battle.rgEnemy[index[i]].e.wLevel + 6) * 4;
- res = g_Battle.rgEnemy[index[i]].e.wPhysicalResistance;
- sDamage = PAL_CalcPhysicalAttackDamage(str, def, res);
- sDamage += RandomLong(1, 2);
- if (fCritical)
- {
- //
- // Critical Hit
- //
- sDamage *= 3;
- }
- sDamage /= division;
- sDamage = (SHORT)(sDamage * RandomFloat(1, 1.125));
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[index[i]].e.wHealth -= sDamage;
- division++;
- if (division > 3)
- {
- division = 3;
- }
- }
- PAL_BattleShowPlayerAttackAnim(wPlayerIndex, fCritical);
- }
- }
- PAL_BattleUpdateFighters();
- PAL_BattleMakeScene();
- PAL_BattleDelay(3, 0, TRUE);
- gpGlobals->Exp.rgAttackExp[wPlayerRole].wCount++;
- gpGlobals->Exp.rgHealthExp[wPlayerRole].wCount += RandomLong(2, 3);
- break;
- case kBattleActionAttackMate:
- //
- // Check if there is someone else who is alive
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (i == wPlayerIndex)
- {
- continue;
- }
- if (gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] > 0)
- {
- break;
- }
- }
- if (i <= gpGlobals->wMaxPartyMemberIndex)
- {
- //
- // Pick a target randomly
- //
- do
- {
- sTarget = RandomLong(0, gpGlobals->wMaxPartyMemberIndex);
- } while (sTarget == wPlayerIndex || gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[sTarget].wPlayerRole] == 0);
- for (j = 0; j < 2; j++)
- {
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 8;
- PAL_BattleDelay(1, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 0;
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleDelay(2, 0, TRUE);
- x = PAL_X(g_Battle.rgPlayer[sTarget].pos) + 30;
- y = PAL_Y(g_Battle.rgPlayer[sTarget].pos) + 12;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 8;
- PAL_BattleDelay(5, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 9;
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwWeaponSound[wPlayerRole]);
- str = PAL_GetPlayerAttackStrength(wPlayerRole);
- def = PAL_GetPlayerDefense(gpGlobals->rgParty[sTarget].wPlayerRole);
- if (g_Battle.rgPlayer[sTarget].fDefending)
- {
- def *= 2;
- }
- sDamage = PAL_CalcPhysicalAttackDamage(str, def, 2);
- if (gpGlobals->rgPlayerStatus[gpGlobals->rgParty[sTarget].wPlayerRole][kStatusProtect] > 0)
- {
- sDamage /= 2;
- }
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- if (sDamage > (SHORT)gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[sTarget].wPlayerRole])
- {
- sDamage = gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[sTarget].wPlayerRole];
- }
- gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[sTarget].wPlayerRole] -= sDamage;
- g_Battle.rgPlayer[sTarget].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[sTarget].pos) - 12,
- PAL_Y(g_Battle.rgPlayer[sTarget].pos) - 6);
- PAL_BattleDelay(1, 0, TRUE);
- g_Battle.rgPlayer[sTarget].iColorShift = 6;
- PAL_BattleDelay(1, 0, TRUE);
- PAL_BattleDisplayStatChange();
- g_Battle.rgPlayer[sTarget].iColorShift = 0;
- PAL_BattleDelay(4, 0, TRUE);
- PAL_BattleUpdateFighters();
- PAL_BattleDelay(4, 0, TRUE);
- }
- break;
- case kBattleActionCoopMagic:
- wObject = PAL_GetPlayerCooperativeMagic(gpGlobals->rgParty[wPlayerIndex].wPlayerRole);
- wMagicNum = gpGlobals->g.rgObject[wObject].magic.wMagicNumber;
- if (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeSummon)
- {
- PAL_BattleShowPlayerPreMagicAnim(wPlayerIndex, TRUE);
- PAL_BattleShowPlayerSummonMagicAnim((WORD)-1, wObject);
- }
- else
- {
- for (i = 1; i <= 6; i++)
- {
- //
- // Update the position for the player who invoked the action
- //
- x = PAL_X(g_Battle.rgPlayer[wPlayerIndex].posOriginal) * (6 - i);
- y = PAL_Y(g_Battle.rgPlayer[wPlayerIndex].posOriginal) * (6 - i);
- x += rgwCoopPos[0][0] * i;
- y += rgwCoopPos[0][1] * i;
- x /= 6;
- y /= 6;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- //
- // Update the position for other players
- //
- t = 0;
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- if ((WORD)j == wPlayerIndex)
- {
- continue;
- }
- t++;
- x = PAL_X(g_Battle.rgPlayer[j].posOriginal) * (6 - i);
- y = PAL_Y(g_Battle.rgPlayer[j].posOriginal) * (6 - i);
- x += rgwCoopPos[t][0] * i;
- y += rgwCoopPos[t][1] * i;
- x /= 6;
- y /= 6;
- g_Battle.rgPlayer[j].pos = PAL_XY(x, y);
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- for (i = gpGlobals->wMaxPartyMemberIndex; i >= 0; i--)
- {
- if ((WORD)i == wPlayerIndex)
- {
- continue;
- }
- g_Battle.rgPlayer[i].wCurrentFrame = 5;
- PAL_BattleDelay(3, 0, TRUE);
- }
- g_Battle.rgPlayer[wPlayerIndex].iColorShift = 6;
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 5;
- SOUND_Play(157);
- PAL_BattleDelay(5, 0, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 6;
- g_Battle.rgPlayer[wPlayerIndex].iColorShift = 0;
- PAL_BattleDelay(3, 0, TRUE);
- PAL_BattleShowPlayerOffMagicAnim((WORD)-1, wObject, sTarget, FALSE);
- }
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] -=
- gpGlobals->g.lprgMagic[wMagicNum].wCostMP;
- if ((SHORT)(gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole]) <= 0)
- {
- gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] = 1;
- }
- //
- // Reset the time meter for everyone when using coopmagic
- //
- if (gConfig.fIsClassic)
- {
- g_Battle.rgPlayer[i].state = kFighterWait;
- }
- else
- {
- g_Battle.rgPlayer[i].flTimeMeter = 0;
- g_Battle.rgPlayer[i].flTimeSpeedModifier = 2;
- }
- }
- PAL_BattleBackupStat(); // so that "damages" to players won't be shown
- str = 0;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- str += PAL_GetPlayerAttackStrength(gpGlobals->rgParty[i].wPlayerRole);
- str += PAL_GetPlayerMagicStrength(gpGlobals->rgParty[i].wPlayerRole);
- }
- str /= 4;
- //
- // Inflict damage to enemies
- //
- if (sTarget == -1)
- {
- //
- // Attack all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- def = g_Battle.rgEnemy[i].e.wDefense;
- def += (g_Battle.rgEnemy[i].e.wLevel + 6) * 4;
- sDamage = PAL_CalcMagicDamage(str, def,
- g_Battle.rgEnemy[i].e.wElemResistance, g_Battle.rgEnemy[i].e.wPoisonResistance, wObject);
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[i].e.wHealth -= sDamage;
- }
- }
- else
- {
- //
- // Attack one enemy
- //
- def = g_Battle.rgEnemy[sTarget].e.wDefense;
- def += (g_Battle.rgEnemy[sTarget].e.wLevel + 6) * 4;
- sDamage = PAL_CalcMagicDamage(str, def,
- g_Battle.rgEnemy[sTarget].e.wElemResistance, g_Battle.rgEnemy[sTarget].e.wPoisonResistance, wObject);
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[sTarget].e.wHealth -= sDamage;
- }
- PAL_BattleDisplayStatChange();
- PAL_BattleShowPostMagicAnim();
- PAL_BattleDelay(5, 0, TRUE);
- if (gpGlobals->g.lprgMagic[wMagicNum].wType != kMagicTypeSummon)
- {
- PAL_BattlePostActionCheck(FALSE);
- //
- // Move all players back to the original position
- //
- for (i = 1; i <= 6; i++)
- {
- //
- // Update the position for the player who invoked the action
- //
- x = PAL_X(g_Battle.rgPlayer[wPlayerIndex].posOriginal) * i;
- y = PAL_Y(g_Battle.rgPlayer[wPlayerIndex].posOriginal) * i;
- x += rgwCoopPos[0][0] * (6 - i);
- y += rgwCoopPos[0][1] * (6 - i);
- x /= 6;
- y /= 6;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- //
- // Update the position for other players
- //
- t = 0;
- for (j = 0; j <= gpGlobals->wMaxPartyMemberIndex; j++)
- {
- g_Battle.rgPlayer[j].wCurrentFrame = 0;
- if ((WORD)j == wPlayerIndex)
- {
- continue;
- }
- t++;
- x = PAL_X(g_Battle.rgPlayer[j].posOriginal) * i;
- y = PAL_Y(g_Battle.rgPlayer[j].posOriginal) * i;
- x += rgwCoopPos[t][0] * (6 - i);
- y += rgwCoopPos[t][1] * (6 - i);
- x /= 6;
- y /= 6;
- g_Battle.rgPlayer[j].pos = PAL_XY(x, y);
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- }
- break;
- case kBattleActionDefend:
- g_Battle.rgPlayer[wPlayerIndex].fDefending = TRUE;
- gpGlobals->Exp.rgDefenseExp[wPlayerRole].wCount += 2;
- break;
- case kBattleActionFlee:
- str = PAL_GetPlayerFleeRate(wPlayerRole);
- def = 0;
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- def += (SHORT)(g_Battle.rgEnemy[i].e.wFleeRate);
- def += (g_Battle.rgEnemy[i].e.wLevel + 6) * 2;
- }
- if ((SHORT)def < 0)
- {
- def = 0;
- }
- if (RandomLong(0, str) >= RandomLong(0, def) && !g_Battle.fIsBoss)
- {
- //
- // Successful escape
- //
- PAL_BattlePlayerEscape();
- }
- else
- {
- //
- // Failed escape
- //
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 0;
- for (i = 0; i < 3; i++)
- {
- x = PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos) + 4;
- y = PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos) + 2;
- g_Battle.rgPlayer[wPlayerIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(1, 0, TRUE);
- }
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 1;
- PAL_BattleDelay(8, BATTLE_LABEL_ESCAPEFAIL, TRUE);
- gpGlobals->Exp.rgFleeExp[wPlayerRole].wCount += 2;
- }
- break;
- case kBattleActionMagic:
- wObject = g_Battle.rgPlayer[wPlayerIndex].action.wActionID;
- wMagicNum = gpGlobals->g.rgObject[wObject].magic.wMagicNumber;
- PAL_BattleShowPlayerPreMagicAnim(wPlayerIndex,
- (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeSummon));
- if (!gpGlobals->fAutoBattle)
- {
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] -= gpGlobals->g.lprgMagic[wMagicNum].wCostMP;
- if ((SHORT)(gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole]) < 0)
- {
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] = 0;
- }
- }
- if (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeApplyToPlayer ||
- gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeApplyToParty ||
- gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeTrance)
- {
- //
- // Using a defensive magic
- //
- WORD w = 0;
- if (g_Battle.rgPlayer[wPlayerIndex].action.sTarget != -1)
- {
- w = gpGlobals->rgParty[g_Battle.rgPlayer[wPlayerIndex].action.sTarget].wPlayerRole;
- }
- else if (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeTrance)
- {
- w = wPlayerRole;
- }
- gpGlobals->g.rgObject[wObject].magic.wScriptOnUse =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].magic.wScriptOnUse, wPlayerRole);
- if (g_fScriptSuccess)
- {
- PAL_BattleShowPlayerDefMagicAnim(wPlayerIndex, wObject, sTarget);
- gpGlobals->g.rgObject[wObject].magic.wScriptOnSuccess =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].magic.wScriptOnSuccess, w);
- if (g_fScriptSuccess)
- {
- if (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeTrance)
- {
- for (i = 0; i < 6; i++)
- {
- g_Battle.rgPlayer[wPlayerIndex].iColorShift = i * 2;
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleBackupScene();
- PAL_LoadBattleSprites();
- g_Battle.rgPlayer[wPlayerIndex].iColorShift = 0;
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- }
- }
- }
- else
- {
- //
- // Using an offensive magic
- //
- gpGlobals->g.rgObject[wObject].magic.wScriptOnUse =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].magic.wScriptOnUse, wPlayerRole);
- if (g_fScriptSuccess)
- {
- if (gpGlobals->g.lprgMagic[wMagicNum].wType == kMagicTypeSummon)
- {
- PAL_BattleShowPlayerSummonMagicAnim(wPlayerIndex, wObject);
- }
- else
- {
- PAL_BattleShowPlayerOffMagicAnim(wPlayerIndex, wObject, sTarget, FALSE);
- }
- gpGlobals->g.rgObject[wObject].magic.wScriptOnSuccess =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].magic.wScriptOnSuccess, (WORD)sTarget);
- //
- // Inflict damage to enemies
- //
- if ((SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wBaseDamage) > 0)
- {
- if (sTarget == -1)
- {
- //
- // Attack all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- str = PAL_GetPlayerMagicStrength(wPlayerRole);
- def = g_Battle.rgEnemy[i].e.wDefense;
- def += (g_Battle.rgEnemy[i].e.wLevel + 6) * 4;
- sDamage = PAL_CalcMagicDamage(str, def,
- g_Battle.rgEnemy[i].e.wElemResistance, g_Battle.rgEnemy[i].e.wPoisonResistance, wObject);
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[i].e.wHealth -= sDamage;
- }
- }
- else
- {
- //
- // Attack one enemy
- //
- str = PAL_GetPlayerMagicStrength(wPlayerRole);
- def = g_Battle.rgEnemy[sTarget].e.wDefense;
- def += (g_Battle.rgEnemy[sTarget].e.wLevel + 6) * 4;
- sDamage = PAL_CalcMagicDamage(str, def,
- g_Battle.rgEnemy[sTarget].e.wElemResistance, g_Battle.rgEnemy[sTarget].e.wPoisonResistance, wObject);
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- g_Battle.rgEnemy[sTarget].e.wHealth -= sDamage;
- }
- }
- }
- }
- PAL_BattleDisplayStatChange();
- PAL_BattleShowPostMagicAnim();
- PAL_BattleDelay(5, 0, TRUE);
- gpGlobals->Exp.rgMagicExp[wPlayerRole].wCount += RandomLong(2, 3);
- gpGlobals->Exp.rgMagicPowerExp[wPlayerRole].wCount++;
- break;
- case kBattleActionThrowItem:
- wObject = g_Battle.rgPlayer[wPlayerIndex].action.wActionID;
- for (i = 0; i < 4; i++)
- {
- g_Battle.rgPlayer[wPlayerIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[wPlayerIndex].pos) - (4 - i),
- PAL_Y(g_Battle.rgPlayer[wPlayerIndex].pos) - (4 - i) / 2);
- PAL_BattleDelay(1, 0, TRUE);
- }
- PAL_BattleDelay(2, wObject, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 5;
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwMagicSound[wPlayerRole]);
- PAL_BattleDelay(8, wObject, TRUE);
- g_Battle.rgPlayer[wPlayerIndex].wCurrentFrame = 6;
- PAL_BattleDelay(2, wObject, TRUE);
- //
- // Run the script
- //
- gpGlobals->g.rgObject[wObject].item.wScriptOnThrow =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].item.wScriptOnThrow, (WORD)sTarget);
- //
- // Remove the thrown item from inventory
- //
- PAL_AddItemToInventory(wObject, -1);
- PAL_BattleDisplayStatChange();
- PAL_BattleDelay(4, 0, TRUE);
- PAL_BattleUpdateFighters();
- PAL_BattleDelay(4, 0, TRUE);
- break;
- case kBattleActionUseItem:
- wObject = g_Battle.rgPlayer[wPlayerIndex].action.wActionID;
- PAL_BattleShowPlayerUseItemAnim(wPlayerIndex, wObject, sTarget);
- //
- // Run the script
- //
- gpGlobals->g.rgObject[wObject].item.wScriptOnUse =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].item.wScriptOnUse,
- (sTarget == -1) ? 0xFFFF : gpGlobals->rgParty[sTarget].wPlayerRole);
- //
- // Remove the item if the item is consuming
- //
- if (gpGlobals->g.rgObject[wObject].item.wFlags & kItemFlagConsuming)
- {
- PAL_AddItemToInventory(wObject, -1);
- }
- if (g_Battle.iHidingTime < 0)
- {
- if (gConfig.fIsClassic)
- {
- g_Battle.iHidingTime = -g_Battle.iHidingTime;
- }
- else
- {
- g_Battle.iHidingTime = -g_Battle.iHidingTime * 20;
- if (gpGlobals->bBattleSpeed > 1)
- {
- g_Battle.iHidingTime *= 1 + (gpGlobals->bBattleSpeed - 1) * 0.5;
- }
- else
- {
- g_Battle.iHidingTime *= 1.2;
- }
- }
- PAL_BattleBackupScene();
- PAL_BattleMakeScene();
- PAL_BattleFadeScene();
- }
- PAL_BattleUpdateFighters();
- PAL_BattleDisplayStatChange();
- PAL_BattleDelay(8, 0, TRUE);
- break;
- case kBattleActionPass:
- break;
- }
- //
- // Revert this player back to waiting state.
- //
- g_Battle.rgPlayer[wPlayerIndex].state = kFighterWait;
- g_Battle.rgPlayer[wPlayerIndex].flTimeMeter = 0;
- PAL_BattlePostActionCheck(FALSE);
- if (!gConfig.fIsClassic)
- {
- //
- // Only check for poisons when the battle is not ended
- //
- BOOL fCheckPoison = FALSE;
- if (g_Battle.BattleResult == kBattleResultOnGoing)
- {
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID != 0)
- {
- fCheckPoison = TRUE;
- break;
- }
- }
- }
- //
- // Check for poisons
- //
- if (fCheckPoison)
- {
- BOOL fPoisoned = FALSE;
- PAL_BattleBackupStat();
- for (i = 0; i < MAX_POISONS; i++)
- {
- wObject = gpGlobals->rgPoisonStatus[i][wPlayerIndex].wPoisonID;
- if (wObject != 0)
- {
- fPoisoned = TRUE;
- gpGlobals->rgPoisonStatus[i][wPlayerIndex].wPoisonScript =
- PAL_RunTriggerScript(gpGlobals->rgPoisonStatus[i][wPlayerIndex].wPoisonScript, wPlayerRole);
- }
- }
- if (fPoisoned)
- {
- PAL_BattleDelay(3, 0, TRUE);
- PAL_BattleUpdateFighters();
- if (PAL_BattleDisplayStatChange())
- {
- PAL_BattleDelay(6, 0, TRUE);
- }
- }
- }
- //
- // Update statuses
- //
- for (i = 0; i < kStatusAll; i++)
- {
- if (gpGlobals->rgPlayerStatus[wPlayerRole][i] > 0)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][i]--;
- }
- }
- }
- }
- static INT
- PAL_BattleEnemySelectTargetIndex(
- VOID
- )
- /*++
- Purpose:
- Select a attackable player randomly.
- Parameters:
- None.
- Return value:
- None.
- --*/
- {
- int i;
- i = RandomLong(0, gpGlobals->wMaxPartyMemberIndex);
- while (gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] == 0)
- {
- i = RandomLong(0, gpGlobals->wMaxPartyMemberIndex);
- }
- return i;
- }
- VOID
- PAL_BattleEnemyPerformAction(
- WORD wEnemyIndex
- )
- /*++
- Purpose:
- Perform the selected action for a player.
- Parameters:
- [IN] wEnemyIndex - the index of the player.
- Return value:
- None.
- --*/
- {
- int str, def, iCoverIndex, i, x, y, ex, ey, iSound;
- WORD rgwElementalResistance[NUM_MAGIC_ELEMENTAL];
- WORD wPlayerRole, w, wMagic, wMagicNum;
- SHORT sTarget, sDamage;
- BOOL fAutoDefend = FALSE, rgfMagAutoDefend[MAX_PLAYERS_IN_PARTY];
- PAL_BattleBackupStat();
- g_Battle.iBlow = 0;
- sTarget = PAL_BattleEnemySelectTargetIndex();
- wPlayerRole = gpGlobals->rgParty[sTarget].wPlayerRole;
- wMagic = g_Battle.rgEnemy[wEnemyIndex].e.wMagic;
- if (g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusSleep] > 0 ||
- g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusParalyzed] > 0 ||
- g_Battle.iHidingTime > 0)
- {
- //
- // Do nothing
- //
- goto end;
- }
- else if (g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusConfused] > 0)
- {
- // TODO
- }
- else if (wMagic != 0 &&
- RandomLong(0, 9) < g_Battle.rgEnemy[wEnemyIndex].e.wMagicRate &&
- g_Battle.rgEnemy[wEnemyIndex].rgwStatus[kStatusSilence] == 0)
- {
- //
- // Magical attack
- //
- if (wMagic == 0xFFFF)
- {
- //
- // Do nothing
- //
- goto end;
- }
- wMagicNum = gpGlobals->g.rgObject[wMagic].magic.wMagicNumber;
- str = (SHORT)g_Battle.rgEnemy[wEnemyIndex].e.wMagicStrength;
- str += (g_Battle.rgEnemy[wEnemyIndex].e.wLevel + 6) * 6;
- if (str < 0)
- {
- str = 0;
- }
- ex = PAL_X(g_Battle.rgEnemy[wEnemyIndex].pos);
- ey = PAL_Y(g_Battle.rgEnemy[wEnemyIndex].pos);
- ex += 12;
- ey += 6;
- g_Battle.rgEnemy[wEnemyIndex].pos = PAL_XY(ex, ey);
- PAL_BattleDelay(1, 0, FALSE);
- ex += 4;
- ey += 2;
- g_Battle.rgEnemy[wEnemyIndex].pos = PAL_XY(ex, ey);
- PAL_BattleDelay(1, 0, FALSE);
- SOUND_Play(g_Battle.rgEnemy[wEnemyIndex].e.wMagicSound);
- for (i = 0; i < g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames; i++)
- {
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame =
- g_Battle.rgEnemy[wEnemyIndex].e.wIdleFrames + i;
- PAL_BattleDelay(g_Battle.rgEnemy[wEnemyIndex].e.wActWaitFrames, 0, FALSE);
- }
- if (g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames == 0)
- {
- PAL_BattleDelay(1, 0, FALSE);
- }
- if (gpGlobals->g.lprgMagic[wMagicNum].wSoundDelay == 0)
- {
- for (i = 0; i <= g_Battle.rgEnemy[wEnemyIndex].e.wAttackFrames; i++)
- {
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame =
- i - 1 + g_Battle.rgEnemy[wEnemyIndex].e.wIdleFrames + g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames;
- PAL_BattleDelay(g_Battle.rgEnemy[wEnemyIndex].e.wActWaitFrames, 0, FALSE);
- }
- }
- if (gpGlobals->g.lprgMagic[wMagicNum].wType != kMagicTypeNormal)
- {
- sTarget = -1;
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->rgPlayerStatus[w][kStatusSleep] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusParalyzedOrSlow] == 0 &&
- gpGlobals->rgPlayerStatus[w][kStatusConfused] == 0 &&
- RandomLong(0, 2) == 0 &&
- gpGlobals->g.PlayerRoles.rgwHP[w] != 0)
- {
- rgfMagAutoDefend[i] = TRUE;
- g_Battle.rgPlayer[i].wCurrentFrame = 3;
- }
- else
- {
- rgfMagAutoDefend[i] = FALSE;
- }
- }
- }
- else if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzedOrSlow] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] == 0 &&
- RandomLong(0, 2) == 0)
- {
- fAutoDefend = TRUE;
- g_Battle.rgPlayer[sTarget].wCurrentFrame = 3;
- }
- // PAL_BattleDelay(12, (WORD)(-((SHORT)wMagic)), FALSE);
- gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse, wPlayerRole);
- if (g_fScriptSuccess)
- {
- PAL_BattleShowEnemyMagicAnim(wMagic, sTarget);
- gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess, wPlayerRole);
- }
- if ((SHORT)(gpGlobals->g.lprgMagic[wMagicNum].wBaseDamage) > 0)
- {
- if (sTarget == -1)
- {
- //
- // damage all players
- //
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- w = gpGlobals->rgParty[i].wPlayerRole;
- if (gpGlobals->g.PlayerRoles.rgwHP[w] == 0)
- {
- //
- // skip dead players
- //
- continue;
- }
- def = PAL_GetPlayerDefense(w);
- for (x = 0; x < NUM_MAGIC_ELEMENTAL; x++)
- {
- rgwElementalResistance[x] =
- 5 + PAL_GetPlayerElementalResistance(w, x) / 20;
- }
- sDamage = PAL_CalcMagicDamage(str, def, rgwElementalResistance,
- 5 + PAL_GetPlayerPoisonResistance(w) / 20, wMagic);
- sDamage /= ((g_Battle.rgPlayer[i].fDefending ? 2 : 1) *
- ((gpGlobals->rgPlayerStatus[w][kStatusProtect] > 0) ? 2 : 1)) +
- (rgfMagAutoDefend[i] ? 1 : 0);
- if (sDamage > gpGlobals->g.PlayerRoles.rgwHP[w])
- {
- sDamage = gpGlobals->g.PlayerRoles.rgwHP[w];
- }
- #ifndef INVINCIBLE
- gpGlobals->g.PlayerRoles.rgwHP[w] -= sDamage;
- #endif
- if (gpGlobals->g.PlayerRoles.rgwHP[w] == 0)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwDeathSound[w]);
- }
- }
- }
- else
- {
- //
- // damage one player
- //
- def = PAL_GetPlayerDefense(wPlayerRole);
- for (x = 0; x < NUM_MAGIC_ELEMENTAL; x++)
- {
- rgwElementalResistance[x] =
- 5 + PAL_GetPlayerElementalResistance(wPlayerRole, x) / 20;
- }
- sDamage = PAL_CalcMagicDamage(str, def, rgwElementalResistance,
- 5 + PAL_GetPlayerPoisonResistance(wPlayerRole) / 20, wMagic);
- sDamage /= ((g_Battle.rgPlayer[sTarget].fDefending ? 2 : 1) *
- ((gpGlobals->rgPlayerStatus[wPlayerRole][kStatusProtect] > 0) ? 2 : 1)) +
- (fAutoDefend ? 1 : 0);
- if (sDamage > gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole])
- {
- sDamage = gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole];
- }
- #ifndef INVINCIBLE
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] -= sDamage;
- #endif
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwDeathSound[wPlayerRole]);
- }
- }
- }
- if (!gpGlobals->fAutoBattle)
- {
- PAL_BattleDisplayStatChange();
- }
- for (i = 0; i < 5; i++)
- {
- if (sTarget == -1)
- {
- for (x = 0; x <= gpGlobals->wMaxPartyMemberIndex; x++)
- {
- if (g_Battle.rgPlayer[x].wPrevHP ==
- gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[x].wPlayerRole])
- {
- //
- // Skip unaffected players
- //
- continue;
- }
- g_Battle.rgPlayer[x].wCurrentFrame = 4;
- if (i > 0)
- {
- g_Battle.rgPlayer[x].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[x].pos) + (8 >> i),
- PAL_Y(g_Battle.rgPlayer[x].pos) + (4 >> i));
- }
- g_Battle.rgPlayer[x].iColorShift = ((i < 3) ? 6 : 0);
- }
- }
- else
- {
- g_Battle.rgPlayer[sTarget].wCurrentFrame = 4;
- if (i > 0)
- {
- g_Battle.rgPlayer[sTarget].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[sTarget].pos) + (8 >> i),
- PAL_Y(g_Battle.rgPlayer[sTarget].pos) + (4 >> i));
- }
- g_Battle.rgPlayer[sTarget].iColorShift = ((i < 3) ? 6 : 0);
- }
- PAL_BattleDelay(1, 0, FALSE);
- }
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame = 0;
- g_Battle.rgEnemy[wEnemyIndex].pos = g_Battle.rgEnemy[wEnemyIndex].posOriginal;
- PAL_BattleDelay(1, 0, FALSE);
- PAL_BattleUpdateFighters();
- PAL_BattlePostActionCheck(TRUE);
- PAL_BattleDelay(8, 0, TRUE);
- }
- else
- {
- //
- // Physical attack
- //
- WORD wFrameBak = g_Battle.rgPlayer[sTarget].wCurrentFrame;
- str = (SHORT)g_Battle.rgEnemy[wEnemyIndex].e.wAttackStrength;
- str += (g_Battle.rgEnemy[wEnemyIndex].e.wLevel + 6) * 6;
- if (str < 0)
- {
- str = 0;
- }
- def = PAL_GetPlayerDefense(wPlayerRole);
- if (g_Battle.rgPlayer[sTarget].fDefending)
- {
- def *= 2;
- }
- SOUND_Play(g_Battle.rgEnemy[wEnemyIndex].e.wAttackSound);
- iCoverIndex = -1;
- fAutoDefend = (RandomLong(0, 16) >= 10);
- //
- // Check if the inflictor should be protected
- //
- if ((PAL_IsPlayerDying(wPlayerRole) ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzed] > 0) && fAutoDefend)
- {
- w = gpGlobals->g.PlayerRoles.rgwCoveredBy[wPlayerRole];
- for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (gpGlobals->rgParty[i].wPlayerRole == w)
- {
- iCoverIndex = i;
- break;
- }
- }
- if (iCoverIndex != -1)
- {
- if (PAL_IsPlayerDying(gpGlobals->rgParty[iCoverIndex].wPlayerRole) ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[iCoverIndex].wPlayerRole][kStatusConfused] > 0 ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[iCoverIndex].wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[gpGlobals->rgParty[iCoverIndex].wPlayerRole][kStatusParalyzed] > 0)
- {
- iCoverIndex = -1;
- }
- }
- }
- //
- // If no one can cover the inflictor and inflictor is in a
- // bad status, don't evade
- //
- if (iCoverIndex == -1 &&
- (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusConfused] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSleep] > 0 ||
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusParalyzedOrSlow] > 0))
- {
- fAutoDefend = FALSE;
- }
- for (i = 0; i < g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames; i++)
- {
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame =
- g_Battle.rgEnemy[wEnemyIndex].e.wIdleFrames + i;
- PAL_BattleDelay(2, 0, FALSE);
- }
- for (i = 0; i < 3 - g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames; i++)
- {
- x = PAL_X(g_Battle.rgEnemy[wEnemyIndex].pos) - 2;
- y = PAL_Y(g_Battle.rgEnemy[wEnemyIndex].pos) - 1;
- g_Battle.rgEnemy[wEnemyIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(1, 0, FALSE);
- }
- if (!gConfig.fIsWIN95 || g_Battle.rgEnemy[wEnemyIndex].e.wActionSound != 0)
- {
- SOUND_Play(g_Battle.rgEnemy[wEnemyIndex].e.wActionSound);
- }
- PAL_BattleDelay(1, 0, FALSE);
- ex = PAL_X(g_Battle.rgPlayer[sTarget].pos) - 44;
- ey = PAL_Y(g_Battle.rgPlayer[sTarget].pos) - 16;
- iSound = g_Battle.rgEnemy[wEnemyIndex].e.wCallSound;
- if (iCoverIndex != -1)
- {
- iSound = gpGlobals->g.PlayerRoles.rgwCoverSound[gpGlobals->rgParty[iCoverIndex].wPlayerRole];
- g_Battle.rgPlayer[iCoverIndex].wCurrentFrame = 3;
- x = PAL_X(g_Battle.rgPlayer[sTarget].pos) - 24;
- y = PAL_Y(g_Battle.rgPlayer[sTarget].pos) - 12;
- g_Battle.rgPlayer[iCoverIndex].pos = PAL_XY(x, y);
- }
- else if (fAutoDefend)
- {
- g_Battle.rgPlayer[sTarget].wCurrentFrame = 3;
- iSound = gpGlobals->g.PlayerRoles.rgwCoverSound[wPlayerRole];
- }
- if (g_Battle.rgEnemy[wEnemyIndex].e.wAttackFrames == 0)
- {
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame =
- g_Battle.rgEnemy[wEnemyIndex].e.wIdleFrames - 1;
- g_Battle.rgEnemy[wEnemyIndex].pos = PAL_XY(ex, ey);
- PAL_BattleDelay(2, 0, FALSE);
- }
- else
- {
- for (i = 0; i <= g_Battle.rgEnemy[wEnemyIndex].e.wAttackFrames; i++)
- {
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame =
- g_Battle.rgEnemy[wEnemyIndex].e.wIdleFrames +
- g_Battle.rgEnemy[wEnemyIndex].e.wMagicFrames + i - 1;
- g_Battle.rgEnemy[wEnemyIndex].pos = PAL_XY(ex, ey);
- PAL_BattleDelay(g_Battle.rgEnemy[wEnemyIndex].e.wActWaitFrames, 0, FALSE);
- }
- }
- if (!fAutoDefend)
- {
- g_Battle.rgPlayer[sTarget].wCurrentFrame = 4;
- sDamage = PAL_CalcPhysicalAttackDamage(str + RandomLong(0, 2), def, 2);
- sDamage += RandomLong(0, 1);
- if (gpGlobals->rgPlayerStatus[wPlayerRole][kStatusProtect])
- {
- sDamage /= 2;
- }
- if ((SHORT)gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] < sDamage)
- {
- sDamage = gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole];
- }
- if (sDamage <= 0)
- {
- sDamage = 1;
- }
- #ifndef INVINCIBLE
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] -= sDamage;
- #endif
- PAL_BattleDisplayStatChange();
- g_Battle.rgPlayer[sTarget].iColorShift = 6;
- }
- if (!gConfig.fIsWIN95 || iSound != 0)
- {
- SOUND_Play(iSound);
- }
- PAL_BattleDelay(1, 0, FALSE);
- g_Battle.rgPlayer[sTarget].iColorShift = 0;
- if (iCoverIndex != -1)
- {
- g_Battle.rgEnemy[wEnemyIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgEnemy[wEnemyIndex].pos) - 10,
- PAL_Y(g_Battle.rgEnemy[wEnemyIndex].pos) - 8);
- g_Battle.rgPlayer[iCoverIndex].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[iCoverIndex].pos) + 4,
- PAL_Y(g_Battle.rgPlayer[iCoverIndex].pos) + 2);
- }
- else
- {
- g_Battle.rgPlayer[sTarget].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[sTarget].pos) + 8,
- PAL_Y(g_Battle.rgPlayer[sTarget].pos) + 4);
- }
- PAL_BattleDelay(1, 0, FALSE);
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0)
- {
- SOUND_Play(gpGlobals->g.PlayerRoles.rgwDeathSound[wPlayerRole]);
- wFrameBak = 2;
- }
- else if (PAL_IsPlayerDying(wPlayerRole))
- {
- wFrameBak = 1;
- }
- if (iCoverIndex == -1)
- {
- g_Battle.rgPlayer[sTarget].pos =
- PAL_XY(PAL_X(g_Battle.rgPlayer[sTarget].pos) + 2,
- PAL_Y(g_Battle.rgPlayer[sTarget].pos) + 1);
- }
- PAL_BattleDelay(3, 0, FALSE);
- g_Battle.rgEnemy[wEnemyIndex].pos = g_Battle.rgEnemy[wEnemyIndex].posOriginal;
- g_Battle.rgEnemy[wEnemyIndex].wCurrentFrame = 0;
- PAL_BattleDelay(1, 0, FALSE);
- g_Battle.rgPlayer[sTarget].wCurrentFrame = wFrameBak;
- PAL_BattleDelay(1, 0, TRUE);
- g_Battle.rgPlayer[sTarget].pos = g_Battle.rgPlayer[sTarget].posOriginal;
- PAL_BattleDelay(4, 0, TRUE);
- PAL_BattleUpdateFighters();
- if (iCoverIndex == -1 && !fAutoDefend &&
- g_Battle.rgEnemy[wEnemyIndex].e.wAttackEquivItemRate >= RandomLong(1, 10))
- {
- i = g_Battle.rgEnemy[wEnemyIndex].e.wAttackEquivItem;
- gpGlobals->g.rgObject[i].item.wScriptOnUse =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[i].item.wScriptOnUse, wPlayerRole);
- }
- PAL_BattlePostActionCheck(TRUE);
- }
- end:
- if (!gConfig.fIsClassic)
- {
- //
- // Check poisons
- //
- if (!g_Battle.rgEnemy[wEnemyIndex].fDualMove)
- {
- PAL_BattleBackupStat();
- for (i = 0; i < MAX_POISONS; i++)
- {
- if (g_Battle.rgEnemy[wEnemyIndex].rgPoisons[i].wPoisonID != 0)
- {
- g_Battle.rgEnemy[wEnemyIndex].rgPoisons[i].wPoisonScript =
- PAL_RunTriggerScript(g_Battle.rgEnemy[wEnemyIndex].rgPoisons[i].wPoisonScript, wEnemyIndex);
- }
- }
- if (PAL_BattleDisplayStatChange())
- {
- PAL_BattleDelay(6, 0, FALSE);
- }
- }
- PAL_BattlePostActionCheck(FALSE);
- //
- // Update statuses
- //
- for (i = 0; i < kStatusAll; i++)
- {
- if (g_Battle.rgEnemy[wEnemyIndex].rgwStatus[i] > 0)
- {
- g_Battle.rgEnemy[wEnemyIndex].rgwStatus[i]--;
- }
- }
- }
- }
- VOID
- PAL_BattleStealFromEnemy(
- WORD wTarget,
- WORD wStealRate
- )
- /*++
- Purpose:
- Steal from the enemy.
- Parameters:
- [IN] wTarget - the target enemy index.
- [IN] wStealRate - the rate of successful theft.
- Return value:
- None.
- --*/
- {
- int iPlayerIndex = g_Battle.wMovingPlayerIndex;
- int offset, x, y, i;
- WCHAR s[256] = L"";
- g_Battle.rgPlayer[iPlayerIndex].wCurrentFrame = 10;
- offset = ((INT)wTarget - iPlayerIndex) * 8;
- x = PAL_X(g_Battle.rgEnemy[wTarget].pos) + 64 - offset;
- y = PAL_Y(g_Battle.rgEnemy[wTarget].pos) + 20 - offset / 2;
- g_Battle.rgPlayer[iPlayerIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(1, 0, TRUE);
- for (i = 0; i < 5; i++)
- {
- x -= i + 8;
- y -= 4;
- g_Battle.rgPlayer[iPlayerIndex].pos = PAL_XY(x, y);
- if (i == 4)
- {
- g_Battle.rgEnemy[wTarget].iColorShift = 6;
- }
- PAL_BattleDelay(1, 0, TRUE);
- }
- g_Battle.rgEnemy[wTarget].iColorShift = 0;
- x--;
- g_Battle.rgPlayer[iPlayerIndex].pos = PAL_XY(x, y);
- PAL_BattleDelay(3, 0, TRUE);
- g_Battle.rgPlayer[iPlayerIndex].state = kFighterWait;
- g_Battle.rgPlayer[iPlayerIndex].flTimeMeter = 0;
- PAL_BattleUpdateFighters();
- PAL_BattleDelay(1, 0, TRUE);
- if (g_Battle.rgEnemy[wTarget].e.nStealItem > 0 &&
- (RandomLong(0, 10) <= wStealRate || wStealRate == 0))
- {
- if (g_Battle.rgEnemy[wTarget].e.wStealItem == 0)
- {
- //
- // stolen coins
- //
- int c = g_Battle.rgEnemy[wTarget].e.nStealItem / RandomLong(2, 3);
- g_Battle.rgEnemy[wTarget].e.nStealItem -= c;
- gpGlobals->dwCash += c;
- if (c > 0)
- {
- swprintf(s, 256, L"%s %d %s", PAL_GetWord(34), c, PAL_GetWord(10));
- }
- }
- else
- {
- //
- // stolen item
- //
- g_Battle.rgEnemy[wTarget].e.nStealItem--;
- PAL_AddItemToInventory(g_Battle.rgEnemy[wTarget].e.wStealItem, 1);
- wcscpy(s, PAL_GetWord(34));
- wcscat(s, PAL_GetWord(g_Battle.rgEnemy[wTarget].e.wStealItem));
- }
- if (s[0] != '\0')
- {
- if (gConfig.fIsClassic)
- {
- PAL_StartDialog(kDialogCenterWindow, 0, 0, FALSE);
- PAL_ShowDialogText(s);
- }
- else
- {
- PAL_BattleUIShowText(s, 800);
- }
- }
- }
- }
- VOID
- PAL_BattleSimulateMagic(
- SHORT sTarget,
- WORD wMagicObjectID,
- WORD wBaseDamage
- )
- /*++
- Purpose:
- Simulate a magic for players. Mostly used in item throwing script.
- Parameters:
- [IN] sTarget - the target enemy index. -1 = all enemies.
- [IN] wMagicObjectID - the object ID of the magic to be simulated.
- [IN] wBaseDamage - the base damage of the simulation.
- Return value:
- None.
- --*/
- {
- SHORT sDamage;
- int i, def;
- if (gpGlobals->g.rgObject[wMagicObjectID].magic.wFlags & kMagicFlagApplyToAll)
- {
- sTarget = -1;
- }
- else if (sTarget == -1)
- {
- sTarget = PAL_BattleSelectAutoTarget();
- }
- //
- // Show the magic animation
- //
- PAL_BattleShowPlayerOffMagicAnim(0xFFFF, wMagicObjectID, sTarget, FALSE);
- if (gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagicObjectID].magic.wMagicNumber].wBaseDamage > 0 ||
- wBaseDamage > 0)
- {
- if (sTarget == -1)
- {
- //
- // Apply to all enemies
- //
- for (i = 0; i <= g_Battle.wMaxEnemyIndex; i++)
- {
- if (g_Battle.rgEnemy[i].wObjectID == 0)
- {
- continue;
- }
- def = (SHORT)g_Battle.rgEnemy[i].e.wDefense;
- def += (g_Battle.rgEnemy[i].e.wLevel + 6) * 4;
- if (def < 0)
- {
- def = 0;
- }
- sDamage = PAL_CalcMagicDamage(wBaseDamage, (WORD)def, g_Battle.rgEnemy[i].e.wElemResistance,
- g_Battle.rgEnemy[i].e.wPoisonResistance, wMagicObjectID);
- if (sDamage < 0)
- {
- sDamage = 0;
- }
- g_Battle.rgEnemy[i].e.wHealth -= sDamage;
- }
- }
- else
- {
- //
- // Apply to one enemy
- //
- def = (SHORT)g_Battle.rgEnemy[sTarget].e.wDefense;
- def += (g_Battle.rgEnemy[sTarget].e.wLevel + 6) * 4;
- if (def < 0)
- {
- def = 0;
- }
- sDamage = PAL_CalcMagicDamage(wBaseDamage, (WORD)def, g_Battle.rgEnemy[sTarget].e.wElemResistance,
- g_Battle.rgEnemy[sTarget].e.wPoisonResistance, wMagicObjectID);
- if (sDamage < 0)
- {
- sDamage = 0;
- }
- g_Battle.rgEnemy[sTarget].e.wHealth -= sDamage;
- }
- }
- }
|