From 3d93478a6c84993d00554da34781e6841ad00ed8 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 25 Jan 2021 01:21:18 +0100 Subject: [PATCH] Some additional clean up --- Source/msg.cpp | 4 +- Source/sync.cpp | 46 ++++++------ Source/sync.h | 4 +- Source/tmsg.cpp | 12 ++- Source/tmsg.h | 4 +- Source/town.cpp | 190 +++++++++++++++++++++++++---------------------- Source/town.h | 7 +- Source/track.cpp | 26 ++++--- Source/track.h | 4 +- 9 files changed, 158 insertions(+), 139 deletions(-) diff --git a/Source/msg.cpp b/Source/msg.cpp index f52c684dc..097d2ed65 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -2501,7 +2501,7 @@ static DWORD On_OPENHIVE(TCmd *pCmd, int pnum) TCmdLocParam2 *p = (TCmdLocParam2 *)pCmd; if (gbBufferMsgs != 1) { AddMissile(p->x, p->y, p->wParam1, p->wParam2, 0, MIS_HIVEEXP2, TARGET_MONSTERS, pnum, 0, 0); - town_4751C6(); + TownOpenHive(); } return sizeof(*p); } @@ -2509,7 +2509,7 @@ static DWORD On_OPENHIVE(TCmd *pCmd, int pnum) static DWORD On_OPENCRYPT(TCmd *pCmd, int pnum) { if (gbBufferMsgs != 1) { - town_475595(); + TownOpenGrave(); InitTownTriggers(); if (currlevel == 0) PlaySFX(IS_SARC); diff --git a/Source/sync.cpp b/Source/sync.cpp index 00a4eb971..b42c00599 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -7,9 +7,11 @@ DEVILUTION_BEGIN_NAMESPACE -WORD sync_word_6AA708[MAXMONSTERS]; +namespace { + +Uint16 sync_word_6AA708[MAXMONSTERS]; int sgnMonsters; -WORD sgwLRU[MAXMONSTERS]; +Uint16 sgwLRU[MAXMONSTERS]; int sgnSyncItem; int sgnSyncPInv; @@ -40,10 +42,10 @@ static void sync_monster_pos(TSyncMonster *p, int ndx) sgwLRU[ndx] = monster[ndx]._msquelch == 0 ? 0xFFFF : 0xFFFE; } -static BOOL sync_monster_active(TSyncMonster *p) +static bool sync_monster_active(TSyncMonster *p) { int i, m, ndx; - DWORD lru; + Uint32 lru; ndx = -1; lru = 0xFFFFFFFF; @@ -57,17 +59,17 @@ static BOOL sync_monster_active(TSyncMonster *p) } if (ndx == -1) { - return FALSE; + return false; } sync_monster_pos(p, ndx); - return TRUE; + return true; } -static BOOL sync_monster_active2(TSyncMonster *p) +static bool sync_monster_active2(TSyncMonster *p) { int i, m, ndx; - DWORD lru; + Uint32 lru; ndx = -1; lru = 0xFFFE; @@ -85,11 +87,11 @@ static BOOL sync_monster_active2(TSyncMonster *p) } if (ndx == -1) { - return FALSE; + return false; } sync_monster_pos(p, ndx); - return TRUE; + return true; } static void SyncPlrInv(TSyncHeader *pHdr) @@ -132,7 +134,7 @@ static void SyncPlrInv(TSyncHeader *pHdr) pHdr->bItemI = -1; } - assert((DWORD)sgnSyncPInv < NUM_INVLOC); + assert(sgnSyncPInv > -1 && sgnSyncPInv < NUM_INVLOC); pItem = &plr[myplr].InvBody[sgnSyncPInv]; if (pItem->_itype != ITYPE_NONE) { pHdr->bPInvLoc = sgnSyncPInv; @@ -150,11 +152,13 @@ static void SyncPlrInv(TSyncHeader *pHdr) } } -DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen) +} + +Uint32 sync_all_monsters(const Uint8 *pbBuf, Uint32 dwMaxLen) { TSyncHeader *pHdr; int i; - BOOL sync; + bool sync; if (nummonsters < 1) { return dwMaxLen; @@ -175,7 +179,7 @@ DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen) sync_one_monster(); for (i = 0; i < nummonsters && dwMaxLen >= sizeof(TSyncMonster); i++) { - sync = FALSE; + sync = false; if (i < 2) { sync = sync_monster_active2((TSyncMonster *)pbBuf); } @@ -195,8 +199,8 @@ DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen) static void sync_monster(int pnum, const TSyncMonster *p) { - int i, ndx, md, mdx, mdy; - DWORD delta; + int ndx, md, mdx, mdy; + Uint32 delta; ndx = p->_mndx; @@ -204,12 +208,6 @@ static void sync_monster(int pnum, const TSyncMonster *p) return; } - for (i = 0; i < nummonsters; i++) { // CODEFIX: this loop does nothing - if (monstactive[i] == ndx) { - break; - } - } - delta = abs(plr[myplr]._px - monster[ndx]._mx) + abs(plr[myplr]._py - monster[ndx]._my); if (delta > 255) { delta = 255; @@ -251,10 +249,10 @@ static void sync_monster(int pnum, const TSyncMonster *p) decode_enemy(ndx, p->_menemy); } -DWORD sync_update(int pnum, const BYTE *pbBuf) +Uint32 sync_update(int pnum, const Uint8 *pbBuf) { TSyncHeader *pHdr; - WORD wLen; + Uint16 wLen; pHdr = (TSyncHeader *)pbBuf; pbBuf += sizeof(*pHdr); diff --git a/Source/sync.h b/Source/sync.h index fdf8e3ac3..3e646bd04 100644 --- a/Source/sync.h +++ b/Source/sync.h @@ -12,8 +12,8 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen); -DWORD sync_update(int pnum, const BYTE *pbBuf); +Uint32 sync_all_monsters(const Uint8 *pbBuf, Uint32 dwMaxLen); +Uint32 sync_update(int pnum, const Uint8 *pbBuf); void sync_init(); #ifdef __cplusplus diff --git a/Source/tmsg.cpp b/Source/tmsg.cpp index c8d30c0a6..25e67b34b 100644 --- a/Source/tmsg.cpp +++ b/Source/tmsg.cpp @@ -7,9 +7,13 @@ DEVILUTION_BEGIN_NAMESPACE -static TMsg *sgpTimedMsgHead; +namespace { -int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen) +TMsg *sgpTimedMsgHead; + +} + +int tmsg_get(Uint8 *pbMsg, Uint32 dwMaxLen) { int len; TMsg *head; @@ -28,12 +32,12 @@ int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen) return len; } -void tmsg_add(BYTE *pbMsg, BYTE bLen) +void tmsg_add(Uint8 *pbMsg, Uint8 bLen) { TMsg **tail; TMsg *msg = (TMsg *)DiabloAllocPtr(bLen + sizeof(*msg)); - msg->hdr.pNext = NULL; + msg->hdr.pNext = nullptr; msg->hdr.dwTime = SDL_GetTicks() + tick_delay * 10; msg->hdr.bLen = bLen; memcpy(msg->body, pbMsg, bLen); diff --git a/Source/tmsg.h b/Source/tmsg.h index 4a15fb30b..a5dbdbee1 100644 --- a/Source/tmsg.h +++ b/Source/tmsg.h @@ -12,8 +12,8 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen); -void tmsg_add(BYTE *pbMsg, BYTE bLen); +int tmsg_get(Uint8 *pbMsg, Uint32 dwMaxLen); +void tmsg_add(Uint8 *pbMsg, Uint8 bLen); void tmsg_start(); void tmsg_cleanup(); diff --git a/Source/town.cpp b/Source/town.cpp index abc5b40c5..d3b778dc4 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -7,6 +7,8 @@ DEVILUTION_BEGIN_NAMESPACE +namespace { + /** * @brief Load level data into dPiece * @param P3Tiles Tile set @@ -16,23 +18,23 @@ DEVILUTION_BEGIN_NAMESPACE * @param w width of sector * @param h height of sector */ -void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) +void T_FillSector(Uint8 *P3Tiles, Uint8 *pSector, int xi, int yi, int w, int h) { int i, j, xx, yy, nMap; - long v1, v2, v3, v4, ii; - WORD *Sector; + Sint16 v1, v2, v3, v4, ii; + Uint16 *Sector; ii = 4; yy = yi; for (j = 0; j < h; j++) { xx = xi; for (i = 0; i < w; i++) { - WORD *Map; + Uint16 *Map; - Map = (WORD *)&pSector[ii]; + Map = (Uint16 *)&pSector[ii]; nMap = SDL_SwapLE16(*Map); if (nMap) { - Sector = (((WORD *)&P3Tiles[(nMap - 1) * 8])); + Sector = (((Uint16 *)&P3Tiles[(nMap - 1) * 8])); v1 = SDL_SwapLE16(*(Sector + 0)) + 1; v2 = SDL_SwapLE16(*(Sector + 1)) + 1; v3 = SDL_SwapLE16(*(Sector + 2)) + 1; @@ -62,12 +64,12 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h) * @param yy upper left destination * @param t tile id */ -void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) +void T_FillTile(Uint8 *P3Tiles, int xx, int yy, int t) { long v1, v2, v3, v4; - WORD *Tiles; + Uint16 *Tiles; - Tiles = ((WORD *)&P3Tiles[(t - 1) * 8]); + Tiles = ((Uint16 *)&P3Tiles[(t - 1) * 8]); v1 = SDL_SwapLE16(*(Tiles + 0)) + 1; v2 = SDL_SwapLE16(*(Tiles + 1)) + 1; v3 = SDL_SwapLE16(*(Tiles + 2)) + 1; @@ -79,58 +81,10 @@ void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t) dPiece[xx + 1][yy + 1] = v4; } -void town_4751C6() -{ - dPiece[78][60] = 0x48a; - dPiece[79][60] = 0x48b; - dPiece[78][61] = 0x48c; - dPiece[79][61] = 0x50e; - dPiece[78][62] = 0x4ee; - dPiece[78][63] = 0x4f0; - dPiece[79][62] = 0x510; - dPiece[79][63] = 0x511; - dPiece[79][64] = 0x512; - dPiece[78][64] = 0x11a; - dPiece[78][65] = 0x11c; - dPiece[79][65] = 0x11d; - dPiece[80][60] = 0x513; - dPiece[80][61] = 0x515; - dPiece[81][61] = 0x516; - dPiece[82][60] = 0x517; - dPiece[83][60] = 0x518; - dPiece[82][61] = 0x519; - dPiece[83][61] = 0x51a; - dPiece[80][62] = 0x51b; - dPiece[81][62] = 0x51c; - dPiece[80][63] = 0x51d; - dPiece[81][63] = 0x51e; - dPiece[80][64] = 0x51f; - dPiece[81][64] = 0x520; - dPiece[80][65] = 0x521; - dPiece[81][65] = 0x522; - dPiece[82][64] = 0x527; - dPiece[83][64] = 0x528; - dPiece[82][65] = 0x529; - dPiece[83][65] = 0x52a; - dPiece[82][62] = 0x523; - dPiece[83][62] = 0x524; - dPiece[82][63] = 0x525; - dPiece[83][63] = 0x526; - dPiece[84][61] = 0x118; - dPiece[84][62] = 0x118; - dPiece[84][63] = 0x118; - dPiece[85][60] = 0x118; - dPiece[85][61] = 0x118; - dPiece[85][63] = 8; - dPiece[85][64] = 8; - dPiece[86][60] = 0xd9; - dPiece[86][61] = 0x18; - dPiece[85][62] = 0x13; - dPiece[84][64] = 0x118; - SetDungeonMicros(); -} - -void town_475379() +/** + * @brief Update the map to show the closed hive + */ +void TownCloseHive() { dPiece[78][60] = 0x48a; dPiece[79][60] = 0x4eb; @@ -181,7 +135,10 @@ void town_475379() SetDungeonMicros(); } -void town_47552C() +/** + * @brief Update the map to show the closed grave + */ +void TownCloseGrave() { dPiece[36][21] = 0x52b; dPiece[37][21] = 0x52c; @@ -196,28 +153,13 @@ void town_47552C() SetDungeonMicros(); } -void town_475595() -{ - dPiece[36][21] = 0x533; - dPiece[37][21] = 0x534; - dPiece[36][22] = 0x535; - dPiece[37][22] = 0x536; - dPiece[36][23] = 0x537; - dPiece[37][23] = 0x538; - dPiece[36][24] = 0x539; - dPiece[37][24] = 0x53a; - dPiece[35][21] = 0x53b; - dPiece[34][21] = 0x53c; - SetDungeonMicros(); -} - /** * @brief Initialize all of the levels data */ void T_Pass3() { int xx, yy, x; - BYTE *P3Tiles, *pSector; + Uint8 *P3Tiles, *pSector; for (yy = 0; yy < MAXDUNY; yy += 2) { for (xx = 0; xx < MAXDUNX; xx += 2) { @@ -228,17 +170,17 @@ void T_Pass3() } } - P3Tiles = LoadFileInMem("Levels\\TownData\\Town.TIL", NULL); - pSector = LoadFileInMem("Levels\\TownData\\Sector1s.DUN", NULL); + P3Tiles = LoadFileInMem("Levels\\TownData\\Town.TIL", nullptr); + pSector = LoadFileInMem("Levels\\TownData\\Sector1s.DUN", nullptr); T_FillSector(P3Tiles, pSector, 46, 46, 25, 25); mem_free_dbg(pSector); - pSector = LoadFileInMem("Levels\\TownData\\Sector2s.DUN", NULL); + pSector = LoadFileInMem("Levels\\TownData\\Sector2s.DUN", nullptr); T_FillSector(P3Tiles, pSector, 46, 0, 25, 23); mem_free_dbg(pSector); - pSector = LoadFileInMem("Levels\\TownData\\Sector3s.DUN", NULL); + pSector = LoadFileInMem("Levels\\TownData\\Sector3s.DUN", nullptr); T_FillSector(P3Tiles, pSector, 0, 46, 23, 25); mem_free_dbg(pSector); - pSector = LoadFileInMem("Levels\\TownData\\Sector4s.DUN", NULL); + pSector = LoadFileInMem("Levels\\TownData\\Sector4s.DUN", nullptr); T_FillSector(P3Tiles, pSector, 0, 0, 23, 23); mem_free_dbg(pSector); @@ -259,14 +201,14 @@ void T_Pass3() if (gbIsHellfire) { if (quests[Q_FARMER]._qactive == 3 || quests[Q_FARMER]._qactive == 10 || quests[Q_JERSEY]._qactive == 3 || quests[Q_JERSEY]._qactive == 10) { - town_4751C6(); + TownOpenHive(); } else { - town_475379(); + TownCloseHive(); } if (quests[Q_GRAVE]._qactive == 3 || plr[myplr]._pLvlVisited[21]) - town_475595(); + TownOpenGrave(); else - town_47552C(); + TownCloseGrave(); } if (quests[Q_PWATER]._qactive != QUEST_DONE && quests[Q_PWATER]._qactive) { @@ -278,6 +220,80 @@ void T_Pass3() mem_free_dbg(P3Tiles); } +} + +/** + * @brief Update the map to show the open hive + */ +void TownOpenHive() +{ + dPiece[78][60] = 0x48a; + dPiece[79][60] = 0x48b; + dPiece[78][61] = 0x48c; + dPiece[79][61] = 0x50e; + dPiece[78][62] = 0x4ee; + dPiece[78][63] = 0x4f0; + dPiece[79][62] = 0x510; + dPiece[79][63] = 0x511; + dPiece[79][64] = 0x512; + dPiece[78][64] = 0x11a; + dPiece[78][65] = 0x11c; + dPiece[79][65] = 0x11d; + dPiece[80][60] = 0x513; + dPiece[80][61] = 0x515; + dPiece[81][61] = 0x516; + dPiece[82][60] = 0x517; + dPiece[83][60] = 0x518; + dPiece[82][61] = 0x519; + dPiece[83][61] = 0x51a; + dPiece[80][62] = 0x51b; + dPiece[81][62] = 0x51c; + dPiece[80][63] = 0x51d; + dPiece[81][63] = 0x51e; + dPiece[80][64] = 0x51f; + dPiece[81][64] = 0x520; + dPiece[80][65] = 0x521; + dPiece[81][65] = 0x522; + dPiece[82][64] = 0x527; + dPiece[83][64] = 0x528; + dPiece[82][65] = 0x529; + dPiece[83][65] = 0x52a; + dPiece[82][62] = 0x523; + dPiece[83][62] = 0x524; + dPiece[82][63] = 0x525; + dPiece[83][63] = 0x526; + dPiece[84][61] = 0x118; + dPiece[84][62] = 0x118; + dPiece[84][63] = 0x118; + dPiece[85][60] = 0x118; + dPiece[85][61] = 0x118; + dPiece[85][63] = 8; + dPiece[85][64] = 8; + dPiece[86][60] = 0xd9; + dPiece[86][61] = 0x18; + dPiece[85][62] = 0x13; + dPiece[84][64] = 0x118; + SetDungeonMicros(); +} + +/** + * @brief Update the map to show the open grave + */ +void TownOpenGrave() +{ + dPiece[36][21] = 0x533; + dPiece[37][21] = 0x534; + dPiece[36][22] = 0x535; + dPiece[37][22] = 0x536; + dPiece[36][23] = 0x537; + dPiece[37][23] = 0x538; + dPiece[36][24] = 0x539; + dPiece[37][24] = 0x53a; + dPiece[35][21] = 0x53b; + dPiece[34][21] = 0x53c; + SetDungeonMicros(); +} + /** * @brief Initialize town level * @param entry Methode of entry diff --git a/Source/town.h b/Source/town.h index e1faf7bd8..c2463930a 100644 --- a/Source/town.h +++ b/Source/town.h @@ -12,11 +12,8 @@ DEVILUTION_BEGIN_NAMESPACE extern "C" { #endif -void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h); -void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t); -void T_Pass3(); -void town_4751C6(); -void town_475595(); +void TownOpenHive(); +void TownOpenGrave(); void CreateTown(int entry); #ifdef __cplusplus diff --git a/Source/track.cpp b/Source/track.cpp index 6eed27e9a..3ac5b9f33 100644 --- a/Source/track.cpp +++ b/Source/track.cpp @@ -7,9 +7,13 @@ DEVILUTION_BEGIN_NAMESPACE -static BYTE sgbIsScrolling; -static DWORD sgdwLastWalk; -static BOOL sgbIsWalking; +namespace { + +BYTE sgbIsScrolling; +Uint32 sgdwLastWalk; +bool sgbIsWalking; + +} void track_process() { @@ -23,32 +27,32 @@ void track_process() return; if (cursmx != plr[myplr]._ptargx || cursmy != plr[myplr]._ptargy) { - DWORD tick = SDL_GetTicks(); + Uint32 tick = SDL_GetTicks(); if ((int)(tick - sgdwLastWalk) >= tick_delay * 6) { sgdwLastWalk = tick; - NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy); + NetSendCmdLoc(true, CMD_WALKXY, cursmx, cursmy); if (!sgbIsScrolling) - sgbIsScrolling = TRUE; + sgbIsScrolling = true; } } } -void track_repeat_walk(BOOL rep) +void track_repeat_walk(bool rep) { if (sgbIsWalking == rep) return; sgbIsWalking = rep; if (rep) { - sgbIsScrolling = FALSE; + sgbIsScrolling = false; sgdwLastWalk = SDL_GetTicks() - tick_delay; - NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy); + NetSendCmdLoc(true, CMD_WALKXY, cursmx, cursmy); } else if (sgbIsScrolling) { - sgbIsScrolling = FALSE; + sgbIsScrolling = false; } } -BOOL track_isscrolling() +bool track_isscrolling() { return sgbIsScrolling; } diff --git a/Source/track.h b/Source/track.h index 14f396abe..ba9ac8a68 100644 --- a/Source/track.h +++ b/Source/track.h @@ -13,8 +13,8 @@ extern "C" { #endif void track_process(); -void track_repeat_walk(BOOL rep); -BOOL track_isscrolling(); +void track_repeat_walk(bool rep); +bool track_isscrolling(); #ifdef __cplusplus }