1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446 |
- #include "main.h"
- #include "resampler.h"
- LPGLOBALVARS gpGlobals = NULL;
- extern BOOL g_fUseMidi;
- #if SDL_BYTEORDER == SDL_LIL_ENDIAN
- #define DO_BYTESWAP(buf, size)
- #else
- #define DO_BYTESWAP(buf, size) \
- do { \
- int i; \
- for (i = 0; i < (size) / 2; i++) \
- { \
- ((LPWORD)(buf))[i] = SDL_SwapLE16(((LPWORD)(buf))[i]); \
- } \
- } while(0)
- #endif
- #define LOAD_DATA(buf, size, chunknum, fp) \
- do { \
- PAL_MKFReadChunk((LPBYTE)(buf), (size), (chunknum), (fp)); \
- DO_BYTESWAP(buf, size); \
- } while(0)
- INT
- PAL_InitGlobals(
- VOID
- )
- /*++
- Purpose:
- Initialize global data.
- Parameters:
- [IN] iCodePage - the code page for text conversion.
- [IN] dwWordLength - the length of each word.
- Return value:
- 0 = success, -1 = error.
- --*/
- {
- FILE *fp;
- CODEPAGE iCodePage = CP_BIG5; // Default for BIG5
- DWORD dwWordLength = 10; // Default for PAL DOS/WIN95
- DWORD dwExtraMagicDescLines = 0; // Default for PAL DOS/WIN95
- DWORD dwExtraItemDescLines = 0; // Default for PAL DOS/WIN95
- DWORD dwIsDOS = 1; // Default for DOS
- DWORD dwUseEmbeddedFonts = 1; // Default for using embedded fonts in DOS version
- DWORD dwUseSurroundOPL = 1; // Default for using surround opl
- DWORD dwUseStereo = 1; // Default for stereo audio
- float flSurroundOPLOffset = 384.0f;// Default for 384.0
- INT iSampleRate = 44100; // Default for 44100 Hz
- INT iOPLSampleRate = 49716; // Default for 49716 Hz
- INT iResampleQuality = RESAMPLER_QUALITY_MAX; // Default to maximum quality
- INT iAudioBufferSize = 1024; // Default for 1024 samples
- INT iVolume = 100; // Default for 100%
- MUSICTYPE eMusicType = g_fUseMidi ? MUSIC_MIDI : MUSIC_RIX;
- MUSICTYPE eCDType = PAL_HAS_SDLCD ? MUSIC_SDLCD : MUSIC_OGG;
- OPLTYPE eOPLType = OPL_DOSBOX;
- if (gpGlobals == NULL)
- {
- gpGlobals = (LPGLOBALVARS)calloc(1, sizeof(GLOBALVARS));
- if (gpGlobals == NULL)
- {
- return -1;
- }
- }
- #if USE_RIX_EXTRA_INIT
- gpGlobals->pExtraFMRegs = NULL;
- gpGlobals->pExtraFMVals = NULL;
- gpGlobals->dwExtraLength = 0;
- #endif
- if (fp = UTIL_OpenFile("sdlpal.cfg"))
- {
- PAL_LARGE char buf[512];
-
-
-
- while (fgets(buf, 512, fp) != NULL)
- {
- char *p = buf;
-
-
-
- while (*p && isspace(*p)) p++;
-
-
-
- if (*p && *p != '#')
- {
- char *ptr;
- if (ptr = strchr(p, '='))
- {
- char *end = ptr - 1;
- *ptr++ = 0;
-
-
-
- while (isspace(*end) && end >= p) *end-- = 0;
- if (SDL_strcasecmp(p, "CODEPAGE") == 0)
- {
- sscanf(ptr, "%d", &iCodePage);
- }
- else if (SDL_strcasecmp(p, "WORDLENGTH") == 0)
- {
- sscanf(ptr, "%u", &dwWordLength);
- }
- else if (SDL_strcasecmp(p, "EXTRAMAGICDESCLINES") == 0)
- {
- sscanf(ptr, "%u", &dwExtraMagicDescLines);
- }
- else if (SDL_strcasecmp(p, "EXTRAITEMDESCLINES") == 0)
- {
- sscanf(ptr, "%u", &dwExtraItemDescLines);
- }
- else if (SDL_strcasecmp(p, "DOS") == 0)
- {
- sscanf(ptr, "%u", &dwIsDOS);
- }
- else if (SDL_strcasecmp(p, "USEEMBEDDEDFONTS") == 0)
- {
- sscanf(ptr, "%u", &dwUseEmbeddedFonts);
- }
- else if (SDL_strcasecmp(p, "USESURROUNDOPL") == 0)
- {
- sscanf(ptr, "%u", &dwUseSurroundOPL);
- }
- else if (SDL_strcasecmp(p, "STEREO") == 0)
- {
- sscanf(ptr, "%u", &dwUseStereo);
- }
- else if (SDL_strcasecmp(p, "SAMPLERATE") == 0)
- {
- sscanf(ptr, "%d", &iSampleRate);
- if (iSampleRate > PAL_MAX_SAMPLERATE) iSampleRate = PAL_MAX_SAMPLERATE;
- }
- else if (SDL_strcasecmp(p, "OPLSAMPLERATE") == 0)
- {
- sscanf(ptr, "%d", &iOPLSampleRate);
- }
- else if (SDL_strcasecmp(p, "RESAMPLEQUALITY") == 0)
- {
- sscanf(ptr, "%d", &iResampleQuality);
- }
- else if (SDL_strcasecmp(p, "SURROUNDOPLOFFSET") == 0)
- {
- sscanf(ptr, "%f", &flSurroundOPLOffset);
- }
- else if (SDL_strcasecmp(p, "AUDIOBUFFERSIZE") == 0)
- {
- sscanf(ptr, "%d", &iAudioBufferSize);
- if (iAudioBufferSize > 32768)
- iAudioBufferSize = 32768;
- else if (iAudioBufferSize < 2)
- iAudioBufferSize = 2;
- if ((iAudioBufferSize & (iAudioBufferSize - 1)) != 0)
- {
-
- int n = 0;
- while (iAudioBufferSize) { iAudioBufferSize >>= 1; n++; }
- iAudioBufferSize = 1 << (n - 1);
- }
- }
- else if (SDL_strcasecmp(p, "VOLUME") == 0)
- {
- sscanf(ptr, "%d", &iVolume);
- if (iVolume > 100)
- iVolume = 100;
- else if (iVolume < 0)
- iVolume = 0;
- }
- #if USE_RIX_EXTRA_INIT
- else if (SDL_strcasecmp(p, "RIXEXTRAINIT") == 0)
- {
- int n = 1;
- char *p;
- for (p = ptr; *p < *end; p++)
- {
- if (*p == ',')
- n++;
- }
- n &= ~0x1;
- if (n > 0)
- {
- uint32_t *regs = malloc(sizeof(uint32_t) * (n >> 1));
- uint8_t *vals = malloc(sizeof(uint8_t) * (n >> 1));
- uint32_t d, i, v = 1;
- if (regs && vals)
- {
- for (p = ptr, i = 0; *p < *end; p++, i++)
- {
- if (sscanf(p, "%u", ®s[i]) == 0) { v = 0; break; }
- while (*p < *end && *p != ',') p++; p++;
- if (sscanf(p, "%u", &d) == 0) { v = 0; break; }
- while (*p < *end && *p != ',') p++;
- vals[i] = (uint8_t)d;
- }
- if (v)
- {
- gpGlobals->pExtraFMRegs = regs;
- gpGlobals->pExtraFMVals = vals;
- gpGlobals->dwExtraLength = n >> 1;
- }
- else
- {
- free(regs);
- free(vals);
- }
- }
- }
- }
- #endif
- else if (SDL_strcasecmp(p, "CD") == 0)
- {
- char cd_type[32];
- sscanf(ptr, "%31s", cd_type);
- if (PAL_HAS_MP3 && SDL_strcasecmp(cd_type, "MP3") == 0)
- eCDType = MUSIC_MP3;
- else if (PAL_HAS_OGG && SDL_strcasecmp(cd_type, "OGG") == 0)
- eCDType = MUSIC_OGG;
- else if (PAL_HAS_SDLCD && SDL_strcasecmp(cd_type, "RAW") == 0)
- eCDType = MUSIC_SDLCD;
- }
- else if (SDL_strcasecmp(p, "MUSIC") == 0)
- {
- char music_type[32];
- sscanf(ptr, "%31s", music_type);
- if (PAL_HAS_NATIVEMIDI && SDL_strcasecmp(music_type, "MIDI") == 0)
- eMusicType = MUSIC_MIDI;
- else if (PAL_HAS_MP3 && SDL_strcasecmp(music_type, "MP3") == 0)
- eMusicType = MUSIC_MP3;
- else if (PAL_HAS_OGG && SDL_strcasecmp(music_type, "OGG") == 0)
- eMusicType = MUSIC_OGG;
- else if (SDL_strcasecmp(music_type, "RIX") == 0)
- eMusicType = MUSIC_RIX;
- }
- else if (SDL_strcasecmp(p, "OPL") == 0)
- {
- char opl_type[32];
- sscanf(ptr, "%31s", opl_type);
- if (SDL_strcasecmp(opl_type, "DOSBOX") == 0)
- eOPLType = OPL_DOSBOX;
- else if (SDL_strcasecmp(opl_type, "DOSBOXOLD") == 0)
- eOPLType = OPL_DOSBOX_OLD;
- else if (PAL_HAS_MAME && SDL_strcasecmp(opl_type, "MAME") == 0)
- eOPLType = OPL_MAME;
- }
- }
- }
- }
- UTIL_CloseFile(fp);
- }
-
-
-
- gpGlobals->fIsWIN95 = dwIsDOS ? FALSE : TRUE;
- gpGlobals->fUseEmbeddedFonts = dwIsDOS && dwUseEmbeddedFonts ? TRUE : FALSE;
- gpGlobals->fUseSurroundOPL = dwUseStereo && dwUseSurroundOPL ? TRUE : FALSE;
- gpGlobals->iAudioChannels = dwUseStereo ? 2 : 1;
- gpGlobals->iSampleRate = iSampleRate;
- gpGlobals->iOPLSampleRate = iOPLSampleRate;
- gpGlobals->iResampleQuality = iResampleQuality;
- gpGlobals->dSurroundOPLOffset = flSurroundOPLOffset;
- gpGlobals->eMusicType = eMusicType;
- gpGlobals->eCDType = eCDType;
- gpGlobals->eOPLType = eOPLType;
- gpGlobals->iCodePage = iCodePage;
- gpGlobals->dwWordLength = dwWordLength;
- gpGlobals->dwExtraMagicDescLines = dwExtraMagicDescLines;
- gpGlobals->dwExtraItemDescLines = dwExtraItemDescLines;
- gpGlobals->wAudioBufferSize = (WORD)iAudioBufferSize;
- gpGlobals->iVolume = SDL_MIX_MAXVOLUME * iVolume / 100;
-
-
-
- Decompress = gpGlobals->fIsWIN95 ? YJ2_Decompress : YJ1_Decompress;
-
-
-
- gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf");
- gpGlobals->f.fpMGO = UTIL_OpenRequiredFile("mgo.mkf");
- gpGlobals->f.fpBALL = UTIL_OpenRequiredFile("ball.mkf");
- gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf");
- gpGlobals->f.fpF = UTIL_OpenRequiredFile("f.mkf");
- gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf");
- gpGlobals->f.fpRGM = UTIL_OpenRequiredFile("rgm.mkf");
- gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf");
- gpGlobals->lpObjectDesc = gpGlobals->fIsWIN95 ? NULL : PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat"));
- gpGlobals->bCurrentSaveSlot = 1;
- return 0;
- }
- VOID
- PAL_FreeGlobals(
- VOID
- )
- {
- if (gpGlobals != NULL)
- {
-
-
-
- UTIL_CloseFile(gpGlobals->f.fpFBP);
- UTIL_CloseFile(gpGlobals->f.fpMGO);
- UTIL_CloseFile(gpGlobals->f.fpBALL);
- UTIL_CloseFile(gpGlobals->f.fpDATA);
- UTIL_CloseFile(gpGlobals->f.fpF);
- UTIL_CloseFile(gpGlobals->f.fpFIRE);
- UTIL_CloseFile(gpGlobals->f.fpRGM);
- UTIL_CloseFile(gpGlobals->f.fpSSS);
-
-
-
- free(gpGlobals->g.lprgEventObject);
- free(gpGlobals->g.lprgScriptEntry);
- free(gpGlobals->g.lprgStore);
- free(gpGlobals->g.lprgEnemy);
- free(gpGlobals->g.lprgEnemyTeam);
- free(gpGlobals->g.lprgMagic);
- free(gpGlobals->g.lprgBattleField);
- free(gpGlobals->g.lprgLevelUpMagic);
-
-
-
- if (!gpGlobals->fIsWIN95)
- PAL_FreeObjectDesc(gpGlobals->lpObjectDesc);
-
-
-
- free(gpGlobals);
- }
- gpGlobals = NULL;
- }
- static VOID
- PAL_ReadGlobalGameData(
- VOID
- )
- {
- const GAMEDATA *p = &gpGlobals->g;
- LOAD_DATA(p->lprgScriptEntry, p->nScriptEntry * sizeof(SCRIPTENTRY),
- 4, gpGlobals->f.fpSSS);
- LOAD_DATA(p->lprgStore, p->nStore * sizeof(STORE), 0, gpGlobals->f.fpDATA);
- LOAD_DATA(p->lprgEnemy, p->nEnemy * sizeof(ENEMY), 1, gpGlobals->f.fpDATA);
- LOAD_DATA(p->lprgEnemyTeam, p->nEnemyTeam * sizeof(ENEMYTEAM),
- 2, gpGlobals->f.fpDATA);
- LOAD_DATA(p->lprgMagic, p->nMagic * sizeof(MAGIC), 4, gpGlobals->f.fpDATA);
- LOAD_DATA(p->lprgBattleField, p->nBattleField * sizeof(BATTLEFIELD),
- 5, gpGlobals->f.fpDATA);
- LOAD_DATA(p->lprgLevelUpMagic, p->nLevelUpMagic * sizeof(LEVELUPMAGIC_ALL),
- 6, gpGlobals->f.fpDATA);
- LOAD_DATA(p->rgwBattleEffectIndex, sizeof(p->rgwBattleEffectIndex),
- 11, gpGlobals->f.fpDATA);
- PAL_MKFReadChunk((LPBYTE)&(p->EnemyPos), sizeof(p->EnemyPos),
- 13, gpGlobals->f.fpDATA);
- DO_BYTESWAP(&(p->EnemyPos), sizeof(p->EnemyPos));
- PAL_MKFReadChunk((LPBYTE)(p->rgLevelUpExp), sizeof(p->rgLevelUpExp),
- 14, gpGlobals->f.fpDATA);
- DO_BYTESWAP(p->rgLevelUpExp, sizeof(p->rgLevelUpExp));
- }
- static VOID
- PAL_InitGlobalGameData(
- VOID
- )
- {
- int len;
- #define PAL_DOALLOCATE(fp, num, type, lptype, ptr, n) \
- { \
- len = PAL_MKFGetChunkSize(num, fp); \
- ptr = (lptype)malloc(len); \
- n = len / sizeof(type); \
- if (ptr == NULL) \
- { \
- TerminateOnError("PAL_InitGlobalGameData(): Memory allocation error!"); \
- } \
- }
-
-
-
- if (gpGlobals->g.lprgEventObject == NULL)
- {
- PAL_DOALLOCATE(gpGlobals->f.fpSSS, 0, EVENTOBJECT, LPEVENTOBJECT,
- gpGlobals->g.lprgEventObject, gpGlobals->g.nEventObject);
- PAL_DOALLOCATE(gpGlobals->f.fpSSS, 4, SCRIPTENTRY, LPSCRIPTENTRY,
- gpGlobals->g.lprgScriptEntry, gpGlobals->g.nScriptEntry);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 0, STORE, LPSTORE,
- gpGlobals->g.lprgStore, gpGlobals->g.nStore);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 1, ENEMY, LPENEMY,
- gpGlobals->g.lprgEnemy, gpGlobals->g.nEnemy);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 2, ENEMYTEAM, LPENEMYTEAM,
- gpGlobals->g.lprgEnemyTeam, gpGlobals->g.nEnemyTeam);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 4, MAGIC, LPMAGIC,
- gpGlobals->g.lprgMagic, gpGlobals->g.nMagic);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 5, BATTLEFIELD, LPBATTLEFIELD,
- gpGlobals->g.lprgBattleField, gpGlobals->g.nBattleField);
- PAL_DOALLOCATE(gpGlobals->f.fpDATA, 6, LEVELUPMAGIC_ALL, LPLEVELUPMAGIC_ALL,
- gpGlobals->g.lprgLevelUpMagic, gpGlobals->g.nLevelUpMagic);
- PAL_ReadGlobalGameData();
- }
- #undef PAL_DOALLOCATE
- }
- static VOID
- PAL_LoadDefaultGame(
- VOID
- )
- {
- GAMEDATA *p = &gpGlobals->g;
- UINT32 i;
-
-
-
- LOAD_DATA(p->lprgEventObject, p->nEventObject * sizeof(EVENTOBJECT),
- 0, gpGlobals->f.fpSSS);
- PAL_MKFReadChunk((LPBYTE)(p->rgScene), sizeof(p->rgScene), 1, gpGlobals->f.fpSSS);
- DO_BYTESWAP(p->rgScene, sizeof(p->rgScene));
- if (gpGlobals->fIsWIN95)
- {
- PAL_MKFReadChunk((LPBYTE)(p->rgObject), sizeof(p->rgObject), 2, gpGlobals->f.fpSSS);
- DO_BYTESWAP(p->rgObject, sizeof(p->rgObject));
- }
- else
- {
- OBJECT_DOS objects[MAX_OBJECTS];
- PAL_MKFReadChunk((LPBYTE)(objects), sizeof(objects), 2, gpGlobals->f.fpSSS);
- DO_BYTESWAP(objects, sizeof(objects));
-
-
-
- for (i = 0; i < MAX_OBJECTS; i++)
- {
- memcpy(&p->rgObject[i], &objects[i], sizeof(OBJECT_DOS));
- if (i >= OBJECT_ITEM_START && i <= OBJECT_MAGIC_END)
- {
- p->rgObject[i].rgwData[6] = objects[i].rgwData[5];
- p->rgObject[i].rgwData[5] = 0;
- }
- else
- {
- p->rgObject[i].rgwData[6] = 0;
- }
- }
- }
- PAL_MKFReadChunk((LPBYTE)(&(p->PlayerRoles)), sizeof(PLAYERROLES),
- 3, gpGlobals->f.fpDATA);
- DO_BYTESWAP(&(p->PlayerRoles), sizeof(PLAYERROLES));
-
-
-
- gpGlobals->dwCash = 0;
- gpGlobals->wNumMusic = 0;
- gpGlobals->wNumPalette = 0;
- gpGlobals->wNumScene = 1;
- gpGlobals->wCollectValue = 0;
- gpGlobals->fNightPalette = FALSE;
- gpGlobals->wMaxPartyMemberIndex = 0;
- gpGlobals->viewport = PAL_XY(0, 0);
- gpGlobals->wLayer = 0;
- gpGlobals->wChaseRange = 1;
- #ifndef PAL_CLASSIC
- gpGlobals->bBattleSpeed = 2;
- #endif
- memset(gpGlobals->rgInventory, 0, sizeof(gpGlobals->rgInventory));
- memset(gpGlobals->rgPoisonStatus, 0, sizeof(gpGlobals->rgPoisonStatus));
- memset(gpGlobals->rgParty, 0, sizeof(gpGlobals->rgParty));
- memset(gpGlobals->rgTrail, 0, sizeof(gpGlobals->rgTrail));
- memset(&(gpGlobals->Exp), 0, sizeof(gpGlobals->Exp));
- for (i = 0; i < MAX_PLAYER_ROLES; i++)
- {
- gpGlobals->Exp.rgPrimaryExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgHealthExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgMagicExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgAttackExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgMagicPowerExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgDefenseExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgDexterityExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- gpGlobals->Exp.rgFleeExp[i].wLevel = p->PlayerRoles.rgwLevel[i];
- }
- gpGlobals->fEnteringScene = TRUE;
- }
- typedef struct tagSAVEDGAME_COMMON
- {
- WORD wSavedTimes;
- WORD wViewportX, wViewportY;
- WORD nPartyMember;
- WORD wNumScene;
- WORD wPaletteOffset;
- WORD wPartyDirection;
- WORD wNumMusic;
- WORD wNumBattleMusic;
- WORD wNumBattleField;
- WORD wScreenWave;
- WORD wBattleSpeed;
- WORD wCollectValue;
- WORD wLayer;
- WORD wChaseRange;
- WORD wChasespeedChangeCycles;
- WORD nFollower;
- WORD rgwReserved2[3];
- DWORD dwCash;
- PARTY rgParty[MAX_PLAYABLE_PLAYER_ROLES];
- TRAIL rgTrail[MAX_PLAYABLE_PLAYER_ROLES];
- ALLEXPERIENCE Exp;
- PLAYERROLES PlayerRoles;
- POISONSTATUS rgPoisonStatus[MAX_POISONS][MAX_PLAYABLE_PLAYER_ROLES];
- INVENTORY rgInventory[MAX_INVENTORY];
- SCENE rgScene[MAX_SCENES];
- } SAVEDGAME_COMMON, *LPSAVEDGAME_COMMON;
- typedef struct tagSAVEDGAME_DOS
- {
- WORD wSavedTimes;
- WORD wViewportX, wViewportY;
- WORD nPartyMember;
- WORD wNumScene;
- WORD wPaletteOffset;
- WORD wPartyDirection;
- WORD wNumMusic;
- WORD wNumBattleMusic;
- WORD wNumBattleField;
- WORD wScreenWave;
- WORD wBattleSpeed;
- WORD wCollectValue;
- WORD wLayer;
- WORD wChaseRange;
- WORD wChasespeedChangeCycles;
- WORD nFollower;
- WORD rgwReserved2[3];
- DWORD dwCash;
- PARTY rgParty[MAX_PLAYABLE_PLAYER_ROLES];
- TRAIL rgTrail[MAX_PLAYABLE_PLAYER_ROLES];
- ALLEXPERIENCE Exp;
- PLAYERROLES PlayerRoles;
- POISONSTATUS rgPoisonStatus[MAX_POISONS][MAX_PLAYABLE_PLAYER_ROLES];
- INVENTORY rgInventory[MAX_INVENTORY];
- SCENE rgScene[MAX_SCENES];
- OBJECT_DOS rgObject[MAX_OBJECTS];
- EVENTOBJECT rgEventObject[MAX_EVENT_OBJECTS];
- } SAVEDGAME_DOS, *LPSAVEDGAME_DOS;
- typedef struct tagSAVEDGAME_WIN
- {
- WORD wSavedTimes;
- WORD wViewportX, wViewportY;
- WORD nPartyMember;
- WORD wNumScene;
- WORD wPaletteOffset;
- WORD wPartyDirection;
- WORD wNumMusic;
- WORD wNumBattleMusic;
- WORD wNumBattleField;
- WORD wScreenWave;
- WORD wBattleSpeed;
- WORD wCollectValue;
- WORD wLayer;
- WORD wChaseRange;
- WORD wChasespeedChangeCycles;
- WORD nFollower;
- WORD rgwReserved2[3];
- DWORD dwCash;
- PARTY rgParty[MAX_PLAYABLE_PLAYER_ROLES];
- TRAIL rgTrail[MAX_PLAYABLE_PLAYER_ROLES];
- ALLEXPERIENCE Exp;
- PLAYERROLES PlayerRoles;
- POISONSTATUS rgPoisonStatus[MAX_POISONS][MAX_PLAYABLE_PLAYER_ROLES];
- INVENTORY rgInventory[MAX_INVENTORY];
- SCENE rgScene[MAX_SCENES];
- OBJECT rgObject[MAX_OBJECTS];
- EVENTOBJECT rgEventObject[MAX_EVENT_OBJECTS];
- } SAVEDGAME_WIN, *LPSAVEDGAME_WIN;
- static VOID
- PAL_LoadGame_Common(
- const LPSAVEDGAME_COMMON s
- )
- {
- gpGlobals->viewport = PAL_XY(s->wViewportX, s->wViewportY);
- gpGlobals->wMaxPartyMemberIndex = s->nPartyMember;
- gpGlobals->wNumScene = s->wNumScene;
- gpGlobals->fNightPalette = (s->wPaletteOffset != 0);
- gpGlobals->wPartyDirection = s->wPartyDirection;
- gpGlobals->wNumMusic = s->wNumMusic;
- gpGlobals->wNumBattleMusic = s->wNumBattleMusic;
- gpGlobals->wNumBattleField = s->wNumBattleField;
- gpGlobals->wScreenWave = s->wScreenWave;
- gpGlobals->sWaveProgression = 0;
- gpGlobals->wCollectValue = s->wCollectValue;
- gpGlobals->wLayer = s->wLayer;
- gpGlobals->wChaseRange = s->wChaseRange;
- gpGlobals->wChasespeedChangeCycles = s->wChasespeedChangeCycles;
- gpGlobals->nFollower = s->nFollower;
- gpGlobals->dwCash = s->dwCash;
- #ifndef PAL_CLASSIC
- gpGlobals->bBattleSpeed = s->wBattleSpeed;
- if (gpGlobals->bBattleSpeed > 5 || gpGlobals->bBattleSpeed == 0)
- {
- gpGlobals->bBattleSpeed = 2;
- }
- #endif
- memcpy(gpGlobals->rgParty, s->rgParty, sizeof(gpGlobals->rgParty));
- memcpy(gpGlobals->rgTrail, s->rgTrail, sizeof(gpGlobals->rgTrail));
- gpGlobals->Exp = s->Exp;
- gpGlobals->g.PlayerRoles = s->PlayerRoles;
- memset(gpGlobals->rgPoisonStatus, 0, sizeof(gpGlobals->rgPoisonStatus));
- memcpy(gpGlobals->rgInventory, s->rgInventory, sizeof(gpGlobals->rgInventory));
- memcpy(gpGlobals->g.rgScene, s->rgScene, sizeof(gpGlobals->g.rgScene));
- }
- static INT
- PAL_LoadGame_DOS(
- LPCSTR szFileName
- )
- {
- FILE *fp;
- PAL_LARGE SAVEDGAME_DOS s;
- int i;
-
-
-
- fp = fopen(szFileName, "rb");
- if (fp == NULL)
- {
- return -1;
- }
-
-
-
- fread(&s, sizeof(SAVEDGAME_DOS), 1, fp);
- fclose(fp);
-
-
-
- DO_BYTESWAP(&s, sizeof(SAVEDGAME_DOS));
-
-
-
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- s.dwCash = ((s.dwCash >> 16) | (s.dwCash << 16));
- #endif
-
-
-
- PAL_LoadGame_Common((LPSAVEDGAME_COMMON)&s);
-
-
-
- for (i = 0; i < MAX_OBJECTS; i++)
- {
- memcpy(&gpGlobals->g.rgObject[i], &s.rgObject[i], sizeof(OBJECT_DOS));
- if (i >= OBJECT_ITEM_START && i <= OBJECT_MAGIC_END)
- {
- gpGlobals->g.rgObject[i].rgwData[6] = s.rgObject[i].rgwData[5];
- gpGlobals->g.rgObject[i].rgwData[5] = 0;
- }
- else
- {
- gpGlobals->g.rgObject[i].rgwData[6] = 0;
- }
- }
- memcpy(gpGlobals->g.lprgEventObject, s.rgEventObject,
- sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
- gpGlobals->fEnteringScene = FALSE;
- PAL_CompressInventory();
-
-
-
- return 0;
- }
- static INT
- PAL_LoadGame_WIN(
- LPCSTR szFileName
- )
- {
- FILE *fp;
- PAL_LARGE SAVEDGAME_WIN s;
-
-
-
- fp = fopen(szFileName, "rb");
- if (fp == NULL)
- {
- return -1;
- }
-
-
-
- fread(&s, sizeof(SAVEDGAME_WIN), 1, fp);
- fclose(fp);
-
-
-
- DO_BYTESWAP(&s, sizeof(SAVEDGAME_WIN));
-
-
-
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- s.dwCash = ((s.dwCash >> 16) | (s.dwCash << 16));
- #endif
-
-
-
- PAL_LoadGame_Common((LPSAVEDGAME_COMMON)&s);
- memcpy(gpGlobals->g.rgObject, s.rgObject, sizeof(gpGlobals->g.rgObject));
- memcpy(gpGlobals->g.lprgEventObject, s.rgEventObject,
- sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
- gpGlobals->fEnteringScene = FALSE;
- PAL_CompressInventory();
-
-
-
- return 0;
- }
- static INT
- PAL_LoadGame(
- LPCSTR szFileName
- )
- {
- return gpGlobals->fIsWIN95 ? PAL_LoadGame_WIN(szFileName) : PAL_LoadGame_DOS(szFileName);
- }
- static VOID
- PAL_SaveGame_Common(
- const LPSAVEDGAME_COMMON s
- )
- {
- s->wViewportX = PAL_X(gpGlobals->viewport);
- s->wViewportY = PAL_Y(gpGlobals->viewport);
- s->nPartyMember = gpGlobals->wMaxPartyMemberIndex;
- s->wNumScene = gpGlobals->wNumScene;
- s->wPaletteOffset = (gpGlobals->fNightPalette ? 0x180 : 0);
- s->wPartyDirection = gpGlobals->wPartyDirection;
- s->wNumMusic = gpGlobals->wNumMusic;
- s->wNumBattleMusic = gpGlobals->wNumBattleMusic;
- s->wNumBattleField = gpGlobals->wNumBattleField;
- s->wScreenWave = gpGlobals->wScreenWave;
- s->wCollectValue = gpGlobals->wCollectValue;
- s->wLayer = gpGlobals->wLayer;
- s->wChaseRange = gpGlobals->wChaseRange;
- s->wChasespeedChangeCycles = gpGlobals->wChasespeedChangeCycles;
- s->nFollower = gpGlobals->nFollower;
- s->dwCash = gpGlobals->dwCash;
- #ifndef PAL_CLASSIC
- s->wBattleSpeed = gpGlobals->bBattleSpeed;
- #else
- s->wBattleSpeed = 2;
- #endif
- memcpy(s->rgParty, gpGlobals->rgParty, sizeof(gpGlobals->rgParty));
- memcpy(s->rgTrail, gpGlobals->rgTrail, sizeof(gpGlobals->rgTrail));
- s->Exp = gpGlobals->Exp;
- s->PlayerRoles = gpGlobals->g.PlayerRoles;
- memcpy(s->rgPoisonStatus, gpGlobals->rgPoisonStatus, sizeof(gpGlobals->rgPoisonStatus));
- memcpy(s->rgInventory, gpGlobals->rgInventory, sizeof(gpGlobals->rgInventory));
- memcpy(s->rgScene, gpGlobals->g.rgScene, sizeof(gpGlobals->g.rgScene));
- }
- static VOID
- PAL_SaveGame_DOS(
- LPCSTR szFileName,
- WORD wSavedTimes
- )
- {
- FILE *fp;
- PAL_LARGE SAVEDGAME_DOS s;
- UINT32 i;
-
-
-
- PAL_SaveGame_Common((LPSAVEDGAME_COMMON)&s);
-
-
-
- for (i = 0; i < MAX_OBJECTS; i++)
- {
- memcpy(&s.rgObject[i], &gpGlobals->g.rgObject[i], sizeof(OBJECT_DOS));
- if (i >= OBJECT_ITEM_START && i <= OBJECT_MAGIC_END)
- {
- s.rgObject[i].rgwData[5] = gpGlobals->g.rgObject[i].rgwData[6];
- }
- }
- memcpy(s.rgEventObject, gpGlobals->g.lprgEventObject,
- sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
- s.wSavedTimes = wSavedTimes;
-
-
-
- DO_BYTESWAP(&s, sizeof(SAVEDGAME));
-
-
-
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- s.dwCash = ((s.dwCash >> 16) | (s.dwCash << 16));
- #endif
-
-
-
- fp = fopen(szFileName, "wb");
- if (fp == NULL)
- {
- return;
- }
- i = PAL_MKFGetChunkSize(0, gpGlobals->f.fpSSS);
- i += sizeof(SAVEDGAME_DOS) - sizeof(EVENTOBJECT) * MAX_EVENT_OBJECTS;
- fwrite(&s, i, 1, fp);
- fclose(fp);
- }
- static VOID
- PAL_SaveGame_WIN(
- LPCSTR szFileName,
- WORD wSavedTimes
- )
- {
- FILE *fp;
- PAL_LARGE SAVEDGAME_WIN s;
- UINT32 i;
-
-
-
- PAL_SaveGame_Common((LPSAVEDGAME_COMMON)&s);
- memcpy(s.rgObject, gpGlobals->g.rgObject, sizeof(gpGlobals->g.rgObject));
- memcpy(s.rgEventObject, gpGlobals->g.lprgEventObject,
- sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
- s.wSavedTimes = wSavedTimes;
-
-
-
- DO_BYTESWAP(&s, sizeof(SAVEDGAME));
-
-
-
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- s.dwCash = ((s.dwCash >> 16) | (s.dwCash << 16));
- #endif
-
-
-
- fp = fopen(szFileName, "wb");
- if (fp == NULL)
- {
- return;
- }
- i = PAL_MKFGetChunkSize(0, gpGlobals->f.fpSSS);
- i += sizeof(SAVEDGAME_WIN) - sizeof(EVENTOBJECT) * MAX_EVENT_OBJECTS;
- fwrite(&s, i, 1, fp);
- fclose(fp);
- }
- VOID
- PAL_SaveGame(
- LPCSTR szFileName,
- WORD wSavedTimes
- )
- {
- if (gpGlobals->fIsWIN95)
- PAL_SaveGame_WIN(szFileName, wSavedTimes);
- else
- PAL_SaveGame_DOS(szFileName, wSavedTimes);
- }
- VOID
- PAL_InitGameData(
- INT iSaveSlot
- )
- {
- PAL_InitGlobalGameData();
- gpGlobals->bCurrentSaveSlot = (BYTE)iSaveSlot;
-
-
-
- if (iSaveSlot == 0 || PAL_LoadGame(va("%s%d%s", PAL_SAVE_PREFIX, iSaveSlot, ".rpg")) != 0)
- {
-
-
-
- PAL_LoadDefaultGame();
- }
- gpGlobals->fGameStart = TRUE;
- gpGlobals->fNeedToFadeIn = FALSE;
- gpGlobals->iCurInvMenuItem = 0;
- gpGlobals->fInBattle = FALSE;
- memset(gpGlobals->rgPlayerStatus, 0, sizeof(gpGlobals->rgPlayerStatus));
- PAL_UpdateEquipments();
- }
- BOOL
- PAL_AddItemToInventory(
- WORD wObjectID,
- INT iNum
- )
- {
- int index;
- BOOL fFound;
- if (wObjectID == 0)
- {
- return FALSE;
- }
- if (iNum == 0)
- {
- iNum = 1;
- }
- index = 0;
- fFound = FALSE;
-
-
-
- while (index < MAX_INVENTORY)
- {
- if (gpGlobals->rgInventory[index].wItem == wObjectID)
- {
- fFound = TRUE;
- break;
- }
- else if (gpGlobals->rgInventory[index].wItem == 0)
- {
- break;
- }
- index++;
- }
- if (iNum > 0)
- {
-
-
-
- if (index >= MAX_INVENTORY)
- {
-
-
-
- return FALSE;
- }
- if (fFound)
- {
- gpGlobals->rgInventory[index].nAmount += iNum;
- if (gpGlobals->rgInventory[index].nAmount > 99)
- {
-
-
-
- gpGlobals->rgInventory[index].nAmount = 99;
- }
- }
- else
- {
- gpGlobals->rgInventory[index].wItem = wObjectID;
- if (iNum > 99)
- {
- iNum = 99;
- }
- gpGlobals->rgInventory[index].nAmount = iNum;
- }
- return TRUE;
- }
- else
- {
-
-
-
- if (fFound)
- {
- iNum *= -1;
- if (gpGlobals->rgInventory[index].nAmount < iNum)
- {
-
-
-
- gpGlobals->rgInventory[index].nAmount = 0;
- return FALSE;
- }
- gpGlobals->rgInventory[index].nAmount -= iNum;
- return TRUE;
- }
- return FALSE;
- }
- }
- INT
- PAL_GetItemAmount(
- WORD wItem
- )
- {
- int i;
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (gpGlobals->rgInventory[i].wItem == 0)
- {
- break;
- }
- if (gpGlobals->rgInventory[i].wItem == wItem)
- {
- return gpGlobals->rgInventory[i].nAmount;
- }
- }
- return 0;
- }
- VOID
- PAL_CompressInventory(
- VOID
- )
- {
- int i, j;
- j = 0;
- for (i = 0; i < MAX_INVENTORY; i++)
- {
- if (gpGlobals->rgInventory[i].wItem == 0)
- {
- break;
- }
- if (gpGlobals->rgInventory[i].nAmount > 0)
- {
- gpGlobals->rgInventory[j] = gpGlobals->rgInventory[i];
- j++;
- }
- }
- for (; j < MAX_INVENTORY; j++)
- {
- gpGlobals->rgInventory[j].nAmount = 0;
- gpGlobals->rgInventory[j].nAmountInUse = 0;
- gpGlobals->rgInventory[j].wItem = 0;
- }
- }
- BOOL
- PAL_IncreaseHPMP(
- WORD wPlayerRole,
- SHORT sHP,
- SHORT sMP
- )
- {
- BOOL fSuccess = FALSE;
-
-
-
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] > 0)
- {
-
-
-
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] += sHP;
- if ((SHORT)(gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole]) < 0)
- {
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] = 0;
- }
- else if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] >
- gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole])
- {
- gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] =
- gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole];
- }
-
-
-
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] += sMP;
- if ((SHORT)(gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole]) < 0)
- {
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] = 0;
- }
- else if (gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] >
- gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole])
- {
- gpGlobals->g.PlayerRoles.rgwMP[wPlayerRole] =
- gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole];
- }
- fSuccess = TRUE;
- }
- return fSuccess;
- }
- VOID
- PAL_UpdateEquipments(
- VOID
- )
- {
- int i, j;
- WORD w;
- memset(&(gpGlobals->rgEquipmentEffect), 0, sizeof(gpGlobals->rgEquipmentEffect));
- for (i = 0; i < MAX_PLAYER_ROLES; i++)
- {
- for (j = 0; j < MAX_PLAYER_EQUIPMENTS; j++)
- {
- w = gpGlobals->g.PlayerRoles.rgwEquipment[j][i];
- if (w != 0)
- {
- gpGlobals->g.rgObject[w].item.wScriptOnEquip =
- PAL_RunTriggerScript(gpGlobals->g.rgObject[w].item.wScriptOnEquip, (WORD)i);
- }
- }
- }
- }
- VOID
- PAL_RemoveEquipmentEffect(
- WORD wPlayerRole,
- WORD wEquipPart
- )
- {
- WORD *p;
- int i, j;
- p = (WORD *)(&gpGlobals->rgEquipmentEffect[wEquipPart]);
- for (i = 0; i < sizeof(PLAYERROLES) / sizeof(PLAYERS); i++)
- {
- p[i * MAX_PLAYER_ROLES + wPlayerRole] = 0;
- }
-
-
-
- if (wEquipPart == kBodyPartHand)
- {
-
-
-
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusDualAttack] = 0;
- }
- else if (wEquipPart == kBodyPartWear)
- {
-
-
-
- for (i = 0; i <= (short)gpGlobals->wMaxPartyMemberIndex; i++)
- {
- if (gpGlobals->rgParty[i].wPlayerRole == wPlayerRole)
- {
- wPlayerRole = i;
- break;
- }
- }
- if (i <= (short)gpGlobals->wMaxPartyMemberIndex)
- {
- j = 0;
- for (i = 0; i < MAX_POISONS; i++)
- {
- WORD w = gpGlobals->rgPoisonStatus[i][wPlayerRole].wPoisonID;
- if (w == 0)
- {
- break;
- }
- if (gpGlobals->g.rgObject[w].poison.wPoisonLevel < 99)
- {
- gpGlobals->rgPoisonStatus[j][wPlayerRole] =
- gpGlobals->rgPoisonStatus[i][wPlayerRole];
- j++;
- }
- }
- while (j < MAX_POISONS)
- {
- gpGlobals->rgPoisonStatus[j][wPlayerRole].wPoisonID = 0;
- gpGlobals->rgPoisonStatus[j][wPlayerRole].wPoisonScript = 0;
- j++;
- }
- }
- }
- }
- VOID
- PAL_AddPoisonForPlayer(
- WORD wPlayerRole,
- WORD wPoisonID
- )
- {
- int i, index;
- WORD w;
- for (index = 0; index <= gpGlobals->wMaxPartyMemberIndex; index++)
- {
- if (gpGlobals->rgParty[index].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (index > gpGlobals->wMaxPartyMemberIndex)
- {
- return;
- }
- for (i = 0; i < MAX_POISONS; i++)
- {
- w = gpGlobals->rgPoisonStatus[i][index].wPoisonID;
- if (w == 0)
- {
- break;
- }
- if (w == wPoisonID)
- {
- return;
- }
- }
- if (i < MAX_POISONS)
- {
- gpGlobals->rgPoisonStatus[i][index].wPoisonID = wPoisonID;
- gpGlobals->rgPoisonStatus[i][index].wPoisonScript =
- gpGlobals->g.rgObject[wPoisonID].poison.wPlayerScript;
- }
- }
- VOID
- PAL_CurePoisonByKind(
- WORD wPlayerRole,
- WORD wPoisonID
- )
- {
- int i, index;
- for (index = 0; index <= gpGlobals->wMaxPartyMemberIndex; index++)
- {
- if (gpGlobals->rgParty[index].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (index > gpGlobals->wMaxPartyMemberIndex)
- {
- return;
- }
- for (i = 0; i < MAX_POISONS; i++)
- {
- if (gpGlobals->rgPoisonStatus[i][index].wPoisonID == wPoisonID)
- {
- gpGlobals->rgPoisonStatus[i][index].wPoisonID = 0;
- gpGlobals->rgPoisonStatus[i][index].wPoisonScript = 0;
- }
- }
- }
- VOID
- PAL_CurePoisonByLevel(
- WORD wPlayerRole,
- WORD wMaxLevel
- )
- {
- int i, index;
- WORD w;
- for (index = 0; index <= gpGlobals->wMaxPartyMemberIndex; index++)
- {
- if (gpGlobals->rgParty[index].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (index > gpGlobals->wMaxPartyMemberIndex)
- {
- return;
- }
- for (i = 0; i < MAX_POISONS; i++)
- {
- w = gpGlobals->rgPoisonStatus[i][index].wPoisonID;
- if (gpGlobals->g.rgObject[w].poison.wPoisonLevel <= wMaxLevel)
- {
- gpGlobals->rgPoisonStatus[i][index].wPoisonID = 0;
- gpGlobals->rgPoisonStatus[i][index].wPoisonScript = 0;
- }
- }
- }
- BOOL
- PAL_IsPlayerPoisonedByLevel(
- WORD wPlayerRole,
- WORD wMinLevel
- )
- {
- int i, index;
- WORD w;
- for (index = 0; index <= gpGlobals->wMaxPartyMemberIndex; index++)
- {
- if (gpGlobals->rgParty[index].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (index > gpGlobals->wMaxPartyMemberIndex)
- {
- return FALSE;
- }
- for (i = 0; i < MAX_POISONS; i++)
- {
- w = gpGlobals->rgPoisonStatus[i][index].wPoisonID;
- w = gpGlobals->g.rgObject[w].poison.wPoisonLevel;
- if (w >= 99)
- {
-
-
-
- continue;
- }
- if (w >= wMinLevel)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- BOOL
- PAL_IsPlayerPoisonedByKind(
- WORD wPlayerRole,
- WORD wPoisonID
- )
- {
- int i, index;
- for (index = 0; index <= gpGlobals->wMaxPartyMemberIndex; index++)
- {
- if (gpGlobals->rgParty[index].wPlayerRole == wPlayerRole)
- {
- break;
- }
- }
- if (index > gpGlobals->wMaxPartyMemberIndex)
- {
- return FALSE;
- }
- for (i = 0; i < MAX_POISONS; i++)
- {
- if (gpGlobals->rgPoisonStatus[i][index].wPoisonID == wPoisonID)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
- WORD
- PAL_GetPlayerAttackStrength(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwAttackStrength[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwAttackStrength[wPlayerRole];
- }
- return w;
- }
- WORD
- PAL_GetPlayerMagicStrength(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwMagicStrength[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwMagicStrength[wPlayerRole];
- }
- return w;
- }
- WORD
- PAL_GetPlayerDefense(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwDefense[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwDefense[wPlayerRole];
- }
- return w;
- }
- WORD
- PAL_GetPlayerDexterity(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwDexterity[wPlayerRole];
- #ifdef PAL_CLASSIC
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- #else
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS - 1; i++)
- #endif
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwDexterity[wPlayerRole];
- }
- return w;
- }
- WORD
- PAL_GetPlayerFleeRate(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwFleeRate[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwFleeRate[wPlayerRole];
- }
- return w;
- }
- WORD
- PAL_GetPlayerPoisonResistance(
- WORD wPlayerRole
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwPoisonResistance[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwPoisonResistance[wPlayerRole];
- }
- if (w > 100)
- {
- w = 100;
- }
- return w;
- }
- WORD
- PAL_GetPlayerElementalResistance(
- WORD wPlayerRole,
- INT iAttrib
- )
- {
- WORD w;
- int i;
- w = gpGlobals->g.PlayerRoles.rgwElementalResistance[iAttrib][wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- w += gpGlobals->rgEquipmentEffect[i].rgwElementalResistance[iAttrib][wPlayerRole];
- }
- if (w > 100)
- {
- w = 100;
- }
- return w;
- }
- WORD
- PAL_GetPlayerBattleSprite(
- WORD wPlayerRole
- )
- {
- int i;
- WORD w;
- w = gpGlobals->g.PlayerRoles.rgwSpriteNumInBattle[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- if (gpGlobals->rgEquipmentEffect[i].rgwSpriteNumInBattle[wPlayerRole] != 0)
- {
- w = gpGlobals->rgEquipmentEffect[i].rgwSpriteNumInBattle[wPlayerRole];
- }
- }
- return w;
- }
- WORD
- PAL_GetPlayerCooperativeMagic(
- WORD wPlayerRole
- )
- {
- int i;
- WORD w;
- w = gpGlobals->g.PlayerRoles.rgwCooperativeMagic[wPlayerRole];
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- if (gpGlobals->rgEquipmentEffect[i].rgwCooperativeMagic[wPlayerRole] != 0)
- {
- w = gpGlobals->rgEquipmentEffect[i].rgwCooperativeMagic[wPlayerRole];
- }
- }
- return w;
- }
- BOOL
- PAL_PlayerCanAttackAll(
- WORD wPlayerRole
- )
- {
- int i;
- BOOL f;
- f = FALSE;
- for (i = 0; i <= MAX_PLAYER_EQUIPMENTS; i++)
- {
- if (gpGlobals->rgEquipmentEffect[i].rgwAttackAll[wPlayerRole] != 0)
- {
- f = TRUE;
- break;
- }
- }
- return f;
- }
- BOOL
- PAL_AddMagic(
- WORD wPlayerRole,
- WORD wMagic
- )
- {
- int i;
- for (i = 0; i < MAX_PLAYER_MAGICS; i++)
- {
- if (gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] == wMagic)
- {
-
-
-
- return FALSE;
- }
- }
- for (i = 0; i < MAX_PLAYER_MAGICS; i++)
- {
- if (gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] == 0)
- {
- break;
- }
- }
- if (i >= MAX_PLAYER_MAGICS)
- {
-
-
-
- return FALSE;
- }
- gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] = wMagic;
- return TRUE;
- }
- VOID
- PAL_RemoveMagic(
- WORD wPlayerRole,
- WORD wMagic
- )
- {
- int i;
- for (i = 0; i < MAX_PLAYER_MAGICS; i++)
- {
- if (gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] == wMagic)
- {
- gpGlobals->g.PlayerRoles.rgwMagic[i][wPlayerRole] = 0;
- break;
- }
- }
- }
- VOID
- PAL_SetPlayerStatus(
- WORD wPlayerRole,
- WORD wStatusID,
- WORD wNumRound
- )
- {
- #ifndef PAL_CLASSIC
- if (wStatusID == kStatusSlow &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusHaste] > 0)
- {
-
-
-
- PAL_RemovePlayerStatus(wPlayerRole, kStatusHaste);
- return;
- }
- if (wStatusID == kStatusHaste &&
- gpGlobals->rgPlayerStatus[wPlayerRole][kStatusSlow] > 0)
- {
-
-
-
- PAL_RemovePlayerStatus(wPlayerRole, kStatusSlow);
- return;
- }
- #endif
- switch (wStatusID)
- {
- case kStatusConfused:
- case kStatusSleep:
- case kStatusSilence:
- #ifdef PAL_CLASSIC
- case kStatusParalyzed:
- #else
- case kStatusSlow:
- #endif
-
-
-
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] != 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] == 0)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] = wNumRound;
- }
- break;
- case kStatusPuppet:
-
-
-
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] == 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] < wNumRound)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] = wNumRound;
- }
- break;
- case kStatusBravery:
- case kStatusProtect:
- case kStatusDualAttack:
- case kStatusHaste:
-
-
-
- if (gpGlobals->g.PlayerRoles.rgwHP[wPlayerRole] != 0 &&
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] < wNumRound)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] = wNumRound;
- }
- break;
- default:
- assert(FALSE);
- break;
- }
- }
- VOID
- PAL_RemovePlayerStatus(
- WORD wPlayerRole,
- WORD wStatusID
- )
- {
-
-
-
- if (gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] <= 999)
- {
- gpGlobals->rgPlayerStatus[wPlayerRole][wStatusID] = 0;
- }
- }
- VOID
- PAL_ClearAllPlayerStatus(
- VOID
- )
- {
- int i, j;
- for (i = 0; i < MAX_PLAYER_ROLES; i++)
- {
- for (j = 0; j < kStatusAll; j++)
- {
-
-
-
- if (gpGlobals->rgPlayerStatus[i][j] <= 999)
- {
- gpGlobals->rgPlayerStatus[i][j] = 0;
- }
- }
- }
- }
- VOID
- PAL_PlayerLevelUp(
- WORD wPlayerRole,
- WORD wNumLevel
- )
- {
- WORD i;
-
-
-
- gpGlobals->g.PlayerRoles.rgwLevel[wPlayerRole] += wNumLevel;
- if (gpGlobals->g.PlayerRoles.rgwLevel[wPlayerRole] > MAX_LEVELS)
- {
- gpGlobals->g.PlayerRoles.rgwLevel[wPlayerRole] = MAX_LEVELS;
- }
- for (i = 0; i < wNumLevel; i++)
- {
-
-
-
- gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole] += 10 + RandomLong(0, 8);
- gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole] += 8 + RandomLong(0, 6);
- gpGlobals->g.PlayerRoles.rgwAttackStrength[wPlayerRole] += 4 + RandomLong(0, 1);
- gpGlobals->g.PlayerRoles.rgwMagicStrength[wPlayerRole] += 4 + RandomLong(0, 1);
- gpGlobals->g.PlayerRoles.rgwDefense[wPlayerRole] += 2 + RandomLong(0, 1);
- gpGlobals->g.PlayerRoles.rgwDexterity[wPlayerRole] += 2 + RandomLong(0, 1);
- gpGlobals->g.PlayerRoles.rgwFleeRate[wPlayerRole] += 2;
- }
- #define STAT_LIMIT(t) { if ((t) > 999) (t) = 999; }
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwMaxHP[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwMaxMP[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwAttackStrength[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwMagicStrength[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwDefense[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwDexterity[wPlayerRole]);
- STAT_LIMIT(gpGlobals->g.PlayerRoles.rgwFleeRate[wPlayerRole]);
- #undef STAT_LIMIT
-
-
-
- gpGlobals->Exp.rgPrimaryExp[wPlayerRole].wExp = 0;
- gpGlobals->Exp.rgPrimaryExp[wPlayerRole].wLevel =
- gpGlobals->g.PlayerRoles.rgwLevel[wPlayerRole];
- }
|