diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 6c1f03162..2217a4448 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -757,7 +757,7 @@ static void RightMouseDown() } } -static void diablo_pause_game() +void diablo_pause_game() { if (gbMaxPlayers <= 1) { if (PauseMode) { diff --git a/Source/diablo.h b/Source/diablo.h index b1285a814..153d9b48e 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -54,6 +54,7 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer); void diablo_quit(int exitStatus); int DiabloMain(int argc, char **argv); BOOL TryIconCurs(); +void diablo_pause_game(); BOOL PressEscKey(); void DisableInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void GM_Game(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/Source/doom.h b/Source/doom.h index 1c489dea4..d079002f4 100644 --- a/Source/doom.h +++ b/Source/doom.h @@ -15,6 +15,7 @@ extern "C" { extern DIABOOL doomflag; extern int DoomQuestState; +int doom_get_frame_from_time(); void doom_init(); void doom_close(); void doom_draw(); diff --git a/Source/effects.cpp b/Source/effects.cpp index 3d93d1494..b477811e9 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1162,7 +1162,7 @@ void FreeMonsterSnd() } } -static BOOL calc_snd_position(int x, int y, int *plVolume, int *plPan) +BOOL calc_snd_position(int x, int y, int *plVolume, int *plPan) { int pan, volume; diff --git a/Source/effects.h b/Source/effects.h index f6b5c9f30..8e6540293 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -19,6 +19,7 @@ BOOL effect_is_playing(int nSFX); void stream_stop(); void InitMonsterSND(int monst); void FreeMonsterSnd(); +BOOL calc_snd_position(int x, int y, int *plVolume, int *plPan); void PlayEffect(int i, int mode); void PlaySFX(int psfx); void PlaySfxLoc(int psfx, int x, int y); diff --git a/Source/inv.h b/Source/inv.h index 5ef6b8dc4..d7835d0c2 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -18,17 +18,13 @@ extern const InvXY InvRect[73]; void FreeInvGFX(); void InitInv(); -void InvDrawSlotBack(int X, int Y, int W, int H); void DrawInv(); void DrawInvBelt(); BOOL AutoPlace(int pnum, int ii, int sx, int sy, BOOL saveflag); BOOL SpecialAutoPlace(int pnum, int ii, int sx, int sy, BOOL saveflag); BOOL GoldAutoPlace(int pnum); -BOOL WeaponAutoPlace(int pnum); int SwapItem(ItemStruct *a, ItemStruct *b); -void CheckInvPaste(int pnum, int mx, int my); void CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId); -void CheckInvCut(int pnum, int mx, int my); void inv_update_rem_item(int pnum, BYTE iv); void RemoveInvItem(int pnum, int iv); #ifdef HELLFIRE @@ -38,8 +34,6 @@ void RemoveSpdBarItem(int pnum, int iv); void CheckInvItem(); void CheckInvScrn(); void CheckItemStats(int pnum); -void CheckBookLevel(int pnum); -void CheckQuestItem(int pnum); void InvGetItem(int pnum, int ii); void AutoGetItem(int pnum, int ii); int FindGetItem(int idx, WORD ci, int iseed); @@ -58,7 +52,6 @@ void RemoveScroll(int pnum); BOOL UseScroll(); void UseStaffCharge(int pnum); BOOL UseStaff(); -void StartGoldDrop(); BOOL UseInvItem(int pnum, int cii); void DoTelekinesis(); int CalculateGold(int pnum); diff --git a/Source/items.cpp b/Source/items.cpp index 7298e6051..cf04dea85 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -494,31 +494,6 @@ int items_get_currlevel() return lvl; } - -void items_42390F() -{ - int x, y, id; - - x = random_(12, 80) + 16; - y = random_(12, 80) + 16; - while (!ItemPlace(x, y)) { - x = random_(12, 80) + 16; - y = random_(12, 80) + 16; - } - switch (currlevel) { - case 22: - id = IDI_NOTE2; - break; - case 23: - id = IDI_NOTE3; - break; - default: - id = IDI_NOTE1; - break; - } - SpawnQuestItem(id, x, y, 0, 1); -} - #endif void InitItemGFX() @@ -600,6 +575,32 @@ void AddInitItems() } } +#ifdef HELLFIRE +static void items_42390F() +{ + int x, y, id; + + x = random_(12, 80) + 16; + y = random_(12, 80) + 16; + while (!ItemPlace(x, y)) { + x = random_(12, 80) + 16; + y = random_(12, 80) + 16; + } + switch (currlevel) { + case 22: + id = IDI_NOTE2; + break; + case 23: + id = IDI_NOTE3; + break; + default: + id = IDI_NOTE1; + break; + } + SpawnQuestItem(id, x, y, 0, 1); +} +#endif + void InitItems() { int i; @@ -1210,6 +1211,20 @@ void CalcSelfItems(int pnum) } while (changeflag); } +static BOOL ItemMinStats(PlayerStruct *p, ItemStruct *x) +{ + if (p->_pMagic < x->_iMinMag) + return FALSE; + + if (p->_pStrength < x->_iMinStr) + return FALSE; + + if (p->_pDexterity < x->_iMinDex) + return FALSE; + + return TRUE; +} + void CalcPlrItemMin(int pnum) { PlayerStruct *p; @@ -1234,20 +1249,6 @@ void CalcPlrItemMin(int pnum) } } -BOOL ItemMinStats(PlayerStruct *p, ItemStruct *x) -{ - if (p->_pMagic < x->_iMinMag) - return FALSE; - - if (p->_pStrength < x->_iMinStr) - return FALSE; - - if (p->_pDexterity < x->_iMinDex) - return FALSE; - - return TRUE; -} - void CalcPlrBookVals(int p) { int i, slvl; @@ -3517,28 +3518,7 @@ void CheckIdentify(int pnum, int cii) SetCursor_(CURSOR_HAND); } -void DoRepair(int pnum, int cii) -{ - PlayerStruct *p; - ItemStruct *pi; - - p = &plr[pnum]; - PlaySfxLoc(IS_REPAIR, p->_px, p->_py); - - if (cii >= NUM_INVLOC) { - pi = &p->InvList[cii - NUM_INVLOC]; - } else { - pi = &p->InvBody[cii]; - } - - RepairItem(pi, p->_pLevel); - CalcPlrInv(pnum, TRUE); - - if (pnum == myplr) - SetCursor_(CURSOR_HAND); -} - -void RepairItem(ItemStruct *i, int lvl) +static void RepairItem(ItemStruct *i, int lvl) { int rep, d; @@ -3569,6 +3549,42 @@ void RepairItem(ItemStruct *i, int lvl) i->_iDurability = i->_iMaxDur; } +void DoRepair(int pnum, int cii) +{ + PlayerStruct *p; + ItemStruct *pi; + + p = &plr[pnum]; + PlaySfxLoc(IS_REPAIR, p->_px, p->_py); + + if (cii >= NUM_INVLOC) { + pi = &p->InvList[cii - NUM_INVLOC]; + } else { + pi = &p->InvBody[cii]; + } + + RepairItem(pi, p->_pLevel); + CalcPlrInv(pnum, TRUE); + + if (pnum == myplr) + SetCursor_(CURSOR_HAND); +} + +static void RechargeItem(ItemStruct *i, int r) +{ + if (i->_iCharges != i->_iMaxCharges) { + do { + i->_iMaxCharges--; + if (i->_iMaxCharges == 0) { + return; + } + i->_iCharges += r; + } while (i->_iCharges < i->_iMaxCharges); + if (i->_iCharges > i->_iMaxCharges) + i->_iCharges = i->_iMaxCharges; + } +} + void DoRecharge(int pnum, int cii) { PlayerStruct *p; @@ -3593,21 +3609,7 @@ void DoRecharge(int pnum, int cii) } #ifdef HELLFIRE -void DoOil(int pnum, int cii) -{ - PlayerStruct *p = &plr[pnum]; - - if (cii >= NUM_INVLOC || cii == INVLOC_HEAD || (cii > INVLOC_AMULET && cii <= INVLOC_CHEST)) { - if (OilItem(&p->InvBody[cii], p)) { - CalcPlrInv(pnum, TRUE); - if (pnum == myplr) { - SetCursor_(CURSOR_HAND); - } - } - } -} - -BOOL OilItem(ItemStruct *x, PlayerStruct *p) +static BOOL OilItem(ItemStruct *x, PlayerStruct *p) { int dur, r; @@ -3727,21 +3729,20 @@ BOOL OilItem(ItemStruct *x, PlayerStruct *p) return TRUE; } -#endif -void RechargeItem(ItemStruct *i, int r) +void DoOil(int pnum, int cii) { - if (i->_iCharges != i->_iMaxCharges) { - do { - i->_iMaxCharges--; - if (i->_iMaxCharges == 0) { - return; + PlayerStruct *p = &plr[pnum]; + + if (cii >= NUM_INVLOC || cii == INVLOC_HEAD || (cii > INVLOC_AMULET && cii <= INVLOC_CHEST)) { + if (OilItem(&p->InvBody[cii], p)) { + CalcPlrInv(pnum, TRUE); + if (pnum == myplr) { + SetCursor_(CURSOR_HAND); } - i->_iCharges += r; - } while (i->_iCharges < i->_iMaxCharges); - if (i->_iCharges > i->_iMaxCharges) - i->_iCharges = i->_iMaxCharges; + } } } +#endif void PrintItemOil(char IDidx) { @@ -4902,7 +4903,7 @@ int RndPremiumItem(int minlvl, int maxlvl) return ril[random_(50, ri)] + 1; } -void SpawnOnePremium(int i, int plvl) +static void SpawnOnePremium(int i, int plvl) { int itype; ItemStruct holditem; @@ -5635,6 +5636,20 @@ void CreateMagicWeapon(int x, int y, int imisc, int icurs, BOOL sendmsg, BOOL de } } +static void NextItemRecord(int i) +{ + gnNumGetRecords--; + + if (gnNumGetRecords == 0) { + return; + } + + itemrecord[i].dwTimestamp = itemrecord[gnNumGetRecords].dwTimestamp; + itemrecord[i].nSeed = itemrecord[gnNumGetRecords].nSeed; + itemrecord[i].wCI = itemrecord[gnNumGetRecords].wCI; + itemrecord[i].nIndex = itemrecord[gnNumGetRecords].nIndex; +} + BOOL GetItemRecord(int nSeed, WORD wCI, int nIndex) { int i; @@ -5654,20 +5669,6 @@ BOOL GetItemRecord(int nSeed, WORD wCI, int nIndex) return TRUE; } -void NextItemRecord(int i) -{ - gnNumGetRecords--; - - if (gnNumGetRecords == 0) { - return; - } - - itemrecord[i].dwTimestamp = itemrecord[gnNumGetRecords].dwTimestamp; - itemrecord[i].nSeed = itemrecord[gnNumGetRecords].nSeed; - itemrecord[i].wCI = itemrecord[gnNumGetRecords].wCI; - itemrecord[i].nIndex = itemrecord[gnNumGetRecords].nIndex; -} - void SetItemRecord(int nSeed, WORD wCI, int nIndex) { DWORD dwTicks; diff --git a/Source/items.h b/Source/items.h index ea12ff6e9..64c4eb013 100644 --- a/Source/items.h +++ b/Source/items.h @@ -15,20 +15,16 @@ extern "C" { extern int itemactive[MAXITEMS]; extern BOOL uitemflag; extern int itemavail[MAXITEMS]; -extern ItemStruct curruitem; extern ItemGetRecordStruct itemrecord[MAXITEMS]; extern ItemStruct item[MAXITEMS + 1]; -extern BOOL itemhold[3][3]; #ifdef HELLFIRE extern CornerStoneStruct CornerStone; #endif -extern BYTE *itemanims[ITEMTYPES]; extern BOOL UniqueItemFlag[128]; #ifdef HELLFIRE extern int auricGold; #endif extern int numitems; -extern int gnNumGetRecords; #ifdef HELLFIRE int items_4231CA(int i); @@ -41,63 +37,29 @@ int items_42342E(int i); int items_4234B2(int i); int items_423518(int i); int items_42357E(int i); -void items_42390F(); -int items_get_currlevel(); #endif void InitItemGFX(); -BOOL ItemPlace(int xp, int yp); -void AddInitItems(); void InitItems(); void CalcPlrItemVals(int p, BOOL Loadgfx); void CalcPlrScrolls(int p); void CalcPlrStaff(int p); -void CalcSelfItems(int pnum); -void CalcPlrItemMin(int pnum); -BOOL ItemMinStats(PlayerStruct *p, ItemStruct *x); -void CalcPlrBookVals(int p); void CalcPlrInv(int p, BOOL Loadgfx); void SetPlrHandItem(ItemStruct *h, int idata); void GetPlrHandSeed(ItemStruct *h); void GetGoldSeed(int pnum, ItemStruct *h); -void SetPlrHandSeed(ItemStruct *h, int iseed); void SetPlrHandGoldCurs(ItemStruct *h); void CreatePlrItems(int p); BOOL ItemSpaceOk(int i, int j); -BOOL GetItemSpace(int x, int y, char inum); -void GetSuperItemSpace(int x, int y, char inum); void GetSuperItemLoc(int x, int y, int *xx, int *yy); -void CalcItemValue(int i); -void GetBookSpell(int i, int lvl); -void GetStaffPower(int i, int lvl, int bs, BOOL onlygood); -void GetStaffSpell(int i, int lvl, BOOL onlygood); void GetItemAttrs(int i, int idata, int lvl); -int RndPL(int param1, int param2); -int PLVal(int pv, int p1, int p2, int minv, int maxv); void SaveItemPower(int i, int power, int param1, int param2, int minval, int maxval, int multval); void GetItemPower(int i, int minlvl, int maxlvl, int flgs, BOOL onlygood); -#ifdef HELLFIRE -void GetItemBonus(int i, int idata, int minlvl, int maxlvl, BOOL onlygood, BOOLEAN allowspells); -#else -void GetItemBonus(int i, int idata, int minlvl, int maxlvl, BOOL onlygood); -#endif void SetupItem(int i); int RndItem(int m); -int RndUItem(int m); -int RndAllItems(); -#ifdef HELLFIRE -int RndTypeItems(int itype, int imid, int lvl); -#else -int RndTypeItems(int itype, int imid); -#endif -int CheckUnique(int i, int lvl, int uper, BOOL recreate); -void GetUniqueItem(int i, int uid); void SpawnUnique(int uid, int x, int y); -void ItemRndDur(int ii); -void SetupAllItems(int ii, int idx, int iseed, int lvl, int uper, BOOL onlygood, BOOL recreate, BOOL pregen); void SpawnItem(int m, int x, int y, BOOL sendmsg); void CreateItem(int uid, int x, int y); void CreateRndItem(int x, int y, BOOL onlygood, BOOL sendmsg, BOOL delta); -void SetupAllUseful(int ii, int iseed, int lvl); void CreateRndUseful(int pnum, int x, int y, BOOL sendmsg); void CreateTypeItem(int x, int y, BOOL onlygood, int itype, int imisc, BOOL sendmsg, BOOL delta); void RecreateItem(int ii, int idx, WORD icreateinfo, int iseed, int ivalue); @@ -116,7 +78,6 @@ void SpawnTheodore(int xx, int yy); #endif void RespawnItem(int i, BOOL FlipFlag); void DeleteItem(int ii, int i); -void ItemDoppel(); void ProcessItems(); void FreeItemGFX(); void GetItemFrm(int i); @@ -127,50 +88,25 @@ void RepairItem(ItemStruct *i, int lvl); void DoRecharge(int pnum, int cii); #ifdef HELLFIRE void DoOil(int pnum, int cii); -BOOL OilItem(ItemStruct *x, PlayerStruct *p); #endif void RechargeItem(ItemStruct *i, int r); -void PrintItemOil(char IDidx); void PrintItemPower(char plidx, ItemStruct *x); -void DrawUTextBack(); -void PrintUString(int x, int y, BOOL cjustflag, const char *str, int col); -void DrawULine(int y); void DrawUniqueInfo(); -void PrintItemMisc(ItemStruct *x); void PrintItemDetails(ItemStruct *x); void PrintItemDur(ItemStruct *x); void UseItem(int p, int Mid, int spl); BOOL StoreStatOk(ItemStruct *h); -BOOL SmithItemOk(int i); -int RndSmithItem(int lvl); -void BubbleSwapItem(ItemStruct *a, ItemStruct *b); -void SortSmith(); void SpawnSmith(int lvl); -BOOL PremiumItemOk(int i); -int RndPremiumItem(int minlvl, int maxlvl); -void SpawnOnePremium(int i, int plvl); #ifdef HELLFIRE void SpawnPremium(int pnum); #else void SpawnPremium(int lvl); #endif -BOOL WitchItemOk(int i); -int RndWitchItem(int lvl); -void SortWitch(); void WitchBookLevel(int ii); void SpawnWitch(int lvl); -int RndBoyItem(int lvl); void SpawnBoy(int lvl); -BOOL HealerItemOk(int i); -int RndHealerItem(int lvl); -void SortHealer(); void SpawnHealer(int lvl); void SpawnStoreGold(); -void RecreateSmithItem(int ii, int idx, int lvl, int iseed); -void RecreatePremiumItem(int ii, int idx, int plvl, int iseed); -void RecreateBoyItem(int ii, int idx, int lvl, int iseed); -void RecreateWitchItem(int ii, int idx, int lvl, int iseed); -void RecreateHealerItem(int ii, int idx, int lvl, int iseed); void RecreateTownItem(int ii, int idx, WORD icreateinfo, int iseed, int ivalue); void RecalcStoreStats(); int ItemNoFlippy(); @@ -181,27 +117,17 @@ void CreateAmulet(int x, int y, int curlv, BOOL sendmsg, BOOL delta); #endif void CreateMagicWeapon(int x, int y, int imisc, int icurs, BOOL sendmsg, BOOL delta); BOOL GetItemRecord(int nSeed, WORD wCI, int nIndex); -void NextItemRecord(int i); void SetItemRecord(int nSeed, WORD wCI, int nIndex); void PutItemRecord(int nSeed, WORD wCI, int nIndex); /* data */ #ifdef HELLFIRE -extern int OilLevels[10]; -extern int OilValues[10]; -extern int OilMagic[10]; -extern char OilNames[10][25]; extern int MaxGold; #endif extern BYTE ItemCAnimTbl[]; -extern const char *const ItemDropNames[]; -extern BYTE ItemAnimLs[]; -extern int ItemDropSnds[]; extern int ItemInvSnds[]; -extern int idoppely; -extern int premiumlvladd[6]; #ifdef __cplusplus } diff --git a/Source/lighting.h b/Source/lighting.h index bceb0e80d..72824105c 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -21,14 +21,11 @@ extern BOOL dovision; extern int numvision; extern char lightmax; extern BOOL dolighting; -extern BYTE lightblock[64][16][16]; extern int visionid; extern BYTE *pLightTbl; extern BOOL lightflag; -void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, int *by); void DoLighting(int nXPos, int nYPos, int nRadius, int Lnum); -void DoUnLight(int nXPos, int nYPos, int nRadius); void DoUnVision(int nXPos, int nYPos, int nRadius); void DoVision(int nXPos, int nYPos, int nRadius, BOOL doautomap, BOOL visible); void FreeLightTable(); @@ -57,10 +54,7 @@ void lighting_color_cycling(); /* rdata */ extern char CrawlTable[2749]; -extern char *pCrawlTable[19]; extern BYTE vCrawlTable[23][30]; -extern BYTE byte_49463C[18][18]; -extern BYTE RadiusAdj[23]; #ifdef __cplusplus } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 6d5448ee2..124c50829 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -9,194 +9,12 @@ DEVILUTION_BEGIN_NAMESPACE BYTE *tbuff; -/** - * @brief Load game state - * @param firstflag Can be set to false if we are simply reloading the current game - */ -void LoadGame(BOOL firstflag) -{ - int i, j; - DWORD dwLen; - char szName[MAX_PATH]; - BYTE *LoadBuff; - int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; - - FreeGameMem(); - pfile_remove_temp_files(); - pfile_get_game_name(szName); - LoadBuff = pfile_read(szName, &dwLen); - tbuff = LoadBuff; - -#ifdef HELLFIRE - if (ILoad() != 'HELF') -#else - if (ILoad() != 'RETL') -#endif - app_fatal("Invalid save file"); - - setlevel = OLoad(); - setlvlnum = WLoad(); - currlevel = WLoad(); - leveltype = WLoad(); - _ViewX = WLoad(); - _ViewY = WLoad(); - invflag = OLoad(); - chrflag = OLoad(); - _nummonsters = WLoad(); - _numitems = WLoad(); - _nummissiles = WLoad(); - _nobjects = WLoad(); - - for (i = 0; i < NUMLEVELS; i++) { - glSeedTbl[i] = ILoad(); - gnLevelTypeTbl[i] = WLoad(); - } - - LoadPlayer(myplr); - - gnDifficulty = plr[myplr].pDifficulty; - if (gnDifficulty < DIFF_NORMAL || gnDifficulty > DIFF_HELL) - gnDifficulty = DIFF_NORMAL; - - for (i = 0; i < MAXQUESTS; i++) - LoadQuest(i); - for (i = 0; i < MAXPORTAL; i++) - LoadPortal(i); - - LoadGameLevel(firstflag, ENTRY_LOAD); - SyncInitPlr(myplr); - SyncPlrAnim(myplr); - - ViewX = _ViewX; - ViewY = _ViewY; - nummonsters = _nummonsters; - numitems = _numitems; - nummissiles = _nummissiles; - nobjects = _nobjects; - - for (i = 0; i < MAXMONSTERS; i++) - monstkills[i] = ILoad(); - - if (leveltype != DTYPE_TOWN) { - for (i = 0; i < MAXMONSTERS; i++) - monstactive[i] = WLoad(); - for (i = 0; i < nummonsters; i++) - LoadMonster(monstactive[i]); - for (i = 0; i < MAXMISSILES; i++) - missileactive[i] = BLoad(); - for (i = 0; i < MAXMISSILES; i++) - missileavail[i] = BLoad(); - for (i = 0; i < nummissiles; i++) - LoadMissile(missileactive[i]); - for (i = 0; i < MAXOBJECTS; i++) - objectactive[i] = BLoad(); - for (i = 0; i < MAXOBJECTS; i++) - objectavail[i] = BLoad(); - for (i = 0; i < nobjects; i++) - LoadObject(objectactive[i]); - for (i = 0; i < nobjects; i++) - SyncObjectAnim(objectactive[i]); - - numlights = WLoad(); - - for (i = 0; i < MAXLIGHTS; i++) - lightactive[i] = BLoad(); - for (i = 0; i < numlights; i++) - LoadLighting(lightactive[i]); - - visionid = WLoad(); - numvision = WLoad(); - - for (i = 0; i < numvision; i++) - LoadVision(i); - } - - for (i = 0; i < MAXITEMS; i++) - itemactive[i] = BLoad(); - for (i = 0; i < MAXITEMS; i++) - itemavail[i] = BLoad(); - for (i = 0; i < numitems; i++) - LoadItem(itemactive[i]); - for (i = 0; i < 128; i++) - UniqueItemFlag[i] = OLoad(); - - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dFlags[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPlayer[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dItem[i][j] = BLoad(); - } - - if (leveltype != DTYPE_TOWN) { - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMonster[i][j] = WLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dDead[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dObject[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dLight[i][j] = BLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dPreLight[i][j] = BLoad(); - } - for (j = 0; j < DMAXY; j++) { - for (i = 0; i < DMAXX; i++) - automapview[i][j] = OLoad(); - } - for (j = 0; j < MAXDUNY; j++) { - for (i = 0; i < MAXDUNX; i++) - dMissile[i][j] = BLoad(); - } - } - - numpremium = WLoad(); - premiumlevel = WLoad(); - - for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) - LoadPremium(i); - - automapflag = OLoad(); - AutoMapScale = WLoad(); - mem_free_dbg(LoadBuff); - AutomapZoomReset(); - ResyncQuests(); - - if (leveltype != DTYPE_TOWN) - ProcessLightList(); - - RedoPlayerVision(); - ProcessVisionList(); - missiles_process_charge(); - ResetPal(); - SetCursor_(CURSOR_HAND); - gbProcessPlayers = TRUE; -} - -char BLoad() +static char BLoad() { return *tbuff++; } -int WLoad() +static int WLoad() { int rv = *tbuff++ << 24; rv |= *tbuff++ << 16; @@ -206,7 +24,7 @@ int WLoad() return rv; } -int ILoad() +static int ILoad() { int rv = *tbuff++ << 24; rv |= *tbuff++ << 16; @@ -216,7 +34,7 @@ int ILoad() return rv; } -BOOL OLoad() +static BOOL OLoad() { if (*tbuff++ == TRUE) return TRUE; @@ -224,19 +42,19 @@ BOOL OLoad() return FALSE; } -void CopyBytes(const void *src, const int n, void *dst) +static void CopyBytes(const void *src, const int n, void *dst) { memcpy(dst, src, n); tbuff += n; } -void CopyChar(const void *src, void *dst) +static void CopyChar(const void *src, void *dst) { *(char *)dst = *(char *)src; tbuff += 1; } -void CopyShort(const void *src, void *dst) +static void CopyShort(const void *src, void *dst) { unsigned short buf; memcpy(&buf, src, 2); @@ -245,7 +63,7 @@ void CopyShort(const void *src, void *dst) memcpy(dst, &buf, 2); } -void CopyShorts(const void *src, const int n, void *dst) +static void CopyShorts(const void *src, const int n, void *dst) { const unsigned short *s = reinterpret_cast(src); unsigned short *d = reinterpret_cast(dst); @@ -256,7 +74,7 @@ void CopyShorts(const void *src, const int n, void *dst) } } -void CopyInt(const void *src, void *dst) +static void CopyInt(const void *src, void *dst) { unsigned int buf; memcpy(&buf, src, 4); @@ -265,7 +83,7 @@ void CopyInt(const void *src, void *dst) memcpy(dst, &buf, 4); } -void CopyInts(const void *src, const int n, void *dst) +static void CopyInts(const void *src, const int n, void *dst) { const unsigned int *s = reinterpret_cast(src); const unsigned int *d = reinterpret_cast(dst); @@ -276,7 +94,7 @@ void CopyInts(const void *src, const int n, void *dst) } } -void CopyInt64(const void *src, void *dst) +static void CopyInt64(const void *src, void *dst) { unsigned long long buf; memcpy(&buf, src, 8); @@ -285,7 +103,92 @@ void CopyInt64(const void *src, void *dst) memcpy(dst, &buf, 8); } -void LoadPlayer(int i) +static void LoadItemData(ItemStruct *pItem) +{ + CopyInt(tbuff, &pItem->_iSeed); + CopyShort(tbuff, &pItem->_iCreateInfo); + tbuff += 2; // Alignment + CopyInt(tbuff, &pItem->_itype); + CopyInt(tbuff, &pItem->_ix); + CopyInt(tbuff, &pItem->_iy); + CopyInt(tbuff, &pItem->_iAnimFlag); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(tbuff, &pItem->_iAnimLen); + CopyInt(tbuff, &pItem->_iAnimFrame); + CopyInt(tbuff, &pItem->_iAnimWidth); + CopyInt(tbuff, &pItem->_iAnimWidth2); + CopyInt(tbuff, &pItem->_iDelFlag); + CopyChar(tbuff, &pItem->_iSelFlag); + tbuff += 3; // Alignment + CopyInt(tbuff, &pItem->_iPostDraw); + CopyInt(tbuff, &pItem->_iIdentified); + CopyChar(tbuff, &pItem->_iMagical); + CopyBytes(tbuff, 64, &pItem->_iName); + CopyBytes(tbuff, 64, &pItem->_iIName); + CopyChar(tbuff, &pItem->_iLoc); + CopyChar(tbuff, &pItem->_iClass); + tbuff += 1; // Alignment + CopyInt(tbuff, &pItem->_iCurs); + CopyInt(tbuff, &pItem->_ivalue); + CopyInt(tbuff, &pItem->_iIvalue); + CopyInt(tbuff, &pItem->_iMinDam); + CopyInt(tbuff, &pItem->_iMaxDam); + CopyInt(tbuff, &pItem->_iAC); + CopyInt(tbuff, &pItem->_iFlags); + CopyInt(tbuff, &pItem->_iMiscId); + CopyInt(tbuff, &pItem->_iSpell); + CopyInt(tbuff, &pItem->_iCharges); + CopyInt(tbuff, &pItem->_iMaxCharges); + CopyInt(tbuff, &pItem->_iDurability); + CopyInt(tbuff, &pItem->_iMaxDur); + CopyInt(tbuff, &pItem->_iPLDam); + CopyInt(tbuff, &pItem->_iPLToHit); + CopyInt(tbuff, &pItem->_iPLAC); + CopyInt(tbuff, &pItem->_iPLStr); + CopyInt(tbuff, &pItem->_iPLMag); + CopyInt(tbuff, &pItem->_iPLDex); + CopyInt(tbuff, &pItem->_iPLVit); + CopyInt(tbuff, &pItem->_iPLFR); + CopyInt(tbuff, &pItem->_iPLLR); + CopyInt(tbuff, &pItem->_iPLMR); + CopyInt(tbuff, &pItem->_iPLMana); + CopyInt(tbuff, &pItem->_iPLHP); + CopyInt(tbuff, &pItem->_iPLDamMod); + CopyInt(tbuff, &pItem->_iPLGetHit); + CopyInt(tbuff, &pItem->_iPLLight); + CopyChar(tbuff, &pItem->_iSplLvlAdd); + CopyChar(tbuff, &pItem->_iRequest); + tbuff += 2; // Alignment + CopyInt(tbuff, &pItem->_iUid); + CopyInt(tbuff, &pItem->_iFMinDam); + CopyInt(tbuff, &pItem->_iFMaxDam); + CopyInt(tbuff, &pItem->_iLMinDam); + CopyInt(tbuff, &pItem->_iLMaxDam); + CopyInt(tbuff, &pItem->_iPLEnAc); + CopyChar(tbuff, &pItem->_iPrePower); + CopyChar(tbuff, &pItem->_iSufPower); + tbuff += 2; // Alignment + CopyInt(tbuff, &pItem->_iVAdd1); + CopyInt(tbuff, &pItem->_iVMult1); + CopyInt(tbuff, &pItem->_iVAdd2); + CopyInt(tbuff, &pItem->_iVMult2); + CopyChar(tbuff, &pItem->_iMinStr); + CopyChar(tbuff, &pItem->_iMinMag); + CopyChar(tbuff, &pItem->_iMinDex); + tbuff += 1; // Alignment + CopyInt(tbuff, &pItem->_iStatFlag); + CopyInt(tbuff, &pItem->IDidx); + CopyInt(tbuff, &pItem->offs016C); +} + +static void LoadItems(const int n, ItemStruct *pItem) +{ + for (int i = 0; i < n; i++) { + LoadItemData(&pItem[i]); + } +} + +static void LoadPlayer(int i) { PlayerStruct *pPlayer = &plr[i]; @@ -499,7 +402,7 @@ void LoadPlayer(int i) // Omit pointer pReserved } -void LoadMonster(int i) +static void LoadMonster(int i) { MonsterStruct *pMonster = &monster[i]; @@ -593,7 +496,7 @@ void LoadMonster(int i) SyncMonsterAnim(i); } -void LoadMissile(int i) +static void LoadMissile(int i) { MissileStruct *pMissile = &missile[i]; @@ -644,7 +547,7 @@ void LoadMissile(int i) CopyInt(tbuff, &pMissile->_miVar8); } -void LoadObject(int i) +static void LoadObject(int i) { ObjectStruct *pObject = &object[i]; @@ -662,124 +565,39 @@ void LoadObject(int i) CopyInt(tbuff, &pObject->_oAnimWidth2); CopyInt(tbuff, &pObject->_oDelFlag); CopyChar(tbuff, &pObject->_oBreak); - tbuff += 3; // Alignment - CopyInt(tbuff, &pObject->_oSolidFlag); - CopyInt(tbuff, &pObject->_oMissFlag); - - CopyChar(tbuff, &pObject->_oSelFlag); - tbuff += 3; // Alignment - CopyInt(tbuff, &pObject->_oPreFlag); - CopyInt(tbuff, &pObject->_oTrapFlag); - CopyInt(tbuff, &pObject->_oDoorFlag); - CopyInt(tbuff, &pObject->_olid); - CopyInt(tbuff, &pObject->_oRndSeed); - CopyInt(tbuff, &pObject->_oVar1); - CopyInt(tbuff, &pObject->_oVar2); - CopyInt(tbuff, &pObject->_oVar3); - CopyInt(tbuff, &pObject->_oVar4); - CopyInt(tbuff, &pObject->_oVar5); - CopyInt(tbuff, &pObject->_oVar6); - CopyInt(tbuff, &pObject->_oVar7); - CopyInt(tbuff, &pObject->_oVar8); -} - -void LoadItem(int i) -{ - LoadItemData(&item[i]); - GetItemFrm(i); -} - -void LoadItemData(ItemStruct *pItem) -{ - CopyInt(tbuff, &pItem->_iSeed); - CopyShort(tbuff, &pItem->_iCreateInfo); - tbuff += 2; // Alignment - CopyInt(tbuff, &pItem->_itype); - CopyInt(tbuff, &pItem->_ix); - CopyInt(tbuff, &pItem->_iy); - CopyInt(tbuff, &pItem->_iAnimFlag); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(tbuff, &pItem->_iAnimLen); - CopyInt(tbuff, &pItem->_iAnimFrame); - CopyInt(tbuff, &pItem->_iAnimWidth); - CopyInt(tbuff, &pItem->_iAnimWidth2); - CopyInt(tbuff, &pItem->_iDelFlag); - CopyChar(tbuff, &pItem->_iSelFlag); - tbuff += 3; // Alignment - CopyInt(tbuff, &pItem->_iPostDraw); - CopyInt(tbuff, &pItem->_iIdentified); - CopyChar(tbuff, &pItem->_iMagical); - CopyBytes(tbuff, 64, &pItem->_iName); - CopyBytes(tbuff, 64, &pItem->_iIName); - CopyChar(tbuff, &pItem->_iLoc); - CopyChar(tbuff, &pItem->_iClass); - tbuff += 1; // Alignment - CopyInt(tbuff, &pItem->_iCurs); - CopyInt(tbuff, &pItem->_ivalue); - CopyInt(tbuff, &pItem->_iIvalue); - CopyInt(tbuff, &pItem->_iMinDam); - CopyInt(tbuff, &pItem->_iMaxDam); - CopyInt(tbuff, &pItem->_iAC); - CopyInt(tbuff, &pItem->_iFlags); - CopyInt(tbuff, &pItem->_iMiscId); - CopyInt(tbuff, &pItem->_iSpell); - CopyInt(tbuff, &pItem->_iCharges); - CopyInt(tbuff, &pItem->_iMaxCharges); - CopyInt(tbuff, &pItem->_iDurability); - CopyInt(tbuff, &pItem->_iMaxDur); - CopyInt(tbuff, &pItem->_iPLDam); - CopyInt(tbuff, &pItem->_iPLToHit); - CopyInt(tbuff, &pItem->_iPLAC); - CopyInt(tbuff, &pItem->_iPLStr); - CopyInt(tbuff, &pItem->_iPLMag); - CopyInt(tbuff, &pItem->_iPLDex); - CopyInt(tbuff, &pItem->_iPLVit); - CopyInt(tbuff, &pItem->_iPLFR); - CopyInt(tbuff, &pItem->_iPLLR); - CopyInt(tbuff, &pItem->_iPLMR); - CopyInt(tbuff, &pItem->_iPLMana); - CopyInt(tbuff, &pItem->_iPLHP); - CopyInt(tbuff, &pItem->_iPLDamMod); - CopyInt(tbuff, &pItem->_iPLGetHit); - CopyInt(tbuff, &pItem->_iPLLight); - CopyChar(tbuff, &pItem->_iSplLvlAdd); - CopyChar(tbuff, &pItem->_iRequest); - tbuff += 2; // Alignment - CopyInt(tbuff, &pItem->_iUid); - CopyInt(tbuff, &pItem->_iFMinDam); - CopyInt(tbuff, &pItem->_iFMaxDam); - CopyInt(tbuff, &pItem->_iLMinDam); - CopyInt(tbuff, &pItem->_iLMaxDam); - CopyInt(tbuff, &pItem->_iPLEnAc); - CopyChar(tbuff, &pItem->_iPrePower); - CopyChar(tbuff, &pItem->_iSufPower); - tbuff += 2; // Alignment - CopyInt(tbuff, &pItem->_iVAdd1); - CopyInt(tbuff, &pItem->_iVMult1); - CopyInt(tbuff, &pItem->_iVAdd2); - CopyInt(tbuff, &pItem->_iVMult2); - CopyChar(tbuff, &pItem->_iMinStr); - CopyChar(tbuff, &pItem->_iMinMag); - CopyChar(tbuff, &pItem->_iMinDex); - tbuff += 1; // Alignment - CopyInt(tbuff, &pItem->_iStatFlag); - CopyInt(tbuff, &pItem->IDidx); - CopyInt(tbuff, &pItem->offs016C); + tbuff += 3; // Alignment + CopyInt(tbuff, &pObject->_oSolidFlag); + CopyInt(tbuff, &pObject->_oMissFlag); + + CopyChar(tbuff, &pObject->_oSelFlag); + tbuff += 3; // Alignment + CopyInt(tbuff, &pObject->_oPreFlag); + CopyInt(tbuff, &pObject->_oTrapFlag); + CopyInt(tbuff, &pObject->_oDoorFlag); + CopyInt(tbuff, &pObject->_olid); + CopyInt(tbuff, &pObject->_oRndSeed); + CopyInt(tbuff, &pObject->_oVar1); + CopyInt(tbuff, &pObject->_oVar2); + CopyInt(tbuff, &pObject->_oVar3); + CopyInt(tbuff, &pObject->_oVar4); + CopyInt(tbuff, &pObject->_oVar5); + CopyInt(tbuff, &pObject->_oVar6); + CopyInt(tbuff, &pObject->_oVar7); + CopyInt(tbuff, &pObject->_oVar8); } -void LoadItems(const int n, ItemStruct *pItem) +static void LoadItem(int i) { - for (int i = 0; i < n; i++) { - LoadItemData(&pItem[i]); - } + LoadItemData(&item[i]); + GetItemFrm(i); } -void LoadPremium(int i) +static void LoadPremium(int i) { LoadItemData(&premiumitem[i]); } -void LoadQuest(int i) +static void LoadQuest(int i) { QuestStruct *pQuest = &quests[i]; @@ -804,7 +622,7 @@ void LoadQuest(int i) DoomQuestState = WLoad(); } -void LoadLighting(int i) +static void LoadLighting(int i) { LightListStruct *pLight = &LightList[i]; @@ -823,7 +641,7 @@ void LoadLighting(int i) CopyInt(tbuff, &pLight->_lflags); } -void LoadVision(int i) +static void LoadVision(int i) { LightListStruct *pVision = &VisionList[i]; @@ -842,7 +660,7 @@ void LoadVision(int i) CopyInt(tbuff, &pVision->_lflags); } -void LoadPortal(int i) +static void LoadPortal(int i) { PortalStruct *pPortal = &portal[i]; @@ -854,160 +672,196 @@ void LoadPortal(int i) CopyInt(tbuff, &pPortal->setlvl); } -void SaveGame() +/** + * @brief Load game state + * @param firstflag Can be set to false if we are simply reloading the current game + */ +void LoadGame(BOOL firstflag) { int i, j; + DWORD dwLen; char szName[MAX_PATH]; + BYTE *LoadBuff; + int _ViewX, _ViewY, _nummonsters, _numitems, _nummissiles, _nobjects; - DWORD dwLen = codec_get_encoded_len(FILEBUFF); - BYTE *SaveBuff = DiabloAllocPtr(dwLen); - tbuff = SaveBuff; + FreeGameMem(); + pfile_remove_temp_files(); + pfile_get_game_name(szName); + LoadBuff = pfile_read(szName, &dwLen); + tbuff = LoadBuff; #ifdef HELLFIRE - ISave('HELF'); + if (ILoad() != 'HELF') +#elif defined(SPAWN) + if (ILoad() != 'SHAR') #else - ISave('RETL'); + if (ILoad() != 'RETL') #endif - OSave(setlevel); - WSave(setlvlnum); - WSave(currlevel); - WSave(leveltype); - WSave(ViewX); - WSave(ViewY); - OSave(invflag); - OSave(chrflag); - WSave(nummonsters); - WSave(numitems); - WSave(nummissiles); - WSave(nobjects); + app_fatal("Invalid save file"); + + setlevel = OLoad(); + setlvlnum = WLoad(); + currlevel = WLoad(); + leveltype = WLoad(); + _ViewX = WLoad(); + _ViewY = WLoad(); + invflag = OLoad(); + chrflag = OLoad(); + _nummonsters = WLoad(); + _numitems = WLoad(); + _nummissiles = WLoad(); + _nobjects = WLoad(); for (i = 0; i < NUMLEVELS; i++) { - ISave(glSeedTbl[i]); - WSave(gnLevelTypeTbl[i]); + glSeedTbl[i] = ILoad(); + gnLevelTypeTbl[i] = WLoad(); } - plr[myplr].pDifficulty = gnDifficulty; - SavePlayer(myplr); + LoadPlayer(myplr); + + gnDifficulty = plr[myplr].pDifficulty; + if (gnDifficulty < DIFF_NORMAL || gnDifficulty > DIFF_HELL) + gnDifficulty = DIFF_NORMAL; for (i = 0; i < MAXQUESTS; i++) - SaveQuest(i); + LoadQuest(i); for (i = 0; i < MAXPORTAL; i++) - SavePortal(i); + LoadPortal(i); + + LoadGameLevel(firstflag, ENTRY_LOAD); + SyncInitPlr(myplr); + SyncPlrAnim(myplr); + + ViewX = _ViewX; + ViewY = _ViewY; + nummonsters = _nummonsters; + numitems = _numitems; + nummissiles = _nummissiles; + nobjects = _nobjects; + for (i = 0; i < MAXMONSTERS; i++) - ISave(monstkills[i]); + monstkills[i] = ILoad(); if (leveltype != DTYPE_TOWN) { for (i = 0; i < MAXMONSTERS; i++) - WSave(monstactive[i]); + monstactive[i] = WLoad(); for (i = 0; i < nummonsters; i++) - SaveMonster(monstactive[i]); + LoadMonster(monstactive[i]); for (i = 0; i < MAXMISSILES; i++) - BSave(missileactive[i]); + missileactive[i] = BLoad(); for (i = 0; i < MAXMISSILES; i++) - BSave(missileavail[i]); + missileavail[i] = BLoad(); for (i = 0; i < nummissiles; i++) - SaveMissile(missileactive[i]); + LoadMissile(missileactive[i]); for (i = 0; i < MAXOBJECTS; i++) - BSave(objectactive[i]); + objectactive[i] = BLoad(); for (i = 0; i < MAXOBJECTS; i++) - BSave(objectavail[i]); + objectavail[i] = BLoad(); for (i = 0; i < nobjects; i++) - SaveObject(objectactive[i]); + LoadObject(objectactive[i]); + for (i = 0; i < nobjects; i++) + SyncObjectAnim(objectactive[i]); - WSave(numlights); + numlights = WLoad(); for (i = 0; i < MAXLIGHTS; i++) - BSave(lightactive[i]); + lightactive[i] = BLoad(); for (i = 0; i < numlights; i++) - SaveLighting(lightactive[i]); + LoadLighting(lightactive[i]); - WSave(visionid); - WSave(numvision); + visionid = WLoad(); + numvision = WLoad(); for (i = 0; i < numvision; i++) - SaveVision(i); + LoadVision(i); } for (i = 0; i < MAXITEMS; i++) - BSave(itemactive[i]); + itemactive[i] = BLoad(); for (i = 0; i < MAXITEMS; i++) - BSave(itemavail[i]); + itemavail[i] = BLoad(); for (i = 0; i < numitems; i++) - SaveItem(&item[itemactive[i]]); + LoadItem(itemactive[i]); for (i = 0; i < 128; i++) - OSave(UniqueItemFlag[i]); + UniqueItemFlag[i] = OLoad(); for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); + dLight[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + dFlags[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dPlayer[i][j]); + dPlayer[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dItem[i][j]); + dItem[i][j] = BLoad(); } if (leveltype != DTYPE_TOWN) { for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - WSave(dMonster[i][j]); + dMonster[i][j] = WLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dDead[i][j]); + dDead[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dObject[i][j]); + dObject[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dLight[i][j]); + dLight[i][j] = BLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dPreLight[i][j]); + dPreLight[i][j] = BLoad(); } for (j = 0; j < DMAXY; j++) { for (i = 0; i < DMAXX; i++) - OSave(automapview[i][j]); + automapview[i][j] = OLoad(); } for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) - BSave(dMissile[i][j]); + dMissile[i][j] = BLoad(); } } - WSave(numpremium); - WSave(premiumlevel); + numpremium = WLoad(); + premiumlevel = WLoad(); for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) - SavePremium(i); + LoadPremium(i); - OSave(automapflag); - WSave(AutoMapScale); - pfile_get_game_name(szName); - dwLen = codec_get_encoded_len(tbuff - SaveBuff); - pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); - mem_free_dbg(SaveBuff); - gbValidSaveFile = TRUE; - pfile_rename_temp_to_perm(); - pfile_write_hero(); + automapflag = OLoad(); + AutoMapScale = WLoad(); + mem_free_dbg(LoadBuff); + AutomapZoomReset(); + ResyncQuests(); + + if (leveltype != DTYPE_TOWN) + ProcessLightList(); + + RedoPlayerVision(); + ProcessVisionList(); + missiles_process_charge(); + ResetPal(); + SetCursor_(CURSOR_HAND); + gbProcessPlayers = TRUE; } -void BSave(char v) +static void BSave(char v) { *tbuff++ = v; } -void WSave(int v) +static void WSave(int v) { *tbuff++ = v >> 24; *tbuff++ = v >> 16; @@ -1015,7 +869,7 @@ void WSave(int v) *tbuff++ = v; } -void ISave(int v) +static void ISave(int v) { *tbuff++ = v >> 24; *tbuff++ = v >> 16; @@ -1023,15 +877,100 @@ void ISave(int v) *tbuff++ = v; } -void OSave(BOOL v) +static void OSave(BOOL v) +{ + if (v != FALSE) + *tbuff++ = TRUE; + else + *tbuff++ = FALSE; +} + +static void SaveItem(ItemStruct *pItem) +{ + CopyInt(&pItem->_iSeed, tbuff); + CopyShort(&pItem->_iCreateInfo, tbuff); + tbuff += 2; // Alignment + CopyInt(&pItem->_itype, tbuff); + CopyInt(&pItem->_ix, tbuff); + CopyInt(&pItem->_iy, tbuff); + CopyInt(&pItem->_iAnimFlag, tbuff); + tbuff += 4; // Skip pointer _iAnimData + CopyInt(&pItem->_iAnimLen, tbuff); + CopyInt(&pItem->_iAnimFrame, tbuff); + CopyInt(&pItem->_iAnimWidth, tbuff); + CopyInt(&pItem->_iAnimWidth2, tbuff); + CopyInt(&pItem->_iDelFlag, tbuff); + CopyChar(&pItem->_iSelFlag, tbuff); + tbuff += 3; // Alignment + CopyInt(&pItem->_iPostDraw, tbuff); + CopyInt(&pItem->_iIdentified, tbuff); + CopyChar(&pItem->_iMagical, tbuff); + CopyBytes(&pItem->_iName, 64, tbuff); + CopyBytes(&pItem->_iIName, 64, tbuff); + CopyChar(&pItem->_iLoc, tbuff); + CopyChar(&pItem->_iClass, tbuff); + tbuff += 1; // Alignment + CopyInt(&pItem->_iCurs, tbuff); + CopyInt(&pItem->_ivalue, tbuff); + CopyInt(&pItem->_iIvalue, tbuff); + CopyInt(&pItem->_iMinDam, tbuff); + CopyInt(&pItem->_iMaxDam, tbuff); + CopyInt(&pItem->_iAC, tbuff); + CopyInt(&pItem->_iFlags, tbuff); + CopyInt(&pItem->_iMiscId, tbuff); + CopyInt(&pItem->_iSpell, tbuff); + CopyInt(&pItem->_iCharges, tbuff); + CopyInt(&pItem->_iMaxCharges, tbuff); + CopyInt(&pItem->_iDurability, tbuff); + CopyInt(&pItem->_iMaxDur, tbuff); + CopyInt(&pItem->_iPLDam, tbuff); + CopyInt(&pItem->_iPLToHit, tbuff); + CopyInt(&pItem->_iPLAC, tbuff); + CopyInt(&pItem->_iPLStr, tbuff); + CopyInt(&pItem->_iPLMag, tbuff); + CopyInt(&pItem->_iPLDex, tbuff); + CopyInt(&pItem->_iPLVit, tbuff); + CopyInt(&pItem->_iPLFR, tbuff); + CopyInt(&pItem->_iPLLR, tbuff); + CopyInt(&pItem->_iPLMR, tbuff); + CopyInt(&pItem->_iPLMana, tbuff); + CopyInt(&pItem->_iPLHP, tbuff); + CopyInt(&pItem->_iPLDamMod, tbuff); + CopyInt(&pItem->_iPLGetHit, tbuff); + CopyInt(&pItem->_iPLLight, tbuff); + CopyChar(&pItem->_iSplLvlAdd, tbuff); + CopyChar(&pItem->_iRequest, tbuff); + tbuff += 2; // Alignment + CopyInt(&pItem->_iUid, tbuff); + CopyInt(&pItem->_iFMinDam, tbuff); + CopyInt(&pItem->_iFMaxDam, tbuff); + CopyInt(&pItem->_iLMinDam, tbuff); + CopyInt(&pItem->_iLMaxDam, tbuff); + CopyInt(&pItem->_iPLEnAc, tbuff); + CopyChar(&pItem->_iPrePower, tbuff); + CopyChar(&pItem->_iSufPower, tbuff); + tbuff += 2; // Alignment + CopyInt(&pItem->_iVAdd1, tbuff); + CopyInt(&pItem->_iVMult1, tbuff); + CopyInt(&pItem->_iVAdd2, tbuff); + CopyInt(&pItem->_iVMult2, tbuff); + CopyChar(&pItem->_iMinStr, tbuff); + CopyChar(&pItem->_iMinMag, tbuff); + CopyChar(&pItem->_iMinDex, tbuff); + tbuff += 1; // Alignment + CopyInt(&pItem->_iStatFlag, tbuff); + CopyInt(&pItem->IDidx, tbuff); + CopyInt(&pItem->offs016C, tbuff); +} + +static void SaveItems(ItemStruct *pItem, const int n) { - if (v != FALSE) - *tbuff++ = TRUE; - else - *tbuff++ = FALSE; + for (int i = 0; i < n; i++) { + SaveItem(&pItem[i]); + } } -void SavePlayer(int i) +static void SavePlayer(int i) { PlayerStruct *pPlayer = &plr[i]; @@ -1238,7 +1177,7 @@ void SavePlayer(int i) // Omit pointer pReserved } -void SaveMonster(int i) +static void SaveMonster(int i) { MonsterStruct *pMonster = &monster[i]; char tempChar; @@ -1335,7 +1274,7 @@ void SaveMonster(int i) // Omit pointer MData; } -void SaveMissile(int i) +static void SaveMissile(int i) { MissileStruct *pMissile = &missile[i]; @@ -1386,7 +1325,7 @@ void SaveMissile(int i) CopyInt(&pMissile->_miVar8, tbuff); } -void SaveObject(int i) +static void SaveObject(int i) { ObjectStruct *pObject = &object[i]; @@ -1425,97 +1364,12 @@ void SaveObject(int i) CopyInt(&pObject->_oVar8, tbuff); } -void SaveItem(ItemStruct *pItem) -{ - CopyInt(&pItem->_iSeed, tbuff); - CopyShort(&pItem->_iCreateInfo, tbuff); - tbuff += 2; // Alignment - CopyInt(&pItem->_itype, tbuff); - CopyInt(&pItem->_ix, tbuff); - CopyInt(&pItem->_iy, tbuff); - CopyInt(&pItem->_iAnimFlag, tbuff); - tbuff += 4; // Skip pointer _iAnimData - CopyInt(&pItem->_iAnimLen, tbuff); - CopyInt(&pItem->_iAnimFrame, tbuff); - CopyInt(&pItem->_iAnimWidth, tbuff); - CopyInt(&pItem->_iAnimWidth2, tbuff); - CopyInt(&pItem->_iDelFlag, tbuff); - CopyChar(&pItem->_iSelFlag, tbuff); - tbuff += 3; // Alignment - CopyInt(&pItem->_iPostDraw, tbuff); - CopyInt(&pItem->_iIdentified, tbuff); - CopyChar(&pItem->_iMagical, tbuff); - CopyBytes(&pItem->_iName, 64, tbuff); - CopyBytes(&pItem->_iIName, 64, tbuff); - CopyChar(&pItem->_iLoc, tbuff); - CopyChar(&pItem->_iClass, tbuff); - tbuff += 1; // Alignment - CopyInt(&pItem->_iCurs, tbuff); - CopyInt(&pItem->_ivalue, tbuff); - CopyInt(&pItem->_iIvalue, tbuff); - CopyInt(&pItem->_iMinDam, tbuff); - CopyInt(&pItem->_iMaxDam, tbuff); - CopyInt(&pItem->_iAC, tbuff); - CopyInt(&pItem->_iFlags, tbuff); - CopyInt(&pItem->_iMiscId, tbuff); - CopyInt(&pItem->_iSpell, tbuff); - CopyInt(&pItem->_iCharges, tbuff); - CopyInt(&pItem->_iMaxCharges, tbuff); - CopyInt(&pItem->_iDurability, tbuff); - CopyInt(&pItem->_iMaxDur, tbuff); - CopyInt(&pItem->_iPLDam, tbuff); - CopyInt(&pItem->_iPLToHit, tbuff); - CopyInt(&pItem->_iPLAC, tbuff); - CopyInt(&pItem->_iPLStr, tbuff); - CopyInt(&pItem->_iPLMag, tbuff); - CopyInt(&pItem->_iPLDex, tbuff); - CopyInt(&pItem->_iPLVit, tbuff); - CopyInt(&pItem->_iPLFR, tbuff); - CopyInt(&pItem->_iPLLR, tbuff); - CopyInt(&pItem->_iPLMR, tbuff); - CopyInt(&pItem->_iPLMana, tbuff); - CopyInt(&pItem->_iPLHP, tbuff); - CopyInt(&pItem->_iPLDamMod, tbuff); - CopyInt(&pItem->_iPLGetHit, tbuff); - CopyInt(&pItem->_iPLLight, tbuff); - CopyChar(&pItem->_iSplLvlAdd, tbuff); - CopyChar(&pItem->_iRequest, tbuff); - tbuff += 2; // Alignment - CopyInt(&pItem->_iUid, tbuff); - CopyInt(&pItem->_iFMinDam, tbuff); - CopyInt(&pItem->_iFMaxDam, tbuff); - CopyInt(&pItem->_iLMinDam, tbuff); - CopyInt(&pItem->_iLMaxDam, tbuff); - CopyInt(&pItem->_iPLEnAc, tbuff); - CopyChar(&pItem->_iPrePower, tbuff); - CopyChar(&pItem->_iSufPower, tbuff); - tbuff += 2; // Alignment - CopyInt(&pItem->_iVAdd1, tbuff); - CopyInt(&pItem->_iVMult1, tbuff); - CopyInt(&pItem->_iVAdd2, tbuff); - CopyInt(&pItem->_iVMult2, tbuff); - CopyChar(&pItem->_iMinStr, tbuff); - CopyChar(&pItem->_iMinMag, tbuff); - CopyChar(&pItem->_iMinDex, tbuff); - tbuff += 1; // Alignment - CopyInt(&pItem->_iStatFlag, tbuff); - CopyInt(&pItem->IDidx, tbuff); - CopyInt(&pItem->offs016C, tbuff); -} - -void SaveItems(ItemStruct *pItem, const int n) -{ - for (int i = 0; i < n; i++) { - SaveItem(&pItem[i]); - } -} - -void SavePremium(int i) +static void SavePremium(int i) { SaveItem(&premiumitem[i]); } -void SaveQuest(int i) +static void SaveQuest(int i) { QuestStruct *pQuest = &quests[i]; @@ -1540,7 +1394,7 @@ void SaveQuest(int i) WSave(DoomQuestState); } -void SaveLighting(int i) +static void SaveLighting(int i) { LightListStruct *pLight = &LightList[i]; @@ -1559,7 +1413,7 @@ void SaveLighting(int i) CopyInt(&pLight->_lflags, tbuff); } -void SaveVision(int i) +static void SaveVision(int i) { LightListStruct *pVision = &VisionList[i]; @@ -1578,7 +1432,7 @@ void SaveVision(int i) CopyInt(&pVision->_lflags, tbuff); } -void SavePortal(int i) +static void SavePortal(int i) { PortalStruct *pPortal = &portal[i]; @@ -1590,6 +1444,156 @@ void SavePortal(int i) CopyInt(&pPortal->setlvl, tbuff); } +void SaveGame() +{ + int i, j; + char szName[MAX_PATH]; + + DWORD dwLen = codec_get_encoded_len(FILEBUFF); + BYTE *SaveBuff = DiabloAllocPtr(dwLen); + tbuff = SaveBuff; + +#ifdef HELLFIRE + ISave('HELF'); +#elif defined(SPAWN) + ISave('SHAR'); +#else + ISave('RETL'); +#endif + OSave(setlevel); + WSave(setlvlnum); + WSave(currlevel); + WSave(leveltype); + WSave(ViewX); + WSave(ViewY); + OSave(invflag); + OSave(chrflag); + WSave(nummonsters); + WSave(numitems); + WSave(nummissiles); + WSave(nobjects); + + for (i = 0; i < NUMLEVELS; i++) { + ISave(glSeedTbl[i]); + WSave(gnLevelTypeTbl[i]); + } + + plr[myplr].pDifficulty = gnDifficulty; + SavePlayer(myplr); + + for (i = 0; i < MAXQUESTS; i++) + SaveQuest(i); + for (i = 0; i < MAXPORTAL; i++) + SavePortal(i); + for (i = 0; i < MAXMONSTERS; i++) + ISave(monstkills[i]); + + if (leveltype != DTYPE_TOWN) { + for (i = 0; i < MAXMONSTERS; i++) + WSave(monstactive[i]); + for (i = 0; i < nummonsters; i++) + SaveMonster(monstactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileactive[i]); + for (i = 0; i < MAXMISSILES; i++) + BSave(missileavail[i]); + for (i = 0; i < nummissiles; i++) + SaveMissile(missileactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectactive[i]); + for (i = 0; i < MAXOBJECTS; i++) + BSave(objectavail[i]); + for (i = 0; i < nobjects; i++) + SaveObject(objectactive[i]); + + WSave(numlights); + + for (i = 0; i < MAXLIGHTS; i++) + BSave(lightactive[i]); + for (i = 0; i < numlights; i++) + SaveLighting(lightactive[i]); + + WSave(visionid); + WSave(numvision); + + for (i = 0; i < numvision; i++) + SaveVision(i); + } + + for (i = 0; i < MAXITEMS; i++) + BSave(itemactive[i]); + for (i = 0; i < MAXITEMS; i++) + BSave(itemavail[i]); + for (i = 0; i < numitems; i++) + SaveItem(&item[itemactive[i]]); + for (i = 0; i < 128; i++) + OSave(UniqueItemFlag[i]); + + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dFlags[i][j] & ~(BFLAG_MISSILE | BFLAG_VISIBLE | BFLAG_DEAD_PLAYER)); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPlayer[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dItem[i][j]); + } + + if (leveltype != DTYPE_TOWN) { + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + WSave(dMonster[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dDead[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dObject[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dLight[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dPreLight[i][j]); + } + for (j = 0; j < DMAXY; j++) { + for (i = 0; i < DMAXX; i++) + OSave(automapview[i][j]); + } + for (j = 0; j < MAXDUNY; j++) { + for (i = 0; i < MAXDUNX; i++) + BSave(dMissile[i][j]); + } + } + + WSave(numpremium); + WSave(premiumlevel); + + for (i = 0; i < SMITH_PREMIUM_ITEMS; i++) + SavePremium(i); + + OSave(automapflag); + WSave(AutoMapScale); + pfile_get_game_name(szName); + dwLen = codec_get_encoded_len(tbuff - SaveBuff); + pfile_write_save_file(szName, SaveBuff, tbuff - SaveBuff, dwLen); + mem_free_dbg(SaveBuff); + gbValidSaveFile = TRUE; + pfile_rename_temp_to_perm(); + pfile_write_hero(); +} + void SaveLevel() { int i, j; diff --git a/Source/loadsave.h b/Source/loadsave.h index 2ff97c212..c2eb312a8 100644 --- a/Source/loadsave.h +++ b/Source/loadsave.h @@ -12,42 +12,8 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern BYTE *tbuff; - void LoadGame(BOOL firstflag); -char BLoad(); -int WLoad(); -int ILoad(); -BOOL OLoad(); -void LoadItems(const int n, ItemStruct *pItem); -void LoadItemData(ItemStruct *pItem); -void SaveItem(ItemStruct *pItem); -void SaveItems(ItemStruct *pItem, const int n); - -void LoadPlayer(int i); -void LoadMonster(int i); -void LoadMissile(int i); -void LoadObject(int i); -void LoadItem(int i); -void LoadPremium(int i); -void LoadQuest(int i); -void LoadLighting(int i); -void LoadVision(int i); -void LoadPortal(int i); void SaveGame(); -void BSave(char v); -void WSave(int v); -void ISave(int v); -void OSave(BOOL v); -void SavePlayer(int i); -void SaveMonster(int i); -void SaveMissile(int i); -void SaveObject(int i); -void SavePremium(int i); -void SaveQuest(int i); -void SaveLighting(int i); -void SaveVision(int i); -void SavePortal(int i); void SaveLevel(); void LoadLevel(); diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index a9f962e95..aec7b1c6f 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -30,6 +30,54 @@ void mainmenu_refresh_music() } while (menu_music_track_id == TMUSIC_TOWN || menu_music_track_id == TMUSIC_L1); } +static BOOL mainmenu_init_menu(int type) +{ + BOOL success; + + if (type == SELHERO_PREVIOUS) + return TRUE; + + music_stop(); + + success = StartGame(type != SELHERO_CONTINUE, type != SELHERO_CONNECT); + if (success) + mainmenu_refresh_music(); + + return success; +} + +static BOOL mainmenu_single_player() +{ +#ifdef HELLFIRE + if (!SRegLoadValue(APP_NAME, jogging_title, 0, &jogging_opt)) { + jogging_opt = TRUE; + } +#endif + gbMaxPlayers = 1; + + if (!SRegLoadValue("devilutionx", "game speed", 0, &ticks_per_sec)) { + SRegSaveValue("devilutionx", "game speed", 0, ticks_per_sec); + } + + return mainmenu_init_menu(SELHERO_NEW_DUNGEON); +} + +static BOOL mainmenu_multi_player() +{ + gbMaxPlayers = MAX_PLRS; + return mainmenu_init_menu(SELHERO_CONNECT); +} + +static void mainmenu_play_intro() +{ + music_stop(); +#ifdef HELLFIRE + play_movie("gendata\\Hellfire.smk", TRUE); +#else + play_movie("gendata\\diablo1.smk", TRUE); +#endif + mainmenu_refresh_music(); +} void mainmenu_change_name(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2) { if (UiValidPlayerName(name_2)) @@ -142,53 +190,4 @@ void mainmenu_loop() music_stop(); } -BOOL mainmenu_single_player() -{ -#ifdef HELLFIRE - if (!SRegLoadValue(APP_NAME, jogging_title, 0, &jogging_opt)) { - jogging_opt = TRUE; - } -#endif - gbMaxPlayers = 1; - - if (!SRegLoadValue("devilutionx", "game speed", 0, &ticks_per_sec)) { - SRegSaveValue("devilutionx", "game speed", 0, ticks_per_sec); - } - - return mainmenu_init_menu(SELHERO_NEW_DUNGEON); -} - -BOOL mainmenu_init_menu(int type) -{ - BOOL success; - - if (type == SELHERO_PREVIOUS) - return TRUE; - - music_stop(); - - success = StartGame(type != SELHERO_CONTINUE, type != SELHERO_CONNECT); - if (success) - mainmenu_refresh_music(); - - return success; -} - -BOOL mainmenu_multi_player() -{ - gbMaxPlayers = MAX_PLRS; - return mainmenu_init_menu(SELHERO_CONNECT); -} - -void mainmenu_play_intro() -{ - music_stop(); -#ifdef HELLFIRE - play_movie("gendata\\Hellfire.smk", TRUE); -#else - play_movie("gendata\\diablo1.smk", TRUE); -#endif - mainmenu_refresh_music(); -} - DEVILUTION_END_NAMESPACE diff --git a/Source/mainmenu.h b/Source/mainmenu.h index 80b9bccdf..9895c719d 100644 --- a/Source/mainmenu.h +++ b/Source/mainmenu.h @@ -14,7 +14,6 @@ extern "C" { extern char gszHero[16]; -void mainmenu_refresh_music(); void mainmenu_change_name(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2); BOOL mainmenu_select_hero_dialog( const _SNETPROGRAMDATA *client_info, @@ -26,16 +25,6 @@ BOOL mainmenu_select_hero_dialog( char *cdesc, DWORD cdlen, // character "description" will be copied here (used to advertise games) BOOL *multi); // new character? - unsure about this void mainmenu_loop(); -BOOL mainmenu_single_player(); -BOOL mainmenu_init_menu(int type); -BOOL mainmenu_multi_player(); -void mainmenu_play_intro(); - -/* rdata */ - -/* data */ - -extern int menu_music_track_id; #ifdef __cplusplus } diff --git a/Source/minitext.h b/Source/minitext.h index 4a1b04dbe..54c9479e5 100644 --- a/Source/minitext.h +++ b/Source/minitext.h @@ -12,28 +12,14 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern int qtexty; -extern const char *qtextptr; extern BOOLEAN qtextflag; -extern BYTE *pMedTextCels; -extern BYTE *pTextBoxCels; void FreeQuestText(); void InitQuestText(); void InitQTextMsg(int m); void DrawQTextBack(); -void PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel); void DrawQText(); -/* rdata */ - -extern const BYTE mfontframe[128]; -extern const BYTE mfontkern[56]; - -/* data */ - -extern int qscroll_spd_tbl[9]; - #ifdef __cplusplus } #endif diff --git a/Source/missiles.cpp b/Source/missiles.cpp index e0d7bfde2..a8f5f9c1a 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1314,24 +1314,7 @@ void missiles_hive_explosion(int mi, int sx, int sy, int dx, int dy, int midir, missile[mi]._miDelFlag = TRUE; } -void missiles_fire_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam) -{ - if (LineClear(sx, sy, dx, dy)) { - if (id >= 0) - UseMana(id, SPL_RUNEFIRE); - if (missiles_found_target(mi, &dx, &dy, 10)) { - missile[mi]._miVar1 = MIS_HIVEEXP; - missile[mi]._miDelFlag = FALSE; - missile[mi]._mlid = AddLight(dx, dy, 8); - } else { - missile[mi]._miDelFlag = TRUE; - } - } else { - missile[mi]._miDelFlag = TRUE; - } -} - -BOOLEAN missiles_found_target(int mi, int *x, int *y, int rad) +static BOOLEAN missiles_found_target(int mi, int *x, int *y, int rad) { BOOLEAN found; int i, j, k, tx, ty, dp; @@ -1365,6 +1348,23 @@ BOOLEAN missiles_found_target(int mi, int *x, int *y, int rad) return found; } +void missiles_fire_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam) +{ + if (LineClear(sx, sy, dx, dy)) { + if (id >= 0) + UseMana(id, SPL_RUNEFIRE); + if (missiles_found_target(mi, &dx, &dy, 10)) { + missile[mi]._miVar1 = MIS_HIVEEXP; + missile[mi]._miDelFlag = FALSE; + missile[mi]._mlid = AddLight(dx, dy, 8); + } else { + missile[mi]._miDelFlag = TRUE; + } + } else { + missile[mi]._miDelFlag = TRUE; + } +} + void missiles_light_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam) { if (LineClear(sx, sy, dx, dy)) { diff --git a/Source/missiles.h b/Source/missiles.h index 1daeb8f62..781306580 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -16,39 +16,23 @@ extern int missileactive[MAXMISSILES]; extern int missileavail[MAXMISSILES]; extern MissileStruct missile[MAXMISSILES]; extern int nummissiles; -extern BOOL ManashieldFlag; -extern ChainStruct chain[MAXMISSILES]; extern BOOL MissilePreFlag; -extern int numchains; void GetDamageAmt(int i, int *mind, int *maxd); -BOOL CheckBlock(int fx, int fy, int tx, int ty); -int FindClosest(int sx, int sy, int rad); int GetSpellLevel(int id, int sn); -int GetDirection8(int x1, int y1, int x2, int y2); -int GetDirection16(int x1, int y1, int x2, int y2); void DeleteMissile(int mi, int i); -void GetMissileVel(int i, int sx, int sy, int dx, int dy, int v); -void PutMissile(int i); -void GetMissilePos(int i); -void MoveMissilePos(int i); BOOL MonsterTrapHit(int m, int mindam, int maxdam, int dist, int t, BOOLEAN shift); -BOOL MonsterMHit(int pnum, int m, int mindam, int maxdam, int dist, int t, BOOLEAN shift); BOOL PlayerMHit(int pnum, int m, int dist, int mind, int maxd, int mtype, BOOLEAN shift, int earflag); -BOOL Plr2PlrMHit(int pnum, int p, int mindam, int maxdam, int dist, int mtype, BOOLEAN shift); -void CheckMissileCol(int i, int mindam, int maxdam, BOOL shift, int mx, int my, BOOLEAN nodel); void SetMissAnim(int mi, int animtype); void SetMissDir(int mi, int dir); void LoadMissileGFX(BYTE mi); void InitMissileGFX(); -void FreeMissileGFX(int mi); void FreeMissiles(); void FreeMissiles2(); void InitMissiles(); #ifdef HELLFIRE void missiles_hive_explosion(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void missiles_fire_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); -BOOLEAN missiles_found_target(int mi, int *x, int *y, int rad); void missiles_light_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void missiles_great_light_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void missiles_immolation_rune(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); @@ -78,7 +62,6 @@ void AddBlodboil(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy #endif void AddLArrow(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddArrow(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); -void GetVileMissPos(int mi, int dx, int dy); void AddRndTeleport(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddFirebolt(int mi, int sx, int sy, int dx, int dy, int midir, char micaster, int id, int dam); void AddMagmaball(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); @@ -91,7 +74,6 @@ void AddLightctrl(int mi, int sx, int sy, int dx, int dy, int midir, char mienem void AddLightning(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddMisexp(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddWeapexp(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); -BOOL CheckIfTrig(int x, int y); void AddTown(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddFlash(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddFlash2(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); @@ -138,7 +120,6 @@ void AddBoneSpirit(int mi, int sx, int sy, int dx, int dy, int midir, char miene void AddRportal(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); void AddDiabApoca(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, int id, int dam); int AddMissile(int sx, int sy, int dx, int dy, int midir, int mitype, char micaster, int id, int midam, int spllvl); -int Sentfire(int i, int sx, int sy); void MI_Dummy(int i); void MI_Golem(int i); void MI_SetManashield(int i); @@ -172,7 +153,6 @@ void MI_Lightning(int i); void MI_Town(int i); void MI_Flash(int i); void MI_Flash2(int i); -void MI_Manashield(int i); void MI_Etherealize(int i); void MI_Firemove(int i); void MI_Guardian(int i); @@ -204,11 +184,6 @@ void ProcessMissiles(); void missiles_process_charge(); void ClearMissileSpot(int mi); -/* rdata */ - -extern int XDirAdd[8]; -extern int YDirAdd[8]; - #ifdef __cplusplus } #endif diff --git a/Source/monster.cpp b/Source/monster.cpp index 300f887cd..e9021a201 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -936,6 +936,36 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int unpackfilesize) } } +static void PlaceUniques() +{ + int u, mt; + BOOL done; + + for (u = 0; UniqMonst[u].mtype != -1; u++) { + if (UniqMonst[u].mlevel != currlevel) + continue; + done = FALSE; + for (mt = 0; mt < nummtypes; mt++) { + if (done) + break; + done = (Monsters[mt].mtype == UniqMonst[u].mtype); + } + mt--; + if (u == UMT_GARBUD && quests[Q_GARBUD]._qactive == QUEST_NOTAVAIL) + done = FALSE; + if (u == UMT_ZHAR && quests[Q_ZHAR]._qactive == QUEST_NOTAVAIL) + done = FALSE; + if (u == UMT_SNOTSPIL && quests[Q_LTBANNER]._qactive == QUEST_NOTAVAIL) + done = FALSE; + if (u == UMT_LACHDAN && quests[Q_VEIL]._qactive == QUEST_NOTAVAIL) + done = FALSE; + if (u == UMT_WARLORD && quests[Q_WARLORD]._qactive == QUEST_NOTAVAIL) + done = FALSE; + if (done) + PlaceUniqueMonst(u, mt, 8); + } +} + void PlaceQuestMonsters() { int skeltype; @@ -1194,36 +1224,6 @@ void InitMonsters() } } -void PlaceUniques() -{ - int u, mt; - BOOL done; - - for (u = 0; UniqMonst[u].mtype != -1; u++) { - if (UniqMonst[u].mlevel != currlevel) - continue; - done = FALSE; - for (mt = 0; mt < nummtypes; mt++) { - if (done) - break; - done = (Monsters[mt].mtype == UniqMonst[u].mtype); - } - mt--; - if (u == UMT_GARBUD && quests[Q_GARBUD]._qactive == QUEST_NOTAVAIL) - done = FALSE; - if (u == UMT_ZHAR && quests[Q_ZHAR]._qactive == QUEST_NOTAVAIL) - done = FALSE; - if (u == UMT_SNOTSPIL && quests[Q_LTBANNER]._qactive == QUEST_NOTAVAIL) - done = FALSE; - if (u == UMT_LACHDAN && quests[Q_VEIL]._qactive == QUEST_NOTAVAIL) - done = FALSE; - if (u == UMT_WARLORD && quests[Q_WARLORD]._qactive == QUEST_NOTAVAIL) - done = FALSE; - if (done) - PlaceUniqueMonst(u, mt, 8); - } -} - void SetMapMonsters(BYTE *pMap, int startx, int starty) { WORD rw, rh; diff --git a/Source/monster.h b/Source/monster.h index 7117d9dce..e9df081bc 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -12,112 +12,48 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -extern int MissileFileFlag; extern int monstkills[MAXMONSTERS]; extern int monstactive[MAXMONSTERS]; extern int nummonsters; extern BOOLEAN sgbSaveSoundOn; extern MonsterStruct monster[MAXMONSTERS]; -extern int totalmonsters; extern CMonster Monsters[MAX_LVLMTYPES]; -#ifdef HELLFIRE -extern int GraphicTable[NUMLEVELS][MAX_LVLMTYPES]; -#else -extern BYTE GraphicTable[NUMLEVELS][MAX_LVLMTYPES]; -#endif -extern int monstimgtot; -extern int uniquetrans; extern int nummtypes; -void InitMonsterTRN(int monst, BOOL special); void InitLevelMonsters(); -int AddMonsterType(int type, int placeflag); void GetLevelMTypes(); void InitMonsterGFX(int monst); -void ClearMVars(int i); void InitMonster(int i, int rd, int mtype, int x, int y); void ClrAllMonsters(); -BOOL MonstPlace(int xp, int yp); void monster_some_crypt(); -void PlaceMonster(int i, int mtype, int x, int y); -void PlaceUniqueMonst(int uniqindex, int miniontype, int unpackfilesize); -void PlaceQuestMonsters(); void PlaceGroup(int mtype, int num, int leaderf, int leader); -void LoadDiabMonsts(); void InitMonsters(); -void PlaceUniques(); void SetMapMonsters(BYTE *pMap, int startx, int starty); void DeleteMonster(int i); int AddMonster(int x, int y, int dir, int mtype, BOOL InMap); #ifdef HELLFIRE void monster_43C785(int i); #endif -void NewMonsterAnim(int i, AnimStruct *anim, int md); -BOOL M_Ranged(int i); BOOL M_Talker(int i); -void M_Enemy(int i); -int M_GetDir(int i); -void M_CheckEFlag(int i); void M_StartStand(int i, int md); -void M_StartDelay(int i, int len); -void M_StartSpStand(int i, int md); -void M_StartWalk(int i, int xvel, int yvel, int xadd, int yadd, int EndDir); -void M_StartWalk2(int i, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int EndDir); -void M_StartWalk3(int i, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, int EndDir); -void M_StartAttack(int i); -void M_StartRAttack(int i, int missile_type, int dam); -void M_StartRSpAttack(int i, int missile_type, int dam); -void M_StartSpAttack(int i); -void M_StartEat(int i); void M_ClearSquares(int i); void M_GetKnockback(int i); void M_StartHit(int i, int pnum, int dam); -void M_DiabloDeath(int i, BOOL sendmsg); -#ifdef HELLFIRE -void SpawnLoot(int i, BOOL sendmsg); -#endif -void M2MStartHit(int mid, int i, int dam); -void MonstStartKill(int i, int pnum, BOOL sendmsg); -void M2MStartKill(int i, int mid); void M_StartKill(int i, int pnum); void M_SyncStartKill(int i, int x, int y, int pnum); -void M_StartFadein(int i, int md, BOOL backwards); -void M_StartFadeout(int i, int md, BOOL backwards); -void M_StartHeal(int i); -void M_ChangeLightOffset(int monst); BOOL M_DoStand(int i); BOOL M_DoWalk(int i); BOOL M_DoWalk2(int i); BOOL M_DoWalk3(int i); -void M_TryM2MHit(int i, int mid, int hper, int mind, int maxd); -void M_TryH2HHit(int i, int pnum, int Hit, int MinDam, int MaxDam); BOOL M_DoAttack(int i); -BOOL M_DoRAttack(int i); -int M_DoRSpAttack(int i); -BOOL M_DoSAttack(int i); -BOOL M_DoFadein(int i); -BOOL M_DoFadeout(int i); -int M_DoHeal(int i); -int M_DoTalk(int i); void M_Teleport(int i); BOOL M_DoGotHit(int i); void M_UpdateLeader(int i); void DoEnding(); void PrepDoEnding(); -BOOL M_DoDeath(int i); -BOOL M_DoSpStand(int i); -BOOL M_DoDelay(int i); -BOOL M_DoStone(int i); void M_WalkDir(int i, int md); -void GroupUnity(int i); -BOOL M_CallWalk(int i, int md); -BOOL M_PathWalk(int i); -BOOL M_CallWalk2(int i, int md); -BOOL M_DumbWalk(int i, int md); -BOOL M_RoundWalk(int i, int md, int *dir); void MAI_Zombie(int i); void MAI_SkelSd(int i); -BOOL MAI_Path(int i); void MAI_Snake(int i); void MAI_Bat(int i); void MAI_SkelBow(int i); @@ -152,7 +88,6 @@ void mai_roundranged_441EA0(int i); #endif void MAI_Acid(int i); void MAI_Diablo(int i); -void MAI_RR2(int i, int mistype, int dam); void MAI_Mega(int i); void MAI_Golum(int i); void MAI_SkelKing(int i); @@ -191,7 +126,6 @@ BOOL PosOkMonst3(int i, int x, int y); BOOL IsSkel(int mt); BOOL IsGoat(int mt); int M_SpawnSkel(int x, int y, int dir); -void ActivateSpawn(int i, int x, int y, int dir); BOOL SpawnSkeleton(int ii, int x, int y); int PreSpawnSkeleton(); void TalktoMonster(int i); @@ -201,30 +135,12 @@ BOOL CheckMonsterHit(int m, BOOL *ret); int encode_enemy(int m); void decode_enemy(int m, int enemy); -/* rdata */ - -extern const char plr2monst[9]; -extern const BYTE counsmiss[4]; - /* data */ -extern int MWVel[24][3]; -extern char animletter[7]; -extern int left[8]; -extern int right[8]; extern int opposite[8]; extern int offset_x[8]; extern int offset_y[8]; -/** unused */ -extern int rnd5[4]; -extern int rnd10[4]; -extern int rnd20[4]; -extern int rnd60[4]; -// - -extern void (*AiProc[])(int i); - #ifdef __cplusplus } #endif diff --git a/Source/movie.h b/Source/movie.h index 69eb7f718..f93c83a46 100644 --- a/Source/movie.h +++ b/Source/movie.h @@ -18,8 +18,6 @@ extern BOOL loop_movie; void play_movie(const char *pszMovie, BOOL user_can_close); void MovieWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -/* rdata */ - #ifdef __cplusplus } #endif diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 67a1032ba..92f6e2e01 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -347,23 +347,26 @@ bool ReadMPQHeader(Archive *archive, _FILEHEADER *hdr) } // namespace -void mpqapi_remove_hash_entry(const char *pszName) +static _BLOCKENTRY *mpqapi_new_block(int *block_index) { - _HASHENTRY *pHashTbl; _BLOCKENTRY *blockEntry; - int hIdx, block_offset, block_size; + DWORD i; - hIdx = FetchHandle(pszName); - if (hIdx != -1) { - pHashTbl = &cur_archive.sgpHashTbl[hIdx]; - blockEntry = &cur_archive.sgpBlockTbl[pHashTbl->block]; - pHashTbl->block = -2; - block_offset = blockEntry->offset; - block_size = blockEntry->sizealloc; - memset(blockEntry, 0, sizeof(*blockEntry)); - mpqapi_alloc_block(block_offset, block_size); - cur_archive.modified = true; + blockEntry = cur_archive.sgpBlockTbl; + + i = 0; + while (blockEntry->offset || blockEntry->sizealloc || blockEntry->flags || blockEntry->sizefile) { + i++; + blockEntry++; + if (i >= 2048) { + app_fatal("Out of free block entries"); + return NULL; + } } + if (block_index) + *block_index = i; + + return blockEntry; } void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) @@ -405,34 +408,38 @@ void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) } } -_BLOCKENTRY *mpqapi_new_block(int *block_index) +int mpqapi_find_free_block(uint32_t size, uint32_t *block_size) { - _BLOCKENTRY *blockEntry; - DWORD i; - - blockEntry = cur_archive.sgpBlockTbl; + _BLOCKENTRY *pBlockTbl; + int i, result; - i = 0; - while (blockEntry->offset || blockEntry->sizealloc || blockEntry->flags || blockEntry->sizefile) { - i++; - blockEntry++; - if (i >= 2048) { - app_fatal("Out of free block entries"); - return NULL; + pBlockTbl = cur_archive.sgpBlockTbl; + i = 2048; + while (1) { + i--; + if (pBlockTbl->offset && !pBlockTbl->flags && !pBlockTbl->sizefile && (DWORD)pBlockTbl->sizealloc >= size) + break; + pBlockTbl++; + if (!i) { + *block_size = size; + result = cur_archive.size; + cur_archive.size += size; + return result; } } - if (block_index) - *block_index = i; - return blockEntry; -} + result = pBlockTbl->offset; + *block_size = size; + pBlockTbl->offset += size; + pBlockTbl->sizealloc -= size; -int FetchHandle(const char *pszName) -{ - return mpqapi_get_hash_index(Hash(pszName, 0), Hash(pszName, 1), Hash(pszName, 2), 0); + if (!pBlockTbl->sizealloc) + memset(pBlockTbl, 0, sizeof(*pBlockTbl)); + + return result; } -int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale) +static int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale) { int idx, i; @@ -449,6 +456,30 @@ int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale) return -1; } +static int FetchHandle(const char *pszName) +{ + return mpqapi_get_hash_index(Hash(pszName, 0), Hash(pszName, 1), Hash(pszName, 2), 0); +} + +void mpqapi_remove_hash_entry(const char *pszName) +{ + _HASHENTRY *pHashTbl; + _BLOCKENTRY *blockEntry; + int hIdx, block_offset, block_size; + + hIdx = FetchHandle(pszName); + if (hIdx != -1) { + pHashTbl = &cur_archive.sgpHashTbl[hIdx]; + blockEntry = &cur_archive.sgpBlockTbl[pHashTbl->block]; + pHashTbl->block = -2; + block_offset = blockEntry->offset; + block_size = blockEntry->sizealloc; + memset(blockEntry, 0, sizeof(*blockEntry)); + mpqapi_alloc_block(block_offset, block_size); + cur_archive.modified = true; + } +} + void mpqapi_remove_hash_entries(BOOL (*fnGetName)(DWORD, char *)) { DWORD dwIndex, i; @@ -460,21 +491,7 @@ void mpqapi_remove_hash_entries(BOOL (*fnGetName)(DWORD, char *)) } } -BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen) -{ - _BLOCKENTRY *blockEntry; - - cur_archive.modified = true; - mpqapi_remove_hash_entry(pszName); - blockEntry = mpqapi_add_file(pszName, 0, 0); - if (!mpqapi_write_file_contents(pszName, pbData, dwLen, blockEntry)) { - mpqapi_remove_hash_entry(pszName); - return FALSE; - } - return TRUE; -} - -_BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index) +static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index) { DWORD h1, h2, h3; int i, hIdx; @@ -504,7 +521,7 @@ _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_i return pBlk; } -BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk) +static BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk) { const char *str_ptr = pszName; const char *tmp; @@ -586,35 +603,18 @@ BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD d return TRUE; } -int mpqapi_find_free_block(uint32_t size, uint32_t *block_size) +BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen) { - _BLOCKENTRY *pBlockTbl; - int i, result; + _BLOCKENTRY *blockEntry; - pBlockTbl = cur_archive.sgpBlockTbl; - i = 2048; - while (1) { - i--; - if (pBlockTbl->offset && !pBlockTbl->flags && !pBlockTbl->sizefile && (DWORD)pBlockTbl->sizealloc >= size) - break; - pBlockTbl++; - if (!i) { - *block_size = size; - result = cur_archive.size; - cur_archive.size += size; - return result; - } + cur_archive.modified = true; + mpqapi_remove_hash_entry(pszName); + blockEntry = mpqapi_add_file(pszName, 0, 0); + if (!mpqapi_write_file_contents(pszName, pbData, dwLen, blockEntry)) { + mpqapi_remove_hash_entry(pszName); + return FALSE; } - - result = pBlockTbl->offset; - *block_size = size; - pBlockTbl->offset += size; - pBlockTbl->sizealloc -= size; - - if (!pBlockTbl->sizealloc) - memset(pBlockTbl, 0, sizeof(*pBlockTbl)); - - return result; + return TRUE; } void mpqapi_rename(char *pszOld, char *pszNew) diff --git a/Source/mpqapi.h b/Source/mpqapi.h index 8743cd686..6444b5856 100644 --- a/Source/mpqapi.h +++ b/Source/mpqapi.h @@ -15,22 +15,13 @@ extern "C" { #endif void mpqapi_remove_hash_entry(const char *pszName); -void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size); -_BLOCKENTRY *mpqapi_new_block(int *block_index); -int FetchHandle(const char *pszName); -int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale); void mpqapi_remove_hash_entries(BOOL (*fnGetName)(DWORD, char *)); BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen); -_BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index); -BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk); -int mpqapi_find_free_block(uint32_t size, uint32_t *block_size); void mpqapi_rename(char *pszOld, char *pszNew); BOOL mpqapi_has_file(const char *pszName); BOOL OpenMPQ(const char *pszArchive, DWORD dwChar); BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, DWORD dwChar); -/* rdata */ -/* data */ #ifdef __cplusplus } #endif